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

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

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 years, 9 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
« no previous file with comments | « components/prefs/pref_value_map.cc ('k') | components/prefs/testing_pref_store.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 "components/prefs/pref_value_map.h" 5 #include "components/prefs/pref_value_map.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace base { 11 namespace base {
12 namespace { 12 namespace {
13 13
14 TEST(PrefValueMapTest, SetValue) { 14 TEST(PrefValueMapTest, SetValue) {
15 PrefValueMap map; 15 PrefValueMap map;
16 const Value* result = NULL; 16 const Value* result = NULL;
17 EXPECT_FALSE(map.GetValue("key", &result)); 17 EXPECT_FALSE(map.GetValue("key", &result));
18 EXPECT_FALSE(result); 18 EXPECT_FALSE(result);
19 19
20 EXPECT_TRUE(map.SetValue("key", base::MakeUnique<StringValue>("test"))); 20 EXPECT_TRUE(map.SetValue("key", base::MakeUnique<Value>("test")));
21 EXPECT_FALSE(map.SetValue("key", base::MakeUnique<StringValue>("test"))); 21 EXPECT_FALSE(map.SetValue("key", base::MakeUnique<Value>("test")));
22 EXPECT_TRUE(map.SetValue("key", base::MakeUnique<StringValue>("hi mom!"))); 22 EXPECT_TRUE(map.SetValue("key", base::MakeUnique<Value>("hi mom!")));
23 23
24 EXPECT_TRUE(map.GetValue("key", &result)); 24 EXPECT_TRUE(map.GetValue("key", &result));
25 EXPECT_TRUE(StringValue("hi mom!").Equals(result)); 25 EXPECT_TRUE(Value("hi mom!").Equals(result));
26 } 26 }
27 27
28 TEST(PrefValueMapTest, GetAndSetIntegerValue) { 28 TEST(PrefValueMapTest, GetAndSetIntegerValue) {
29 PrefValueMap map; 29 PrefValueMap map;
30 ASSERT_TRUE(map.SetValue("key", base::MakeUnique<Value>(5))); 30 ASSERT_TRUE(map.SetValue("key", base::MakeUnique<Value>(5)));
31 31
32 int int_value = 0; 32 int int_value = 0;
33 EXPECT_TRUE(map.GetInteger("key", &int_value)); 33 EXPECT_TRUE(map.GetInteger("key", &int_value));
34 EXPECT_EQ(5, int_value); 34 EXPECT_EQ(5, int_value);
35 35
(...skipping 10 matching lines...) Expand all
46 ASSERT_TRUE(map.GetValue("key", &result)); 46 ASSERT_TRUE(map.GetValue("key", &result));
47 double double_value = 0.; 47 double double_value = 0.;
48 EXPECT_TRUE(result->GetAsDouble(&double_value)); 48 EXPECT_TRUE(result->GetAsDouble(&double_value));
49 EXPECT_DOUBLE_EQ(5.5, double_value); 49 EXPECT_DOUBLE_EQ(5.5, double_value);
50 } 50 }
51 51
52 TEST(PrefValueMapTest, RemoveValue) { 52 TEST(PrefValueMapTest, RemoveValue) {
53 PrefValueMap map; 53 PrefValueMap map;
54 EXPECT_FALSE(map.RemoveValue("key")); 54 EXPECT_FALSE(map.RemoveValue("key"));
55 55
56 EXPECT_TRUE(map.SetValue("key", base::MakeUnique<StringValue>("test"))); 56 EXPECT_TRUE(map.SetValue("key", base::MakeUnique<Value>("test")));
57 EXPECT_TRUE(map.GetValue("key", NULL)); 57 EXPECT_TRUE(map.GetValue("key", NULL));
58 58
59 EXPECT_TRUE(map.RemoveValue("key")); 59 EXPECT_TRUE(map.RemoveValue("key"));
60 EXPECT_FALSE(map.GetValue("key", NULL)); 60 EXPECT_FALSE(map.GetValue("key", NULL));
61 61
62 EXPECT_FALSE(map.RemoveValue("key")); 62 EXPECT_FALSE(map.RemoveValue("key"));
63 } 63 }
64 64
65 TEST(PrefValueMapTest, Clear) { 65 TEST(PrefValueMapTest, Clear) {
66 PrefValueMap map; 66 PrefValueMap map;
67 EXPECT_TRUE(map.SetValue("key", base::MakeUnique<StringValue>("test"))); 67 EXPECT_TRUE(map.SetValue("key", base::MakeUnique<Value>("test")));
68 EXPECT_TRUE(map.GetValue("key", NULL)); 68 EXPECT_TRUE(map.GetValue("key", NULL));
69 69
70 map.Clear(); 70 map.Clear();
71 71
72 EXPECT_FALSE(map.GetValue("key", NULL)); 72 EXPECT_FALSE(map.GetValue("key", NULL));
73 } 73 }
74 74
75 TEST(PrefValueMapTest, GetDifferingKeys) { 75 TEST(PrefValueMapTest, GetDifferingKeys) {
76 PrefValueMap reference; 76 PrefValueMap reference;
77 EXPECT_TRUE(reference.SetValue("b", base::MakeUnique<StringValue>("test"))); 77 EXPECT_TRUE(reference.SetValue("b", base::MakeUnique<Value>("test")));
78 EXPECT_TRUE(reference.SetValue("c", base::MakeUnique<StringValue>("test"))); 78 EXPECT_TRUE(reference.SetValue("c", base::MakeUnique<Value>("test")));
79 EXPECT_TRUE(reference.SetValue("e", base::MakeUnique<StringValue>("test"))); 79 EXPECT_TRUE(reference.SetValue("e", base::MakeUnique<Value>("test")));
80 80
81 PrefValueMap check; 81 PrefValueMap check;
82 std::vector<std::string> differing_paths; 82 std::vector<std::string> differing_paths;
83 std::vector<std::string> expected_differing_paths; 83 std::vector<std::string> expected_differing_paths;
84 84
85 reference.GetDifferingKeys(&check, &differing_paths); 85 reference.GetDifferingKeys(&check, &differing_paths);
86 expected_differing_paths.push_back("b"); 86 expected_differing_paths.push_back("b");
87 expected_differing_paths.push_back("c"); 87 expected_differing_paths.push_back("c");
88 expected_differing_paths.push_back("e"); 88 expected_differing_paths.push_back("e");
89 EXPECT_EQ(expected_differing_paths, differing_paths); 89 EXPECT_EQ(expected_differing_paths, differing_paths);
90 90
91 EXPECT_TRUE(check.SetValue("a", base::MakeUnique<StringValue>("test"))); 91 EXPECT_TRUE(check.SetValue("a", base::MakeUnique<Value>("test")));
92 EXPECT_TRUE(check.SetValue("c", base::MakeUnique<StringValue>("test"))); 92 EXPECT_TRUE(check.SetValue("c", base::MakeUnique<Value>("test")));
93 EXPECT_TRUE(check.SetValue("d", base::MakeUnique<StringValue>("test"))); 93 EXPECT_TRUE(check.SetValue("d", base::MakeUnique<Value>("test")));
94 94
95 reference.GetDifferingKeys(&check, &differing_paths); 95 reference.GetDifferingKeys(&check, &differing_paths);
96 expected_differing_paths.clear(); 96 expected_differing_paths.clear();
97 expected_differing_paths.push_back("a"); 97 expected_differing_paths.push_back("a");
98 expected_differing_paths.push_back("b"); 98 expected_differing_paths.push_back("b");
99 expected_differing_paths.push_back("d"); 99 expected_differing_paths.push_back("d");
100 expected_differing_paths.push_back("e"); 100 expected_differing_paths.push_back("e");
101 EXPECT_EQ(expected_differing_paths, differing_paths); 101 EXPECT_EQ(expected_differing_paths, differing_paths);
102 } 102 }
103 103
104 TEST(PrefValueMapTest, SwapTwoMaps) { 104 TEST(PrefValueMapTest, SwapTwoMaps) {
105 PrefValueMap first_map; 105 PrefValueMap first_map;
106 EXPECT_TRUE(first_map.SetValue("a", base::MakeUnique<StringValue>("test"))); 106 EXPECT_TRUE(first_map.SetValue("a", base::MakeUnique<Value>("test")));
107 EXPECT_TRUE(first_map.SetValue("b", base::MakeUnique<StringValue>("test"))); 107 EXPECT_TRUE(first_map.SetValue("b", base::MakeUnique<Value>("test")));
108 EXPECT_TRUE(first_map.SetValue("c", base::MakeUnique<StringValue>("test"))); 108 EXPECT_TRUE(first_map.SetValue("c", base::MakeUnique<Value>("test")));
109 109
110 PrefValueMap second_map; 110 PrefValueMap second_map;
111 EXPECT_TRUE(second_map.SetValue("d", base::MakeUnique<StringValue>("test"))); 111 EXPECT_TRUE(second_map.SetValue("d", base::MakeUnique<Value>("test")));
112 EXPECT_TRUE(second_map.SetValue("e", base::MakeUnique<StringValue>("test"))); 112 EXPECT_TRUE(second_map.SetValue("e", base::MakeUnique<Value>("test")));
113 EXPECT_TRUE(second_map.SetValue("f", base::MakeUnique<StringValue>("test"))); 113 EXPECT_TRUE(second_map.SetValue("f", base::MakeUnique<Value>("test")));
114 114
115 first_map.Swap(&second_map); 115 first_map.Swap(&second_map);
116 116
117 EXPECT_TRUE(first_map.GetValue("d", NULL)); 117 EXPECT_TRUE(first_map.GetValue("d", NULL));
118 EXPECT_TRUE(first_map.GetValue("e", NULL)); 118 EXPECT_TRUE(first_map.GetValue("e", NULL));
119 EXPECT_TRUE(first_map.GetValue("f", NULL)); 119 EXPECT_TRUE(first_map.GetValue("f", NULL));
120 120
121 EXPECT_TRUE(second_map.GetValue("a", NULL)); 121 EXPECT_TRUE(second_map.GetValue("a", NULL));
122 EXPECT_TRUE(second_map.GetValue("b", NULL)); 122 EXPECT_TRUE(second_map.GetValue("b", NULL));
123 EXPECT_TRUE(second_map.GetValue("c", NULL)); 123 EXPECT_TRUE(second_map.GetValue("c", NULL));
124 } 124 }
125 125
126 } // namespace 126 } // namespace
127 } // namespace base 127 } // namespace base
OLDNEW
« no previous file with comments | « components/prefs/pref_value_map.cc ('k') | components/prefs/testing_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698