| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/string_number_conversions.h" | 6 #include "base/string_number_conversions.h" |
| 7 #include "base/test/values_test_util.h" | 7 #include "base/test/values_test_util.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 | 12 |
| 13 void ExpectDictBooleanValue(bool expected_value, | 13 void ExpectDictBooleanValue(bool expected_value, |
| 14 const DictionaryValue& value, | 14 const DictionaryValue& value, |
| 15 const std::string& key) { | 15 const std::string& key) { |
| 16 bool boolean_value = false; | 16 bool boolean_value = false; |
| 17 EXPECT_TRUE(value.GetBoolean(key, &boolean_value)) << key; | 17 EXPECT_TRUE(value.GetBoolean(key, &boolean_value)) << key; |
| 18 EXPECT_EQ(expected_value, boolean_value) << key; | 18 EXPECT_EQ(expected_value, boolean_value) << key; |
| 19 } | 19 } |
| 20 | 20 |
| 21 void ExpectDictDictionaryValue(const DictionaryValue& expected_value, | 21 void ExpectDictDictionaryValue(const DictionaryValue& expected_value, |
| 22 const DictionaryValue& value, | 22 const DictionaryValue& value, |
| 23 const std::string& key) { | 23 const std::string& key) { |
| 24 DictionaryValue* dict_value = NULL; | 24 const DictionaryValue* dict_value = NULL; |
| 25 EXPECT_TRUE(value.GetDictionary(key, &dict_value)) << key; | 25 EXPECT_TRUE(value.GetDictionary(key, &dict_value)) << key; |
| 26 EXPECT_TRUE(Value::Equals(dict_value, &expected_value)) << key; | 26 EXPECT_TRUE(Value::Equals(dict_value, &expected_value)) << key; |
| 27 } | 27 } |
| 28 | 28 |
| 29 void ExpectDictIntegerValue(int expected_value, | 29 void ExpectDictIntegerValue(int expected_value, |
| 30 const DictionaryValue& value, | 30 const DictionaryValue& value, |
| 31 const std::string& key) { | 31 const std::string& key) { |
| 32 int integer_value = 0; | 32 int integer_value = 0; |
| 33 EXPECT_TRUE(value.GetInteger(key, &integer_value)) << key; | 33 EXPECT_TRUE(value.GetInteger(key, &integer_value)) << key; |
| 34 EXPECT_EQ(expected_value, integer_value) << key; | 34 EXPECT_EQ(expected_value, integer_value) << key; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void ExpectDictListValue(const ListValue& expected_value, | 37 void ExpectDictListValue(const ListValue& expected_value, |
| 38 const DictionaryValue& value, | 38 const DictionaryValue& value, |
| 39 const std::string& key) { | 39 const std::string& key) { |
| 40 ListValue* list_value = NULL; | 40 const ListValue* list_value = NULL; |
| 41 EXPECT_TRUE(value.GetList(key, &list_value)) << key; | 41 EXPECT_TRUE(value.GetList(key, &list_value)) << key; |
| 42 EXPECT_TRUE(Value::Equals(list_value, &expected_value)) << key; | 42 EXPECT_TRUE(Value::Equals(list_value, &expected_value)) << key; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void ExpectDictStringValue(const std::string& expected_value, | 45 void ExpectDictStringValue(const std::string& expected_value, |
| 46 const DictionaryValue& value, | 46 const DictionaryValue& value, |
| 47 const std::string& key) { | 47 const std::string& key) { |
| 48 std::string string_value; | 48 std::string string_value; |
| 49 EXPECT_TRUE(value.GetString(key, &string_value)) << key; | 49 EXPECT_TRUE(value.GetString(key, &string_value)) << key; |
| 50 EXPECT_EQ(expected_value, string_value) << key; | 50 EXPECT_EQ(expected_value, string_value) << key; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void ExpectStringValue(const std::string& expected_str, | 53 void ExpectStringValue(const std::string& expected_str, |
| 54 StringValue* actual) { | 54 StringValue* actual) { |
| 55 scoped_ptr<StringValue> scoped_actual(actual); | 55 scoped_ptr<StringValue> scoped_actual(actual); |
| 56 std::string actual_str; | 56 std::string actual_str; |
| 57 EXPECT_TRUE(scoped_actual->GetAsString(&actual_str)); | 57 EXPECT_TRUE(scoped_actual->GetAsString(&actual_str)); |
| 58 EXPECT_EQ(expected_str, actual_str); | 58 EXPECT_EQ(expected_str, actual_str); |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace base | 61 } // namespace base |
| OLD | NEW |