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

Side by Side Diff: base/values_unittest.cc

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