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

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

Issue 2481753002: Push preg_parser and registry_dict changes upstream (Closed)
Patch Set: Minor formatting fixes Created 4 years, 1 month 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
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.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "components/policy/core/common/schema.h" 12 #include "components/policy/core/common/schema.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace policy { 15 namespace policy {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 EXPECT_TRUE(base::Value::Equals(&int_value, dict_b.GetValue("one"))); 178 EXPECT_TRUE(base::Value::Equals(&int_value, dict_b.GetValue("one")));
179 EXPECT_TRUE(dict_b.GetKey("two")); 179 EXPECT_TRUE(dict_b.GetKey("two"));
180 EXPECT_FALSE(dict_b.GetValue("two")); 180 EXPECT_FALSE(dict_b.GetValue("two"));
181 181
182 EXPECT_TRUE(base::Value::Equals(&string_value, dict_a.GetValue("three"))); 182 EXPECT_TRUE(base::Value::Equals(&string_value, dict_a.GetValue("three")));
183 EXPECT_FALSE(dict_a.GetValue("one")); 183 EXPECT_FALSE(dict_a.GetValue("one"));
184 EXPECT_FALSE(dict_a.GetKey("two")); 184 EXPECT_FALSE(dict_a.GetKey("two"));
185 } 185 }
186 186
187 #if defined(OS_WIN)
187 TEST(RegistryDictTest, ConvertToJSON) { 188 TEST(RegistryDictTest, ConvertToJSON) {
188 RegistryDict test_dict; 189 RegistryDict test_dict;
189 190
190 base::FundamentalValue int_value(42); 191 base::FundamentalValue int_value(42);
191 base::StringValue string_value("fortytwo"); 192 base::StringValue string_value("fortytwo");
192 base::StringValue string_zero("0"); 193 base::StringValue string_zero("0");
193 base::StringValue string_dict("{ \"key\": [ \"value\" ] }"); 194 base::StringValue string_dict("{ \"key\": [ \"value\" ] }");
194 195
195 test_dict.SetValue("one", int_value.CreateDeepCopy()); 196 test_dict.SetValue("one", int_value.CreateDeepCopy());
196 std::unique_ptr<RegistryDict> subdict(new RegistryDict()); 197 std::unique_ptr<RegistryDict> subdict(new RegistryDict());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 std::unique_ptr<base::ListValue> expected_list(new base::ListValue()); 238 std::unique_ptr<base::ListValue> expected_list(new base::ListValue());
238 expected_list->Append(string_value.CreateDeepCopy()); 239 expected_list->Append(string_value.CreateDeepCopy());
239 expected.Set("dict-to-list", std::move(expected_list)); 240 expected.Set("dict-to-list", std::move(expected_list));
240 expected.Set("int-to-bool", new base::FundamentalValue(true)); 241 expected.Set("int-to-bool", new base::FundamentalValue(true));
241 expected.Set("int-to-double", new base::FundamentalValue(42.0)); 242 expected.Set("int-to-double", new base::FundamentalValue(42.0));
242 expected.Set("string-to-bool", new base::FundamentalValue(false)); 243 expected.Set("string-to-bool", new base::FundamentalValue(false));
243 expected.Set("string-to-double", new base::FundamentalValue(0.0)); 244 expected.Set("string-to-double", new base::FundamentalValue(0.0));
244 expected.Set("string-to-int", 245 expected.Set("string-to-int",
245 new base::FundamentalValue(static_cast<int>(0))); 246 new base::FundamentalValue(static_cast<int>(0)));
246 expected_list.reset(new base::ListValue()); 247 expected_list.reset(new base::ListValue());
247 expected_list->Append(new base::StringValue("value")); 248 expected_list->Append(base::MakeUnique<base::StringValue>("value"));
248 expected_subdict.reset(new base::DictionaryValue()); 249 expected_subdict.reset(new base::DictionaryValue());
249 expected_subdict->Set("key", std::move(expected_list)); 250 expected_subdict->Set("key", std::move(expected_list));
250 expected.Set("string-to-dict", std::move(expected_subdict)); 251 expected.Set("string-to-dict", std::move(expected_subdict));
251 252
252 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); 253 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected));
253 } 254 }
254 255
255 TEST(RegistryDictTest, NonSequentialConvertToJSON) { 256 TEST(RegistryDictTest, NonSequentialConvertToJSON) {
256 RegistryDict test_dict; 257 RegistryDict test_dict;
257 258
(...skipping 22 matching lines...) Expand all
280 281
281 base::DictionaryValue expected; 282 base::DictionaryValue expected;
282 std::unique_ptr<base::ListValue> expected_list(new base::ListValue()); 283 std::unique_ptr<base::ListValue> expected_list(new base::ListValue());
283 expected_list->Append(base::StringValue("1").CreateDeepCopy()); 284 expected_list->Append(base::StringValue("1").CreateDeepCopy());
284 expected_list->Append(base::StringValue("2").CreateDeepCopy()); 285 expected_list->Append(base::StringValue("2").CreateDeepCopy());
285 expected_list->Append(base::StringValue("4").CreateDeepCopy()); 286 expected_list->Append(base::StringValue("4").CreateDeepCopy());
286 expected.Set("dict-to-list", std::move(expected_list)); 287 expected.Set("dict-to-list", std::move(expected_list));
287 288
288 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); 289 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected));
289 } 290 }
291 #endif
290 292
291 TEST(RegistryDictTest, KeyValueNameClashes) { 293 TEST(RegistryDictTest, KeyValueNameClashes) {
292 RegistryDict test_dict; 294 RegistryDict test_dict;
293 295
294 base::FundamentalValue int_value(42); 296 base::FundamentalValue int_value(42);
295 base::StringValue string_value("fortytwo"); 297 base::StringValue string_value("fortytwo");
296 298
297 test_dict.SetValue("one", int_value.CreateDeepCopy()); 299 test_dict.SetValue("one", int_value.CreateDeepCopy());
298 std::unique_ptr<RegistryDict> subdict(new RegistryDict()); 300 std::unique_ptr<RegistryDict> subdict(new RegistryDict());
299 subdict->SetValue("two", string_value.CreateDeepCopy()); 301 subdict->SetValue("two", string_value.CreateDeepCopy());
300 test_dict.SetKey("one", std::move(subdict)); 302 test_dict.SetKey("one", std::move(subdict));
301 303
302 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); 304 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one")));
303 RegistryDict* actual_subdict = test_dict.GetKey("one"); 305 RegistryDict* actual_subdict = test_dict.GetKey("one");
304 ASSERT_TRUE(actual_subdict); 306 ASSERT_TRUE(actual_subdict);
305 EXPECT_TRUE(base::Value::Equals(&string_value, 307 EXPECT_TRUE(base::Value::Equals(&string_value,
306 actual_subdict->GetValue("two"))); 308 actual_subdict->GetValue("two")));
307 } 309 }
308 310
309 } // namespace 311 } // namespace
310 } // namespace policy 312 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/registry_dict.cc ('k') | components/policy/core/common/registry_dict_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698