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/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 std::string
ReadTestData(const std::string
& filename
) {
27 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory
,
30 NOTREACHED() << "Unable to get test data path for "
31 << kNetworkComponentDirectory
<< "/" << filename
;
35 base::ReadFileToString(path
, &result
);
39 scoped_ptr
<base::DictionaryValue
> ReadTestDictionary(
40 const std::string
& filename
) {
41 base::DictionaryValue
* dict
= NULL
;
43 if (!chromeos::test_utils::GetTestDataPath(kNetworkComponentDirectory
,
46 NOTREACHED() << "Unable to get test dictionary path for "
47 << kNetworkComponentDirectory
<< "/" << filename
;
48 return make_scoped_ptr(dict
);
51 JSONFileValueDeserializer
deserializer(path
);
52 deserializer
.set_allow_trailing_comma(true);
54 std::string error_message
;
55 base::Value
* content
= deserializer
.Deserialize(NULL
, &error_message
);
56 CHECK(content
!= NULL
) << "Couldn't json-deserialize file '"
57 << filename
<< "': " << error_message
;
59 CHECK(content
->GetAsDictionary(&dict
))
60 << "File '" << filename
61 << "' does not contain a dictionary as expected, but type "
62 << content
->GetType();
63 return make_scoped_ptr(dict
);
66 ::testing::AssertionResult
Equals(const base::Value
* expected
,
67 const base::Value
* actual
) {
68 CHECK(expected
!= NULL
);
70 return ::testing::AssertionFailure() << "Actual value pointer is NULL";
72 if (expected
->Equals(actual
))
73 return ::testing::AssertionSuccess() << "Values are equal";
75 return ::testing::AssertionFailure() << "Values are unequal.\n"
76 << "Expected value:\n" << *expected
77 << "Actual value:\n" << *actual
;
80 } // namespace test_utils
82 } // namespace chromeos