Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(615)

Side by Side Diff: base/json_reader_unittest.cc

Issue 31014: Port DictionaryValue to use string16 instead of wstring. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/json_reader.cc ('k') | base/json_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "base/json_reader.h" 6 #include "base/json_reader.h"
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/string_util.h"
8 #include "base/values.h" 9 #include "base/values.h"
9 #include "build/build_config.h" 10 #include "build/build_config.h"
10 11
11 TEST(JSONReaderTest, Reading) { 12 TEST(JSONReaderTest, Reading) {
12 // some whitespace checking 13 // some whitespace checking
13 scoped_ptr<Value> root; 14 scoped_ptr<Value> root;
14 root.reset(JSONReader().JsonToValue(" null ", false, false)); 15 root.reset(JSONReader().JsonToValue(" null ", false, false));
15 ASSERT_TRUE(root.get()); 16 ASSERT_TRUE(root.get());
16 ASSERT_TRUE(root->IsType(Value::TYPE_NULL)); 17 ASSERT_TRUE(root->IsType(Value::TYPE_NULL));
17 18
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 ASSERT_TRUE(root.get()); 291 ASSERT_TRUE(root.get());
291 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); 292 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
292 293
293 root.reset(JSONReader::Read( 294 root.reset(JSONReader::Read(
294 "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\" }", 295 "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\" }",
295 false)); 296 false));
296 ASSERT_TRUE(root.get()); 297 ASSERT_TRUE(root.get());
297 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); 298 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
298 DictionaryValue* dict_val = static_cast<DictionaryValue*>(root.get()); 299 DictionaryValue* dict_val = static_cast<DictionaryValue*>(root.get());
299 real_val = 0.0; 300 real_val = 0.0;
300 ASSERT_TRUE(dict_val->GetReal(L"number", &real_val)); 301 ASSERT_TRUE(dict_val->GetReal(ASCIIToUTF16("number"), &real_val));
301 ASSERT_DOUBLE_EQ(9.87654321, real_val); 302 ASSERT_DOUBLE_EQ(9.87654321, real_val);
302 Value* null_val = NULL; 303 Value* null_val = NULL;
303 ASSERT_TRUE(dict_val->Get(L"null", &null_val)); 304 ASSERT_TRUE(dict_val->Get(ASCIIToUTF16("null"), &null_val));
304 ASSERT_TRUE(null_val->IsType(Value::TYPE_NULL)); 305 ASSERT_TRUE(null_val->IsType(Value::TYPE_NULL));
305 str_val.clear(); 306 string16 str16_val;
306 ASSERT_TRUE(dict_val->GetString(L"S", &str_val)); 307 ASSERT_TRUE(dict_val->GetString(ASCIIToUTF16("S"), &str16_val));
307 ASSERT_EQ(L"str", str_val); 308 ASSERT_EQ(ASCIIToUTF16("str"), str16_val);
308 309
309 root2.reset(JSONReader::Read( 310 root2.reset(JSONReader::Read(
310 "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\", }", true)); 311 "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\", }", true));
311 EXPECT_TRUE(root->Equals(root2.get())); 312 EXPECT_TRUE(root->Equals(root2.get()));
312 313
313 // Test nesting 314 // Test nesting
314 root.reset(JSONReader::Read( 315 root.reset(JSONReader::Read(
315 "{\"inner\":{\"array\":[true]},\"false\":false,\"d\":{}}", false)); 316 "{\"inner\":{\"array\":[true]},\"false\":false,\"d\":{}}", false));
316 ASSERT_TRUE(root.get()); 317 ASSERT_TRUE(root.get());
317 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); 318 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
318 dict_val = static_cast<DictionaryValue*>(root.get()); 319 dict_val = static_cast<DictionaryValue*>(root.get());
319 DictionaryValue* inner_dict = NULL; 320 DictionaryValue* inner_dict = NULL;
320 ASSERT_TRUE(dict_val->GetDictionary(L"inner", &inner_dict)); 321 ASSERT_TRUE(dict_val->GetDictionary(ASCIIToUTF16("inner"), &inner_dict));
321 ListValue* inner_array = NULL; 322 ListValue* inner_array = NULL;
322 ASSERT_TRUE(inner_dict->GetList(L"array", &inner_array)); 323 ASSERT_TRUE(inner_dict->GetList(ASCIIToUTF16("array"), &inner_array));
323 ASSERT_EQ(1U, inner_array->GetSize()); 324 ASSERT_EQ(1U, inner_array->GetSize());
324 bool_value = true; 325 bool_value = true;
325 ASSERT_TRUE(dict_val->GetBoolean(L"false", &bool_value)); 326 ASSERT_TRUE(dict_val->GetBoolean(ASCIIToUTF16("false"), &bool_value));
326 ASSERT_FALSE(bool_value); 327 ASSERT_FALSE(bool_value);
327 inner_dict = NULL; 328 inner_dict = NULL;
328 ASSERT_TRUE(dict_val->GetDictionary(L"d", &inner_dict)); 329 ASSERT_TRUE(dict_val->GetDictionary(ASCIIToUTF16("d"), &inner_dict));
329 330
330 root2.reset(JSONReader::Read( 331 root2.reset(JSONReader::Read(
331 "{\"inner\": {\"array\":[true] , },\"false\":false,\"d\":{},}", true)); 332 "{\"inner\": {\"array\":[true] , },\"false\":false,\"d\":{},}", true));
332 EXPECT_TRUE(root->Equals(root2.get())); 333 EXPECT_TRUE(root->Equals(root2.get()));
333 334
334 // Invalid, no closing brace 335 // Invalid, no closing brace
335 root.reset(JSONReader::Read("{\"a\": true", false)); 336 root.reset(JSONReader::Read("{\"a\": true", false));
336 ASSERT_FALSE(root.get()); 337 ASSERT_FALSE(root.get());
337 338
338 // Invalid, keys must be quoted 339 // Invalid, keys must be quoted
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape), 484 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape),
484 error_message); 485 error_message);
485 486
486 root.reset(JSONReader::ReadAndReturnError("[\"xxx\\q\"]", false, 487 root.reset(JSONReader::ReadAndReturnError("[\"xxx\\q\"]", false,
487 &error_message)); 488 &error_message));
488 EXPECT_FALSE(root.get()); 489 EXPECT_FALSE(root.get());
489 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape), 490 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape),
490 error_message); 491 error_message);
491 492
492 } 493 }
OLDNEW
« no previous file with comments | « base/json_reader.cc ('k') | base/json_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698