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/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/json/json_file_value_serializer.h"
10 #include "base/logging.h"
11 #include "base/path_service.h"
12 #include "base/values.h"
13 #include "chromeos/chromeos_test_utils.h"
17 namespace test_utils
{
21 // The name of the component directory to get the test data from.
22 const char kNetworkComponentDirectory
[] = "network";
26 std::string
ReadTestData(const std::string
& filename
) {
28 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory
,
31 NOTREACHED() << "Unable to get test data path for "
32 << kNetworkComponentDirectory
<< "/" << filename
;
36 base::ReadFileToString(path
, &result
);
40 scoped_ptr
<base::DictionaryValue
> ReadTestDictionary(
41 const std::string
& filename
) {
42 base::DictionaryValue
* dict
= NULL
;
44 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory
,
47 NOTREACHED() << "Unable to get test dictionary path for "
48 << kNetworkComponentDirectory
<< "/" << filename
;
49 return make_scoped_ptr(dict
);
52 JSONFileValueSerializer
serializer(path
);
53 serializer
.set_allow_trailing_comma(true);
55 std::string error_message
;
56 base::Value
* content
= serializer
.Deserialize(NULL
, &error_message
);
57 CHECK(content
!= NULL
) << "Couldn't json-deserialize file '"
58 << filename
<< "': " << error_message
;
60 CHECK(content
->GetAsDictionary(&dict
))
61 << "File '" << filename
62 << "' does not contain a dictionary as expected, but type "
63 << content
->GetType();
64 return make_scoped_ptr(dict
);
67 ::testing::AssertionResult
Equals(const base::Value
* expected
,
68 const base::Value
* actual
) {
69 CHECK(expected
!= NULL
);
71 return ::testing::AssertionFailure() << "Actual value pointer is NULL";
73 if (expected
->Equals(actual
))
74 return ::testing::AssertionSuccess() << "Values are equal";
76 return ::testing::AssertionFailure() << "Values are unequal.\n"
77 << "Expected value:\n" << *expected
78 << "Actual value:\n" << *actual
;
81 } // namespace test_utils
83 } // namespace chromeos