OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 root.reset(JSONReader::Read("\"root\"")); | 537 root.reset(JSONReader::Read("\"root\"")); |
538 ASSERT_TRUE(root.get()); | 538 ASSERT_TRUE(root.get()); |
539 EXPECT_TRUE(root->GetAsString(&str_val)); | 539 EXPECT_TRUE(root->GetAsString(&str_val)); |
540 EXPECT_EQ("root", str_val); | 540 EXPECT_EQ("root", str_val); |
541 } | 541 } |
542 | 542 |
543 TEST(JSONReaderTest, ReadFromFile) { | 543 TEST(JSONReaderTest, ReadFromFile) { |
544 FilePath path; | 544 FilePath path; |
545 ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &path)); | 545 ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &path)); |
546 path = path.AppendASCII("json"); | 546 path = path.AppendASCII("json"); |
547 ASSERT_TRUE(file_util::PathExists(path)); | 547 ASSERT_TRUE(base::PathExists(path)); |
548 | 548 |
549 std::string input; | 549 std::string input; |
550 ASSERT_TRUE(file_util::ReadFileToString( | 550 ASSERT_TRUE(file_util::ReadFileToString( |
551 path.Append(FILE_PATH_LITERAL("bom_feff.json")), &input)); | 551 path.Append(FILE_PATH_LITERAL("bom_feff.json")), &input)); |
552 | 552 |
553 JSONReader reader; | 553 JSONReader reader; |
554 scoped_ptr<Value> root(reader.ReadToValue(input)); | 554 scoped_ptr<Value> root(reader.ReadToValue(input)); |
555 ASSERT_TRUE(root.get()) << reader.GetErrorMessage(); | 555 ASSERT_TRUE(root.get()) << reader.GetErrorMessage(); |
556 EXPECT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); | 556 EXPECT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); |
557 } | 557 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 | 651 |
652 TEST(JSONReaderTest, IllegalTrailingNull) { | 652 TEST(JSONReaderTest, IllegalTrailingNull) { |
653 const char json[] = { '"', 'n', 'u', 'l', 'l', '"', '\0' }; | 653 const char json[] = { '"', 'n', 'u', 'l', 'l', '"', '\0' }; |
654 std::string json_string(json, sizeof(json)); | 654 std::string json_string(json, sizeof(json)); |
655 JSONReader reader; | 655 JSONReader reader; |
656 EXPECT_FALSE(reader.ReadToValue(json_string)); | 656 EXPECT_FALSE(reader.ReadToValue(json_string)); |
657 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, reader.error_code()); | 657 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, reader.error_code()); |
658 } | 658 } |
659 | 659 |
660 } // namespace base | 660 } // namespace base |
OLD | NEW |