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

Side by Side Diff: base/values_unittest.cc

Issue 2645073002: Inline FundamentalValue into base::Value (Closed)
Patch Set: Use literals for default initialization. Created 3 years, 11 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 | « base/values.cc ('k') | skia/ext/benchmarking_canvas.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/values.h" 5 #include "base/values.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace base { 18 namespace base {
19 19
20 // Group of tests for the value constructors.
21 TEST(ValuesTest, ConstructBool) {
22 FundamentalValue true_value(true);
23 EXPECT_EQ(Value::Type::BOOLEAN, true_value.type());
24 EXPECT_TRUE(true_value.GetBool());
25
26 FundamentalValue false_value(false);
27 EXPECT_EQ(Value::Type::BOOLEAN, false_value.type());
28 EXPECT_FALSE(false_value.GetBool());
29 }
30
31 TEST(ValuesTest, ConstructInt) {
32 FundamentalValue value(-37);
33 EXPECT_EQ(Value::Type::INTEGER, value.type());
34 EXPECT_EQ(-37, value.GetInt());
35 }
36
37 TEST(ValuesTest, ConstructDouble) {
38 FundamentalValue value(-4.655);
39 EXPECT_EQ(Value::Type::DOUBLE, value.type());
40 EXPECT_EQ(-4.655, value.GetDouble());
41 }
42
43 // Group of tests for the copy constructors and copy-assigmnent. For equality
44 // checks comparisons of the interesting fields are done instead of relying on
45 // Equals being correct.
46 TEST(ValuesTest, CopyBool) {
47 FundamentalValue true_value(true);
48 FundamentalValue copied_true_value(true_value);
49 EXPECT_EQ(true_value.type(), copied_true_value.type());
50 EXPECT_EQ(true_value.GetBool(), copied_true_value.GetBool());
51
52 FundamentalValue false_value(false);
53 FundamentalValue copied_false_value(false_value);
54 EXPECT_EQ(false_value.type(), copied_false_value.type());
55 EXPECT_EQ(false_value.GetBool(), copied_false_value.GetBool());
56
57 Value blank;
58
59 blank = true_value;
60 EXPECT_EQ(true_value.type(), blank.type());
61 EXPECT_EQ(true_value.GetBool(), blank.GetBool());
62
63 blank = false_value;
64 EXPECT_EQ(false_value.type(), blank.type());
65 EXPECT_EQ(false_value.GetBool(), blank.GetBool());
66 }
67
68 TEST(ValuesTest, CopyInt) {
69 FundamentalValue value(74);
70 FundamentalValue copied_value(value);
71 EXPECT_EQ(value.type(), copied_value.type());
72 EXPECT_EQ(value.GetInt(), copied_value.GetInt());
73
74 Value blank;
75
76 blank = value;
77 EXPECT_EQ(value.type(), blank.type());
78 EXPECT_EQ(value.GetInt(), blank.GetInt());
79 }
80
81 TEST(ValuesTest, CopyDouble) {
82 FundamentalValue value(74.896);
83 FundamentalValue copied_value(value);
84 EXPECT_EQ(value.type(), copied_value.type());
85 EXPECT_EQ(value.GetDouble(), copied_value.GetDouble());
86
87 Value blank;
88
89 blank = value;
90 EXPECT_EQ(value.type(), blank.type());
91 EXPECT_EQ(value.GetDouble(), blank.GetDouble());
92 }
93
94 // Group of tests for the move constructors and move-assigmnent.
95 TEST(ValuesTest, MoveBool) {
96 FundamentalValue true_value(true);
97 FundamentalValue moved_true_value(std::move(true_value));
98 EXPECT_EQ(Value::Type::BOOLEAN, moved_true_value.type());
99 EXPECT_TRUE(moved_true_value.GetBool());
100
101 FundamentalValue false_value(false);
102 FundamentalValue moved_false_value(std::move(false_value));
103 EXPECT_EQ(Value::Type::BOOLEAN, moved_false_value.type());
104 EXPECT_FALSE(moved_false_value.GetBool());
105
106 Value blank;
107
108 blank = FundamentalValue(true);
109 EXPECT_EQ(Value::Type::BOOLEAN, blank.type());
110 EXPECT_TRUE(blank.GetBool());
111
112 blank = FundamentalValue(false);
113 EXPECT_EQ(Value::Type::BOOLEAN, blank.type());
114 EXPECT_FALSE(blank.GetBool());
115 }
116
117 TEST(ValuesTest, MoveInt) {
118 FundamentalValue value(74);
119 FundamentalValue moved_value(std::move(value));
120 EXPECT_EQ(Value::Type::INTEGER, moved_value.type());
121 EXPECT_EQ(74, moved_value.GetInt());
122
123 Value blank;
124
125 blank = FundamentalValue(47);
126 EXPECT_EQ(Value::Type::INTEGER, blank.type());
127 EXPECT_EQ(47, blank.GetInt());
128 }
129
130 TEST(ValuesTest, MoveDouble) {
131 FundamentalValue value(74.896);
132 FundamentalValue moved_value(std::move(value));
133 EXPECT_EQ(Value::Type::DOUBLE, moved_value.type());
134 EXPECT_EQ(74.896, moved_value.GetDouble());
135
136 Value blank;
137
138 blank = FundamentalValue(654.38);
139 EXPECT_EQ(Value::Type::DOUBLE, blank.type());
140 EXPECT_EQ(654.38, blank.GetDouble());
141 }
142
20 TEST(ValuesTest, Basic) { 143 TEST(ValuesTest, Basic) {
21 // Test basic dictionary getting/setting 144 // Test basic dictionary getting/setting
22 DictionaryValue settings; 145 DictionaryValue settings;
23 std::string homepage = "http://google.com"; 146 std::string homepage = "http://google.com";
24 ASSERT_FALSE(settings.GetString("global.homepage", &homepage)); 147 ASSERT_FALSE(settings.GetString("global.homepage", &homepage));
25 ASSERT_EQ(std::string("http://google.com"), homepage); 148 ASSERT_EQ(std::string("http://google.com"), homepage);
26 149
27 ASSERT_FALSE(settings.Get("global", NULL)); 150 ASSERT_FALSE(settings.Get("global", NULL));
28 settings.SetBoolean("global", true); 151 settings.SetBoolean("global", true);
29 ASSERT_TRUE(settings.Get("global", NULL)); 152 ASSERT_TRUE(settings.Get("global", NULL));
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 EXPECT_FALSE(main_list.GetList(1, NULL)); 1270 EXPECT_FALSE(main_list.GetList(1, NULL));
1148 EXPECT_FALSE(main_list.GetList(2, NULL)); 1271 EXPECT_FALSE(main_list.GetList(2, NULL));
1149 EXPECT_FALSE(main_list.GetList(3, NULL)); 1272 EXPECT_FALSE(main_list.GetList(3, NULL));
1150 EXPECT_FALSE(main_list.GetList(4, NULL)); 1273 EXPECT_FALSE(main_list.GetList(4, NULL));
1151 EXPECT_FALSE(main_list.GetList(5, NULL)); 1274 EXPECT_FALSE(main_list.GetList(5, NULL));
1152 EXPECT_TRUE(main_list.GetList(6, NULL)); 1275 EXPECT_TRUE(main_list.GetList(6, NULL));
1153 EXPECT_FALSE(main_list.GetList(7, NULL)); 1276 EXPECT_FALSE(main_list.GetList(7, NULL));
1154 } 1277 }
1155 1278
1156 } // namespace base 1279 } // namespace base
OLDNEW
« no previous file with comments | « base/values.cc ('k') | skia/ext/benchmarking_canvas.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698