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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" |
8 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chromeos/chromeos_test_utils.h" | 13 #include "chromeos/chromeos_test_utils.h" |
13 | 14 |
14 namespace chromeos { | 15 namespace chromeos { |
15 namespace onc { | 16 namespace onc { |
16 namespace test_utils { | 17 namespace test_utils { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // The name of the component directory to get the test data from. | 21 // The name of the component directory to get the test data from. |
21 const char kNetworkComponentDirectory[] = "network"; | 22 const char kNetworkComponentDirectory[] = "network"; |
22 | 23 |
23 } // namespace | 24 } // namespace |
24 | 25 |
| 26 std::string ReadTestData(const std::string& filename) { |
| 27 FilePath path; |
| 28 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory, |
| 29 filename, |
| 30 &path)) { |
| 31 NOTREACHED() << "Unable to get test data path for " |
| 32 << kNetworkComponentDirectory << "/" << filename; |
| 33 return ""; |
| 34 } |
| 35 std::string result; |
| 36 file_util::ReadFileToString(path, &result); |
| 37 return result; |
| 38 } |
| 39 |
25 scoped_ptr<base::DictionaryValue> ReadTestDictionary( | 40 scoped_ptr<base::DictionaryValue> ReadTestDictionary( |
26 const std::string& filename) { | 41 const std::string& filename) { |
27 base::DictionaryValue* dict = NULL; | 42 base::DictionaryValue* dict = NULL; |
28 FilePath path; | 43 FilePath path; |
29 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory, | 44 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory, |
30 filename, | 45 filename, |
31 &path)) { | 46 &path)) { |
32 NOTREACHED() << "Unable to get test dictionary path for " | 47 NOTREACHED() << "Unable to get test dictionary path for " |
33 << kNetworkComponentDirectory << "/" << filename; | 48 << kNetworkComponentDirectory << "/" << filename; |
34 return make_scoped_ptr(dict); | 49 return make_scoped_ptr(dict); |
(...skipping 24 matching lines...) Expand all Loading... |
59 return ::testing::AssertionSuccess() << "Dictionaries are equal"; | 74 return ::testing::AssertionSuccess() << "Dictionaries are equal"; |
60 | 75 |
61 return ::testing::AssertionFailure() << "Dictionaries are unequal.\n" | 76 return ::testing::AssertionFailure() << "Dictionaries are unequal.\n" |
62 << "Expected dictionary:\n" << *expected | 77 << "Expected dictionary:\n" << *expected |
63 << "Actual dictionary:\n" << *actual; | 78 << "Actual dictionary:\n" << *actual; |
64 } | 79 } |
65 | 80 |
66 } // namespace test_utils | 81 } // namespace test_utils |
67 } // namespace onc | 82 } // namespace onc |
68 } // namespace chromeos | 83 } // namespace chromeos |
OLD | NEW |