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

Side by Side Diff: base/values_unittest.cc

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 years, 9 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') | chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.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>
(...skipping 25 matching lines...) Expand all
36 } 36 }
37 37
38 TEST(ValuesTest, ConstructDouble) { 38 TEST(ValuesTest, ConstructDouble) {
39 Value value(-4.655); 39 Value value(-4.655);
40 EXPECT_EQ(Value::Type::DOUBLE, value.type()); 40 EXPECT_EQ(Value::Type::DOUBLE, value.type());
41 EXPECT_EQ(-4.655, value.GetDouble()); 41 EXPECT_EQ(-4.655, value.GetDouble());
42 } 42 }
43 43
44 TEST(ValuesTest, ConstructStringFromConstCharPtr) { 44 TEST(ValuesTest, ConstructStringFromConstCharPtr) {
45 const char* str = "foobar"; 45 const char* str = "foobar";
46 StringValue value(str); 46 Value value(str);
47 EXPECT_EQ(Value::Type::STRING, value.type()); 47 EXPECT_EQ(Value::Type::STRING, value.type());
48 EXPECT_EQ("foobar", value.GetString()); 48 EXPECT_EQ("foobar", value.GetString());
49 } 49 }
50 50
51 TEST(ValuesTest, ConstructStringFromStdStringConstRef) { 51 TEST(ValuesTest, ConstructStringFromStdStringConstRef) {
52 std::string str = "foobar"; 52 std::string str = "foobar";
53 StringValue value(str); 53 Value value(str);
54 EXPECT_EQ(Value::Type::STRING, value.type()); 54 EXPECT_EQ(Value::Type::STRING, value.type());
55 EXPECT_EQ("foobar", value.GetString()); 55 EXPECT_EQ("foobar", value.GetString());
56 } 56 }
57 57
58 TEST(ValuesTest, ConstructStringFromStdStringRefRef) { 58 TEST(ValuesTest, ConstructStringFromStdStringRefRef) {
59 std::string str = "foobar"; 59 std::string str = "foobar";
60 StringValue value(std::move(str)); 60 Value value(std::move(str));
61 EXPECT_EQ(Value::Type::STRING, value.type()); 61 EXPECT_EQ(Value::Type::STRING, value.type());
62 EXPECT_EQ("foobar", value.GetString()); 62 EXPECT_EQ("foobar", value.GetString());
63 } 63 }
64 64
65 TEST(ValuesTest, ConstructStringFromConstChar16Ptr) { 65 TEST(ValuesTest, ConstructStringFromConstChar16Ptr) {
66 string16 str = ASCIIToUTF16("foobar"); 66 string16 str = ASCIIToUTF16("foobar");
67 StringValue value(str.c_str()); 67 Value value(str.c_str());
68 EXPECT_EQ(Value::Type::STRING, value.type()); 68 EXPECT_EQ(Value::Type::STRING, value.type());
69 EXPECT_EQ("foobar", value.GetString()); 69 EXPECT_EQ("foobar", value.GetString());
70 } 70 }
71 71
72 TEST(ValuesTest, ConstructStringFromString16) { 72 TEST(ValuesTest, ConstructStringFromString16) {
73 string16 str = ASCIIToUTF16("foobar"); 73 string16 str = ASCIIToUTF16("foobar");
74 StringValue value(str); 74 Value value(str);
75 EXPECT_EQ(Value::Type::STRING, value.type()); 75 EXPECT_EQ(Value::Type::STRING, value.type());
76 EXPECT_EQ("foobar", value.GetString()); 76 EXPECT_EQ("foobar", value.GetString());
77 } 77 }
78 78
79 TEST(ValuesTest, ConstructStringFromStringPiece) { 79 TEST(ValuesTest, ConstructStringFromStringPiece) {
80 StringPiece str = "foobar"; 80 StringPiece str = "foobar";
81 StringValue value(str); 81 Value value(str);
82 EXPECT_EQ(Value::Type::STRING, value.type()); 82 EXPECT_EQ(Value::Type::STRING, value.type());
83 EXPECT_EQ("foobar", value.GetString()); 83 EXPECT_EQ("foobar", value.GetString());
84 } 84 }
85 85
86 TEST(ValuesTest, ConstructBinary) { 86 TEST(ValuesTest, ConstructBinary) {
87 BinaryValue value(std::vector<char>({0xF, 0x0, 0x0, 0xB, 0xA, 0x2})); 87 BinaryValue value(std::vector<char>({0xF, 0x0, 0x0, 0xB, 0xA, 0x2}));
88 EXPECT_EQ(Value::Type::BINARY, value.type()); 88 EXPECT_EQ(Value::Type::BINARY, value.type());
89 EXPECT_EQ(std::vector<char>({0xF, 0x0, 0x0, 0xB, 0xA, 0x2}), value.GetBlob()); 89 EXPECT_EQ(std::vector<char>({0xF, 0x0, 0x0, 0xB, 0xA, 0x2}), value.GetBlob());
90 } 90 }
91 91
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 EXPECT_EQ(value.GetDouble(), copied_value.GetDouble()); 144 EXPECT_EQ(value.GetDouble(), copied_value.GetDouble());
145 145
146 Value blank; 146 Value blank;
147 147
148 blank = value; 148 blank = value;
149 EXPECT_EQ(value.type(), blank.type()); 149 EXPECT_EQ(value.type(), blank.type());
150 EXPECT_EQ(value.GetDouble(), blank.GetDouble()); 150 EXPECT_EQ(value.GetDouble(), blank.GetDouble());
151 } 151 }
152 152
153 TEST(ValuesTest, CopyString) { 153 TEST(ValuesTest, CopyString) {
154 StringValue value("foobar"); 154 Value value("foobar");
155 StringValue copied_value(value); 155 Value copied_value(value);
156 EXPECT_EQ(value.type(), copied_value.type()); 156 EXPECT_EQ(value.type(), copied_value.type());
157 EXPECT_EQ(value.GetString(), copied_value.GetString()); 157 EXPECT_EQ(value.GetString(), copied_value.GetString());
158 158
159 Value blank; 159 Value blank;
160 160
161 blank = value; 161 blank = value;
162 EXPECT_EQ(value.type(), blank.type()); 162 EXPECT_EQ(value.type(), blank.type());
163 EXPECT_EQ(value.GetString(), blank.GetString()); 163 EXPECT_EQ(value.GetString(), blank.GetString());
164 } 164 }
165 165
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 EXPECT_EQ(74.896, moved_value.GetDouble()); 263 EXPECT_EQ(74.896, moved_value.GetDouble());
264 264
265 Value blank; 265 Value blank;
266 266
267 blank = Value(654.38); 267 blank = Value(654.38);
268 EXPECT_EQ(Value::Type::DOUBLE, blank.type()); 268 EXPECT_EQ(Value::Type::DOUBLE, blank.type());
269 EXPECT_EQ(654.38, blank.GetDouble()); 269 EXPECT_EQ(654.38, blank.GetDouble());
270 } 270 }
271 271
272 TEST(ValuesTest, MoveString) { 272 TEST(ValuesTest, MoveString) {
273 StringValue value("foobar"); 273 Value value("foobar");
274 StringValue moved_value(std::move(value)); 274 Value moved_value(std::move(value));
275 EXPECT_EQ(Value::Type::STRING, moved_value.type()); 275 EXPECT_EQ(Value::Type::STRING, moved_value.type());
276 EXPECT_EQ("foobar", moved_value.GetString()); 276 EXPECT_EQ("foobar", moved_value.GetString());
277 277
278 Value blank; 278 Value blank;
279 279
280 blank = StringValue("foobar"); 280 blank = Value("foobar");
281 EXPECT_EQ(Value::Type::STRING, blank.type()); 281 EXPECT_EQ(Value::Type::STRING, blank.type());
282 EXPECT_EQ("foobar", blank.GetString()); 282 EXPECT_EQ("foobar", blank.GetString());
283 } 283 }
284 284
285 TEST(ValuesTest, MoveBinary) { 285 TEST(ValuesTest, MoveBinary) {
286 const std::vector<char> buffer = {0xF, 0x0, 0x0, 0xB, 0xA, 0x2}; 286 const std::vector<char> buffer = {0xF, 0x0, 0x0, 0xB, 0xA, 0x2};
287 BinaryValue value(buffer); 287 BinaryValue value(buffer);
288 BinaryValue moved_value(std::move(value)); 288 BinaryValue moved_value(std::move(value));
289 EXPECT_EQ(Value::Type::BINARY, moved_value.type()); 289 EXPECT_EQ(Value::Type::BINARY, moved_value.type());
290 EXPECT_EQ(buffer, moved_value.GetBlob()); 290 EXPECT_EQ(buffer, moved_value.GetBlob());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 std::string bookmark_url; 375 std::string bookmark_url;
376 ASSERT_TRUE(bookmark->GetString("url", &bookmark_url)); 376 ASSERT_TRUE(bookmark->GetString("url", &bookmark_url));
377 ASSERT_EQ(std::string("http://froogle.com"), bookmark_url); 377 ASSERT_EQ(std::string("http://froogle.com"), bookmark_url);
378 } 378 }
379 379
380 TEST(ValuesTest, List) { 380 TEST(ValuesTest, List) {
381 std::unique_ptr<ListValue> mixed_list(new ListValue()); 381 std::unique_ptr<ListValue> mixed_list(new ListValue());
382 mixed_list->Set(0, MakeUnique<Value>(true)); 382 mixed_list->Set(0, MakeUnique<Value>(true));
383 mixed_list->Set(1, MakeUnique<Value>(42)); 383 mixed_list->Set(1, MakeUnique<Value>(42));
384 mixed_list->Set(2, MakeUnique<Value>(88.8)); 384 mixed_list->Set(2, MakeUnique<Value>(88.8));
385 mixed_list->Set(3, MakeUnique<StringValue>("foo")); 385 mixed_list->Set(3, MakeUnique<Value>("foo"));
386 ASSERT_EQ(4u, mixed_list->GetSize()); 386 ASSERT_EQ(4u, mixed_list->GetSize());
387 387
388 Value *value = NULL; 388 Value *value = NULL;
389 bool bool_value = false; 389 bool bool_value = false;
390 int int_value = 0; 390 int int_value = 0;
391 double double_value = 0.0; 391 double double_value = 0.0;
392 std::string string_value; 392 std::string string_value;
393 393
394 ASSERT_FALSE(mixed_list->Get(4, &value)); 394 ASSERT_FALSE(mixed_list->Get(4, &value));
395 395
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 452
453 // Test overloaded GetAsBinary. 453 // Test overloaded GetAsBinary.
454 Value* narrow_value = binary.get(); 454 Value* narrow_value = binary.get();
455 const BinaryValue* narrow_binary = NULL; 455 const BinaryValue* narrow_binary = NULL;
456 ASSERT_TRUE(narrow_value->GetAsBinary(&narrow_binary)); 456 ASSERT_TRUE(narrow_value->GetAsBinary(&narrow_binary));
457 EXPECT_EQ(binary.get(), narrow_binary); 457 EXPECT_EQ(binary.get(), narrow_binary);
458 } 458 }
459 459
460 TEST(ValuesTest, StringValue) { 460 TEST(ValuesTest, StringValue) {
461 // Test overloaded StringValue constructor. 461 // Test overloaded StringValue constructor.
462 std::unique_ptr<Value> narrow_value(new StringValue("narrow")); 462 std::unique_ptr<Value> narrow_value(new Value("narrow"));
463 ASSERT_TRUE(narrow_value.get()); 463 ASSERT_TRUE(narrow_value.get());
464 ASSERT_TRUE(narrow_value->IsType(Value::Type::STRING)); 464 ASSERT_TRUE(narrow_value->IsType(Value::Type::STRING));
465 std::unique_ptr<Value> utf16_value(new StringValue(ASCIIToUTF16("utf16"))); 465 std::unique_ptr<Value> utf16_value(new Value(ASCIIToUTF16("utf16")));
466 ASSERT_TRUE(utf16_value.get()); 466 ASSERT_TRUE(utf16_value.get());
467 ASSERT_TRUE(utf16_value->IsType(Value::Type::STRING)); 467 ASSERT_TRUE(utf16_value->IsType(Value::Type::STRING));
468 468
469 // Test overloaded GetAsString. 469 // Test overloaded GetAsString.
470 std::string narrow = "http://google.com"; 470 std::string narrow = "http://google.com";
471 string16 utf16 = ASCIIToUTF16("http://google.com"); 471 string16 utf16 = ASCIIToUTF16("http://google.com");
472 const StringValue* string_value = NULL; 472 const Value* string_value = NULL;
473 ASSERT_TRUE(narrow_value->GetAsString(&narrow)); 473 ASSERT_TRUE(narrow_value->GetAsString(&narrow));
474 ASSERT_TRUE(narrow_value->GetAsString(&utf16)); 474 ASSERT_TRUE(narrow_value->GetAsString(&utf16));
475 ASSERT_TRUE(narrow_value->GetAsString(&string_value)); 475 ASSERT_TRUE(narrow_value->GetAsString(&string_value));
476 ASSERT_EQ(std::string("narrow"), narrow); 476 ASSERT_EQ(std::string("narrow"), narrow);
477 ASSERT_EQ(ASCIIToUTF16("narrow"), utf16); 477 ASSERT_EQ(ASCIIToUTF16("narrow"), utf16);
478 ASSERT_EQ(string_value->GetString(), narrow); 478 ASSERT_EQ(string_value->GetString(), narrow);
479 479
480 ASSERT_TRUE(utf16_value->GetAsString(&narrow)); 480 ASSERT_TRUE(utf16_value->GetAsString(&narrow));
481 ASSERT_TRUE(utf16_value->GetAsString(&utf16)); 481 ASSERT_TRUE(utf16_value->GetAsString(&utf16));
482 ASSERT_TRUE(utf16_value->GetAsString(&string_value)); 482 ASSERT_TRUE(utf16_value->GetAsString(&string_value));
483 ASSERT_EQ(std::string("utf16"), narrow); 483 ASSERT_EQ(std::string("utf16"), narrow);
484 ASSERT_EQ(ASCIIToUTF16("utf16"), utf16); 484 ASSERT_EQ(ASCIIToUTF16("utf16"), utf16);
485 ASSERT_EQ(string_value->GetString(), narrow); 485 ASSERT_EQ(string_value->GetString(), narrow);
486 486
487 // Don't choke on NULL values. 487 // Don't choke on NULL values.
488 ASSERT_TRUE(narrow_value->GetAsString(static_cast<string16*>(NULL))); 488 ASSERT_TRUE(narrow_value->GetAsString(static_cast<string16*>(NULL)));
489 ASSERT_TRUE(narrow_value->GetAsString(static_cast<std::string*>(NULL))); 489 ASSERT_TRUE(narrow_value->GetAsString(static_cast<std::string*>(NULL)));
490 ASSERT_TRUE(narrow_value->GetAsString( 490 ASSERT_TRUE(narrow_value->GetAsString(static_cast<const Value**>(NULL)));
491 static_cast<const StringValue**>(NULL)));
492 } 491 }
493 492
494 TEST(ValuesTest, ListDeletion) { 493 TEST(ValuesTest, ListDeletion) {
495 ListValue list; 494 ListValue list;
496 list.Append(MakeUnique<Value>()); 495 list.Append(MakeUnique<Value>());
497 EXPECT_FALSE(list.empty()); 496 EXPECT_FALSE(list.empty());
498 list.Clear(); 497 list.Clear();
499 EXPECT_TRUE(list.empty()); 498 EXPECT_TRUE(list.empty());
500 } 499 }
501 500
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 original_dict.Set("null", std::move(scoped_null)); 643 original_dict.Set("null", std::move(scoped_null));
645 std::unique_ptr<Value> scoped_bool(new Value(true)); 644 std::unique_ptr<Value> scoped_bool(new Value(true));
646 Value* original_bool = scoped_bool.get(); 645 Value* original_bool = scoped_bool.get();
647 original_dict.Set("bool", std::move(scoped_bool)); 646 original_dict.Set("bool", std::move(scoped_bool));
648 std::unique_ptr<Value> scoped_int(new Value(42)); 647 std::unique_ptr<Value> scoped_int(new Value(42));
649 Value* original_int = scoped_int.get(); 648 Value* original_int = scoped_int.get();
650 original_dict.Set("int", std::move(scoped_int)); 649 original_dict.Set("int", std::move(scoped_int));
651 std::unique_ptr<Value> scoped_double(new Value(3.14)); 650 std::unique_ptr<Value> scoped_double(new Value(3.14));
652 Value* original_double = scoped_double.get(); 651 Value* original_double = scoped_double.get();
653 original_dict.Set("double", std::move(scoped_double)); 652 original_dict.Set("double", std::move(scoped_double));
654 std::unique_ptr<StringValue> scoped_string(new StringValue("hello")); 653 std::unique_ptr<Value> scoped_string(new Value("hello"));
655 StringValue* original_string = scoped_string.get(); 654 Value* original_string = scoped_string.get();
656 original_dict.Set("string", std::move(scoped_string)); 655 original_dict.Set("string", std::move(scoped_string));
657 std::unique_ptr<StringValue> scoped_string16( 656 std::unique_ptr<Value> scoped_string16(new Value(ASCIIToUTF16("hello16")));
658 new StringValue(ASCIIToUTF16("hello16"))); 657 Value* original_string16 = scoped_string16.get();
659 StringValue* original_string16 = scoped_string16.get();
660 original_dict.Set("string16", std::move(scoped_string16)); 658 original_dict.Set("string16", std::move(scoped_string16));
661 659
662 std::vector<char> original_buffer(42, '!'); 660 std::vector<char> original_buffer(42, '!');
663 std::unique_ptr<BinaryValue> scoped_binary( 661 std::unique_ptr<BinaryValue> scoped_binary(
664 new BinaryValue(std::move(original_buffer))); 662 new BinaryValue(std::move(original_buffer)));
665 BinaryValue* original_binary = scoped_binary.get(); 663 BinaryValue* original_binary = scoped_binary.get();
666 original_dict.Set("binary", std::move(scoped_binary)); 664 original_dict.Set("binary", std::move(scoped_binary));
667 665
668 std::unique_ptr<ListValue> scoped_list(new ListValue()); 666 std::unique_ptr<ListValue> scoped_list(new ListValue());
669 Value* original_list = scoped_list.get(); 667 Value* original_list = scoped_list.get();
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 original_dict.Set("null", std::move(scoped_null)); 857 original_dict.Set("null", std::move(scoped_null));
860 std::unique_ptr<Value> scoped_bool(new Value(true)); 858 std::unique_ptr<Value> scoped_bool(new Value(true));
861 Value* original_bool = scoped_bool.get(); 859 Value* original_bool = scoped_bool.get();
862 original_dict.Set("bool", std::move(scoped_bool)); 860 original_dict.Set("bool", std::move(scoped_bool));
863 std::unique_ptr<Value> scoped_int(new Value(42)); 861 std::unique_ptr<Value> scoped_int(new Value(42));
864 Value* original_int = scoped_int.get(); 862 Value* original_int = scoped_int.get();
865 original_dict.Set("int", std::move(scoped_int)); 863 original_dict.Set("int", std::move(scoped_int));
866 std::unique_ptr<Value> scoped_double(new Value(3.14)); 864 std::unique_ptr<Value> scoped_double(new Value(3.14));
867 Value* original_double = scoped_double.get(); 865 Value* original_double = scoped_double.get();
868 original_dict.Set("double", std::move(scoped_double)); 866 original_dict.Set("double", std::move(scoped_double));
869 std::unique_ptr<StringValue> scoped_string(new StringValue("hello")); 867 std::unique_ptr<Value> scoped_string(new Value("hello"));
870 Value* original_string = scoped_string.get(); 868 Value* original_string = scoped_string.get();
871 original_dict.Set("string", std::move(scoped_string)); 869 original_dict.Set("string", std::move(scoped_string));
872 std::unique_ptr<StringValue> scoped_string16( 870 std::unique_ptr<Value> scoped_string16(new Value(ASCIIToUTF16("hello16")));
873 new StringValue(ASCIIToUTF16("hello16")));
874 Value* original_string16 = scoped_string16.get(); 871 Value* original_string16 = scoped_string16.get();
875 original_dict.Set("string16", std::move(scoped_string16)); 872 original_dict.Set("string16", std::move(scoped_string16));
876 873
877 std::vector<char> original_buffer(42, '!'); 874 std::vector<char> original_buffer(42, '!');
878 std::unique_ptr<BinaryValue> scoped_binary( 875 std::unique_ptr<BinaryValue> scoped_binary(
879 new BinaryValue(std::move(original_buffer))); 876 new BinaryValue(std::move(original_buffer)));
880 Value* original_binary = scoped_binary.get(); 877 Value* original_binary = scoped_binary.get();
881 original_dict.Set("binary", std::move(scoped_binary)); 878 original_dict.Set("binary", std::move(scoped_binary));
882 879
883 std::unique_ptr<ListValue> scoped_list(new ListValue()); 880 std::unique_ptr<ListValue> scoped_list(new ListValue());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 inner2->Set("empty_list", WrapUnique(new ListValue)); 962 inner2->Set("empty_list", WrapUnique(new ListValue));
966 root->Set("dict_with_empty_children", std::move(inner2)); 963 root->Set("dict_with_empty_children", std::move(inner2));
967 root = root->DeepCopyWithoutEmptyChildren(); 964 root = root->DeepCopyWithoutEmptyChildren();
968 EXPECT_EQ(2U, root->size()); 965 EXPECT_EQ(2U, root->size());
969 } 966 }
970 967
971 // Make sure nested values don't get pruned. 968 // Make sure nested values don't get pruned.
972 { 969 {
973 std::unique_ptr<ListValue> inner(new ListValue); 970 std::unique_ptr<ListValue> inner(new ListValue);
974 std::unique_ptr<ListValue> inner2(new ListValue); 971 std::unique_ptr<ListValue> inner2(new ListValue);
975 inner2->Append(MakeUnique<StringValue>("hello")); 972 inner2->Append(MakeUnique<Value>("hello"));
976 inner->Append(WrapUnique(new DictionaryValue)); 973 inner->Append(WrapUnique(new DictionaryValue));
977 inner->Append(std::move(inner2)); 974 inner->Append(std::move(inner2));
978 root->Set("list_with_empty_children", std::move(inner)); 975 root->Set("list_with_empty_children", std::move(inner));
979 root = root->DeepCopyWithoutEmptyChildren(); 976 root = root->DeepCopyWithoutEmptyChildren();
980 EXPECT_EQ(3U, root->size()); 977 EXPECT_EQ(3U, root->size());
981 978
982 ListValue* inner_value, *inner_value2; 979 ListValue* inner_value, *inner_value2;
983 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner_value)); 980 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner_value));
984 EXPECT_EQ(1U, inner_value->GetSize()); // Dictionary was pruned. 981 EXPECT_EQ(1U, inner_value->GetSize()); // Dictionary was pruned.
985 EXPECT_TRUE(inner_value->GetList(0, &inner_value2)); 982 EXPECT_TRUE(inner_value->GetList(0, &inner_value2));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 EXPECT_TRUE(ptr->GetString("test", &value)); 1060 EXPECT_TRUE(ptr->GetString("test", &value));
1064 EXPECT_EQ("value", value); 1061 EXPECT_EQ("value", value);
1065 } 1062 }
1066 1063
1067 TEST(ValuesTest, DictionaryIterator) { 1064 TEST(ValuesTest, DictionaryIterator) {
1068 DictionaryValue dict; 1065 DictionaryValue dict;
1069 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { 1066 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
1070 ADD_FAILURE(); 1067 ADD_FAILURE();
1071 } 1068 }
1072 1069
1073 StringValue value1("value1"); 1070 Value value1("value1");
1074 dict.Set("key1", value1.CreateDeepCopy()); 1071 dict.Set("key1", value1.CreateDeepCopy());
1075 bool seen1 = false; 1072 bool seen1 = false;
1076 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { 1073 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
1077 EXPECT_FALSE(seen1); 1074 EXPECT_FALSE(seen1);
1078 EXPECT_EQ("key1", it.key()); 1075 EXPECT_EQ("key1", it.key());
1079 EXPECT_TRUE(value1.Equals(&it.value())); 1076 EXPECT_TRUE(value1.Equals(&it.value()));
1080 seen1 = true; 1077 seen1 = true;
1081 } 1078 }
1082 EXPECT_TRUE(seen1); 1079 EXPECT_TRUE(seen1);
1083 1080
1084 StringValue value2("value2"); 1081 Value value2("value2");
1085 dict.Set("key2", value2.CreateDeepCopy()); 1082 dict.Set("key2", value2.CreateDeepCopy());
1086 bool seen2 = seen1 = false; 1083 bool seen2 = seen1 = false;
1087 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { 1084 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
1088 if (it.key() == "key1") { 1085 if (it.key() == "key1") {
1089 EXPECT_FALSE(seen1); 1086 EXPECT_FALSE(seen1);
1090 EXPECT_TRUE(value1.Equals(&it.value())); 1087 EXPECT_TRUE(value1.Equals(&it.value()));
1091 seen1 = true; 1088 seen1 = true;
1092 } else if (it.key() == "key2") { 1089 } else if (it.key() == "key2") {
1093 EXPECT_FALSE(seen2); 1090 EXPECT_FALSE(seen2);
1094 EXPECT_TRUE(value2.Equals(&it.value())); 1091 EXPECT_TRUE(value2.Equals(&it.value()));
1095 seen2 = true; 1092 seen2 = true;
1096 } else { 1093 } else {
1097 ADD_FAILURE(); 1094 ADD_FAILURE();
1098 } 1095 }
1099 } 1096 }
1100 EXPECT_TRUE(seen1); 1097 EXPECT_TRUE(seen1);
1101 EXPECT_TRUE(seen2); 1098 EXPECT_TRUE(seen2);
1102 } 1099 }
1103 1100
1104 // DictionaryValue/ListValue's Get*() methods should accept NULL as an out-value 1101 // DictionaryValue/ListValue's Get*() methods should accept NULL as an out-value
1105 // and still return true/false based on success. 1102 // and still return true/false based on success.
1106 TEST(ValuesTest, GetWithNullOutValue) { 1103 TEST(ValuesTest, GetWithNullOutValue) {
1107 DictionaryValue main_dict; 1104 DictionaryValue main_dict;
1108 ListValue main_list; 1105 ListValue main_list;
1109 1106
1110 Value bool_value(false); 1107 Value bool_value(false);
1111 Value int_value(1234); 1108 Value int_value(1234);
1112 Value double_value(12.34567); 1109 Value double_value(12.34567);
1113 StringValue string_value("foo"); 1110 Value string_value("foo");
1114 BinaryValue binary_value(Value::Type::BINARY); 1111 BinaryValue binary_value(Value::Type::BINARY);
1115 DictionaryValue dict_value; 1112 DictionaryValue dict_value;
1116 ListValue list_value; 1113 ListValue list_value;
1117 1114
1118 main_dict.Set("bool", bool_value.CreateDeepCopy()); 1115 main_dict.Set("bool", bool_value.CreateDeepCopy());
1119 main_dict.Set("int", int_value.CreateDeepCopy()); 1116 main_dict.Set("int", int_value.CreateDeepCopy());
1120 main_dict.Set("double", double_value.CreateDeepCopy()); 1117 main_dict.Set("double", double_value.CreateDeepCopy());
1121 main_dict.Set("string", string_value.CreateDeepCopy()); 1118 main_dict.Set("string", string_value.CreateDeepCopy());
1122 main_dict.Set("binary", binary_value.CreateDeepCopy()); 1119 main_dict.Set("binary", binary_value.CreateDeepCopy());
1123 main_dict.Set("dict", dict_value.CreateDeepCopy()); 1120 main_dict.Set("dict", dict_value.CreateDeepCopy());
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 EXPECT_FALSE(main_list.GetList(1, NULL)); 1377 EXPECT_FALSE(main_list.GetList(1, NULL));
1381 EXPECT_FALSE(main_list.GetList(2, NULL)); 1378 EXPECT_FALSE(main_list.GetList(2, NULL));
1382 EXPECT_FALSE(main_list.GetList(3, NULL)); 1379 EXPECT_FALSE(main_list.GetList(3, NULL));
1383 EXPECT_FALSE(main_list.GetList(4, NULL)); 1380 EXPECT_FALSE(main_list.GetList(4, NULL));
1384 EXPECT_FALSE(main_list.GetList(5, NULL)); 1381 EXPECT_FALSE(main_list.GetList(5, NULL));
1385 EXPECT_TRUE(main_list.GetList(6, NULL)); 1382 EXPECT_TRUE(main_list.GetList(6, NULL));
1386 EXPECT_FALSE(main_list.GetList(7, NULL)); 1383 EXPECT_FALSE(main_list.GetList(7, NULL));
1387 } 1384 }
1388 1385
1389 } // namespace base 1386 } // namespace base
OLDNEW
« no previous file with comments | « base/values.cc ('k') | chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698