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

Side by Side Diff: components/policy/core/common/registry_dict_win_unittest.cc

Issue 369303004: Pass() type followups after https://codereview.chromium.org/367403002/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bleh Created 6 years, 5 months 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 | « components/policy/core/common/registry_dict_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/policy/core/common/registry_dict_win.h" 5 #include "components/policy/core/common/registry_dict_win.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/policy/core/common/schema.h" 10 #include "components/policy/core/common/schema.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace policy { 13 namespace policy {
14 namespace { 14 namespace {
15 15
16 TEST(RegistryDictTest, SetAndGetValue) { 16 TEST(RegistryDictTest, SetAndGetValue) {
17 RegistryDict test_dict; 17 RegistryDict test_dict;
18 18
19 base::FundamentalValue int_value(42); 19 base::FundamentalValue int_value(42);
20 base::StringValue string_value("fortytwo"); 20 base::StringValue string_value("fortytwo");
21 21
22 test_dict.SetValue("one", make_scoped_ptr(int_value.DeepCopy()).Pass()); 22 test_dict.SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy()));
23 EXPECT_EQ(1, test_dict.values().size()); 23 EXPECT_EQ(1, test_dict.values().size());
24 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); 24 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one")));
25 EXPECT_FALSE(test_dict.GetValue("two")); 25 EXPECT_FALSE(test_dict.GetValue("two"));
26 26
27 test_dict.SetValue("two", make_scoped_ptr(string_value.DeepCopy()).Pass()); 27 test_dict.SetValue("two", scoped_ptr<base::Value>(string_value.DeepCopy()));
28 EXPECT_EQ(2, test_dict.values().size()); 28 EXPECT_EQ(2, test_dict.values().size());
29 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); 29 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one")));
30 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("two"))); 30 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("two")));
31 31
32 scoped_ptr<base::Value> one(test_dict.RemoveValue("one")); 32 scoped_ptr<base::Value> one(test_dict.RemoveValue("one"));
33 EXPECT_EQ(1, test_dict.values().size()); 33 EXPECT_EQ(1, test_dict.values().size());
34 EXPECT_TRUE(base::Value::Equals(&int_value, one.get())); 34 EXPECT_TRUE(base::Value::Equals(&int_value, one.get()));
35 EXPECT_FALSE(test_dict.GetValue("one")); 35 EXPECT_FALSE(test_dict.GetValue("one"));
36 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("two"))); 36 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("two")));
37 37
38 test_dict.ClearValues(); 38 test_dict.ClearValues();
39 EXPECT_FALSE(test_dict.GetValue("one")); 39 EXPECT_FALSE(test_dict.GetValue("one"));
40 EXPECT_FALSE(test_dict.GetValue("two")); 40 EXPECT_FALSE(test_dict.GetValue("two"));
41 EXPECT_TRUE(test_dict.values().empty()); 41 EXPECT_TRUE(test_dict.values().empty());
42 } 42 }
43 43
44 TEST(RegistryDictTest, CaseInsensitiveButPreservingValueNames) { 44 TEST(RegistryDictTest, CaseInsensitiveButPreservingValueNames) {
45 RegistryDict test_dict; 45 RegistryDict test_dict;
46 46
47 base::FundamentalValue int_value(42); 47 base::FundamentalValue int_value(42);
48 base::StringValue string_value("fortytwo"); 48 base::StringValue string_value("fortytwo");
49 49
50 test_dict.SetValue("One", make_scoped_ptr(int_value.DeepCopy()).Pass()); 50 test_dict.SetValue("One", scoped_ptr<base::Value>(int_value.DeepCopy()));
51 EXPECT_EQ(1, test_dict.values().size()); 51 EXPECT_EQ(1, test_dict.values().size());
52 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("oNe"))); 52 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("oNe")));
53 53
54 RegistryDict::ValueMap::const_iterator entry = test_dict.values().begin(); 54 RegistryDict::ValueMap::const_iterator entry = test_dict.values().begin();
55 ASSERT_NE(entry, test_dict.values().end()); 55 ASSERT_NE(entry, test_dict.values().end());
56 EXPECT_EQ("One", entry->first); 56 EXPECT_EQ("One", entry->first);
57 57
58 test_dict.SetValue("ONE", make_scoped_ptr(string_value.DeepCopy()).Pass()); 58 test_dict.SetValue("ONE", scoped_ptr<base::Value>(string_value.DeepCopy()));
59 EXPECT_EQ(1, test_dict.values().size()); 59 EXPECT_EQ(1, test_dict.values().size());
60 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("one"))); 60 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("one")));
61 61
62 scoped_ptr<base::Value> removed_value(test_dict.RemoveValue("onE")); 62 scoped_ptr<base::Value> removed_value(test_dict.RemoveValue("onE"));
63 EXPECT_TRUE(base::Value::Equals(&string_value, removed_value.get())); 63 EXPECT_TRUE(base::Value::Equals(&string_value, removed_value.get()));
64 EXPECT_TRUE(test_dict.values().empty()); 64 EXPECT_TRUE(test_dict.values().empty());
65 } 65 }
66 66
67 TEST(RegistryDictTest, SetAndGetKeys) { 67 TEST(RegistryDictTest, SetAndGetKeys) {
68 RegistryDict test_dict; 68 RegistryDict test_dict;
69 69
70 base::FundamentalValue int_value(42); 70 base::FundamentalValue int_value(42);
71 base::StringValue string_value("fortytwo"); 71 base::StringValue string_value("fortytwo");
72 72
73 scoped_ptr<RegistryDict> subdict(new RegistryDict()); 73 scoped_ptr<RegistryDict> subdict(new RegistryDict());
74 subdict->SetValue("one", make_scoped_ptr(int_value.DeepCopy()).Pass()); 74 subdict->SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy()));
75 test_dict.SetKey("two", subdict.Pass()); 75 test_dict.SetKey("two", subdict.Pass());
76 EXPECT_EQ(1, test_dict.keys().size()); 76 EXPECT_EQ(1, test_dict.keys().size());
77 RegistryDict* actual_subdict = test_dict.GetKey("two"); 77 RegistryDict* actual_subdict = test_dict.GetKey("two");
78 ASSERT_TRUE(actual_subdict); 78 ASSERT_TRUE(actual_subdict);
79 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("one"))); 79 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("one")));
80 80
81 subdict.reset(new RegistryDict()); 81 subdict.reset(new RegistryDict());
82 subdict->SetValue("three", make_scoped_ptr(string_value.DeepCopy()).Pass()); 82 subdict->SetValue("three", scoped_ptr<base::Value>(string_value.DeepCopy()));
83 test_dict.SetKey("four", subdict.Pass()); 83 test_dict.SetKey("four", subdict.Pass());
84 EXPECT_EQ(2, test_dict.keys().size()); 84 EXPECT_EQ(2, test_dict.keys().size());
85 actual_subdict = test_dict.GetKey("two"); 85 actual_subdict = test_dict.GetKey("two");
86 ASSERT_TRUE(actual_subdict); 86 ASSERT_TRUE(actual_subdict);
87 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("one"))); 87 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("one")));
88 actual_subdict = test_dict.GetKey("four"); 88 actual_subdict = test_dict.GetKey("four");
89 ASSERT_TRUE(actual_subdict); 89 ASSERT_TRUE(actual_subdict);
90 EXPECT_TRUE(base::Value::Equals(&string_value, 90 EXPECT_TRUE(base::Value::Equals(&string_value,
91 actual_subdict->GetValue("three"))); 91 actual_subdict->GetValue("three")));
92 92
(...skipping 12 matching lines...) Expand all
105 EXPECT_EQ(1, test_dict.keys().size()); 105 EXPECT_EQ(1, test_dict.keys().size());
106 RegistryDict* actual_subdict = test_dict.GetKey("One"); 106 RegistryDict* actual_subdict = test_dict.GetKey("One");
107 ASSERT_TRUE(actual_subdict); 107 ASSERT_TRUE(actual_subdict);
108 EXPECT_TRUE(actual_subdict->values().empty()); 108 EXPECT_TRUE(actual_subdict->values().empty());
109 109
110 RegistryDict::KeyMap::const_iterator entry = test_dict.keys().begin(); 110 RegistryDict::KeyMap::const_iterator entry = test_dict.keys().begin();
111 ASSERT_NE(entry, test_dict.keys().end()); 111 ASSERT_NE(entry, test_dict.keys().end());
112 EXPECT_EQ("One", entry->first); 112 EXPECT_EQ("One", entry->first);
113 113
114 scoped_ptr<RegistryDict> subdict(new RegistryDict()); 114 scoped_ptr<RegistryDict> subdict(new RegistryDict());
115 subdict->SetValue("two", make_scoped_ptr(int_value.DeepCopy()).Pass()); 115 subdict->SetValue("two", scoped_ptr<base::Value>(int_value.DeepCopy()));
116 test_dict.SetKey("ONE", subdict.Pass()); 116 test_dict.SetKey("ONE", subdict.Pass());
117 EXPECT_EQ(1, test_dict.keys().size()); 117 EXPECT_EQ(1, test_dict.keys().size());
118 actual_subdict = test_dict.GetKey("One"); 118 actual_subdict = test_dict.GetKey("One");
119 ASSERT_TRUE(actual_subdict); 119 ASSERT_TRUE(actual_subdict);
120 EXPECT_TRUE(base::Value::Equals(&int_value, 120 EXPECT_TRUE(base::Value::Equals(&int_value,
121 actual_subdict->GetValue("two"))); 121 actual_subdict->GetValue("two")));
122 122
123 scoped_ptr<RegistryDict> removed_key(test_dict.RemoveKey("one")); 123 scoped_ptr<RegistryDict> removed_key(test_dict.RemoveKey("one"));
124 ASSERT_TRUE(removed_key); 124 ASSERT_TRUE(removed_key);
125 EXPECT_TRUE(base::Value::Equals(&int_value, 125 EXPECT_TRUE(base::Value::Equals(&int_value,
126 removed_key->GetValue("two"))); 126 removed_key->GetValue("two")));
127 EXPECT_TRUE(test_dict.keys().empty()); 127 EXPECT_TRUE(test_dict.keys().empty());
128 } 128 }
129 129
130 TEST(RegistryDictTest, Merge) { 130 TEST(RegistryDictTest, Merge) {
131 RegistryDict dict_a; 131 RegistryDict dict_a;
132 RegistryDict dict_b; 132 RegistryDict dict_b;
133 133
134 base::FundamentalValue int_value(42); 134 base::FundamentalValue int_value(42);
135 base::StringValue string_value("fortytwo"); 135 base::StringValue string_value("fortytwo");
136 136
137 dict_a.SetValue("one", make_scoped_ptr(int_value.DeepCopy()).Pass()); 137 dict_a.SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy()));
138 scoped_ptr<RegistryDict> subdict(new RegistryDict()); 138 scoped_ptr<RegistryDict> subdict(new RegistryDict());
139 subdict->SetValue("two", make_scoped_ptr(string_value.DeepCopy()).Pass()); 139 subdict->SetValue("two", scoped_ptr<base::Value>(string_value.DeepCopy()));
140 dict_a.SetKey("three", subdict.Pass()); 140 dict_a.SetKey("three", subdict.Pass());
141 141
142 dict_b.SetValue("four", make_scoped_ptr(string_value.DeepCopy()).Pass()); 142 dict_b.SetValue("four", scoped_ptr<base::Value>(string_value.DeepCopy()));
143 subdict.reset(new RegistryDict()); 143 subdict.reset(new RegistryDict());
144 subdict->SetValue("two", make_scoped_ptr(int_value.DeepCopy()).Pass()); 144 subdict->SetValue("two", scoped_ptr<base::Value>(int_value.DeepCopy()));
145 dict_b.SetKey("three", subdict.Pass()); 145 dict_b.SetKey("three", subdict.Pass());
146 subdict.reset(new RegistryDict()); 146 subdict.reset(new RegistryDict());
147 subdict->SetValue("five", make_scoped_ptr(int_value.DeepCopy()).Pass()); 147 subdict->SetValue("five", scoped_ptr<base::Value>(int_value.DeepCopy()));
148 dict_b.SetKey("six", subdict.Pass()); 148 dict_b.SetKey("six", subdict.Pass());
149 149
150 dict_a.Merge(dict_b); 150 dict_a.Merge(dict_b);
151 151
152 EXPECT_TRUE(base::Value::Equals(&int_value, dict_a.GetValue("one"))); 152 EXPECT_TRUE(base::Value::Equals(&int_value, dict_a.GetValue("one")));
153 EXPECT_TRUE(base::Value::Equals(&string_value, dict_b.GetValue("four"))); 153 EXPECT_TRUE(base::Value::Equals(&string_value, dict_b.GetValue("four")));
154 RegistryDict* actual_subdict = dict_a.GetKey("three"); 154 RegistryDict* actual_subdict = dict_a.GetKey("three");
155 ASSERT_TRUE(actual_subdict); 155 ASSERT_TRUE(actual_subdict);
156 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("two"))); 156 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("two")));
157 actual_subdict = dict_a.GetKey("six"); 157 actual_subdict = dict_a.GetKey("six");
158 ASSERT_TRUE(actual_subdict); 158 ASSERT_TRUE(actual_subdict);
159 EXPECT_TRUE(base::Value::Equals(&int_value, 159 EXPECT_TRUE(base::Value::Equals(&int_value,
160 actual_subdict->GetValue("five"))); 160 actual_subdict->GetValue("five")));
161 } 161 }
162 162
163 TEST(RegistryDictTest, Swap) { 163 TEST(RegistryDictTest, Swap) {
164 RegistryDict dict_a; 164 RegistryDict dict_a;
165 RegistryDict dict_b; 165 RegistryDict dict_b;
166 166
167 base::FundamentalValue int_value(42); 167 base::FundamentalValue int_value(42);
168 base::StringValue string_value("fortytwo"); 168 base::StringValue string_value("fortytwo");
169 169
170 dict_a.SetValue("one", make_scoped_ptr(int_value.DeepCopy()).Pass()); 170 dict_a.SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy()));
171 dict_a.SetKey("two", make_scoped_ptr(new RegistryDict()).Pass()); 171 dict_a.SetKey("two", make_scoped_ptr(new RegistryDict()).Pass());
172 dict_b.SetValue("three", make_scoped_ptr(string_value.DeepCopy()).Pass()); 172 dict_b.SetValue("three", scoped_ptr<base::Value>(string_value.DeepCopy()));
173 173
174 dict_a.Swap(&dict_b); 174 dict_a.Swap(&dict_b);
175 175
176 EXPECT_TRUE(base::Value::Equals(&int_value, dict_b.GetValue("one"))); 176 EXPECT_TRUE(base::Value::Equals(&int_value, dict_b.GetValue("one")));
177 EXPECT_TRUE(dict_b.GetKey("two")); 177 EXPECT_TRUE(dict_b.GetKey("two"));
178 EXPECT_FALSE(dict_b.GetValue("two")); 178 EXPECT_FALSE(dict_b.GetValue("two"));
179 179
180 EXPECT_TRUE(base::Value::Equals(&string_value, dict_a.GetValue("three"))); 180 EXPECT_TRUE(base::Value::Equals(&string_value, dict_a.GetValue("three")));
181 EXPECT_FALSE(dict_a.GetValue("one")); 181 EXPECT_FALSE(dict_a.GetValue("one"));
182 EXPECT_FALSE(dict_a.GetKey("two")); 182 EXPECT_FALSE(dict_a.GetKey("two"));
183 } 183 }
184 184
185 TEST(RegistryDictTest, ConvertToJSON) { 185 TEST(RegistryDictTest, ConvertToJSON) {
186 RegistryDict test_dict; 186 RegistryDict test_dict;
187 187
188 base::FundamentalValue int_value(42); 188 base::FundamentalValue int_value(42);
189 base::StringValue string_value("fortytwo"); 189 base::StringValue string_value("fortytwo");
190 base::StringValue string_zero("0"); 190 base::StringValue string_zero("0");
191 base::StringValue string_dict("{ \"key\": [ \"value\" ] }"); 191 base::StringValue string_dict("{ \"key\": [ \"value\" ] }");
192 192
193 test_dict.SetValue("one", make_scoped_ptr(int_value.DeepCopy()).Pass()); 193 test_dict.SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy()));
194 scoped_ptr<RegistryDict> subdict(new RegistryDict()); 194 scoped_ptr<RegistryDict> subdict(new RegistryDict());
195 subdict->SetValue("two", make_scoped_ptr(string_value.DeepCopy()).Pass()); 195 subdict->SetValue("two", scoped_ptr<base::Value>(string_value.DeepCopy()));
196 test_dict.SetKey("three", subdict.Pass()); 196 test_dict.SetKey("three", subdict.Pass());
197 scoped_ptr<RegistryDict> list(new RegistryDict()); 197 scoped_ptr<RegistryDict> list(new RegistryDict());
198 list->SetValue("1", make_scoped_ptr(string_value.DeepCopy()).Pass()); 198 list->SetValue("1", scoped_ptr<base::Value>(string_value.DeepCopy()));
199 test_dict.SetKey("dict-to-list", list.Pass()); 199 test_dict.SetKey("dict-to-list", list.Pass());
200 test_dict.SetValue("int-to-bool", 200 test_dict.SetValue("int-to-bool",
201 make_scoped_ptr(int_value.DeepCopy()).Pass()); 201 scoped_ptr<base::Value>(int_value.DeepCopy()));
202 test_dict.SetValue("int-to-double", 202 test_dict.SetValue("int-to-double",
203 make_scoped_ptr(int_value.DeepCopy()).Pass()); 203 scoped_ptr<base::Value>(int_value.DeepCopy()));
204 test_dict.SetValue("string-to-bool", 204 test_dict.SetValue("string-to-bool",
205 make_scoped_ptr(string_zero.DeepCopy()).Pass()); 205 scoped_ptr<base::Value>(string_zero.DeepCopy()));
206 test_dict.SetValue("string-to-double", 206 test_dict.SetValue("string-to-double",
207 make_scoped_ptr(string_zero.DeepCopy()).Pass()); 207 scoped_ptr<base::Value>(string_zero.DeepCopy()));
208 test_dict.SetValue("string-to-int", 208 test_dict.SetValue("string-to-int",
209 make_scoped_ptr(string_zero.DeepCopy()).Pass()); 209 scoped_ptr<base::Value>(string_zero.DeepCopy()));
210 test_dict.SetValue("string-to-dict", 210 test_dict.SetValue("string-to-dict",
211 make_scoped_ptr(string_dict.DeepCopy()).Pass()); 211 scoped_ptr<base::Value>(string_dict.DeepCopy()));
212 212
213 std::string error; 213 std::string error;
214 Schema schema = Schema::Parse( 214 Schema schema = Schema::Parse(
215 "{" 215 "{"
216 " \"type\": \"object\"," 216 " \"type\": \"object\","
217 " \"properties\": {" 217 " \"properties\": {"
218 " \"dict-to-list\": {" 218 " \"dict-to-list\": {"
219 " \"type\": \"array\"," 219 " \"type\": \"array\","
220 " \"items\": { \"type\": \"string\" }" 220 " \"items\": { \"type\": \"string\" }"
221 " }," 221 " },"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 253
254 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); 254 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected));
255 } 255 }
256 256
257 TEST(RegistryDictTest, KeyValueNameClashes) { 257 TEST(RegistryDictTest, KeyValueNameClashes) {
258 RegistryDict test_dict; 258 RegistryDict test_dict;
259 259
260 base::FundamentalValue int_value(42); 260 base::FundamentalValue int_value(42);
261 base::StringValue string_value("fortytwo"); 261 base::StringValue string_value("fortytwo");
262 262
263 test_dict.SetValue("one", make_scoped_ptr(int_value.DeepCopy()).Pass()); 263 test_dict.SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy()));
264 scoped_ptr<RegistryDict> subdict(new RegistryDict()); 264 scoped_ptr<RegistryDict> subdict(new RegistryDict());
265 subdict->SetValue("two", make_scoped_ptr(string_value.DeepCopy()).Pass()); 265 subdict->SetValue("two", scoped_ptr<base::Value>(string_value.DeepCopy()));
266 test_dict.SetKey("one", subdict.Pass()); 266 test_dict.SetKey("one", subdict.Pass());
267 267
268 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); 268 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one")));
269 RegistryDict* actual_subdict = test_dict.GetKey("one"); 269 RegistryDict* actual_subdict = test_dict.GetKey("one");
270 ASSERT_TRUE(actual_subdict); 270 ASSERT_TRUE(actual_subdict);
271 EXPECT_TRUE(base::Value::Equals(&string_value, 271 EXPECT_TRUE(base::Value::Equals(&string_value,
272 actual_subdict->GetValue("two"))); 272 actual_subdict->GetValue("two")));
273 } 273 }
274 274
275 } // namespace 275 } // namespace
276 } // namespace policy 276 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/registry_dict_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698