| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include <google/protobuf/stubs/common.h> | 46 #include <google/protobuf/stubs/common.h> |
| 47 #include <google/protobuf/stubs/logging.h> | 47 #include <google/protobuf/stubs/logging.h> |
| 48 #include <google/protobuf/testing/file.h> | 48 #include <google/protobuf/testing/file.h> |
| 49 #include <google/protobuf/testing/file.h> | 49 #include <google/protobuf/testing/file.h> |
| 50 #include <google/protobuf/test_util.h> | 50 #include <google/protobuf/test_util.h> |
| 51 #include <google/protobuf/unittest.pb.h> | 51 #include <google/protobuf/unittest.pb.h> |
| 52 #include <google/protobuf/unittest_mset.pb.h> | 52 #include <google/protobuf/unittest_mset.pb.h> |
| 53 #include <google/protobuf/unittest_mset_wire_format.pb.h> | 53 #include <google/protobuf/unittest_mset_wire_format.pb.h> |
| 54 #include <google/protobuf/io/tokenizer.h> | 54 #include <google/protobuf/io/tokenizer.h> |
| 55 #include <google/protobuf/io/zero_copy_stream_impl.h> | 55 #include <google/protobuf/io/zero_copy_stream_impl.h> |
| 56 #include <google/protobuf/stubs/mathlimits.h> |
| 56 #include <google/protobuf/stubs/strutil.h> | 57 #include <google/protobuf/stubs/strutil.h> |
| 57 #include <google/protobuf/stubs/substitute.h> | 58 #include <google/protobuf/stubs/substitute.h> |
| 58 #include <google/protobuf/testing/googletest.h> | 59 #include <google/protobuf/testing/googletest.h> |
| 59 #include <gtest/gtest.h> | 60 #include <gtest/gtest.h> |
| 60 #include <google/protobuf/stubs/mathlimits.h> | |
| 61 | 61 |
| 62 | 62 |
| 63 namespace google { | 63 namespace google { |
| 64 namespace protobuf { | 64 namespace protobuf { |
| 65 | 65 |
| 66 // Can't use an anonymous namespace here due to brokenness of Tru64 compiler. | 66 // Can't use an anonymous namespace here due to brokenness of Tru64 compiler. |
| 67 namespace text_format_unittest { | 67 namespace text_format_unittest { |
| 68 | 68 |
| 69 // A basic string with different escapable characters for testing. | 69 // A basic string with different escapable characters for testing. |
| 70 const string kEscapeTestString = | 70 const string kEscapeTestString = |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 proto_.add_repeated_string("foo"); | 150 proto_.add_repeated_string("foo"); |
| 151 proto_.add_repeated_string("bar"); | 151 proto_.add_repeated_string("bar"); |
| 152 proto_.add_repeated_nested_message()->set_bb(2); | 152 proto_.add_repeated_nested_message()->set_bb(2); |
| 153 proto_.add_repeated_nested_message()->set_bb(3); | 153 proto_.add_repeated_nested_message()->set_bb(3); |
| 154 proto_.add_repeated_nested_enum(unittest::TestAllTypes::FOO); | 154 proto_.add_repeated_nested_enum(unittest::TestAllTypes::FOO); |
| 155 proto_.add_repeated_nested_enum(unittest::TestAllTypes::BAR); | 155 proto_.add_repeated_nested_enum(unittest::TestAllTypes::BAR); |
| 156 | 156 |
| 157 TextFormat::Printer printer; | 157 TextFormat::Printer printer; |
| 158 printer.SetUseShortRepeatedPrimitives(true); | 158 printer.SetUseShortRepeatedPrimitives(true); |
| 159 string text; | 159 string text; |
| 160 printer.PrintToString(proto_, &text); | 160 EXPECT_TRUE(printer.PrintToString(proto_, &text)); |
| 161 | 161 |
| 162 EXPECT_EQ("optional_int32: 123\n" | 162 EXPECT_EQ("optional_int32: 123\n" |
| 163 "repeated_int32: [456, 789]\n" | 163 "repeated_int32: [456, 789]\n" |
| 164 "repeated_string: \"foo\"\n" |
| 165 "repeated_string: \"bar\"\n" |
| 166 "repeated_nested_message {\n bb: 2\n}\n" |
| 167 "repeated_nested_message {\n bb: 3\n}\n" |
| 168 "repeated_nested_enum: [FOO, BAR]\n", |
| 169 text); |
| 170 |
| 171 // Verify that any existing data in the string is cleared when |
| 172 // PrintToString() is called. |
| 173 text = "just some data here...\n\nblah blah"; |
| 174 EXPECT_TRUE(printer.PrintToString(proto_, &text)); |
| 175 |
| 176 EXPECT_EQ("optional_int32: 123\n" |
| 177 "repeated_int32: [456, 789]\n" |
| 164 "repeated_string: \"foo\"\n" | 178 "repeated_string: \"foo\"\n" |
| 165 "repeated_string: \"bar\"\n" | 179 "repeated_string: \"bar\"\n" |
| 166 "repeated_nested_message {\n bb: 2\n}\n" | 180 "repeated_nested_message {\n bb: 2\n}\n" |
| 167 "repeated_nested_message {\n bb: 3\n}\n" | 181 "repeated_nested_message {\n bb: 3\n}\n" |
| 168 "repeated_nested_enum: [FOO, BAR]\n", | 182 "repeated_nested_enum: [FOO, BAR]\n", |
| 169 text); | 183 text); |
| 170 | 184 |
| 171 // Try in single-line mode. | 185 // Try in single-line mode. |
| 172 printer.SetSingleLineMode(true); | 186 printer.SetSingleLineMode(true); |
| 173 printer.PrintToString(proto_, &text); | 187 EXPECT_TRUE(printer.PrintToString(proto_, &text)); |
| 174 | 188 |
| 175 EXPECT_EQ("optional_int32: 123 " | 189 EXPECT_EQ("optional_int32: 123 " |
| 176 "repeated_int32: [456, 789] " | 190 "repeated_int32: [456, 789] " |
| 177 "repeated_string: \"foo\" " | 191 "repeated_string: \"foo\" " |
| 178 "repeated_string: \"bar\" " | 192 "repeated_string: \"bar\" " |
| 179 "repeated_nested_message { bb: 2 } " | 193 "repeated_nested_message { bb: 2 } " |
| 180 "repeated_nested_message { bb: 3 } " | 194 "repeated_nested_message { bb: 3 } " |
| 181 "repeated_nested_enum: [FOO, BAR] ", | 195 "repeated_nested_enum: [FOO, BAR] ", |
| 182 text); | 196 text); |
| 183 } | 197 } |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 | 666 |
| 653 ASSERT_EQ(2, proto_.repeated_nested_message_size()); | 667 ASSERT_EQ(2, proto_.repeated_nested_message_size()); |
| 654 EXPECT_EQ(1, proto_.repeated_nested_message(0).bb()); | 668 EXPECT_EQ(1, proto_.repeated_nested_message(0).bb()); |
| 655 EXPECT_EQ(2, proto_.repeated_nested_message(1).bb()); | 669 EXPECT_EQ(2, proto_.repeated_nested_message(1).bb()); |
| 656 | 670 |
| 657 ASSERT_EQ(2, proto_.repeatedgroup_size()); | 671 ASSERT_EQ(2, proto_.repeatedgroup_size()); |
| 658 EXPECT_EQ(3, proto_.repeatedgroup(0).a()); | 672 EXPECT_EQ(3, proto_.repeatedgroup(0).a()); |
| 659 EXPECT_EQ(4, proto_.repeatedgroup(1).a()); | 673 EXPECT_EQ(4, proto_.repeatedgroup(1).a()); |
| 660 } | 674 } |
| 661 | 675 |
| 676 TEST_F(TextFormatTest, ParseShortRepeatedWithTrailingComma) { |
| 677 string parse_string = "repeated_int32: [456,]\n"; |
| 678 ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_)); |
| 679 parse_string = "repeated_nested_enum: [ FOO , ]"; |
| 680 ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_)); |
| 681 parse_string = "repeated_string: [ \"foo\", ]"; |
| 682 ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_)); |
| 683 parse_string = "repeated_nested_message: [ { bb: 1 }, ]"; |
| 684 ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_)); |
| 685 parse_string = "RepeatedGroup [{ a: 3 },]\n"; |
| 686 } |
| 687 |
| 688 TEST_F(TextFormatTest, ParseShortRepeatedEmpty) { |
| 689 string parse_string = |
| 690 "repeated_int32: []\n" |
| 691 "repeated_nested_enum: []\n" |
| 692 "repeated_string: []\n" |
| 693 "repeated_nested_message: []\n" |
| 694 "RepeatedGroup []\n"; |
| 695 |
| 696 ASSERT_TRUE(TextFormat::ParseFromString(parse_string, &proto_)); |
| 697 |
| 698 EXPECT_EQ(0, proto_.repeated_int32_size()); |
| 699 EXPECT_EQ(0, proto_.repeated_nested_enum_size()); |
| 700 EXPECT_EQ(0, proto_.repeated_string_size()); |
| 701 EXPECT_EQ(0, proto_.repeated_nested_message_size()); |
| 702 EXPECT_EQ(0, proto_.repeatedgroup_size()); |
| 703 } |
| 704 |
| 705 TEST_F(TextFormatTest, ParseShortRepeatedConcatenatedWithEmpty) { |
| 706 string parse_string = |
| 707 // Starting with empty [] should have no impact. |
| 708 "repeated_int32: []\n" |
| 709 "repeated_nested_enum: []\n" |
| 710 "repeated_string: []\n" |
| 711 "repeated_nested_message: []\n" |
| 712 "RepeatedGroup []\n" |
| 713 // Mixed short-form and long-form are simply concatenated. |
| 714 "repeated_int32: 1\n" |
| 715 "repeated_int32: [456, 789]\n" |
| 716 "repeated_nested_enum: [ FOO ,BAR, # comment\n" |
| 717 " 3]\n" |
| 718 // Note that while the printer won't print repeated strings in short-form, |
| 719 // the parser will accept them. |
| 720 "repeated_string: [ \"foo\", 'bar' ]\n" |
| 721 // Repeated message |
| 722 "repeated_nested_message: [ { bb: 1 }, { bb : 2 }]\n" |
| 723 // Repeated group |
| 724 "RepeatedGroup [{ a: 3 },{ a: 4 }]\n" |
| 725 // Adding empty [] should have no impact. |
| 726 "repeated_int32: []\n" |
| 727 "repeated_nested_enum: []\n" |
| 728 "repeated_string: []\n" |
| 729 "repeated_nested_message: []\n" |
| 730 "RepeatedGroup []\n"; |
| 731 |
| 732 ASSERT_TRUE(TextFormat::ParseFromString(parse_string, &proto_)); |
| 733 |
| 734 ASSERT_EQ(3, proto_.repeated_int32_size()); |
| 735 EXPECT_EQ(1, proto_.repeated_int32(0)); |
| 736 EXPECT_EQ(456, proto_.repeated_int32(1)); |
| 737 EXPECT_EQ(789, proto_.repeated_int32(2)); |
| 738 |
| 739 ASSERT_EQ(3, proto_.repeated_nested_enum_size()); |
| 740 EXPECT_EQ(unittest::TestAllTypes::FOO, proto_.repeated_nested_enum(0)); |
| 741 EXPECT_EQ(unittest::TestAllTypes::BAR, proto_.repeated_nested_enum(1)); |
| 742 EXPECT_EQ(unittest::TestAllTypes::BAZ, proto_.repeated_nested_enum(2)); |
| 743 |
| 744 ASSERT_EQ(2, proto_.repeated_string_size()); |
| 745 EXPECT_EQ("foo", proto_.repeated_string(0)); |
| 746 EXPECT_EQ("bar", proto_.repeated_string(1)); |
| 747 |
| 748 ASSERT_EQ(2, proto_.repeated_nested_message_size()); |
| 749 EXPECT_EQ(1, proto_.repeated_nested_message(0).bb()); |
| 750 EXPECT_EQ(2, proto_.repeated_nested_message(1).bb()); |
| 751 |
| 752 ASSERT_EQ(2, proto_.repeatedgroup_size()); |
| 753 EXPECT_EQ(3, proto_.repeatedgroup(0).a()); |
| 754 EXPECT_EQ(4, proto_.repeatedgroup(1).a()); |
| 755 } |
| 756 |
| 662 | 757 |
| 663 TEST_F(TextFormatTest, Comments) { | 758 TEST_F(TextFormatTest, Comments) { |
| 664 // Test that comments are ignored. | 759 // Test that comments are ignored. |
| 665 | 760 |
| 666 string parse_string = "optional_int32: 1 # a comment\n" | 761 string parse_string = "optional_int32: 1 # a comment\n" |
| 667 "optional_int64: 2 # another comment"; | 762 "optional_int64: 2 # another comment"; |
| 668 | 763 |
| 669 io::ArrayInputStream input_stream(parse_string.data(), | 764 io::ArrayInputStream input_stream(parse_string.data(), |
| 670 parse_string.size()); | 765 parse_string.size()); |
| 671 | 766 |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 | 1284 |
| 1190 #undef EXPECT_FIELD | 1285 #undef EXPECT_FIELD |
| 1191 #undef EXPECT_BOOL_FIELD | 1286 #undef EXPECT_BOOL_FIELD |
| 1192 #undef EXPECT_FLOAT_FIELD | 1287 #undef EXPECT_FLOAT_FIELD |
| 1193 #undef EXPECT_DOUBLE_FIELD | 1288 #undef EXPECT_DOUBLE_FIELD |
| 1194 #undef EXPECT_INVALID | 1289 #undef EXPECT_INVALID |
| 1195 } | 1290 } |
| 1196 | 1291 |
| 1197 | 1292 |
| 1198 TEST_F(TextFormatParserTest, InvalidToken) { | 1293 TEST_F(TextFormatParserTest, InvalidToken) { |
| 1199 ExpectFailure("optional_bool: true\n-5\n", "Expected identifier.", | 1294 ExpectFailure("optional_bool: true\n-5\n", "Expected identifier, got: -", |
| 1200 2, 1); | 1295 2, 1); |
| 1201 | 1296 |
| 1202 ExpectFailure("optional_bool: true!\n", "Expected identifier.", 1, 20); | 1297 ExpectFailure("optional_bool: true!\n", "Expected identifier, got: !", 1, |
| 1203 ExpectFailure("\"some string\"", "Expected identifier.", 1, 1); | 1298 20); |
| 1299 ExpectFailure("\"some string\"", |
| 1300 "Expected identifier, got: \"some string\"", 1, 1); |
| 1204 } | 1301 } |
| 1205 | 1302 |
| 1206 TEST_F(TextFormatParserTest, InvalidFieldName) { | 1303 TEST_F(TextFormatParserTest, InvalidFieldName) { |
| 1207 ExpectFailure( | 1304 ExpectFailure( |
| 1208 "invalid_field: somevalue\n", | 1305 "invalid_field: somevalue\n", |
| 1209 "Message type \"protobuf_unittest.TestAllTypes\" has no field named " | 1306 "Message type \"protobuf_unittest.TestAllTypes\" has no field named " |
| 1210 "\"invalid_field\".", | 1307 "\"invalid_field\".", |
| 1211 1, 14); | 1308 1, 14); |
| 1212 } | 1309 } |
| 1213 | 1310 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1241 // ... but are parsed correctly if we match case insensitive. | 1338 // ... but are parsed correctly if we match case insensitive. |
| 1242 parser.AllowCaseInsensitiveField(true); | 1339 parser.AllowCaseInsensitiveField(true); |
| 1243 EXPECT_TRUE(parser.ParseFromString("Optional_Double: 10.0", &proto)); | 1340 EXPECT_TRUE(parser.ParseFromString("Optional_Double: 10.0", &proto)); |
| 1244 EXPECT_EQ(10.0, proto.optional_double()); | 1341 EXPECT_EQ(10.0, proto.optional_double()); |
| 1245 EXPECT_TRUE(parser.ParseFromString("oPtIoNaLgRoUp { a: 15 }", &proto)); | 1342 EXPECT_TRUE(parser.ParseFromString("oPtIoNaLgRoUp { a: 15 }", &proto)); |
| 1246 EXPECT_EQ(15, proto.optionalgroup().a()); | 1343 EXPECT_EQ(15, proto.optionalgroup().a()); |
| 1247 } | 1344 } |
| 1248 | 1345 |
| 1249 TEST_F(TextFormatParserTest, InvalidFieldValues) { | 1346 TEST_F(TextFormatParserTest, InvalidFieldValues) { |
| 1250 // Invalid values for a double/float field. | 1347 // Invalid values for a double/float field. |
| 1251 ExpectFailure("optional_double: \"hello\"\n", "Expected double.", 1, 18); | 1348 ExpectFailure("optional_double: \"hello\"\n", |
| 1252 ExpectFailure("optional_double: true\n", "Expected double.", 1, 18); | 1349 "Expected double, got: \"hello\"", 1, 18); |
| 1253 ExpectFailure("optional_double: !\n", "Expected double.", 1, 18); | 1350 ExpectFailure("optional_double: true\n", "Expected double, got: true", 1, |
| 1351 18); |
| 1352 ExpectFailure("optional_double: !\n", "Expected double, got: !", 1, 18); |
| 1254 ExpectFailure("optional_double {\n \n}\n", "Expected \":\", found \"{\".", | 1353 ExpectFailure("optional_double {\n \n}\n", "Expected \":\", found \"{\".", |
| 1255 1, 17); | 1354 1, 17); |
| 1256 | 1355 |
| 1257 // Invalid values for a signed integer field. | 1356 // Invalid values for a signed integer field. |
| 1258 ExpectFailure("optional_int32: \"hello\"\n", "Expected integer.", 1, 17); | 1357 ExpectFailure("optional_int32: \"hello\"\n", |
| 1259 ExpectFailure("optional_int32: true\n", "Expected integer.", 1, 17); | 1358 "Expected integer, got: \"hello\"", 1, 17); |
| 1260 ExpectFailure("optional_int32: 4.5\n", "Expected integer.", 1, 17); | 1359 ExpectFailure("optional_int32: true\n", "Expected integer, got: true", 1, 17); |
| 1261 ExpectFailure("optional_int32: !\n", "Expected integer.", 1, 17); | 1360 ExpectFailure("optional_int32: 4.5\n", "Expected integer, got: 4.5", 1, 17); |
| 1361 ExpectFailure("optional_int32: !\n", "Expected integer, got: !", 1, 17); |
| 1262 ExpectFailure("optional_int32 {\n \n}\n", "Expected \":\", found \"{\".", | 1362 ExpectFailure("optional_int32 {\n \n}\n", "Expected \":\", found \"{\".", |
| 1263 1, 16); | 1363 1, 16); |
| 1264 ExpectFailure("optional_int32: 0x80000000\n", | 1364 ExpectFailure("optional_int32: 0x80000000\n", |
| 1265 "Integer out of range.", 1, 17); | 1365 "Integer out of range (0x80000000)", 1, 17); |
| 1266 ExpectFailure("optional_int64: 0x8000000000000000\n", | 1366 ExpectFailure("optional_int64: 0x8000000000000000\n", |
| 1267 "Integer out of range.", 1, 17); | 1367 "Integer out of range (0x8000000000000000)", 1, 17); |
| 1268 ExpectFailure("optional_int32: -0x80000001\n", | 1368 ExpectFailure("optional_int32: -0x80000001\n", |
| 1269 "Integer out of range.", 1, 18); | 1369 "Integer out of range (0x80000001)", 1, 18); |
| 1270 ExpectFailure("optional_int64: -0x8000000000000001\n", | 1370 ExpectFailure("optional_int64: -0x8000000000000001\n", |
| 1271 "Integer out of range.", 1, 18); | 1371 "Integer out of range (0x8000000000000001)", 1, 18); |
| 1272 | 1372 |
| 1273 // Invalid values for an unsigned integer field. | 1373 // Invalid values for an unsigned integer field. |
| 1274 ExpectFailure("optional_uint64: \"hello\"\n", "Expected integer.", 1, 18); | 1374 ExpectFailure("optional_uint64: \"hello\"\n", |
| 1275 ExpectFailure("optional_uint64: true\n", "Expected integer.", 1, 18); | 1375 "Expected integer, got: \"hello\"", 1, 18); |
| 1276 ExpectFailure("optional_uint64: 4.5\n", "Expected integer.", 1, 18); | 1376 ExpectFailure("optional_uint64: true\n", |
| 1277 ExpectFailure("optional_uint64: -5\n", "Expected integer.", 1, 18); | 1377 "Expected integer, got: true", 1, 18); |
| 1278 ExpectFailure("optional_uint64: !\n", "Expected integer.", 1, 18); | 1378 ExpectFailure("optional_uint64: 4.5\n", "Expected integer, got: 4.5", 1, 18); |
| 1379 ExpectFailure("optional_uint64: -5\n", "Expected integer, got: -", 1, 18); |
| 1380 ExpectFailure("optional_uint64: !\n", "Expected integer, got: !", 1, 18); |
| 1279 ExpectFailure("optional_uint64 {\n \n}\n", "Expected \":\", found \"{\".", | 1381 ExpectFailure("optional_uint64 {\n \n}\n", "Expected \":\", found \"{\".", |
| 1280 1, 17); | 1382 1, 17); |
| 1281 ExpectFailure("optional_uint32: 0x100000000\n", | 1383 ExpectFailure("optional_uint32: 0x100000000\n", |
| 1282 "Integer out of range.", 1, 18); | 1384 "Integer out of range (0x100000000)", 1, 18); |
| 1283 ExpectFailure("optional_uint64: 0x10000000000000000\n", | 1385 ExpectFailure("optional_uint64: 0x10000000000000000\n", |
| 1284 "Integer out of range.", 1, 18); | 1386 "Integer out of range (0x10000000000000000)", 1, 18); |
| 1285 | 1387 |
| 1286 // Invalid values for a boolean field. | 1388 // Invalid values for a boolean field. |
| 1287 ExpectFailure("optional_bool: \"hello\"\n", "Expected identifier.", 1, 16); | 1389 ExpectFailure("optional_bool: \"hello\"\n", |
| 1288 ExpectFailure("optional_bool: 5\n", "Integer out of range.", 1, 16); | 1390 "Expected identifier, got: \"hello\"", 1, 16); |
| 1289 ExpectFailure("optional_bool: -7.5\n", "Expected identifier.", 1, 16); | 1391 ExpectFailure("optional_bool: 5\n", "Integer out of range (5)", 1, 16); |
| 1290 ExpectFailure("optional_bool: !\n", "Expected identifier.", 1, 16); | 1392 ExpectFailure("optional_bool: -7.5\n", "Expected identifier, got: -", 1, 16); |
| 1393 ExpectFailure("optional_bool: !\n", "Expected identifier, got: !", 1, 16); |
| 1291 | 1394 |
| 1292 ExpectFailure( | 1395 ExpectFailure( |
| 1293 "optional_bool: meh\n", | 1396 "optional_bool: meh\n", |
| 1294 "Invalid value for boolean field \"optional_bool\". Value: \"meh\".", | 1397 "Invalid value for boolean field \"optional_bool\". Value: \"meh\".", |
| 1295 2, 1); | 1398 2, 1); |
| 1296 | 1399 |
| 1297 ExpectFailure("optional_bool {\n \n}\n", "Expected \":\", found \"{\".", | 1400 ExpectFailure("optional_bool {\n \n}\n", "Expected \":\", found \"{\".", |
| 1298 1, 15); | 1401 1, 15); |
| 1299 | 1402 |
| 1300 // Invalid values for a string field. | 1403 // Invalid values for a string field. |
| 1301 ExpectFailure("optional_string: true\n", "Expected string.", 1, 18); | 1404 ExpectFailure("optional_string: true\n", "Expected string, got: true", 1, 18); |
| 1302 ExpectFailure("optional_string: 5\n", "Expected string.", 1, 18); | 1405 ExpectFailure("optional_string: 5\n", "Expected string, got: 5", 1, 18); |
| 1303 ExpectFailure("optional_string: -7.5\n", "Expected string.", 1, 18); | 1406 ExpectFailure("optional_string: -7.5\n", "Expected string, got: -", 1, 18); |
| 1304 ExpectFailure("optional_string: !\n", "Expected string.", 1, 18); | 1407 ExpectFailure("optional_string: !\n", "Expected string, got: !", 1, 18); |
| 1305 ExpectFailure("optional_string {\n \n}\n", "Expected \":\", found \"{\".", | 1408 ExpectFailure("optional_string {\n \n}\n", "Expected \":\", found \"{\".", |
| 1306 1, 17); | 1409 1, 17); |
| 1307 | 1410 |
| 1308 // Invalid values for an enumeration field. | 1411 // Invalid values for an enumeration field. |
| 1309 ExpectFailure("optional_nested_enum: \"hello\"\n", | 1412 ExpectFailure("optional_nested_enum: \"hello\"\n", |
| 1310 "Expected integer or identifier.", 1, 23); | 1413 "Expected integer or identifier, got: \"hello\"", 1, 23); |
| 1311 | 1414 |
| 1312 // Valid token, but enum value is not defined. | 1415 // Valid token, but enum value is not defined. |
| 1313 ExpectFailure("optional_nested_enum: 5\n", | 1416 ExpectFailure("optional_nested_enum: 5\n", |
| 1314 "Unknown enumeration value of \"5\" for field " | 1417 "Unknown enumeration value of \"5\" for field " |
| 1315 "\"optional_nested_enum\".", 2, 1); | 1418 "\"optional_nested_enum\".", 2, 1); |
| 1316 // We consume the negative sign, so the error position starts one character | 1419 // We consume the negative sign, so the error position starts one character |
| 1317 // later. | 1420 // later. |
| 1318 ExpectFailure("optional_nested_enum: -7.5\n", "Expected integer.", 1, 24); | 1421 ExpectFailure("optional_nested_enum: -7.5\n", "Expected integer, got: 7.5", 1, |
| 1422 24); |
| 1319 ExpectFailure("optional_nested_enum: !\n", | 1423 ExpectFailure("optional_nested_enum: !\n", |
| 1320 "Expected integer or identifier.", 1, 23); | 1424 "Expected integer or identifier, got: !", 1, 23); |
| 1321 | 1425 |
| 1322 ExpectFailure( | 1426 ExpectFailure( |
| 1323 "optional_nested_enum: grah\n", | 1427 "optional_nested_enum: grah\n", |
| 1324 "Unknown enumeration value of \"grah\" for field " | 1428 "Unknown enumeration value of \"grah\" for field " |
| 1325 "\"optional_nested_enum\".", 2, 1); | 1429 "\"optional_nested_enum\".", 2, 1); |
| 1326 | 1430 |
| 1327 ExpectFailure( | 1431 ExpectFailure( |
| 1328 "optional_nested_enum {\n \n}\n", | 1432 "optional_nested_enum {\n \n}\n", |
| 1329 "Expected \":\", found \"{\".", 1, 22); | 1433 "Expected \":\", found \"{\".", 1, 22); |
| 1330 } | 1434 } |
| 1331 | 1435 |
| 1332 TEST_F(TextFormatParserTest, MessageDelimiters) { | 1436 TEST_F(TextFormatParserTest, MessageDelimiters) { |
| 1333 // Non-matching delimiters. | 1437 // Non-matching delimiters. |
| 1334 ExpectFailure("OptionalGroup <\n \n}\n", "Expected \">\", found \"}\".", | 1438 ExpectFailure("OptionalGroup <\n \n}\n", "Expected \">\", found \"}\".", |
| 1335 3, 1); | 1439 3, 1); |
| 1336 | 1440 |
| 1337 // Invalid delimiters. | 1441 // Invalid delimiters. |
| 1338 ExpectFailure("OptionalGroup [\n \n]\n", "Expected \"{\", found \"[\".", | 1442 ExpectFailure("OptionalGroup [\n \n]\n", "Expected \"{\", found \"[\".", |
| 1339 1, 15); | 1443 1, 15); |
| 1340 | 1444 |
| 1341 // Unending message. | 1445 // Unending message. |
| 1342 ExpectFailure("optional_nested_message {\n \nbb: 118\n", | 1446 ExpectFailure("optional_nested_message {\n \nbb: 118\n", |
| 1343 "Expected identifier.", | 1447 "Expected identifier, got: ", |
| 1344 4, 1); | 1448 4, 1); |
| 1345 } | 1449 } |
| 1346 | 1450 |
| 1347 TEST_F(TextFormatParserTest, UnknownExtension) { | 1451 TEST_F(TextFormatParserTest, UnknownExtension) { |
| 1348 // Non-matching delimiters. | 1452 // Non-matching delimiters. |
| 1349 ExpectFailure("[blahblah]: 123", | 1453 ExpectFailure("[blahblah]: 123", |
| 1350 "Extension \"blahblah\" is not defined or is not an " | 1454 "Extension \"blahblah\" is not defined or is not an " |
| 1351 "extension of \"protobuf_unittest.TestAllTypes\".", | 1455 "extension of \"protobuf_unittest.TestAllTypes\".", |
| 1352 1, 11); | 1456 1, 11); |
| 1353 } | 1457 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 vector<const FieldDescriptor*> descriptors; | 1579 vector<const FieldDescriptor*> descriptors; |
| 1476 proto.message_set().GetReflection()->ListFields( | 1580 proto.message_set().GetReflection()->ListFields( |
| 1477 proto.message_set(), &descriptors); | 1581 proto.message_set(), &descriptors); |
| 1478 EXPECT_EQ(2, descriptors.size()); | 1582 EXPECT_EQ(2, descriptors.size()); |
| 1479 } | 1583 } |
| 1480 | 1584 |
| 1481 | 1585 |
| 1482 } // namespace text_format_unittest | 1586 } // namespace text_format_unittest |
| 1483 } // namespace protobuf | 1587 } // namespace protobuf |
| 1484 } // namespace google | 1588 } // namespace google |
| OLD | NEW |