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

Side by Side Diff: base/values_unittest.cc

Issue 2843783003: Expose Value::GetList and Value(ListStorage) on ListValue (Closed)
Patch Set: Created 3 years, 7 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') | no next file » | 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>
(...skipping 17 matching lines...) Expand all
28 static_assert(std::is_nothrow_constructible<Value, std::string&&>::value, 28 static_assert(std::is_nothrow_constructible<Value, std::string&&>::value,
29 "IsNothrowMoveConstructibleFromString"); 29 "IsNothrowMoveConstructibleFromString");
30 static_assert( 30 static_assert(
31 std::is_nothrow_constructible<Value, Value::BlobStorage&&>::value, 31 std::is_nothrow_constructible<Value, Value::BlobStorage&&>::value,
32 "IsNothrowMoveConstructibleFromBlob"); 32 "IsNothrowMoveConstructibleFromBlob");
33 static_assert( 33 static_assert(
34 std::is_nothrow_constructible<Value, Value::ListStorage&&>::value, 34 std::is_nothrow_constructible<Value, Value::ListStorage&&>::value,
35 "IsNothrowMoveConstructibleFromList"); 35 "IsNothrowMoveConstructibleFromList");
36 static_assert(std::is_nothrow_move_assignable<Value>::value, 36 static_assert(std::is_nothrow_move_assignable<Value>::value,
37 "IsNothrowMoveAssignable"); 37 "IsNothrowMoveAssignable");
38 static_assert(
39 std::is_nothrow_constructible<ListValue, Value::ListStorage&&>::value,
40 "ListIsNothrowMoveConstructibleFromList");
38 } 41 }
39 42
40 // Group of tests for the value constructors. 43 // Group of tests for the value constructors.
41 TEST(ValuesTest, ConstructBool) { 44 TEST(ValuesTest, ConstructBool) {
42 Value true_value(true); 45 Value true_value(true);
43 EXPECT_EQ(Value::Type::BOOLEAN, true_value.type()); 46 EXPECT_EQ(Value::Type::BOOLEAN, true_value.type());
44 EXPECT_TRUE(true_value.GetBool()); 47 EXPECT_TRUE(true_value.GetBool());
45 48
46 Value false_value(false); 49 Value false_value(false);
47 EXPECT_EQ(Value::Type::BOOLEAN, false_value.type()); 50 EXPECT_EQ(Value::Type::BOOLEAN, false_value.type());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 TEST(ValuesTest, ConstructDict) { 115 TEST(ValuesTest, ConstructDict) {
113 DictionaryValue value; 116 DictionaryValue value;
114 EXPECT_EQ(Value::Type::DICTIONARY, value.type()); 117 EXPECT_EQ(Value::Type::DICTIONARY, value.type());
115 } 118 }
116 119
117 TEST(ValuesTest, ConstructList) { 120 TEST(ValuesTest, ConstructList) {
118 ListValue value; 121 ListValue value;
119 EXPECT_EQ(Value::Type::LIST, value.type()); 122 EXPECT_EQ(Value::Type::LIST, value.type());
120 } 123 }
121 124
125 TEST(ValuesTest, ConstructListFromStorage) {
126 Value::ListStorage storage;
127 storage.emplace_back("foo");
128
129 {
130 ListValue value(storage);
131 EXPECT_EQ(Value::Type::LIST, value.type());
132 EXPECT_EQ(1u, value.GetList().size());
133 EXPECT_EQ(Value::Type::STRING, value.GetList()[0].type());
134 EXPECT_EQ("foo", value.GetList()[0].GetString());
135 }
136
137 storage.back() = base::Value("bar");
138 {
139 ListValue value(std::move(storage));
140 EXPECT_EQ(Value::Type::LIST, value.type());
141 EXPECT_EQ(1u, value.GetList().size());
142 EXPECT_EQ(Value::Type::STRING, value.GetList()[0].type());
143 EXPECT_EQ("bar", value.GetList()[0].GetString());
144 }
145 }
146
122 // Group of tests for the copy constructors and copy-assigmnent. For equality 147 // Group of tests for the copy constructors and copy-assigmnent. For equality
123 // checks comparisons of the interesting fields are done instead of relying on 148 // checks comparisons of the interesting fields are done instead of relying on
124 // Equals being correct. 149 // Equals being correct.
125 TEST(ValuesTest, CopyBool) { 150 TEST(ValuesTest, CopyBool) {
126 Value true_value(true); 151 Value true_value(true);
127 Value copied_true_value(true_value); 152 Value copied_true_value(true_value);
128 EXPECT_EQ(true_value.type(), copied_true_value.type()); 153 EXPECT_EQ(true_value.type(), copied_true_value.type());
129 EXPECT_EQ(true_value.GetBool(), copied_true_value.GetBool()); 154 EXPECT_EQ(true_value.GetBool(), copied_true_value.GetBool());
130 155
131 Value false_value(false); 156 Value false_value(false);
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 EXPECT_FALSE(main_list.GetList(7, NULL)); 1531 EXPECT_FALSE(main_list.GetList(7, NULL));
1507 } 1532 }
1508 1533
1509 TEST(ValuesTest, SelfSwap) { 1534 TEST(ValuesTest, SelfSwap) {
1510 base::Value test(1); 1535 base::Value test(1);
1511 std::swap(test, test); 1536 std::swap(test, test);
1512 EXPECT_TRUE(test.GetInt() == 1); 1537 EXPECT_TRUE(test.GetInt() == 1);
1513 } 1538 }
1514 1539
1515 } // namespace base 1540 } // namespace base
OLDNEW
« no previous file with comments | « base/values.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698