Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Unified Diff: third_party/protobuf/src/google/protobuf/text_format_unittest.cc

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/src/google/protobuf/text_format_unittest.cc
diff --git a/third_party/protobuf/src/google/protobuf/text_format_unittest.cc b/third_party/protobuf/src/google/protobuf/text_format_unittest.cc
index e644133953548e09107f469794d34d78427ddec5..58aa3f8d6172fe326008c7b745c9fa497cfd23ea 100644
--- a/third_party/protobuf/src/google/protobuf/text_format_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/text_format_unittest.cc
@@ -53,11 +53,11 @@
#include <google/protobuf/unittest_mset_wire_format.pb.h>
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
-#include <google/protobuf/stubs/mathlimits.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
+#include <google/protobuf/stubs/mathlimits.h>
namespace google {
@@ -157,21 +157,7 @@ TEST_F(TextFormatTest, ShortPrimitiveRepeateds) {
TextFormat::Printer printer;
printer.SetUseShortRepeatedPrimitives(true);
string text;
- EXPECT_TRUE(printer.PrintToString(proto_, &text));
-
- EXPECT_EQ("optional_int32: 123\n"
- "repeated_int32: [456, 789]\n"
- "repeated_string: \"foo\"\n"
- "repeated_string: \"bar\"\n"
- "repeated_nested_message {\n bb: 2\n}\n"
- "repeated_nested_message {\n bb: 3\n}\n"
- "repeated_nested_enum: [FOO, BAR]\n",
- text);
-
- // Verify that any existing data in the string is cleared when
- // PrintToString() is called.
- text = "just some data here...\n\nblah blah";
- EXPECT_TRUE(printer.PrintToString(proto_, &text));
+ printer.PrintToString(proto_, &text);
EXPECT_EQ("optional_int32: 123\n"
"repeated_int32: [456, 789]\n"
@@ -184,7 +170,7 @@ TEST_F(TextFormatTest, ShortPrimitiveRepeateds) {
// Try in single-line mode.
printer.SetSingleLineMode(true);
- EXPECT_TRUE(printer.PrintToString(proto_, &text));
+ printer.PrintToString(proto_, &text);
EXPECT_EQ("optional_int32: 123 "
"repeated_int32: [456, 789] "
@@ -673,87 +659,6 @@ TEST_F(TextFormatTest, ParseShortRepeatedForm) {
EXPECT_EQ(4, proto_.repeatedgroup(1).a());
}
-TEST_F(TextFormatTest, ParseShortRepeatedWithTrailingComma) {
- string parse_string = "repeated_int32: [456,]\n";
- ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_));
- parse_string = "repeated_nested_enum: [ FOO , ]";
- ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_));
- parse_string = "repeated_string: [ \"foo\", ]";
- ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_));
- parse_string = "repeated_nested_message: [ { bb: 1 }, ]";
- ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_));
- parse_string = "RepeatedGroup [{ a: 3 },]\n";
-}
-
-TEST_F(TextFormatTest, ParseShortRepeatedEmpty) {
- string parse_string =
- "repeated_int32: []\n"
- "repeated_nested_enum: []\n"
- "repeated_string: []\n"
- "repeated_nested_message: []\n"
- "RepeatedGroup []\n";
-
- ASSERT_TRUE(TextFormat::ParseFromString(parse_string, &proto_));
-
- EXPECT_EQ(0, proto_.repeated_int32_size());
- EXPECT_EQ(0, proto_.repeated_nested_enum_size());
- EXPECT_EQ(0, proto_.repeated_string_size());
- EXPECT_EQ(0, proto_.repeated_nested_message_size());
- EXPECT_EQ(0, proto_.repeatedgroup_size());
-}
-
-TEST_F(TextFormatTest, ParseShortRepeatedConcatenatedWithEmpty) {
- string parse_string =
- // Starting with empty [] should have no impact.
- "repeated_int32: []\n"
- "repeated_nested_enum: []\n"
- "repeated_string: []\n"
- "repeated_nested_message: []\n"
- "RepeatedGroup []\n"
- // Mixed short-form and long-form are simply concatenated.
- "repeated_int32: 1\n"
- "repeated_int32: [456, 789]\n"
- "repeated_nested_enum: [ FOO ,BAR, # comment\n"
- " 3]\n"
- // Note that while the printer won't print repeated strings in short-form,
- // the parser will accept them.
- "repeated_string: [ \"foo\", 'bar' ]\n"
- // Repeated message
- "repeated_nested_message: [ { bb: 1 }, { bb : 2 }]\n"
- // Repeated group
- "RepeatedGroup [{ a: 3 },{ a: 4 }]\n"
- // Adding empty [] should have no impact.
- "repeated_int32: []\n"
- "repeated_nested_enum: []\n"
- "repeated_string: []\n"
- "repeated_nested_message: []\n"
- "RepeatedGroup []\n";
-
- ASSERT_TRUE(TextFormat::ParseFromString(parse_string, &proto_));
-
- ASSERT_EQ(3, proto_.repeated_int32_size());
- EXPECT_EQ(1, proto_.repeated_int32(0));
- EXPECT_EQ(456, proto_.repeated_int32(1));
- EXPECT_EQ(789, proto_.repeated_int32(2));
-
- ASSERT_EQ(3, proto_.repeated_nested_enum_size());
- EXPECT_EQ(unittest::TestAllTypes::FOO, proto_.repeated_nested_enum(0));
- EXPECT_EQ(unittest::TestAllTypes::BAR, proto_.repeated_nested_enum(1));
- EXPECT_EQ(unittest::TestAllTypes::BAZ, proto_.repeated_nested_enum(2));
-
- ASSERT_EQ(2, proto_.repeated_string_size());
- EXPECT_EQ("foo", proto_.repeated_string(0));
- EXPECT_EQ("bar", proto_.repeated_string(1));
-
- ASSERT_EQ(2, proto_.repeated_nested_message_size());
- EXPECT_EQ(1, proto_.repeated_nested_message(0).bb());
- EXPECT_EQ(2, proto_.repeated_nested_message(1).bb());
-
- ASSERT_EQ(2, proto_.repeatedgroup_size());
- EXPECT_EQ(3, proto_.repeatedgroup(0).a());
- EXPECT_EQ(4, proto_.repeatedgroup(1).a());
-}
-
TEST_F(TextFormatTest, Comments) {
// Test that comments are ignored.
@@ -993,14 +898,10 @@ TEST_F(TextFormatTest, ParseExotic) {
EXPECT_EQ(1.235E22 , message.repeated_double(4));
EXPECT_EQ(1.235E-18 , message.repeated_double(5));
EXPECT_EQ(123.456789, message.repeated_double(6));
- EXPECT_EQ(message.repeated_double(7),
- std::numeric_limits<double>::infinity());
- EXPECT_EQ(message.repeated_double(8),
- std::numeric_limits<double>::infinity());
- EXPECT_EQ(message.repeated_double(9),
- -std::numeric_limits<double>::infinity());
- EXPECT_EQ(message.repeated_double(10),
- -std::numeric_limits<double>::infinity());
+ EXPECT_EQ(message.repeated_double(7), numeric_limits<double>::infinity());
+ EXPECT_EQ(message.repeated_double(8), numeric_limits<double>::infinity());
+ EXPECT_EQ(message.repeated_double(9), -numeric_limits<double>::infinity());
+ EXPECT_EQ(message.repeated_double(10), -numeric_limits<double>::infinity());
EXPECT_TRUE(MathLimits<double>::IsNaN(message.repeated_double(11)));
EXPECT_TRUE(MathLimits<double>::IsNaN(message.repeated_double(12)));
@@ -1295,13 +1196,11 @@ TEST_F(TextFormatParserTest, ParseFieldValueFromString) {
TEST_F(TextFormatParserTest, InvalidToken) {
- ExpectFailure("optional_bool: true\n-5\n", "Expected identifier, got: -",
+ ExpectFailure("optional_bool: true\n-5\n", "Expected identifier.",
2, 1);
- ExpectFailure("optional_bool: true!\n", "Expected identifier, got: !", 1,
- 20);
- ExpectFailure("\"some string\"",
- "Expected identifier, got: \"some string\"", 1, 1);
+ ExpectFailure("optional_bool: true!\n", "Expected identifier.", 1, 20);
+ ExpectFailure("\"some string\"", "Expected identifier.", 1, 1);
}
TEST_F(TextFormatParserTest, InvalidFieldName) {
@@ -1349,52 +1248,46 @@ TEST_F(TextFormatParserTest, AllowIgnoreCapitalizationError) {
TEST_F(TextFormatParserTest, InvalidFieldValues) {
// Invalid values for a double/float field.
- ExpectFailure("optional_double: \"hello\"\n",
- "Expected double, got: \"hello\"", 1, 18);
- ExpectFailure("optional_double: true\n", "Expected double, got: true", 1,
- 18);
- ExpectFailure("optional_double: !\n", "Expected double, got: !", 1, 18);
+ ExpectFailure("optional_double: \"hello\"\n", "Expected double.", 1, 18);
+ ExpectFailure("optional_double: true\n", "Expected double.", 1, 18);
+ ExpectFailure("optional_double: !\n", "Expected double.", 1, 18);
ExpectFailure("optional_double {\n \n}\n", "Expected \":\", found \"{\".",
1, 17);
// Invalid values for a signed integer field.
- ExpectFailure("optional_int32: \"hello\"\n",
- "Expected integer, got: \"hello\"", 1, 17);
- ExpectFailure("optional_int32: true\n", "Expected integer, got: true", 1, 17);
- ExpectFailure("optional_int32: 4.5\n", "Expected integer, got: 4.5", 1, 17);
- ExpectFailure("optional_int32: !\n", "Expected integer, got: !", 1, 17);
+ ExpectFailure("optional_int32: \"hello\"\n", "Expected integer.", 1, 17);
+ ExpectFailure("optional_int32: true\n", "Expected integer.", 1, 17);
+ ExpectFailure("optional_int32: 4.5\n", "Expected integer.", 1, 17);
+ ExpectFailure("optional_int32: !\n", "Expected integer.", 1, 17);
ExpectFailure("optional_int32 {\n \n}\n", "Expected \":\", found \"{\".",
1, 16);
ExpectFailure("optional_int32: 0x80000000\n",
- "Integer out of range (0x80000000)", 1, 17);
+ "Integer out of range.", 1, 17);
ExpectFailure("optional_int64: 0x8000000000000000\n",
- "Integer out of range (0x8000000000000000)", 1, 17);
+ "Integer out of range.", 1, 17);
ExpectFailure("optional_int32: -0x80000001\n",
- "Integer out of range (0x80000001)", 1, 18);
+ "Integer out of range.", 1, 18);
ExpectFailure("optional_int64: -0x8000000000000001\n",
- "Integer out of range (0x8000000000000001)", 1, 18);
+ "Integer out of range.", 1, 18);
// Invalid values for an unsigned integer field.
- ExpectFailure("optional_uint64: \"hello\"\n",
- "Expected integer, got: \"hello\"", 1, 18);
- ExpectFailure("optional_uint64: true\n",
- "Expected integer, got: true", 1, 18);
- ExpectFailure("optional_uint64: 4.5\n", "Expected integer, got: 4.5", 1, 18);
- ExpectFailure("optional_uint64: -5\n", "Expected integer, got: -", 1, 18);
- ExpectFailure("optional_uint64: !\n", "Expected integer, got: !", 1, 18);
+ ExpectFailure("optional_uint64: \"hello\"\n", "Expected integer.", 1, 18);
+ ExpectFailure("optional_uint64: true\n", "Expected integer.", 1, 18);
+ ExpectFailure("optional_uint64: 4.5\n", "Expected integer.", 1, 18);
+ ExpectFailure("optional_uint64: -5\n", "Expected integer.", 1, 18);
+ ExpectFailure("optional_uint64: !\n", "Expected integer.", 1, 18);
ExpectFailure("optional_uint64 {\n \n}\n", "Expected \":\", found \"{\".",
1, 17);
ExpectFailure("optional_uint32: 0x100000000\n",
- "Integer out of range (0x100000000)", 1, 18);
+ "Integer out of range.", 1, 18);
ExpectFailure("optional_uint64: 0x10000000000000000\n",
- "Integer out of range (0x10000000000000000)", 1, 18);
+ "Integer out of range.", 1, 18);
// Invalid values for a boolean field.
- ExpectFailure("optional_bool: \"hello\"\n",
- "Expected identifier, got: \"hello\"", 1, 16);
- ExpectFailure("optional_bool: 5\n", "Integer out of range (5)", 1, 16);
- ExpectFailure("optional_bool: -7.5\n", "Expected identifier, got: -", 1, 16);
- ExpectFailure("optional_bool: !\n", "Expected identifier, got: !", 1, 16);
+ ExpectFailure("optional_bool: \"hello\"\n", "Expected identifier.", 1, 16);
+ ExpectFailure("optional_bool: 5\n", "Integer out of range.", 1, 16);
+ ExpectFailure("optional_bool: -7.5\n", "Expected identifier.", 1, 16);
+ ExpectFailure("optional_bool: !\n", "Expected identifier.", 1, 16);
ExpectFailure(
"optional_bool: meh\n",
@@ -1405,16 +1298,16 @@ TEST_F(TextFormatParserTest, InvalidFieldValues) {
1, 15);
// Invalid values for a string field.
- ExpectFailure("optional_string: true\n", "Expected string, got: true", 1, 18);
- ExpectFailure("optional_string: 5\n", "Expected string, got: 5", 1, 18);
- ExpectFailure("optional_string: -7.5\n", "Expected string, got: -", 1, 18);
- ExpectFailure("optional_string: !\n", "Expected string, got: !", 1, 18);
+ ExpectFailure("optional_string: true\n", "Expected string.", 1, 18);
+ ExpectFailure("optional_string: 5\n", "Expected string.", 1, 18);
+ ExpectFailure("optional_string: -7.5\n", "Expected string.", 1, 18);
+ ExpectFailure("optional_string: !\n", "Expected string.", 1, 18);
ExpectFailure("optional_string {\n \n}\n", "Expected \":\", found \"{\".",
1, 17);
// Invalid values for an enumeration field.
ExpectFailure("optional_nested_enum: \"hello\"\n",
- "Expected integer or identifier, got: \"hello\"", 1, 23);
+ "Expected integer or identifier.", 1, 23);
// Valid token, but enum value is not defined.
ExpectFailure("optional_nested_enum: 5\n",
@@ -1422,10 +1315,9 @@ TEST_F(TextFormatParserTest, InvalidFieldValues) {
"\"optional_nested_enum\".", 2, 1);
// We consume the negative sign, so the error position starts one character
// later.
- ExpectFailure("optional_nested_enum: -7.5\n", "Expected integer, got: 7.5", 1,
- 24);
+ ExpectFailure("optional_nested_enum: -7.5\n", "Expected integer.", 1, 24);
ExpectFailure("optional_nested_enum: !\n",
- "Expected integer or identifier, got: !", 1, 23);
+ "Expected integer or identifier.", 1, 23);
ExpectFailure(
"optional_nested_enum: grah\n",
@@ -1448,7 +1340,7 @@ TEST_F(TextFormatParserTest, MessageDelimiters) {
// Unending message.
ExpectFailure("optional_nested_message {\n \nbb: 118\n",
- "Expected identifier, got: ",
+ "Expected identifier.",
4, 1);
}
@@ -1504,7 +1396,7 @@ TEST_F(TextFormatParserTest, ExplicitDelimiters) {
}
TEST_F(TextFormatParserTest, PrintErrorsToStderr) {
- std::vector<string> errors;
+ vector<string> errors;
{
ScopedMemoryLog log;
@@ -1521,7 +1413,7 @@ TEST_F(TextFormatParserTest, PrintErrorsToStderr) {
}
TEST_F(TextFormatParserTest, FailsOnTokenizationError) {
- std::vector<string> errors;
+ vector<string> errors;
{
ScopedMemoryLog log;
@@ -1580,7 +1472,7 @@ TEST_F(TextFormatMessageSetTest, Deserialize) {
protobuf_unittest::TestMessageSetExtension2::message_set_extension).str());
// Ensure that these are the only entries present.
- std::vector<const FieldDescriptor*> descriptors;
+ vector<const FieldDescriptor*> descriptors;
proto.message_set().GetReflection()->ListFields(
proto.message_set(), &descriptors);
EXPECT_EQ(2, descriptors.size());
« no previous file with comments | « third_party/protobuf/src/google/protobuf/text_format.cc ('k') | third_party/protobuf/src/google/protobuf/timestamp.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698