Chromium Code Reviews| 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 // Read a json dictionary from |filename| and return it as a | |
| 19 // DictionaryValue. CHECKs if any error occurs. | |
|
Mattias Nissler (ping if slow)
2012/11/02 10:10:00
Ah, here are the comments :) move to the header pl
pneubeck (no reviews)
2012/11/05 12:04:48
Done.
| |
| 20 scoped_ptr<base::DictionaryValue> ReadTestDictionary( | |
| 21 const std::string& filename) { | |
| 22 FilePath path; | |
| 23 PathService::Get(chrome::DIR_TEST_DATA, &path); | |
| 24 path = path.AppendASCII("chromeos").AppendASCII("network_settings"). | |
| 25 Append(filename); | |
| 26 JSONFileValueSerializer serializer(path); | |
| 27 serializer.set_allow_trailing_comma(true); | |
| 28 | |
| 29 std::string error_message; | |
| 30 base::Value* content = serializer.Deserialize(NULL, &error_message); | |
| 31 CHECK(content != NULL) << "Couldn't json-deserialize file '" | |
| 32 << filename << "': " << error_message; | |
| 33 | |
| 34 base::DictionaryValue* dict = NULL; | |
| 35 CHECK(content->GetAsDictionary(&dict)) | |
| 36 << "File '" << filename | |
| 37 << "' does not contain a dictionary as expected, but type " | |
| 38 << content->GetType(); | |
| 39 return make_scoped_ptr(dict); | |
| 40 } | |
| 41 | |
| 42 // Checks that the dictionary |actual| is not NULL and equal to |expected|. | |
| 43 ::testing::AssertionResult Equals(const base::DictionaryValue* expected, | |
| 44 const base::DictionaryValue* actual) { | |
| 45 CHECK(expected != NULL); | |
| 46 if (actual == NULL) | |
| 47 return ::testing::AssertionFailure() << "Actual dictionary pointer is NULL"; | |
| 48 | |
| 49 if (expected->Equals(actual)) | |
| 50 return ::testing::AssertionSuccess() << "Dictionaries are equal"; | |
| 51 | |
| 52 return ::testing::AssertionFailure() << "Dictionaries are unequal.\n" | |
| 53 << "Expected dictionary:\n" << *expected | |
| 54 << "Actual dictionary:\n" << *actual; | |
| 55 } | |
| 56 | |
| 57 } // namespace test_utils | |
| 58 } // namespace onc | |
| 59 } // namespace chromeos | |
| OLD | NEW |