Android Credit Card unmasking UI - replace text with progress bar
[chromium-blink-merge.git] / base / values_unittest.cc
blob296880ac6c8db56bddac8e1c77d2c55787812adc
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
3 // found in the LICENSE file.
5 #include <limits>
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace base {
15 TEST(ValuesTest, Basic) {
16 // Test basic dictionary getting/setting
17 DictionaryValue settings;
18 std::string homepage = "http://google.com";
19 ASSERT_FALSE(settings.GetString("global.homepage", &homepage));
20 ASSERT_EQ(std::string("http://google.com"), homepage);
22 ASSERT_FALSE(settings.Get("global", NULL));
23 settings.Set("global", new FundamentalValue(true));
24 ASSERT_TRUE(settings.Get("global", NULL));
25 settings.SetString("global.homepage", "http://scurvy.com");
26 ASSERT_TRUE(settings.Get("global", NULL));
27 homepage = "http://google.com";
28 ASSERT_TRUE(settings.GetString("global.homepage", &homepage));
29 ASSERT_EQ(std::string("http://scurvy.com"), homepage);
31 // Test storing a dictionary in a list.
32 ListValue* toolbar_bookmarks;
33 ASSERT_FALSE(
34 settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks));
36 toolbar_bookmarks = new ListValue;
37 settings.Set("global.toolbar.bookmarks", toolbar_bookmarks);
38 ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks));
40 DictionaryValue* new_bookmark = new DictionaryValue;
41 new_bookmark->SetString("name", "Froogle");
42 new_bookmark->SetString("url", "http://froogle.com");
43 toolbar_bookmarks->Append(new_bookmark);
45 ListValue* bookmark_list;
46 ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &bookmark_list));
47 DictionaryValue* bookmark;
48 ASSERT_EQ(1U, bookmark_list->GetSize());
49 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark));
50 std::string bookmark_name = "Unnamed";
51 ASSERT_TRUE(bookmark->GetString("name", &bookmark_name));
52 ASSERT_EQ(std::string("Froogle"), bookmark_name);
53 std::string bookmark_url;
54 ASSERT_TRUE(bookmark->GetString("url", &bookmark_url));
55 ASSERT_EQ(std::string("http://froogle.com"), bookmark_url);
58 TEST(ValuesTest, List) {
59 scoped_ptr<ListValue> mixed_list(new ListValue());
60 mixed_list->Set(0, new FundamentalValue(true));
61 mixed_list->Set(1, new FundamentalValue(42));
62 mixed_list->Set(2, new FundamentalValue(88.8));
63 mixed_list->Set(3, new StringValue("foo"));
64 ASSERT_EQ(4u, mixed_list->GetSize());
66 Value *value = NULL;
67 bool bool_value = false;
68 int int_value = 0;
69 double double_value = 0.0;
70 std::string string_value;
72 ASSERT_FALSE(mixed_list->Get(4, &value));
74 ASSERT_FALSE(mixed_list->GetInteger(0, &int_value));
75 ASSERT_EQ(0, int_value);
76 ASSERT_FALSE(mixed_list->GetBoolean(1, &bool_value));
77 ASSERT_FALSE(bool_value);
78 ASSERT_FALSE(mixed_list->GetString(2, &string_value));
79 ASSERT_EQ("", string_value);
80 ASSERT_FALSE(mixed_list->GetInteger(2, &int_value));
81 ASSERT_EQ(0, int_value);
82 ASSERT_FALSE(mixed_list->GetBoolean(3, &bool_value));
83 ASSERT_FALSE(bool_value);
85 ASSERT_TRUE(mixed_list->GetBoolean(0, &bool_value));
86 ASSERT_TRUE(bool_value);
87 ASSERT_TRUE(mixed_list->GetInteger(1, &int_value));
88 ASSERT_EQ(42, int_value);
89 // implicit conversion from Integer to Double should be possible.
90 ASSERT_TRUE(mixed_list->GetDouble(1, &double_value));
91 ASSERT_EQ(42, double_value);
92 ASSERT_TRUE(mixed_list->GetDouble(2, &double_value));
93 ASSERT_EQ(88.8, double_value);
94 ASSERT_TRUE(mixed_list->GetString(3, &string_value));
95 ASSERT_EQ("foo", string_value);
97 // Try searching in the mixed list.
98 base::FundamentalValue sought_value(42);
99 base::FundamentalValue not_found_value(false);
101 ASSERT_NE(mixed_list->end(), mixed_list->Find(sought_value));
102 ASSERT_TRUE((*mixed_list->Find(sought_value))->GetAsInteger(&int_value));
103 ASSERT_EQ(42, int_value);
104 ASSERT_EQ(mixed_list->end(), mixed_list->Find(not_found_value));
107 TEST(ValuesTest, BinaryValue) {
108 // Default constructor creates a BinaryValue with a null buffer and size 0.
109 scoped_ptr<BinaryValue> binary(new BinaryValue());
110 ASSERT_TRUE(binary.get());
111 ASSERT_EQ(NULL, binary->GetBuffer());
112 ASSERT_EQ(0U, binary->GetSize());
114 // Test the common case of a non-empty buffer
115 char* buffer = new char[15];
116 binary.reset(new BinaryValue(scoped_ptr<char[]>(buffer), 15));
117 ASSERT_TRUE(binary.get());
118 ASSERT_TRUE(binary->GetBuffer());
119 ASSERT_EQ(buffer, binary->GetBuffer());
120 ASSERT_EQ(15U, binary->GetSize());
122 char stack_buffer[42];
123 memset(stack_buffer, '!', 42);
124 binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42));
125 ASSERT_TRUE(binary.get());
126 ASSERT_TRUE(binary->GetBuffer());
127 ASSERT_NE(stack_buffer, binary->GetBuffer());
128 ASSERT_EQ(42U, binary->GetSize());
129 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize()));
132 TEST(ValuesTest, StringValue) {
133 // Test overloaded StringValue constructor.
134 scoped_ptr<Value> narrow_value(new StringValue("narrow"));
135 ASSERT_TRUE(narrow_value.get());
136 ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING));
137 scoped_ptr<Value> utf16_value(new StringValue(ASCIIToUTF16("utf16")));
138 ASSERT_TRUE(utf16_value.get());
139 ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING));
141 // Test overloaded GetAsString.
142 std::string narrow = "http://google.com";
143 string16 utf16 = ASCIIToUTF16("http://google.com");
144 const StringValue* string_value = NULL;
145 ASSERT_TRUE(narrow_value->GetAsString(&narrow));
146 ASSERT_TRUE(narrow_value->GetAsString(&utf16));
147 ASSERT_TRUE(narrow_value->GetAsString(&string_value));
148 ASSERT_EQ(std::string("narrow"), narrow);
149 ASSERT_EQ(ASCIIToUTF16("narrow"), utf16);
150 ASSERT_EQ(string_value->GetString(), narrow);
152 ASSERT_TRUE(utf16_value->GetAsString(&narrow));
153 ASSERT_TRUE(utf16_value->GetAsString(&utf16));
154 ASSERT_TRUE(utf16_value->GetAsString(&string_value));
155 ASSERT_EQ(std::string("utf16"), narrow);
156 ASSERT_EQ(ASCIIToUTF16("utf16"), utf16);
157 ASSERT_EQ(string_value->GetString(), narrow);
159 // Don't choke on NULL values.
160 ASSERT_TRUE(narrow_value->GetAsString(static_cast<string16*>(NULL)));
161 ASSERT_TRUE(narrow_value->GetAsString(static_cast<std::string*>(NULL)));
162 ASSERT_TRUE(narrow_value->GetAsString(
163 static_cast<const StringValue**>(NULL)));
166 // This is a Value object that allows us to tell if it's been
167 // properly deleted by modifying the value of external flag on destruction.
168 class DeletionTestValue : public Value {
169 public:
170 explicit DeletionTestValue(bool* deletion_flag) : Value(TYPE_NULL) {
171 Init(deletion_flag); // Separate function so that we can use ASSERT_*
174 void Init(bool* deletion_flag) {
175 ASSERT_TRUE(deletion_flag);
176 deletion_flag_ = deletion_flag;
177 *deletion_flag_ = false;
180 ~DeletionTestValue() override { *deletion_flag_ = true; }
182 private:
183 bool* deletion_flag_;
186 TEST(ValuesTest, ListDeletion) {
187 bool deletion_flag = true;
190 ListValue list;
191 list.Append(new DeletionTestValue(&deletion_flag));
192 EXPECT_FALSE(deletion_flag);
194 EXPECT_TRUE(deletion_flag);
197 ListValue list;
198 list.Append(new DeletionTestValue(&deletion_flag));
199 EXPECT_FALSE(deletion_flag);
200 list.Clear();
201 EXPECT_TRUE(deletion_flag);
205 ListValue list;
206 list.Append(new DeletionTestValue(&deletion_flag));
207 EXPECT_FALSE(deletion_flag);
208 EXPECT_TRUE(list.Set(0, Value::CreateNullValue()));
209 EXPECT_TRUE(deletion_flag);
213 TEST(ValuesTest, ListRemoval) {
214 bool deletion_flag = true;
215 scoped_ptr<Value> removed_item;
218 ListValue list;
219 list.Append(new DeletionTestValue(&deletion_flag));
220 EXPECT_FALSE(deletion_flag);
221 EXPECT_EQ(1U, list.GetSize());
222 EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(),
223 &removed_item));
224 EXPECT_FALSE(list.Remove(1, &removed_item));
225 EXPECT_TRUE(list.Remove(0, &removed_item));
226 ASSERT_TRUE(removed_item);
227 EXPECT_EQ(0U, list.GetSize());
229 EXPECT_FALSE(deletion_flag);
230 removed_item.reset();
231 EXPECT_TRUE(deletion_flag);
234 ListValue list;
235 list.Append(new DeletionTestValue(&deletion_flag));
236 EXPECT_FALSE(deletion_flag);
237 EXPECT_TRUE(list.Remove(0, NULL));
238 EXPECT_TRUE(deletion_flag);
239 EXPECT_EQ(0U, list.GetSize());
243 ListValue list;
244 DeletionTestValue* value = new DeletionTestValue(&deletion_flag);
245 list.Append(value);
246 EXPECT_FALSE(deletion_flag);
247 size_t index = 0;
248 list.Remove(*value, &index);
249 EXPECT_EQ(0U, index);
250 EXPECT_TRUE(deletion_flag);
251 EXPECT_EQ(0U, list.GetSize());
255 TEST(ValuesTest, DictionaryDeletion) {
256 std::string key = "test";
257 bool deletion_flag = true;
260 DictionaryValue dict;
261 dict.Set(key, new DeletionTestValue(&deletion_flag));
262 EXPECT_FALSE(deletion_flag);
264 EXPECT_TRUE(deletion_flag);
267 DictionaryValue dict;
268 dict.Set(key, new DeletionTestValue(&deletion_flag));
269 EXPECT_FALSE(deletion_flag);
270 dict.Clear();
271 EXPECT_TRUE(deletion_flag);
275 DictionaryValue dict;
276 dict.Set(key, new DeletionTestValue(&deletion_flag));
277 EXPECT_FALSE(deletion_flag);
278 dict.Set(key, Value::CreateNullValue());
279 EXPECT_TRUE(deletion_flag);
283 TEST(ValuesTest, DictionaryRemoval) {
284 std::string key = "test";
285 bool deletion_flag = true;
286 scoped_ptr<Value> removed_item;
289 DictionaryValue dict;
290 dict.Set(key, new DeletionTestValue(&deletion_flag));
291 EXPECT_FALSE(deletion_flag);
292 EXPECT_TRUE(dict.HasKey(key));
293 EXPECT_FALSE(dict.Remove("absent key", &removed_item));
294 EXPECT_TRUE(dict.Remove(key, &removed_item));
295 EXPECT_FALSE(dict.HasKey(key));
296 ASSERT_TRUE(removed_item);
298 EXPECT_FALSE(deletion_flag);
299 removed_item.reset();
300 EXPECT_TRUE(deletion_flag);
303 DictionaryValue dict;
304 dict.Set(key, new DeletionTestValue(&deletion_flag));
305 EXPECT_FALSE(deletion_flag);
306 EXPECT_TRUE(dict.HasKey(key));
307 EXPECT_TRUE(dict.Remove(key, NULL));
308 EXPECT_TRUE(deletion_flag);
309 EXPECT_FALSE(dict.HasKey(key));
313 TEST(ValuesTest, DictionaryWithoutPathExpansion) {
314 DictionaryValue dict;
315 dict.Set("this.is.expanded", make_scoped_ptr(Value::CreateNullValue()));
316 dict.SetWithoutPathExpansion("this.isnt.expanded",
317 make_scoped_ptr(Value::CreateNullValue()));
319 EXPECT_FALSE(dict.HasKey("this.is.expanded"));
320 EXPECT_TRUE(dict.HasKey("this"));
321 Value* value1;
322 EXPECT_TRUE(dict.Get("this", &value1));
323 DictionaryValue* value2;
324 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2));
325 EXPECT_EQ(value1, value2);
326 EXPECT_EQ(1U, value2->size());
328 EXPECT_TRUE(dict.HasKey("this.isnt.expanded"));
329 Value* value3;
330 EXPECT_FALSE(dict.Get("this.isnt.expanded", &value3));
331 Value* value4;
332 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4));
333 EXPECT_EQ(Value::TYPE_NULL, value4->GetType());
336 // Tests the deprecated version of SetWithoutPathExpansion.
337 // TODO(estade): remove.
338 TEST(ValuesTest, DictionaryWithoutPathExpansionDeprecated) {
339 DictionaryValue dict;
340 dict.Set("this.is.expanded", Value::CreateNullValue());
341 dict.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue());
343 EXPECT_FALSE(dict.HasKey("this.is.expanded"));
344 EXPECT_TRUE(dict.HasKey("this"));
345 Value* value1;
346 EXPECT_TRUE(dict.Get("this", &value1));
347 DictionaryValue* value2;
348 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2));
349 EXPECT_EQ(value1, value2);
350 EXPECT_EQ(1U, value2->size());
352 EXPECT_TRUE(dict.HasKey("this.isnt.expanded"));
353 Value* value3;
354 EXPECT_FALSE(dict.Get("this.isnt.expanded", &value3));
355 Value* value4;
356 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4));
357 EXPECT_EQ(Value::TYPE_NULL, value4->GetType());
360 TEST(ValuesTest, DictionaryRemovePath) {
361 DictionaryValue dict;
362 dict.SetInteger("a.long.way.down", 1);
363 dict.SetBoolean("a.long.key.path", true);
365 scoped_ptr<Value> removed_item;
366 EXPECT_TRUE(dict.RemovePath("a.long.way.down", &removed_item));
367 ASSERT_TRUE(removed_item);
368 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_INTEGER));
369 EXPECT_FALSE(dict.HasKey("a.long.way.down"));
370 EXPECT_FALSE(dict.HasKey("a.long.way"));
371 EXPECT_TRUE(dict.Get("a.long.key.path", NULL));
373 removed_item.reset();
374 EXPECT_FALSE(dict.RemovePath("a.long.way.down", &removed_item));
375 EXPECT_FALSE(removed_item);
376 EXPECT_TRUE(dict.Get("a.long.key.path", NULL));
378 removed_item.reset();
379 EXPECT_TRUE(dict.RemovePath("a.long.key.path", &removed_item));
380 ASSERT_TRUE(removed_item);
381 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_BOOLEAN));
382 EXPECT_TRUE(dict.empty());
385 TEST(ValuesTest, DeepCopy) {
386 DictionaryValue original_dict;
387 Value* original_null = Value::CreateNullValue();
388 original_dict.Set("null", make_scoped_ptr(original_null));
389 FundamentalValue* original_bool = new FundamentalValue(true);
390 original_dict.Set("bool", make_scoped_ptr(original_bool));
391 FundamentalValue* original_int = new FundamentalValue(42);
392 original_dict.Set("int", make_scoped_ptr(original_int));
393 FundamentalValue* original_double = new FundamentalValue(3.14);
394 original_dict.Set("double", make_scoped_ptr(original_double));
395 StringValue* original_string = new StringValue("hello");
396 original_dict.Set("string", make_scoped_ptr(original_string));
397 StringValue* original_string16 = new StringValue(ASCIIToUTF16("hello16"));
398 original_dict.Set("string16", make_scoped_ptr(original_string16));
400 scoped_ptr<char[]> original_buffer(new char[42]);
401 memset(original_buffer.get(), '!', 42);
402 BinaryValue* original_binary = new BinaryValue(original_buffer.Pass(), 42);
403 original_dict.Set("binary", original_binary);
405 ListValue* original_list = new ListValue();
406 FundamentalValue* original_list_element_0 = new FundamentalValue(0);
407 original_list->Append(original_list_element_0);
408 FundamentalValue* original_list_element_1 = new FundamentalValue(1);
409 original_list->Append(original_list_element_1);
410 original_dict.Set("list", make_scoped_ptr(original_list));
412 DictionaryValue* original_nested_dictionary = new DictionaryValue();
413 original_nested_dictionary->SetString("key", "value");
414 original_dict.Set("dictionary", make_scoped_ptr(original_nested_dictionary));
416 scoped_ptr<DictionaryValue> copy_dict(original_dict.DeepCopy());
417 ASSERT_TRUE(copy_dict.get());
418 ASSERT_NE(copy_dict.get(), &original_dict);
420 Value* copy_null = NULL;
421 ASSERT_TRUE(copy_dict->Get("null", &copy_null));
422 ASSERT_TRUE(copy_null);
423 ASSERT_NE(copy_null, original_null);
424 ASSERT_TRUE(copy_null->IsType(Value::TYPE_NULL));
426 Value* copy_bool = NULL;
427 ASSERT_TRUE(copy_dict->Get("bool", &copy_bool));
428 ASSERT_TRUE(copy_bool);
429 ASSERT_NE(copy_bool, original_bool);
430 ASSERT_TRUE(copy_bool->IsType(Value::TYPE_BOOLEAN));
431 bool copy_bool_value = false;
432 ASSERT_TRUE(copy_bool->GetAsBoolean(&copy_bool_value));
433 ASSERT_TRUE(copy_bool_value);
435 Value* copy_int = NULL;
436 ASSERT_TRUE(copy_dict->Get("int", &copy_int));
437 ASSERT_TRUE(copy_int);
438 ASSERT_NE(copy_int, original_int);
439 ASSERT_TRUE(copy_int->IsType(Value::TYPE_INTEGER));
440 int copy_int_value = 0;
441 ASSERT_TRUE(copy_int->GetAsInteger(&copy_int_value));
442 ASSERT_EQ(42, copy_int_value);
444 Value* copy_double = NULL;
445 ASSERT_TRUE(copy_dict->Get("double", &copy_double));
446 ASSERT_TRUE(copy_double);
447 ASSERT_NE(copy_double, original_double);
448 ASSERT_TRUE(copy_double->IsType(Value::TYPE_DOUBLE));
449 double copy_double_value = 0;
450 ASSERT_TRUE(copy_double->GetAsDouble(&copy_double_value));
451 ASSERT_EQ(3.14, copy_double_value);
453 Value* copy_string = NULL;
454 ASSERT_TRUE(copy_dict->Get("string", &copy_string));
455 ASSERT_TRUE(copy_string);
456 ASSERT_NE(copy_string, original_string);
457 ASSERT_TRUE(copy_string->IsType(Value::TYPE_STRING));
458 std::string copy_string_value;
459 string16 copy_string16_value;
460 ASSERT_TRUE(copy_string->GetAsString(&copy_string_value));
461 ASSERT_TRUE(copy_string->GetAsString(&copy_string16_value));
462 ASSERT_EQ(std::string("hello"), copy_string_value);
463 ASSERT_EQ(ASCIIToUTF16("hello"), copy_string16_value);
465 Value* copy_string16 = NULL;
466 ASSERT_TRUE(copy_dict->Get("string16", &copy_string16));
467 ASSERT_TRUE(copy_string16);
468 ASSERT_NE(copy_string16, original_string16);
469 ASSERT_TRUE(copy_string16->IsType(Value::TYPE_STRING));
470 ASSERT_TRUE(copy_string16->GetAsString(&copy_string_value));
471 ASSERT_TRUE(copy_string16->GetAsString(&copy_string16_value));
472 ASSERT_EQ(std::string("hello16"), copy_string_value);
473 ASSERT_EQ(ASCIIToUTF16("hello16"), copy_string16_value);
475 Value* copy_binary = NULL;
476 ASSERT_TRUE(copy_dict->Get("binary", &copy_binary));
477 ASSERT_TRUE(copy_binary);
478 ASSERT_NE(copy_binary, original_binary);
479 ASSERT_TRUE(copy_binary->IsType(Value::TYPE_BINARY));
480 ASSERT_NE(original_binary->GetBuffer(),
481 static_cast<BinaryValue*>(copy_binary)->GetBuffer());
482 ASSERT_EQ(original_binary->GetSize(),
483 static_cast<BinaryValue*>(copy_binary)->GetSize());
484 ASSERT_EQ(0, memcmp(original_binary->GetBuffer(),
485 static_cast<BinaryValue*>(copy_binary)->GetBuffer(),
486 original_binary->GetSize()));
488 Value* copy_value = NULL;
489 ASSERT_TRUE(copy_dict->Get("list", &copy_value));
490 ASSERT_TRUE(copy_value);
491 ASSERT_NE(copy_value, original_list);
492 ASSERT_TRUE(copy_value->IsType(Value::TYPE_LIST));
493 ListValue* copy_list = NULL;
494 ASSERT_TRUE(copy_value->GetAsList(&copy_list));
495 ASSERT_TRUE(copy_list);
496 ASSERT_EQ(2U, copy_list->GetSize());
498 Value* copy_list_element_0;
499 ASSERT_TRUE(copy_list->Get(0, &copy_list_element_0));
500 ASSERT_TRUE(copy_list_element_0);
501 ASSERT_NE(copy_list_element_0, original_list_element_0);
502 int copy_list_element_0_value;
503 ASSERT_TRUE(copy_list_element_0->GetAsInteger(&copy_list_element_0_value));
504 ASSERT_EQ(0, copy_list_element_0_value);
506 Value* copy_list_element_1;
507 ASSERT_TRUE(copy_list->Get(1, &copy_list_element_1));
508 ASSERT_TRUE(copy_list_element_1);
509 ASSERT_NE(copy_list_element_1, original_list_element_1);
510 int copy_list_element_1_value;
511 ASSERT_TRUE(copy_list_element_1->GetAsInteger(&copy_list_element_1_value));
512 ASSERT_EQ(1, copy_list_element_1_value);
514 copy_value = NULL;
515 ASSERT_TRUE(copy_dict->Get("dictionary", &copy_value));
516 ASSERT_TRUE(copy_value);
517 ASSERT_NE(copy_value, original_nested_dictionary);
518 ASSERT_TRUE(copy_value->IsType(Value::TYPE_DICTIONARY));
519 DictionaryValue* copy_nested_dictionary = NULL;
520 ASSERT_TRUE(copy_value->GetAsDictionary(&copy_nested_dictionary));
521 ASSERT_TRUE(copy_nested_dictionary);
522 EXPECT_TRUE(copy_nested_dictionary->HasKey("key"));
525 TEST(ValuesTest, Equals) {
526 Value* null1 = Value::CreateNullValue();
527 Value* null2 = Value::CreateNullValue();
528 EXPECT_NE(null1, null2);
529 EXPECT_TRUE(null1->Equals(null2));
531 Value* boolean = new FundamentalValue(false);
532 EXPECT_FALSE(null1->Equals(boolean));
533 delete null1;
534 delete null2;
535 delete boolean;
537 DictionaryValue dv;
538 dv.SetBoolean("a", false);
539 dv.SetInteger("b", 2);
540 dv.SetDouble("c", 2.5);
541 dv.SetString("d1", "string");
542 dv.SetString("d2", ASCIIToUTF16("http://google.com"));
543 dv.Set("e", make_scoped_ptr(Value::CreateNullValue()));
545 scoped_ptr<DictionaryValue> copy;
546 copy.reset(dv.DeepCopy());
547 EXPECT_TRUE(dv.Equals(copy.get()));
549 ListValue* list = new ListValue;
550 list->Append(Value::CreateNullValue());
551 list->Append(new DictionaryValue);
552 dv.Set("f", make_scoped_ptr(list));
554 EXPECT_FALSE(dv.Equals(copy.get()));
555 copy->Set("f", list->DeepCopy());
556 EXPECT_TRUE(dv.Equals(copy.get()));
558 list->Append(new FundamentalValue(true));
559 EXPECT_FALSE(dv.Equals(copy.get()));
561 // Check if Equals detects differences in only the keys.
562 copy.reset(dv.DeepCopy());
563 EXPECT_TRUE(dv.Equals(copy.get()));
564 copy->Remove("a", NULL);
565 copy->SetBoolean("aa", false);
566 EXPECT_FALSE(dv.Equals(copy.get()));
569 TEST(ValuesTest, StaticEquals) {
570 scoped_ptr<Value> null1(Value::CreateNullValue());
571 scoped_ptr<Value> null2(Value::CreateNullValue());
572 EXPECT_TRUE(Value::Equals(null1.get(), null2.get()));
573 EXPECT_TRUE(Value::Equals(NULL, NULL));
575 scoped_ptr<Value> i42(new FundamentalValue(42));
576 scoped_ptr<Value> j42(new FundamentalValue(42));
577 scoped_ptr<Value> i17(new FundamentalValue(17));
578 EXPECT_TRUE(Value::Equals(i42.get(), i42.get()));
579 EXPECT_TRUE(Value::Equals(j42.get(), i42.get()));
580 EXPECT_TRUE(Value::Equals(i42.get(), j42.get()));
581 EXPECT_FALSE(Value::Equals(i42.get(), i17.get()));
582 EXPECT_FALSE(Value::Equals(i42.get(), NULL));
583 EXPECT_FALSE(Value::Equals(NULL, i42.get()));
585 // NULL and Value::CreateNullValue() are intentionally different: We need
586 // support for NULL as a return value for "undefined" without caring for
587 // ownership of the pointer.
588 EXPECT_FALSE(Value::Equals(null1.get(), NULL));
589 EXPECT_FALSE(Value::Equals(NULL, null1.get()));
592 TEST(ValuesTest, DeepCopyCovariantReturnTypes) {
593 DictionaryValue original_dict;
594 Value* original_null = Value::CreateNullValue();
595 original_dict.Set("null", original_null);
596 FundamentalValue* original_bool = new FundamentalValue(true);
597 original_dict.Set("bool", original_bool);
598 FundamentalValue* original_int = new FundamentalValue(42);
599 original_dict.Set("int", original_int);
600 FundamentalValue* original_double = new FundamentalValue(3.14);
601 original_dict.Set("double", original_double);
602 StringValue* original_string = new StringValue("hello");
603 original_dict.Set("string", original_string);
604 StringValue* original_string16 = new StringValue(ASCIIToUTF16("hello16"));
605 original_dict.Set("string16", original_string16);
607 scoped_ptr<char[]> original_buffer(new char[42]);
608 memset(original_buffer.get(), '!', 42);
609 BinaryValue* original_binary = new BinaryValue(original_buffer.Pass(), 42);
610 original_dict.Set("binary", original_binary);
612 ListValue* original_list = new ListValue();
613 FundamentalValue* original_list_element_0 = new FundamentalValue(0);
614 original_list->Append(original_list_element_0);
615 FundamentalValue* original_list_element_1 = new FundamentalValue(1);
616 original_list->Append(original_list_element_1);
617 original_dict.Set("list", original_list);
619 Value* original_dict_value = &original_dict;
620 Value* original_bool_value = original_bool;
621 Value* original_int_value = original_int;
622 Value* original_double_value = original_double;
623 Value* original_string_value = original_string;
624 Value* original_string16_value = original_string16;
625 Value* original_binary_value = original_binary;
626 Value* original_list_value = original_list;
628 scoped_ptr<Value> copy_dict_value(original_dict_value->DeepCopy());
629 scoped_ptr<Value> copy_bool_value(original_bool_value->DeepCopy());
630 scoped_ptr<Value> copy_int_value(original_int_value->DeepCopy());
631 scoped_ptr<Value> copy_double_value(original_double_value->DeepCopy());
632 scoped_ptr<Value> copy_string_value(original_string_value->DeepCopy());
633 scoped_ptr<Value> copy_string16_value(original_string16_value->DeepCopy());
634 scoped_ptr<Value> copy_binary_value(original_binary_value->DeepCopy());
635 scoped_ptr<Value> copy_list_value(original_list_value->DeepCopy());
637 EXPECT_TRUE(original_dict_value->Equals(copy_dict_value.get()));
638 EXPECT_TRUE(original_bool_value->Equals(copy_bool_value.get()));
639 EXPECT_TRUE(original_int_value->Equals(copy_int_value.get()));
640 EXPECT_TRUE(original_double_value->Equals(copy_double_value.get()));
641 EXPECT_TRUE(original_string_value->Equals(copy_string_value.get()));
642 EXPECT_TRUE(original_string16_value->Equals(copy_string16_value.get()));
643 EXPECT_TRUE(original_binary_value->Equals(copy_binary_value.get()));
644 EXPECT_TRUE(original_list_value->Equals(copy_list_value.get()));
647 TEST(ValuesTest, RemoveEmptyChildren) {
648 scoped_ptr<DictionaryValue> root(new DictionaryValue);
649 // Remove empty lists and dictionaries.
650 root->Set("empty_dict", make_scoped_ptr(new DictionaryValue));
651 root->Set("empty_list", make_scoped_ptr(new ListValue));
652 root->SetWithoutPathExpansion("a.b.c.d.e",
653 make_scoped_ptr(new DictionaryValue));
654 root.reset(root->DeepCopyWithoutEmptyChildren());
655 EXPECT_TRUE(root->empty());
657 // Make sure we don't prune too much.
658 root->SetBoolean("bool", true);
659 root->Set("empty_dict", new DictionaryValue);
660 root->SetString("empty_string", std::string());
661 root.reset(root->DeepCopyWithoutEmptyChildren());
662 EXPECT_EQ(2U, root->size());
664 // Should do nothing.
665 root.reset(root->DeepCopyWithoutEmptyChildren());
666 EXPECT_EQ(2U, root->size());
668 // Nested test cases. These should all reduce back to the bool and string
669 // set above.
671 root->Set("a.b.c.d.e", new DictionaryValue);
672 root.reset(root->DeepCopyWithoutEmptyChildren());
673 EXPECT_EQ(2U, root->size());
676 DictionaryValue* inner = new DictionaryValue;
677 root->Set("dict_with_emtpy_children", inner);
678 inner->Set("empty_dict", new DictionaryValue);
679 inner->Set("empty_list", new ListValue);
680 root.reset(root->DeepCopyWithoutEmptyChildren());
681 EXPECT_EQ(2U, root->size());
684 ListValue* inner = new ListValue;
685 root->Set("list_with_empty_children", inner);
686 inner->Append(new DictionaryValue);
687 inner->Append(new ListValue);
688 root.reset(root->DeepCopyWithoutEmptyChildren());
689 EXPECT_EQ(2U, root->size());
692 // Nested with siblings.
694 ListValue* inner = new ListValue;
695 root->Set("list_with_empty_children", inner);
696 inner->Append(new DictionaryValue);
697 inner->Append(new ListValue);
698 DictionaryValue* inner2 = new DictionaryValue;
699 root->Set("dict_with_empty_children", inner2);
700 inner2->Set("empty_dict", new DictionaryValue);
701 inner2->Set("empty_list", new ListValue);
702 root.reset(root->DeepCopyWithoutEmptyChildren());
703 EXPECT_EQ(2U, root->size());
706 // Make sure nested values don't get pruned.
708 ListValue* inner = new ListValue;
709 root->Set("list_with_empty_children", inner);
710 ListValue* inner2 = new ListValue;
711 inner->Append(new DictionaryValue);
712 inner->Append(inner2);
713 inner2->Append(new StringValue("hello"));
714 root.reset(root->DeepCopyWithoutEmptyChildren());
715 EXPECT_EQ(3U, root->size());
716 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner));
717 EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned.
718 EXPECT_TRUE(inner->GetList(0, &inner2));
719 EXPECT_EQ(1U, inner2->GetSize());
723 TEST(ValuesTest, MergeDictionary) {
724 scoped_ptr<DictionaryValue> base(new DictionaryValue);
725 base->SetString("base_key", "base_key_value_base");
726 base->SetString("collide_key", "collide_key_value_base");
727 DictionaryValue* base_sub_dict = new DictionaryValue;
728 base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base");
729 base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base");
730 base->Set("sub_dict_key", base_sub_dict);
732 scoped_ptr<DictionaryValue> merge(new DictionaryValue);
733 merge->SetString("merge_key", "merge_key_value_merge");
734 merge->SetString("collide_key", "collide_key_value_merge");
735 DictionaryValue* merge_sub_dict = new DictionaryValue;
736 merge_sub_dict->SetString("sub_merge_key", "sub_merge_key_value_merge");
737 merge_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_merge");
738 merge->Set("sub_dict_key", merge_sub_dict);
740 base->MergeDictionary(merge.get());
742 EXPECT_EQ(4U, base->size());
743 std::string base_key_value;
744 EXPECT_TRUE(base->GetString("base_key", &base_key_value));
745 EXPECT_EQ("base_key_value_base", base_key_value); // Base value preserved.
746 std::string collide_key_value;
747 EXPECT_TRUE(base->GetString("collide_key", &collide_key_value));
748 EXPECT_EQ("collide_key_value_merge", collide_key_value); // Replaced.
749 std::string merge_key_value;
750 EXPECT_TRUE(base->GetString("merge_key", &merge_key_value));
751 EXPECT_EQ("merge_key_value_merge", merge_key_value); // Merged in.
753 DictionaryValue* res_sub_dict;
754 EXPECT_TRUE(base->GetDictionary("sub_dict_key", &res_sub_dict));
755 EXPECT_EQ(3U, res_sub_dict->size());
756 std::string sub_base_key_value;
757 EXPECT_TRUE(res_sub_dict->GetString("sub_base_key", &sub_base_key_value));
758 EXPECT_EQ("sub_base_key_value_base", sub_base_key_value); // Preserved.
759 std::string sub_collide_key_value;
760 EXPECT_TRUE(res_sub_dict->GetString("sub_collide_key",
761 &sub_collide_key_value));
762 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced.
763 std::string sub_merge_key_value;
764 EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value));
765 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in.
768 TEST(ValuesTest, MergeDictionaryDeepCopy) {
769 DictionaryValue* child = new DictionaryValue;
770 child->SetString("test", "value");
771 EXPECT_EQ(1U, child->size());
773 std::string value;
774 EXPECT_TRUE(child->GetString("test", &value));
775 EXPECT_EQ("value", value);
777 scoped_ptr<DictionaryValue> base(new DictionaryValue);
778 base->Set("dict", child);
779 EXPECT_EQ(1U, base->size());
781 DictionaryValue* ptr;
782 EXPECT_TRUE(base->GetDictionary("dict", &ptr));
783 EXPECT_EQ(child, ptr);
785 scoped_ptr<DictionaryValue> merged(new DictionaryValue);
786 merged->MergeDictionary(base.get());
787 EXPECT_EQ(1U, merged->size());
788 EXPECT_TRUE(merged->GetDictionary("dict", &ptr));
789 EXPECT_NE(child, ptr);
790 EXPECT_TRUE(ptr->GetString("test", &value));
791 EXPECT_EQ("value", value);
793 child->SetString("test", "overwrite");
794 base.reset();
795 EXPECT_TRUE(ptr->GetString("test", &value));
796 EXPECT_EQ("value", value);
799 TEST(ValuesTest, DictionaryIterator) {
800 DictionaryValue dict;
801 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
802 ADD_FAILURE();
805 StringValue value1("value1");
806 dict.Set("key1", value1.DeepCopy());
807 bool seen1 = false;
808 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
809 EXPECT_FALSE(seen1);
810 EXPECT_EQ("key1", it.key());
811 EXPECT_TRUE(value1.Equals(&it.value()));
812 seen1 = true;
814 EXPECT_TRUE(seen1);
816 StringValue value2("value2");
817 dict.Set("key2", value2.DeepCopy());
818 bool seen2 = seen1 = false;
819 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
820 if (it.key() == "key1") {
821 EXPECT_FALSE(seen1);
822 EXPECT_TRUE(value1.Equals(&it.value()));
823 seen1 = true;
824 } else if (it.key() == "key2") {
825 EXPECT_FALSE(seen2);
826 EXPECT_TRUE(value2.Equals(&it.value()));
827 seen2 = true;
828 } else {
829 ADD_FAILURE();
832 EXPECT_TRUE(seen1);
833 EXPECT_TRUE(seen2);
836 // DictionaryValue/ListValue's Get*() methods should accept NULL as an out-value
837 // and still return true/false based on success.
838 TEST(ValuesTest, GetWithNullOutValue) {
839 DictionaryValue main_dict;
840 ListValue main_list;
842 FundamentalValue bool_value(false);
843 FundamentalValue int_value(1234);
844 FundamentalValue double_value(12.34567);
845 StringValue string_value("foo");
846 BinaryValue binary_value;
847 DictionaryValue dict_value;
848 ListValue list_value;
850 main_dict.Set("bool", bool_value.DeepCopy());
851 main_dict.Set("int", int_value.DeepCopy());
852 main_dict.Set("double", double_value.DeepCopy());
853 main_dict.Set("string", string_value.DeepCopy());
854 main_dict.Set("binary", binary_value.DeepCopy());
855 main_dict.Set("dict", dict_value.DeepCopy());
856 main_dict.Set("list", list_value.DeepCopy());
858 main_list.Append(bool_value.DeepCopy());
859 main_list.Append(int_value.DeepCopy());
860 main_list.Append(double_value.DeepCopy());
861 main_list.Append(string_value.DeepCopy());
862 main_list.Append(binary_value.DeepCopy());
863 main_list.Append(dict_value.DeepCopy());
864 main_list.Append(list_value.DeepCopy());
866 EXPECT_TRUE(main_dict.Get("bool", NULL));
867 EXPECT_TRUE(main_dict.Get("int", NULL));
868 EXPECT_TRUE(main_dict.Get("double", NULL));
869 EXPECT_TRUE(main_dict.Get("string", NULL));
870 EXPECT_TRUE(main_dict.Get("binary", NULL));
871 EXPECT_TRUE(main_dict.Get("dict", NULL));
872 EXPECT_TRUE(main_dict.Get("list", NULL));
873 EXPECT_FALSE(main_dict.Get("DNE", NULL));
875 EXPECT_TRUE(main_dict.GetBoolean("bool", NULL));
876 EXPECT_FALSE(main_dict.GetBoolean("int", NULL));
877 EXPECT_FALSE(main_dict.GetBoolean("double", NULL));
878 EXPECT_FALSE(main_dict.GetBoolean("string", NULL));
879 EXPECT_FALSE(main_dict.GetBoolean("binary", NULL));
880 EXPECT_FALSE(main_dict.GetBoolean("dict", NULL));
881 EXPECT_FALSE(main_dict.GetBoolean("list", NULL));
882 EXPECT_FALSE(main_dict.GetBoolean("DNE", NULL));
884 EXPECT_FALSE(main_dict.GetInteger("bool", NULL));
885 EXPECT_TRUE(main_dict.GetInteger("int", NULL));
886 EXPECT_FALSE(main_dict.GetInteger("double", NULL));
887 EXPECT_FALSE(main_dict.GetInteger("string", NULL));
888 EXPECT_FALSE(main_dict.GetInteger("binary", NULL));
889 EXPECT_FALSE(main_dict.GetInteger("dict", NULL));
890 EXPECT_FALSE(main_dict.GetInteger("list", NULL));
891 EXPECT_FALSE(main_dict.GetInteger("DNE", NULL));
893 // Both int and double values can be obtained from GetDouble.
894 EXPECT_FALSE(main_dict.GetDouble("bool", NULL));
895 EXPECT_TRUE(main_dict.GetDouble("int", NULL));
896 EXPECT_TRUE(main_dict.GetDouble("double", NULL));
897 EXPECT_FALSE(main_dict.GetDouble("string", NULL));
898 EXPECT_FALSE(main_dict.GetDouble("binary", NULL));
899 EXPECT_FALSE(main_dict.GetDouble("dict", NULL));
900 EXPECT_FALSE(main_dict.GetDouble("list", NULL));
901 EXPECT_FALSE(main_dict.GetDouble("DNE", NULL));
903 EXPECT_FALSE(main_dict.GetString("bool", static_cast<std::string*>(NULL)));
904 EXPECT_FALSE(main_dict.GetString("int", static_cast<std::string*>(NULL)));
905 EXPECT_FALSE(main_dict.GetString("double", static_cast<std::string*>(NULL)));
906 EXPECT_TRUE(main_dict.GetString("string", static_cast<std::string*>(NULL)));
907 EXPECT_FALSE(main_dict.GetString("binary", static_cast<std::string*>(NULL)));
908 EXPECT_FALSE(main_dict.GetString("dict", static_cast<std::string*>(NULL)));
909 EXPECT_FALSE(main_dict.GetString("list", static_cast<std::string*>(NULL)));
910 EXPECT_FALSE(main_dict.GetString("DNE", static_cast<std::string*>(NULL)));
912 EXPECT_FALSE(main_dict.GetString("bool", static_cast<string16*>(NULL)));
913 EXPECT_FALSE(main_dict.GetString("int", static_cast<string16*>(NULL)));
914 EXPECT_FALSE(main_dict.GetString("double", static_cast<string16*>(NULL)));
915 EXPECT_TRUE(main_dict.GetString("string", static_cast<string16*>(NULL)));
916 EXPECT_FALSE(main_dict.GetString("binary", static_cast<string16*>(NULL)));
917 EXPECT_FALSE(main_dict.GetString("dict", static_cast<string16*>(NULL)));
918 EXPECT_FALSE(main_dict.GetString("list", static_cast<string16*>(NULL)));
919 EXPECT_FALSE(main_dict.GetString("DNE", static_cast<string16*>(NULL)));
921 EXPECT_FALSE(main_dict.GetBinary("bool", NULL));
922 EXPECT_FALSE(main_dict.GetBinary("int", NULL));
923 EXPECT_FALSE(main_dict.GetBinary("double", NULL));
924 EXPECT_FALSE(main_dict.GetBinary("string", NULL));
925 EXPECT_TRUE(main_dict.GetBinary("binary", NULL));
926 EXPECT_FALSE(main_dict.GetBinary("dict", NULL));
927 EXPECT_FALSE(main_dict.GetBinary("list", NULL));
928 EXPECT_FALSE(main_dict.GetBinary("DNE", NULL));
930 EXPECT_FALSE(main_dict.GetDictionary("bool", NULL));
931 EXPECT_FALSE(main_dict.GetDictionary("int", NULL));
932 EXPECT_FALSE(main_dict.GetDictionary("double", NULL));
933 EXPECT_FALSE(main_dict.GetDictionary("string", NULL));
934 EXPECT_FALSE(main_dict.GetDictionary("binary", NULL));
935 EXPECT_TRUE(main_dict.GetDictionary("dict", NULL));
936 EXPECT_FALSE(main_dict.GetDictionary("list", NULL));
937 EXPECT_FALSE(main_dict.GetDictionary("DNE", NULL));
939 EXPECT_FALSE(main_dict.GetList("bool", NULL));
940 EXPECT_FALSE(main_dict.GetList("int", NULL));
941 EXPECT_FALSE(main_dict.GetList("double", NULL));
942 EXPECT_FALSE(main_dict.GetList("string", NULL));
943 EXPECT_FALSE(main_dict.GetList("binary", NULL));
944 EXPECT_FALSE(main_dict.GetList("dict", NULL));
945 EXPECT_TRUE(main_dict.GetList("list", NULL));
946 EXPECT_FALSE(main_dict.GetList("DNE", NULL));
948 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("bool", NULL));
949 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("int", NULL));
950 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("double", NULL));
951 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("string", NULL));
952 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("binary", NULL));
953 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("dict", NULL));
954 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("list", NULL));
955 EXPECT_FALSE(main_dict.GetWithoutPathExpansion("DNE", NULL));
957 EXPECT_TRUE(main_dict.GetBooleanWithoutPathExpansion("bool", NULL));
958 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("int", NULL));
959 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("double", NULL));
960 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("string", NULL));
961 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("binary", NULL));
962 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("dict", NULL));
963 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("list", NULL));
964 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("DNE", NULL));
966 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("bool", NULL));
967 EXPECT_TRUE(main_dict.GetIntegerWithoutPathExpansion("int", NULL));
968 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("double", NULL));
969 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("string", NULL));
970 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("binary", NULL));
971 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("dict", NULL));
972 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("list", NULL));
973 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("DNE", NULL));
975 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("bool", NULL));
976 EXPECT_TRUE(main_dict.GetDoubleWithoutPathExpansion("int", NULL));
977 EXPECT_TRUE(main_dict.GetDoubleWithoutPathExpansion("double", NULL));
978 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("string", NULL));
979 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("binary", NULL));
980 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("dict", NULL));
981 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("list", NULL));
982 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("DNE", NULL));
984 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
985 "bool", static_cast<std::string*>(NULL)));
986 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
987 "int", static_cast<std::string*>(NULL)));
988 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
989 "double", static_cast<std::string*>(NULL)));
990 EXPECT_TRUE(main_dict.GetStringWithoutPathExpansion(
991 "string", static_cast<std::string*>(NULL)));
992 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
993 "binary", static_cast<std::string*>(NULL)));
994 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
995 "dict", static_cast<std::string*>(NULL)));
996 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
997 "list", static_cast<std::string*>(NULL)));
998 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
999 "DNE", static_cast<std::string*>(NULL)));
1001 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1002 "bool", static_cast<string16*>(NULL)));
1003 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1004 "int", static_cast<string16*>(NULL)));
1005 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1006 "double", static_cast<string16*>(NULL)));
1007 EXPECT_TRUE(main_dict.GetStringWithoutPathExpansion(
1008 "string", static_cast<string16*>(NULL)));
1009 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1010 "binary", static_cast<string16*>(NULL)));
1011 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1012 "dict", static_cast<string16*>(NULL)));
1013 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1014 "list", static_cast<string16*>(NULL)));
1015 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1016 "DNE", static_cast<string16*>(NULL)));
1018 // There is no GetBinaryWithoutPathExpansion for some reason, but if there
1019 // were it should be tested here...
1021 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("bool", NULL));
1022 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("int", NULL));
1023 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("double", NULL));
1024 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("string", NULL));
1025 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("binary", NULL));
1026 EXPECT_TRUE(main_dict.GetDictionaryWithoutPathExpansion("dict", NULL));
1027 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("list", NULL));
1028 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("DNE", NULL));
1030 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("bool", NULL));
1031 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("int", NULL));
1032 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("double", NULL));
1033 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("string", NULL));
1034 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("binary", NULL));
1035 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("dict", NULL));
1036 EXPECT_TRUE(main_dict.GetListWithoutPathExpansion("list", NULL));
1037 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("DNE", NULL));
1039 EXPECT_TRUE(main_list.Get(0, NULL));
1040 EXPECT_TRUE(main_list.Get(1, NULL));
1041 EXPECT_TRUE(main_list.Get(2, NULL));
1042 EXPECT_TRUE(main_list.Get(3, NULL));
1043 EXPECT_TRUE(main_list.Get(4, NULL));
1044 EXPECT_TRUE(main_list.Get(5, NULL));
1045 EXPECT_TRUE(main_list.Get(6, NULL));
1046 EXPECT_FALSE(main_list.Get(7, NULL));
1048 EXPECT_TRUE(main_list.GetBoolean(0, NULL));
1049 EXPECT_FALSE(main_list.GetBoolean(1, NULL));
1050 EXPECT_FALSE(main_list.GetBoolean(2, NULL));
1051 EXPECT_FALSE(main_list.GetBoolean(3, NULL));
1052 EXPECT_FALSE(main_list.GetBoolean(4, NULL));
1053 EXPECT_FALSE(main_list.GetBoolean(5, NULL));
1054 EXPECT_FALSE(main_list.GetBoolean(6, NULL));
1055 EXPECT_FALSE(main_list.GetBoolean(7, NULL));
1057 EXPECT_FALSE(main_list.GetInteger(0, NULL));
1058 EXPECT_TRUE(main_list.GetInteger(1, NULL));
1059 EXPECT_FALSE(main_list.GetInteger(2, NULL));
1060 EXPECT_FALSE(main_list.GetInteger(3, NULL));
1061 EXPECT_FALSE(main_list.GetInteger(4, NULL));
1062 EXPECT_FALSE(main_list.GetInteger(5, NULL));
1063 EXPECT_FALSE(main_list.GetInteger(6, NULL));
1064 EXPECT_FALSE(main_list.GetInteger(7, NULL));
1066 EXPECT_FALSE(main_list.GetDouble(0, NULL));
1067 EXPECT_TRUE(main_list.GetDouble(1, NULL));
1068 EXPECT_TRUE(main_list.GetDouble(2, NULL));
1069 EXPECT_FALSE(main_list.GetDouble(3, NULL));
1070 EXPECT_FALSE(main_list.GetDouble(4, NULL));
1071 EXPECT_FALSE(main_list.GetDouble(5, NULL));
1072 EXPECT_FALSE(main_list.GetDouble(6, NULL));
1073 EXPECT_FALSE(main_list.GetDouble(7, NULL));
1075 EXPECT_FALSE(main_list.GetString(0, static_cast<std::string*>(NULL)));
1076 EXPECT_FALSE(main_list.GetString(1, static_cast<std::string*>(NULL)));
1077 EXPECT_FALSE(main_list.GetString(2, static_cast<std::string*>(NULL)));
1078 EXPECT_TRUE(main_list.GetString(3, static_cast<std::string*>(NULL)));
1079 EXPECT_FALSE(main_list.GetString(4, static_cast<std::string*>(NULL)));
1080 EXPECT_FALSE(main_list.GetString(5, static_cast<std::string*>(NULL)));
1081 EXPECT_FALSE(main_list.GetString(6, static_cast<std::string*>(NULL)));
1082 EXPECT_FALSE(main_list.GetString(7, static_cast<std::string*>(NULL)));
1084 EXPECT_FALSE(main_list.GetString(0, static_cast<string16*>(NULL)));
1085 EXPECT_FALSE(main_list.GetString(1, static_cast<string16*>(NULL)));
1086 EXPECT_FALSE(main_list.GetString(2, static_cast<string16*>(NULL)));
1087 EXPECT_TRUE(main_list.GetString(3, static_cast<string16*>(NULL)));
1088 EXPECT_FALSE(main_list.GetString(4, static_cast<string16*>(NULL)));
1089 EXPECT_FALSE(main_list.GetString(5, static_cast<string16*>(NULL)));
1090 EXPECT_FALSE(main_list.GetString(6, static_cast<string16*>(NULL)));
1091 EXPECT_FALSE(main_list.GetString(7, static_cast<string16*>(NULL)));
1093 EXPECT_FALSE(main_list.GetBinary(0, NULL));
1094 EXPECT_FALSE(main_list.GetBinary(1, NULL));
1095 EXPECT_FALSE(main_list.GetBinary(2, NULL));
1096 EXPECT_FALSE(main_list.GetBinary(3, NULL));
1097 EXPECT_TRUE(main_list.GetBinary(4, NULL));
1098 EXPECT_FALSE(main_list.GetBinary(5, NULL));
1099 EXPECT_FALSE(main_list.GetBinary(6, NULL));
1100 EXPECT_FALSE(main_list.GetBinary(7, NULL));
1102 EXPECT_FALSE(main_list.GetDictionary(0, NULL));
1103 EXPECT_FALSE(main_list.GetDictionary(1, NULL));
1104 EXPECT_FALSE(main_list.GetDictionary(2, NULL));
1105 EXPECT_FALSE(main_list.GetDictionary(3, NULL));
1106 EXPECT_FALSE(main_list.GetDictionary(4, NULL));
1107 EXPECT_TRUE(main_list.GetDictionary(5, NULL));
1108 EXPECT_FALSE(main_list.GetDictionary(6, NULL));
1109 EXPECT_FALSE(main_list.GetDictionary(7, NULL));
1111 EXPECT_FALSE(main_list.GetList(0, NULL));
1112 EXPECT_FALSE(main_list.GetList(1, NULL));
1113 EXPECT_FALSE(main_list.GetList(2, NULL));
1114 EXPECT_FALSE(main_list.GetList(3, NULL));
1115 EXPECT_FALSE(main_list.GetList(4, NULL));
1116 EXPECT_FALSE(main_list.GetList(5, NULL));
1117 EXPECT_TRUE(main_list.GetList(6, NULL));
1118 EXPECT_FALSE(main_list.GetList(7, NULL));
1121 } // namespace base