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

Side by Side Diff: chrome/browser/prefs/pref_value_map_unittest.cc

Issue 11243002: Move the bits of Prefs where production code has only trivially easy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments, fix gypi problem Created 8 years, 2 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 | « chrome/browser/prefs/pref_value_map.cc ('k') | chrome/browser/prefs/pref_value_store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/values.h"
6 #include "chrome/browser/prefs/pref_value_map.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 class PrefValueMapTest : public testing::Test {
10 };
11
12 TEST_F(PrefValueMapTest, SetValue) {
13 PrefValueMap map;
14 const Value* result = NULL;
15 EXPECT_FALSE(map.GetValue("key", &result));
16 EXPECT_FALSE(result);
17
18 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test")));
19 EXPECT_FALSE(map.SetValue("key", Value::CreateStringValue("test")));
20 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("hi mom!")));
21
22 EXPECT_TRUE(map.GetValue("key", &result));
23 EXPECT_TRUE(StringValue("hi mom!").Equals(result));
24 }
25
26 TEST_F(PrefValueMapTest, GetAndSetIntegerValue) {
27 PrefValueMap map;
28 ASSERT_TRUE(map.SetValue("key", Value::CreateIntegerValue(5)));
29
30 int int_value = 0;
31 EXPECT_TRUE(map.GetInteger("key", &int_value));
32 EXPECT_EQ(5, int_value);
33
34 map.SetInteger("key", -14);
35 EXPECT_TRUE(map.GetInteger("key", &int_value));
36 EXPECT_EQ(-14, int_value);
37 }
38
39 TEST_F(PrefValueMapTest, RemoveValue) {
40 PrefValueMap map;
41 EXPECT_FALSE(map.RemoveValue("key"));
42
43 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test")));
44 EXPECT_TRUE(map.GetValue("key", NULL));
45
46 EXPECT_TRUE(map.RemoveValue("key"));
47 EXPECT_FALSE(map.GetValue("key", NULL));
48
49 EXPECT_FALSE(map.RemoveValue("key"));
50 }
51
52 TEST_F(PrefValueMapTest, Clear) {
53 PrefValueMap map;
54 EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test")));
55 EXPECT_TRUE(map.GetValue("key", NULL));
56
57 map.Clear();
58
59 EXPECT_FALSE(map.GetValue("key", NULL));
60 }
61
62 TEST_F(PrefValueMapTest, GetDifferingKeys) {
63 PrefValueMap reference;
64 EXPECT_TRUE(reference.SetValue("b", Value::CreateStringValue("test")));
65 EXPECT_TRUE(reference.SetValue("c", Value::CreateStringValue("test")));
66 EXPECT_TRUE(reference.SetValue("e", Value::CreateStringValue("test")));
67
68 PrefValueMap check;
69 std::vector<std::string> differing_paths;
70 std::vector<std::string> expected_differing_paths;
71
72 reference.GetDifferingKeys(&check, &differing_paths);
73 expected_differing_paths.push_back("b");
74 expected_differing_paths.push_back("c");
75 expected_differing_paths.push_back("e");
76 EXPECT_EQ(expected_differing_paths, differing_paths);
77
78 EXPECT_TRUE(check.SetValue("a", Value::CreateStringValue("test")));
79 EXPECT_TRUE(check.SetValue("c", Value::CreateStringValue("test")));
80 EXPECT_TRUE(check.SetValue("d", Value::CreateStringValue("test")));
81
82 reference.GetDifferingKeys(&check, &differing_paths);
83 expected_differing_paths.clear();
84 expected_differing_paths.push_back("a");
85 expected_differing_paths.push_back("b");
86 expected_differing_paths.push_back("d");
87 expected_differing_paths.push_back("e");
88 EXPECT_EQ(expected_differing_paths, differing_paths);
89 }
90
91 TEST_F(PrefValueMapTest, SwapTwoMaps) {
92 PrefValueMap first_map;
93 EXPECT_TRUE(first_map.SetValue("a", Value::CreateStringValue("test")));
94 EXPECT_TRUE(first_map.SetValue("b", Value::CreateStringValue("test")));
95 EXPECT_TRUE(first_map.SetValue("c", Value::CreateStringValue("test")));
96
97 PrefValueMap second_map;
98 EXPECT_TRUE(second_map.SetValue("d", Value::CreateStringValue("test")));
99 EXPECT_TRUE(second_map.SetValue("e", Value::CreateStringValue("test")));
100 EXPECT_TRUE(second_map.SetValue("f", Value::CreateStringValue("test")));
101
102 first_map.Swap(&second_map);
103
104 EXPECT_TRUE(first_map.GetValue("d", NULL));
105 EXPECT_TRUE(first_map.GetValue("e", NULL));
106 EXPECT_TRUE(first_map.GetValue("f", NULL));
107
108 EXPECT_TRUE(second_map.GetValue("a", NULL));
109 EXPECT_TRUE(second_map.GetValue("b", NULL));
110 EXPECT_TRUE(second_map.GetValue("c", NULL));
111 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_value_map.cc ('k') | chrome/browser/prefs/pref_value_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698