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 "chromeos/network/onc/onc_test_utils.h" | 5 #include "chromeos/network/onc/onc_test_utils.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 << kNetworkComponentDirectory << "/" << filename; | 31 << kNetworkComponentDirectory << "/" << filename; |
32 return ""; | 32 return ""; |
33 } | 33 } |
34 std::string result; | 34 std::string result; |
35 base::ReadFileToString(path, &result); | 35 base::ReadFileToString(path, &result); |
36 return result; | 36 return result; |
37 } | 37 } |
38 | 38 |
39 scoped_ptr<base::DictionaryValue> ReadTestDictionary( | 39 scoped_ptr<base::DictionaryValue> ReadTestDictionary( |
40 const std::string& filename) { | 40 const std::string& filename) { |
41 base::DictionaryValue* dict = NULL; | 41 scoped_ptr<base::DictionaryValue> dict = NULL; |
Lei Zhang
2015/10/14 16:55:35
No need to initialize to NULL.
| |
42 base::FilePath path; | 42 base::FilePath path; |
43 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory, | 43 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory, |
44 filename, | 44 filename, |
45 &path)) { | 45 &path)) { |
46 NOTREACHED() << "Unable to get test dictionary path for " | 46 NOTREACHED() << "Unable to get test dictionary path for " |
47 << kNetworkComponentDirectory << "/" << filename; | 47 << kNetworkComponentDirectory << "/" << filename; |
48 return make_scoped_ptr(dict); | 48 return dict; |
49 } | 49 } |
50 | 50 |
51 JSONFileValueDeserializer deserializer(path); | 51 JSONFileValueDeserializer deserializer(path); |
52 deserializer.set_allow_trailing_comma(true); | 52 deserializer.set_allow_trailing_comma(true); |
53 | 53 |
54 std::string error_message; | 54 std::string error_message; |
55 base::Value* content = deserializer.Deserialize(NULL, &error_message); | 55 scoped_ptr<base::Value> content = |
56 deserializer.Deserialize(NULL, &error_message); | |
56 CHECK(content != NULL) << "Couldn't json-deserialize file '" | 57 CHECK(content != NULL) << "Couldn't json-deserialize file '" |
57 << filename << "': " << error_message; | 58 << filename << "': " << error_message; |
58 | 59 |
59 CHECK(content->GetAsDictionary(&dict)) | 60 dict = base::DictionaryValue::From(content.Pass()); |
60 << "File '" << filename | 61 CHECK(dict) << "File '" << filename |
61 << "' does not contain a dictionary as expected, but type " | 62 << "' does not contain a dictionary as expected, but type " |
62 << content->GetType(); | 63 << content->GetType(); |
63 return make_scoped_ptr(dict); | 64 return dict; |
64 } | 65 } |
65 | 66 |
66 ::testing::AssertionResult Equals(const base::Value* expected, | 67 ::testing::AssertionResult Equals(const base::Value* expected, |
67 const base::Value* actual) { | 68 const base::Value* actual) { |
68 CHECK(expected != NULL); | 69 CHECK(expected != NULL); |
69 if (actual == NULL) | 70 if (actual == NULL) |
70 return ::testing::AssertionFailure() << "Actual value pointer is NULL"; | 71 return ::testing::AssertionFailure() << "Actual value pointer is NULL"; |
71 | 72 |
72 if (expected->Equals(actual)) | 73 if (expected->Equals(actual)) |
73 return ::testing::AssertionSuccess() << "Values are equal"; | 74 return ::testing::AssertionSuccess() << "Values are equal"; |
74 | 75 |
75 return ::testing::AssertionFailure() << "Values are unequal.\n" | 76 return ::testing::AssertionFailure() << "Values are unequal.\n" |
76 << "Expected value:\n" << *expected | 77 << "Expected value:\n" << *expected |
77 << "Actual value:\n" << *actual; | 78 << "Actual value:\n" << *actual; |
78 } | 79 } |
79 | 80 |
80 } // namespace test_utils | 81 } // namespace test_utils |
81 } // namespace onc | 82 } // namespace onc |
82 } // namespace chromeos | 83 } // namespace chromeos |
OLD | NEW |