Home | History | Annotate | Download | only in json

Lines Matching refs:root

17   scoped_ptr<Value> root;
18 root.reset(JSONReader().JsonToValue(" null ", false, false));
19 ASSERT_TRUE(root.get());
20 ASSERT_TRUE(root->IsType(Value::TYPE_NULL));
23 root.reset(JSONReader().JsonToValue("nu", false, false));
24 ASSERT_FALSE(root.get());
27 root.reset(JSONReader().JsonToValue("true ", false, false));
28 ASSERT_TRUE(root.get());
29 ASSERT_TRUE(root->IsType(Value::TYPE_BOOLEAN));
32 root.reset(JSONReader().JsonToValue("/* comment */null", false, false));
33 ASSERT_TRUE(root.get());
34 ASSERT_TRUE(root->IsType(Value::TYPE_NULL));
35 root.reset(JSONReader().JsonToValue("40 /* comment */", false, false));
36 ASSERT_TRUE(root.get());
37 ASSERT_TRUE(root->IsType(Value::TYPE_INTEGER));
38 root.reset(JSONReader().JsonToValue("true // comment", false, false));
39 ASSERT_TRUE(root.get());
40 ASSERT_TRUE(root->IsType(Value::TYPE_BOOLEAN));
41 root.reset(JSONReader().JsonToValue("/* comment */\"sample string\"",
43 ASSERT_TRUE(root.get());
44 ASSERT_TRUE(root->IsType(Value::TYPE_STRING));
46 ASSERT_TRUE(root->GetAsString(&value));
50 root.reset(JSONReader().JsonToValue("43", false, false));
51 ASSERT_TRUE(root.get());
52 ASSERT_TRUE(root->IsType(Value::TYPE_INTEGER));
54 ASSERT_TRUE(root->GetAsInteger(&int_val));
58 root.reset(JSONReader().JsonToValue("043", false, false));
59 ASSERT_FALSE(root.get());
60 root.reset(JSONReader().JsonToValue("0x43", false, false));
61 ASSERT_FALSE(root.get());
62 root.reset(JSONReader().JsonToValue("00", false, false));
63 ASSERT_FALSE(root.get());
67 root.reset(JSONReader().JsonToValue("0", false, false));
68 ASSERT_TRUE(root.get());
69 ASSERT_TRUE(root->IsType(Value::TYPE_INTEGER));
71 ASSERT_TRUE(root->GetAsInteger(&int_val));
76 root.reset(JSONReader().JsonToValue("2147483648", false, false));
77 ASSERT_TRUE(root.get());
79 ASSERT_TRUE(root->IsType(Value::TYPE_DOUBLE));
81 ASSERT_TRUE(root->GetAsDouble(&double_val));
83 root.reset(JSONReader().JsonToValue("-2147483649", false, false));
84 ASSERT_TRUE(root.get());
85 ASSERT_TRUE(root->IsType(Value::TYPE_DOUBLE));
87 ASSERT_TRUE(root->GetAsDouble(&double_val));
91 root.reset(JSONReader().JsonToValue("43.1", false, false));
92 ASSERT_TRUE(root.get());
93 ASSERT_TRUE(root->IsType(Value::TYPE_DOUBLE));
95 ASSERT_TRUE(root->GetAsDouble(&double_val));
98 root.reset(JSONReader().JsonToValue("4.3e-1", false, false));
99 ASSERT_TRUE(root.get());
100 ASSERT_TRUE(root->IsType(Value::TYPE_DOUBLE));
102 ASSERT_TRUE(root->GetAsDouble(&double_val));
105 root.reset(JSONReader().JsonToValue("2.1e0", false, false));
106 ASSERT_TRUE(root.get());
107 ASSERT_TRUE(root->IsType(Value::TYPE_DOUBLE));
109 ASSERT_TRUE(root->GetAsDouble(&double_val));
112 root.reset(JSONReader().JsonToValue("2.1e+0001", false, false));
113 ASSERT_TRUE(root.get());
114 ASSERT_TRUE(root->IsType(Value::TYPE_DOUBLE));
116 ASSERT_TRUE(root->GetAsDouble(&double_val));
119 root.reset(JSONReader().JsonToValue("0.01", false, false));
120 ASSERT_TRUE(root.get());
121 ASSERT_TRUE(root->IsType(Value::TYPE_DOUBLE));
123 ASSERT_TRUE(root->GetAsDouble(&double_val));
126 root.reset(JSONReader().JsonToValue("1.00", false, false));
127 ASSERT_TRUE(root.get());
128 ASSERT_TRUE(root->IsType(Value::TYPE_DOUBLE));
130 ASSERT_TRUE(root->GetAsDouble(&double_val));
134 root.reset(JSONReader().JsonToValue("1.", false, false));
135 ASSERT_FALSE(root.get());
136 root.reset(JSONReader().JsonToValue(".1", false, false));
137 ASSERT_FALSE(root.get());
138 root.reset(JSONReader().JsonToValue("1.e10", false, false));
139 ASSERT_FALSE(root.get());
142 root.reset(JSONReader().JsonToValue("1e", false, false));
143 ASSERT_FALSE(root.get());
144 root.reset(JSONReader().JsonToValue("1E", false, false));
145 ASSERT_FALSE(root.get());
146 root.reset(JSONReader().JsonToValue("1e1.", false, false));
147 ASSERT_FALSE(root.get());
148 root.reset(JSONReader().JsonToValue("1e1.0", false, false));
149 ASSERT_FALSE(root.get());
152 root.reset(JSONReader().JsonToValue("1e1000", false, false));
153 ASSERT_FALSE(root.get());
154 root.reset(JSONReader().JsonToValue("-1e1000", false, false));
155 ASSERT_FALSE(root.get());
156 root.reset(JSONReader().JsonToValue("NaN", false, false));
157 ASSERT_FALSE(root.get());
158 root.reset(JSONReader().JsonToValue("nan", false, false));
159 ASSERT_FALSE(root.get());
160 root.reset(JSONReader().JsonToValue("inf", false, false));
161 ASSERT_FALSE(root.get());
164 root.reset(JSONReader().JsonToValue("4.3.1", false, false));
165 ASSERT_FALSE(root.get());
166 root.reset(JSONReader().JsonToValue("4e3.1", false, false));
167 ASSERT_FALSE(root.get());
170 root.reset(JSONReader().JsonToValue("\"hello world\"", false, false));
171 ASSERT_TRUE(root.get());
172 ASSERT_TRUE(root->IsType(Value::TYPE_STRING));
174 ASSERT_TRUE(root->GetAsString(&str_val));
178 root.reset(JSONReader().JsonToValue("\"\"", false, false));
179 ASSERT_TRUE(root.get());
180 ASSERT_TRUE(root->IsType(Value::TYPE_STRING));
182 ASSERT_TRUE(root->GetAsString(&str_val));
186 root.reset(JSONReader().JsonToValue("\" \\\"\\\\\\/\\b\\f\\n\\r\\t\\v\"",
188 ASSERT_TRUE(root.get());
189 ASSERT_TRUE(root->IsType(Value::TYPE_STRING));
191 ASSERT_TRUE(root->GetAsString(&str_val));
195 root.reset(JSONReader().JsonToValue("\"\\x41\\x00\\u1234\"", false,
197 ASSERT_TRUE(root.get());
198 ASSERT_TRUE(root->IsType(Value::TYPE_STRING));
200 ASSERT_TRUE(root->GetAsString(&str_val));
204 root.reset(JSONReader().JsonToValue("\"no closing quote", false, false));
205 ASSERT_FALSE(root.get());
206 root.reset(JSONReader().JsonToValue("\"\\z invalid escape char\"", false,
208 ASSERT_FALSE(root.get());
209 root.reset(JSONReader().JsonToValue("\"\\xAQ invalid hex code\"", false,
211 ASSERT_FALSE(root.get());
212 root.reset(JSONReader().JsonToValue("not enough hex chars\\x1\"", false,
214 ASSERT_FALSE(root.get());
215 root.reset(JSONReader().JsonToValue("\"not enough escape chars\\u123\"",
217 ASSERT_FALSE(root.get());
218 root.reset(JSONReader().JsonToValue("\"extra backslash at end of input\\\"",
220 ASSERT_FALSE(root.get());
223 root.reset(JSONReader::Read("[true, false, null]", false));
224 ASSERT_TRUE(root.get());
225 ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
226 ListValue* list = static_cast<ListValue*>(root.get());
232 EXPECT_TRUE(root->Equals(root2.get()));
235 root.reset(JSONReader::Read("[]", false));
236 ASSERT_TRUE(root.get());
237 ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
238 list = static_cast<ListValue*>(root.get());
242 root.reset(JSONReader::Read("[[true], [], [false, [], [null]], null]",
244 ASSERT_TRUE(root.get());
245 ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
246 list = static_cast<ListValue*>(root.get());
252 EXPECT_TRUE(root->Equals(root2.get()));
255 root.reset(JSONReader::Read("[[true], [], [false, [], [null]], null", false));
256 ASSERT_FALSE(root.get());
259 root.reset(JSONReader::Read("[true,, null]", false));
260 ASSERT_FALSE(root.get());
261 root.reset(JSONReader::Read("[true,, null]", true));
262 ASSERT_FALSE(root.get());
265 root.reset(JSONReader::Read("[true null]", false));
266 ASSERT_FALSE(root.get());
269 root.reset(JSONReader::Read("[true,]", false));
270 ASSERT_FALSE(root.get());
273 root.reset(JSONReader::Read("[true,]", true));
274 ASSERT_TRUE(root.get());
275 ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
276 list = static_cast<ListValue*>(root.get());
287 root.reset(JSONReader::Read("[,]", true));
288 EXPECT_FALSE(root.get());
289 root.reset(JSONReader::Read("[true,,]", true));
290 EXPECT_FALSE(root.get());
291 root.reset(JSONReader::Read("[,true,]", true));
292 EXPECT_FALSE(root.get());
293 root.reset(JSONReader::Read("[true,,false]", true));
294 EXPECT_FALSE(root.get());
297 root.reset(JSONReader::Read("{}", false));
298 ASSERT_TRUE(root.get());
299 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
301 root.reset(JSONReader::Read(
303 ASSERT_TRUE(root.get());
304 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
305 DictionaryValue* dict_val = static_cast<DictionaryValue*>(root.get());
319 EXPECT_TRUE(root->Equals(root2.get()));
329 EXPECT_TRUE(root->Equals(root2.get()));
338 EXPECT_TRUE(root->Equals(root2.get()));
341 root.reset(JSONReader::Read(
343 ASSERT_TRUE(root.get());
344 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
345 dict_val = static_cast<DictionaryValue*>(root.get());
359 EXPECT_TRUE(root->Equals(root2.get()));
362 root.reset(JSONReader::Read(
364 ASSERT_TRUE(root.get());
365 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
366 dict_val = static_cast<DictionaryValue*>(root.get());
380 root.reset(JSONReader::Read("{\"a\":{\"b\":2},\"a.b\":1}", false));
381 ASSERT_TRUE(root.get());
382 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
383 dict_val = static_cast<DictionaryValue*>(root.get());
390 root.reset(JSONReader::Read("{\"a\": true", false));
391 ASSERT_FALSE(root.get());
394 root.reset(JSONReader::Read("{foo:true}", false));
395 ASSERT_FALSE(root.get());
398 root.reset(JSONReader::Read("{\"a\":true,}", false));
399 ASSERT_FALSE(root.get());
402 root.reset(JSONReader::Read("{\"a\":true,,\"b\":false}", false));
403 ASSERT_FALSE(root.get());
404 root.reset(JSONReader::Read("{\"a\":true,,\"b\":false}", true));
405 ASSERT_FALSE(root.get());
408 root.reset(JSONReader::Read("{\"a\" \"b\"}", false));
409 ASSERT_FALSE(root.get());
412 root.reset(JSONReader::Read("{,}", false));
413 ASSERT_FALSE(root.get());
414 root.reset(JSONReader::Read("{,}", true));
415 ASSERT_FALSE(root.get());
416 root.reset(JSONReader::Read("{\"a\":true,,}", true));
417 ASSERT_FALSE(root.get());
418 root.reset(JSONReader::Read("{,\"a\":true}", true));
419 ASSERT_FALSE(root.get());
420 root.reset(JSONReader::Read("{\"a\":true,,\"b\":false}", true));
421 ASSERT_FALSE(root.get());
426 root.reset(JSONReader::Read(evil, false));
427 ASSERT_FALSE(root.get());
436 root.reset(JSONReader::Read(not_evil, false));
437 ASSERT_TRUE(root.get());
438 ASSERT_TRUE(root->IsType(Value::TYPE_LIST));
439 list = static_cast<ListValue*>(root.get());
443 root.reset(JSONReader().JsonToValue("\"\xe7\xbd\x91\xe9\xa1\xb5\"",
445 ASSERT_TRUE(root.get());
446 ASSERT_TRUE(root
448 ASSERT_TRUE(root->GetAsString(&str_val));
452 root.reset(JSONReader().JsonToValue("\"345\xb0\xa1\xb0\xa2\"",
454 ASSERT_FALSE(root.get());
455 root.reset(JSONReader().JsonToValue("\"123\xc0\x81\"",
457 ASSERT_FALSE(root.get());
459 // Test invalid root objects.
460 root.reset(JSONReader::Read("null", false));
461 ASSERT_FALSE(root.get());
462 root.reset(JSONReader::Read("true", false));
463 ASSERT_FALSE(root.get());
464 root.reset(JSONReader::Read("10", false));
465 ASSERT_FALSE(root.get());
466 root.reset(JSONReader::Read("\"root\"", false));
467 ASSERT_FALSE(root.get());
474 scoped_ptr<Value> root;
475 root.reset(JSONReader::ReadAndReturnError("[42]", false,
483 root.reset(JSONReader::ReadAndReturnError(big_json, false,
485 EXPECT_FALSE(root.get());
491 root.reset(JSONReader::ReadAndReturnError("{},{}", false,
493 EXPECT_FALSE(root.get());
503 root.reset(JSONReader::ReadAndReturnError(nested_json, false,
505 EXPECT_FALSE(root.get());
510 root.reset(JSONReader::ReadAndReturnError("42", false,
512 EXPECT_FALSE(root.get());
517 root.reset(JSONReader::ReadAndReturnError("[1,]", false,
519 EXPECT_FALSE(root.get());
524 root.reset(JSONReader::ReadAndReturnError("{foo:\"bar\"}", false,
526 EXPECT_FALSE(root.get());
531 root.reset(JSONReader::ReadAndReturnError("{\"foo\":\"bar\",}", false,
533 EXPECT_FALSE(root.get());
537 root.reset(JSONReader::ReadAndReturnError("[nu]", false,
539 EXPECT_FALSE(root.get());
544 root.reset(JSONReader::ReadAndReturnError("[\"xxx\\xq\"]", false,
546 EXPECT_FALSE(root.get());
551 root.reset(JSONReader::ReadAndReturnError("[\"xxx\\uq\"]", false,
553 EXPECT_FALSE(root.get());
558 root.reset(JSONReader::ReadAndReturnError("[\"xxx\\q\"]", false,
560 EXPECT_FALSE(root.get());