| 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..eaa7e045338efd9f0bffe861de17f2b64f05d63d 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,15 @@ 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) {
|
| JsonStreamParser parser(&mock_);
|
|
|
| // Special case for split == length, test parsing one character at a time.
|
| @@ -116,8 +119,10 @@ 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) {
|
| + util::Status result =
|
| + RunTest(json, split, coerce_utf8, allow_empty_null);
|
| if (!result.ok()) {
|
| GOOGLE_LOG(WARNING) << result;
|
| }
|
| @@ -125,14 +130,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 +320,28 @@ TEST_F(JsonStreamParserTest, ObjectKeyTypes) {
|
| }
|
| }
|
|
|
| -// - array containing array, object, values (true, false, null, num, string)
|
| -TEST_F(JsonStreamParserTest, ArrayValues) {
|
| +// - array containing primitive values (true, false, null, num, string)
|
| +TEST_F(JsonStreamParserTest, ArrayPrimitiveValues) {
|
| StringPiece str =
|
| - "[true, false, null, 'a string', \"another string\", [22, -127, 45.3, "
|
| - "-1056.4, 11779497823553162765], {'key': true}]";
|
| + "[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 +357,7 @@ TEST_F(JsonStreamParserTest, ArrayValues) {
|
| }
|
| }
|
|
|
| +
|
| // - object containing array, object, value (true, false, null, num, string)
|
| TEST_F(JsonStreamParserTest, ObjectValues) {
|
| StringPiece str =
|
|
|