43 #include <google/protobuf/unittest.pb.h>
44 #include <google/protobuf/unittest_custom_options.pb.h>
45 #include <google/protobuf/unittest_lazy_dependencies.pb.h>
46 #include <google/protobuf/unittest_proto3_arena.pb.h>
65 #include <google/protobuf/port_def.inc>
71 namespace descriptor_unittest {
209 const char* location_name =
nullptr;
212 location_name =
"NAME";
215 location_name =
"NUMBER";
218 location_name =
"TYPE";
221 location_name =
"EXTENDEE";
224 location_name =
"DEFAULT_VALUE";
227 location_name =
"OPTION_NAME";
230 location_name =
"OPTION_VALUE";
233 location_name =
"INPUT_TYPE";
236 location_name =
"OUTPUT_TYPE";
239 location_name =
"IMPORT";
242 location_name =
"OTHER";
254 const char* location_name =
nullptr;
257 location_name =
"NAME";
260 location_name =
"NUMBER";
263 location_name =
"TYPE";
266 location_name =
"EXTENDEE";
269 location_name =
"DEFAULT_VALUE";
272 location_name =
"OPTION_NAME";
275 location_name =
"OPTION_VALUE";
278 location_name =
"INPUT_TYPE";
281 location_name =
"OUTPUT_TYPE";
284 location_name =
"IMPORT";
287 location_name =
"OTHER";
326 AddExtension(&foo_file,
"FooMessage",
"foo_extension", 1,
337 AddExtension(&bar_file,
"bar_package.BarMessage",
"bar_extension", 1,
397 EXPECT_EQ(
"foo.proto", foo_file_->name());
398 EXPECT_EQ(
"bar.proto", bar_file_->name());
399 EXPECT_EQ(
"baz.proto", baz_file_->name());
404 EXPECT_EQ(
"bar_package", bar_file_->package());
408 EXPECT_EQ(0, foo_file_->dependency_count());
409 EXPECT_EQ(1, bar_file_->dependency_count());
410 EXPECT_EQ(foo_file_, bar_file_->dependency(0));
414 EXPECT_EQ(foo_message_, foo_file_->FindMessageTypeByName(
"FooMessage"));
415 EXPECT_EQ(bar_message_, bar_file_->FindMessageTypeByName(
"BarMessage"));
417 EXPECT_TRUE(foo_file_->FindMessageTypeByName(
"BarMessage") ==
nullptr);
418 EXPECT_TRUE(bar_file_->FindMessageTypeByName(
"FooMessage") ==
nullptr);
419 EXPECT_TRUE(baz_file_->FindMessageTypeByName(
"FooMessage") ==
nullptr);
421 EXPECT_TRUE(foo_file_->FindMessageTypeByName(
"NoSuchMessage") ==
nullptr);
422 EXPECT_TRUE(foo_file_->FindMessageTypeByName(
"FooEnum") ==
nullptr);
426 EXPECT_EQ(foo_enum_, foo_file_->FindEnumTypeByName(
"FooEnum"));
427 EXPECT_EQ(bar_enum_, bar_file_->FindEnumTypeByName(
"BarEnum"));
429 EXPECT_TRUE(foo_file_->FindEnumTypeByName(
"BarEnum") ==
nullptr);
430 EXPECT_TRUE(bar_file_->FindEnumTypeByName(
"FooEnum") ==
nullptr);
431 EXPECT_TRUE(baz_file_->FindEnumTypeByName(
"FooEnum") ==
nullptr);
433 EXPECT_TRUE(foo_file_->FindEnumTypeByName(
"NoSuchEnum") ==
nullptr);
434 EXPECT_TRUE(foo_file_->FindEnumTypeByName(
"FooMessage") ==
nullptr);
438 EXPECT_EQ(foo_enum_value_, foo_file_->FindEnumValueByName(
"FOO_ENUM_VALUE"));
439 EXPECT_EQ(bar_enum_value_, bar_file_->FindEnumValueByName(
"BAR_ENUM_VALUE"));
441 EXPECT_TRUE(foo_file_->FindEnumValueByName(
"BAR_ENUM_VALUE") ==
nullptr);
442 EXPECT_TRUE(bar_file_->FindEnumValueByName(
"FOO_ENUM_VALUE") ==
nullptr);
443 EXPECT_TRUE(baz_file_->FindEnumValueByName(
"FOO_ENUM_VALUE") ==
nullptr);
445 EXPECT_TRUE(foo_file_->FindEnumValueByName(
"NO_SUCH_VALUE") ==
nullptr);
446 EXPECT_TRUE(foo_file_->FindEnumValueByName(
"FooMessage") ==
nullptr);
450 EXPECT_EQ(foo_service_, foo_file_->FindServiceByName(
"FooService"));
451 EXPECT_EQ(bar_service_, bar_file_->FindServiceByName(
"BarService"));
453 EXPECT_TRUE(foo_file_->FindServiceByName(
"BarService") ==
nullptr);
454 EXPECT_TRUE(bar_file_->FindServiceByName(
"FooService") ==
nullptr);
455 EXPECT_TRUE(baz_file_->FindServiceByName(
"FooService") ==
nullptr);
457 EXPECT_TRUE(foo_file_->FindServiceByName(
"NoSuchService") ==
nullptr);
458 EXPECT_TRUE(foo_file_->FindServiceByName(
"FooMessage") ==
nullptr);
462 EXPECT_EQ(foo_extension_, foo_file_->FindExtensionByName(
"foo_extension"));
463 EXPECT_EQ(bar_extension_, bar_file_->FindExtensionByName(
"bar_extension"));
465 EXPECT_TRUE(foo_file_->FindExtensionByName(
"bar_extension") ==
nullptr);
466 EXPECT_TRUE(bar_file_->FindExtensionByName(
"foo_extension") ==
nullptr);
467 EXPECT_TRUE(baz_file_->FindExtensionByName(
"foo_extension") ==
nullptr);
469 EXPECT_TRUE(foo_file_->FindExtensionByName(
"no_such_extension") ==
nullptr);
470 EXPECT_TRUE(foo_file_->FindExtensionByName(
"FooMessage") ==
nullptr);
474 EXPECT_EQ(foo_extension_,
pool_.FindExtensionByNumber(foo_message_, 1));
475 EXPECT_EQ(bar_extension_,
pool_.FindExtensionByNumber(bar_message_, 1));
485 foo_file_->CopyTo(&file);
497 proto_syntax2.
set_name(
"foo_syntax2");
505 implicit_proto2.
set_name(
"foo_implicit_syntax2");
508 pool_.BuildFile(implicit_proto2);
509 EXPECT_TRUE(implicit_proto2_descriptor !=
nullptr);
513 EXPECT_EQ(implicit_proto2_descriptor,
pool_.BuildFile(implicit_proto2));
516 proto_syntax3.
set_name(
"foo_syntax3");
554 std::vector<std::pair<std::string, std::string>>* debug_strings) {
555 if (!visited->insert(file->
name()).second) {
561 debug_strings->push_back(std::make_pair(file->
name(), file->
DebugString()));
579 std::set<std::string> visited;
580 std::vector<std::pair<std::string, std::string>> debug_strings;
582 &visited, &debug_strings);
585 &visited, &debug_strings);
587 &visited, &debug_strings);
591 for (
int i = 0;
i < debug_strings.size(); ++
i) {
598 parser.RecordErrorsTo(&error_collector);
704 AddField(message3,
"map_int32_int32", 1,
773 message->CopyJsonNameTo(proto);
803 EXPECT_EQ(
"TestMessage", message_->name());
804 EXPECT_EQ(
"TestMessage", message_->full_name());
807 EXPECT_EQ(
"TestMessage2", message2_->name());
808 EXPECT_EQ(
"corge.grault.TestMessage2", message2_->full_name());
813 EXPECT_TRUE(message_->containing_type() ==
nullptr);
814 EXPECT_TRUE(message2_->containing_type() ==
nullptr);
831 EXPECT_EQ(foo_, message_->FindFieldByName(
"foo"));
832 EXPECT_EQ(bar_, message_->FindFieldByName(
"bar"));
833 EXPECT_EQ(baz_, message_->FindFieldByName(
"baz"));
834 EXPECT_EQ(qux_, message_->FindFieldByName(
"qux"));
835 EXPECT_TRUE(message_->FindFieldByName(
"no_such_field") ==
nullptr);
836 EXPECT_TRUE(message_->FindFieldByName(
"quux") ==
nullptr);
838 EXPECT_EQ(foo2_, message2_->FindFieldByName(
"foo"));
839 EXPECT_EQ(bar2_, message2_->FindFieldByName(
"bar"));
840 EXPECT_EQ(quux2_, message2_->FindFieldByName(
"quux"));
841 EXPECT_TRUE(message2_->FindFieldByName(
"baz") ==
nullptr);
842 EXPECT_TRUE(message2_->FindFieldByName(
"qux") ==
nullptr);
846 EXPECT_EQ(foo_, message_->FindFieldByNumber(1));
847 EXPECT_EQ(bar_, message_->FindFieldByNumber(6));
848 EXPECT_EQ(baz_, message_->FindFieldByNumber(500000000));
849 EXPECT_EQ(qux_, message_->FindFieldByNumber(15));
850 EXPECT_TRUE(message_->FindFieldByNumber(837592) ==
nullptr);
851 EXPECT_TRUE(message_->FindFieldByNumber(2) ==
nullptr);
853 EXPECT_EQ(foo2_, message2_->FindFieldByNumber(1));
854 EXPECT_EQ(bar2_, message2_->FindFieldByNumber(2));
855 EXPECT_EQ(quux2_, message2_->FindFieldByNumber(6));
856 EXPECT_TRUE(message2_->FindFieldByNumber(15) ==
nullptr);
857 EXPECT_TRUE(message2_->FindFieldByNumber(500000000) ==
nullptr);
868 EXPECT_EQ(
"TestMessage.foo", foo_->full_name());
869 EXPECT_EQ(
"TestMessage.bar", bar_->full_name());
870 EXPECT_EQ(
"TestMessage.baz", baz_->full_name());
871 EXPECT_EQ(
"TestMessage.qux", qux_->full_name());
873 EXPECT_EQ(
"corge.grault.TestMessage2.foo", foo2_->full_name());
874 EXPECT_EQ(
"corge.grault.TestMessage2.bar", bar2_->full_name());
875 EXPECT_EQ(
"corge.grault.TestMessage2.quux", quux2_->full_name());
879 EXPECT_EQ(
"TestMessage.foo", foo_->PrintableNameForExtension());
880 EXPECT_EQ(
"TestMessage.bar", bar_->PrintableNameForExtension());
881 EXPECT_EQ(
"TestMessage.baz", baz_->PrintableNameForExtension());
882 EXPECT_EQ(
"TestMessage.qux", qux_->PrintableNameForExtension());
884 EXPECT_EQ(
"corge.grault.TestMessage2.foo",
885 foo2_->PrintableNameForExtension());
886 EXPECT_EQ(
"corge.grault.TestMessage2.bar",
887 bar2_->PrintableNameForExtension());
888 EXPECT_EQ(
"corge.grault.TestMessage2.quux",
889 quux2_->PrintableNameForExtension());
893 EXPECT_EQ(
"protobuf_unittest.Aggregate.nested",
896 ->PrintableNameForExtension());
900 EXPECT_EQ(
"protobuf_unittest.AggregateMessageSetElement",
903 ->PrintableNameForExtension());
907 EXPECT_EQ(
"fieldName1", message4_->field(0)->json_name());
908 EXPECT_EQ(
"fieldName2", message4_->field(1)->json_name());
909 EXPECT_EQ(
"FieldName3", message4_->field(2)->json_name());
910 EXPECT_EQ(
"FieldName4", message4_->field(3)->json_name());
911 EXPECT_EQ(
"FIELDNAME5", message4_->field(4)->json_name());
912 EXPECT_EQ(
"@type", message4_->field(5)->json_name());
915 message4_->CopyTo(&proto);
925 CopyWithJsonName(message4_, &proto);
999 EXPECT_TRUE(map_->message_type()->options().map_entry());
1010 EXPECT_EQ(message_, foo_->containing_type());
1011 EXPECT_EQ(message_, bar_->containing_type());
1012 EXPECT_EQ(message_, baz_->containing_type());
1013 EXPECT_EQ(message_, qux_->containing_type());
1015 EXPECT_EQ(message2_, foo2_->containing_type());
1016 EXPECT_EQ(message2_, bar2_->containing_type());
1017 EXPECT_EQ(message2_, quux2_->containing_type());
1024 EXPECT_EQ(foreign_, baz_->message_type());
1025 EXPECT_EQ(foreign_, qux_->message_type());
1073 oneof_message->
mutable_field(2)->set_type_name(
"TestOneof");
1113 EXPECT_EQ(
"garply.TestOneof.foo", oneof_->full_name());
1124 EXPECT_EQ(oneof_, oneof_message_->FindOneofByName(
"foo"));
1125 EXPECT_EQ(oneof2_, oneof_message_->FindOneofByName(
"bar"));
1126 EXPECT_TRUE(oneof_message_->FindOneofByName(
"no_such_oneof") ==
nullptr);
1169 AddExtension(&file,
"ExtendableMessage",
"baz_foo", 11,
1201 EXPECT_EQ(
"foo_foo", message_->field(0)->lowercase_name());
1202 EXPECT_EQ(
"foobar", message_->field(1)->lowercase_name());
1203 EXPECT_EQ(
"foobaz", message_->field(2)->lowercase_name());
1204 EXPECT_EQ(
"foofoo", message_->field(3)->lowercase_name());
1205 EXPECT_EQ(
"foobar", message_->field(4)->lowercase_name());
1207 EXPECT_EQ(
"bar_foo", message_->extension(0)->lowercase_name());
1208 EXPECT_EQ(
"barbar", message_->extension(1)->lowercase_name());
1209 EXPECT_EQ(
"barbaz", message_->extension(2)->lowercase_name());
1210 EXPECT_EQ(
"barfoo", message_->extension(3)->lowercase_name());
1211 EXPECT_EQ(
"barbar", message_->extension(4)->lowercase_name());
1221 EXPECT_EQ(
"fooFoo", message_->field(0)->camelcase_name());
1222 EXPECT_EQ(
"fooBar", message_->field(1)->camelcase_name());
1223 EXPECT_EQ(
"fooBaz", message_->field(2)->camelcase_name());
1224 EXPECT_EQ(
"fooFoo", message_->field(3)->camelcase_name());
1225 EXPECT_EQ(
"foobar", message_->field(4)->camelcase_name());
1227 EXPECT_EQ(
"barFoo", message_->extension(0)->camelcase_name());
1228 EXPECT_EQ(
"barBar", message_->extension(1)->camelcase_name());
1229 EXPECT_EQ(
"barBaz", message_->extension(2)->camelcase_name());
1230 EXPECT_EQ(
"barFoo", message_->extension(3)->camelcase_name());
1231 EXPECT_EQ(
"barbar", message_->extension(4)->camelcase_name());
1241 EXPECT_EQ(message_->field(0), message_->FindFieldByLowercaseName(
"foo_foo"));
1242 EXPECT_EQ(message_->field(1), message_->FindFieldByLowercaseName(
"foobar"));
1243 EXPECT_EQ(message_->field(2), message_->FindFieldByLowercaseName(
"foobaz"));
1244 EXPECT_TRUE(message_->FindFieldByLowercaseName(
"FooBar") ==
nullptr);
1245 EXPECT_TRUE(message_->FindFieldByLowercaseName(
"fooBaz") ==
nullptr);
1246 EXPECT_TRUE(message_->FindFieldByLowercaseName(
"bar_foo") ==
nullptr);
1247 EXPECT_TRUE(message_->FindFieldByLowercaseName(
"nosuchfield") ==
nullptr);
1250 message_->FindExtensionByLowercaseName(
"bar_foo"));
1252 message_->FindExtensionByLowercaseName(
"barbar"));
1254 message_->FindExtensionByLowercaseName(
"barbaz"));
1255 EXPECT_TRUE(message_->FindExtensionByLowercaseName(
"BarBar") ==
nullptr);
1256 EXPECT_TRUE(message_->FindExtensionByLowercaseName(
"barBaz") ==
nullptr);
1257 EXPECT_TRUE(message_->FindExtensionByLowercaseName(
"foo_foo") ==
nullptr);
1258 EXPECT_TRUE(message_->FindExtensionByLowercaseName(
"nosuchfield") ==
nullptr);
1261 file_->FindExtensionByLowercaseName(
"baz_foo"));
1266 EXPECT_TRUE(
file_->FindExtensionByLowercaseName(
"nosuchfield") ==
nullptr);
1270 EXPECT_EQ(message_->field(0), message_->FindFieldByCamelcaseName(
"fooFoo"));
1271 EXPECT_EQ(message_->field(1), message_->FindFieldByCamelcaseName(
"fooBar"));
1272 EXPECT_EQ(message_->field(2), message_->FindFieldByCamelcaseName(
"fooBaz"));
1273 EXPECT_TRUE(message_->FindFieldByCamelcaseName(
"foo_foo") ==
nullptr);
1274 EXPECT_TRUE(message_->FindFieldByCamelcaseName(
"FooBar") ==
nullptr);
1275 EXPECT_TRUE(message_->FindFieldByCamelcaseName(
"barFoo") ==
nullptr);
1276 EXPECT_TRUE(message_->FindFieldByCamelcaseName(
"nosuchfield") ==
nullptr);
1279 message_->FindExtensionByCamelcaseName(
"barFoo"));
1281 message_->FindExtensionByCamelcaseName(
"barBar"));
1283 message_->FindExtensionByCamelcaseName(
"barBaz"));
1284 EXPECT_TRUE(message_->FindExtensionByCamelcaseName(
"bar_foo") ==
nullptr);
1285 EXPECT_TRUE(message_->FindExtensionByCamelcaseName(
"BarBar") ==
nullptr);
1286 EXPECT_TRUE(message_->FindExtensionByCamelcaseName(
"fooFoo") ==
nullptr);
1287 EXPECT_TRUE(message_->FindExtensionByCamelcaseName(
"nosuchfield") ==
nullptr);
1294 EXPECT_TRUE(
file_->FindExtensionByCamelcaseName(
"nosuchfield") ==
nullptr);
1378 EXPECT_EQ(
"TestEnum", enum_->full_name());
1382 EXPECT_EQ(
"corge.grault.TestEnum2", enum2_->full_name());
1388 EXPECT_TRUE(enum2_->containing_type() ==
nullptr);
1398 EXPECT_EQ(foo_, enum_->FindValueByName(
"FOO"));
1399 EXPECT_EQ(bar_, enum_->FindValueByName(
"BAR"));
1400 EXPECT_EQ(foo2_, enum2_->FindValueByName(
"FOO"));
1401 EXPECT_EQ(baz2_, enum2_->FindValueByName(
"BAZ"));
1403 EXPECT_TRUE(enum_->FindValueByName(
"NO_SUCH_VALUE") ==
nullptr);
1404 EXPECT_TRUE(enum_->FindValueByName(
"BAZ") ==
nullptr);
1405 EXPECT_TRUE(enum2_->FindValueByName(
"BAR") ==
nullptr);
1409 EXPECT_EQ(foo_, enum_->FindValueByNumber(1));
1410 EXPECT_EQ(bar_, enum_->FindValueByNumber(2));
1411 EXPECT_EQ(foo2_, enum2_->FindValueByNumber(1));
1412 EXPECT_EQ(baz2_, enum2_->FindValueByNumber(3));
1414 EXPECT_TRUE(enum_->FindValueByNumber(416) ==
nullptr);
1415 EXPECT_TRUE(enum_->FindValueByNumber(3) ==
nullptr);
1416 EXPECT_TRUE(enum2_->FindValueByNumber(2) ==
nullptr);
1427 EXPECT_EQ(
"corge.grault.FOO", foo2_->full_name());
1428 EXPECT_EQ(
"corge.grault.BAZ", baz2_->full_name());
1486 AddMethod(service,
"Foo",
"FooRequest",
"FooResponse");
1487 AddMethod(service,
"Bar",
"BarRequest",
"BarResponse");
1495 AddMethod(service2,
"Foo",
"FooRequest",
"FooResponse");
1496 AddMethod(service2,
"Baz",
"BazRequest",
"BazResponse");
1551 EXPECT_EQ(
"TestService", service_->name());
1552 EXPECT_EQ(
"TestService", service_->full_name());
1555 EXPECT_EQ(
"TestService2", service2_->name());
1556 EXPECT_EQ(
"corge.grault.TestService2", service2_->full_name());
1557 EXPECT_EQ(bar_file_, service2_->file());
1567 EXPECT_EQ(foo_, service_->FindMethodByName(
"Foo"));
1568 EXPECT_EQ(bar_, service_->FindMethodByName(
"Bar"));
1569 EXPECT_EQ(foo2_, service2_->FindMethodByName(
"Foo"));
1570 EXPECT_EQ(baz2_, service2_->FindMethodByName(
"Baz"));
1572 EXPECT_TRUE(service_->FindMethodByName(
"NoSuchMethod") ==
nullptr);
1573 EXPECT_TRUE(service_->FindMethodByName(
"Baz") ==
nullptr);
1574 EXPECT_TRUE(service2_->FindMethodByName(
"Bar") ==
nullptr);
1583 EXPECT_EQ(
"TestService.Foo", foo_->full_name());
1584 EXPECT_EQ(
"TestService.Bar", bar_->full_name());
1585 EXPECT_EQ(
"corge.grault.TestService2.Foo", foo2_->full_name());
1586 EXPECT_EQ(
"corge.grault.TestService2.Baz", baz2_->full_name());
1600 EXPECT_EQ(foo_request_, foo_->input_type());
1601 EXPECT_EQ(bar_request_, bar_->input_type());
1605 EXPECT_EQ(foo_response_, foo_->output_type());
1606 EXPECT_EQ(bar_response_, bar_->output_type());
1733 EXPECT_EQ(
"TestMessage.Foo", foo_->full_name());
1734 EXPECT_EQ(
"TestMessage.Bar", bar_->full_name());
1735 EXPECT_EQ(
"corge.grault.TestMessage2.Foo", foo2_->full_name());
1736 EXPECT_EQ(
"corge.grault.TestMessage2.Baz", baz2_->full_name());
1740 EXPECT_EQ(message_, foo_->containing_type());
1741 EXPECT_EQ(message_, bar_->containing_type());
1742 EXPECT_EQ(message2_, foo2_->containing_type());
1743 EXPECT_EQ(message2_, baz2_->containing_type());
1747 ASSERT_EQ(2, message_->nested_type_count());
1748 EXPECT_EQ(foo_, message_->nested_type(0));
1749 EXPECT_EQ(bar_, message_->nested_type(1));
1753 EXPECT_TRUE(message_->FindFieldByName(
"Foo") ==
nullptr);
1754 EXPECT_TRUE(message_->FindFieldByName(
"Qux") ==
nullptr);
1755 EXPECT_TRUE(message_->FindExtensionByName(
"Foo") ==
nullptr);
1756 EXPECT_TRUE(message_->FindExtensionByName(
"Qux") ==
nullptr);
1760 EXPECT_EQ(foo_, message_->FindNestedTypeByName(
"Foo"));
1761 EXPECT_EQ(bar_, message_->FindNestedTypeByName(
"Bar"));
1762 EXPECT_EQ(foo2_, message2_->FindNestedTypeByName(
"Foo"));
1763 EXPECT_EQ(baz2_, message2_->FindNestedTypeByName(
"Baz"));
1765 EXPECT_TRUE(message_->FindNestedTypeByName(
"NoSuchType") ==
nullptr);
1766 EXPECT_TRUE(message_->FindNestedTypeByName(
"Baz") ==
nullptr);
1767 EXPECT_TRUE(message2_->FindNestedTypeByName(
"Bar") ==
nullptr);
1769 EXPECT_TRUE(message_->FindNestedTypeByName(
"Qux") ==
nullptr);
1778 EXPECT_EQ(
"TestMessage.Baz", baz_->full_name());
1779 EXPECT_EQ(
"TestMessage.Qux", qux_->full_name());
1780 EXPECT_EQ(
"corge.grault.TestMessage2.Qux", qux2_->full_name());
1781 EXPECT_EQ(
"corge.grault.TestMessage2.Quux", quux2_->full_name());
1785 EXPECT_EQ(message_, baz_->containing_type());
1786 EXPECT_EQ(message_, qux_->containing_type());
1787 EXPECT_EQ(message2_, qux2_->containing_type());
1788 EXPECT_EQ(message2_, quux2_->containing_type());
1792 ASSERT_EQ(2, message_->nested_type_count());
1793 EXPECT_EQ(foo_, message_->nested_type(0));
1794 EXPECT_EQ(bar_, message_->nested_type(1));
1798 EXPECT_EQ(baz_, message_->FindEnumTypeByName(
"Baz"));
1799 EXPECT_EQ(qux_, message_->FindEnumTypeByName(
"Qux"));
1800 EXPECT_EQ(qux2_, message2_->FindEnumTypeByName(
"Qux"));
1801 EXPECT_EQ(quux2_, message2_->FindEnumTypeByName(
"Quux"));
1803 EXPECT_TRUE(message_->FindEnumTypeByName(
"NoSuchType") ==
nullptr);
1804 EXPECT_TRUE(message_->FindEnumTypeByName(
"Quux") ==
nullptr);
1805 EXPECT_TRUE(message2_->FindEnumTypeByName(
"Baz") ==
nullptr);
1807 EXPECT_TRUE(message_->FindEnumTypeByName(
"Foo") ==
nullptr);
1811 EXPECT_EQ(
a_, message_->FindEnumValueByName(
"A"));
1812 EXPECT_EQ(
b_, message_->FindEnumValueByName(
"B"));
1813 EXPECT_EQ(a2_, message2_->FindEnumValueByName(
"A"));
1814 EXPECT_EQ(c2_, message2_->FindEnumValueByName(
"C"));
1816 EXPECT_TRUE(message_->FindEnumValueByName(
"NO_SUCH_VALUE") ==
nullptr);
1817 EXPECT_TRUE(message_->FindEnumValueByName(
"C") ==
nullptr);
1818 EXPECT_TRUE(message2_->FindEnumValueByName(
"B") ==
nullptr);
1820 EXPECT_TRUE(message_->FindEnumValueByName(
"Foo") ==
nullptr);
1898 EXPECT_EQ(0, bar_->extension_range_count());
1899 ASSERT_EQ(2, foo_->extension_range_count());
1901 EXPECT_EQ(10, foo_->extension_range(0)->start);
1902 EXPECT_EQ(30, foo_->extension_range(1)->start);
1904 EXPECT_EQ(20, foo_->extension_range(0)->end);
1905 EXPECT_EQ(40, foo_->extension_range(1)->end);
1910 ASSERT_EQ(2, foo_file_->extension_count());
1913 EXPECT_TRUE(foo_file_->extension(0)->is_extension());
1914 EXPECT_TRUE(foo_file_->extension(1)->is_extension());
1918 EXPECT_EQ(
"foo_int32", foo_file_->extension(0)->name());
1919 EXPECT_EQ(
"foo_enum", foo_file_->extension(1)->name());
1920 EXPECT_EQ(
"foo_message", bar_->extension(0)->name());
1921 EXPECT_EQ(
"foo_group", bar_->extension(1)->name());
1923 EXPECT_EQ(10, foo_file_->extension(0)->number());
1924 EXPECT_EQ(19, foo_file_->extension(1)->number());
1925 EXPECT_EQ(30, bar_->extension(0)->number());
1926 EXPECT_EQ(39, bar_->extension(1)->number());
1933 EXPECT_EQ(baz_, foo_file_->extension(1)->enum_type());
1934 EXPECT_EQ(qux_, bar_->extension(0)->message_type());
1935 EXPECT_EQ(qux_, bar_->extension(1)->message_type());
1942 EXPECT_EQ(foo_, foo_file_->extension(0)->containing_type());
1943 EXPECT_EQ(foo_, foo_file_->extension(1)->containing_type());
1944 EXPECT_EQ(foo_, bar_->extension(0)->containing_type());
1945 EXPECT_EQ(foo_, bar_->extension(1)->containing_type());
1947 EXPECT_TRUE(foo_file_->extension(0)->extension_scope() ==
nullptr);
1948 EXPECT_TRUE(foo_file_->extension(1)->extension_scope() ==
nullptr);
1949 EXPECT_EQ(bar_, bar_->extension(0)->extension_scope());
1950 EXPECT_EQ(bar_, bar_->extension(1)->extension_scope());
1969 EXPECT_EQ(bar_->extension(0), bar_->FindExtensionByName(
"foo_message"));
1970 EXPECT_EQ(bar_->extension(1), bar_->FindExtensionByName(
"foo_group"));
1972 EXPECT_TRUE(bar_->FindExtensionByName(
"no_such_extension") ==
nullptr);
1973 EXPECT_TRUE(foo_->FindExtensionByName(
"foo_int32") ==
nullptr);
1974 EXPECT_TRUE(foo_->FindExtensionByName(
"foo_message") ==
nullptr);
1978 EXPECT_TRUE(
pool_.FindExtensionByPrintableName(foo_,
"no_such_extension") ==
1980 EXPECT_TRUE(
pool_.FindExtensionByPrintableName(bar_,
"no_such_extension") ==
1989 EXPECT_TRUE(
pool_.FindExtensionByPrintableName(bar_,
"foo_group") ==
nullptr);
1990 EXPECT_EQ(bar_->FindExtensionByName(
"foo_message"),
1991 pool_.FindExtensionByPrintableName(foo_,
"Bar.foo_message"));
1992 EXPECT_EQ(bar_->FindExtensionByName(
"foo_group"),
1993 pool_.FindExtensionByPrintableName(foo_,
"Bar.foo_group"));
1998 EXPECT_TRUE(
pool_.FindExtensionByPrintableName(bar_,
"foo_int32") ==
nullptr);
1999 EXPECT_TRUE(
pool_.FindExtensionByPrintableName(bar_,
"foo_enum") ==
nullptr);
2000 EXPECT_EQ(foo_file_->FindExtensionByName(
"foo_int32"),
2001 pool_.FindExtensionByPrintableName(foo_,
"foo_int32"));
2002 EXPECT_EQ(foo_file_->FindExtensionByName(
"foo_enum"),
2003 pool_.FindExtensionByPrintableName(foo_,
"foo_enum"));
2007 std::vector<const FieldDescriptor*> extensions;
2008 pool_.FindAllExtensions(foo_, &extensions);
2031 AddExtension(&file_proto,
"google.protobuf.FieldOptions",
"option1", 1000,
2043 AddExtension(&file_proto,
"google.protobuf.FieldOptions",
"option2", 1000,
2072 foo->add_reserved_name(
"foo");
2073 foo->add_reserved_name(
"bar");
2089 ASSERT_EQ(3, foo_->reserved_range_count());
2091 EXPECT_EQ(2, foo_->reserved_range(0)->start);
2092 EXPECT_EQ(3, foo_->reserved_range(0)->end);
2094 EXPECT_EQ(9, foo_->reserved_range(1)->start);
2095 EXPECT_EQ(12, foo_->reserved_range(1)->end);
2097 EXPECT_EQ(15, foo_->reserved_range(2)->start);
2098 EXPECT_EQ(16, foo_->reserved_range(2)->end);
2117 ASSERT_EQ(2, foo_->reserved_name_count());
2119 EXPECT_EQ(
"foo", foo_->reserved_name(0));
2120 EXPECT_EQ(
"bar", foo_->reserved_name(1));
2157 foo->add_reserved_name(
"foo");
2158 foo->add_reserved_name(
"bar");
2188 ASSERT_EQ(5, foo_->reserved_range_count());
2190 EXPECT_EQ(-5, foo_->reserved_range(0)->start);
2191 EXPECT_EQ(-3, foo_->reserved_range(0)->end);
2193 EXPECT_EQ(-2, foo_->reserved_range(1)->start);
2194 EXPECT_EQ(1, foo_->reserved_range(1)->end);
2196 EXPECT_EQ(2, foo_->reserved_range(2)->start);
2197 EXPECT_EQ(3, foo_->reserved_range(2)->end);
2199 EXPECT_EQ(9, foo_->reserved_range(3)->start);
2200 EXPECT_EQ(12, foo_->reserved_range(3)->end);
2202 EXPECT_EQ(15, foo_->reserved_range(4)->start);
2203 EXPECT_EQ(16, foo_->reserved_range(4)->end);
2205 ASSERT_EQ(1, edge1_->reserved_range_count());
2206 EXPECT_EQ(10, edge1_->reserved_range(0)->start);
2207 EXPECT_EQ(INT_MAX, edge1_->reserved_range(0)->end);
2209 ASSERT_EQ(1, edge2_->reserved_range_count());
2210 EXPECT_EQ(INT_MIN, edge2_->reserved_range(0)->start);
2211 EXPECT_EQ(10, edge2_->reserved_range(0)->end);
2238 EXPECT_TRUE(edge1_->IsReservedNumber(INT_MAX - 1));
2248 ASSERT_EQ(2, foo_->reserved_name_count());
2250 EXPECT_EQ(
"foo", foo_->reserved_name(0));
2251 EXPECT_EQ(
"bar", foo_->reserved_name(1));
2277 field->set_type_name(
"TestMessage");
2279 field->set_type_name(
"DummyEnum");
2296 return field !=
nullptr ?
field->type_name() :
"";
2307 return field !=
nullptr ?
field->cpp_type_name() :
"";
2313 return field !=
nullptr ?
field->message_type() :
nullptr;
2319 return field !=
nullptr ?
field->enum_type() :
nullptr;
2330 EXPECT_STREQ(
"double", GetTypeNameForFieldType(FD::TYPE_DOUBLE));
2331 EXPECT_STREQ(
"float", GetTypeNameForFieldType(FD::TYPE_FLOAT));
2332 EXPECT_STREQ(
"int64", GetTypeNameForFieldType(FD::TYPE_INT64));
2333 EXPECT_STREQ(
"uint64", GetTypeNameForFieldType(FD::TYPE_UINT64));
2334 EXPECT_STREQ(
"int32", GetTypeNameForFieldType(FD::TYPE_INT32));
2335 EXPECT_STREQ(
"fixed64", GetTypeNameForFieldType(FD::TYPE_FIXED64));
2336 EXPECT_STREQ(
"fixed32", GetTypeNameForFieldType(FD::TYPE_FIXED32));
2337 EXPECT_STREQ(
"bool", GetTypeNameForFieldType(FD::TYPE_BOOL));
2338 EXPECT_STREQ(
"string", GetTypeNameForFieldType(FD::TYPE_STRING));
2339 EXPECT_STREQ(
"group", GetTypeNameForFieldType(FD::TYPE_GROUP));
2340 EXPECT_STREQ(
"message", GetTypeNameForFieldType(FD::TYPE_MESSAGE));
2341 EXPECT_STREQ(
"bytes", GetTypeNameForFieldType(FD::TYPE_BYTES));
2342 EXPECT_STREQ(
"uint32", GetTypeNameForFieldType(FD::TYPE_UINT32));
2343 EXPECT_STREQ(
"enum", GetTypeNameForFieldType(FD::TYPE_ENUM));
2344 EXPECT_STREQ(
"sfixed32", GetTypeNameForFieldType(FD::TYPE_SFIXED32));
2345 EXPECT_STREQ(
"sfixed64", GetTypeNameForFieldType(FD::TYPE_SFIXED64));
2346 EXPECT_STREQ(
"sint32", GetTypeNameForFieldType(FD::TYPE_SINT32));
2347 EXPECT_STREQ(
"sint64", GetTypeNameForFieldType(FD::TYPE_SINT64));
2380 EXPECT_EQ(FD::CPPTYPE_DOUBLE, GetCppTypeForFieldType(FD::TYPE_DOUBLE));
2381 EXPECT_EQ(FD::CPPTYPE_FLOAT, GetCppTypeForFieldType(FD::TYPE_FLOAT));
2382 EXPECT_EQ(FD::CPPTYPE_INT64, GetCppTypeForFieldType(FD::TYPE_INT64));
2383 EXPECT_EQ(FD::CPPTYPE_UINT64, GetCppTypeForFieldType(FD::TYPE_UINT64));
2384 EXPECT_EQ(FD::CPPTYPE_INT32, GetCppTypeForFieldType(FD::TYPE_INT32));
2385 EXPECT_EQ(FD::CPPTYPE_UINT64, GetCppTypeForFieldType(FD::TYPE_FIXED64));
2386 EXPECT_EQ(FD::CPPTYPE_UINT32, GetCppTypeForFieldType(FD::TYPE_FIXED32));
2387 EXPECT_EQ(FD::CPPTYPE_BOOL, GetCppTypeForFieldType(FD::TYPE_BOOL));
2388 EXPECT_EQ(FD::CPPTYPE_STRING, GetCppTypeForFieldType(FD::TYPE_STRING));
2389 EXPECT_EQ(FD::CPPTYPE_MESSAGE, GetCppTypeForFieldType(FD::TYPE_GROUP));
2390 EXPECT_EQ(FD::CPPTYPE_MESSAGE, GetCppTypeForFieldType(FD::TYPE_MESSAGE));
2391 EXPECT_EQ(FD::CPPTYPE_STRING, GetCppTypeForFieldType(FD::TYPE_BYTES));
2392 EXPECT_EQ(FD::CPPTYPE_UINT32, GetCppTypeForFieldType(FD::TYPE_UINT32));
2393 EXPECT_EQ(FD::CPPTYPE_ENUM, GetCppTypeForFieldType(FD::TYPE_ENUM));
2394 EXPECT_EQ(FD::CPPTYPE_INT32, GetCppTypeForFieldType(FD::TYPE_SFIXED32));
2395 EXPECT_EQ(FD::CPPTYPE_INT64, GetCppTypeForFieldType(FD::TYPE_SFIXED64));
2396 EXPECT_EQ(FD::CPPTYPE_INT32, GetCppTypeForFieldType(FD::TYPE_SINT32));
2397 EXPECT_EQ(FD::CPPTYPE_INT64, GetCppTypeForFieldType(FD::TYPE_SINT64));
2405 EXPECT_STREQ(
"double", GetCppTypeNameForFieldType(FD::TYPE_DOUBLE));
2406 EXPECT_STREQ(
"float", GetCppTypeNameForFieldType(FD::TYPE_FLOAT));
2407 EXPECT_STREQ(
"int64", GetCppTypeNameForFieldType(FD::TYPE_INT64));
2408 EXPECT_STREQ(
"uint64", GetCppTypeNameForFieldType(FD::TYPE_UINT64));
2409 EXPECT_STREQ(
"int32", GetCppTypeNameForFieldType(FD::TYPE_INT32));
2410 EXPECT_STREQ(
"uint64", GetCppTypeNameForFieldType(FD::TYPE_FIXED64));
2411 EXPECT_STREQ(
"uint32", GetCppTypeNameForFieldType(FD::TYPE_FIXED32));
2412 EXPECT_STREQ(
"bool", GetCppTypeNameForFieldType(FD::TYPE_BOOL));
2413 EXPECT_STREQ(
"string", GetCppTypeNameForFieldType(FD::TYPE_STRING));
2414 EXPECT_STREQ(
"message", GetCppTypeNameForFieldType(FD::TYPE_GROUP));
2415 EXPECT_STREQ(
"message", GetCppTypeNameForFieldType(FD::TYPE_MESSAGE));
2416 EXPECT_STREQ(
"string", GetCppTypeNameForFieldType(FD::TYPE_BYTES));
2417 EXPECT_STREQ(
"uint32", GetCppTypeNameForFieldType(FD::TYPE_UINT32));
2418 EXPECT_STREQ(
"enum", GetCppTypeNameForFieldType(FD::TYPE_ENUM));
2419 EXPECT_STREQ(
"int32", GetCppTypeNameForFieldType(FD::TYPE_SFIXED32));
2420 EXPECT_STREQ(
"int64", GetCppTypeNameForFieldType(FD::TYPE_SFIXED64));
2421 EXPECT_STREQ(
"int32", GetCppTypeNameForFieldType(FD::TYPE_SINT32));
2422 EXPECT_STREQ(
"int64", GetCppTypeNameForFieldType(FD::TYPE_SINT64));
2430 EXPECT_STREQ(
"int32", FD::CppTypeName(FD::CPPTYPE_INT32));
2431 EXPECT_STREQ(
"int64", FD::CppTypeName(FD::CPPTYPE_INT64));
2432 EXPECT_STREQ(
"uint32", FD::CppTypeName(FD::CPPTYPE_UINT32));
2433 EXPECT_STREQ(
"uint64", FD::CppTypeName(FD::CPPTYPE_UINT64));
2434 EXPECT_STREQ(
"double", FD::CppTypeName(FD::CPPTYPE_DOUBLE));
2435 EXPECT_STREQ(
"float", FD::CppTypeName(FD::CPPTYPE_FLOAT));
2436 EXPECT_STREQ(
"bool", FD::CppTypeName(FD::CPPTYPE_BOOL));
2437 EXPECT_STREQ(
"enum", FD::CppTypeName(FD::CPPTYPE_ENUM));
2438 EXPECT_STREQ(
"string", FD::CppTypeName(FD::CPPTYPE_STRING));
2439 EXPECT_STREQ(
"message", FD::CppTypeName(FD::CPPTYPE_MESSAGE));
2447 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_DOUBLE));
2448 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_FLOAT));
2449 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_INT64));
2450 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_UINT64));
2451 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_INT32));
2452 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_FIXED64));
2453 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_FIXED32));
2454 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_BOOL));
2455 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_STRING));
2456 EXPECT_TRUE(
nullptr != GetMessageDescriptorForFieldType(FD::TYPE_GROUP));
2457 EXPECT_TRUE(
nullptr != GetMessageDescriptorForFieldType(FD::TYPE_MESSAGE));
2458 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_BYTES));
2459 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_UINT32));
2460 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_ENUM));
2461 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_SFIXED32));
2462 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_SFIXED64));
2463 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_SINT32));
2464 EXPECT_TRUE(
nullptr == GetMessageDescriptorForFieldType(FD::TYPE_SINT64));
2472 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_DOUBLE));
2473 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_FLOAT));
2474 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_INT64));
2475 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_UINT64));
2476 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_INT32));
2477 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_FIXED64));
2478 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_FIXED32));
2479 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_BOOL));
2480 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_STRING));
2481 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_GROUP));
2482 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_MESSAGE));
2483 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_BYTES));
2484 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_UINT32));
2485 EXPECT_TRUE(
nullptr != GetEnumDescriptorForFieldType(FD::TYPE_ENUM));
2486 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_SFIXED32));
2487 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_SFIXED64));
2488 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_SINT32));
2489 EXPECT_TRUE(
nullptr == GetEnumDescriptorForFieldType(FD::TYPE_SINT64));
2504 const FD::Label
label = FD::LABEL_OPTIONAL;
2511 AddField(message_proto,
"uint32", 3,
label, FD::TYPE_UINT32)
2513 AddField(message_proto,
"uint64", 4,
label, FD::TYPE_UINT64)
2517 AddField(message_proto,
"double", 6,
label, FD::TYPE_DOUBLE)
2521 AddField(message_proto,
"string", 8,
label, FD::TYPE_STRING)
2533 AddField(message_proto,
"empty_string", 11,
label, FD::TYPE_STRING)
2537 AddField(message_proto,
"implicit_int32", 21,
label, FD::TYPE_INT32);
2538 AddField(message_proto,
"implicit_int64", 22,
label, FD::TYPE_INT64);
2539 AddField(message_proto,
"implicit_uint32", 23,
label, FD::TYPE_UINT32);
2540 AddField(message_proto,
"implicit_uint64", 24,
label, FD::TYPE_UINT64);
2541 AddField(message_proto,
"implicit_float", 25,
label, FD::TYPE_FLOAT);
2542 AddField(message_proto,
"implicit_double", 26,
label, FD::TYPE_DOUBLE);
2543 AddField(message_proto,
"implicit_bool", 27,
label, FD::TYPE_BOOL);
2544 AddField(message_proto,
"implicit_string", 28,
label, FD::TYPE_STRING);
2545 AddField(message_proto,
"implicit_data", 29,
label, FD::TYPE_BYTES);
2546 AddField(message_proto,
"implicit_enum", 30,
label, FD::TYPE_ENUM)
2579 EXPECT_EQ(-PROTOBUF_ULONGLONG(1000000000000),
2580 message->field(1)->default_value_int64());
2582 EXPECT_EQ(PROTOBUF_ULONGLONG(2000000000000),
2583 message->field(3)->default_value_uint64());
2672 pool_->AllowUnknownDependencies();
2676 "dependency: 'bar.proto'"
2677 "dependency: 'baz.proto'"
2680 " field { name:'bar' number:1 label:LABEL_OPTIONAL type_name:'Bar' }"
2681 " field { name:'baz' number:2 label:LABEL_OPTIONAL type_name:'Baz' }"
2682 " field { name:'qux' number:3 label:LABEL_OPTIONAL"
2683 " type_name: '.corge.Qux'"
2686 " uninterpreted_option {"
2688 " name_part: 'grault'"
2689 " is_extension: true"
2691 " positive_int_value: 1234"
2699 "message_type { name: 'Bar' }",
2724 return pool_->BuildFile(proto);
2728 return pool_->FindFileByName(proto.
name());
2748 ASSERT_EQ(2, foo_file_->dependency_count());
2749 EXPECT_EQ(bar_file_, foo_file_->dependency(0));
2763 baz_file->
CopyTo(&baz_file_proto);
2770 EXPECT_EQ(bar_type_, bar_field_->message_type());
2774 const Descriptor* baz_type = baz_field_->message_type();
2787 EXPECT_EQ(bar_type_,
pool_->FindMessageTypeByName(bar_type_->full_name()));
2798 bar_field_->CopyTo(&proto);
2804 baz_field_->CopyTo(&proto);
2810 qux_field_->CopyTo(&proto);
2817 ASSERT_EQ(1, qux_field_->options().uninterpreted_option_size());
2819 qux_field_->options().uninterpreted_option(0);
2831 "name: 'extension.proto'"
2832 "extension { extendee: 'UnknownType' name:'some_extension' number:123"
2833 " label:LABEL_OPTIONAL type:TYPE_INT32 }",
2855 "name: \"unknown_custom_options.proto\" "
2856 "dependency: \"google/protobuf/descriptor.proto\" "
2858 " extendee: \"google.protobuf.FileOptions\" "
2859 " name: \"some_option\" "
2861 " label: LABEL_OPTIONAL "
2862 " type: TYPE_INT32 "
2865 " uninterpreted_option { "
2867 " name_part: \"some_option\" "
2868 " is_extension: true "
2870 " positive_int_value: 1234 "
2872 " uninterpreted_option { "
2874 " name_part: \"unknown_option\" "
2875 " is_extension: true "
2877 " positive_int_value: 1234 "
2879 " uninterpreted_option { "
2881 " name_part: \"optimize_for\" "
2882 " is_extension: false "
2884 " identifier_value: \"SPEED\" "
2894 std::vector<const FieldDescriptor*>
fields;
2902 UndeclaredDependencyTriggersBuildOfDependency) {
2914 "name: \"invalid_file_as_undeclared_dep.proto\" "
2915 "package: \"undeclared\" "
2919 " name:'qux' number:1 label:LABEL_OPTIONAL type: TYPE_INT32 "
2922 " name:'quux' number:1 label:LABEL_OPTIONAL type: TYPE_INT64 "
2925 &undeclared_dep_proto));
2942 "name: \"test.proto\" "
2946 " name:'quux' number:1 label: LABEL_OPTIONAL "
2947 " type_name:'undeclared.Quux' type: TYPE_MESSAGE "
2977 TEST(CustomOptions, OptionLocations) {
2989 EXPECT_EQ(PROTOBUF_LONGLONG(9876543210),
2990 file->
options().GetExtension(protobuf_unittest::file_opt1));
2992 message->options().GetExtension(protobuf_unittest::message_opt1));
2993 EXPECT_EQ(PROTOBUF_LONGLONG(8765432109),
2994 field->options().GetExtension(protobuf_unittest::field_opt1));
2996 field->options().GetExtension(protobuf_unittest::field_opt2));
2997 EXPECT_EQ(-99, oneof->
options().GetExtension(protobuf_unittest::oneof_opt1));
2998 EXPECT_EQ(-789, enm->
options().GetExtension(protobuf_unittest::enum_opt1));
3000 protobuf_unittest::enum_value_opt1));
3001 EXPECT_EQ(PROTOBUF_LONGLONG(-9876543210),
3002 service->
options().GetExtension(protobuf_unittest::service_opt1));
3003 EXPECT_EQ(protobuf_unittest::METHODOPT1_VAL2,
3004 method->
options().GetExtension(protobuf_unittest::method_opt1));
3045 options->GetExtension(protobuf_unittest::float_opt));
3047 options->GetExtension(protobuf_unittest::double_opt));
3049 options->GetExtension(protobuf_unittest::string_opt));
3052 options->GetExtension(protobuf_unittest::bytes_opt));
3054 EXPECT_EQ(protobuf_unittest::DummyMessageContainingEnum::TEST_OPTION_ENUM_TYPE2,
3055 options->GetExtension(protobuf_unittest::enum_opt));
3068 TEST(CustomOptions, ComplexExtensionOptions) {
3071 EXPECT_EQ(
options->GetExtension(protobuf_unittest::complex_opt1).foo(), 42);
3073 .GetExtension(protobuf_unittest::quux),
3076 .GetExtension(protobuf_unittest::corge)
3079 EXPECT_EQ(
options->GetExtension(protobuf_unittest::complex_opt2).baz(), 987);
3081 .GetExtension(protobuf_unittest::grault),
3083 EXPECT_EQ(
options->GetExtension(protobuf_unittest::complex_opt2).bar().foo(),
3087 .GetExtension(protobuf_unittest::quux),
3091 .GetExtension(protobuf_unittest::corge)
3095 .GetExtension(protobuf_unittest::garply)
3099 .GetExtension(protobuf_unittest::garply)
3100 .GetExtension(protobuf_unittest::quux),
3103 .GetExtension(protobuf_unittest::garply)
3104 .GetExtension(protobuf_unittest::corge)
3108 ->GetExtension(protobuf_unittest::ComplexOptionType2::
3109 ComplexOptionType4::complex_opt4)
3112 EXPECT_EQ(
options->GetExtension(protobuf_unittest::complex_opt2).fred().waldo(),
3114 EXPECT_EQ(9,
options->GetExtension(protobuf_unittest::complex_opt3).qux());
3116 .complexoptiontype5()
3118 EXPECT_EQ(24,
options->GetExtension(protobuf_unittest::complexopt6).xyzzy());
3121 TEST(CustomOptions, OptionsFromOtherFile) {
3135 "name: \"custom_options_import.proto\" "
3136 "package: \"protobuf_unittest\" "
3137 "dependency: \"google/protobuf/unittest_custom_options.proto\" "
3139 " uninterpreted_option { "
3141 " name_part: \"file_opt1\" "
3142 " is_extension: true "
3144 " positive_int_value: 1234 "
3148 " uninterpreted_option { "
3150 " name_part: \"java_package\" "
3151 " is_extension: false "
3153 " string_value: \"foo\" "
3157 " uninterpreted_option { "
3159 " name_part: \"optimize_for\" "
3160 " is_extension: false "
3162 " identifier_value: \"SPEED\" "
3169 EXPECT_EQ(1234, file->
options().GetExtension(protobuf_unittest::file_opt1));
3176 TEST(CustomOptions, MessageOptionThreeFieldsSet) {
3202 "name: \"custom_options_import.proto\" "
3203 "package: \"protobuf_unittest\" "
3204 "dependency: \"google/protobuf/unittest_custom_options.proto\" "
3208 " uninterpreted_option { "
3210 " name_part: \"complex_opt1\" "
3211 " is_extension: true "
3214 " name_part: \"foo\" "
3215 " is_extension: false "
3217 " positive_int_value: 1234 "
3219 " uninterpreted_option { "
3221 " name_part: \"complex_opt1\" "
3222 " is_extension: true "
3225 " name_part: \"foo2\" "
3226 " is_extension: false "
3228 " positive_int_value: 1234 "
3230 " uninterpreted_option { "
3232 " name_part: \"complex_opt1\" "
3233 " is_extension: true "
3236 " name_part: \"foo3\" "
3237 " is_extension: false "
3239 " positive_int_value: 1234 "
3250 EXPECT_EQ(1234,
options.GetExtension(protobuf_unittest::complex_opt1).foo());
3253 TEST(CustomOptions, MessageOptionRepeatedLeafFieldSet) {
3279 "name: \"custom_options_import.proto\" "
3280 "package: \"protobuf_unittest\" "
3281 "dependency: \"google/protobuf/unittest_custom_options.proto\" "
3285 " uninterpreted_option { "
3287 " name_part: \"complex_opt1\" "
3288 " is_extension: true "
3291 " name_part: \"foo4\" "
3292 " is_extension: false "
3294 " positive_int_value: 12 "
3296 " uninterpreted_option { "
3298 " name_part: \"complex_opt1\" "
3299 " is_extension: true "
3302 " name_part: \"foo4\" "
3303 " is_extension: false "
3305 " positive_int_value: 34 "
3307 " uninterpreted_option { "
3309 " name_part: \"complex_opt1\" "
3310 " is_extension: true "
3313 " name_part: \"foo4\" "
3314 " is_extension: false "
3316 " positive_int_value: 56 "
3327 EXPECT_EQ(3,
options.GetExtension(protobuf_unittest::complex_opt1).foo4_size());
3328 EXPECT_EQ(12,
options.GetExtension(protobuf_unittest::complex_opt1).foo4(0));
3329 EXPECT_EQ(34,
options.GetExtension(protobuf_unittest::complex_opt1).foo4(1));
3330 EXPECT_EQ(56,
options.GetExtension(protobuf_unittest::complex_opt1).foo4(2));
3333 TEST(CustomOptions, MessageOptionRepeatedMsgFieldSet) {
3359 "name: \"custom_options_import.proto\" "
3360 "package: \"protobuf_unittest\" "
3361 "dependency: \"google/protobuf/unittest_custom_options.proto\" "
3365 " uninterpreted_option { "
3367 " name_part: \"complex_opt2\" "
3368 " is_extension: true "
3371 " name_part: \"barney\" "
3372 " is_extension: false "
3374 " aggregate_value: \"waldo: 1\" "
3376 " uninterpreted_option { "
3378 " name_part: \"complex_opt2\" "
3379 " is_extension: true "
3382 " name_part: \"barney\" "
3383 " is_extension: false "
3385 " aggregate_value: \"waldo: 10\" "
3387 " uninterpreted_option { "
3389 " name_part: \"complex_opt2\" "
3390 " is_extension: true "
3393 " name_part: \"barney\" "
3394 " is_extension: false "
3396 " aggregate_value: \"waldo: 100\" "
3408 options.GetExtension(protobuf_unittest::complex_opt2).barney_size());
3410 1,
options.GetExtension(protobuf_unittest::complex_opt2).barney(0).waldo());
3413 options.GetExtension(protobuf_unittest::complex_opt2).barney(1).waldo());
3416 options.GetExtension(protobuf_unittest::complex_opt2).barney(2).waldo());
3421 TEST(CustomOptions, AggregateOptions) {
3432 const protobuf_unittest::Aggregate& file_options =
3433 file->
options().GetExtension(protobuf_unittest::fileopt);
3435 EXPECT_EQ(
"FileAnnotation", file_options.s());
3436 EXPECT_EQ(
"NestedFileAnnotation", file_options.sub().s());
3438 file_options.file().GetExtension(protobuf_unittest::fileopt).s());
3441 .GetExtension(protobuf_unittest::AggregateMessageSetElement ::
3442 message_set_extension)
3447 msg->
options().GetExtension(protobuf_unittest::msgopt).s());
3449 field->options().GetExtension(protobuf_unittest::fieldopt).s());
3451 enumd->
options().GetExtension(protobuf_unittest::enumopt).s());
3453 enumv->
options().GetExtension(protobuf_unittest::enumvalopt).s());
3455 service->
options().GetExtension(protobuf_unittest::serviceopt).s());
3457 method->
options().GetExtension(protobuf_unittest::methodopt).s());
3460 TEST(CustomOptions, UnusedImportWarning) {
3471 pool.AddUnusedImportTrackFile(
"custom_options_import.proto");
3473 "name: \"custom_options_import.proto\" "
3474 "package: \"protobuf_unittest\" "
3475 "dependency: \"google/protobuf/unittest_custom_options.proto\" ",
3479 EXPECT_TRUE(
pool.BuildFileCollectingErrors(file_proto, &error_collector));
3486 TEST(CustomOptions, OptionsWithIncompatibleDescriptors) {
3496 file_proto.
set_name(
"unittest_custom_options.proto");
3504 ->FindExtensionByName(
"required_enum_opt")
3514 extension->set_type_name(
".protobuf_unittest.NewOptionType");
3523 " name_part: 'required_enum_opt' "
3524 " is_extension: true "
3526 " aggregate_value: 'value: NEW_VALUE'"
3552 "name: \"foo.proto\" "
3553 "package: \"protobuf_unittest\" "
3554 "dependency: \"google/protobuf/descriptor.proto\" "
3556 " uninterpreted_option { "
3558 " name_part: \"protobuf_unittest.cc_option1\" "
3559 " is_extension: true "
3561 " positive_int_value: 1 "
3563 " uninterpreted_option { "
3565 " name_part: \"protobuf_unittest.cc_option2\" "
3566 " is_extension: true "
3568 " positive_int_value: 2 "
3572 " name: \"cc_option1\" "
3573 " extendee: \".google.protobuf.FileOptions\" "
3580 " label: LABEL_OPTIONAL "
3581 " type: TYPE_INT32 "
3584 " name: \"cc_option2\" "
3585 " extendee: \".google.protobuf.FileOptions\" "
3587 " label: LABEL_OPTIONAL "
3588 " type: TYPE_INT32 "
3597 "syntax = \"proto2\";\n"
3599 "import \"google/protobuf/descriptor.proto\";\n"
3600 "package protobuf_unittest;\n"
3602 "option (.protobuf_unittest.cc_option1) = 1;\n"
3603 "option (.protobuf_unittest.cc_option2) = 2;\n"
3605 "extend .google.protobuf.FileOptions {\n"
3606 " optional int32 cc_option1 = 7736974;\n"
3607 " optional int32 cc_option2 = 7736975;\n"
3655 file->
CopyTo(&file_proto);
3669 BuildFileWithErrors(
3670 "name: \"foo.proto\" "
3671 "message_type { name: \"Foo\" }"
3672 "message_type { name: \"Foo\" }",
3674 "foo.proto: Foo: NAME: \"Foo\" is already defined.\n");
3678 BuildFileWithErrors(
3679 "name: \"foo.proto\" "
3680 "package: \"foo.bar\" "
3681 "message_type { name: \"Foo\" }"
3682 "message_type { name: \"Foo\" }",
3684 "foo.proto: foo.bar.Foo: NAME: \"Foo\" is already defined in "
3690 "name: \"foo.proto\" "
3691 "message_type { name: \"Foo\" }");
3693 BuildFileWithErrors(
3694 "name: \"bar.proto\" "
3695 "message_type { name: \"Foo\" }",
3697 "bar.proto: Foo: NAME: \"Foo\" is already defined in file "
3698 "\"foo.proto\".\n");
3703 "name: \"foo.proto\" "
3704 "message_type { name: \"foo\" }");
3705 BuildFileWithErrors(
3706 "name: \"bar.proto\" "
3707 "package: \"foo.bar\"",
3709 "bar.proto: foo: NAME: \"foo\" is already defined (as something other "
3710 "than a package) in file \"foo.proto\".\n");
3714 BuildFileWithErrors(
3715 "name: \"foo.proto\" "
3716 "enum_type { name: \"Foo\" value { name: \"FOO\" number: 1 } } "
3717 "enum_type { name: \"Bar\" value { name: \"FOO\" number: 1 } } ",
3719 "foo.proto: FOO: NAME: \"FOO\" is already defined.\n"
3720 "foo.proto: FOO: NAME: Note that enum values use C++ scoping rules, "
3721 "meaning that enum values are siblings of their type, not children of "
3722 "it. Therefore, \"FOO\" must be unique within the global scope, not "
3723 "just within \"Bar\".\n");
3727 BuildFileWithErrors(
3728 "name: \"foo.proto\" "
3730 "enum_type { name: \"Foo\" value { name: \"FOO\" number: 1 } } "
3731 "enum_type { name: \"Bar\" value { name: \"FOO\" number: 1 } } ",
3733 "foo.proto: pkg.FOO: NAME: \"FOO\" is already defined in \"pkg\".\n"
3734 "foo.proto: pkg.FOO: NAME: Note that enum values use C++ scoping rules, "
3735 "meaning that enum values are siblings of their type, not children of "
3736 "it. Therefore, \"FOO\" must be unique within \"pkg\", not just within "
3741 BuildFileWithErrors(
3742 "name: \"foo.proto\" "
3745 "foo.proto: : NAME: Missing name.\n");
3749 BuildFileWithErrors(
3750 "name: \"foo.proto\" "
3751 "message_type { name: \"$\" }",
3753 "foo.proto: $: NAME: \"$\" is not a valid identifier.\n");
3757 BuildFileWithErrors(
3758 "name: \"foo.proto\" "
3759 "package: \"foo.$\"",
3761 "foo.proto: foo.$: NAME: \"$\" is not a valid identifier.\n");
3765 BuildFileWithErrors(
"",
3767 ": : OTHER: Missing field: FileDescriptorProto.name.\n");
3771 BuildFile(
"name: \"foo.proto\"");
3772 BuildFileWithErrors(
3773 "name: \"bar.proto\" "
3774 "dependency: \"foo.proto\" "
3775 "dependency: \"foo.proto\" ",
3777 "bar.proto: foo.proto: IMPORT: Import \"foo.proto\" was listed twice.\n");
3781 BuildFileWithErrors(
3782 "name: \"bar.proto\" "
3783 "dependency: \"foo.proto\" ",
3785 "bar.proto: foo.proto: IMPORT: Import \"foo.proto\" has not been "
3790 BuildFile(
"name: \"foo.proto\"");
3791 BuildFileWithErrors(
3792 "name: \"bar.proto\" "
3793 "dependency: \"foo.proto\" "
3794 "public_dependency: 1",
3795 "bar.proto: bar.proto: OTHER: Invalid public dependency index.\n");
3805 "name: 'foo.proto' "
3806 "package: 'outer.foo' ");
3807 BuildFileWithErrors(
3808 "name: 'bar.proto' "
3809 "dependency: 'baz.proto' "
3810 "package: 'outer.bar' "
3813 " field { name:'bar' number:1 label:LABEL_OPTIONAL type_name:'foo.Foo' }"
3816 "bar.proto: baz.proto: IMPORT: Import \"baz.proto\" has not been "
3818 "bar.proto: outer.bar.Bar.bar: TYPE: \"outer.foo\" seems to be defined "
3820 "\"foo.proto\", which is not imported by \"bar.proto\". To use it here, "
3821 "please add the necessary import.\n");
3826 "name: \"foo.proto\" "
3827 "message_type { name: \"Foo\" }");
3830 BuildFileWithErrors(
3831 "name: \"foo.proto\" "
3832 "message_type { name: \"Foo\" } "
3835 "enum_type { name: \"Bar\" }",
3837 "foo.proto: foo.proto: OTHER: A file with this name is already in the "
3842 BuildFileWithErrors(
3843 "name: \"foo.proto\" "
3846 " field { name: \"foo\" number: 9 label:LABEL_OPTIONAL type:TYPE_INT32 "
3848 " field { name: \"bar\" number: 10 label:LABEL_OPTIONAL type:TYPE_INT32 "
3850 " field { name: \"baz\" number: 19 label:LABEL_OPTIONAL type:TYPE_INT32 "
3852 " field { name: \"qux\" number: 20 label:LABEL_OPTIONAL type:TYPE_INT32 "
3854 " extension_range { start: 10 end: 20 }"
3857 "foo.proto: Foo.bar: NUMBER: Extension range 10 to 19 includes field "
3859 "foo.proto: Foo.baz: NUMBER: Extension range 10 to 19 includes field "
3864 BuildFileWithErrors(
3865 "name: \"foo.proto\" "
3868 " extension_range { start: 10 end: 20 }"
3869 " extension_range { start: 20 end: 30 }"
3870 " extension_range { start: 19 end: 21 }"
3873 "foo.proto: Foo: NUMBER: Extension range 19 to 20 overlaps with "
3874 "already-defined range 10 to 19.\n"
3875 "foo.proto: Foo: NUMBER: Extension range 19 to 20 overlaps with "
3876 "already-defined range 20 to 29.\n");
3880 BuildFileWithErrors(
3881 "name: \"foo.proto\" "
3884 " field { name: \"foo\" number: 15 label:LABEL_OPTIONAL type:TYPE_INT32 "
3886 " reserved_range { start: 10 end: 20 }"
3889 "foo.proto: Foo.foo: NUMBER: Field \"foo\" uses reserved number 15.\n");
3893 BuildFileWithErrors(
3894 "name: \"foo.proto\" "
3897 " extension_range { start: 10 end: 20 }"
3898 " reserved_range { start: 5 end: 15 }"
3901 "foo.proto: Foo: NUMBER: Extension range 10 to 19"
3902 " overlaps with reserved range 5 to 14.\n");
3907 "name: \"foo.proto\" "
3910 " extension_range { start: 10 end: 20 }"
3911 " reserved_range { start: 5 end: 10 }"
3916 BuildFileWithErrors(
3917 "name: \"foo.proto\" "
3920 " reserved_range { start: 10 end: 20 }"
3921 " reserved_range { start: 5 end: 15 }"
3924 "foo.proto: Foo: NUMBER: Reserved range 5 to 14"
3925 " overlaps with already-defined range 10 to 19.\n");
3929 BuildFileWithErrors(
3930 "name: \"foo.proto\" "
3933 " field { name: \"foo\" number: 15 label:LABEL_OPTIONAL type:TYPE_INT32 "
3935 " field { name: \"bar\" number: 16 label:LABEL_OPTIONAL type:TYPE_INT32 "
3937 " field { name: \"baz\" number: 17 label:LABEL_OPTIONAL type:TYPE_INT32 "
3939 " reserved_name: \"foo\""
3940 " reserved_name: \"bar\""
3943 "foo.proto: Foo.foo: NAME: Field name \"foo\" is reserved.\n"
3944 "foo.proto: Foo.bar: NAME: Field name \"bar\" is reserved.\n");
3948 BuildFileWithErrors(
3949 "name: \"foo.proto\" "
3952 " reserved_name: \"foo\""
3953 " reserved_name: \"foo\""
3956 "foo.proto: foo: NAME: Field name \"foo\" is reserved multiple times.\n");
3961 "name: \"foo.proto\" "
3964 " reserved_name: \"foo\""
3965 " reserved_name: \"bar\""
3966 " reserved_range { start: 5 end: 6 }"
3967 " reserved_range { start: 10 end: 20 }"
3971 "syntax = \"proto2\";\n\n"
3973 " reserved 5, 10 to 19;\n"
3974 " reserved \"foo\", \"bar\";\n"
3980 BuildFileWithErrors(
3981 "name: \"foo.proto\" "
3984 " value { name:\"BAR\" number:15 }"
3985 " reserved_range { start: 10 end: 20 }"
3988 "foo.proto: BAR: NUMBER: Enum value \"BAR\" uses reserved number 15.\n");
3992 BuildFileWithErrors(
3993 "name: \"foo.proto\" "
3996 " value { name:\"BAR\" number:-15 }"
3997 " reserved_range { start: -20 end: -10 }"
4000 "foo.proto: BAR: NUMBER: Enum value \"BAR\" uses reserved number -15.\n");
4004 BuildFileWithErrors(
4005 "name: \"foo.proto\" "
4008 " value { name:\"BAR\" number:0 }"
4009 " reserved_range { start: 10 end: 20 }"
4010 " reserved_range { start: 5 end: 15 }"
4013 "foo.proto: Foo: NUMBER: Reserved range 5 to 15"
4014 " overlaps with already-defined range 10 to 20.\n");
4018 BuildFileWithErrors(
4019 "name: \"foo.proto\" "
4022 " value { name:\"BAR\" number:0 }"
4023 " reserved_range { start: 10 end: 20 }"
4024 " reserved_range { start: 5 end: 10 }"
4027 "foo.proto: Foo: NUMBER: Reserved range 5 to 10"
4028 " overlaps with already-defined range 10 to 20.\n");
4032 BuildFileWithErrors(
4033 "name: \"foo.proto\" "
4036 " value { name:\"BAR\" number:0 }"
4037 " reserved_range { start: -20 end: -10 }"
4038 " reserved_range { start: -15 end: -5 }"
4041 "foo.proto: Foo: NUMBER: Reserved range -15 to -5"
4042 " overlaps with already-defined range -20 to -10.\n");
4046 BuildFileWithErrors(
4047 "name: \"foo.proto\" "
4050 " value { name:\"BAR\" number:20 }"
4051 " reserved_range { start: -20 end: 10 }"
4052 " reserved_range { start: -15 end: 5 }"
4055 "foo.proto: Foo: NUMBER: Reserved range -15 to 5"
4056 " overlaps with already-defined range -20 to 10.\n");
4060 BuildFileWithErrors(
4061 "name: \"foo.proto\" "
4064 " value { name:\"BAR\" number:20 }"
4065 " reserved_range { start: -20 end: 10 }"
4066 " reserved_range { start: 10 end: 10 }"
4069 "foo.proto: Foo: NUMBER: Reserved range 10 to 10"
4070 " overlaps with already-defined range -20 to 10.\n");
4074 BuildFileWithErrors(
4075 "name: \"foo.proto\" "
4078 " value { name:\"BAR\" number:20 }"
4079 " reserved_range { start: 11 end: 10 }"
4082 "foo.proto: Foo: NUMBER: Reserved range end number must be greater"
4083 " than start number.\n");
4087 BuildFileWithErrors(
4088 "name: \"foo.proto\" "
4091 " value { name:\"FOO\" number:15 }"
4092 " value { name:\"BAR\" number:15 }"
4093 " reserved_name: \"FOO\""
4094 " reserved_name: \"BAR\""
4097 "foo.proto: FOO: NAME: Enum value \"FOO\" is reserved.\n"
4098 "foo.proto: BAR: NAME: Enum value \"BAR\" is reserved.\n");
4102 BuildFileWithErrors(
4103 "name: \"foo.proto\" "
4106 " value { name:\"FOO\" number:15 }"
4107 " reserved_name: \"foo\""
4108 " reserved_name: \"foo\""
4111 "foo.proto: foo: NAME: Enum value \"foo\" is reserved multiple times.\n");
4116 "name: \"foo.proto\" "
4119 " value { name:\"FOO\" number:3 }"
4120 " reserved_name: \"foo\""
4121 " reserved_name: \"bar\""
4122 " reserved_range { start: -6 end: -6 }"
4123 " reserved_range { start: -5 end: -4 }"
4124 " reserved_range { start: -1 end: 1 }"
4125 " reserved_range { start: 5 end: 5 }"
4126 " reserved_range { start: 10 end: 19 }"
4130 "syntax = \"proto2\";\n\n"
4133 " reserved -6, -5 to -4, -1 to 1, 5, 10 to 19;\n"
4134 " reserved \"foo\", \"bar\";\n"
4140 BuildFileWithErrors(
4141 "name: \"foo.proto\" "
4146 " field { name: \"foo\" number: 1 label: LABEL_OPTIONAL type: TYPE_INT32"
4147 " default_value: \"abc\" }"
4150 " field { name: \"bar\" number: 2 label: LABEL_OPTIONAL type: TYPE_INT32"
4151 " default_value: \"\" }"
4154 " field { name: \"baz\" number: 3 label: LABEL_OPTIONAL type: TYPE_BOOL"
4155 " default_value: \"abc\" }"
4158 " field { name: \"qux\" number: 4 label: LABEL_OPTIONAL type: "
4160 " default_value: \"abc\" type_name: \"Foo\" }"
4164 " field { name: \"quux\" number: 5 label: LABEL_OPTIONAL"
4165 " default_value: \"abc\" type_name: \"Foo\" }"
4168 " field { name: \"corge\" number: 6 label: LABEL_REPEATED type: "
4170 " default_value: \"1\" }"
4173 "foo.proto: Foo.foo: DEFAULT_VALUE: Couldn't parse default value "
4175 "foo.proto: Foo.bar: DEFAULT_VALUE: Couldn't parse default value \"\".\n"
4176 "foo.proto: Foo.baz: DEFAULT_VALUE: Boolean default must be true or "
4178 "foo.proto: Foo.qux: DEFAULT_VALUE: Messages can't have default values.\n"
4179 "foo.proto: Foo.corge: DEFAULT_VALUE: Repeated fields can't have default "
4183 "foo.proto: Foo.quux: DEFAULT_VALUE: Messages can't have default "
4188 BuildFileWithErrors(
4189 "name: \"foo.proto\" "
4192 " field { name: \"foo\" number: -1 label:LABEL_OPTIONAL type:TYPE_INT32 "
4196 "foo.proto: Foo.foo: NUMBER: Field numbers must be positive integers.\n");
4200 BuildFileWithErrors(
4201 "name: \"foo.proto\" "
4204 " field { name: \"foo\" number: 0x70000000 "
4205 " label:LABEL_OPTIONAL type:TYPE_INT32 }"
4208 "foo.proto: Foo.foo: NUMBER: Field numbers cannot be greater than "
4213 BuildFileWithErrors(
4214 "name: \"foo.proto\" "
4217 " field {name:\"foo\" number: 18999 label:LABEL_OPTIONAL "
4219 " field {name:\"bar\" number: 19000 label:LABEL_OPTIONAL "
4221 " field {name:\"baz\" number: 19999 label:LABEL_OPTIONAL "
4223 " field {name:\"qux\" number: 20000 label:LABEL_OPTIONAL "
4227 "foo.proto: Foo.bar: NUMBER: Field numbers 19000 through 19999 are "
4228 "reserved for the protocol buffer library implementation.\n"
4229 "foo.proto: Foo.baz: NUMBER: Field numbers 19000 through 19999 are "
4230 "reserved for the protocol buffer library implementation.\n");
4234 BuildFileWithErrors(
4235 "name: \"foo.proto\" "
4238 " extension { name: \"foo\" number: 1 label: LABEL_OPTIONAL"
4239 " type_name: \"Foo\" }"
4242 "foo.proto: Foo.foo: EXTENDEE: FieldDescriptorProto.extendee not set for "
4243 "extension field.\n");
4247 BuildFileWithErrors(
4248 "name: \"foo.proto\" "
4251 " extension_range { start: 1 end: 2 }"
4255 " field { name: \"foo\" number: 1 label: LABEL_OPTIONAL"
4256 " type_name: \"Foo\" extendee: \"Bar\" }"
4259 "foo.proto: Foo.foo: EXTENDEE: FieldDescriptorProto.extendee set for "
4260 "non-extension field.\n");
4264 BuildFileWithErrors(
4265 "name: \"foo.proto\" "
4268 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_INT32 "
4270 " field { name:\"dummy\" number:2 label:LABEL_OPTIONAL type:TYPE_INT32 "
4272 " oneof_decl { name:\"bar\" }"
4275 "foo.proto: Foo.foo: TYPE: FieldDescriptorProto.oneof_index 1 is out of "
4276 "range for type \"Foo\".\n");
4280 BuildFileWithErrors(
4281 "name: \"foo.proto\" "
4284 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_INT32 "
4285 " oneof_index: -1 }"
4286 " field { name:\"dummy\" number:2 label:LABEL_OPTIONAL type:TYPE_INT32 "
4288 " oneof_decl { name:\"bar\" }"
4291 "foo.proto: Foo.foo: TYPE: FieldDescriptorProto.oneof_index -1 is out "
4293 "range for type \"Foo\".\n");
4298 BuildFileWithErrors(
4299 "name: \"foo.proto\" "
4302 " field { name:\"foo1\" number: 1 label:LABEL_OPTIONAL type:TYPE_INT32 "
4304 " field { name:\"bar\" number: 2 label:LABEL_OPTIONAL type:TYPE_INT32 }"
4305 " field { name:\"foo2\" number: 3 label:LABEL_OPTIONAL type:TYPE_INT32 "
4307 " oneof_decl { name:\"foos\" }"
4310 "foo.proto: Foo.bar: TYPE: Fields in the same oneof must be defined "
4311 "consecutively. \"bar\" cannot be defined before the completion of the "
4312 "\"foos\" oneof definition.\n");
4315 BuildFileWithErrors(
4316 "name: \"foo2.proto\" "
4319 " field { name:\"foo1\" number: 1 label:LABEL_OPTIONAL type:TYPE_INT32 "
4321 " field { name:\"bar1\" number: 2 label:LABEL_OPTIONAL type:TYPE_INT32 "
4323 " field { name:\"foo2\" number: 3 label:LABEL_OPTIONAL type:TYPE_INT32 "
4325 " field { name:\"bar2\" number: 4 label:LABEL_OPTIONAL type:TYPE_INT32 "
4327 " oneof_decl { name:\"foos\" }"
4328 " oneof_decl { name:\"bars\" }"
4330 "foo2.proto: Foo2.bar1: TYPE: Fields in the same oneof must be defined "
4331 "consecutively. \"bar1\" cannot be defined before the completion of the "
4332 "\"foos\" oneof definition.\n"
4333 "foo2.proto: Foo2.foo2: TYPE: Fields in the same oneof must be defined "
4334 "consecutively. \"foo2\" cannot be defined before the completion of the "
4335 "\"bars\" oneof definition.\n");
4338 BuildFileWithErrors(
4339 "name: \"foo3.proto\" "
4342 " field { name:\"foo1\" number: 1 label:LABEL_OPTIONAL type:TYPE_INT32 "
4344 " field { name:\"bar1\" number: 2 label:LABEL_OPTIONAL type:TYPE_INT32 "
4346 " field { name:\"baz\" number: 3 label:LABEL_OPTIONAL type:TYPE_INT32 }"
4347 " field { name:\"foo2\" number: 4 label:LABEL_OPTIONAL type:TYPE_INT32 "
4349 " oneof_decl { name:\"foos\" }"
4350 " oneof_decl { name:\"bars\" }"
4352 "foo3.proto: Foo3.baz: TYPE: Fields in the same oneof must be defined "
4353 "consecutively. \"baz\" cannot be defined before the completion of the "
4354 "\"foos\" oneof definition.\n");
4358 BuildFileWithErrors(
4359 "name: \"foo.proto\" "
4362 " field { name: \"foo\" number: 1 label:LABEL_OPTIONAL type:TYPE_INT32 }"
4363 " field { name: \"bar\" number: 1 label:LABEL_OPTIONAL type:TYPE_INT32 }"
4366 "foo.proto: Foo.bar: NUMBER: Field number 1 has already been used in "
4367 "\"Foo\" by field \"foo\".\n");
4371 BuildFileWithErrors(
4372 "name: \"foo.proto\" "
4374 " name: \"MessageSet\""
4375 " options { message_set_wire_format: true }"
4376 " extension_range { start: 4 end: 5 }"
4380 " extension { name:\"foo\" number:4 label:LABEL_OPTIONAL type:TYPE_INT32"
4381 " extendee: \"MessageSet\" }"
4384 "foo.proto: Foo.foo: TYPE: Extensions of MessageSets must be optional "
4389 BuildFileWithErrors(
4390 "name: \"foo.proto\" "
4392 " name: \"MessageSet\""
4393 " options { message_set_wire_format: true }"
4394 " extension_range { start: 4 end: 5 }"
4398 " extension { name:\"foo\" number:4 label:LABEL_REPEATED "
4400 " type_name: \"Foo\" extendee: \"MessageSet\" }"
4403 "foo.proto: Foo.foo: TYPE: Extensions of MessageSets must be optional "
4408 BuildFileWithErrors(
4409 "name: \"foo.proto\" "
4412 " options { message_set_wire_format: true }"
4413 " field { name: \"foo\" number: 1 label:LABEL_OPTIONAL type:TYPE_INT32 }"
4416 "foo.proto: Foo.foo: NAME: MessageSets cannot have fields, only "
4421 BuildFileWithErrors(
4422 "name: \"foo.proto\" "
4425 " extension_range { start: -10 end: -1 }"
4428 "foo.proto: Foo: NUMBER: Extension numbers must be positive integers.\n");
4432 BuildFileWithErrors(
4433 "name: \"foo.proto\" "
4436 " extension_range { start: 1 end: 0x70000000 }"
4439 "foo.proto: Foo: NUMBER: Extension numbers cannot be greater than "
4444 BuildFileWithErrors(
4445 "name: \"foo.proto\" "
4448 " extension_range { start: 10 end: 10 }"
4449 " extension_range { start: 10 end: 5 }"
4452 "foo.proto: Foo: NUMBER: Extension range end number must be greater than "
4454 "foo.proto: Foo: NUMBER: Extension range end number must be greater than "
4459 BuildFileWithErrors(
4460 "name: \"foo.proto\" "
4461 "enum_type { name: \"Foo\" }"
4467 " field { name: \"foo\" number: 1 label:LABEL_OPTIONAL "
4468 "type_name:\"Foo\" }"
4469 " field { name: \"bar\" number: 2 label:LABEL_OPTIONAL "
4470 "type_name:\"Foo\" "
4471 " default_value: \"NO_SUCH_VALUE\" }"
4474 "foo.proto: Foo: NAME: Enums must contain at least one value.\n"
4475 "foo.proto: Bar.bar: DEFAULT_VALUE: Enum type \"Foo\" has no value named "
4476 "\"NO_SUCH_VALUE\".\n");
4480 BuildFileWithErrors(
4481 "name: \"foo.proto\" "
4484 " extension { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_INT32"
4485 " extendee: \"Bar\" }"
4488 "foo.proto: Foo.foo: EXTENDEE: \"Bar\" is not defined.\n");
4492 BuildFileWithErrors(
4493 "name: \"foo.proto\" "
4494 "enum_type { name: \"Bar\" value { name:\"DUMMY\" number:0 } }"
4497 " extension { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_INT32"
4498 " extendee: \"Bar\" }"
4501 "foo.proto: Foo.foo: EXTENDEE: \"Bar\" is not a message type.\n");
4505 BuildFileWithErrors(
4506 "name: \"foo.proto\" "
4512 " extension { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_INT32"
4513 " extendee: \"Bar\" }"
4516 "foo.proto: Foo.foo: NUMBER: \"Bar\" does not declare 1 as an extension "
4521 BuildFileWithErrors(
4522 "name: \"foo.proto\" "
4525 " extension_range { start: 1000 end: 10000 }"
4532 " label:LABEL_REQUIRED"
4534 " extendee: \"Bar\""
4538 "foo.proto: Foo.foo: TYPE: Message extensions cannot have required "
4543 BuildFileWithErrors(
4544 "name: \"foo.proto\" "
4547 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type_name:\"Bar\" }"
4550 "foo.proto: Foo.foo: TYPE: \"Bar\" is not defined.\n");
4558 BuildFileWithErrors(
4559 "name: \"foo.proto\" "
4562 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type_name:\"int\" "
4563 " default_value:\"1\" }"
4566 "foo.proto: Foo.foo: TYPE: \"int\" is not defined.\n");
4570 BuildFileWithErrors(
4571 "name: \"foo.proto\" "
4574 " nested_type { name:\"Baz\" }"
4575 " field { name:\"foo\" number:1"
4576 " label:LABEL_OPTIONAL"
4577 " type_name:\"Foo.Baz.Bar\" }"
4580 "foo.proto: Foo.foo: TYPE: \"Foo.Baz.Bar\" is not defined.\n");
4585 "name: \"bar.proto\" "
4586 "message_type { name: \"Bar\" } ");
4588 BuildFileWithErrors(
4589 "name: \"foo.proto\" "
4592 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type_name:\"Bar\" }"
4594 "foo.proto: Foo.foo: TYPE: \"Bar\" seems to be defined in \"bar.proto\", "
4595 "which is not imported by \"foo.proto\". To use it here, please add the "
4596 "necessary import.\n");
4615 "name: \"bar.proto\" "
4616 "message_type { name: \"Bar\" }");
4619 "name: \"forward.proto\""
4620 "dependency: \"bar.proto\"");
4622 BuildFileWithErrors(
4623 "name: \"foo.proto\" "
4624 "dependency: \"forward.proto\" "
4627 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type_name:\"Bar\" }"
4629 "foo.proto: Foo.foo: TYPE: \"Bar\" seems to be defined in \"bar.proto\", "
4630 "which is not imported by \"foo.proto\". To use it here, please add the "
4631 "necessary import.\n");
4652 "name: \"bar.proto\" "
4653 "message_type { name: \"Bar\" }");
4656 "name: \"forward.proto\""
4657 "dependency: \"bar.proto\" "
4658 "public_dependency: 0");
4661 "name: \"foo.proto\" "
4662 "dependency: \"forward.proto\" "
4665 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type_name:\"Bar\" }"
4688 "name: \"bar.proto\" "
4689 "message_type { name: \"Bar\" }");
4692 "name: \"forward.proto\""
4693 "dependency: \"bar.proto\" "
4694 "public_dependency: 0");
4697 "name: \"forward2.proto\""
4698 "dependency: \"forward.proto\" "
4699 "public_dependency: 0");
4702 "name: \"foo.proto\" "
4703 "dependency: \"forward2.proto\" "
4706 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type_name:\"Bar\" }"
4711 FieldTypeDefinedInPrivateDependencyOfPublicDependency) {
4732 "name: \"bar.proto\" "
4733 "message_type { name: \"Bar\" }");
4736 "name: \"forward.proto\""
4737 "dependency: \"bar.proto\"");
4740 "name: \"forward2.proto\""
4741 "dependency: \"forward.proto\" "
4742 "public_dependency: 0");
4744 BuildFileWithErrors(
4745 "name: \"foo.proto\" "
4746 "dependency: \"forward2.proto\" "
4749 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type_name:\"Bar\" }"
4751 "foo.proto: Foo.foo: TYPE: \"Bar\" seems to be defined in \"bar.proto\", "
4752 "which is not imported by \"foo.proto\". To use it here, please add the "
4753 "necessary import.\n");
4772 BuildFileWithErrors(
4773 "name: \"foo.proto\" "
4776 " nested_type { name: \"Baz\" }"
4780 " nested_type { name: \"Bar\" }"
4781 " field { name:\"baz\" number:1 label:LABEL_OPTIONAL"
4782 " type_name:\"Bar.Baz\" }"
4785 "foo.proto: Foo.baz: TYPE: \"Bar.Baz\" is resolved to \"Foo.Bar.Baz\","
4786 " which is not defined. The innermost scope is searched first in name "
4787 "resolution. Consider using a leading '.'(i.e., \".Bar.Baz\") to start "
4788 "from the outermost scope.\n");
4796 "name: \"foo.proto\" "
4799 " nested_type { name: \"Baz\" }"
4803 " field { name: \"Bar\" number:1 type:TYPE_BYTES } "
4804 " field { name:\"baz\" number:2 label:LABEL_OPTIONAL"
4805 " type_name:\"Bar.Baz\" }"
4832 "name: \"foo.proto\" "
4833 "package: \"foo.bar\" ");
4835 "name: \"bar.proto\" "
4836 "package: \"foo.bar\" "
4837 "dependency: \"foo.proto\" "
4838 "message_type { name: \"Bar\" }");
4840 "name: \"baz.proto\" "
4842 "dependency: \"bar.proto\" "
4845 " field { name:\"qux\" number:1 label:LABEL_OPTIONAL "
4846 " type_name:\"bar.Bar\" }"
4851 BuildFileWithErrors(
4852 "name: \"foo.proto\" "
4855 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL "
4856 " type_name:\".Foo.bar\" }"
4857 " field { name:\"bar\" number:2 label:LABEL_OPTIONAL type:TYPE_INT32 }"
4860 "foo.proto: Foo.foo: TYPE: \".Foo.bar\" is not a type.\n");
4864 BuildFileWithErrors(
4865 "name: \"foo.proto\" "
4869 " field { name:\"Baz\" number:2 label:LABEL_OPTIONAL type:TYPE_INT32 }"
4872 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL "
4873 " type_name:\"Bar.Baz\" }"
4875 "foo.proto: Foo.foo: TYPE: \"Bar.Baz\" is not a type.\n");
4880 "name: \"foo.proto\" "
4886 " field { name:\"Bar\" number:1 label:LABEL_OPTIONAL type_name:\"Bar\" }"
4891 BuildFileWithErrors(
4892 "name: \"foo.proto\" "
4893 "message_type { name: \"Bar\" } "
4896 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_ENUM"
4897 " type_name:\"Bar\" }"
4900 "foo.proto: Foo.foo: TYPE: \"Bar\" is not an enum type.\n");
4904 BuildFileWithErrors(
4905 "name: \"foo.proto\" "
4906 "enum_type { name: \"Bar\" value { name:\"DUMMY\" number:0 } } "
4909 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_MESSAGE"
4910 " type_name:\"Bar\" }"
4913 "foo.proto: Foo.foo: TYPE: \"Bar\" is not a message type.\n");
4917 BuildFileWithErrors(
4918 "name: \"foo.proto\" "
4919 "enum_type { name: \"Bar\" value { name:\"DUMMY\" number:0 } } "
4922 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type_name:\"Bar\""
4923 " default_value:\"NO_SUCH_VALUE\" }"
4926 "foo.proto: Foo.foo: DEFAULT_VALUE: Enum type \"Bar\" has no value named "
4927 "\"NO_SUCH_VALUE\".\n");
4931 BuildFileWithErrors(
4932 "name: \"foo.proto\" "
4933 "enum_type { name: \"Bar\" value { name:\"DUMMY\" number:0 } } "
4936 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type_name:\"Bar\""
4937 " default_value:\"0\" }"
4940 "foo.proto: Foo.foo: DEFAULT_VALUE: Default value for an enum field must "
4941 "be an identifier.\n");
4945 BuildFileWithErrors(
4946 "name: \"foo.proto\" "
4949 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_INT32"
4950 " type_name:\"Foo\" }"
4953 "foo.proto: Foo.foo: TYPE: Field with primitive type has type_name.\n");
4957 BuildFileWithErrors(
4958 "name: \"foo.proto\" "
4961 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_MESSAGE }"
4964 "foo.proto: Foo.foo: TYPE: Field with message or enum type missing "
4969 BuildFileWithErrors(
4970 "name: \"foo.proto\" "
4973 " oneof_decl { name:\"bar\" }"
4976 "foo.proto: Foo.bar: NAME: Oneof must have at least one field.\n");
4980 BuildFileWithErrors(
4981 "name: \"foo.proto\" "
4984 " field { name:\"foo\" number:1 label:LABEL_REPEATED type:TYPE_INT32 "
4986 " oneof_decl { name:\"bar\" }"
4989 "foo.proto: Foo.foo: NAME: Fields of oneofs must themselves have label "
4990 "LABEL_OPTIONAL.\n");
4994 BuildFileWithErrors(
4995 "name: \"foo.proto\" "
4996 "message_type { name: \"Foo\" } "
4998 " name: \"TestService\""
4999 " method { name: \"A\" input_type: \"Bar\" output_type: \"Foo\" }"
5002 "foo.proto: TestService.A: INPUT_TYPE: \"Bar\" is not defined.\n"
5007 BuildFileWithErrors(
5008 "name: \"foo.proto\" "
5009 "message_type { name: \"Foo\" } "
5010 "enum_type { name: \"Bar\" value { name:\"DUMMY\" number:0 } } "
5012 " name: \"TestService\""
5013 " method { name: \"A\" input_type: \"Bar\" output_type: \"Foo\" }"
5016 "foo.proto: TestService.A: INPUT_TYPE: \"Bar\" is not a message type.\n"
5021 BuildFileWithErrors(
5022 "name: \"foo.proto\" "
5023 "message_type { name: \"Foo\" } "
5025 " name: \"TestService\""
5026 " method { name: \"A\" input_type: \"Foo\" output_type: \"Bar\" }"
5029 "foo.proto: TestService.A: OUTPUT_TYPE: \"Bar\" is not defined.\n"
5034 BuildFileWithErrors(
5035 "name: \"foo.proto\" "
5036 "message_type { name: \"Foo\" } "
5037 "enum_type { name: \"Bar\" value { name:\"DUMMY\" number:0 } } "
5039 " name: \"TestService\""
5040 " method { name: \"A\" input_type: \"Foo\" output_type: \"Bar\" }"
5043 "foo.proto: TestService.A: OUTPUT_TYPE: \"Bar\" is not a message type.\n"
5049 BuildFileWithErrors(
5050 "name: \"foo.proto\" "
5053 " field { name:\"packed_string\" number:1 label:LABEL_REPEATED "
5054 " type:TYPE_STRING "
5055 " options { uninterpreted_option {"
5056 " name { name_part: \"packed\" is_extension: false }"
5057 " identifier_value: \"true\" }}}\n"
5058 " field { name:\"packed_message\" number:3 label:LABEL_REPEATED "
5059 " type_name: \"Foo\""
5060 " options { uninterpreted_option {"
5061 " name { name_part: \"packed\" is_extension: false }"
5062 " identifier_value: \"true\" }}}\n"
5063 " field { name:\"optional_int32\" number: 4 label: LABEL_OPTIONAL "
5065 " options { uninterpreted_option {"
5066 " name { name_part: \"packed\" is_extension: false }"
5067 " identifier_value: \"true\" }}}\n"
5070 "foo.proto: Foo.packed_string: TYPE: [packed = true] can only be "
5071 "specified for repeated primitive fields.\n"
5072 "foo.proto: Foo.packed_message: TYPE: [packed = true] can only be "
5073 "specified for repeated primitive fields.\n"
5074 "foo.proto: Foo.optional_int32: TYPE: [packed = true] can only be "
5075 "specified for repeated primitive fields.\n");
5079 BuildFileWithErrors(
5080 "name: \"foo.proto\" "
5082 " name: \"TestMessage\" "
5083 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_STRING "
5084 " options { uninterpreted_option { name { name_part: \"ctype\" "
5085 " is_extension: false }"
5086 " positive_int_value: 1 }"
5091 "foo.proto: TestMessage.foo: OPTION_VALUE: Value must be identifier for "
5092 "enum-valued option \"google.protobuf.FieldOptions.ctype\".\n");
5096 BuildFileWithErrors(
5097 "name: \"foo.proto\" "
5099 " name: \"TestMessage\" "
5100 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_STRING "
5101 " options { uninterpreted_option { name { name_part: \"ctype\" "
5102 " is_extension: false }"
5103 " name { name_part: \"foo\" "
5104 " is_extension: true }"
5105 " positive_int_value: 1 }"
5110 "foo.proto: TestMessage.foo: OPTION_NAME: Option \"ctype\" is an "
5111 "atomic type, not a message.\n");
5115 BuildFileWithErrors(
5116 "name: \"foo.proto\" "
5118 " name: \"TestMessage\" "
5119 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_UINT32 "
5120 " options { uninterpreted_option { name { name_part: \"ctype\" "
5121 " is_extension: false }"
5122 " identifier_value: \"CORD\" }"
5123 " uninterpreted_option { name { name_part: \"ctype\" "
5124 " is_extension: false }"
5125 " identifier_value: \"CORD\" }"
5130 "foo.proto: TestMessage.foo: OPTION_NAME: Option \"ctype\" was "
5135 BuildFileWithErrors(
5136 "name: \"foo.proto\" "
5138 " name: \"TestMessage\" "
5139 " field { name:\"foo\" number:1 label:LABEL_OPTIONAL type:TYPE_BOOL "
5140 " options { uninterpreted_option { "
5141 " name { name_part: \"uninterpreted_option\" "
5142 " is_extension: false }"
5143 " positive_int_value: 1 "
5149 "foo.proto: TestMessage.foo: OPTION_NAME: Option must not use "
5150 "reserved name \"uninterpreted_option\".\n");
5154 BuildDescriptorMessagesInTestPool();
5156 BuildFileWithErrors(
5157 "name: \"foo.proto\" "
5158 "dependency: \"google/protobuf/descriptor.proto\" "
5159 "message_type: { name: \"Bar\" field: { "
5160 " name: \"foo\" number: 1 label: LABEL_OPTIONAL type: TYPE_INT32 } "
5162 "extension { name: \"bar\" number: 7672757 label: LABEL_REPEATED "
5163 " type: TYPE_MESSAGE type_name: \"Bar\" "
5164 " extendee: \"google.protobuf.FileOptions\" }"
5165 "options { uninterpreted_option { name { name_part: \"bar\" "
5166 " is_extension: true } "
5167 " name { name_part: \"foo\" "
5168 " is_extension: false } "
5169 " positive_int_value: 1 } }",
5171 "foo.proto: foo.proto: OPTION_NAME: Option field \"(bar)\" is a "
5172 "repeated message. Repeated message options must be initialized "
5173 "using an aggregate value.\n");
5192 BuildDescriptorMessagesInTestPool();
5195 "name: \"foo.proto\" "
5197 "dependency: \"google/protobuf/descriptor.proto\" "
5198 "message_type: { name: \"Bar\" field: { "
5199 " name: \"foo\" number: 1 label: LABEL_OPTIONAL type: TYPE_INT32 } "
5201 "extension { name: \"bar\" number: 7672757 label: LABEL_OPTIONAL "
5202 " type: TYPE_MESSAGE type_name: \"Bar\" "
5203 " extendee: \"google.protobuf.FileOptions\" }");
5205 BuildFileWithErrors(
5206 "name: \"qux.proto\" "
5207 "package: \"qux.baz\" "
5208 "options { uninterpreted_option { name { name_part: \"baz.bar\" "
5209 " is_extension: true } "
5210 " name { name_part: \"foo\" "
5211 " is_extension: false } "
5212 " positive_int_value: 1 } }",
5214 "qux.proto: qux.proto: OPTION_NAME: Option \"(baz.bar)\" is resolved to "
5215 "\"(qux.baz.bar)\","
5216 " which is not defined. The innermost scope is searched first in name "
5217 "resolution. Consider using a leading '.'(i.e., \"(.baz.bar)\") to start "
5218 "from the outermost scope.\n");
5222 BuildFileWithErrors(
5223 "name: \"qux.proto\" "
5224 "package: \"qux.baz\" "
5225 "options { uninterpreted_option { name { name_part: \"baaz.bar\" "
5226 " is_extension: true } "
5227 " name { name_part: \"foo\" "
5228 " is_extension: false } "
5229 " positive_int_value: 1 } }",
5231 "qux.proto: qux.proto: OPTION_NAME: Option \"(baaz.bar)\" unknown. "
5233 "that your proto definition file imports the proto which defines the "
5238 BuildDescriptorMessagesInTestPool();
5240 BuildFileWithErrors(
5241 "name: \"foo.proto\" "
5242 "dependency: \"google/protobuf/descriptor.proto\" "
5243 "extension { name: \"foo1\" number: 7672757 label: LABEL_OPTIONAL "
5244 " type: TYPE_INT32 extendee: \"google.protobuf.FieldOptions\" }"
5245 "extension { name: \"foo2\" number: 7672757 label: LABEL_OPTIONAL "
5246 " type: TYPE_INT32 extendee: \"google.protobuf.FieldOptions\" }",
5248 "foo.proto: foo2: NUMBER: Extension number 7672757 has already been used "
5249 "in \"google.protobuf.FieldOptions\" by extension \"foo1\".\n");
5253 BuildDescriptorMessagesInTestPool();
5255 BuildFileWithErrors(
5256 "name: \"foo.proto\" "
5257 "dependency: \"google/protobuf/descriptor.proto\" "
5258 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5259 " type: TYPE_INT32 extendee: \"google.protobuf.FileOptions\" }"
5260 "options { uninterpreted_option { name { name_part: \"foo\" "
5261 " is_extension: true } "
5262 " positive_int_value: 0x80000000 } "
5265 "foo.proto: foo.proto: OPTION_VALUE: Value out of range "
5266 "for int32 option \"foo\".\n");
5270 BuildDescriptorMessagesInTestPool();
5272 BuildFileWithErrors(
5273 "name: \"foo.proto\" "
5274 "dependency: \"google/protobuf/descriptor.proto\" "
5275 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5276 " type: TYPE_INT32 extendee: \"google.protobuf.FileOptions\" }"
5277 "options { uninterpreted_option { name { name_part: \"foo\" "
5278 " is_extension: true } "
5279 " negative_int_value: -0x80000001 } "
5282 "foo.proto: foo.proto: OPTION_VALUE: Value out of range "
5283 "for int32 option \"foo\".\n");
5287 BuildDescriptorMessagesInTestPool();
5289 BuildFileWithErrors(
5290 "name: \"foo.proto\" "
5291 "dependency: \"google/protobuf/descriptor.proto\" "
5292 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5293 " type: TYPE_INT32 extendee: \"google.protobuf.FileOptions\" }"
5294 "options { uninterpreted_option { name { name_part: \"foo\" "
5295 " is_extension: true } "
5296 " string_value: \"5\" } }",
5298 "foo.proto: foo.proto: OPTION_VALUE: Value must be integer "
5299 "for int32 option \"foo\".\n");
5303 BuildDescriptorMessagesInTestPool();
5305 BuildFileWithErrors(
5306 "name: \"foo.proto\" "
5307 "dependency: \"google/protobuf/descriptor.proto\" "
5308 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5309 " type: TYPE_INT64 extendee: \"google.protobuf.FileOptions\" }"
5310 "options { uninterpreted_option { name { name_part: \"foo\" "
5311 " is_extension: true } "
5312 " positive_int_value: 0x8000000000000000 "
5316 "foo.proto: foo.proto: OPTION_VALUE: Value out of range "
5317 "for int64 option \"foo\".\n");
5321 BuildDescriptorMessagesInTestPool();
5323 BuildFileWithErrors(
5324 "name: \"foo.proto\" "
5325 "dependency: \"google/protobuf/descriptor.proto\" "
5326 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5327 " type: TYPE_INT64 extendee: \"google.protobuf.FileOptions\" }"
5328 "options { uninterpreted_option { name { name_part: \"foo\" "
5329 " is_extension: true } "
5330 " identifier_value: \"5\" } }",
5332 "foo.proto: foo.proto: OPTION_VALUE: Value must be integer "
5333 "for int64 option \"foo\".\n");
5337 BuildDescriptorMessagesInTestPool();
5339 BuildFileWithErrors(
5340 "name: \"foo.proto\" "
5341 "dependency: \"google/protobuf/descriptor.proto\" "
5342 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5343 " type: TYPE_UINT32 extendee: \"google.protobuf.FileOptions\" }"
5344 "options { uninterpreted_option { name { name_part: \"foo\" "
5345 " is_extension: true } "
5346 " positive_int_value: 0x100000000 } }",
5348 "foo.proto: foo.proto: OPTION_VALUE: Value out of range "
5349 "for uint32 option \"foo\".\n");
5353 BuildDescriptorMessagesInTestPool();
5355 BuildFileWithErrors(
5356 "name: \"foo.proto\" "
5357 "dependency: \"google/protobuf/descriptor.proto\" "
5358 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5359 " type: TYPE_UINT32 extendee: \"google.protobuf.FileOptions\" }"
5360 "options { uninterpreted_option { name { name_part: \"foo\" "
5361 " is_extension: true } "
5362 " double_value: -5.6 } }",
5364 "foo.proto: foo.proto: OPTION_VALUE: Value must be non-negative integer "
5365 "for uint32 option \"foo\".\n");
5369 BuildDescriptorMessagesInTestPool();
5371 BuildFileWithErrors(
5372 "name: \"foo.proto\" "
5373 "dependency: \"google/protobuf/descriptor.proto\" "
5374 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5375 " type: TYPE_UINT64 extendee: \"google.protobuf.FileOptions\" }"
5376 "options { uninterpreted_option { name { name_part: \"foo\" "
5377 " is_extension: true } "
5378 " negative_int_value: -5 } }",
5380 "foo.proto: foo.proto: OPTION_VALUE: Value must be non-negative integer "
5381 "for uint64 option \"foo\".\n");
5385 BuildDescriptorMessagesInTestPool();
5387 BuildFileWithErrors(
5388 "name: \"foo.proto\" "
5389 "dependency: \"google/protobuf/descriptor.proto\" "
5390 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5391 " type: TYPE_FLOAT extendee: \"google.protobuf.FileOptions\" }"
5392 "options { uninterpreted_option { name { name_part: \"foo\" "
5393 " is_extension: true } "
5394 " string_value: \"bar\" } }",
5396 "foo.proto: foo.proto: OPTION_VALUE: Value must be number "
5397 "for float option \"foo\".\n");
5401 BuildDescriptorMessagesInTestPool();
5403 BuildFileWithErrors(
5404 "name: \"foo.proto\" "
5405 "dependency: \"google/protobuf/descriptor.proto\" "
5406 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5407 " type: TYPE_DOUBLE extendee: \"google.protobuf.FileOptions\" }"
5408 "options { uninterpreted_option { name { name_part: \"foo\" "
5409 " is_extension: true } "
5410 " string_value: \"bar\" } }",
5412 "foo.proto: foo.proto: OPTION_VALUE: Value must be number "
5413 "for double option \"foo\".\n");
5417 BuildDescriptorMessagesInTestPool();
5419 BuildFileWithErrors(
5420 "name: \"foo.proto\" "
5421 "dependency: \"google/protobuf/descriptor.proto\" "
5422 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5423 " type: TYPE_BOOL extendee: \"google.protobuf.FileOptions\" }"
5424 "options { uninterpreted_option { name { name_part: \"foo\" "
5425 " is_extension: true } "
5426 " identifier_value: \"bar\" } }",
5428 "foo.proto: foo.proto: OPTION_VALUE: Value must be \"true\" or \"false\" "
5429 "for boolean option \"foo\".\n");
5433 BuildDescriptorMessagesInTestPool();
5435 BuildFileWithErrors(
5436 "name: \"foo.proto\" "
5437 "dependency: \"google/protobuf/descriptor.proto\" "
5438 "enum_type { name: \"FooEnum\" value { name: \"BAR\" number: 1 } "
5439 " value { name: \"BAZ\" number: 2 } }"
5440 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5441 " type: TYPE_ENUM type_name: \"FooEnum\" "
5442 " extendee: \"google.protobuf.FileOptions\" }"
5443 "options { uninterpreted_option { name { name_part: \"foo\" "
5444 " is_extension: true } "
5445 " string_value: \"QUUX\" } }",
5447 "foo.proto: foo.proto: OPTION_VALUE: Value must be identifier for "
5448 "enum-valued option \"foo\".\n");
5452 BuildDescriptorMessagesInTestPool();
5454 BuildFileWithErrors(
5455 "name: \"foo.proto\" "
5456 "dependency: \"google/protobuf/descriptor.proto\" "
5457 "enum_type { name: \"FooEnum\" value { name: \"BAR\" number: 1 } "
5458 " value { name: \"BAZ\" number: 2 } }"
5459 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5460 " type: TYPE_ENUM type_name: \"FooEnum\" "
5461 " extendee: \"google.protobuf.FileOptions\" }"
5462 "options { uninterpreted_option { name { name_part: \"foo\" "
5463 " is_extension: true } "
5464 " identifier_value: \"QUUX\" } }",
5466 "foo.proto: foo.proto: OPTION_VALUE: Enum type \"FooEnum\" has no value "
5467 "named \"QUUX\" for option \"foo\".\n");
5471 BuildDescriptorMessagesInTestPool();
5473 BuildFileWithErrors(
5474 "name: \"foo.proto\" "
5475 "dependency: \"google/protobuf/descriptor.proto\" "
5476 "enum_type { name: \"FooEnum1\" value { name: \"BAR\" number: 1 } "
5477 " value { name: \"BAZ\" number: 2 } }"
5478 "enum_type { name: \"FooEnum2\" value { name: \"QUX\" number: 1 } "
5479 " value { name: \"QUUX\" number: 2 } }"
5480 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5481 " type: TYPE_ENUM type_name: \"FooEnum1\" "
5482 " extendee: \"google.protobuf.FileOptions\" }"
5483 "options { uninterpreted_option { name { name_part: \"foo\" "
5484 " is_extension: true } "
5485 " identifier_value: \"QUUX\" } }",
5487 "foo.proto: foo.proto: OPTION_VALUE: Enum type \"FooEnum1\" has no value "
5488 "named \"QUUX\" for option \"foo\". This appears to be a value from a "
5493 BuildDescriptorMessagesInTestPool();
5495 BuildFileWithErrors(
5496 "name: \"foo.proto\" "
5497 "dependency: \"google/protobuf/descriptor.proto\" "
5498 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5499 " type: TYPE_STRING extendee: \"google.protobuf.FileOptions\" }"
5500 "options { uninterpreted_option { name { name_part: \"foo\" "
5501 " is_extension: true } "
5502 " identifier_value: \"QUUX\" } }",
5504 "foo.proto: foo.proto: OPTION_VALUE: Value must be quoted string "
5506 "string option \"foo\".\n");
5510 BuildFileWithErrors(
5511 "name: \"foo.proto\" "
5515 " extension_range { start: 10 end: 20 }"
5520 " label: LABEL_OPTIONAL"
5522 " extendee: \"foo.Foo\""
5523 " json_name: \"myName\""
5525 "foo.proto: foo.value: OPTION_NAME: option json_name is not allowed on "
5526 "extension fields.\n");
5530 BuildDescriptorMessagesInTestPool();
5533 "name: \"foo.proto\" "
5534 "dependency: \"google/protobuf/descriptor.proto\" "
5535 "extension { name: \"option1\" number: 1000 label: LABEL_OPTIONAL "
5536 " type: TYPE_INT32 extendee: \"google.protobuf.FileOptions\" }");
5538 BuildFileWithWarnings(
5539 "name: \"bar.proto\" "
5540 "dependency: \"google/protobuf/descriptor.proto\" "
5541 "extension { name: \"option2\" number: 1000 label: LABEL_OPTIONAL "
5542 " type: TYPE_INT32 extendee: \"google.protobuf.FileOptions\" }",
5543 "bar.proto: option2: NUMBER: Extension number 1000 has already been used "
5544 "in \"google.protobuf.FileOptions\" by extension \"option1\" defined in "
5553 "name: \"foo.proto\" "
5554 "dependency: \"google/protobuf/descriptor.proto\" "
5555 "message_type { name: \"Foo\" } "
5556 "extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
5557 " type: TYPE_MESSAGE type_name: \"Foo\" "
5558 " extendee: \"google.protobuf.FileOptions\" }"
5559 "options { uninterpreted_option { name { name_part: \"foo\" "
5560 " is_extension: true } "
5566 BuildDescriptorMessagesInTestPool();
5568 BuildFileWithErrors(
5570 "foo.proto: foo.proto: OPTION_VALUE: Option \"foo\" is a message. "
5571 "To set the entire message, use syntax like "
5572 "\"foo = { <proto text format> }\". To set fields within it, use "
5573 "syntax like \"foo.foo = value\".\n");
5577 BuildDescriptorMessagesInTestPool();
5579 BuildFileWithErrors(
5581 "foo.proto: foo.proto: OPTION_VALUE: Error while parsing option "
5582 "value for \"foo\": Expected identifier, got: 1\n");
5586 BuildDescriptorMessagesInTestPool();
5588 BuildFileWithErrors(
5590 "foo.proto: foo.proto: OPTION_VALUE: Error while parsing option "
5591 "value for \"foo\": Message type \"Foo\" has no field named \"x\".\n");
5596 "name: \"bar.proto\" "
5597 "options { optimize_for: LITE_RUNTIME } ");
5599 BuildFileWithErrors(
5600 "name: \"foo.proto\" "
5601 "dependency: \"bar.proto\" ",
5603 "foo.proto: bar.proto: IMPORT: Files that do not use optimize_for = "
5604 "LITE_RUNTIME cannot import files which do use this option. This file "
5605 "is not lite, but it imports \"bar.proto\" which is.\n");
5610 "name: \"bar.proto\" "
5613 " extension_range { start: 1 end: 1000 }"
5616 BuildFileWithErrors(
5617 "name: \"foo.proto\" "
5618 "dependency: \"bar.proto\" "
5619 "options { optimize_for: LITE_RUNTIME } "
5620 "extension { name: \"ext\" number: 123 label: LABEL_OPTIONAL "
5621 " type: TYPE_INT32 extendee: \"Bar\" }",
5623 "foo.proto: ext: EXTENDEE: Extensions to non-lite types can only be "
5624 "declared in non-lite files. Note that you cannot extend a non-lite "
5625 "type to contain a lite type, but the reverse is allowed.\n");
5629 BuildFileWithErrors(
5630 "name: \"foo.proto\" "
5632 " optimize_for: LITE_RUNTIME"
5633 " cc_generic_services: true"
5634 " java_generic_services: true"
5636 "service { name: \"Foo\" }",
5638 "foo.proto: Foo: NAME: Files with optimize_for = LITE_RUNTIME cannot "
5639 "define services unless you set both options cc_generic_services and "
5640 "java_generic_services to false.\n");
5643 "name: \"bar.proto\" "
5645 " optimize_for: LITE_RUNTIME"
5646 " cc_generic_services: false"
5647 " java_generic_services: false"
5649 "service { name: \"Bar\" }");
5657 BuildFileWithErrors(
5658 "name: \"foo.proto\" "
5660 " name: \"TestMessage\""
5661 " field { name:\"foo\" label:LABEL_OPTIONAL type:TYPE_INT32 number:1 }"
5664 " name: \"TestEnum\""
5665 " value { name:\"BAR\" number:1 }"
5668 " name: \"TestService\""
5671 " input_type: \"NoSuchType\""
5672 " output_type: \"TestMessage\""
5676 "foo.proto: TestService.Baz: INPUT_TYPE: \"NoSuchType\" is not defined.\n"
5684 "name: \"foo.proto\" "
5686 " name: \"TestMessage\""
5687 " field { name:\"foo\" label:LABEL_OPTIONAL type:TYPE_INT32 number:1 }"
5690 " name: \"TestEnum\""
5691 " value { name:\"BAR\" number:1 }"
5694 " name: \"TestService\""
5695 " method { name:\"Baz\""
5696 " input_type:\"TestMessage\""
5697 " output_type:\"TestMessage\" }"
5708 "message_type { name: \"Foo\" } "
5709 "message_type { name: \"Foo\" } ",
5712 std::vector<std::string>
errors;
5722 EXPECT_EQ(
"Invalid proto descriptor for file \"foo.proto\":",
errors[0]);
5727 BuildFileWithErrors(
5728 "name: \"foo.proto\" "
5731 " value { name:\"ENUM_A\" number:0 }"
5732 " value { name:\"ENUM_B\" number:0 }"
5734 "foo.proto: Bar: NUMBER: "
5735 "\"ENUM_B\" uses the same enum value as \"ENUM_A\". "
5736 "If this is intended, set 'option allow_alias = true;' to the enum "
5742 "name: \"foo.proto\" "
5745 " value { name:\"ENUM_A\" number:0 }"
5746 " value { name:\"ENUM_B\" number:0 }"
5747 " options { allow_alias: true }"
5752 pool_.AddUnusedImportTrackFile(
"bar.proto");
5754 "name: \"bar.proto\" "
5755 "message_type { name: \"Bar\" }");
5757 pool_.AddUnusedImportTrackFile(
"base.proto");
5759 "name: \"base.proto\" "
5760 "message_type { name: \"Base\" }");
5762 pool_.AddUnusedImportTrackFile(
"baz.proto");
5764 "name: \"baz.proto\" "
5765 "message_type { name: \"Baz\" }");
5767 pool_.AddUnusedImportTrackFile(
"public.proto");
5769 "name: \"public.proto\" "
5770 "dependency: \"bar.proto\""
5771 "public_dependency: 0");
5782 pool_.AddUnusedImportTrackFile(
"forward.proto");
5783 BuildFileWithWarnings(
5784 "name: \"forward.proto\""
5785 "dependency: \"base.proto\""
5786 "dependency: \"bar.proto\""
5787 "dependency: \"baz.proto\""
5788 "dependency: \"public.proto\""
5789 "public_dependency: 2 "
5791 " name: \"Forward\""
5792 " field { name:\"base\" number:1 label:LABEL_OPTIONAL "
5793 "type_name:\"Base\" }"
5795 "forward.proto: bar.proto: IMPORT: Import bar.proto but not used.\n");
5801 "name: 'foo.proto' "
5805 " name: 'foo_map' number: 1 label:LABEL_REPEATED "
5806 " type_name: 'FooMapEntry' "
5809 " name: 'FooMapEntry' "
5810 " options { map_entry: true } "
5812 " name: 'key' number: 1 type:TYPE_INT32 label:LABEL_OPTIONAL "
5815 " name: 'value' number: 2 type:TYPE_INT32 label:LABEL_OPTIONAL "
5821 " extension_range { start: 1 end: 10 }"
5825 static const char* kMapEntryErrorMessage =
5826 "foo.proto: Foo.foo_map: TYPE: map_entry should not be set explicitly. "
5827 "Use map<KeyType, ValueType> instead.\n";
5828 static const char* kMapEntryKeyTypeErrorMessage =
5829 "foo.proto: Foo.foo_map: TYPE: Key in map fields cannot be float/double, "
5830 "bytes or message types.\n";
5836 FillValidMapEntry(&file_proto);
5837 BuildFile(file_proto.DebugString());
5842 FillValidMapEntry(&file_proto);
5844 "extension_range { "
5845 " start: 10 end: 20 "
5848 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5853 FillValidMapEntry(&file_proto);
5856 " name: 'foo_ext' extendee: '.Bar' number: 5"
5859 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5864 FillValidMapEntry(&file_proto);
5870 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5875 FillValidMapEntry(&file_proto);
5879 " value { name: 'BAR_BAR' number:0 } "
5882 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5887 FillValidMapEntry(&file_proto);
5890 " name: 'other_field' "
5891 " label: LABEL_OPTIONAL "
5892 " type: TYPE_INT32 "
5896 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5901 FillValidMapEntry(&file_proto);
5906 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5911 FillValidMapEntry(&file_proto);
5914 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5919 FillValidMapEntry(&file_proto);
5924 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5929 FillValidMapEntry(&file_proto);
5933 key->set_name(
"Key");
5934 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5939 FillValidMapEntry(&file_proto);
5944 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5949 FillValidMapEntry(&file_proto);
5954 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5959 FillValidMapEntry(&file_proto);
5963 value->set_name(
"Value");
5964 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5969 FillValidMapEntry(&file_proto);
5974 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5979 FillValidMapEntry(&file_proto);
5983 value->set_number(3);
5984 BuildFileWithErrors(file_proto.DebugString(), kMapEntryErrorMessage);
5989 FillValidMapEntry(&file_proto);
5994 BuildFileWithErrors(file_proto.DebugString(), kMapEntryKeyTypeErrorMessage);
5999 FillValidMapEntry(&file_proto);
6004 BuildFileWithErrors(file_proto.DebugString(), kMapEntryKeyTypeErrorMessage);
6009 FillValidMapEntry(&file_proto);
6014 BuildFileWithErrors(file_proto.DebugString(), kMapEntryKeyTypeErrorMessage);
6019 FillValidMapEntry(&file_proto);
6024 key->set_type_name(
"BarEnum");
6028 enum_value_proto->
set_name(
"BAR_VALUE0");
6030 BuildFileWithErrors(file_proto.DebugString(),
6031 "foo.proto: Foo.foo_map: TYPE: Key in map fields cannot "
6032 "be enum types.\n");
6037 BuildFileWithErrors(file_proto.DebugString(),
6038 "foo.proto: Foo.foo_map: TYPE: Key in map fields cannot "
6039 "be enum types.\n");
6044 FillValidMapEntry(&file_proto);
6049 key->set_type_name(
".Bar");
6050 BuildFileWithErrors(file_proto.DebugString(), kMapEntryKeyTypeErrorMessage);
6055 FillValidMapEntry(&file_proto);
6058 " name: 'FooMapEntry' "
6059 " type: TYPE_INT32 "
6060 " label: LABEL_OPTIONAL "
6064 BuildFileWithErrors(
6065 file_proto.DebugString(),
6066 "foo.proto: Foo.FooMapEntry: NAME: \"FooMapEntry\" is already defined in "
6068 "foo.proto: Foo.foo_map: TYPE: \"FooMapEntry\" is not defined.\n"
6069 "foo.proto: Foo: NAME: Expanded map entry type FooMapEntry conflicts "
6070 "with an existing field.\n");
6075 FillValidMapEntry(&file_proto);
6078 " name: 'FooMapEntry' "
6081 BuildFileWithErrors(
6082 file_proto.DebugString(),
6083 "foo.proto: Foo.FooMapEntry: NAME: \"FooMapEntry\" is already defined in "
6085 "foo.proto: Foo: NAME: Expanded map entry type FooMapEntry conflicts "
6086 "with an existing nested message type.\n");
6091 FillValidMapEntry(&file_proto);
6094 " name: 'FooMapEntry' "
6095 " value { name: 'ENTRY_FOO' number: 0 }"
6098 BuildFileWithErrors(
6099 file_proto.DebugString(),
6100 "foo.proto: Foo.FooMapEntry: NAME: \"FooMapEntry\" is already defined in "
6102 "foo.proto: Foo: NAME: Expanded map entry type FooMapEntry conflicts "
6103 "with an existing enum type.\n");
6107 BuildFileWithErrors(
6109 "name: 'foo.proto' "
6112 " value { name: 'BAR' number: 0 }"
6113 " value { name: 'bar' number: 1 }"
6115 "foo.proto: bar: NAME: Enum name bar has the same name as BAR "
6116 "if you ignore case and strip out the enum name prefix (if any). "
6117 "This is error-prone and can lead to undefined behavior. "
6118 "Please avoid doing this. If you are using allow_alias, please assign "
6119 "the same numeric value to both enums.\n");
6124 "name: 'foo.proto' "
6127 " options { allow_alias: true }"
6128 " value { name: 'UNKNOWN' number: 0 }"
6129 " value { name: 'BAR' number: 1 }"
6130 " value { name: 'bar' number: 1 }"
6135 BuildFileWithErrors(
6137 "name: 'foo.proto' "
6140 " value { name: 'FOO_ENUM_BAZ' number: 0 }"
6141 " value { name: 'BAZ' number: 1 }"
6143 "foo.proto: BAZ: NAME: Enum name BAZ has the same name as FOO_ENUM_BAZ "
6144 "if you ignore case and strip out the enum name prefix (if any). "
6145 "This is error-prone and can lead to undefined behavior. "
6146 "Please avoid doing this. If you are using allow_alias, please assign "
6147 "the same numeric value to both enums.\n");
6149 BuildFileWithErrors(
6151 "name: 'foo.proto' "
6154 " value { name: 'FOOENUM_BAZ' number: 0 }"
6155 " value { name: 'BAZ' number: 1 }"
6157 "foo.proto: BAZ: NAME: Enum name BAZ has the same name as FOOENUM_BAZ "
6158 "if you ignore case and strip out the enum name prefix (if any). "
6159 "This is error-prone and can lead to undefined behavior. "
6160 "Please avoid doing this. If you are using allow_alias, please assign "
6161 "the same numeric value to both enums.\n");
6163 BuildFileWithErrors(
6165 "name: 'foo.proto' "
6168 " value { name: 'FOO_ENUM_BAR_BAZ' number: 0 }"
6169 " value { name: 'BAR__BAZ' number: 1 }"
6171 "foo.proto: BAR__BAZ: NAME: Enum name BAR__BAZ has the same name as "
6172 "FOO_ENUM_BAR_BAZ if you ignore case and strip out the enum name prefix "
6173 "(if any). This is error-prone and can lead to undefined behavior. "
6174 "Please avoid doing this. If you are using allow_alias, please assign "
6175 "the same numeric value to both enums.\n");
6177 BuildFileWithErrors(
6179 "name: 'foo.proto' "
6182 " value { name: 'FOO_ENUM__BAR_BAZ' number: 0 }"
6183 " value { name: 'BAR_BAZ' number: 1 }"
6185 "foo.proto: BAR_BAZ: NAME: Enum name BAR_BAZ has the same name as "
6186 "FOO_ENUM__BAR_BAZ if you ignore case and strip out the enum name prefix "
6187 "(if any). This is error-prone and can lead to undefined behavior. "
6188 "Please avoid doing this. If you are using allow_alias, please assign "
6189 "the same numeric value to both enums.\n");
6195 "name: 'foo.proto' "
6198 " value { name: 'BAR_BAZ' number: 0 }"
6199 " value { name: 'BARBAZ' number: 1 }"
6205 FillValidMapEntry(&file_proto);
6208 " name: 'FooMapEntry' "
6211 " name: 'int_field' "
6212 " type: TYPE_INT32 "
6213 " label: LABEL_OPTIONAL "
6218 BuildFileWithErrors(
6219 file_proto.DebugString(),
6220 "foo.proto: Foo.FooMapEntry: NAME: \"FooMapEntry\" is already defined in "
6222 "foo.proto: Foo.foo_map: TYPE: \"FooMapEntry\" is not defined.\n"
6223 "foo.proto: Foo: NAME: Expanded map entry type FooMapEntry conflicts "
6224 "with an existing oneof type.\n");
6228 BuildFileWithErrors(
6229 "name: \"foo.proto\" "
6232 " value { name:\"ENUM_A\" number:1 }"
6233 " value { name:\"ENUM_B\" number:2 }"
6238 " name: 'foo_map' number: 1 label:LABEL_REPEATED "
6239 " type_name: 'FooMapEntry' "
6242 " name: 'FooMapEntry' "
6243 " options { map_entry: true } "
6245 " name: 'key' number: 1 type:TYPE_INT32 label:LABEL_OPTIONAL "
6248 " name: 'value' number: 2 type_name:\"Bar\" label:LABEL_OPTIONAL "
6252 "foo.proto: Foo.foo_map: "
6253 "TYPE: Enum value in map must define 0 as the first value.\n");
6257 BuildFileWithErrors(
6258 "name: 'foo.proto' "
6262 " field { name:'foo' number:1 label:LABEL_REQUIRED type:TYPE_INT32 } "
6264 "foo.proto: Foo.foo: TYPE: Required fields are not allowed in "
6268 BuildFileWithErrors(
6269 "name: 'foo.proto' "
6275 " field { name:'bar' number:1 label:LABEL_REQUIRED type:TYPE_INT32 } "
6278 "foo.proto: Foo.Bar.bar: TYPE: Required fields are not allowed in "
6283 "name: 'foo.proto' "
6287 " field { name:'foo' number:1 label:LABEL_OPTIONAL type:TYPE_INT32 } "
6288 " field { name:'bar' number:2 label:LABEL_REPEATED type:TYPE_INT32 } "
6293 BuildFileWithErrors(
6294 "name: 'foo.proto' "
6298 " field { name:'foo' number:1 label:LABEL_OPTIONAL type:TYPE_INT32 "
6299 " default_value: '1' }"
6301 "foo.proto: Foo.foo: DEFAULT_VALUE: Explicit default values are not "
6302 "allowed in proto3.\n");
6304 BuildFileWithErrors(
6305 "name: 'foo.proto' "
6311 " field { name:'bar' number:1 label:LABEL_OPTIONAL type:TYPE_INT32 "
6312 " default_value: '1' }"
6315 "foo.proto: Foo.Bar.bar: DEFAULT_VALUE: Explicit default values are not "
6316 "allowed in proto3.\n");
6320 BuildFileWithErrors(
6321 "name: 'foo.proto' "
6325 " field { name:'foo' number:1 label:LABEL_OPTIONAL type:TYPE_INT32 } "
6326 " extension_range { start:10 end:100 } "
6328 "foo.proto: Foo: NUMBER: Extension ranges are not allowed in "
6331 BuildFileWithErrors(
6332 "name: 'foo.proto' "
6338 " field { name:'bar' number:1 label:LABEL_OPTIONAL type:TYPE_INT32 } "
6339 " extension_range { start:10 end:100 } "
6342 "foo.proto: Foo.Bar: NUMBER: Extension ranges are not allowed in "
6347 BuildFileWithErrors(
6348 "name: 'foo.proto' "
6352 " options { message_set_wire_format: true } "
6354 "foo.proto: Foo: NAME: MessageSet is not supported "
6359 BuildFileWithErrors(
6360 "name: 'foo.proto' "
6364 " value { name: 'FOO_FOO' number:1 } "
6366 "foo.proto: FooEnum: NUMBER: The first enum value must be "
6367 "zero in proto3.\n");
6369 BuildFileWithErrors(
6370 "name: 'foo.proto' "
6376 " value { name: 'FOO_FOO' number:1 } "
6379 "foo.proto: Foo.FooEnum: NUMBER: The first enum value must be "
6380 "zero in proto3.\n");
6384 "name: 'foo.proto' "
6388 " value { name: 'FOO_FOO' number:0 } "
6393 BuildFileWithErrors(
6394 "name: 'foo.proto' "
6399 " name: 'FooGroup' "
6401 " field { name:'foo_group' number: 1 label:LABEL_OPTIONAL "
6402 " type: TYPE_GROUP type_name:'FooGroup' } "
6404 "foo.proto: Foo.foo_group: TYPE: Groups are not supported in proto3 "
6412 "name: 'foo.proto' "
6417 " value { name: 'DEFAULT_OPTION' number:0 } "
6422 BuildFileWithErrors(
6423 "name: 'bar.proto' "
6424 "dependency: 'foo.proto' "
6428 " field { name:'bar' number:1 label:LABEL_OPTIONAL type:TYPE_ENUM "
6429 " type_name: 'foo.FooEnum' }"
6431 "bar.proto: Foo.bar: TYPE: Enum type \"foo.FooEnum\" is not a proto3 "
6432 "enum, but is used in \"Foo\" which is a proto3 message type.\n");
6451 AddExtension(&file_proto,
"google.protobuf.FieldOptions",
"option1", 1000,
6458 "name: 'google.protobuf.proto' "
6461 " name: 'Container' extension_range { start: 1 end: 1000 } "
6463 BuildFileWithErrors(
6464 "name: 'bar.proto' "
6466 "dependency: 'google.protobuf.proto' "
6468 " name: 'bar' number: 1 label: LABEL_OPTIONAL type: TYPE_INT32 "
6469 " extendee: 'Container' "
6471 "bar.proto: bar: EXTENDEE: Extensions in proto3 are only allowed for "
6472 "defining options.\n");
6478 BuildFileWithErrors(
6479 "name: 'foo.proto' "
6483 " field { name:'name' number:1 label:LABEL_OPTIONAL type:TYPE_INT32 }"
6484 " field { name:'Name' number:2 label:LABEL_OPTIONAL type:TYPE_INT32 }"
6486 "foo.proto: Foo: NAME: The JSON camel-case name of field \"Name\" "
6487 "conflicts with field \"name\". This is not allowed in proto3.\n");
6489 BuildFileWithErrors(
6490 "name: 'foo.proto' "
6494 " field { name:'ab' number:1 label:LABEL_OPTIONAL type:TYPE_INT32 }"
6495 " field { name:'_a__b_' number:2 label:LABEL_OPTIONAL type:TYPE_INT32 }"
6497 "foo.proto: Foo: NAME: The JSON camel-case name of field \"_a__b_\" "
6498 "conflicts with field \"ab\". This is not allowed in proto3.\n");
6506 const char* file_text) {
6521 "name: 'foo.proto' "
6522 "message_type { name:'Foo' extension_range { start: 1 end: 100 } } "
6523 "enum_type { name:'TestEnum' value { name:'DUMMY' number:0 } } "
6524 "service { name:'TestService' } ");
6526 "name: 'bar.proto' "
6527 "dependency: 'foo.proto' "
6528 "message_type { name:'Bar' } "
6529 "extension { name:'foo_ext' extendee: '.Foo' number:5 "
6530 " label:LABEL_OPTIONAL type:TYPE_INT32 } ");
6534 "name: 'baz.proto' "
6537 " field { name:'foo' number:1 label:LABEL_OPTIONAL type_name:'Foo' } "
6552 if (filename ==
"error.proto") {
6554 output->set_name(
"error.proto");
6555 output->add_dependency(
"error2.proto");
6557 }
else if (filename ==
"error2.proto") {
6559 output->set_name(
"error2.proto");
6560 output->add_dependency(
"error.proto");
6701 EXPECT_TRUE(
pool.FindFileContainingSymbol(
"NoSuchSymbol") ==
nullptr);
6734 for (
int i = 0;
i < 2; ++
i) {
6737 std::vector<const FieldDescriptor*> extensions;
6738 pool.FindAllExtensions(
foo, &extensions);
6745 ErrorDescriptorDatabase error_database;
6748 std::vector<std::string>
errors;
6760 ErrorDescriptorDatabase error_database;
6766 "error.proto: error2.proto: IMPORT: File recursively imports itself: "
6767 "error.proto -> error2.proto -> error.proto\n"
6768 "error2.proto: error.proto: IMPORT: Import \"error.proto\" was not "
6769 "found or had errors.\n"
6770 "error.proto: error2.proto: IMPORT: Import \"error2.proto\" was not "
6771 "found or had errors.\n",
6772 error_collector.
text_);
6782 "baz.proto: Baz.foo: TYPE: \"Foo\" seems to be defined in \"foo.proto\", "
6783 "which is not imported by \"baz.proto\". To use it here, please add "
6784 "the necessary import.\n",
6785 error_collector.
text_);
6812 pool.FindFileByName(original_file->
name());
6817 original_file->
CopyTo(&original_file_proto);
6820 file_from_database->
CopyTo(&file_from_database_proto);
6822 EXPECT_EQ(original_file_proto.DebugString(),
6823 file_from_database_proto.DebugString());
6833 CallCountingDatabase call_counter(&database_);
6846 call_counter.Clear();
6849 EXPECT_TRUE(
foo->FindExtensionByName(
"no_such_extension") ==
nullptr);
6850 EXPECT_TRUE(
foo->FindNestedTypeByName(
"NoSuchMessageType") ==
nullptr);
6851 EXPECT_TRUE(
foo->FindEnumTypeByName(
"NoSuchEnumType") ==
nullptr);
6852 EXPECT_TRUE(
foo->FindEnumValueByName(
"NO_SUCH_VALUE") ==
nullptr);
6862 EXPECT_TRUE(
pool.FindFileContainingSymbol(
"Foo.no.such.field") ==
nullptr);
6863 EXPECT_TRUE(
pool.FindFileContainingSymbol(
"Foo.no_such_field") ==
nullptr);
6864 EXPECT_TRUE(
pool.FindMessageTypeByName(
"Foo.NoSuchMessageType") ==
nullptr);
6866 EXPECT_TRUE(
pool.FindExtensionByName(
"Foo.no_such_extension") ==
nullptr);
6867 EXPECT_TRUE(
pool.FindEnumTypeByName(
"Foo.NoSuchEnumType") ==
nullptr);
6868 EXPECT_TRUE(
pool.FindEnumValueByName(
"Foo.NO_SUCH_VALUE") ==
nullptr);
6869 EXPECT_TRUE(
pool.FindMethodByName(
"TestService.NoSuchMethod") ==
nullptr);
6878 FalsePositiveDatabase false_positive_database(&database_);
6913 FullMatch(filename,
"file",
".proto", &file_num);
6914 if (file_num > -1) {
6923 FullMatch(symbol_name,
"Message",
"", &file_num);
6939 int begin_size = begin_with.size();
6940 int end_size = end_with.size();
6941 if (
name.substr(0, begin_size) != begin_with ||
6942 name.substr(
name.size() - end_size, end_size) != end_with) {
6946 name.substr(begin_size,
name.size() - end_size - begin_size), file_num);
6958 for (
int i = 0;
i < file_num; ++
i) {
6976 GOOGLE_LOG(
INFO) <<
"A timeout in this test probably indicates a real bug.";
6986 CallCountingDatabase call_counter(&database_);
6997 call_counter.Clear();
7020 GOOGLE_LOG(
FATAL) <<
"AddError() called unexpectedly: " << filename <<
" ["
7048 "syntax = \"proto2\";\n"
7049 "option java_package = \"com.foo.bar\";\n"
7050 "option (test_file_opt) = \"foobar\";\n"
7052 " option (test_msg_opt) = \"foobar\";\n"
7053 " optional int32 a = 1 [deprecated = true];\n"
7055 " required double b = 1 [(test_field_opt) = \"foobar\"];\n"
7058 " option (test_oneof_opt) = \"foobar\";\n"
7064 "enum Indecision {\n"
7065 " option (test_enum_opt) = 21;\n"
7066 " option (test_enum_opt) = 42;\n"
7067 " option (test_enum_opt) = 63;\n"
7068 " YES = 1 [(test_enumval_opt).a = 100];\n"
7069 " NO = 2 [(test_enumval_opt) = {a:200}];\n"
7073 " option (test_svc_opt) = {a:100};\n"
7074 " option (test_svc_opt) = {a:200};\n"
7075 " option (test_svc_opt) = {a:300};\n"
7076 " rpc Method(A) returns (A.B);\n"
7079 " rpc OtherMethod(A) returns (A) {\n"
7080 " option deprecated = true;\n"
7081 " option (test_method_opt) = \"foobar\";\n"
7084 "message MessageWithExtensions {\n"
7085 " extensions 1000 to 2000, 2001 to max [(test_ext_opt) = \"foobar\"];\n"
7087 "extend MessageWithExtensions {\n"
7088 " repeated int32 int32_extension = 1001 [packed=true];\n"
7091 " extend MessageWithExtensions {\n"
7092 " optional C message_extension = 1002;\n"
7095 "import \"google/protobuf/descriptor.proto\";\n"
7096 "extend google.protobuf.FileOptions {\n"
7097 " optional string test_file_opt = 10101;\n"
7099 "extend google.protobuf.MessageOptions {\n"
7100 " optional string test_msg_opt = 10101;\n"
7102 "extend google.protobuf.FieldOptions {\n"
7103 " optional string test_field_opt = 10101;\n"
7105 "extend google.protobuf.EnumOptions {\n"
7106 " repeated int32 test_enum_opt = 10101;\n"
7108 "extend google.protobuf.EnumValueOptions {\n"
7109 " optional A test_enumval_opt = 10101;\n"
7111 "extend google.protobuf.ServiceOptions {\n"
7112 " repeated A test_svc_opt = 10101;\n"
7114 "extend google.protobuf.MethodOptions {\n"
7115 " optional string test_method_opt = 10101;\n"
7117 "extend google.protobuf.OneofOptions {\n"
7118 " optional string test_oneof_opt = 10101;\n"
7120 "extend google.protobuf.ExtensionRangeOptions {\n"
7121 " optional string test_ext_opt = 10101;\n"
7172 EXPECT_EQ(
"4:1-16:2", PrintSourceLocation(loc));
7176 EXPECT_EQ(
"7:3-9:4", PrintSourceLocation(loc));
7180 EXPECT_EQ(
"17:1-24:2", PrintSourceLocation(loc));
7184 EXPECT_EQ(
"21:3-21:42", PrintSourceLocation(loc));
7188 EXPECT_EQ(
"25:1-35:2", PrintSourceLocation(loc));
7192 EXPECT_EQ(
"29:3-29:31", PrintSourceLocation(loc));
7205 EXPECT_EQ(
"40:3-40:55", PrintSourceLocation(loc));
7209 EXPECT_EQ(
"42:1-46:2", PrintSourceLocation(loc));
7214 EXPECT_EQ(
"44:5-44:41", PrintSourceLocation(loc));
7236 std::vector<int> vpath(
path,
path + 2);
7238 EXPECT_EQ(
"2:1-2:37", PrintSourceLocation(loc));
7240 std::vector<int> vunint(unint, unint + 3);
7245 kCustomOptionFieldNumber};
7248 std::vector<int> vpath(
path,
path + 2);
7250 EXPECT_EQ(
"3:1-3:35", PrintSourceLocation(loc));
7252 std::vector<int> vunint(unint, unint + 3);
7260 kCustomOptionFieldNumber};
7264 std::vector<int> vpath(
path,
path + 4);
7266 EXPECT_EQ(
"5:3-5:36", PrintSourceLocation(loc));
7268 std::vector<int> vunint(unint, unint + 5);
7287 std::vector<int> vpath(
path,
path + 6);
7289 EXPECT_EQ(
"6:25-6:42", PrintSourceLocation(loc));
7291 std::vector<int> vunint(unint, unint + 7);
7311 std::vector<int> vpath(
path,
path + 8);
7313 EXPECT_EQ(
"8:28-8:55", PrintSourceLocation(loc));
7315 std::vector<int> vunint(unint, unint + 9);
7332 std::vector<int> vpath(
path,
path + 6);
7334 EXPECT_EQ(
"11:5-11:40", PrintSourceLocation(loc));
7336 std::vector<int> vunint(unint, unint + 7);
7344 kCustomOptionFieldNumber, 0};
7348 std::vector<int> vpath(
path,
path + 5);
7350 EXPECT_EQ(
"18:3-18:31", PrintSourceLocation(loc));
7352 std::vector<int> vunint(unint, unint + 5);
7358 kCustomOptionFieldNumber, 1};
7362 std::vector<int> vpath(
path,
path + 5);
7364 EXPECT_EQ(
"19:3-19:31", PrintSourceLocation(loc));
7366 std::vector<int> vunint(unint, unint + 5);
7372 kCustomOptionFieldNumber, 2};
7376 std::vector<int> vpath(
path,
path + 5);
7378 EXPECT_EQ(
"20:3-20:31", PrintSourceLocation(loc));
7380 std::vector<int> vunint(unint, unint + 5);
7392 kCustomOptionFieldNumber,
7401 std::vector<int> vpath(
path,
path + 7);
7403 EXPECT_EQ(
"21:14-21:40", PrintSourceLocation(loc));
7405 std::vector<int> vunint(unint, unint + 7);
7414 kCustomOptionFieldNumber};
7422 std::vector<int> vpath(
path,
path + 6);
7424 EXPECT_EQ(
"22:14-22:42", PrintSourceLocation(loc));
7426 std::vector<int> vunint(unint, unint + 7);
7434 kCustomOptionFieldNumber, 0};
7438 std::vector<int> vpath(
path,
path + 5);
7440 EXPECT_EQ(
"26:3-26:35", PrintSourceLocation(loc));
7442 std::vector<int> vunint(unint, unint + 5);
7448 kCustomOptionFieldNumber, 1};
7452 std::vector<int> vpath(
path,
path + 5);
7454 EXPECT_EQ(
"27:3-27:35", PrintSourceLocation(loc));
7456 std::vector<int> vunint(unint, unint + 5);
7462 kCustomOptionFieldNumber, 2};
7466 std::vector<int> vpath(
path,
path + 5);
7468 EXPECT_EQ(
"28:3-28:35", PrintSourceLocation(loc));
7470 std::vector<int> vunint(unint, unint + 5);
7489 std::vector<int> vpath(
path,
path + 6);
7491 EXPECT_EQ(
"32:5-32:30", PrintSourceLocation(loc));
7493 std::vector<int> vunint(unint, unint + 7);
7508 std::vector<int> vpath(
path,
path + 6);
7510 EXPECT_EQ(
"33:5-33:41", PrintSourceLocation(loc));
7512 std::vector<int> vunint(unint, unint + 7);
7521 std::vector<int> vpath(
path,
path + 5);
7523 EXPECT_EQ(
"37:40-37:67", PrintSourceLocation(loc));
7531 kCustomOptionFieldNumber};
7539 std::vector<int> vpath(
path,
path + 6);
7541 EXPECT_EQ(
"37:41-37:66", PrintSourceLocation(loc));
7543 std::vector<int> vunint(unint, unint + 7);
7552 kCustomOptionFieldNumber};
7560 std::vector<int> vpath(
path,
path + 6);
7562 EXPECT_EQ(
"37:41-37:66", PrintSourceLocation(loc));
7564 std::vector<int> vunint(unint, unint + 7);
7576 std::vector<int> vpath(
path,
path + 4);
7578 EXPECT_EQ(
"40:42-40:53", PrintSourceLocation(loc));
7580 std::vector<int> vunint(unint, unint + 5);
7593 file_desc->
CopyTo(&proto);
7611 file_desc->
CopyTo(&proto);
7632 "syntax = \"proto2\";\n"
7659 file_desc->
CopyTo(&file_desc_proto);
7704 const char* message_name) {
7707 "package: \"protobuf_unittest\" "
7712 " field { name:'a' number:1 "
7713 " label:LABEL_OPTIONAL "
7714 " type_name:'int32' } "
7719 const char* enum_value_name) {
7722 "package: 'protobuf_unittest' "
7739 ParseProtoAndAddToDb(
7740 "name: 'foo.proto' "
7741 "package: 'protobuf_unittest' "
7742 "dependency: 'bar.proto' "
7745 " field { name:'bar' number:1 label:LABEL_OPTIONAL "
7746 "type_name:'.protobuf_unittest.Bar' } "
7748 AddSimpleMessageProtoFileToDb(
"bar",
"Bar");
7779 ParseProtoAndAddToDb(
7780 "name: 'foo.proto' "
7781 "package: 'protobuf_unittest' "
7782 "dependency: 'enum1.proto' "
7783 "dependency: 'enum2.proto' "
7786 " field { name:'enum1' number:1 label:LABEL_OPTIONAL "
7787 "type_name:'.protobuf_unittest.Enum1' } "
7788 " field { name:'enum2' number:1 label:LABEL_OPTIONAL "
7789 "type_name:'.protobuf_unittest.Enum2' } "
7791 AddSimpleEnumProtoFileToDb(
"enum1",
"Enum1",
"ENUM1");
7792 AddSimpleEnumProtoFileToDb(
"enum2",
"Enum2",
"ENUM2");
7816 ParseProtoAndAddToDb(
7817 "name: 'foo.proto' "
7818 "package: 'protobuf_unittest' "
7819 "dependency: 'message1.proto' "
7820 "dependency: 'message2.proto' "
7821 "dependency: 'enum1.proto' "
7822 "dependency: 'enum2.proto' "
7825 " field { name:'message1' number:1 label:LABEL_OPTIONAL "
7826 "type_name:'.protobuf_unittest.Message1' } "
7827 " field { name:'message2' number:1 label:LABEL_OPTIONAL "
7828 "type_name:'.protobuf_unittest.Message2' } "
7829 " field { name:'enum1' number:1 label:LABEL_OPTIONAL "
7830 "type_name:'.protobuf_unittest.Enum1' } "
7831 " field { name:'enum2' number:1 label:LABEL_OPTIONAL "
7832 "type_name:'.protobuf_unittest.Enum2' } "
7834 AddSimpleMessageProtoFileToDb(
"message1",
"Message1");
7835 AddSimpleMessageProtoFileToDb(
"message2",
"Message2");
7836 AddSimpleEnumProtoFileToDb(
"enum1",
"Enum1",
"ENUM1");
7837 AddSimpleEnumProtoFileToDb(
"enum2",
"Enum2",
"ENUM2");
7854 field =
desc->FindFieldByName(
"message2");
7877 ParseProtoAndAddToDb(
7878 "name: 'foo.proto' "
7879 "package: 'protobuf_unittest' "
7880 "dependency: 'bar.proto' "
7881 "dependency: 'baz.proto' "
7882 "extension { extendee: '.protobuf_unittest.Bar' name:'bar' number:11"
7883 " label:LABEL_OPTIONAL type_name:'.protobuf_unittest.Baz' }");
7884 ParseProtoAndAddToDb(
7885 "name: 'bar.proto' "
7886 "package: 'protobuf_unittest' "
7889 " extension_range { start: 10 end: 20 }"
7891 AddSimpleMessageProtoFileToDb(
"baz",
"Baz");
7909 ParseProtoAndAddToDb(
7910 "name: 'foo.proto' "
7911 "package: 'protobuf_unittest' "
7912 "dependency: 'message1.proto' "
7913 "dependency: 'message2.proto' "
7914 "dependency: 'message3.proto' "
7915 "dependency: 'message4.proto' "
7917 " name: 'LazyService'"
7918 " method { name: 'A' input_type: '.protobuf_unittest.Message1' "
7919 " output_type: '.protobuf_unittest.Message2' }"
7921 AddSimpleMessageProtoFileToDb(
"message1",
"Message1");
7922 AddSimpleMessageProtoFileToDb(
"message2",
"Message2");
7923 AddSimpleMessageProtoFileToDb(
"message3",
"Message3");
7924 AddSimpleMessageProtoFileToDb(
"message4",
"Message4");
7953 "google/protobuf/unittest_lazy_dependencies.proto"));
7955 "google/protobuf/unittest_lazy_dependencies_custom_option.proto"));
7957 "google/protobuf/unittest_lazy_dependencies_enum.proto"));
7967 "google/protobuf/unittest_lazy_dependencies.proto"));
7969 "google/protobuf/unittest_lazy_dependencies_custom_option.proto"));
7971 "google/protobuf/unittest_lazy_dependencies_enum.proto"));
7979 protobuf_unittest::lazy_imports::LazyEnum custom_option_value =
7980 options.GetExtension(protobuf_unittest::lazy_imports::lazy_enum_option);
7983 "google/protobuf/unittest_lazy_dependencies_custom_option.proto"));
7985 "google/protobuf/unittest_lazy_dependencies_enum.proto"));
7986 EXPECT_EQ(custom_option_value, protobuf_unittest::lazy_imports::LAZY_ENUM_1);
7991 custom_option_value =
7992 options2.GetExtension(protobuf_unittest::lazy_imports::lazy_enum_option);
7995 "google/protobuf/unittest_lazy_dependencies_custom_option.proto"));
7997 "google/protobuf/unittest_lazy_dependencies_enum.proto"));
7998 EXPECT_EQ(custom_option_value, protobuf_unittest::lazy_imports::LAZY_ENUM_0);
8002 ParseProtoAndAddToDb(
8003 "name: 'foo.proto' "
8004 "package: 'protobuf_unittest' "
8005 "dependency: 'bar.proto' "
8008 " field { name:'bar' number:1 label:LABEL_OPTIONAL "
8009 "type_name:'.protobuf_unittest.Bar' } "
8011 ParseProtoAndAddToDb(
8012 "name: 'bar.proto' "
8013 "package: 'protobuf_unittest' "
8014 "dependency: 'baz.proto' "
8017 " field { name:'baz' number:1 label:LABEL_OPTIONAL "
8018 "type_name:'.protobuf_unittest.Baz' } "
8020 AddSimpleMessageProtoFileToDb(
"baz",
"Baz");