| Index: base/json/json_reader_unittest.cc
|
| diff --git a/base/json/json_reader_unittest.cc b/base/json/json_reader_unittest.cc
|
| index a3ec4f72e2f8ae6ee1cc2692d72828f2ed27ec54..7d3a6d96477641b00a9696fa44a20804f2eda7a2 100644
|
| --- a/base/json/json_reader_unittest.cc
|
| +++ b/base/json/json_reader_unittest.cc
|
| @@ -20,36 +20,36 @@ namespace base {
|
| TEST(JSONReaderTest, Reading) {
|
| // some whitespace checking
|
| scoped_ptr<Value> root;
|
| - root.reset(JSONReader().ReadToValue(" null "));
|
| + root = JSONReader().ReadToValue(" null ");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_NULL));
|
|
|
| // Invalid JSON string
|
| - root.reset(JSONReader().ReadToValue("nu"));
|
| + root = JSONReader().ReadToValue("nu");
|
| EXPECT_FALSE(root.get());
|
|
|
| // Simple bool
|
| - root.reset(JSONReader().ReadToValue("true "));
|
| + root = JSONReader().ReadToValue("true ");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_BOOLEAN));
|
|
|
| // Embedded comment
|
| - root.reset(JSONReader().ReadToValue("/* comment */null"));
|
| + root = JSONReader().ReadToValue("/* comment */null");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_NULL));
|
| - root.reset(JSONReader().ReadToValue("40 /* comment */"));
|
| + root = JSONReader().ReadToValue("40 /* comment */");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_INTEGER));
|
| - root.reset(JSONReader().ReadToValue("true // comment"));
|
| + root = JSONReader().ReadToValue("true // comment");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_BOOLEAN));
|
| - root.reset(JSONReader().ReadToValue("/* comment */\"sample string\""));
|
| + root = JSONReader().ReadToValue("/* comment */\"sample string\"");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_STRING));
|
| std::string value;
|
| EXPECT_TRUE(root->GetAsString(&value));
|
| EXPECT_EQ("sample string", value);
|
| - root.reset(JSONReader().ReadToValue("[1, /* comment, 2 ] */ \n 3]"));
|
| + root = JSONReader().ReadToValue("[1, /* comment, 2 ] */ \n 3]");
|
| ASSERT_TRUE(root.get());
|
| ListValue* list = static_cast<ListValue*>(root.get());
|
| EXPECT_EQ(2u, list->GetSize());
|
| @@ -58,42 +58,42 @@ TEST(JSONReaderTest, Reading) {
|
| EXPECT_EQ(1, int_val);
|
| EXPECT_TRUE(list->GetInteger(1, &int_val));
|
| EXPECT_EQ(3, int_val);
|
| - root.reset(JSONReader().ReadToValue("[1, /*a*/2, 3]"));
|
| + root = JSONReader().ReadToValue("[1, /*a*/2, 3]");
|
| ASSERT_TRUE(root.get());
|
| list = static_cast<ListValue*>(root.get());
|
| EXPECT_EQ(3u, list->GetSize());
|
| - root.reset(JSONReader().ReadToValue("/* comment **/42"));
|
| + root = JSONReader().ReadToValue("/* comment **/42");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_INTEGER));
|
| EXPECT_TRUE(root->GetAsInteger(&int_val));
|
| EXPECT_EQ(42, int_val);
|
| - root.reset(JSONReader().ReadToValue(
|
| + root = JSONReader().ReadToValue(
|
| "/* comment **/\n"
|
| "// */ 43\n"
|
| - "44"));
|
| + "44");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_INTEGER));
|
| EXPECT_TRUE(root->GetAsInteger(&int_val));
|
| EXPECT_EQ(44, int_val);
|
|
|
| // Test number formats
|
| - root.reset(JSONReader().ReadToValue("43"));
|
| + root = JSONReader().ReadToValue("43");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_INTEGER));
|
| EXPECT_TRUE(root->GetAsInteger(&int_val));
|
| EXPECT_EQ(43, int_val);
|
|
|
| // According to RFC4627, oct, hex, and leading zeros are invalid JSON.
|
| - root.reset(JSONReader().ReadToValue("043"));
|
| + root = JSONReader().ReadToValue("043");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("0x43"));
|
| + root = JSONReader().ReadToValue("0x43");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("00"));
|
| + root = JSONReader().ReadToValue("00");
|
| EXPECT_FALSE(root.get());
|
|
|
| // Test 0 (which needs to be special cased because of the leading zero
|
| // clause).
|
| - root.reset(JSONReader().ReadToValue("0"));
|
| + root = JSONReader().ReadToValue("0");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_INTEGER));
|
| int_val = 1;
|
| @@ -102,14 +102,14 @@ TEST(JSONReaderTest, Reading) {
|
|
|
| // Numbers that overflow ints should succeed, being internally promoted to
|
| // storage as doubles
|
| - root.reset(JSONReader().ReadToValue("2147483648"));
|
| + root = JSONReader().ReadToValue("2147483648");
|
| ASSERT_TRUE(root.get());
|
| double double_val;
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DOUBLE));
|
| double_val = 0.0;
|
| EXPECT_TRUE(root->GetAsDouble(&double_val));
|
| EXPECT_DOUBLE_EQ(2147483648.0, double_val);
|
| - root.reset(JSONReader().ReadToValue("-2147483649"));
|
| + root = JSONReader().ReadToValue("-2147483649");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DOUBLE));
|
| double_val = 0.0;
|
| @@ -117,42 +117,42 @@ TEST(JSONReaderTest, Reading) {
|
| EXPECT_DOUBLE_EQ(-2147483649.0, double_val);
|
|
|
| // Parse a double
|
| - root.reset(JSONReader().ReadToValue("43.1"));
|
| + root = JSONReader().ReadToValue("43.1");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DOUBLE));
|
| double_val = 0.0;
|
| EXPECT_TRUE(root->GetAsDouble(&double_val));
|
| EXPECT_DOUBLE_EQ(43.1, double_val);
|
|
|
| - root.reset(JSONReader().ReadToValue("4.3e-1"));
|
| + root = JSONReader().ReadToValue("4.3e-1");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DOUBLE));
|
| double_val = 0.0;
|
| EXPECT_TRUE(root->GetAsDouble(&double_val));
|
| EXPECT_DOUBLE_EQ(.43, double_val);
|
|
|
| - root.reset(JSONReader().ReadToValue("2.1e0"));
|
| + root = JSONReader().ReadToValue("2.1e0");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DOUBLE));
|
| double_val = 0.0;
|
| EXPECT_TRUE(root->GetAsDouble(&double_val));
|
| EXPECT_DOUBLE_EQ(2.1, double_val);
|
|
|
| - root.reset(JSONReader().ReadToValue("2.1e+0001"));
|
| + root = JSONReader().ReadToValue("2.1e+0001");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DOUBLE));
|
| double_val = 0.0;
|
| EXPECT_TRUE(root->GetAsDouble(&double_val));
|
| EXPECT_DOUBLE_EQ(21.0, double_val);
|
|
|
| - root.reset(JSONReader().ReadToValue("0.01"));
|
| + root = JSONReader().ReadToValue("0.01");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DOUBLE));
|
| double_val = 0.0;
|
| EXPECT_TRUE(root->GetAsDouble(&double_val));
|
| EXPECT_DOUBLE_EQ(0.01, double_val);
|
|
|
| - root.reset(JSONReader().ReadToValue("1.00"));
|
| + root = JSONReader().ReadToValue("1.00");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DOUBLE));
|
| double_val = 0.0;
|
| @@ -160,43 +160,43 @@ TEST(JSONReaderTest, Reading) {
|
| EXPECT_DOUBLE_EQ(1.0, double_val);
|
|
|
| // Fractional parts must have a digit before and after the decimal point.
|
| - root.reset(JSONReader().ReadToValue("1."));
|
| + root = JSONReader().ReadToValue("1.");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue(".1"));
|
| + root = JSONReader().ReadToValue(".1");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("1.e10"));
|
| + root = JSONReader().ReadToValue("1.e10");
|
| EXPECT_FALSE(root.get());
|
|
|
| // Exponent must have a digit following the 'e'.
|
| - root.reset(JSONReader().ReadToValue("1e"));
|
| + root = JSONReader().ReadToValue("1e");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("1E"));
|
| + root = JSONReader().ReadToValue("1E");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("1e1."));
|
| + root = JSONReader().ReadToValue("1e1.");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("1e1.0"));
|
| + root = JSONReader().ReadToValue("1e1.0");
|
| EXPECT_FALSE(root.get());
|
|
|
| // INF/-INF/NaN are not valid
|
| - root.reset(JSONReader().ReadToValue("1e1000"));
|
| + root = JSONReader().ReadToValue("1e1000");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("-1e1000"));
|
| + root = JSONReader().ReadToValue("-1e1000");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("NaN"));
|
| + root = JSONReader().ReadToValue("NaN");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("nan"));
|
| + root = JSONReader().ReadToValue("nan");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("inf"));
|
| + root = JSONReader().ReadToValue("inf");
|
| EXPECT_FALSE(root.get());
|
|
|
| // Invalid number formats
|
| - root.reset(JSONReader().ReadToValue("4.3.1"));
|
| + root = JSONReader().ReadToValue("4.3.1");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("4e3.1"));
|
| + root = JSONReader().ReadToValue("4e3.1");
|
| EXPECT_FALSE(root.get());
|
|
|
| // Test string parser
|
| - root.reset(JSONReader().ReadToValue("\"hello world\""));
|
| + root = JSONReader().ReadToValue("\"hello world\"");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_STRING));
|
| std::string str_val;
|
| @@ -204,7 +204,7 @@ TEST(JSONReaderTest, Reading) {
|
| EXPECT_EQ("hello world", str_val);
|
|
|
| // Empty string
|
| - root.reset(JSONReader().ReadToValue("\"\""));
|
| + root = JSONReader().ReadToValue("\"\"");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_STRING));
|
| str_val.clear();
|
| @@ -212,7 +212,7 @@ TEST(JSONReaderTest, Reading) {
|
| EXPECT_EQ("", str_val);
|
|
|
| // Test basic string escapes
|
| - root.reset(JSONReader().ReadToValue("\" \\\"\\\\\\/\\b\\f\\n\\r\\t\\v\""));
|
| + root = JSONReader().ReadToValue("\" \\\"\\\\\\/\\b\\f\\n\\r\\t\\v\"");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_STRING));
|
| str_val.clear();
|
| @@ -220,7 +220,7 @@ TEST(JSONReaderTest, Reading) {
|
| EXPECT_EQ(" \"\\/\b\f\n\r\t\v", str_val);
|
|
|
| // Test hex and unicode escapes including the null character.
|
| - root.reset(JSONReader().ReadToValue("\"\\x41\\x00\\u1234\""));
|
| + root = JSONReader().ReadToValue("\"\\x41\\x00\\u1234\"");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_STRING));
|
| str_val.clear();
|
| @@ -228,21 +228,21 @@ TEST(JSONReaderTest, Reading) {
|
| EXPECT_EQ(std::wstring(L"A\0\x1234", 3), UTF8ToWide(str_val));
|
|
|
| // Test invalid strings
|
| - root.reset(JSONReader().ReadToValue("\"no closing quote"));
|
| + root = JSONReader().ReadToValue("\"no closing quote");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("\"\\z invalid escape char\""));
|
| + root = JSONReader().ReadToValue("\"\\z invalid escape char\"");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("\"\\xAQ invalid hex code\""));
|
| + root = JSONReader().ReadToValue("\"\\xAQ invalid hex code\"");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("not enough hex chars\\x1\""));
|
| + root = JSONReader().ReadToValue("not enough hex chars\\x1\"");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("\"not enough escape chars\\u123\""));
|
| + root = JSONReader().ReadToValue("\"not enough escape chars\\u123\"");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("\"extra backslash at end of input\\\""));
|
| + root = JSONReader().ReadToValue("\"extra backslash at end of input\\\"");
|
| EXPECT_FALSE(root.get());
|
|
|
| // Basic array
|
| - root.reset(JSONReader::Read("[true, false, null]"));
|
| + root.reset(JSONReader::DeprecatedRead("[true, false, null]"));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_LIST));
|
| list = static_cast<ListValue*>(root.get());
|
| @@ -250,49 +250,53 @@ TEST(JSONReaderTest, Reading) {
|
|
|
| // Test with trailing comma. Should be parsed the same as above.
|
| scoped_ptr<Value> root2;
|
| - root2.reset(JSONReader::Read("[true, false, null, ]",
|
| - JSON_ALLOW_TRAILING_COMMAS));
|
| + root2.reset(JSONReader::DeprecatedRead("[true, false, null, ]",
|
| + JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_TRUE(root->Equals(root2.get()));
|
|
|
| // Empty array
|
| - root.reset(JSONReader::Read("[]"));
|
| + root.reset(JSONReader::DeprecatedRead("[]"));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_LIST));
|
| list = static_cast<ListValue*>(root.get());
|
| EXPECT_EQ(0U, list->GetSize());
|
|
|
| // Nested arrays
|
| - root.reset(JSONReader::Read("[[true], [], [false, [], [null]], null]"));
|
| + root.reset(
|
| + JSONReader::DeprecatedRead("[[true], [], [false, [], [null]], null]"));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_LIST));
|
| list = static_cast<ListValue*>(root.get());
|
| EXPECT_EQ(4U, list->GetSize());
|
|
|
| // Lots of trailing commas.
|
| - root2.reset(JSONReader::Read("[[true], [], [false, [], [null, ] , ], null,]",
|
| - JSON_ALLOW_TRAILING_COMMAS));
|
| + root2.reset(JSONReader::DeprecatedRead(
|
| + "[[true], [], [false, [], [null, ] , ], null,]",
|
| + JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_TRUE(root->Equals(root2.get()));
|
|
|
| // Invalid, missing close brace.
|
| - root.reset(JSONReader::Read("[[true], [], [false, [], [null]], null"));
|
| + root.reset(
|
| + JSONReader::DeprecatedRead("[[true], [], [false, [], [null]], null"));
|
| EXPECT_FALSE(root.get());
|
|
|
| // Invalid, too many commas
|
| - root.reset(JSONReader::Read("[true,, null]"));
|
| + root.reset(JSONReader::DeprecatedRead("[true,, null]"));
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader::Read("[true,, null]", JSON_ALLOW_TRAILING_COMMAS));
|
| + root.reset(
|
| + JSONReader::DeprecatedRead("[true,, null]", JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_FALSE(root.get());
|
|
|
| // Invalid, no commas
|
| - root.reset(JSONReader::Read("[true null]"));
|
| + root.reset(JSONReader::DeprecatedRead("[true null]"));
|
| EXPECT_FALSE(root.get());
|
|
|
| // Invalid, trailing comma
|
| - root.reset(JSONReader::Read("[true,]"));
|
| + root.reset(JSONReader::DeprecatedRead("[true,]"));
|
| EXPECT_FALSE(root.get());
|
|
|
| // Valid if we set |allow_trailing_comma| to true.
|
| - root.reset(JSONReader::Read("[true,]", JSON_ALLOW_TRAILING_COMMAS));
|
| + root.reset(JSONReader::DeprecatedRead("[true,]", JSON_ALLOW_TRAILING_COMMAS));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_LIST));
|
| list = static_cast<ListValue*>(root.get());
|
| @@ -306,21 +310,24 @@ TEST(JSONReaderTest, Reading) {
|
|
|
| // Don't allow empty elements, even if |allow_trailing_comma| is
|
| // true.
|
| - root.reset(JSONReader::Read("[,]", JSON_ALLOW_TRAILING_COMMAS));
|
| + root.reset(JSONReader::DeprecatedRead("[,]", JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader::Read("[true,,]", JSON_ALLOW_TRAILING_COMMAS));
|
| + root.reset(
|
| + JSONReader::DeprecatedRead("[true,,]", JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader::Read("[,true,]", JSON_ALLOW_TRAILING_COMMAS));
|
| + root.reset(
|
| + JSONReader::DeprecatedRead("[,true,]", JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader::Read("[true,,false]", JSON_ALLOW_TRAILING_COMMAS));
|
| + root.reset(
|
| + JSONReader::DeprecatedRead("[true,,false]", JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_FALSE(root.get());
|
|
|
| // Test objects
|
| - root.reset(JSONReader::Read("{}"));
|
| + root.reset(JSONReader::DeprecatedRead("{}"));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
|
|
|
| - root.reset(JSONReader::Read(
|
| + root.reset(JSONReader::DeprecatedRead(
|
| "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\" }"));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
|
| @@ -335,33 +342,35 @@ TEST(JSONReaderTest, Reading) {
|
| EXPECT_TRUE(dict_val->GetString("S", &str_val));
|
| EXPECT_EQ("str", str_val);
|
|
|
| - root2.reset(JSONReader::Read(
|
| + root2.reset(JSONReader::DeprecatedRead(
|
| "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\", }",
|
| JSON_ALLOW_TRAILING_COMMAS));
|
| ASSERT_TRUE(root2.get());
|
| EXPECT_TRUE(root->Equals(root2.get()));
|
|
|
| // Test newline equivalence.
|
| - root2.reset(JSONReader::Read(
|
| + root2.reset(JSONReader::DeprecatedRead(
|
| "{\n"
|
| " \"number\":9.87654321,\n"
|
| " \"null\":null,\n"
|
| " \"\\x53\":\"str\",\n"
|
| - "}\n", JSON_ALLOW_TRAILING_COMMAS));
|
| + "}\n",
|
| + JSON_ALLOW_TRAILING_COMMAS));
|
| ASSERT_TRUE(root2.get());
|
| EXPECT_TRUE(root->Equals(root2.get()));
|
|
|
| - root2.reset(JSONReader::Read(
|
| + root2.reset(JSONReader::DeprecatedRead(
|
| "{\r\n"
|
| " \"number\":9.87654321,\r\n"
|
| " \"null\":null,\r\n"
|
| " \"\\x53\":\"str\",\r\n"
|
| - "}\r\n", JSON_ALLOW_TRAILING_COMMAS));
|
| + "}\r\n",
|
| + JSON_ALLOW_TRAILING_COMMAS));
|
| ASSERT_TRUE(root2.get());
|
| EXPECT_TRUE(root->Equals(root2.get()));
|
|
|
| // Test nesting
|
| - root.reset(JSONReader::Read(
|
| + root.reset(JSONReader::DeprecatedRead(
|
| "{\"inner\":{\"array\":[true]},\"false\":false,\"d\":{}}"));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
|
| @@ -377,13 +386,13 @@ TEST(JSONReaderTest, Reading) {
|
| inner_dict = NULL;
|
| EXPECT_TRUE(dict_val->GetDictionary("d", &inner_dict));
|
|
|
| - root2.reset(JSONReader::Read(
|
| + root2.reset(JSONReader::DeprecatedRead(
|
| "{\"inner\": {\"array\":[true] , },\"false\":false,\"d\":{},}",
|
| JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_TRUE(root->Equals(root2.get()));
|
|
|
| // Test keys with periods
|
| - root.reset(JSONReader::Read(
|
| + root.reset(JSONReader::DeprecatedRead(
|
| "{\"a.b\":3,\"c\":2,\"d.e.f\":{\"g.h.i.j\":1}}"));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
|
| @@ -401,7 +410,7 @@ TEST(JSONReaderTest, Reading) {
|
| &integer_value));
|
| EXPECT_EQ(1, integer_value);
|
|
|
| - root.reset(JSONReader::Read("{\"a\":{\"b\":2},\"a.b\":1}"));
|
| + root.reset(JSONReader::DeprecatedRead("{\"a\":{\"b\":2},\"a.b\":1}"));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
|
| dict_val = static_cast<DictionaryValue*>(root.get());
|
| @@ -411,45 +420,47 @@ TEST(JSONReaderTest, Reading) {
|
| EXPECT_EQ(1, integer_value);
|
|
|
| // Invalid, no closing brace
|
| - root.reset(JSONReader::Read("{\"a\": true"));
|
| + root.reset(JSONReader::DeprecatedRead("{\"a\": true"));
|
| EXPECT_FALSE(root.get());
|
|
|
| // Invalid, keys must be quoted
|
| - root.reset(JSONReader::Read("{foo:true}"));
|
| + root.reset(JSONReader::DeprecatedRead("{foo:true}"));
|
| EXPECT_FALSE(root.get());
|
|
|
| // Invalid, trailing comma
|
| - root.reset(JSONReader::Read("{\"a\":true,}"));
|
| + root.reset(JSONReader::DeprecatedRead("{\"a\":true,}"));
|
| EXPECT_FALSE(root.get());
|
|
|
| // Invalid, too many commas
|
| - root.reset(JSONReader::Read("{\"a\":true,,\"b\":false}"));
|
| + root.reset(JSONReader::DeprecatedRead("{\"a\":true,,\"b\":false}"));
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader::Read("{\"a\":true,,\"b\":false}",
|
| - JSON_ALLOW_TRAILING_COMMAS));
|
| + root.reset(JSONReader::DeprecatedRead("{\"a\":true,,\"b\":false}",
|
| + JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_FALSE(root.get());
|
|
|
| // Invalid, no separator
|
| - root.reset(JSONReader::Read("{\"a\" \"b\"}"));
|
| + root.reset(JSONReader::DeprecatedRead("{\"a\" \"b\"}"));
|
| EXPECT_FALSE(root.get());
|
|
|
| // Invalid, lone comma.
|
| - root.reset(JSONReader::Read("{,}"));
|
| + root.reset(JSONReader::DeprecatedRead("{,}"));
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader::Read("{,}", JSON_ALLOW_TRAILING_COMMAS));
|
| + root.reset(JSONReader::DeprecatedRead("{,}", JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader::Read("{\"a\":true,,}", JSON_ALLOW_TRAILING_COMMAS));
|
| + root.reset(
|
| + JSONReader::DeprecatedRead("{\"a\":true,,}", JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader::Read("{,\"a\":true}", JSON_ALLOW_TRAILING_COMMAS));
|
| + root.reset(
|
| + JSONReader::DeprecatedRead("{,\"a\":true}", JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader::Read("{\"a\":true,,\"b\":false}",
|
| - JSON_ALLOW_TRAILING_COMMAS));
|
| + root.reset(JSONReader::DeprecatedRead("{\"a\":true,,\"b\":false}",
|
| + JSON_ALLOW_TRAILING_COMMAS));
|
| EXPECT_FALSE(root.get());
|
|
|
| // Test stack overflow
|
| std::string evil(1000000, '[');
|
| evil.append(std::string(1000000, ']'));
|
| - root.reset(JSONReader::Read(evil));
|
| + root.reset(JSONReader::DeprecatedRead(evil));
|
| EXPECT_FALSE(root.get());
|
|
|
| // A few thousand adjacent lists is fine.
|
| @@ -459,22 +470,22 @@ TEST(JSONReaderTest, Reading) {
|
| not_evil.append("[],");
|
| }
|
| not_evil.append("[]]");
|
| - root.reset(JSONReader::Read(not_evil));
|
| + root.reset(JSONReader::DeprecatedRead(not_evil));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_LIST));
|
| list = static_cast<ListValue*>(root.get());
|
| EXPECT_EQ(5001U, list->GetSize());
|
|
|
| // Test utf8 encoded input
|
| - root.reset(JSONReader().ReadToValue("\"\xe7\xbd\x91\xe9\xa1\xb5\""));
|
| + root = JSONReader().ReadToValue("\"\xe7\xbd\x91\xe9\xa1\xb5\"");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_STRING));
|
| str_val.clear();
|
| EXPECT_TRUE(root->GetAsString(&str_val));
|
| EXPECT_EQ(L"\x7f51\x9875", UTF8ToWide(str_val));
|
|
|
| - root.reset(JSONReader().ReadToValue(
|
| - "{\"path\": \"/tmp/\xc3\xa0\xc3\xa8\xc3\xb2.png\"}"));
|
| + root = JSONReader().ReadToValue(
|
| + "{\"path\": \"/tmp/\xc3\xa0\xc3\xa8\xc3\xb2.png\"}");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
|
| EXPECT_TRUE(root->GetAsDictionary(&dict_val));
|
| @@ -482,22 +493,22 @@ TEST(JSONReaderTest, Reading) {
|
| EXPECT_EQ("/tmp/\xC3\xA0\xC3\xA8\xC3\xB2.png", str_val);
|
|
|
| // Test invalid utf8 encoded input
|
| - root.reset(JSONReader().ReadToValue("\"345\xb0\xa1\xb0\xa2\""));
|
| + root = JSONReader().ReadToValue("\"345\xb0\xa1\xb0\xa2\"");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("\"123\xc0\x81\""));
|
| + root = JSONReader().ReadToValue("\"123\xc0\x81\"");
|
| EXPECT_FALSE(root.get());
|
| - root.reset(JSONReader().ReadToValue("\"abc\xc0\xae\""));
|
| + root = JSONReader().ReadToValue("\"abc\xc0\xae\"");
|
| EXPECT_FALSE(root.get());
|
|
|
| // Test utf16 encoded strings.
|
| - root.reset(JSONReader().ReadToValue("\"\\u20ac3,14\""));
|
| + root = JSONReader().ReadToValue("\"\\u20ac3,14\"");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_STRING));
|
| str_val.clear();
|
| EXPECT_TRUE(root->GetAsString(&str_val));
|
| EXPECT_EQ("\xe2\x82\xac""3,14", str_val);
|
|
|
| - root.reset(JSONReader().ReadToValue("\"\\ud83d\\udca9\\ud83d\\udc6c\""));
|
| + root = JSONReader().ReadToValue("\"\\ud83d\\udca9\\ud83d\\udc6c\"");
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->IsType(Value::TYPE_STRING));
|
| str_val.clear();
|
| @@ -516,25 +527,25 @@ TEST(JSONReaderTest, Reading) {
|
| "\"\\ud83\\foo\"" // No lower surrogate.
|
| };
|
| for (size_t i = 0; i < arraysize(cases); ++i) {
|
| - root.reset(JSONReader().ReadToValue(cases[i]));
|
| + root = JSONReader().ReadToValue(cases[i]);
|
| EXPECT_FALSE(root.get()) << cases[i];
|
| }
|
|
|
| // Test literal root objects.
|
| - root.reset(JSONReader::Read("null"));
|
| + root.reset(JSONReader::DeprecatedRead("null"));
|
| EXPECT_TRUE(root->IsType(Value::TYPE_NULL));
|
|
|
| - root.reset(JSONReader::Read("true"));
|
| + root.reset(JSONReader::DeprecatedRead("true"));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->GetAsBoolean(&bool_value));
|
| EXPECT_TRUE(bool_value);
|
|
|
| - root.reset(JSONReader::Read("10"));
|
| + root.reset(JSONReader::DeprecatedRead("10"));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->GetAsInteger(&integer_value));
|
| EXPECT_EQ(10, integer_value);
|
|
|
| - root.reset(JSONReader::Read("\"root\""));
|
| + root.reset(JSONReader::DeprecatedRead("\"root\""));
|
| ASSERT_TRUE(root.get());
|
| EXPECT_TRUE(root->GetAsString(&str_val));
|
| EXPECT_EQ("root", str_val);
|
| @@ -567,7 +578,7 @@ TEST(JSONReaderTest, StringOptimizations) {
|
| scoped_ptr<Value> list_value_1;
|
|
|
| {
|
| - scoped_ptr<Value> root(JSONReader::Read(
|
| + scoped_ptr<Value> root = JSONReader::Read(
|
| "{"
|
| " \"test\": {"
|
| " \"foo\": true,"
|
| @@ -579,7 +590,8 @@ TEST(JSONReaderTest, StringOptimizations) {
|
| " \"a\","
|
| " \"b\""
|
| " ]"
|
| - "}", JSON_DETACHABLE_CHILDREN));
|
| + "}",
|
| + JSON_DETACHABLE_CHILDREN);
|
| ASSERT_TRUE(root.get());
|
|
|
| DictionaryValue* root_dict = NULL;
|
|
|