| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/network_settings/onc_test_utils.h" | |
| 6 | |
| 7 #include "base/file_path.h" | |
| 8 #include "base/json/json_file_value_serializer.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/path_service.h" | |
| 11 #include "base/values.h" | |
| 12 #include "chrome/common/chrome_paths.h" | |
| 13 | |
| 14 namespace chromeos { | |
| 15 namespace onc { | |
| 16 namespace test_utils { | |
| 17 | |
| 18 scoped_ptr<base::DictionaryValue> ReadTestDictionary( | |
| 19 const std::string& filename) { | |
| 20 FilePath path; | |
| 21 PathService::Get(chrome::DIR_TEST_DATA, &path); | |
| 22 path = path.AppendASCII("chromeos").AppendASCII("network_settings"). | |
| 23 Append(filename); | |
| 24 JSONFileValueSerializer serializer(path); | |
| 25 serializer.set_allow_trailing_comma(true); | |
| 26 | |
| 27 std::string error_message; | |
| 28 base::Value* content = serializer.Deserialize(NULL, &error_message); | |
| 29 CHECK(content != NULL) << "Couldn't json-deserialize file '" | |
| 30 << filename << "': " << error_message; | |
| 31 | |
| 32 base::DictionaryValue* dict = NULL; | |
| 33 CHECK(content->GetAsDictionary(&dict)) | |
| 34 << "File '" << filename | |
| 35 << "' does not contain a dictionary as expected, but type " | |
| 36 << content->GetType(); | |
| 37 return make_scoped_ptr(dict); | |
| 38 } | |
| 39 | |
| 40 ::testing::AssertionResult Equals(const base::DictionaryValue* expected, | |
| 41 const base::DictionaryValue* actual) { | |
| 42 CHECK(expected != NULL); | |
| 43 if (actual == NULL) | |
| 44 return ::testing::AssertionFailure() << "Actual dictionary pointer is NULL"; | |
| 45 | |
| 46 if (expected->Equals(actual)) | |
| 47 return ::testing::AssertionSuccess() << "Dictionaries are equal"; | |
| 48 | |
| 49 return ::testing::AssertionFailure() << "Dictionaries are unequal.\n" | |
| 50 << "Expected dictionary:\n" << *expected | |
| 51 << "Actual dictionary:\n" << *actual; | |
| 52 } | |
| 53 | |
| 54 } // namespace test_utils | |
| 55 } // namespace onc | |
| 56 } // namespace chromeos | |
| OLD | NEW |