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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(base::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(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 } |
558 | 558 |
559 // Tests that the root of a JSON object can be deleted safely while its | 559 // Tests that the root of a JSON object can be deleted safely while its |
560 // children outlive it. | 560 // children outlive it. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 647 |
648 TEST(JSONReaderTest, IllegalTrailingNull) { | 648 TEST(JSONReaderTest, IllegalTrailingNull) { |
649 const char json[] = { '"', 'n', 'u', 'l', 'l', '"', '\0' }; | 649 const char json[] = { '"', 'n', 'u', 'l', 'l', '"', '\0' }; |
650 std::string json_string(json, sizeof(json)); | 650 std::string json_string(json, sizeof(json)); |
651 JSONReader reader; | 651 JSONReader reader; |
652 EXPECT_FALSE(reader.ReadToValue(json_string)); | 652 EXPECT_FALSE(reader.ReadToValue(json_string)); |
653 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, reader.error_code()); | 653 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, reader.error_code()); |
654 } | 654 } |
655 | 655 |
656 } // namespace base | 656 } // namespace base |
OLD | NEW |