| 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 | 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", scoped_ptr<base::Value>(int_value.DeepCopy())); | 22 test_dict.SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy())); |
| 23 EXPECT_EQ(1, test_dict.values().size()); | 23 EXPECT_EQ(1u, 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", scoped_ptr<base::Value>(string_value.DeepCopy())); | 27 test_dict.SetValue("two", scoped_ptr<base::Value>(string_value.DeepCopy())); |
| 28 EXPECT_EQ(2, test_dict.values().size()); | 28 EXPECT_EQ(2u, 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(1u, 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", scoped_ptr<base::Value>(int_value.DeepCopy())); | 50 test_dict.SetValue("One", scoped_ptr<base::Value>(int_value.DeepCopy())); |
| 51 EXPECT_EQ(1, test_dict.values().size()); | 51 EXPECT_EQ(1u, 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", scoped_ptr<base::Value>(string_value.DeepCopy())); | 58 test_dict.SetValue("ONE", scoped_ptr<base::Value>(string_value.DeepCopy())); |
| 59 EXPECT_EQ(1, test_dict.values().size()); | 59 EXPECT_EQ(1u, 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", scoped_ptr<base::Value>(int_value.DeepCopy())); | 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(1u, 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", scoped_ptr<base::Value>(string_value.DeepCopy())); | 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(2u, 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 |
| 93 test_dict.ClearKeys(); | 93 test_dict.ClearKeys(); |
| 94 EXPECT_FALSE(test_dict.GetKey("one")); | 94 EXPECT_FALSE(test_dict.GetKey("one")); |
| 95 EXPECT_FALSE(test_dict.GetKey("three")); | 95 EXPECT_FALSE(test_dict.GetKey("three")); |
| 96 EXPECT_TRUE(test_dict.keys().empty()); | 96 EXPECT_TRUE(test_dict.keys().empty()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST(RegistryDictTest, CaseInsensitiveButPreservingKeyNames) { | 99 TEST(RegistryDictTest, CaseInsensitiveButPreservingKeyNames) { |
| 100 RegistryDict test_dict; | 100 RegistryDict test_dict; |
| 101 | 101 |
| 102 base::FundamentalValue int_value(42); | 102 base::FundamentalValue int_value(42); |
| 103 | 103 |
| 104 test_dict.SetKey("One", make_scoped_ptr(new RegistryDict()).Pass()); | 104 test_dict.SetKey("One", make_scoped_ptr(new RegistryDict()).Pass()); |
| 105 EXPECT_EQ(1, test_dict.keys().size()); | 105 EXPECT_EQ(1u, 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", scoped_ptr<base::Value>(int_value.DeepCopy())); | 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(1u, 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()); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 268 |
| 269 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); | 269 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); |
| 270 RegistryDict* actual_subdict = test_dict.GetKey("one"); | 270 RegistryDict* actual_subdict = test_dict.GetKey("one"); |
| 271 ASSERT_TRUE(actual_subdict); | 271 ASSERT_TRUE(actual_subdict); |
| 272 EXPECT_TRUE(base::Value::Equals(&string_value, | 272 EXPECT_TRUE(base::Value::Equals(&string_value, |
| 273 actual_subdict->GetValue("two"))); | 273 actual_subdict->GetValue("two"))); |
| 274 } | 274 } |
| 275 | 275 |
| 276 } // namespace | 276 } // namespace |
| 277 } // namespace policy | 277 } // namespace policy |
| OLD | NEW |