You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by qi...@apache.org on 2018/03/14 03:33:13 UTC

[5/5] mesos git commit: Updated `ProtobufTest.JSON` for parsing JSON::String to bools & numbers.

Updated `ProtobufTest.JSON` for parsing JSON::String to bools & numbers.

Review: https://reviews.apache.org/r/66026


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/61e77658
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/61e77658
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/61e77658

Branch: refs/heads/master
Commit: 61e77658ad1fc9eb72f1b0fa26c4c3257e265fbb
Parents: 499afcc
Author: Qian Zhang <zh...@gmail.com>
Authored: Mon Mar 12 09:15:10 2018 +0800
Committer: Qian Zhang <zh...@gmail.com>
Committed: Wed Mar 14 08:18:53 2018 +0800

----------------------------------------------------------------------
 3rdparty/stout/tests/protobuf_tests.cpp | 44 ++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/61e77658/3rdparty/stout/tests/protobuf_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/protobuf_tests.cpp b/3rdparty/stout/tests/protobuf_tests.cpp
index be35ad0..1c98ce2 100644
--- a/3rdparty/stout/tests/protobuf_tests.cpp
+++ b/3rdparty/stout/tests/protobuf_tests.cpp
@@ -136,6 +136,40 @@ TEST(ProtobufTest, JSON)
       "}",
       " ");
 
+  // The only difference between this JSON string and the above one is, all
+  // the bools and numbers are in the format of strings.
+  string accepted = strings::remove(
+      "{"
+      "  \"b\": \"true\","
+      "  \"bytes\": \"Ynl0ZXM=\","
+      "  \"d\": \"1.0\","
+      "  \"e\": \"ONE\","
+      "  \"f\": \"1.0\","
+      "  \"int32\": \"-1\","
+      "  \"int64\": \"-1\","
+      "  \"nested\": { \"str\": \"nested\"},"
+      "  \"optional_default\": \"42.0\","
+      "  \"repeated_bool\": [\"true\"],"
+      "  \"repeated_bytes\": [\"cmVwZWF0ZWRfYnl0ZXM=\"],"
+      "  \"repeated_double\": [\"1.0\", \"2.0\"],"
+      "  \"repeated_enum\": [\"TWO\"],"
+      "  \"repeated_float\": [\"1.0\"],"
+      "  \"repeated_int32\": [\"-2\"],"
+      "  \"repeated_int64\": [\"-2\"],"
+      "  \"repeated_nested\": [ { \"str\": \"repeated_nested\" } ],"
+      "  \"repeated_sint32\": [\"-2\"],"
+      "  \"repeated_sint64\": [\"-2\"],"
+      "  \"repeated_string\": [\"repeated_string\"],"
+      "  \"repeated_uint32\": [\"2\"],"
+      "  \"repeated_uint64\": [\"2\"],"
+      "  \"sint32\": \"-1\","
+      "  \"sint64\": \"-1\","
+      "  \"str\": \"string\","
+      "  \"uint32\": \"1\","
+      "  \"uint64\": \"1\""
+      "}",
+      " ");
+
   JSON::Object object = JSON::protobuf(message);
 
   EXPECT_EQ(expected, stringify(object));
@@ -146,6 +180,16 @@ TEST(ProtobufTest, JSON)
 
   EXPECT_EQ(object, JSON::protobuf(parse.get()));
 
+  // Test all the bools and numbers in the JSON string `accepted` can be
+  // successfully parsed.
+  Try<JSON::Object> json = JSON::parse<JSON::Object>(accepted);
+  ASSERT_SOME(json);
+
+  parse = protobuf::parse<tests::Message>(json.get());
+  ASSERT_SOME(parse);
+
+  EXPECT_EQ(object, JSON::protobuf(parse.get()));
+
   // Modify the message to test (de-)serialization of random bytes generated
   // by UUID.
   message.set_bytes(id::UUID::random().toBytes());