Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: base/prefs/pref_value_map_unittest.cc

Issue 11519026: base: Do not use Value::Create* functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: scoped_ptr Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/prefs/pref_value_map.cc ('k') | base/prefs/public/pref_change_registrar_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/prefs/pref_value_map.h" 5 #include "base/prefs/pref_value_map.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace base {
11 namespace {
12
10 TEST(PrefValueMapTest, SetValue) { 13 TEST(PrefValueMapTest, SetValue) {
11 PrefValueMap map; 14 PrefValueMap map;
12 const Value* result = NULL; 15 const Value* result = NULL;
13 EXPECT_FALSE(map.GetValue("key", &result)); 16 EXPECT_FALSE(map.GetValue("key", &result));
14 EXPECT_FALSE(result); 17 EXPECT_FALSE(result);
15 18
16 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test"))); 19 EXPECT_TRUE(map.SetValue("key", new StringValue("test")));
17 EXPECT_FALSE(map.SetValue("key", Value::CreateStringValue("test"))); 20 EXPECT_FALSE(map.SetValue("key", new StringValue("test")));
18 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("hi mom!"))); 21 EXPECT_TRUE(map.SetValue("key", new StringValue("hi mom!")));
19 22
20 EXPECT_TRUE(map.GetValue("key", &result)); 23 EXPECT_TRUE(map.GetValue("key", &result));
21 EXPECT_TRUE(StringValue("hi mom!").Equals(result)); 24 EXPECT_TRUE(StringValue("hi mom!").Equals(result));
22 } 25 }
23 26
24 TEST(PrefValueMapTest, GetAndSetIntegerValue) { 27 TEST(PrefValueMapTest, GetAndSetIntegerValue) {
25 PrefValueMap map; 28 PrefValueMap map;
26 ASSERT_TRUE(map.SetValue("key", Value::CreateIntegerValue(5))); 29 ASSERT_TRUE(map.SetValue("key", new FundamentalValue(5)));
27 30
28 int int_value = 0; 31 int int_value = 0;
29 EXPECT_TRUE(map.GetInteger("key", &int_value)); 32 EXPECT_TRUE(map.GetInteger("key", &int_value));
30 EXPECT_EQ(5, int_value); 33 EXPECT_EQ(5, int_value);
31 34
32 map.SetInteger("key", -14); 35 map.SetInteger("key", -14);
33 EXPECT_TRUE(map.GetInteger("key", &int_value)); 36 EXPECT_TRUE(map.GetInteger("key", &int_value));
34 EXPECT_EQ(-14, int_value); 37 EXPECT_EQ(-14, int_value);
35 } 38 }
36 39
37 TEST(PrefValueMapTest, RemoveValue) { 40 TEST(PrefValueMapTest, RemoveValue) {
38 PrefValueMap map; 41 PrefValueMap map;
39 EXPECT_FALSE(map.RemoveValue("key")); 42 EXPECT_FALSE(map.RemoveValue("key"));
40 43
41 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test"))); 44 EXPECT_TRUE(map.SetValue("key", new StringValue("test")));
42 EXPECT_TRUE(map.GetValue("key", NULL)); 45 EXPECT_TRUE(map.GetValue("key", NULL));
43 46
44 EXPECT_TRUE(map.RemoveValue("key")); 47 EXPECT_TRUE(map.RemoveValue("key"));
45 EXPECT_FALSE(map.GetValue("key", NULL)); 48 EXPECT_FALSE(map.GetValue("key", NULL));
46 49
47 EXPECT_FALSE(map.RemoveValue("key")); 50 EXPECT_FALSE(map.RemoveValue("key"));
48 } 51 }
49 52
50 TEST(PrefValueMapTest, Clear) { 53 TEST(PrefValueMapTest, Clear) {
51 PrefValueMap map; 54 PrefValueMap map;
52 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test"))); 55 EXPECT_TRUE(map.SetValue("key", new StringValue("test")));
53 EXPECT_TRUE(map.GetValue("key", NULL)); 56 EXPECT_TRUE(map.GetValue("key", NULL));
54 57
55 map.Clear(); 58 map.Clear();
56 59
57 EXPECT_FALSE(map.GetValue("key", NULL)); 60 EXPECT_FALSE(map.GetValue("key", NULL));
58 } 61 }
59 62
60 TEST(PrefValueMapTest, GetDifferingKeys) { 63 TEST(PrefValueMapTest, GetDifferingKeys) {
61 PrefValueMap reference; 64 PrefValueMap reference;
62 EXPECT_TRUE(reference.SetValue("b", Value::CreateStringValue("test"))); 65 EXPECT_TRUE(reference.SetValue("b", new StringValue("test")));
63 EXPECT_TRUE(reference.SetValue("c", Value::CreateStringValue("test"))); 66 EXPECT_TRUE(reference.SetValue("c", new StringValue("test")));
64 EXPECT_TRUE(reference.SetValue("e", Value::CreateStringValue("test"))); 67 EXPECT_TRUE(reference.SetValue("e", new StringValue("test")));
65 68
66 PrefValueMap check; 69 PrefValueMap check;
67 std::vector<std::string> differing_paths; 70 std::vector<std::string> differing_paths;
68 std::vector<std::string> expected_differing_paths; 71 std::vector<std::string> expected_differing_paths;
69 72
70 reference.GetDifferingKeys(&check, &differing_paths); 73 reference.GetDifferingKeys(&check, &differing_paths);
71 expected_differing_paths.push_back("b"); 74 expected_differing_paths.push_back("b");
72 expected_differing_paths.push_back("c"); 75 expected_differing_paths.push_back("c");
73 expected_differing_paths.push_back("e"); 76 expected_differing_paths.push_back("e");
74 EXPECT_EQ(expected_differing_paths, differing_paths); 77 EXPECT_EQ(expected_differing_paths, differing_paths);
75 78
76 EXPECT_TRUE(check.SetValue("a", Value::CreateStringValue("test"))); 79 EXPECT_TRUE(check.SetValue("a", new StringValue("test")));
77 EXPECT_TRUE(check.SetValue("c", Value::CreateStringValue("test"))); 80 EXPECT_TRUE(check.SetValue("c", new StringValue("test")));
78 EXPECT_TRUE(check.SetValue("d", Value::CreateStringValue("test"))); 81 EXPECT_TRUE(check.SetValue("d", new StringValue("test")));
79 82
80 reference.GetDifferingKeys(&check, &differing_paths); 83 reference.GetDifferingKeys(&check, &differing_paths);
81 expected_differing_paths.clear(); 84 expected_differing_paths.clear();
82 expected_differing_paths.push_back("a"); 85 expected_differing_paths.push_back("a");
83 expected_differing_paths.push_back("b"); 86 expected_differing_paths.push_back("b");
84 expected_differing_paths.push_back("d"); 87 expected_differing_paths.push_back("d");
85 expected_differing_paths.push_back("e"); 88 expected_differing_paths.push_back("e");
86 EXPECT_EQ(expected_differing_paths, differing_paths); 89 EXPECT_EQ(expected_differing_paths, differing_paths);
87 } 90 }
88 91
89 TEST(PrefValueMapTest, SwapTwoMaps) { 92 TEST(PrefValueMapTest, SwapTwoMaps) {
90 PrefValueMap first_map; 93 PrefValueMap first_map;
91 EXPECT_TRUE(first_map.SetValue("a", Value::CreateStringValue("test"))); 94 EXPECT_TRUE(first_map.SetValue("a", new StringValue("test")));
92 EXPECT_TRUE(first_map.SetValue("b", Value::CreateStringValue("test"))); 95 EXPECT_TRUE(first_map.SetValue("b", new StringValue("test")));
93 EXPECT_TRUE(first_map.SetValue("c", Value::CreateStringValue("test"))); 96 EXPECT_TRUE(first_map.SetValue("c", new StringValue("test")));
94 97
95 PrefValueMap second_map; 98 PrefValueMap second_map;
96 EXPECT_TRUE(second_map.SetValue("d", Value::CreateStringValue("test"))); 99 EXPECT_TRUE(second_map.SetValue("d", new StringValue("test")));
97 EXPECT_TRUE(second_map.SetValue("e", Value::CreateStringValue("test"))); 100 EXPECT_TRUE(second_map.SetValue("e", new StringValue("test")));
98 EXPECT_TRUE(second_map.SetValue("f", Value::CreateStringValue("test"))); 101 EXPECT_TRUE(second_map.SetValue("f", new StringValue("test")));
99 102
100 first_map.Swap(&second_map); 103 first_map.Swap(&second_map);
101 104
102 EXPECT_TRUE(first_map.GetValue("d", NULL)); 105 EXPECT_TRUE(first_map.GetValue("d", NULL));
103 EXPECT_TRUE(first_map.GetValue("e", NULL)); 106 EXPECT_TRUE(first_map.GetValue("e", NULL));
104 EXPECT_TRUE(first_map.GetValue("f", NULL)); 107 EXPECT_TRUE(first_map.GetValue("f", NULL));
105 108
106 EXPECT_TRUE(second_map.GetValue("a", NULL)); 109 EXPECT_TRUE(second_map.GetValue("a", NULL));
107 EXPECT_TRUE(second_map.GetValue("b", NULL)); 110 EXPECT_TRUE(second_map.GetValue("b", NULL));
108 EXPECT_TRUE(second_map.GetValue("c", NULL)); 111 EXPECT_TRUE(second_map.GetValue("c", NULL));
109 } 112 }
113
114 } // namespace
115 } // namespace base
OLDNEW
« no previous file with comments | « base/prefs/pref_value_map.cc ('k') | base/prefs/public/pref_change_registrar_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698