Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 " \"type\": \"array\"," | 215 " \"type\": \"array\"," |
| 216 " \"items\": { \"type\": \"string\" }" | 216 " \"items\": { \"type\": \"string\" }" |
| 217 " }," | 217 " }," |
| 218 " \"int-to-bool\": { \"type\": \"boolean\" }," | 218 " \"int-to-bool\": { \"type\": \"boolean\" }," |
| 219 " \"int-to-double\": { \"type\": \"number\" }," | 219 " \"int-to-double\": { \"type\": \"number\" }," |
| 220 " \"string-to-bool\": { \"type\": \"boolean\" }," | 220 " \"string-to-bool\": { \"type\": \"boolean\" }," |
| 221 " \"string-to-double\": { \"type\": \"number\" }," | 221 " \"string-to-double\": { \"type\": \"number\" }," |
| 222 " \"string-to-int\": { \"type\": \"integer\" }," | 222 " \"string-to-int\": { \"type\": \"integer\" }," |
| 223 " \"string-to-dict\": { \"type\": \"object\" }" | 223 " \"string-to-dict\": { \"type\": \"object\" }" |
| 224 " }" | 224 " }" |
| 225 "}", &error); | 225 "}", |
| 226 &error); | |
|
Georges Khalil
2016/11/03 16:04:31
Result of git cl format.
| |
| 226 ASSERT_TRUE(schema.valid()) << error; | 227 ASSERT_TRUE(schema.valid()) << error; |
| 227 | 228 |
| 228 std::unique_ptr<base::Value> actual(test_dict.ConvertToJSON(schema)); | 229 std::unique_ptr<base::Value> actual(test_dict.ConvertToJSON(schema)); |
| 229 | 230 |
| 230 base::DictionaryValue expected; | 231 base::DictionaryValue expected; |
| 231 expected.Set("one", int_value.CreateDeepCopy()); | 232 expected.Set("one", int_value.CreateDeepCopy()); |
| 232 std::unique_ptr<base::DictionaryValue> expected_subdict( | 233 std::unique_ptr<base::DictionaryValue> expected_subdict( |
| 233 new base::DictionaryValue()); | 234 new base::DictionaryValue()); |
| 234 expected_subdict->Set("two", string_value.CreateDeepCopy()); | 235 expected_subdict->Set("two", string_value.CreateDeepCopy()); |
| 235 expected.Set("three", std::move(expected_subdict)); | 236 expected.Set("three", std::move(expected_subdict)); |
| 236 std::unique_ptr<base::ListValue> expected_list(new base::ListValue()); | 237 std::unique_ptr<base::ListValue> expected_list(new base::ListValue()); |
| 237 expected_list->Append(string_value.CreateDeepCopy()); | 238 expected_list->Append(string_value.CreateDeepCopy()); |
| 238 expected.Set("dict-to-list", std::move(expected_list)); | 239 expected.Set("dict-to-list", std::move(expected_list)); |
| 239 expected.Set("int-to-bool", new base::FundamentalValue(true)); | 240 expected.Set("int-to-bool", new base::FundamentalValue(true)); |
| 240 expected.Set("int-to-double", new base::FundamentalValue(42.0)); | 241 expected.Set("int-to-double", new base::FundamentalValue(42.0)); |
| 241 expected.Set("string-to-bool", new base::FundamentalValue(false)); | 242 expected.Set("string-to-bool", new base::FundamentalValue(false)); |
| 242 expected.Set("string-to-double", new base::FundamentalValue(0.0)); | 243 expected.Set("string-to-double", new base::FundamentalValue(0.0)); |
| 243 expected.Set("string-to-int", | 244 expected.Set("string-to-int", |
| 244 new base::FundamentalValue(static_cast<int>(0))); | 245 new base::FundamentalValue(static_cast<int>(0))); |
| 245 expected_list.reset(new base::ListValue()); | 246 expected_list.reset(new base::ListValue()); |
| 246 expected_list->Append(new base::StringValue("value")); | 247 expected_list->Append(new base::StringValue("value")); |
| 247 expected_subdict.reset(new base::DictionaryValue()); | 248 expected_subdict.reset(new base::DictionaryValue()); |
| 248 expected_subdict->Set("key", std::move(expected_list)); | 249 expected_subdict->Set("key", std::move(expected_list)); |
| 249 expected.Set("string-to-dict", std::move(expected_subdict)); | 250 expected.Set("string-to-dict", std::move(expected_subdict)); |
| 250 | 251 |
| 251 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); | 252 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); |
| 252 } | 253 } |
| 253 | 254 |
| 255 TEST(RegistryDictTest, NonSequentialConvertToJSON) { | |
| 256 RegistryDict test_dict; | |
| 257 | |
| 258 std::unique_ptr<RegistryDict> list(new RegistryDict()); | |
| 259 list->SetValue("1", base::StringValue("1").CreateDeepCopy()); | |
| 260 list->SetValue("2", base::StringValue("2").CreateDeepCopy()); | |
| 261 list->SetValue("4", base::StringValue("4").CreateDeepCopy()); | |
| 262 test_dict.SetKey("dict-to-list", std::move(list)); | |
| 263 | |
| 264 std::string error; | |
| 265 Schema schema = Schema::Parse( | |
| 266 "{" | |
| 267 " \"type\": \"object\"," | |
| 268 " \"properties\": {" | |
| 269 " \"dict-to-list\": {" | |
| 270 " \"type\": \"array\"," | |
| 271 " \"items\": { \"type\": \"string\" }" | |
| 272 " }" | |
| 273 " }" | |
| 274 "}", | |
| 275 &error); | |
| 276 ASSERT_TRUE(schema.valid()) << error; | |
| 277 | |
| 278 std::unique_ptr<base::Value> actual(test_dict.ConvertToJSON(schema)); | |
| 279 | |
| 280 base::DictionaryValue expected; | |
| 281 std::unique_ptr<base::ListValue> expected_list(new base::ListValue()); | |
| 282 expected_list->Append(base::StringValue("1").CreateDeepCopy()); | |
| 283 expected_list->Append(base::StringValue("2").CreateDeepCopy()); | |
| 284 expected_list->Append(base::StringValue("4").CreateDeepCopy()); | |
| 285 expected.Set("dict-to-list", std::move(expected_list)); | |
| 286 | |
| 287 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); | |
| 288 } | |
| 289 | |
| 254 TEST(RegistryDictTest, KeyValueNameClashes) { | 290 TEST(RegistryDictTest, KeyValueNameClashes) { |
| 255 RegistryDict test_dict; | 291 RegistryDict test_dict; |
| 256 | 292 |
| 257 base::FundamentalValue int_value(42); | 293 base::FundamentalValue int_value(42); |
| 258 base::StringValue string_value("fortytwo"); | 294 base::StringValue string_value("fortytwo"); |
| 259 | 295 |
| 260 test_dict.SetValue("one", int_value.CreateDeepCopy()); | 296 test_dict.SetValue("one", int_value.CreateDeepCopy()); |
| 261 std::unique_ptr<RegistryDict> subdict(new RegistryDict()); | 297 std::unique_ptr<RegistryDict> subdict(new RegistryDict()); |
| 262 subdict->SetValue("two", string_value.CreateDeepCopy()); | 298 subdict->SetValue("two", string_value.CreateDeepCopy()); |
| 263 test_dict.SetKey("one", std::move(subdict)); | 299 test_dict.SetKey("one", std::move(subdict)); |
| 264 | 300 |
| 265 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); | 301 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); |
| 266 RegistryDict* actual_subdict = test_dict.GetKey("one"); | 302 RegistryDict* actual_subdict = test_dict.GetKey("one"); |
| 267 ASSERT_TRUE(actual_subdict); | 303 ASSERT_TRUE(actual_subdict); |
| 268 EXPECT_TRUE(base::Value::Equals(&string_value, | 304 EXPECT_TRUE(base::Value::Equals(&string_value, |
| 269 actual_subdict->GetValue("two"))); | 305 actual_subdict->GetValue("two"))); |
| 270 } | 306 } |
| 271 | 307 |
| 272 } // namespace | 308 } // namespace |
| 273 } // namespace policy | 309 } // namespace policy |
| OLD | NEW |