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 "chrome/browser/chromeos/network_settings/onc_test_utils.h" | 5 #include "chromeos/network/onc/onc_test_utils.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chromeos/chromeos_test_utils.h" |
13 | 13 |
14 namespace chromeos { | 14 namespace chromeos { |
15 namespace onc { | 15 namespace onc { |
16 namespace test_utils { | 16 namespace test_utils { |
17 | 17 |
18 namespace { | |
19 | |
20 // The name of the component directory to get the test data from. | |
21 const char kNetworkComponentDirectory[] = "network"; | |
22 | |
23 } // namespace | |
24 | |
18 scoped_ptr<base::DictionaryValue> ReadTestDictionary( | 25 scoped_ptr<base::DictionaryValue> ReadTestDictionary( |
19 const std::string& filename) { | 26 const std::string& filename) { |
27 base::DictionaryValue* dict = NULL; | |
20 FilePath path; | 28 FilePath path; |
21 PathService::Get(chrome::DIR_TEST_DATA, &path); | 29 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory, |
22 path = path.AppendASCII("chromeos").AppendASCII("network_settings"). | 30 filename, |
23 Append(filename); | 31 &path)) { |
32 NOTREACHED() << "Unable to get test dictionary path for " | |
pneubeck (no reviews)
2012/12/10 09:33:10
better log a message at the DCHECK in GetTestDataP
| |
33 << kNetworkComponentDirectory << "/" << filename; | |
34 return make_scoped_ptr(dict); | |
35 } | |
36 | |
24 JSONFileValueSerializer serializer(path); | 37 JSONFileValueSerializer serializer(path); |
25 serializer.set_allow_trailing_comma(true); | 38 serializer.set_allow_trailing_comma(true); |
26 | 39 |
27 std::string error_message; | 40 std::string error_message; |
28 base::Value* content = serializer.Deserialize(NULL, &error_message); | 41 base::Value* content = serializer.Deserialize(NULL, &error_message); |
29 CHECK(content != NULL) << "Couldn't json-deserialize file '" | 42 CHECK(content != NULL) << "Couldn't json-deserialize file '" |
30 << filename << "': " << error_message; | 43 << filename << "': " << error_message; |
31 | 44 |
32 base::DictionaryValue* dict = NULL; | |
33 CHECK(content->GetAsDictionary(&dict)) | 45 CHECK(content->GetAsDictionary(&dict)) |
34 << "File '" << filename | 46 << "File '" << filename |
35 << "' does not contain a dictionary as expected, but type " | 47 << "' does not contain a dictionary as expected, but type " |
36 << content->GetType(); | 48 << content->GetType(); |
37 return make_scoped_ptr(dict); | 49 return make_scoped_ptr(dict); |
38 } | 50 } |
39 | 51 |
40 ::testing::AssertionResult Equals(const base::DictionaryValue* expected, | 52 ::testing::AssertionResult Equals(const base::DictionaryValue* expected, |
41 const base::DictionaryValue* actual) { | 53 const base::DictionaryValue* actual) { |
42 CHECK(expected != NULL); | 54 CHECK(expected != NULL); |
43 if (actual == NULL) | 55 if (actual == NULL) |
44 return ::testing::AssertionFailure() << "Actual dictionary pointer is NULL"; | 56 return ::testing::AssertionFailure() << "Actual dictionary pointer is NULL"; |
45 | 57 |
46 if (expected->Equals(actual)) | 58 if (expected->Equals(actual)) |
47 return ::testing::AssertionSuccess() << "Dictionaries are equal"; | 59 return ::testing::AssertionSuccess() << "Dictionaries are equal"; |
48 | 60 |
49 return ::testing::AssertionFailure() << "Dictionaries are unequal.\n" | 61 return ::testing::AssertionFailure() << "Dictionaries are unequal.\n" |
50 << "Expected dictionary:\n" << *expected | 62 << "Expected dictionary:\n" << *expected |
51 << "Actual dictionary:\n" << *actual; | 63 << "Actual dictionary:\n" << *actual; |
52 } | 64 } |
53 | 65 |
54 } // namespace test_utils | 66 } // namespace test_utils |
55 } // namespace onc | 67 } // namespace onc |
56 } // namespace chromeos | 68 } // namespace chromeos |
OLD | NEW |