Index: third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser_test.cc |
diff --git a/third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser_test.cc b/third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser_test.cc |
index 059ea6d86af099f9237e53d1e80af7b118f5ef84..ca71ff2419ff5bf8ab7546094448685917a756c6 100644 |
--- a/third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser_test.cc |
+++ b/third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser_test.cc |
@@ -81,12 +81,16 @@ using util::Status; |
// For each test we split the input string on every possible character to ensure |
// the parser is able to handle arbitrarily split input for all cases. We also |
// do a final test of the entire test case one character at a time. |
+// |
+// It is verified that expected calls to the mocked objects are in sequence. |
class JsonStreamParserTest : public ::testing::Test { |
protected: |
JsonStreamParserTest() : mock_(), ow_(&mock_) {} |
virtual ~JsonStreamParserTest() {} |
- util::Status RunTest(StringPiece json, int split, bool coerce_utf8 = false) { |
+ util::Status RunTest(StringPiece json, int split, bool coerce_utf8 = false, |
+ bool allow_empty_null = false, |
+ bool loose_float_number_conversion = false) { |
JsonStreamParser parser(&mock_); |
// Special case for split == length, test parsing one character at a time. |
@@ -116,8 +120,11 @@ class JsonStreamParserTest : public ::testing::Test { |
return result; |
} |
- void DoTest(StringPiece json, int split, bool coerce_utf8 = false) { |
- util::Status result = RunTest(json, split, coerce_utf8); |
+ void DoTest(StringPiece json, int split, bool coerce_utf8 = false, |
+ bool allow_empty_null = false, |
+ bool loose_float_number_conversion = false) { |
+ util::Status result = RunTest(json, split, coerce_utf8, allow_empty_null, |
+ loose_float_number_conversion); |
if (!result.ok()) { |
GOOGLE_LOG(WARNING) << result; |
} |
@@ -125,14 +132,21 @@ class JsonStreamParserTest : public ::testing::Test { |
} |
void DoErrorTest(StringPiece json, int split, StringPiece error_prefix, |
- bool coerce_utf8 = false) { |
- util::Status result = RunTest(json, split, coerce_utf8); |
+ bool coerce_utf8 = false, bool allow_empty_null = false) { |
+ util::Status result = |
+ RunTest(json, split, coerce_utf8, allow_empty_null); |
EXPECT_EQ(util::error::INVALID_ARGUMENT, result.error_code()); |
StringPiece error_message(result.error_message()); |
EXPECT_EQ(error_prefix, error_message.substr(0, error_prefix.size())); |
} |
+#ifndef _MSC_VER |
+ // TODO(xiaofeng): We have to disable InSequence check for MSVC because it |
+ // causes stack overflow due to its use of a linked list that is desctructed |
+ // recursively. |
+ ::testing::InSequence in_sequence_; |
+#endif // !_MSC_VER |
MockObjectWriter mock_; |
ExpectingObjectWriter ow_; |
}; |
@@ -308,18 +322,27 @@ TEST_F(JsonStreamParserTest, ObjectKeyTypes) { |
} |
} |
-// - array containing array, object, values (true, false, null, num, string) |
-TEST_F(JsonStreamParserTest, ArrayValues) { |
- StringPiece str = |
- "[true, false, null, 'a string', \"another string\", [22, -127, 45.3, " |
- "-1056.4, 11779497823553162765], {'key': true}]"; |
+// - array containing primitive values (true, false, null, num, string) |
+TEST_F(JsonStreamParserTest, ArrayPrimitiveValues) { |
+ StringPiece str = "[true, false, null, 'one', \"two\"]"; |
for (int i = 0; i <= str.length(); ++i) { |
ow_.StartList("") |
->RenderBool("", true) |
->RenderBool("", false) |
->RenderNull("") |
- ->RenderString("", "a string") |
- ->RenderString("", "another string") |
+ ->RenderString("", "one") |
+ ->RenderString("", "two") |
+ ->EndList(); |
+ DoTest(str, i); |
+ } |
+} |
+ |
+// - array containing array, object |
+TEST_F(JsonStreamParserTest, ArrayComplexValues) { |
+ StringPiece str = |
+ "[[22, -127, 45.3, -1056.4, 11779497823553162765], {'key': true}]"; |
+ for (int i = 0; i <= str.length(); ++i) { |
+ ow_.StartList("") |
->StartList("") |
->RenderUint64("", 22) |
->RenderInt64("", -127) |
@@ -335,6 +358,7 @@ TEST_F(JsonStreamParserTest, ArrayValues) { |
} |
} |
+ |
// - object containing array, object, value (true, false, null, num, string) |
TEST_F(JsonStreamParserTest, ObjectValues) { |
StringPiece str = |
@@ -687,17 +711,19 @@ TEST_F(JsonStreamParserTest, NegativeNumberTooBig) { |
} |
} |
-/* |
-TODO(sven): Fail parsing when parsing a double that is too large. |
- |
TEST_F(JsonStreamParserTest, DoubleTooBig) { |
- StringPiece str = "[184464073709551232321616.45]"; |
+ StringPiece str = "[1.89769e+308]"; |
for (int i = 0; i <= str.length(); ++i) { |
ow_.StartList(""); |
- DoErrorTest(str, i, "Unable to parse number"); |
+ DoErrorTest(str, i, "Number exceeds the range of double."); |
+ } |
+ str = "[-1.89769e+308]"; |
+ for (int i = 0; i <= str.length(); ++i) { |
+ ow_.StartList(""); |
+ DoErrorTest(str, i, "Number exceeds the range of double."); |
} |
} |
-*/ |
+ |
// invalid bare backslash. |
TEST_F(JsonStreamParserTest, UnfinishedEscape) { |