Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / base / test / values_test_util.cc
blobebfc4948ecf3b9f0c6b8089ea92eb463a5523000
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 "base/test/values_test_util.h"
7 #include "base/json/json_reader.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace base {
15 void ExpectDictBooleanValue(bool expected_value,
16 const DictionaryValue& value,
17 const std::string& key) {
18 bool boolean_value = false;
19 EXPECT_TRUE(value.GetBoolean(key, &boolean_value)) << key;
20 EXPECT_EQ(expected_value, boolean_value) << key;
23 void ExpectDictDictionaryValue(const DictionaryValue& expected_value,
24 const DictionaryValue& value,
25 const std::string& key) {
26 const DictionaryValue* dict_value = NULL;
27 EXPECT_TRUE(value.GetDictionary(key, &dict_value)) << key;
28 EXPECT_TRUE(Value::Equals(dict_value, &expected_value)) << key;
31 void ExpectDictIntegerValue(int expected_value,
32 const DictionaryValue& value,
33 const std::string& key) {
34 int integer_value = 0;
35 EXPECT_TRUE(value.GetInteger(key, &integer_value)) << key;
36 EXPECT_EQ(expected_value, integer_value) << key;
39 void ExpectDictListValue(const ListValue& expected_value,
40 const DictionaryValue& value,
41 const std::string& key) {
42 const ListValue* list_value = NULL;
43 EXPECT_TRUE(value.GetList(key, &list_value)) << key;
44 EXPECT_TRUE(Value::Equals(list_value, &expected_value)) << key;
47 void ExpectDictStringValue(const std::string& expected_value,
48 const DictionaryValue& value,
49 const std::string& key) {
50 std::string string_value;
51 EXPECT_TRUE(value.GetString(key, &string_value)) << key;
52 EXPECT_EQ(expected_value, string_value) << key;
55 void ExpectStringValue(const std::string& expected_str,
56 StringValue* actual) {
57 scoped_ptr<StringValue> scoped_actual(actual);
58 std::string actual_str;
59 EXPECT_TRUE(scoped_actual->GetAsString(&actual_str));
60 EXPECT_EQ(expected_str, actual_str);
63 namespace test {
65 scoped_ptr<Value> ParseJson(base::StringPiece json) {
66 std::string error_msg;
67 scoped_ptr<Value> result = base::JSONReader::ReadAndReturnError(
68 json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg);
69 if (!result) {
70 ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg;
71 result = Value::CreateNullValue();
73 return result.Pass();
76 } // namespace test
77 } // namespace base