|
|
|
@ -628,7 +628,7 @@ class DescriptorTest : public testing::Test { |
|
|
|
|
// required string foo = 1;
|
|
|
|
|
// optional TestEnum bar = 6;
|
|
|
|
|
// repeated TestForeign baz = 500000000;
|
|
|
|
|
// optional group qux = 15 {}
|
|
|
|
|
// optional group moo = 15 {}
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // in "bar.proto"
|
|
|
|
@ -636,7 +636,7 @@ class DescriptorTest : public testing::Test { |
|
|
|
|
// message TestMessage2 {
|
|
|
|
|
// required string foo = 1;
|
|
|
|
|
// required string bar = 2;
|
|
|
|
|
// required string quux = 6;
|
|
|
|
|
// required string mooo = 6;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // in "map.proto"
|
|
|
|
@ -654,7 +654,7 @@ class DescriptorTest : public testing::Test { |
|
|
|
|
// optional int32 field_name6 = 6 [json_name = "@type"];
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// We cheat and use TestForeign as the type for qux rather than create
|
|
|
|
|
// We cheat and use TestForeign as the type for moo rather than create
|
|
|
|
|
// an actual nested type.
|
|
|
|
|
//
|
|
|
|
|
// Since all primitive types (including string) use the same building
|
|
|
|
@ -678,7 +678,7 @@ class DescriptorTest : public testing::Test { |
|
|
|
|
AddField(message, "baz", 500000000, FieldDescriptorProto::LABEL_REPEATED, |
|
|
|
|
FieldDescriptorProto::TYPE_MESSAGE) |
|
|
|
|
->set_type_name("TestForeign"); |
|
|
|
|
AddField(message, "qux", 15, FieldDescriptorProto::LABEL_OPTIONAL, |
|
|
|
|
AddField(message, "moo", 15, FieldDescriptorProto::LABEL_OPTIONAL, |
|
|
|
|
FieldDescriptorProto::TYPE_GROUP) |
|
|
|
|
->set_type_name("TestForeign"); |
|
|
|
|
|
|
|
|
@ -691,7 +691,7 @@ class DescriptorTest : public testing::Test { |
|
|
|
|
FieldDescriptorProto::TYPE_STRING); |
|
|
|
|
AddField(message2, "bar", 2, FieldDescriptorProto::LABEL_REQUIRED, |
|
|
|
|
FieldDescriptorProto::TYPE_STRING); |
|
|
|
|
AddField(message2, "quux", 6, FieldDescriptorProto::LABEL_REQUIRED, |
|
|
|
|
AddField(message2, "mooo", 6, FieldDescriptorProto::LABEL_REQUIRED, |
|
|
|
|
FieldDescriptorProto::TYPE_STRING); |
|
|
|
|
|
|
|
|
|
FileDescriptorProto map_file; |
|
|
|
@ -754,7 +754,7 @@ class DescriptorTest : public testing::Test { |
|
|
|
|
foo_ = message_->field(0); |
|
|
|
|
bar_ = message_->field(1); |
|
|
|
|
baz_ = message_->field(2); |
|
|
|
|
qux_ = message_->field(3); |
|
|
|
|
moo_ = message_->field(3); |
|
|
|
|
|
|
|
|
|
ASSERT_EQ(1, bar_file_->message_type_count()); |
|
|
|
|
message2_ = bar_file_->message_type(0); |
|
|
|
@ -762,7 +762,7 @@ class DescriptorTest : public testing::Test { |
|
|
|
|
ASSERT_EQ(3, message2_->field_count()); |
|
|
|
|
foo2_ = message2_->field(0); |
|
|
|
|
bar2_ = message2_->field(1); |
|
|
|
|
quux2_ = message2_->field(2); |
|
|
|
|
mooo2_ = message2_->field(2); |
|
|
|
|
|
|
|
|
|
ASSERT_EQ(1, map_file_->message_type_count()); |
|
|
|
|
message3_ = map_file_->message_type(0); |
|
|
|
@ -801,11 +801,11 @@ class DescriptorTest : public testing::Test { |
|
|
|
|
const FieldDescriptor* foo_; |
|
|
|
|
const FieldDescriptor* bar_; |
|
|
|
|
const FieldDescriptor* baz_; |
|
|
|
|
const FieldDescriptor* qux_; |
|
|
|
|
const FieldDescriptor* moo_; |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* foo2_; |
|
|
|
|
const FieldDescriptor* bar2_; |
|
|
|
|
const FieldDescriptor* quux2_; |
|
|
|
|
const FieldDescriptor* mooo2_; |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* map_; |
|
|
|
|
}; |
|
|
|
@ -886,7 +886,7 @@ TEST_F(DescriptorTest, FieldsByIndex) { |
|
|
|
|
EXPECT_EQ(foo_, message_->field(0)); |
|
|
|
|
EXPECT_EQ(bar_, message_->field(1)); |
|
|
|
|
EXPECT_EQ(baz_, message_->field(2)); |
|
|
|
|
EXPECT_EQ(qux_, message_->field(3)); |
|
|
|
|
EXPECT_EQ(moo_, message_->field(3)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, FindFieldByName) { |
|
|
|
@ -898,28 +898,28 @@ TEST_F(DescriptorTest, FindFieldByName) { |
|
|
|
|
EXPECT_EQ(foo_, message_->FindFieldByName("foo")); |
|
|
|
|
EXPECT_EQ(bar_, message_->FindFieldByName("bar")); |
|
|
|
|
EXPECT_EQ(baz_, message_->FindFieldByName("baz")); |
|
|
|
|
EXPECT_EQ(qux_, message_->FindFieldByName("qux")); |
|
|
|
|
EXPECT_EQ(moo_, message_->FindFieldByName("moo")); |
|
|
|
|
EXPECT_TRUE(message_->FindFieldByName("no_such_field") == nullptr); |
|
|
|
|
EXPECT_TRUE(message_->FindFieldByName("quux") == nullptr); |
|
|
|
|
EXPECT_TRUE(message_->FindFieldByName("mooo") == nullptr); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ(foo2_, message2_->FindFieldByName("foo")); |
|
|
|
|
EXPECT_EQ(bar2_, message2_->FindFieldByName("bar")); |
|
|
|
|
EXPECT_EQ(quux2_, message2_->FindFieldByName("quux")); |
|
|
|
|
EXPECT_EQ(mooo2_, message2_->FindFieldByName("mooo")); |
|
|
|
|
EXPECT_TRUE(message2_->FindFieldByName("baz") == nullptr); |
|
|
|
|
EXPECT_TRUE(message2_->FindFieldByName("qux") == nullptr); |
|
|
|
|
EXPECT_TRUE(message2_->FindFieldByName("moo") == nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, FindFieldByNumber) { |
|
|
|
|
EXPECT_EQ(foo_, message_->FindFieldByNumber(1)); |
|
|
|
|
EXPECT_EQ(bar_, message_->FindFieldByNumber(6)); |
|
|
|
|
EXPECT_EQ(baz_, message_->FindFieldByNumber(500000000)); |
|
|
|
|
EXPECT_EQ(qux_, message_->FindFieldByNumber(15)); |
|
|
|
|
EXPECT_EQ(moo_, message_->FindFieldByNumber(15)); |
|
|
|
|
EXPECT_TRUE(message_->FindFieldByNumber(837592) == nullptr); |
|
|
|
|
EXPECT_TRUE(message_->FindFieldByNumber(2) == nullptr); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ(foo2_, message2_->FindFieldByNumber(1)); |
|
|
|
|
EXPECT_EQ(bar2_, message2_->FindFieldByNumber(2)); |
|
|
|
|
EXPECT_EQ(quux2_, message2_->FindFieldByNumber(6)); |
|
|
|
|
EXPECT_EQ(mooo2_, message2_->FindFieldByNumber(6)); |
|
|
|
|
EXPECT_TRUE(message2_->FindFieldByNumber(15) == nullptr); |
|
|
|
|
EXPECT_TRUE(message2_->FindFieldByNumber(500000000) == nullptr); |
|
|
|
|
} |
|
|
|
@ -928,32 +928,32 @@ TEST_F(DescriptorTest, FieldName) { |
|
|
|
|
EXPECT_EQ("foo", foo_->name()); |
|
|
|
|
EXPECT_EQ("bar", bar_->name()); |
|
|
|
|
EXPECT_EQ("baz", baz_->name()); |
|
|
|
|
EXPECT_EQ("qux", qux_->name()); |
|
|
|
|
EXPECT_EQ("moo", moo_->name()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, FieldFullName) { |
|
|
|
|
EXPECT_EQ("TestMessage.foo", foo_->full_name()); |
|
|
|
|
EXPECT_EQ("TestMessage.bar", bar_->full_name()); |
|
|
|
|
EXPECT_EQ("TestMessage.baz", baz_->full_name()); |
|
|
|
|
EXPECT_EQ("TestMessage.qux", qux_->full_name()); |
|
|
|
|
EXPECT_EQ("TestMessage.moo", moo_->full_name()); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.foo", foo2_->full_name()); |
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.bar", bar2_->full_name()); |
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.quux", quux2_->full_name()); |
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.mooo", mooo2_->full_name()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, PrintableNameIsFullNameForNonExtensionFields) { |
|
|
|
|
EXPECT_EQ("TestMessage.foo", foo_->PrintableNameForExtension()); |
|
|
|
|
EXPECT_EQ("TestMessage.bar", bar_->PrintableNameForExtension()); |
|
|
|
|
EXPECT_EQ("TestMessage.baz", baz_->PrintableNameForExtension()); |
|
|
|
|
EXPECT_EQ("TestMessage.qux", qux_->PrintableNameForExtension()); |
|
|
|
|
EXPECT_EQ("TestMessage.moo", moo_->PrintableNameForExtension()); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.foo", |
|
|
|
|
foo2_->PrintableNameForExtension()); |
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.bar", |
|
|
|
|
bar2_->PrintableNameForExtension()); |
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.quux", |
|
|
|
|
quux2_->PrintableNameForExtension()); |
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.mooo", |
|
|
|
|
mooo2_->PrintableNameForExtension()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, PrintableNameIsFullNameForNonMessageSetExtension) { |
|
|
|
@ -1016,39 +1016,39 @@ TEST_F(DescriptorTest, FieldFile) { |
|
|
|
|
EXPECT_EQ(foo_file_, foo_->file()); |
|
|
|
|
EXPECT_EQ(foo_file_, bar_->file()); |
|
|
|
|
EXPECT_EQ(foo_file_, baz_->file()); |
|
|
|
|
EXPECT_EQ(foo_file_, qux_->file()); |
|
|
|
|
EXPECT_EQ(foo_file_, moo_->file()); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ(bar_file_, foo2_->file()); |
|
|
|
|
EXPECT_EQ(bar_file_, bar2_->file()); |
|
|
|
|
EXPECT_EQ(bar_file_, quux2_->file()); |
|
|
|
|
EXPECT_EQ(bar_file_, mooo2_->file()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, FieldIndex) { |
|
|
|
|
EXPECT_EQ(0, foo_->index()); |
|
|
|
|
EXPECT_EQ(1, bar_->index()); |
|
|
|
|
EXPECT_EQ(2, baz_->index()); |
|
|
|
|
EXPECT_EQ(3, qux_->index()); |
|
|
|
|
EXPECT_EQ(3, moo_->index()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, FieldNumber) { |
|
|
|
|
EXPECT_EQ(1, foo_->number()); |
|
|
|
|
EXPECT_EQ(6, bar_->number()); |
|
|
|
|
EXPECT_EQ(500000000, baz_->number()); |
|
|
|
|
EXPECT_EQ(15, qux_->number()); |
|
|
|
|
EXPECT_EQ(15, moo_->number()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, FieldType) { |
|
|
|
|
EXPECT_EQ(FieldDescriptor::TYPE_STRING, foo_->type()); |
|
|
|
|
EXPECT_EQ(FieldDescriptor::TYPE_ENUM, bar_->type()); |
|
|
|
|
EXPECT_EQ(FieldDescriptor::TYPE_MESSAGE, baz_->type()); |
|
|
|
|
EXPECT_EQ(FieldDescriptor::TYPE_GROUP, qux_->type()); |
|
|
|
|
EXPECT_EQ(FieldDescriptor::TYPE_GROUP, moo_->type()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, FieldLabel) { |
|
|
|
|
EXPECT_EQ(FieldDescriptor::LABEL_REQUIRED, foo_->label()); |
|
|
|
|
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, bar_->label()); |
|
|
|
|
EXPECT_EQ(FieldDescriptor::LABEL_REPEATED, baz_->label()); |
|
|
|
|
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, qux_->label()); |
|
|
|
|
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, moo_->label()); |
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(foo_->is_required()); |
|
|
|
|
EXPECT_FALSE(foo_->is_optional()); |
|
|
|
@ -1089,18 +1089,18 @@ TEST_F(DescriptorTest, FieldHasDefault) { |
|
|
|
|
EXPECT_FALSE(foo_->has_default_value()); |
|
|
|
|
EXPECT_FALSE(bar_->has_default_value()); |
|
|
|
|
EXPECT_FALSE(baz_->has_default_value()); |
|
|
|
|
EXPECT_FALSE(qux_->has_default_value()); |
|
|
|
|
EXPECT_FALSE(moo_->has_default_value()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, FieldContainingType) { |
|
|
|
|
EXPECT_EQ(message_, foo_->containing_type()); |
|
|
|
|
EXPECT_EQ(message_, bar_->containing_type()); |
|
|
|
|
EXPECT_EQ(message_, baz_->containing_type()); |
|
|
|
|
EXPECT_EQ(message_, qux_->containing_type()); |
|
|
|
|
EXPECT_EQ(message_, moo_->containing_type()); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ(message2_, foo2_->containing_type()); |
|
|
|
|
EXPECT_EQ(message2_, bar2_->containing_type()); |
|
|
|
|
EXPECT_EQ(message2_, quux2_->containing_type()); |
|
|
|
|
EXPECT_EQ(message2_, mooo2_->containing_type()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, FieldMessageType) { |
|
|
|
@ -1108,13 +1108,13 @@ TEST_F(DescriptorTest, FieldMessageType) { |
|
|
|
|
EXPECT_TRUE(bar_->message_type() == nullptr); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ(foreign_, baz_->message_type()); |
|
|
|
|
EXPECT_EQ(foreign_, qux_->message_type()); |
|
|
|
|
EXPECT_EQ(foreign_, moo_->message_type()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DescriptorTest, FieldEnumType) { |
|
|
|
|
EXPECT_TRUE(foo_->enum_type() == nullptr); |
|
|
|
|
EXPECT_TRUE(baz_->enum_type() == nullptr); |
|
|
|
|
EXPECT_TRUE(qux_->enum_type() == nullptr); |
|
|
|
|
EXPECT_TRUE(moo_->enum_type() == nullptr); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ(enum_, bar_->enum_type()); |
|
|
|
|
} |
|
|
|
@ -1708,7 +1708,7 @@ class NestedDescriptorTest : public testing::Test { |
|
|
|
|
// message Foo {}
|
|
|
|
|
// message Bar {}
|
|
|
|
|
// enum Baz { A = 1; }
|
|
|
|
|
// enum Qux { B = 1; }
|
|
|
|
|
// enum Moo { B = 1; }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // in "bar.proto"
|
|
|
|
@ -1716,8 +1716,8 @@ class NestedDescriptorTest : public testing::Test { |
|
|
|
|
// message TestMessage2 {
|
|
|
|
|
// message Foo {}
|
|
|
|
|
// message Baz {}
|
|
|
|
|
// enum Qux { A = 1; }
|
|
|
|
|
// enum Quux { C = 1; }
|
|
|
|
|
// enum Moo { A = 1; }
|
|
|
|
|
// enum Mooo { C = 1; }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// TestMessage2 is primarily here to test FindNestedTypeByName and friends.
|
|
|
|
@ -1735,8 +1735,8 @@ class NestedDescriptorTest : public testing::Test { |
|
|
|
|
AddNestedMessage(message, "Bar"); |
|
|
|
|
EnumDescriptorProto* baz = AddNestedEnum(message, "Baz"); |
|
|
|
|
AddEnumValue(baz, "A", 1); |
|
|
|
|
EnumDescriptorProto* qux = AddNestedEnum(message, "Qux"); |
|
|
|
|
AddEnumValue(qux, "B", 1); |
|
|
|
|
EnumDescriptorProto* moo = AddNestedEnum(message, "Moo"); |
|
|
|
|
AddEnumValue(moo, "B", 1); |
|
|
|
|
|
|
|
|
|
FileDescriptorProto bar_file; |
|
|
|
|
bar_file.set_name("bar.proto"); |
|
|
|
@ -1745,10 +1745,10 @@ class NestedDescriptorTest : public testing::Test { |
|
|
|
|
DescriptorProto* message2 = AddMessage(&bar_file, "TestMessage2"); |
|
|
|
|
AddNestedMessage(message2, "Foo"); |
|
|
|
|
AddNestedMessage(message2, "Baz"); |
|
|
|
|
EnumDescriptorProto* qux2 = AddNestedEnum(message2, "Qux"); |
|
|
|
|
AddEnumValue(qux2, "A", 1); |
|
|
|
|
EnumDescriptorProto* quux2 = AddNestedEnum(message2, "Quux"); |
|
|
|
|
AddEnumValue(quux2, "C", 1); |
|
|
|
|
EnumDescriptorProto* moo2 = AddNestedEnum(message2, "Moo"); |
|
|
|
|
AddEnumValue(moo2, "A", 1); |
|
|
|
|
EnumDescriptorProto* mooo2 = AddNestedEnum(message2, "Mooo"); |
|
|
|
|
AddEnumValue(mooo2, "C", 1); |
|
|
|
|
|
|
|
|
|
// Build the descriptors and get the pointers.
|
|
|
|
|
foo_file_ = pool_.BuildFile(foo_file); |
|
|
|
@ -1766,12 +1766,12 @@ class NestedDescriptorTest : public testing::Test { |
|
|
|
|
|
|
|
|
|
ASSERT_EQ(2, message_->enum_type_count()); |
|
|
|
|
baz_ = message_->enum_type(0); |
|
|
|
|
qux_ = message_->enum_type(1); |
|
|
|
|
moo_ = message_->enum_type(1); |
|
|
|
|
|
|
|
|
|
ASSERT_EQ(1, baz_->value_count()); |
|
|
|
|
a_ = baz_->value(0); |
|
|
|
|
ASSERT_EQ(1, qux_->value_count()); |
|
|
|
|
b_ = qux_->value(0); |
|
|
|
|
ASSERT_EQ(1, moo_->value_count()); |
|
|
|
|
b_ = moo_->value(0); |
|
|
|
|
|
|
|
|
|
ASSERT_EQ(1, bar_file_->message_type_count()); |
|
|
|
|
message2_ = bar_file_->message_type(0); |
|
|
|
@ -1781,13 +1781,13 @@ class NestedDescriptorTest : public testing::Test { |
|
|
|
|
baz2_ = message2_->nested_type(1); |
|
|
|
|
|
|
|
|
|
ASSERT_EQ(2, message2_->enum_type_count()); |
|
|
|
|
qux2_ = message2_->enum_type(0); |
|
|
|
|
quux2_ = message2_->enum_type(1); |
|
|
|
|
moo2_ = message2_->enum_type(0); |
|
|
|
|
mooo2_ = message2_->enum_type(1); |
|
|
|
|
|
|
|
|
|
ASSERT_EQ(1, qux2_->value_count()); |
|
|
|
|
a2_ = qux2_->value(0); |
|
|
|
|
ASSERT_EQ(1, quux2_->value_count()); |
|
|
|
|
c2_ = quux2_->value(0); |
|
|
|
|
ASSERT_EQ(1, moo2_->value_count()); |
|
|
|
|
a2_ = moo2_->value(0); |
|
|
|
|
ASSERT_EQ(1, mooo2_->value_count()); |
|
|
|
|
c2_ = mooo2_->value(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DescriptorPool pool_; |
|
|
|
@ -1801,14 +1801,14 @@ class NestedDescriptorTest : public testing::Test { |
|
|
|
|
const Descriptor* foo_; |
|
|
|
|
const Descriptor* bar_; |
|
|
|
|
const EnumDescriptor* baz_; |
|
|
|
|
const EnumDescriptor* qux_; |
|
|
|
|
const EnumDescriptor* moo_; |
|
|
|
|
const EnumValueDescriptor* a_; |
|
|
|
|
const EnumValueDescriptor* b_; |
|
|
|
|
|
|
|
|
|
const Descriptor* foo2_; |
|
|
|
|
const Descriptor* baz2_; |
|
|
|
|
const EnumDescriptor* qux2_; |
|
|
|
|
const EnumDescriptor* quux2_; |
|
|
|
|
const EnumDescriptor* moo2_; |
|
|
|
|
const EnumDescriptor* mooo2_; |
|
|
|
|
const EnumValueDescriptor* a2_; |
|
|
|
|
const EnumValueDescriptor* c2_; |
|
|
|
|
}; |
|
|
|
@ -1840,9 +1840,9 @@ TEST_F(NestedDescriptorTest, NestedMessagesByIndex) { |
|
|
|
|
|
|
|
|
|
TEST_F(NestedDescriptorTest, FindFieldByNameDoesntFindNestedTypes) { |
|
|
|
|
EXPECT_TRUE(message_->FindFieldByName("Foo") == nullptr); |
|
|
|
|
EXPECT_TRUE(message_->FindFieldByName("Qux") == nullptr); |
|
|
|
|
EXPECT_TRUE(message_->FindFieldByName("Moo") == nullptr); |
|
|
|
|
EXPECT_TRUE(message_->FindExtensionByName("Foo") == nullptr); |
|
|
|
|
EXPECT_TRUE(message_->FindExtensionByName("Qux") == nullptr); |
|
|
|
|
EXPECT_TRUE(message_->FindExtensionByName("Moo") == nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(NestedDescriptorTest, FindNestedTypeByName) { |
|
|
|
@ -1855,26 +1855,26 @@ TEST_F(NestedDescriptorTest, FindNestedTypeByName) { |
|
|
|
|
EXPECT_TRUE(message_->FindNestedTypeByName("Baz") == nullptr); |
|
|
|
|
EXPECT_TRUE(message2_->FindNestedTypeByName("Bar") == nullptr); |
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(message_->FindNestedTypeByName("Qux") == nullptr); |
|
|
|
|
EXPECT_TRUE(message_->FindNestedTypeByName("Moo") == nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(NestedDescriptorTest, EnumName) { |
|
|
|
|
EXPECT_EQ("Baz", baz_->name()); |
|
|
|
|
EXPECT_EQ("Qux", qux_->name()); |
|
|
|
|
EXPECT_EQ("Qux", qux2_->name()); |
|
|
|
|
EXPECT_EQ("Quux", quux2_->name()); |
|
|
|
|
EXPECT_EQ("Moo", moo_->name()); |
|
|
|
|
EXPECT_EQ("Moo", moo2_->name()); |
|
|
|
|
EXPECT_EQ("Mooo", mooo2_->name()); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ("TestMessage.Baz", baz_->full_name()); |
|
|
|
|
EXPECT_EQ("TestMessage.Qux", qux_->full_name()); |
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.Qux", qux2_->full_name()); |
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.Quux", quux2_->full_name()); |
|
|
|
|
EXPECT_EQ("TestMessage.Moo", moo_->full_name()); |
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.Moo", moo2_->full_name()); |
|
|
|
|
EXPECT_EQ("corge.grault.TestMessage2.Mooo", mooo2_->full_name()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(NestedDescriptorTest, EnumContainingType) { |
|
|
|
|
EXPECT_EQ(message_, baz_->containing_type()); |
|
|
|
|
EXPECT_EQ(message_, qux_->containing_type()); |
|
|
|
|
EXPECT_EQ(message2_, qux2_->containing_type()); |
|
|
|
|
EXPECT_EQ(message2_, quux2_->containing_type()); |
|
|
|
|
EXPECT_EQ(message_, moo_->containing_type()); |
|
|
|
|
EXPECT_EQ(message2_, moo2_->containing_type()); |
|
|
|
|
EXPECT_EQ(message2_, mooo2_->containing_type()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(NestedDescriptorTest, NestedEnumsByIndex) { |
|
|
|
@ -1885,12 +1885,12 @@ TEST_F(NestedDescriptorTest, NestedEnumsByIndex) { |
|
|
|
|
|
|
|
|
|
TEST_F(NestedDescriptorTest, FindEnumTypeByName) { |
|
|
|
|
EXPECT_EQ(baz_, message_->FindEnumTypeByName("Baz")); |
|
|
|
|
EXPECT_EQ(qux_, message_->FindEnumTypeByName("Qux")); |
|
|
|
|
EXPECT_EQ(qux2_, message2_->FindEnumTypeByName("Qux")); |
|
|
|
|
EXPECT_EQ(quux2_, message2_->FindEnumTypeByName("Quux")); |
|
|
|
|
EXPECT_EQ(moo_, message_->FindEnumTypeByName("Moo")); |
|
|
|
|
EXPECT_EQ(moo2_, message2_->FindEnumTypeByName("Moo")); |
|
|
|
|
EXPECT_EQ(mooo2_, message2_->FindEnumTypeByName("Mooo")); |
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(message_->FindEnumTypeByName("NoSuchType") == nullptr); |
|
|
|
|
EXPECT_TRUE(message_->FindEnumTypeByName("Quux") == nullptr); |
|
|
|
|
EXPECT_TRUE(message_->FindEnumTypeByName("Mooo") == nullptr); |
|
|
|
|
EXPECT_TRUE(message2_->FindEnumTypeByName("Baz") == nullptr); |
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(message_->FindEnumTypeByName("Foo") == nullptr); |
|
|
|
@ -1918,7 +1918,7 @@ class ExtensionDescriptorTest : public testing::Test { |
|
|
|
|
// Build descriptors for the following definitions:
|
|
|
|
|
//
|
|
|
|
|
// enum Baz {}
|
|
|
|
|
// message Qux {}
|
|
|
|
|
// message Moo {}
|
|
|
|
|
//
|
|
|
|
|
// message Foo {
|
|
|
|
|
// extensions 10 to 19;
|
|
|
|
@ -1933,8 +1933,8 @@ class ExtensionDescriptorTest : public testing::Test { |
|
|
|
|
// message Bar {
|
|
|
|
|
// optional int32 non_ext_int32 = 1;
|
|
|
|
|
// extend Foo {
|
|
|
|
|
// optional Qux foo_message = 30;
|
|
|
|
|
// repeated Qux foo_group = 39; // (but internally set to TYPE_GROUP)
|
|
|
|
|
// optional Moo foo_message = 30;
|
|
|
|
|
// repeated Moo foo_group = 39; // (but internally set to TYPE_GROUP)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
@ -1942,7 +1942,7 @@ class ExtensionDescriptorTest : public testing::Test { |
|
|
|
|
foo_file.set_name("foo.proto"); |
|
|
|
|
|
|
|
|
|
AddEmptyEnum(&foo_file, "Baz"); |
|
|
|
|
AddMessage(&foo_file, "Qux"); |
|
|
|
|
AddMessage(&foo_file, "Moo"); |
|
|
|
|
|
|
|
|
|
DescriptorProto* foo = AddMessage(&foo_file, "Foo"); |
|
|
|
|
AddExtensionRange(foo, 10, 20); |
|
|
|
@ -1962,11 +1962,11 @@ class ExtensionDescriptorTest : public testing::Test { |
|
|
|
|
AddNestedExtension(bar, "Foo", "foo_message", 30, |
|
|
|
|
FieldDescriptorProto::LABEL_OPTIONAL, |
|
|
|
|
FieldDescriptorProto::TYPE_MESSAGE) |
|
|
|
|
->set_type_name("Qux"); |
|
|
|
|
->set_type_name("Moo"); |
|
|
|
|
AddNestedExtension(bar, "Foo", "foo_group", 39, |
|
|
|
|
FieldDescriptorProto::LABEL_REPEATED, |
|
|
|
|
FieldDescriptorProto::TYPE_GROUP) |
|
|
|
|
->set_type_name("Qux"); |
|
|
|
|
->set_type_name("Moo"); |
|
|
|
|
|
|
|
|
|
// Build the descriptors and get the pointers.
|
|
|
|
|
foo_file_ = pool_.BuildFile(foo_file); |
|
|
|
@ -1976,7 +1976,7 @@ class ExtensionDescriptorTest : public testing::Test { |
|
|
|
|
baz_ = foo_file_->enum_type(0); |
|
|
|
|
|
|
|
|
|
ASSERT_EQ(3, foo_file_->message_type_count()); |
|
|
|
|
qux_ = foo_file_->message_type(0); |
|
|
|
|
moo_ = foo_file_->message_type(0); |
|
|
|
|
foo_ = foo_file_->message_type(1); |
|
|
|
|
bar_ = foo_file_->message_type(2); |
|
|
|
|
} |
|
|
|
@ -1988,7 +1988,7 @@ class ExtensionDescriptorTest : public testing::Test { |
|
|
|
|
const Descriptor* foo_; |
|
|
|
|
const Descriptor* bar_; |
|
|
|
|
const EnumDescriptor* baz_; |
|
|
|
|
const Descriptor* qux_; |
|
|
|
|
const Descriptor* moo_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
TEST_F(ExtensionDescriptorTest, ExtensionRanges) { |
|
|
|
@ -2028,8 +2028,8 @@ TEST_F(ExtensionDescriptorTest, Extensions) { |
|
|
|
|
EXPECT_EQ(FieldDescriptor::TYPE_GROUP, bar_->extension(1)->type()); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ(baz_, foo_file_->extension(1)->enum_type()); |
|
|
|
|
EXPECT_EQ(qux_, bar_->extension(0)->message_type()); |
|
|
|
|
EXPECT_EQ(qux_, bar_->extension(1)->message_type()); |
|
|
|
|
EXPECT_EQ(moo_, bar_->extension(0)->message_type()); |
|
|
|
|
EXPECT_EQ(moo_, bar_->extension(1)->message_type()); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, foo_file_->extension(0)->label()); |
|
|
|
|
EXPECT_EQ(FieldDescriptor::LABEL_REPEATED, foo_file_->extension(1)->label()); |
|
|
|
@ -2863,8 +2863,8 @@ class AllowUnknownDependenciesTest |
|
|
|
|
" name: 'Foo'" |
|
|
|
|
" field { name:'bar' number:1 label:LABEL_OPTIONAL type_name:'Bar' }" |
|
|
|
|
" field { name:'baz' number:2 label:LABEL_OPTIONAL type_name:'Baz' }" |
|
|
|
|
" field { name:'qux' number:3 label:LABEL_OPTIONAL" |
|
|
|
|
" type_name: '.corge.Qux'" |
|
|
|
|
" field { name:'moo' number:3 label:LABEL_OPTIONAL" |
|
|
|
|
" type_name: '.corge.Moo'" |
|
|
|
|
" type: TYPE_ENUM" |
|
|
|
|
" options {" |
|
|
|
|
" uninterpreted_option {" |
|
|
|
@ -2902,7 +2902,7 @@ class AllowUnknownDependenciesTest |
|
|
|
|
ASSERT_EQ(3, foo_type_->field_count()); |
|
|
|
|
bar_field_ = foo_type_->field(0); |
|
|
|
|
baz_field_ = foo_type_->field(1); |
|
|
|
|
qux_field_ = foo_type_->field(2); |
|
|
|
|
moo_field_ = foo_type_->field(2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FileDescriptor* BuildFile(const FileDescriptorProto& proto) { |
|
|
|
@ -2925,7 +2925,7 @@ class AllowUnknownDependenciesTest |
|
|
|
|
const Descriptor* foo_type_; |
|
|
|
|
const FieldDescriptor* bar_field_; |
|
|
|
|
const FieldDescriptor* baz_field_; |
|
|
|
|
const FieldDescriptor* qux_field_; |
|
|
|
|
const FieldDescriptor* moo_field_; |
|
|
|
|
|
|
|
|
|
SimpleDescriptorDatabase db_; // used if in FALLBACK_DATABASE mode.
|
|
|
|
|
std::unique_ptr<DescriptorPool> pool_; |
|
|
|
@ -2964,18 +2964,18 @@ TEST_P(AllowUnknownDependenciesTest, PlaceholderTypes) { |
|
|
|
|
EXPECT_EQ(0, baz_type->extension_range_count()); |
|
|
|
|
EXPECT_TRUE(baz_type->is_placeholder()); |
|
|
|
|
|
|
|
|
|
ASSERT_EQ(FieldDescriptor::TYPE_ENUM, qux_field_->type()); |
|
|
|
|
const EnumDescriptor* qux_type = qux_field_->enum_type(); |
|
|
|
|
EXPECT_EQ("Qux", qux_type->name()); |
|
|
|
|
EXPECT_EQ("corge.Qux", qux_type->full_name()); |
|
|
|
|
EXPECT_TRUE(qux_type->is_placeholder()); |
|
|
|
|
ASSERT_EQ(FieldDescriptor::TYPE_ENUM, moo_field_->type()); |
|
|
|
|
const EnumDescriptor* moo_type = moo_field_->enum_type(); |
|
|
|
|
EXPECT_EQ("Moo", moo_type->name()); |
|
|
|
|
EXPECT_EQ("corge.Moo", moo_type->full_name()); |
|
|
|
|
EXPECT_TRUE(moo_type->is_placeholder()); |
|
|
|
|
// Placeholder enum values should not be findable.
|
|
|
|
|
EXPECT_EQ(qux_type->FindValueByNumber(0), nullptr); |
|
|
|
|
EXPECT_EQ(moo_type->FindValueByNumber(0), nullptr); |
|
|
|
|
|
|
|
|
|
// Placeholder types should not be findable.
|
|
|
|
|
EXPECT_EQ(bar_type_, pool_->FindMessageTypeByName(bar_type_->full_name())); |
|
|
|
|
EXPECT_TRUE(pool_->FindMessageTypeByName(baz_type->full_name()) == nullptr); |
|
|
|
|
EXPECT_TRUE(pool_->FindEnumTypeByName(qux_type->full_name()) == nullptr); |
|
|
|
|
EXPECT_TRUE(pool_->FindEnumTypeByName(moo_type->full_name()) == nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_P(AllowUnknownDependenciesTest, CopyTo) { |
|
|
|
@ -2994,18 +2994,18 @@ TEST_P(AllowUnknownDependenciesTest, CopyTo) { |
|
|
|
|
EXPECT_EQ("Baz", proto.type_name()); |
|
|
|
|
EXPECT_FALSE(proto.has_type()); |
|
|
|
|
|
|
|
|
|
// Qux is a fully-qualified placeholder.
|
|
|
|
|
// Moo is a fully-qualified placeholder.
|
|
|
|
|
proto.Clear(); |
|
|
|
|
qux_field_->CopyTo(&proto); |
|
|
|
|
EXPECT_EQ(".corge.Qux", proto.type_name()); |
|
|
|
|
moo_field_->CopyTo(&proto); |
|
|
|
|
EXPECT_EQ(".corge.Moo", proto.type_name()); |
|
|
|
|
EXPECT_EQ(FieldDescriptorProto::TYPE_ENUM, proto.type()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_P(AllowUnknownDependenciesTest, CustomOptions) { |
|
|
|
|
// Qux should still have the uninterpreted option attached.
|
|
|
|
|
ASSERT_EQ(1, qux_field_->options().uninterpreted_option_size()); |
|
|
|
|
// Moo should still have the uninterpreted option attached.
|
|
|
|
|
ASSERT_EQ(1, moo_field_->options().uninterpreted_option_size()); |
|
|
|
|
const UninterpretedOption& option = |
|
|
|
|
qux_field_->options().uninterpreted_option(0); |
|
|
|
|
moo_field_->options().uninterpreted_option(0); |
|
|
|
|
ASSERT_EQ(1, option.name_size()); |
|
|
|
|
EXPECT_EQ("grault", option.name(0).name_part()); |
|
|
|
|
} |
|
|
|
@ -3103,12 +3103,12 @@ TEST_P(AllowUnknownDependenciesTest, |
|
|
|
|
"name: \"invalid_file_as_undeclared_dep.proto\" " |
|
|
|
|
"package: \"undeclared\" " |
|
|
|
|
"message_type: { " |
|
|
|
|
" name: \"Quux\" " |
|
|
|
|
" name: \"Mooo\" " |
|
|
|
|
" field { " |
|
|
|
|
" name:'qux' number:1 label:LABEL_OPTIONAL type: TYPE_INT32 " |
|
|
|
|
" name:'moo' number:1 label:LABEL_OPTIONAL type: TYPE_INT32 " |
|
|
|
|
" }" |
|
|
|
|
" field { " |
|
|
|
|
" name:'quux' number:1 label:LABEL_OPTIONAL type: TYPE_INT64 " |
|
|
|
|
" name:'mooo' number:1 label:LABEL_OPTIONAL type: TYPE_INT64 " |
|
|
|
|
" }" |
|
|
|
|
"}", |
|
|
|
|
&undeclared_dep_proto)); |
|
|
|
@ -3132,8 +3132,8 @@ TEST_P(AllowUnknownDependenciesTest, |
|
|
|
|
"message_type: { " |
|
|
|
|
" name: \"Corge\" " |
|
|
|
|
" field { " |
|
|
|
|
" name:'quux' number:1 label: LABEL_OPTIONAL " |
|
|
|
|
" type_name:'undeclared.Quux' type: TYPE_MESSAGE " |
|
|
|
|
" name:'mooo' number:1 label: LABEL_OPTIONAL " |
|
|
|
|
" type_name:'undeclared.Mooo' type: TYPE_MESSAGE " |
|
|
|
|
" }" |
|
|
|
|
"}", |
|
|
|
|
&test_proto)); |
|
|
|
@ -3149,13 +3149,13 @@ TEST_P(AllowUnknownDependenciesTest, |
|
|
|
|
ASSERT_EQ(1, corge_desc->field_count()); |
|
|
|
|
EXPECT_FALSE(corge_desc->is_placeholder()); |
|
|
|
|
|
|
|
|
|
const FieldDescriptor* quux_field = corge_desc->field(0); |
|
|
|
|
ASSERT_EQ(FieldDescriptor::TYPE_MESSAGE, quux_field->type()); |
|
|
|
|
ASSERT_EQ("Quux", quux_field->message_type()->name()); |
|
|
|
|
ASSERT_EQ("undeclared.Quux", quux_field->message_type()->full_name()); |
|
|
|
|
EXPECT_TRUE(quux_field->message_type()->is_placeholder()); |
|
|
|
|
const FieldDescriptor* mooo_field = corge_desc->field(0); |
|
|
|
|
ASSERT_EQ(FieldDescriptor::TYPE_MESSAGE, mooo_field->type()); |
|
|
|
|
ASSERT_EQ("Mooo", mooo_field->message_type()->name()); |
|
|
|
|
ASSERT_EQ("undeclared.Mooo", mooo_field->message_type()->full_name()); |
|
|
|
|
EXPECT_TRUE(mooo_field->message_type()->is_placeholder()); |
|
|
|
|
// The place holder type should not be findable.
|
|
|
|
|
ASSERT_TRUE(pool_->FindMessageTypeByName("undeclared.Quux") == nullptr); |
|
|
|
|
ASSERT_TRUE(pool_->FindMessageTypeByName("undeclared.Mooo") == nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(DatabaseSource, AllowUnknownDependenciesTest, |
|
|
|
@ -3271,11 +3271,11 @@ TEST(CustomOptions, ComplexExtensionOptions) { |
|
|
|
|
&protobuf_unittest::VariousComplexOptions::descriptor()->options(); |
|
|
|
|
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt1).foo(), 42); |
|
|
|
|
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt1) |
|
|
|
|
.GetExtension(protobuf_unittest::quux), |
|
|
|
|
.GetExtension(protobuf_unittest::mooo), |
|
|
|
|
324); |
|
|
|
|
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt1) |
|
|
|
|
.GetExtension(protobuf_unittest::corge) |
|
|
|
|
.qux(), |
|
|
|
|
.moo(), |
|
|
|
|
876); |
|
|
|
|
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2).baz(), 987); |
|
|
|
|
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2) |
|
|
|
@ -3285,12 +3285,12 @@ TEST(CustomOptions, ComplexExtensionOptions) { |
|
|
|
|
743); |
|
|
|
|
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2) |
|
|
|
|
.bar() |
|
|
|
|
.GetExtension(protobuf_unittest::quux), |
|
|
|
|
.GetExtension(protobuf_unittest::mooo), |
|
|
|
|
1999); |
|
|
|
|
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2) |
|
|
|
|
.bar() |
|
|
|
|
.GetExtension(protobuf_unittest::corge) |
|
|
|
|
.qux(), |
|
|
|
|
.moo(), |
|
|
|
|
2008); |
|
|
|
|
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2) |
|
|
|
|
.GetExtension(protobuf_unittest::garply) |
|
|
|
@ -3298,12 +3298,12 @@ TEST(CustomOptions, ComplexExtensionOptions) { |
|
|
|
|
741); |
|
|
|
|
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2) |
|
|
|
|
.GetExtension(protobuf_unittest::garply) |
|
|
|
|
.GetExtension(protobuf_unittest::quux), |
|
|
|
|
.GetExtension(protobuf_unittest::mooo), |
|
|
|
|
1998); |
|
|
|
|
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2) |
|
|
|
|
.GetExtension(protobuf_unittest::garply) |
|
|
|
|
.GetExtension(protobuf_unittest::corge) |
|
|
|
|
.qux(), |
|
|
|
|
.moo(), |
|
|
|
|
2121); |
|
|
|
|
EXPECT_EQ(options |
|
|
|
|
->GetExtension(protobuf_unittest::ComplexOptionType2:: |
|
|
|
@ -3312,7 +3312,7 @@ TEST(CustomOptions, ComplexExtensionOptions) { |
|
|
|
|
1971); |
|
|
|
|
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2).fred().waldo(), |
|
|
|
|
321); |
|
|
|
|
EXPECT_EQ(9, options->GetExtension(protobuf_unittest::complex_opt3).qux()); |
|
|
|
|
EXPECT_EQ(9, options->GetExtension(protobuf_unittest::complex_opt3).moo()); |
|
|
|
|
EXPECT_EQ(22, options->GetExtension(protobuf_unittest::complex_opt3) |
|
|
|
|
.complexoptiontype5() |
|
|
|
|
.plugh()); |
|
|
|
@ -4114,7 +4114,7 @@ TEST_F(ValidationErrorTest, FieldInExtensionRange) { |
|
|
|
|
"}" |
|
|
|
|
" field { name: \"baz\" number: 19 label:LABEL_OPTIONAL type:TYPE_INT32 " |
|
|
|
|
"}" |
|
|
|
|
" field { name: \"qux\" number: 20 label:LABEL_OPTIONAL type:TYPE_INT32 " |
|
|
|
|
" field { name: \"moo\" number: 20 label:LABEL_OPTIONAL type:TYPE_INT32 " |
|
|
|
|
"}" |
|
|
|
|
" extension_range { start: 10 end: 20 }" |
|
|
|
|
"}", |
|
|
|
@ -4446,13 +4446,13 @@ TEST_F(ValidationErrorTest, InvalidDefaults) { |
|
|
|
|
" default_value: \"abc\" }" |
|
|
|
|
|
|
|
|
|
// Messages can't have defaults.
|
|
|
|
|
" field { name: \"qux\" number: 4 label: LABEL_OPTIONAL type: " |
|
|
|
|
" field { name: \"moo\" number: 4 label: LABEL_OPTIONAL type: " |
|
|
|
|
"TYPE_MESSAGE" |
|
|
|
|
" default_value: \"abc\" type_name: \"Foo\" }" |
|
|
|
|
|
|
|
|
|
// Same thing, but we don't know that this field has message type until
|
|
|
|
|
// we look up the type name.
|
|
|
|
|
" field { name: \"quux\" number: 5 label: LABEL_OPTIONAL" |
|
|
|
|
" field { name: \"mooo\" number: 5 label: LABEL_OPTIONAL" |
|
|
|
|
" default_value: \"abc\" type_name: \"Foo\" }" |
|
|
|
|
|
|
|
|
|
// Repeateds can't have defaults.
|
|
|
|
@ -4466,12 +4466,12 @@ TEST_F(ValidationErrorTest, InvalidDefaults) { |
|
|
|
|
"foo.proto: Foo.bar: DEFAULT_VALUE: Couldn't parse default value \"\".\n" |
|
|
|
|
"foo.proto: Foo.baz: DEFAULT_VALUE: Boolean default must be true or " |
|
|
|
|
"false.\n" |
|
|
|
|
"foo.proto: Foo.qux: DEFAULT_VALUE: Messages can't have default values.\n" |
|
|
|
|
"foo.proto: Foo.moo: DEFAULT_VALUE: Messages can't have default values.\n" |
|
|
|
|
"foo.proto: Foo.corge: DEFAULT_VALUE: Repeated fields can't have default " |
|
|
|
|
"values.\n" |
|
|
|
|
// This ends up being reported later because the error is detected at
|
|
|
|
|
// cross-linking time.
|
|
|
|
|
"foo.proto: Foo.quux: DEFAULT_VALUE: Messages can't have default " |
|
|
|
|
"foo.proto: Foo.mooo: DEFAULT_VALUE: Messages can't have default " |
|
|
|
|
"values.\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -4511,7 +4511,7 @@ TEST_F(ValidationErrorTest, ReservedFieldNumber) { |
|
|
|
|
"type:TYPE_INT32 }" |
|
|
|
|
" field {name:\"baz\" number: 19999 label:LABEL_OPTIONAL " |
|
|
|
|
"type:TYPE_INT32 }" |
|
|
|
|
" field {name:\"qux\" number: 20000 label:LABEL_OPTIONAL " |
|
|
|
|
" field {name:\"moo\" number: 20000 label:LABEL_OPTIONAL " |
|
|
|
|
"type:TYPE_INT32 }" |
|
|
|
|
"}", |
|
|
|
|
|
|
|
|
@ -5108,7 +5108,7 @@ TEST_F(ValidationErrorTest, PackageOriginallyDeclaredInTransitiveDependent) { |
|
|
|
|
// baz.proto:
|
|
|
|
|
// package foo;
|
|
|
|
|
// import "bar.proto"
|
|
|
|
|
// message Baz { optional bar.Bar qux = 1; }
|
|
|
|
|
// message Baz { optional bar.Bar moo = 1; }
|
|
|
|
|
//
|
|
|
|
|
// When validating baz.proto, we will look up "bar.Bar". As part of this
|
|
|
|
|
// lookup, we first lookup "bar" then try to find "Bar" within it. "bar"
|
|
|
|
@ -5132,7 +5132,7 @@ TEST_F(ValidationErrorTest, PackageOriginallyDeclaredInTransitiveDependent) { |
|
|
|
|
"dependency: \"bar.proto\" " |
|
|
|
|
"message_type { " |
|
|
|
|
" name: \"Baz\" " |
|
|
|
|
" field { name:\"qux\" number:1 label:LABEL_OPTIONAL " |
|
|
|
|
" field { name:\"moo\" number:1 label:LABEL_OPTIONAL " |
|
|
|
|
" type_name:\"bar.Bar\" }" |
|
|
|
|
"}"); |
|
|
|
|
} |
|
|
|
@ -5472,12 +5472,12 @@ TEST_F(ValidationErrorTest, ResolveUndefinedOption) { |
|
|
|
|
// message Bar { optional int32 foo = 1; }
|
|
|
|
|
// extend FileOptions { optional Bar bar = 7672757; }
|
|
|
|
|
//
|
|
|
|
|
// qux.proto:
|
|
|
|
|
// package qux.baz
|
|
|
|
|
// moo.proto:
|
|
|
|
|
// package moo.baz
|
|
|
|
|
// option (baz.bar).foo = 1;
|
|
|
|
|
//
|
|
|
|
|
// Although "baz.bar" is already defined, the lookup code will try
|
|
|
|
|
// "qux.baz.bar", since it's the match from the innermost scope, which will
|
|
|
|
|
// "moo.baz.bar", since it's the match from the innermost scope, which will
|
|
|
|
|
// cause a symbol not defined error.
|
|
|
|
|
BuildDescriptorMessagesInTestPool(); |
|
|
|
|
|
|
|
|
@ -5493,16 +5493,16 @@ TEST_F(ValidationErrorTest, ResolveUndefinedOption) { |
|
|
|
|
" extendee: \"google.protobuf.FileOptions\" }"); |
|
|
|
|
|
|
|
|
|
BuildFileWithErrors( |
|
|
|
|
"name: \"qux.proto\" " |
|
|
|
|
"package: \"qux.baz\" " |
|
|
|
|
"name: \"moo.proto\" " |
|
|
|
|
"package: \"moo.baz\" " |
|
|
|
|
"options { uninterpreted_option { name { name_part: \"baz.bar\" " |
|
|
|
|
" is_extension: true } " |
|
|
|
|
" name { name_part: \"foo\" " |
|
|
|
|
" is_extension: false } " |
|
|
|
|
" positive_int_value: 1 } }", |
|
|
|
|
|
|
|
|
|
"qux.proto: qux.proto: OPTION_NAME: Option \"(baz.bar)\" is resolved to " |
|
|
|
|
"\"(qux.baz.bar)\"," |
|
|
|
|
"moo.proto: moo.proto: OPTION_NAME: Option \"(baz.bar)\" is resolved to " |
|
|
|
|
"\"(moo.baz.bar)\"," |
|
|
|
|
" which is not defined. The innermost scope is searched first in name " |
|
|
|
|
"resolution. Consider using a leading '.'(i.e., \"(.baz.bar)\") to start " |
|
|
|
|
"from the outermost scope.\n"); |
|
|
|
@ -5510,15 +5510,15 @@ TEST_F(ValidationErrorTest, ResolveUndefinedOption) { |
|
|
|
|
|
|
|
|
|
TEST_F(ValidationErrorTest, UnknownOption) { |
|
|
|
|
BuildFileWithErrors( |
|
|
|
|
"name: \"qux.proto\" " |
|
|
|
|
"package: \"qux.baz\" " |
|
|
|
|
"name: \"moo.proto\" " |
|
|
|
|
"package: \"moo.baz\" " |
|
|
|
|
"options { uninterpreted_option { name { name_part: \"baaz.bar\" " |
|
|
|
|
" is_extension: true } " |
|
|
|
|
" name { name_part: \"foo\" " |
|
|
|
|
" is_extension: false } " |
|
|
|
|
" positive_int_value: 1 } }", |
|
|
|
|
|
|
|
|
|
"qux.proto: qux.proto: OPTION_NAME: Option \"(baaz.bar)\" unknown. " |
|
|
|
|
"moo.proto: moo.proto: OPTION_NAME: Option \"(baaz.bar)\" unknown. " |
|
|
|
|
"Ensure " |
|
|
|
|
"that your proto definition file imports the proto which defines the " |
|
|
|
|
"option.\n"); |
|
|
|
@ -5732,7 +5732,7 @@ TEST_F(ValidationErrorTest, EnumOptionValueIsNotIdentifier) { |
|
|
|
|
" extendee: \"google.protobuf.FileOptions\" }" |
|
|
|
|
"options { uninterpreted_option { name { name_part: \"foo\" " |
|
|
|
|
" is_extension: true } " |
|
|
|
|
" string_value: \"QUUX\" } }", |
|
|
|
|
" string_value: \"MOOO\" } }", |
|
|
|
|
|
|
|
|
|
"foo.proto: foo.proto: OPTION_VALUE: Value must be identifier for " |
|
|
|
|
"enum-valued option \"foo\".\n"); |
|
|
|
@ -5751,10 +5751,10 @@ TEST_F(ValidationErrorTest, EnumOptionValueIsNotEnumValueName) { |
|
|
|
|
" extendee: \"google.protobuf.FileOptions\" }" |
|
|
|
|
"options { uninterpreted_option { name { name_part: \"foo\" " |
|
|
|
|
" is_extension: true } " |
|
|
|
|
" identifier_value: \"QUUX\" } }", |
|
|
|
|
" identifier_value: \"MOOO\" } }", |
|
|
|
|
|
|
|
|
|
"foo.proto: foo.proto: OPTION_VALUE: Enum type \"FooEnum\" has no value " |
|
|
|
|
"named \"QUUX\" for option \"foo\".\n"); |
|
|
|
|
"named \"MOOO\" for option \"foo\".\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(ValidationErrorTest, EnumOptionValueIsSiblingEnumValueName) { |
|
|
|
@ -5765,17 +5765,17 @@ TEST_F(ValidationErrorTest, EnumOptionValueIsSiblingEnumValueName) { |
|
|
|
|
"dependency: \"google/protobuf/descriptor.proto\" " |
|
|
|
|
"enum_type { name: \"FooEnum1\" value { name: \"BAR\" number: 1 } " |
|
|
|
|
" value { name: \"BAZ\" number: 2 } }" |
|
|
|
|
"enum_type { name: \"FooEnum2\" value { name: \"QUX\" number: 1 } " |
|
|
|
|
" value { name: \"QUUX\" number: 2 } }" |
|
|
|
|
"enum_type { name: \"FooEnum2\" value { name: \"MOO\" number: 1 } " |
|
|
|
|
" value { name: \"MOOO\" number: 2 } }" |
|
|
|
|
"extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL " |
|
|
|
|
" type: TYPE_ENUM type_name: \"FooEnum1\" " |
|
|
|
|
" extendee: \"google.protobuf.FileOptions\" }" |
|
|
|
|
"options { uninterpreted_option { name { name_part: \"foo\" " |
|
|
|
|
" is_extension: true } " |
|
|
|
|
" identifier_value: \"QUUX\" } }", |
|
|
|
|
" identifier_value: \"MOOO\" } }", |
|
|
|
|
|
|
|
|
|
"foo.proto: foo.proto: OPTION_VALUE: Enum type \"FooEnum1\" has no value " |
|
|
|
|
"named \"QUUX\" for option \"foo\". This appears to be a value from a " |
|
|
|
|
"named \"MOOO\" for option \"foo\". This appears to be a value from a " |
|
|
|
|
"sibling type.\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -5789,7 +5789,7 @@ TEST_F(ValidationErrorTest, StringOptionValueIsNotString) { |
|
|
|
|
" type: TYPE_STRING extendee: \"google.protobuf.FileOptions\" }" |
|
|
|
|
"options { uninterpreted_option { name { name_part: \"foo\" " |
|
|
|
|
" is_extension: true } " |
|
|
|
|
" identifier_value: \"QUUX\" } }", |
|
|
|
|
" identifier_value: \"MOOO\" } }", |
|
|
|
|
|
|
|
|
|
"foo.proto: foo.proto: OPTION_VALUE: Value must be quoted string " |
|
|
|
|
"for " |
|
|
|
@ -6731,16 +6731,64 @@ TEST_F(ValidationErrorTest, ValidateProto3Extension) { |
|
|
|
|
ASSERT_TRUE(pool.BuildFile(file_proto) != nullptr); |
|
|
|
|
// Add "foo.proto":
|
|
|
|
|
// import "google/protobuf/descriptor.proto";
|
|
|
|
|
// extend google.protobuf.FileOptions {
|
|
|
|
|
// optional string test_file_opt = 1001;
|
|
|
|
|
// }
|
|
|
|
|
// extend google.protobuf.MessageOptions {
|
|
|
|
|
// optional string test_msg_opt = 1002;
|
|
|
|
|
// }
|
|
|
|
|
// extend google.protobuf.FieldOptions {
|
|
|
|
|
// optional int32 option1 = 1000;
|
|
|
|
|
// optional string test_field_opt = 1003;
|
|
|
|
|
// }
|
|
|
|
|
// extend google.protobuf.EnumOptions {
|
|
|
|
|
// repeated int32 test_enum_opt = 1004;
|
|
|
|
|
// }
|
|
|
|
|
// extend google.protobuf.EnumValueOptions {
|
|
|
|
|
// optional int32 test_enumval_opt = 1005;
|
|
|
|
|
// }
|
|
|
|
|
// extend google.protobuf.ServiceOptions {
|
|
|
|
|
// repeated int32 test_svc_opt = 1006;
|
|
|
|
|
// }
|
|
|
|
|
// extend google.protobuf.MethodOptions {
|
|
|
|
|
// optional string test_method_opt = 1007;
|
|
|
|
|
// }
|
|
|
|
|
// extend google.protobuf.OneofOptions {
|
|
|
|
|
// optional string test_oneof_opt = 1008;
|
|
|
|
|
// }
|
|
|
|
|
// extend google.protobuf.ExtensionRangeOptions {
|
|
|
|
|
// optional string test_ext_opt = 1009;
|
|
|
|
|
// }
|
|
|
|
|
file_proto.Clear(); |
|
|
|
|
file_proto.set_name("foo.proto"); |
|
|
|
|
file_proto.set_syntax("proto3"); |
|
|
|
|
file_proto.add_dependency("google/protobuf/descriptor.proto"); |
|
|
|
|
AddExtension(&file_proto, "google.protobuf.FieldOptions", "option1", 1000, |
|
|
|
|
AddExtension(&file_proto, "google.protobuf.FileOptions", "test_file_opt", 1001, |
|
|
|
|
FieldDescriptorProto::LABEL_OPTIONAL, |
|
|
|
|
FieldDescriptorProto::TYPE_STRING); |
|
|
|
|
AddExtension(&file_proto, "google.protobuf.MessageOptions", "test_msg_opt", 1001, |
|
|
|
|
FieldDescriptorProto::LABEL_OPTIONAL, |
|
|
|
|
FieldDescriptorProto::TYPE_STRING); |
|
|
|
|
AddExtension(&file_proto, "google.protobuf.FieldOptions", "test_field_opt", 1003, |
|
|
|
|
FieldDescriptorProto::LABEL_OPTIONAL, |
|
|
|
|
FieldDescriptorProto::TYPE_STRING); |
|
|
|
|
AddExtension(&file_proto, "google.protobuf.EnumOptions", "test_enum_opt", 1004, |
|
|
|
|
FieldDescriptorProto::LABEL_REPEATED, |
|
|
|
|
FieldDescriptorProto::TYPE_INT32); |
|
|
|
|
AddExtension(&file_proto, "google.protobuf.EnumValueOptions", "test_enumval_opt", 1005, |
|
|
|
|
FieldDescriptorProto::LABEL_OPTIONAL, |
|
|
|
|
FieldDescriptorProto::TYPE_INT32); |
|
|
|
|
AddExtension(&file_proto, "google.protobuf.ServiceOptions", "test_svc_opt", 1006, |
|
|
|
|
FieldDescriptorProto::LABEL_REPEATED, |
|
|
|
|
FieldDescriptorProto::TYPE_INT32); |
|
|
|
|
AddExtension(&file_proto, "google.protobuf.MethodOptions", "test_method_opt", 1007, |
|
|
|
|
FieldDescriptorProto::LABEL_OPTIONAL, |
|
|
|
|
FieldDescriptorProto::TYPE_STRING); |
|
|
|
|
AddExtension(&file_proto, "google.protobuf.OneofOptions", "test_oneof_opt", 1008, |
|
|
|
|
FieldDescriptorProto::LABEL_OPTIONAL, |
|
|
|
|
FieldDescriptorProto::TYPE_STRING); |
|
|
|
|
AddExtension(&file_proto, "google.protobuf.ExtensionRangeOptions", "test_ext_opt", |
|
|
|
|
1009, FieldDescriptorProto::LABEL_OPTIONAL, |
|
|
|
|
FieldDescriptorProto::TYPE_STRING); |
|
|
|
|
ASSERT_TRUE(pool.BuildFile(file_proto) != nullptr); |
|
|
|
|
|
|
|
|
|
// Copy and change the package of the descriptor.proto
|
|
|
|
|