license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
| 5 | #include "testing/gtest/include/gtest/gtest.h" |
| 6 | #include "base/json_reader.h" |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 7 | #include "base/scoped_ptr.h" |
dsh@google.com | 14e0b9a | 2009-03-04 06:49:53 +0900 | [diff] [blame^] | 8 | #include "base/string_util.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 9 | #include "base/values.h" |
tc@google.com | d3bb16f | 2008-08-09 02:26:42 +0900 | [diff] [blame] | 10 | #include "build/build_config.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 11 | |
| 12 | TEST(JSONReaderTest, Reading) { |
| 13 | // some whitespace checking |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 14 | scoped_ptr<Value> root; |
| 15 | root.reset(JSONReader().JsonToValue(" null ", false, false)); |
| 16 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 17 | ASSERT_TRUE(root->IsType(Value::TYPE_NULL)); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 18 | |
| 19 | // Invalid JSON string |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 20 | root.reset(JSONReader().JsonToValue("nu", false, false)); |
| 21 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 22 | |
| 23 | // Simple bool |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 24 | root.reset(JSONReader().JsonToValue("true ", false, false)); |
| 25 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 26 | ASSERT_TRUE(root->IsType(Value::TYPE_BOOLEAN)); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 27 | |
| 28 | // Test number formats |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 29 | root.reset(JSONReader().JsonToValue("43", false, false)); |
| 30 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 31 | ASSERT_TRUE(root->IsType(Value::TYPE_INTEGER)); |
| 32 | int int_val = 0; |
| 33 | ASSERT_TRUE(root->GetAsInteger(&int_val)); |
| 34 | ASSERT_EQ(43, int_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 35 | |
| 36 | // According to RFC4627, oct, hex, and leading zeros are invalid JSON. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 37 | root.reset(JSONReader().JsonToValue("043", false, false)); |
| 38 | ASSERT_FALSE(root.get()); |
| 39 | root.reset(JSONReader().JsonToValue("0x43", false, false)); |
| 40 | ASSERT_FALSE(root.get()); |
| 41 | root.reset(JSONReader().JsonToValue("00", false, false)); |
| 42 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 43 | |
| 44 | // Test 0 (which needs to be special cased because of the leading zero |
| 45 | // clause). |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 46 | root.reset(JSONReader().JsonToValue("0", false, false)); |
| 47 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 48 | ASSERT_TRUE(root->IsType(Value::TYPE_INTEGER)); |
| 49 | int_val = 1; |
| 50 | ASSERT_TRUE(root->GetAsInteger(&int_val)); |
| 51 | ASSERT_EQ(0, int_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 52 | |
mmentovai@google.com | 8dcf71c | 2008-08-08 02:15:41 +0900 | [diff] [blame] | 53 | // Numbers that overflow ints should succeed, being internally promoted to |
| 54 | // storage as doubles |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 55 | root.reset(JSONReader().JsonToValue("2147483648", false, false)); |
| 56 | ASSERT_TRUE(root.get()); |
tc@google.com | d3bb16f | 2008-08-09 02:26:42 +0900 | [diff] [blame] | 57 | double real_val; |
| 58 | #ifdef ARCH_CPU_32_BITS |
| 59 | ASSERT_TRUE(root->IsType(Value::TYPE_REAL)); |
| 60 | real_val = 0.0; |
| 61 | ASSERT_TRUE(root->GetAsReal(&real_val)); |
| 62 | ASSERT_DOUBLE_EQ(2147483648.0, real_val); |
| 63 | #else |
| 64 | ASSERT_TRUE(root->IsType(Value::TYPE_INTEGER)); |
| 65 | int_val = 0; |
| 66 | ASSERT_TRUE(root->GetAsInteger(&int_val)); |
| 67 | ASSERT_EQ(2147483648, int_val); |
| 68 | #endif |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 69 | root.reset(JSONReader().JsonToValue("-2147483649", false, false)); |
| 70 | ASSERT_TRUE(root.get()); |
tc@google.com | d3bb16f | 2008-08-09 02:26:42 +0900 | [diff] [blame] | 71 | #ifdef ARCH_CPU_32_BITS |
| 72 | ASSERT_TRUE(root->IsType(Value::TYPE_REAL)); |
| 73 | real_val = 0.0; |
| 74 | ASSERT_TRUE(root->GetAsReal(&real_val)); |
| 75 | ASSERT_DOUBLE_EQ(-2147483649.0, real_val); |
| 76 | #else |
| 77 | ASSERT_TRUE(root->IsType(Value::TYPE_INTEGER)); |
| 78 | int_val = 0; |
| 79 | ASSERT_TRUE(root->GetAsInteger(&int_val)); |
| 80 | ASSERT_EQ(-2147483649, int_val); |
| 81 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 82 | |
| 83 | // Parse a double |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 84 | root.reset(JSONReader().JsonToValue("43.1", false, false)); |
| 85 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 86 | ASSERT_TRUE(root->IsType(Value::TYPE_REAL)); |
tc@google.com | d3bb16f | 2008-08-09 02:26:42 +0900 | [diff] [blame] | 87 | real_val = 0.0; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 88 | ASSERT_TRUE(root->GetAsReal(&real_val)); |
| 89 | ASSERT_DOUBLE_EQ(43.1, real_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 90 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 91 | root.reset(JSONReader().JsonToValue("4.3e-1", false, false)); |
| 92 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 93 | ASSERT_TRUE(root->IsType(Value::TYPE_REAL)); |
| 94 | real_val = 0.0; |
| 95 | ASSERT_TRUE(root->GetAsReal(&real_val)); |
| 96 | ASSERT_DOUBLE_EQ(.43, real_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 97 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 98 | root.reset(JSONReader().JsonToValue("2.1e0", false, false)); |
| 99 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 100 | ASSERT_TRUE(root->IsType(Value::TYPE_REAL)); |
| 101 | real_val = 0.0; |
| 102 | ASSERT_TRUE(root->GetAsReal(&real_val)); |
| 103 | ASSERT_DOUBLE_EQ(2.1, real_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 104 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 105 | root.reset(JSONReader().JsonToValue("2.1e+0001", false, false)); |
| 106 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 107 | ASSERT_TRUE(root->IsType(Value::TYPE_REAL)); |
| 108 | real_val = 0.0; |
| 109 | ASSERT_TRUE(root->GetAsReal(&real_val)); |
| 110 | ASSERT_DOUBLE_EQ(21.0, real_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 111 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 112 | root.reset(JSONReader().JsonToValue("0.01", false, false)); |
| 113 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 114 | ASSERT_TRUE(root->IsType(Value::TYPE_REAL)); |
| 115 | real_val = 0.0; |
| 116 | ASSERT_TRUE(root->GetAsReal(&real_val)); |
| 117 | ASSERT_DOUBLE_EQ(0.01, real_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 118 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 119 | root.reset(JSONReader().JsonToValue("1.00", false, false)); |
| 120 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 121 | ASSERT_TRUE(root->IsType(Value::TYPE_REAL)); |
| 122 | real_val = 0.0; |
| 123 | ASSERT_TRUE(root->GetAsReal(&real_val)); |
| 124 | ASSERT_DOUBLE_EQ(1.0, real_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 125 | |
| 126 | // Fractional parts must have a digit before and after the decimal point. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 127 | root.reset(JSONReader().JsonToValue("1.", false, false)); |
| 128 | ASSERT_FALSE(root.get()); |
| 129 | root.reset(JSONReader().JsonToValue(".1", false, false)); |
| 130 | ASSERT_FALSE(root.get()); |
| 131 | root.reset(JSONReader().JsonToValue("1.e10", false, false)); |
| 132 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 133 | |
| 134 | // Exponent must have a digit following the 'e'. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 135 | root.reset(JSONReader().JsonToValue("1e", false, false)); |
| 136 | ASSERT_FALSE(root.get()); |
| 137 | root.reset(JSONReader().JsonToValue("1E", false, false)); |
| 138 | ASSERT_FALSE(root.get()); |
| 139 | root.reset(JSONReader().JsonToValue("1e1.", false, false)); |
| 140 | ASSERT_FALSE(root.get()); |
| 141 | root.reset(JSONReader().JsonToValue("1e1.0", false, false)); |
| 142 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 143 | |
| 144 | // INF/-INF/NaN are not valid |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 145 | root.reset(JSONReader().JsonToValue("1e1000", false, false)); |
| 146 | ASSERT_FALSE(root.get()); |
| 147 | root.reset(JSONReader().JsonToValue("-1e1000", false, false)); |
| 148 | ASSERT_FALSE(root.get()); |
| 149 | root.reset(JSONReader().JsonToValue("NaN", false, false)); |
| 150 | ASSERT_FALSE(root.get()); |
| 151 | root.reset(JSONReader().JsonToValue("nan", false, false)); |
| 152 | ASSERT_FALSE(root.get()); |
| 153 | root.reset(JSONReader().JsonToValue("inf", false, false)); |
| 154 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 155 | |
| 156 | // Invalid number formats |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 157 | root.reset(JSONReader().JsonToValue("4.3.1", false, false)); |
| 158 | ASSERT_FALSE(root.get()); |
| 159 | root.reset(JSONReader().JsonToValue("4e3.1", false, false)); |
| 160 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 161 | |
| 162 | // Test string parser |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 163 | root.reset(JSONReader().JsonToValue("\"hello world\"", false, false)); |
| 164 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 165 | ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); |
| 166 | std::wstring str_val; |
| 167 | ASSERT_TRUE(root->GetAsString(&str_val)); |
| 168 | ASSERT_EQ(L"hello world", str_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 169 | |
| 170 | // Empty string |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 171 | root.reset(JSONReader().JsonToValue("\"\"", false, false)); |
| 172 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 173 | ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); |
| 174 | str_val.clear(); |
| 175 | ASSERT_TRUE(root->GetAsString(&str_val)); |
| 176 | ASSERT_EQ(L"", str_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 177 | |
| 178 | // Test basic string escapes |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 179 | root.reset(JSONReader().JsonToValue("\" \\\"\\\\\\/\\b\\f\\n\\r\\t\\v\"", |
| 180 | false, false)); |
| 181 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 182 | ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); |
| 183 | str_val.clear(); |
| 184 | ASSERT_TRUE(root->GetAsString(&str_val)); |
sky@google.com | 0ba9351 | 2008-10-02 02:26:06 +0900 | [diff] [blame] | 185 | ASSERT_EQ(L" \"\\/\b\f\n\r\t\v", str_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 186 | |
| 187 | // Test hex and unicode escapes including the null character. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 188 | root.reset(JSONReader().JsonToValue("\"\\x41\\x00\\u1234\"", false, |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 189 | false)); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 190 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 191 | ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); |
| 192 | str_val.clear(); |
| 193 | ASSERT_TRUE(root->GetAsString(&str_val)); |
| 194 | ASSERT_EQ(std::wstring(L"A\0\x1234", 3), str_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 195 | |
| 196 | // Test invalid strings |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 197 | root.reset(JSONReader().JsonToValue("\"no closing quote", false, false)); |
| 198 | ASSERT_FALSE(root.get()); |
| 199 | root.reset(JSONReader().JsonToValue("\"\\z invalid escape char\"", false, |
| 200 | false)); |
| 201 | ASSERT_FALSE(root.get()); |
| 202 | root.reset(JSONReader().JsonToValue("\"\\xAQ invalid hex code\"", false, |
| 203 | false)); |
| 204 | ASSERT_FALSE(root.get()); |
| 205 | root.reset(JSONReader().JsonToValue("not enough hex chars\\x1\"", false, |
| 206 | false)); |
| 207 | ASSERT_FALSE(root.get()); |
| 208 | root.reset(JSONReader().JsonToValue("\"not enough escape chars\\u123\"", |
| 209 | false, false)); |
| 210 | ASSERT_FALSE(root.get()); |
| 211 | root.reset(JSONReader().JsonToValue("\"extra backslash at end of input\\\"", |
| 212 | false, false)); |
| 213 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 214 | |
| 215 | // Basic array |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 216 | root.reset(JSONReader::Read("[true, false, null]", false)); |
| 217 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 218 | ASSERT_TRUE(root->IsType(Value::TYPE_LIST)); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 219 | ListValue* list = static_cast<ListValue*>(root.get()); |
darin@google.com | f327280 | 2008-08-15 05:27:29 +0900 | [diff] [blame] | 220 | ASSERT_EQ(3U, list->GetSize()); |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 221 | |
| 222 | // Test with trailing comma. Should be parsed the same as above. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 223 | scoped_ptr<Value> root2; |
| 224 | root2.reset(JSONReader::Read("[true, false, null, ]", true)); |
| 225 | EXPECT_TRUE(root->Equals(root2.get())); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 226 | |
| 227 | // Empty array |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 228 | root.reset(JSONReader::Read("[]", false)); |
| 229 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 230 | ASSERT_TRUE(root->IsType(Value::TYPE_LIST)); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 231 | list = static_cast<ListValue*>(root.get()); |
darin@google.com | f327280 | 2008-08-15 05:27:29 +0900 | [diff] [blame] | 232 | ASSERT_EQ(0U, list->GetSize()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 233 | |
| 234 | // Nested arrays |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 235 | root.reset(JSONReader::Read("[[true], [], [false, [], [null]], null]", |
| 236 | false)); |
| 237 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 238 | ASSERT_TRUE(root->IsType(Value::TYPE_LIST)); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 239 | list = static_cast<ListValue*>(root.get()); |
darin@google.com | f327280 | 2008-08-15 05:27:29 +0900 | [diff] [blame] | 240 | ASSERT_EQ(4U, list->GetSize()); |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 241 | |
| 242 | // Lots of trailing commas. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 243 | root2.reset(JSONReader::Read("[[true], [], [false, [], [null, ] , ], null,]", |
| 244 | true)); |
| 245 | EXPECT_TRUE(root->Equals(root2.get())); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 246 | |
| 247 | // Invalid, missing close brace. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 248 | root.reset(JSONReader::Read("[[true], [], [false, [], [null]], null", false)); |
| 249 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 250 | |
| 251 | // Invalid, too many commas |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 252 | root.reset(JSONReader::Read("[true,, null]", false)); |
| 253 | ASSERT_FALSE(root.get()); |
| 254 | root.reset(JSONReader::Read("[true,, null]", true)); |
| 255 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 256 | |
| 257 | // Invalid, no commas |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 258 | root.reset(JSONReader::Read("[true null]", false)); |
| 259 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 260 | |
| 261 | // Invalid, trailing comma |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 262 | root.reset(JSONReader::Read("[true,]", false)); |
| 263 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 264 | |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 265 | // Valid if we set |allow_trailing_comma| to true. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 266 | root.reset(JSONReader::Read("[true,]", true)); |
| 267 | ASSERT_TRUE(root.get()); |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 268 | ASSERT_TRUE(root->IsType(Value::TYPE_LIST)); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 269 | list = static_cast<ListValue*>(root.get()); |
darin@google.com | f327280 | 2008-08-15 05:27:29 +0900 | [diff] [blame] | 270 | EXPECT_EQ(1U, list->GetSize()); |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 271 | Value* tmp_value = NULL; |
| 272 | ASSERT_TRUE(list->Get(0, &tmp_value)); |
| 273 | EXPECT_TRUE(tmp_value->IsType(Value::TYPE_BOOLEAN)); |
| 274 | bool bool_value = false; |
| 275 | ASSERT_TRUE(tmp_value->GetAsBoolean(&bool_value)); |
| 276 | EXPECT_TRUE(bool_value); |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 277 | |
| 278 | // Don't allow empty elements, even if |allow_trailing_comma| is |
| 279 | // true. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 280 | root.reset(JSONReader::Read("[,]", true)); |
| 281 | EXPECT_FALSE(root.get()); |
| 282 | root.reset(JSONReader::Read("[true,,]", true)); |
| 283 | EXPECT_FALSE(root.get()); |
| 284 | root.reset(JSONReader::Read("[,true,]", true)); |
| 285 | EXPECT_FALSE(root.get()); |
| 286 | root.reset(JSONReader::Read("[true,,false]", true)); |
| 287 | EXPECT_FALSE(root.get()); |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 288 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 289 | // Test objects |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 290 | root.reset(JSONReader::Read("{}", false)); |
| 291 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 292 | ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 293 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 294 | root.reset(JSONReader::Read( |
| 295 | "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\" }", |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 296 | false)); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 297 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 298 | ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 299 | DictionaryValue* dict_val = static_cast<DictionaryValue*>(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 300 | real_val = 0.0; |
dsh@google.com | 14e0b9a | 2009-03-04 06:49:53 +0900 | [diff] [blame^] | 301 | ASSERT_TRUE(dict_val->GetReal(ASCIIToUTF16("number"), &real_val)); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 302 | ASSERT_DOUBLE_EQ(9.87654321, real_val); |
| 303 | Value* null_val = NULL; |
dsh@google.com | 14e0b9a | 2009-03-04 06:49:53 +0900 | [diff] [blame^] | 304 | ASSERT_TRUE(dict_val->Get(ASCIIToUTF16("null"), &null_val)); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 305 | ASSERT_TRUE(null_val->IsType(Value::TYPE_NULL)); |
dsh@google.com | 14e0b9a | 2009-03-04 06:49:53 +0900 | [diff] [blame^] | 306 | string16 str16_val; |
| 307 | ASSERT_TRUE(dict_val->GetString(ASCIIToUTF16("S"), &str16_val)); |
| 308 | ASSERT_EQ(ASCIIToUTF16("str"), str16_val); |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 309 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 310 | root2.reset(JSONReader::Read( |
| 311 | "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\", }", true)); |
| 312 | EXPECT_TRUE(root->Equals(root2.get())); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 313 | |
| 314 | // Test nesting |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 315 | root.reset(JSONReader::Read( |
| 316 | "{\"inner\":{\"array\":[true]},\"false\":false,\"d\":{}}", false)); |
| 317 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 318 | ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 319 | dict_val = static_cast<DictionaryValue*>(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 320 | DictionaryValue* inner_dict = NULL; |
dsh@google.com | 14e0b9a | 2009-03-04 06:49:53 +0900 | [diff] [blame^] | 321 | ASSERT_TRUE(dict_val->GetDictionary(ASCIIToUTF16("inner"), &inner_dict)); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 322 | ListValue* inner_array = NULL; |
dsh@google.com | 14e0b9a | 2009-03-04 06:49:53 +0900 | [diff] [blame^] | 323 | ASSERT_TRUE(inner_dict->GetList(ASCIIToUTF16("array"), &inner_array)); |
darin@google.com | f327280 | 2008-08-15 05:27:29 +0900 | [diff] [blame] | 324 | ASSERT_EQ(1U, inner_array->GetSize()); |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 325 | bool_value = true; |
dsh@google.com | 14e0b9a | 2009-03-04 06:49:53 +0900 | [diff] [blame^] | 326 | ASSERT_TRUE(dict_val->GetBoolean(ASCIIToUTF16("false"), &bool_value)); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 327 | ASSERT_FALSE(bool_value); |
| 328 | inner_dict = NULL; |
dsh@google.com | 14e0b9a | 2009-03-04 06:49:53 +0900 | [diff] [blame^] | 329 | ASSERT_TRUE(dict_val->GetDictionary(ASCIIToUTF16("d"), &inner_dict)); |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 330 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 331 | root2.reset(JSONReader::Read( |
| 332 | "{\"inner\": {\"array\":[true] , },\"false\":false,\"d\":{},}", true)); |
| 333 | EXPECT_TRUE(root->Equals(root2.get())); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 334 | |
| 335 | // Invalid, no closing brace |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 336 | root.reset(JSONReader::Read("{\"a\": true", false)); |
| 337 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 338 | |
| 339 | // Invalid, keys must be quoted |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 340 | root.reset(JSONReader::Read("{foo:true}", false)); |
| 341 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 342 | |
| 343 | // Invalid, trailing comma |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 344 | root.reset(JSONReader::Read("{\"a\":true,}", false)); |
| 345 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 346 | |
| 347 | // Invalid, too many commas |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 348 | root.reset(JSONReader::Read("{\"a\":true,,\"b\":false}", false)); |
| 349 | ASSERT_FALSE(root.get()); |
| 350 | root.reset(JSONReader::Read("{\"a\":true,,\"b\":false}", true)); |
| 351 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 352 | |
| 353 | // Invalid, no separator |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 354 | root.reset(JSONReader::Read("{\"a\" \"b\"}", false)); |
| 355 | ASSERT_FALSE(root.get()); |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 356 | |
| 357 | // Invalid, lone comma. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 358 | root.reset(JSONReader::Read("{,}", false)); |
| 359 | ASSERT_FALSE(root.get()); |
| 360 | root.reset(JSONReader::Read("{,}", true)); |
| 361 | ASSERT_FALSE(root.get()); |
| 362 | root.reset(JSONReader::Read("{\"a\":true,,}", true)); |
| 363 | ASSERT_FALSE(root.get()); |
| 364 | root.reset(JSONReader::Read("{,\"a\":true}", true)); |
| 365 | ASSERT_FALSE(root.get()); |
| 366 | root.reset(JSONReader::Read("{\"a\":true,,\"b\":false}", true)); |
| 367 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 368 | |
| 369 | // Test stack overflow |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 370 | std::string evil(1000000, '['); |
| 371 | evil.append(std::string(1000000, ']')); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 372 | root.reset(JSONReader::Read(evil, false)); |
| 373 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 374 | |
| 375 | // A few thousand adjacent lists is fine. |
| 376 | std::string not_evil("["); |
| 377 | not_evil.reserve(15010); |
| 378 | for (int i = 0; i < 5000; ++i) { |
| 379 | not_evil.append("[],"); |
| 380 | } |
| 381 | not_evil.append("[]]"); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 382 | root.reset(JSONReader::Read(not_evil, false)); |
| 383 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 384 | ASSERT_TRUE(root->IsType(Value::TYPE_LIST)); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 385 | list = static_cast<ListValue*>(root.get()); |
darin@google.com | f327280 | 2008-08-15 05:27:29 +0900 | [diff] [blame] | 386 | ASSERT_EQ(5001U, list->GetSize()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 387 | |
| 388 | // Test utf8 encoded input |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 389 | root.reset(JSONReader().JsonToValue("\"\xe7\xbd\x91\xe9\xa1\xb5\"", |
tc@google.com | ce6a78d | 2008-07-29 09:01:31 +0900 | [diff] [blame] | 390 | false, false)); |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 391 | ASSERT_TRUE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 392 | ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); |
| 393 | str_val.clear(); |
| 394 | ASSERT_TRUE(root->GetAsString(&str_val)); |
| 395 | ASSERT_EQ(L"\x7f51\x9875", str_val); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 396 | |
jungshik@google.com | 37790f3 | 2008-09-26 06:42:00 +0900 | [diff] [blame] | 397 | // Test invalid utf8 encoded input |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 398 | root.reset(JSONReader().JsonToValue("\"345\xb0\xa1\xb0\xa2\"", |
| 399 | false, false)); |
| 400 | ASSERT_FALSE(root.get()); |
| 401 | root.reset(JSONReader().JsonToValue("\"123\xc0\x81\"", |
| 402 | false, false)); |
| 403 | ASSERT_FALSE(root.get()); |
jungshik@google.com | 37790f3 | 2008-09-26 06:42:00 +0900 | [diff] [blame] | 404 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 405 | // Test invalid root objects. |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 406 | root.reset(JSONReader::Read("null", false)); |
| 407 | ASSERT_FALSE(root.get()); |
| 408 | root.reset(JSONReader::Read("true", false)); |
| 409 | ASSERT_FALSE(root.get()); |
| 410 | root.reset(JSONReader::Read("10", false)); |
| 411 | ASSERT_FALSE(root.get()); |
| 412 | root.reset(JSONReader::Read("\"root\"", false)); |
| 413 | ASSERT_FALSE(root.get()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 414 | } |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 415 | |
| 416 | TEST(JSONReaderTest, ErrorMessages) { |
| 417 | // Error strings should not be modified in case of success. |
| 418 | std::string error_message; |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 419 | scoped_ptr<Value> root; |
| 420 | root.reset(JSONReader::ReadAndReturnError("[42]", false, &error_message)); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 421 | EXPECT_TRUE(error_message.empty()); |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 422 | |
| 423 | // Test line and column counting |
| 424 | const char* big_json = "[\n0,\n1,\n2,\n3,4,5,6 7,\n8,\n9\n]"; |
| 425 | // error here --------------------------------^ |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 426 | root.reset(JSONReader::ReadAndReturnError(big_json, false, &error_message)); |
| 427 | EXPECT_FALSE(root.get()); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 428 | EXPECT_EQ(JSONReader::FormatErrorMessage(5, 9, JSONReader::kSyntaxError), |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 429 | error_message); |
| 430 | |
| 431 | // Test each of the error conditions |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 432 | root.reset(JSONReader::ReadAndReturnError("{},{}", false, &error_message)); |
| 433 | EXPECT_FALSE(root.get()); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 434 | EXPECT_EQ(JSONReader::FormatErrorMessage(1, 3, |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 435 | JSONReader::kUnexpectedDataAfterRoot), error_message); |
| 436 | |
| 437 | std::string nested_json; |
| 438 | for (int i = 0; i < 101; ++i) { |
| 439 | nested_json.insert(nested_json.begin(), '['); |
| 440 | nested_json.append(1, ']'); |
| 441 | } |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 442 | root.reset(JSONReader::ReadAndReturnError(nested_json, false, |
| 443 | &error_message)); |
| 444 | EXPECT_FALSE(root.get()); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 445 | EXPECT_EQ(JSONReader::FormatErrorMessage(1, 101, JSONReader::kTooMuchNesting), |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 446 | error_message); |
| 447 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 448 | root.reset(JSONReader::ReadAndReturnError("42", false, &error_message)); |
| 449 | EXPECT_FALSE(root.get()); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 450 | EXPECT_EQ(JSONReader::FormatErrorMessage(1, 1, |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 451 | JSONReader::kBadRootElementType), error_message); |
| 452 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 453 | root.reset(JSONReader::ReadAndReturnError("[1,]", false, &error_message)); |
| 454 | EXPECT_FALSE(root.get()); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 455 | EXPECT_EQ(JSONReader::FormatErrorMessage(1, 4, JSONReader::kTrailingComma), |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 456 | error_message); |
| 457 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 458 | root.reset(JSONReader::ReadAndReturnError("{foo:\"bar\"}", false, |
| 459 | &error_message)); |
| 460 | EXPECT_FALSE(root.get()); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 461 | EXPECT_EQ(JSONReader::FormatErrorMessage(1, 2, |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 462 | JSONReader::kUnquotedDictionaryKey), error_message); |
| 463 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 464 | root.reset(JSONReader::ReadAndReturnError("{\"foo\":\"bar\",}", false, |
| 465 | &error_message)); |
| 466 | EXPECT_FALSE(root.get()); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 467 | EXPECT_EQ(JSONReader::FormatErrorMessage(1, 14, JSONReader::kTrailingComma), |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 468 | error_message); |
| 469 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 470 | root.reset(JSONReader::ReadAndReturnError("[nu]", false, &error_message)); |
| 471 | EXPECT_FALSE(root.get()); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 472 | EXPECT_EQ(JSONReader::FormatErrorMessage(1, 2, JSONReader::kSyntaxError), |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 473 | error_message); |
| 474 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 475 | root.reset(JSONReader::ReadAndReturnError("[\"xxx\\xq\"]", false, |
| 476 | &error_message)); |
| 477 | EXPECT_FALSE(root.get()); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 478 | EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape), |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 479 | error_message); |
| 480 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 481 | root.reset(JSONReader::ReadAndReturnError("[\"xxx\\uq\"]", false, |
| 482 | &error_message)); |
| 483 | EXPECT_FALSE(root.get()); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 484 | EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape), |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 485 | error_message); |
| 486 | |
aa@chromium.org | ca9c79e | 2008-12-30 04:59:08 +0900 | [diff] [blame] | 487 | root.reset(JSONReader::ReadAndReturnError("[\"xxx\\q\"]", false, |
| 488 | &error_message)); |
| 489 | EXPECT_FALSE(root.get()); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 490 | EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape), |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 491 | error_message); |
aa@chromium.org | 09941d4 | 2008-12-24 11:07:48 +0900 | [diff] [blame] | 492 | |
aa@chromium.org | 971901c | 2008-12-06 07:14:46 +0900 | [diff] [blame] | 493 | } |