|
| 1 | +// Protocol Buffers - Google's data interchange format |
| 2 | +// Copyright 2023 Google LLC. All rights reserved. |
| 3 | +// |
| 4 | +// Use of this source code is governed by a BSD-style |
| 5 | +// license that can be found in the LICENSE file or at |
| 6 | +// https://developers.google.com/open-source/licenses/bsd |
| 7 | + |
| 8 | +#include <gtest/gtest.h> |
| 9 | +#include "upb/base/descriptor_constants.h" |
| 10 | +#include "upb/mem/arena.hpp" |
| 11 | +#include "upb/reflection/def.hpp" |
| 12 | +#include "upb/test/editions_test.upb.h" |
| 13 | +#include "upb/test/editions_test.upbdefs.h" |
| 14 | + |
| 15 | +TEST(EditionsTest, PlainField) { |
| 16 | + upb::DefPool defpool; |
| 17 | + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); |
| 18 | + upb::FieldDefPtr f(md.FindFieldByName("plain_field")); |
| 19 | + EXPECT_TRUE(f.has_presence()); |
| 20 | +} |
| 21 | + |
| 22 | +TEST(EditionsTest, ImplicitPresenceField) { |
| 23 | + upb::DefPool defpool; |
| 24 | + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); |
| 25 | + upb::FieldDefPtr f(md.FindFieldByName("implicit_presence_field")); |
| 26 | + EXPECT_FALSE(f.has_presence()); |
| 27 | +} |
| 28 | + |
| 29 | +TEST(EditionsTest, DelimitedField) { |
| 30 | + upb::DefPool defpool; |
| 31 | + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); |
| 32 | + upb::FieldDefPtr f(md.FindFieldByName("delimited_field")); |
| 33 | + EXPECT_EQ(kUpb_FieldType_Group, f.type()); |
| 34 | +} |
| 35 | + |
| 36 | +TEST(EditionsTest, RequiredField) { |
| 37 | + upb::DefPool defpool; |
| 38 | + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); |
| 39 | + upb::FieldDefPtr f(md.FindFieldByName("required_field")); |
| 40 | + EXPECT_EQ(kUpb_Label_Required, f.label()); |
| 41 | +} |
| 42 | + |
| 43 | +TEST(EditionsTest, ClosedEnum) { |
| 44 | + upb::DefPool defpool; |
| 45 | + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); |
| 46 | + upb::FieldDefPtr f(md.FindFieldByName("enum_field")); |
| 47 | + ASSERT_TRUE(f.enum_subdef().is_closed()); |
| 48 | +} |
| 49 | + |
| 50 | +TEST(EditionsTest, PackedField) { |
| 51 | + upb::DefPool defpool; |
| 52 | + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); |
| 53 | + upb::FieldDefPtr f(md.FindFieldByName("unpacked_field")); |
| 54 | + ASSERT_FALSE(f.packed()); |
| 55 | +} |
| 56 | + |
| 57 | +TEST(EditionsTest, ConstructProto) { |
| 58 | + // Doesn't do anything except construct the proto. This just verifies that |
| 59 | + // the generated code compiles successfully. |
| 60 | + upb::Arena arena; |
| 61 | + upb_test_2023_EditionsMessage_new(arena.ptr()); |
| 62 | +} |
0 commit comments