Chromium Code Reviews| Index: chrome/browser/chromeos/network_settings/onc_test_utils.cc |
| diff --git a/chrome/browser/chromeos/network_settings/onc_test_utils.cc b/chrome/browser/chromeos/network_settings/onc_test_utils.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..05e589a0ea9227b0d96b3fb76160647fa648ff8e |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/network_settings/onc_test_utils.cc |
| @@ -0,0 +1,59 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/network_settings/onc_test_utils.h" |
| + |
| +#include "base/file_path.h" |
| +#include "base/json/json_file_value_serializer.h" |
| +#include "base/logging.h" |
| +#include "base/path_service.h" |
| +#include "base/values.h" |
| +#include "chrome/common/chrome_paths.h" |
| + |
| +namespace chromeos { |
| +namespace onc { |
| +namespace test_utils { |
| + |
| +// Read a json dictionary from |filename| and return it as a |
| +// 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.
|
| +scoped_ptr<base::DictionaryValue> ReadTestDictionary( |
| + const std::string& filename) { |
| + FilePath path; |
| + PathService::Get(chrome::DIR_TEST_DATA, &path); |
| + path = path.AppendASCII("chromeos").AppendASCII("network_settings"). |
| + Append(filename); |
| + JSONFileValueSerializer serializer(path); |
| + serializer.set_allow_trailing_comma(true); |
| + |
| + std::string error_message; |
| + base::Value* content = serializer.Deserialize(NULL, &error_message); |
| + CHECK(content != NULL) << "Couldn't json-deserialize file '" |
| + << filename << "': " << error_message; |
| + |
| + base::DictionaryValue* dict = NULL; |
| + CHECK(content->GetAsDictionary(&dict)) |
| + << "File '" << filename |
| + << "' does not contain a dictionary as expected, but type " |
| + << content->GetType(); |
| + return make_scoped_ptr(dict); |
| +} |
| + |
| +// Checks that the dictionary |actual| is not NULL and equal to |expected|. |
| +::testing::AssertionResult Equals(const base::DictionaryValue* expected, |
| + const base::DictionaryValue* actual) { |
| + CHECK(expected != NULL); |
| + if (actual == NULL) |
| + return ::testing::AssertionFailure() << "Actual dictionary pointer is NULL"; |
| + |
| + if (expected->Equals(actual)) |
| + return ::testing::AssertionSuccess() << "Dictionaries are equal"; |
| + |
| + return ::testing::AssertionFailure() << "Dictionaries are unequal.\n" |
| + << "Expected dictionary:\n" << *expected |
| + << "Actual dictionary:\n" << *actual; |
| +} |
| + |
| +} // namespace test_utils |
| +} // namespace onc |
| +} // namespace chromeos |