OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/values.h" | 5 #include "base/values.h" |
6 #include "chrome/browser/prefs/pref_value_map.h" | 6 #include "chrome/browser/prefs/pref_value_map.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 class PrefValueMapTest : public testing::Test { | 9 class PrefValueMapTest : public testing::Test { |
10 }; | 10 }; |
11 | 11 |
12 TEST_F(PrefValueMapTest, SetValue) { | 12 TEST_F(PrefValueMapTest, SetValue) { |
13 PrefValueMap map; | 13 PrefValueMap map; |
14 const Value* result = NULL; | 14 const Value* result = NULL; |
15 EXPECT_FALSE(map.GetValue("key", &result)); | 15 EXPECT_FALSE(map.GetValue("key", &result)); |
16 EXPECT_FALSE(result); | 16 EXPECT_FALSE(result); |
17 | 17 |
18 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test"))); | 18 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test"))); |
19 EXPECT_FALSE(map.SetValue("key", Value::CreateStringValue("test"))); | 19 EXPECT_FALSE(map.SetValue("key", Value::CreateStringValue("test"))); |
20 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("hi mom!"))); | 20 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("hi mom!"))); |
21 | 21 |
22 EXPECT_TRUE(map.GetValue("key", &result)); | 22 EXPECT_TRUE(map.GetValue("key", &result)); |
23 EXPECT_TRUE(StringValue("hi mom!").Equals(result)); | 23 EXPECT_TRUE(StringValue("hi mom!").Equals(result)); |
24 } | 24 } |
25 | 25 |
| 26 TEST_F(PrefValueMapTest, GetAndSetIntegerValue) { |
| 27 PrefValueMap map; |
| 28 ASSERT_TRUE(map.SetValue("key", Value::CreateIntegerValue(5))); |
| 29 |
| 30 int int_value = 0; |
| 31 EXPECT_TRUE(map.GetInteger("key", &int_value)); |
| 32 EXPECT_EQ(5, int_value); |
| 33 |
| 34 map.SetInteger("key", -14); |
| 35 EXPECT_TRUE(map.GetInteger("key", &int_value)); |
| 36 EXPECT_EQ(-14, int_value); |
| 37 } |
| 38 |
26 TEST_F(PrefValueMapTest, RemoveValue) { | 39 TEST_F(PrefValueMapTest, RemoveValue) { |
27 PrefValueMap map; | 40 PrefValueMap map; |
28 EXPECT_FALSE(map.RemoveValue("key")); | 41 EXPECT_FALSE(map.RemoveValue("key")); |
29 | 42 |
30 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test"))); | 43 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test"))); |
31 EXPECT_TRUE(map.GetValue("key", NULL)); | 44 EXPECT_TRUE(map.GetValue("key", NULL)); |
32 | 45 |
33 EXPECT_TRUE(map.RemoveValue("key")); | 46 EXPECT_TRUE(map.RemoveValue("key")); |
34 EXPECT_FALSE(map.GetValue("key", NULL)); | 47 EXPECT_FALSE(map.GetValue("key", NULL)); |
35 | 48 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 EXPECT_TRUE(check.SetValue("d", Value::CreateStringValue("test"))); | 80 EXPECT_TRUE(check.SetValue("d", Value::CreateStringValue("test"))); |
68 | 81 |
69 reference.GetDifferingKeys(&check, &differing_paths); | 82 reference.GetDifferingKeys(&check, &differing_paths); |
70 expected_differing_paths.clear(); | 83 expected_differing_paths.clear(); |
71 expected_differing_paths.push_back("a"); | 84 expected_differing_paths.push_back("a"); |
72 expected_differing_paths.push_back("b"); | 85 expected_differing_paths.push_back("b"); |
73 expected_differing_paths.push_back("d"); | 86 expected_differing_paths.push_back("d"); |
74 expected_differing_paths.push_back("e"); | 87 expected_differing_paths.push_back("e"); |
75 EXPECT_EQ(expected_differing_paths, differing_paths); | 88 EXPECT_EQ(expected_differing_paths, differing_paths); |
76 } | 89 } |
OLD | NEW |