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.
5 #include "chromeos/network/onc/onc_test_utils.h"
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 "chromeos/chromeos_test_utils.h"
16 namespace test_utils
{
20 // The name of the component directory to get the test data from.
21 const char kNetworkComponentDirectory
[] = "network";
25 scoped_ptr
<base::DictionaryValue
> ReadTestDictionary(
26 const std::string
& filename
) {
27 base::DictionaryValue
* dict
= NULL
;
29 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory
,
32 NOTREACHED() << "Unable to get test dictionary path for "
33 << kNetworkComponentDirectory
<< "/" << filename
;
34 return make_scoped_ptr(dict
);
37 JSONFileValueSerializer
serializer(path
);
38 serializer
.set_allow_trailing_comma(true);
40 std::string error_message
;
41 base::Value
* content
= serializer
.Deserialize(NULL
, &error_message
);
42 CHECK(content
!= NULL
) << "Couldn't json-deserialize file '"
43 << filename
<< "': " << error_message
;
45 CHECK(content
->GetAsDictionary(&dict
))
46 << "File '" << filename
47 << "' does not contain a dictionary as expected, but type "
48 << content
->GetType();
49 return make_scoped_ptr(dict
);
52 ::testing::AssertionResult
Equals(const base::DictionaryValue
* expected
,
53 const base::DictionaryValue
* actual
) {
54 CHECK(expected
!= NULL
);
56 return ::testing::AssertionFailure() << "Actual dictionary pointer is NULL";
58 if (expected
->Equals(actual
))
59 return ::testing::AssertionSuccess() << "Dictionaries are equal";
61 return ::testing::AssertionFailure() << "Dictionaries are unequal.\n"
62 << "Expected dictionary:\n" << *expected
63 << "Actual dictionary:\n" << *actual
;
66 } // namespace test_utils
68 } // namespace chromeos