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

Side by Side Diff: base/values_unittest.cc

Issue 2823233002: Introduce Value::GetList and Value(ListStorage) (Closed)
Patch Set: Created 3 years, 8 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 12 matching lines...) Expand all
23 TEST(ValuesTest, TestNothrow) { 23 TEST(ValuesTest, TestNothrow) {
24 static_assert(std::is_nothrow_move_constructible<Value>::value, 24 static_assert(std::is_nothrow_move_constructible<Value>::value,
25 "IsNothrowMoveConstructible"); 25 "IsNothrowMoveConstructible");
26 static_assert(std::is_nothrow_default_constructible<Value>::value, 26 static_assert(std::is_nothrow_default_constructible<Value>::value,
27 "IsNothrowDefaultConstructible"); 27 "IsNothrowDefaultConstructible");
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(
34 std::is_nothrow_constructible<Value, Value::ListStorage&&>::value,
35 "IsNothrowMoveConstructibleFromList");
33 static_assert(std::is_nothrow_move_assignable<Value>::value, 36 static_assert(std::is_nothrow_move_assignable<Value>::value,
34 "IsNothrowMoveAssignable"); 37 "IsNothrowMoveAssignable");
35 } 38 }
36 39
37 // Group of tests for the value constructors. 40 // Group of tests for the value constructors.
38 TEST(ValuesTest, ConstructBool) { 41 TEST(ValuesTest, ConstructBool) {
39 Value true_value(true); 42 Value true_value(true);
40 EXPECT_EQ(Value::Type::BOOLEAN, true_value.type()); 43 EXPECT_EQ(Value::Type::BOOLEAN, true_value.type());
41 EXPECT_TRUE(true_value.GetBool()); 44 EXPECT_TRUE(true_value.GetBool());
42 45
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 auto blank = MakeUnique<Value>(); 212 auto blank = MakeUnique<Value>();
210 213
211 *blank = value; 214 *blank = value;
212 EXPECT_EQ(Value::Type::DICTIONARY, blank->type()); 215 EXPECT_EQ(Value::Type::DICTIONARY, blank->type());
213 216
214 static_cast<DictionaryValue*>(blank.get())->GetInteger("Int", &copy); 217 static_cast<DictionaryValue*>(blank.get())->GetInteger("Int", &copy);
215 EXPECT_EQ(123, copy); 218 EXPECT_EQ(123, copy);
216 } 219 }
217 220
218 TEST(ValuesTest, CopyList) { 221 TEST(ValuesTest, CopyList) {
219 // TODO(crbug.com/646113): Clean this up once ListValue switched to 222 Value value(Value::ListStorage{Value(123)});
220 // value semantics.
221 int copy;
222 ListValue value;
223 value.AppendInteger(123);
224 223
225 ListValue copied_value(value); 224 Value copied_value(value);
226 copied_value.GetInteger(0, &copy); 225 EXPECT_EQ(value, copied_value);
227 226
228 EXPECT_EQ(value.type(), copied_value.type()); 227 Value blank;
229 EXPECT_EQ(123, copy); 228 blank = value;
230 229 EXPECT_EQ(value, blank);
231 auto blank = MakeUnique<Value>();
232
233 *blank = value;
234 EXPECT_EQ(Value::Type::LIST, blank->type());
235
236 static_cast<ListValue*>(blank.get())->GetInteger(0, &copy);
237 EXPECT_EQ(123, copy);
238 } 230 }
239 231
240 // Group of tests for the move constructors and move-assigmnent. 232 // Group of tests for the move constructors and move-assigmnent.
241 TEST(ValuesTest, MoveBool) { 233 TEST(ValuesTest, MoveBool) {
242 Value true_value(true); 234 Value true_value(true);
243 Value moved_true_value(std::move(true_value)); 235 Value moved_true_value(std::move(true_value));
244 EXPECT_EQ(Value::Type::BOOLEAN, moved_true_value.type()); 236 EXPECT_EQ(Value::Type::BOOLEAN, moved_true_value.type());
245 EXPECT_TRUE(moved_true_value.GetBool()); 237 EXPECT_TRUE(moved_true_value.GetBool());
246 238
247 Value false_value(false); 239 Value false_value(false);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 EXPECT_EQ(Value::Type::DICTIONARY, moved_value.type()); 318 EXPECT_EQ(Value::Type::DICTIONARY, moved_value.type());
327 EXPECT_EQ(123, move); 319 EXPECT_EQ(123, move);
328 320
329 Value blank; 321 Value blank;
330 322
331 blank = DictionaryValue(); 323 blank = DictionaryValue();
332 EXPECT_EQ(Value::Type::DICTIONARY, blank.type()); 324 EXPECT_EQ(Value::Type::DICTIONARY, blank.type());
333 } 325 }
334 326
335 TEST(ValuesTest, MoveList) { 327 TEST(ValuesTest, MoveList) {
336 // TODO(crbug.com/646113): Clean this up once ListValue switched to 328 const Value::ListStorage list = {Value(123)};
337 // value semantics. 329 Value value(list);
338 int move; 330 Value moved_value(std::move(value));
339 ListValue value;
340 value.AppendInteger(123);
341
342 ListValue moved_value(std::move(value));
343 moved_value.GetInteger(0, &move);
344
345 EXPECT_EQ(Value::Type::LIST, moved_value.type()); 331 EXPECT_EQ(Value::Type::LIST, moved_value.type());
346 EXPECT_EQ(123, move); 332 EXPECT_EQ(123, moved_value.GetList().back().GetInt());
347 333
348 Value blank; 334 Value blank;
349 335
350 blank = ListValue(); 336 blank = Value(list);
351 EXPECT_EQ(Value::Type::LIST, blank.type()); 337 EXPECT_EQ(Value::Type::LIST, blank.type());
338 EXPECT_EQ(123, blank.GetList().back().GetInt());
352 } 339 }
353 340
354 TEST(ValuesTest, Basic) { 341 TEST(ValuesTest, Basic) {
355 // Test basic dictionary getting/setting 342 // Test basic dictionary getting/setting
356 DictionaryValue settings; 343 DictionaryValue settings;
357 std::string homepage = "http://google.com"; 344 std::string homepage = "http://google.com";
358 ASSERT_FALSE(settings.GetString("global.homepage", &homepage)); 345 ASSERT_FALSE(settings.GetString("global.homepage", &homepage));
359 ASSERT_EQ(std::string("http://google.com"), homepage); 346 ASSERT_EQ(std::string("http://google.com"), homepage);
360 347
361 ASSERT_FALSE(settings.Get("global", NULL)); 348 ASSERT_FALSE(settings.Get("global", NULL));
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 EXPECT_FALSE(main_list.GetList(7, NULL)); 1505 EXPECT_FALSE(main_list.GetList(7, NULL));
1519 } 1506 }
1520 1507
1521 TEST(ValuesTest, SelfSwap) { 1508 TEST(ValuesTest, SelfSwap) {
1522 base::Value test(1); 1509 base::Value test(1);
1523 std::swap(test, test); 1510 std::swap(test, test);
1524 EXPECT_TRUE(test.GetInt() == 1); 1511 EXPECT_TRUE(test.GetInt() == 1);
1525 } 1512 }
1526 1513
1527 } // namespace base 1514 } // 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