IndexedDB: Protect against use-after-free in ChainedBlobWriter.
[chromium-blink-merge.git] / base / values_unittest.cc
blobb66730b55e9cb40e03bc0165c92d5f32c8e1484a
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()));
131 // Test overloaded GetAsBinary.
132 Value* narrow_value = binary.get();
133 const BinaryValue* narrow_binary = NULL;
134 ASSERT_TRUE(narrow_value->GetAsBinary(&narrow_binary));
135 EXPECT_EQ(binary.get(), narrow_binary);
138 TEST(ValuesTest, StringValue) {
139 // Test overloaded StringValue constructor.
140 scoped_ptr<Value> narrow_value(new StringValue("narrow"));
141 ASSERT_TRUE(narrow_value.get());
142 ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING));
143 scoped_ptr<Value> utf16_value(new StringValue(ASCIIToUTF16("utf16")));
144 ASSERT_TRUE(utf16_value.get());
145 ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING));
147 // Test overloaded GetAsString.
148 std::string narrow = "http://google.com";
149 string16 utf16 = ASCIIToUTF16("http://google.com");
150 const StringValue* string_value = NULL;
151 ASSERT_TRUE(narrow_value->GetAsString(&narrow));
152 ASSERT_TRUE(narrow_value->GetAsString(&utf16));
153 ASSERT_TRUE(narrow_value->GetAsString(&string_value));
154 ASSERT_EQ(std::string("narrow"), narrow);
155 ASSERT_EQ(ASCIIToUTF16("narrow"), utf16);
156 ASSERT_EQ(string_value->GetString(), narrow);
158 ASSERT_TRUE(utf16_value->GetAsString(&narrow));
159 ASSERT_TRUE(utf16_value->GetAsString(&utf16));
160 ASSERT_TRUE(utf16_value->GetAsString(&string_value));
161 ASSERT_EQ(std::string("utf16"), narrow);
162 ASSERT_EQ(ASCIIToUTF16("utf16"), utf16);
163 ASSERT_EQ(string_value->GetString(), narrow);
165 // Don't choke on NULL values.
166 ASSERT_TRUE(narrow_value->GetAsString(static_cast<string16*>(NULL)));
167 ASSERT_TRUE(narrow_value->GetAsString(static_cast<std::string*>(NULL)));
168 ASSERT_TRUE(narrow_value->GetAsString(
169 static_cast<const StringValue**>(NULL)));
172 // This is a Value object that allows us to tell if it's been
173 // properly deleted by modifying the value of external flag on destruction.
174 class DeletionTestValue : public Value {
175 public:
176 explicit DeletionTestValue(bool* deletion_flag) : Value(TYPE_NULL) {
177 Init(deletion_flag); // Separate function so that we can use ASSERT_*
180 void Init(bool* deletion_flag) {
181 ASSERT_TRUE(deletion_flag);
182 deletion_flag_ = deletion_flag;
183 *deletion_flag_ = false;
186 ~DeletionTestValue() override { *deletion_flag_ = true; }
188 private:
189 bool* deletion_flag_;
192 TEST(ValuesTest, ListDeletion) {
193 bool deletion_flag = true;
196 ListValue list;
197 list.Append(new DeletionTestValue(&deletion_flag));
198 EXPECT_FALSE(deletion_flag);
200 EXPECT_TRUE(deletion_flag);
203 ListValue list;
204 list.Append(new DeletionTestValue(&deletion_flag));
205 EXPECT_FALSE(deletion_flag);
206 list.Clear();
207 EXPECT_TRUE(deletion_flag);
211 ListValue list;
212 list.Append(new DeletionTestValue(&deletion_flag));
213 EXPECT_FALSE(deletion_flag);
214 EXPECT_TRUE(list.Set(0, Value::CreateNullValue()));
215 EXPECT_TRUE(deletion_flag);
219 TEST(ValuesTest, ListRemoval) {
220 bool deletion_flag = true;
221 scoped_ptr<Value> removed_item;
224 ListValue list;
225 list.Append(new DeletionTestValue(&deletion_flag));
226 EXPECT_FALSE(deletion_flag);
227 EXPECT_EQ(1U, list.GetSize());
228 EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(),
229 &removed_item));
230 EXPECT_FALSE(list.Remove(1, &removed_item));
231 EXPECT_TRUE(list.Remove(0, &removed_item));
232 ASSERT_TRUE(removed_item);
233 EXPECT_EQ(0U, list.GetSize());
235 EXPECT_FALSE(deletion_flag);
236 removed_item.reset();
237 EXPECT_TRUE(deletion_flag);
240 ListValue list;
241 list.Append(new DeletionTestValue(&deletion_flag));
242 EXPECT_FALSE(deletion_flag);
243 EXPECT_TRUE(list.Remove(0, NULL));
244 EXPECT_TRUE(deletion_flag);
245 EXPECT_EQ(0U, list.GetSize());
249 ListValue list;
250 DeletionTestValue* value = new DeletionTestValue(&deletion_flag);
251 list.Append(value);
252 EXPECT_FALSE(deletion_flag);
253 size_t index = 0;
254 list.Remove(*value, &index);
255 EXPECT_EQ(0U, index);
256 EXPECT_TRUE(deletion_flag);
257 EXPECT_EQ(0U, list.GetSize());
261 TEST(ValuesTest, DictionaryDeletion) {
262 std::string key = "test";
263 bool deletion_flag = true;
266 DictionaryValue dict;
267 dict.Set(key, new DeletionTestValue(&deletion_flag));
268 EXPECT_FALSE(deletion_flag);
270 EXPECT_TRUE(deletion_flag);
273 DictionaryValue dict;
274 dict.Set(key, new DeletionTestValue(&deletion_flag));
275 EXPECT_FALSE(deletion_flag);
276 dict.Clear();
277 EXPECT_TRUE(deletion_flag);
281 DictionaryValue dict;
282 dict.Set(key, new DeletionTestValue(&deletion_flag));
283 EXPECT_FALSE(deletion_flag);
284 dict.Set(key, Value::CreateNullValue());
285 EXPECT_TRUE(deletion_flag);
289 TEST(ValuesTest, DictionaryRemoval) {
290 std::string key = "test";
291 bool deletion_flag = true;
292 scoped_ptr<Value> removed_item;
295 DictionaryValue dict;
296 dict.Set(key, new DeletionTestValue(&deletion_flag));
297 EXPECT_FALSE(deletion_flag);
298 EXPECT_TRUE(dict.HasKey(key));
299 EXPECT_FALSE(dict.Remove("absent key", &removed_item));
300 EXPECT_TRUE(dict.Remove(key, &removed_item));
301 EXPECT_FALSE(dict.HasKey(key));
302 ASSERT_TRUE(removed_item);
304 EXPECT_FALSE(deletion_flag);
305 removed_item.reset();
306 EXPECT_TRUE(deletion_flag);
309 DictionaryValue dict;
310 dict.Set(key, new DeletionTestValue(&deletion_flag));
311 EXPECT_FALSE(deletion_flag);
312 EXPECT_TRUE(dict.HasKey(key));
313 EXPECT_TRUE(dict.Remove(key, NULL));
314 EXPECT_TRUE(deletion_flag);
315 EXPECT_FALSE(dict.HasKey(key));
319 TEST(ValuesTest, DictionaryWithoutPathExpansion) {
320 DictionaryValue dict;
321 dict.Set("this.is.expanded", make_scoped_ptr(Value::CreateNullValue()));
322 dict.SetWithoutPathExpansion("this.isnt.expanded",
323 make_scoped_ptr(Value::CreateNullValue()));
325 EXPECT_FALSE(dict.HasKey("this.is.expanded"));
326 EXPECT_TRUE(dict.HasKey("this"));
327 Value* value1;
328 EXPECT_TRUE(dict.Get("this", &value1));
329 DictionaryValue* value2;
330 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2));
331 EXPECT_EQ(value1, value2);
332 EXPECT_EQ(1U, value2->size());
334 EXPECT_TRUE(dict.HasKey("this.isnt.expanded"));
335 Value* value3;
336 EXPECT_FALSE(dict.Get("this.isnt.expanded", &value3));
337 Value* value4;
338 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4));
339 EXPECT_EQ(Value::TYPE_NULL, value4->GetType());
342 // Tests the deprecated version of SetWithoutPathExpansion.
343 // TODO(estade): remove.
344 TEST(ValuesTest, DictionaryWithoutPathExpansionDeprecated) {
345 DictionaryValue dict;
346 dict.Set("this.is.expanded", Value::CreateNullValue());
347 dict.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue());
349 EXPECT_FALSE(dict.HasKey("this.is.expanded"));
350 EXPECT_TRUE(dict.HasKey("this"));
351 Value* value1;
352 EXPECT_TRUE(dict.Get("this", &value1));
353 DictionaryValue* value2;
354 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2));
355 EXPECT_EQ(value1, value2);
356 EXPECT_EQ(1U, value2->size());
358 EXPECT_TRUE(dict.HasKey("this.isnt.expanded"));
359 Value* value3;
360 EXPECT_FALSE(dict.Get("this.isnt.expanded", &value3));
361 Value* value4;
362 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4));
363 EXPECT_EQ(Value::TYPE_NULL, value4->GetType());
366 TEST(ValuesTest, DictionaryRemovePath) {
367 DictionaryValue dict;
368 dict.SetInteger("a.long.way.down", 1);
369 dict.SetBoolean("a.long.key.path", true);
371 scoped_ptr<Value> removed_item;
372 EXPECT_TRUE(dict.RemovePath("a.long.way.down", &removed_item));
373 ASSERT_TRUE(removed_item);
374 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_INTEGER));
375 EXPECT_FALSE(dict.HasKey("a.long.way.down"));
376 EXPECT_FALSE(dict.HasKey("a.long.way"));
377 EXPECT_TRUE(dict.Get("a.long.key.path", NULL));
379 removed_item.reset();
380 EXPECT_FALSE(dict.RemovePath("a.long.way.down", &removed_item));
381 EXPECT_FALSE(removed_item);
382 EXPECT_TRUE(dict.Get("a.long.key.path", NULL));
384 removed_item.reset();
385 EXPECT_TRUE(dict.RemovePath("a.long.key.path", &removed_item));
386 ASSERT_TRUE(removed_item);
387 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_BOOLEAN));
388 EXPECT_TRUE(dict.empty());
391 TEST(ValuesTest, DeepCopy) {
392 DictionaryValue original_dict;
393 Value* original_null = Value::CreateNullValue();
394 original_dict.Set("null", make_scoped_ptr(original_null));
395 FundamentalValue* original_bool = new FundamentalValue(true);
396 original_dict.Set("bool", make_scoped_ptr(original_bool));
397 FundamentalValue* original_int = new FundamentalValue(42);
398 original_dict.Set("int", make_scoped_ptr(original_int));
399 FundamentalValue* original_double = new FundamentalValue(3.14);
400 original_dict.Set("double", make_scoped_ptr(original_double));
401 StringValue* original_string = new StringValue("hello");
402 original_dict.Set("string", make_scoped_ptr(original_string));
403 StringValue* original_string16 = new StringValue(ASCIIToUTF16("hello16"));
404 original_dict.Set("string16", make_scoped_ptr(original_string16));
406 scoped_ptr<char[]> original_buffer(new char[42]);
407 memset(original_buffer.get(), '!', 42);
408 BinaryValue* original_binary = new BinaryValue(original_buffer.Pass(), 42);
409 original_dict.Set("binary", original_binary);
411 ListValue* original_list = new ListValue();
412 FundamentalValue* original_list_element_0 = new FundamentalValue(0);
413 original_list->Append(original_list_element_0);
414 FundamentalValue* original_list_element_1 = new FundamentalValue(1);
415 original_list->Append(original_list_element_1);
416 original_dict.Set("list", make_scoped_ptr(original_list));
418 DictionaryValue* original_nested_dictionary = new DictionaryValue();
419 original_nested_dictionary->SetString("key", "value");
420 original_dict.Set("dictionary", make_scoped_ptr(original_nested_dictionary));
422 scoped_ptr<DictionaryValue> copy_dict(original_dict.DeepCopy());
423 ASSERT_TRUE(copy_dict.get());
424 ASSERT_NE(copy_dict.get(), &original_dict);
426 Value* copy_null = NULL;
427 ASSERT_TRUE(copy_dict->Get("null", &copy_null));
428 ASSERT_TRUE(copy_null);
429 ASSERT_NE(copy_null, original_null);
430 ASSERT_TRUE(copy_null->IsType(Value::TYPE_NULL));
432 Value* copy_bool = NULL;
433 ASSERT_TRUE(copy_dict->Get("bool", &copy_bool));
434 ASSERT_TRUE(copy_bool);
435 ASSERT_NE(copy_bool, original_bool);
436 ASSERT_TRUE(copy_bool->IsType(Value::TYPE_BOOLEAN));
437 bool copy_bool_value = false;
438 ASSERT_TRUE(copy_bool->GetAsBoolean(&copy_bool_value));
439 ASSERT_TRUE(copy_bool_value);
441 Value* copy_int = NULL;
442 ASSERT_TRUE(copy_dict->Get("int", &copy_int));
443 ASSERT_TRUE(copy_int);
444 ASSERT_NE(copy_int, original_int);
445 ASSERT_TRUE(copy_int->IsType(Value::TYPE_INTEGER));
446 int copy_int_value = 0;
447 ASSERT_TRUE(copy_int->GetAsInteger(&copy_int_value));
448 ASSERT_EQ(42, copy_int_value);
450 Value* copy_double = NULL;
451 ASSERT_TRUE(copy_dict->Get("double", &copy_double));
452 ASSERT_TRUE(copy_double);
453 ASSERT_NE(copy_double, original_double);
454 ASSERT_TRUE(copy_double->IsType(Value::TYPE_DOUBLE));
455 double copy_double_value = 0;
456 ASSERT_TRUE(copy_double->GetAsDouble(&copy_double_value));
457 ASSERT_EQ(3.14, copy_double_value);
459 Value* copy_string = NULL;
460 ASSERT_TRUE(copy_dict->Get("string", &copy_string));
461 ASSERT_TRUE(copy_string);
462 ASSERT_NE(copy_string, original_string);
463 ASSERT_TRUE(copy_string->IsType(Value::TYPE_STRING));
464 std::string copy_string_value;
465 string16 copy_string16_value;
466 ASSERT_TRUE(copy_string->GetAsString(&copy_string_value));
467 ASSERT_TRUE(copy_string->GetAsString(&copy_string16_value));
468 ASSERT_EQ(std::string("hello"), copy_string_value);
469 ASSERT_EQ(ASCIIToUTF16("hello"), copy_string16_value);
471 Value* copy_string16 = NULL;
472 ASSERT_TRUE(copy_dict->Get("string16", &copy_string16));
473 ASSERT_TRUE(copy_string16);
474 ASSERT_NE(copy_string16, original_string16);
475 ASSERT_TRUE(copy_string16->IsType(Value::TYPE_STRING));
476 ASSERT_TRUE(copy_string16->GetAsString(&copy_string_value));
477 ASSERT_TRUE(copy_string16->GetAsString(&copy_string16_value));
478 ASSERT_EQ(std::string("hello16"), copy_string_value);
479 ASSERT_EQ(ASCIIToUTF16("hello16"), copy_string16_value);
481 Value* copy_binary = NULL;
482 ASSERT_TRUE(copy_dict->Get("binary", &copy_binary));
483 ASSERT_TRUE(copy_binary);
484 ASSERT_NE(copy_binary, original_binary);
485 ASSERT_TRUE(copy_binary->IsType(Value::TYPE_BINARY));
486 ASSERT_NE(original_binary->GetBuffer(),
487 static_cast<BinaryValue*>(copy_binary)->GetBuffer());
488 ASSERT_EQ(original_binary->GetSize(),
489 static_cast<BinaryValue*>(copy_binary)->GetSize());
490 ASSERT_EQ(0, memcmp(original_binary->GetBuffer(),
491 static_cast<BinaryValue*>(copy_binary)->GetBuffer(),
492 original_binary->GetSize()));
494 Value* copy_value = NULL;
495 ASSERT_TRUE(copy_dict->Get("list", &copy_value));
496 ASSERT_TRUE(copy_value);
497 ASSERT_NE(copy_value, original_list);
498 ASSERT_TRUE(copy_value->IsType(Value::TYPE_LIST));
499 ListValue* copy_list = NULL;
500 ASSERT_TRUE(copy_value->GetAsList(&copy_list));
501 ASSERT_TRUE(copy_list);
502 ASSERT_EQ(2U, copy_list->GetSize());
504 Value* copy_list_element_0;
505 ASSERT_TRUE(copy_list->Get(0, &copy_list_element_0));
506 ASSERT_TRUE(copy_list_element_0);
507 ASSERT_NE(copy_list_element_0, original_list_element_0);
508 int copy_list_element_0_value;
509 ASSERT_TRUE(copy_list_element_0->GetAsInteger(&copy_list_element_0_value));
510 ASSERT_EQ(0, copy_list_element_0_value);
512 Value* copy_list_element_1;
513 ASSERT_TRUE(copy_list->Get(1, &copy_list_element_1));
514 ASSERT_TRUE(copy_list_element_1);
515 ASSERT_NE(copy_list_element_1, original_list_element_1);
516 int copy_list_element_1_value;
517 ASSERT_TRUE(copy_list_element_1->GetAsInteger(&copy_list_element_1_value));
518 ASSERT_EQ(1, copy_list_element_1_value);
520 copy_value = NULL;
521 ASSERT_TRUE(copy_dict->Get("dictionary", &copy_value));
522 ASSERT_TRUE(copy_value);
523 ASSERT_NE(copy_value, original_nested_dictionary);
524 ASSERT_TRUE(copy_value->IsType(Value::TYPE_DICTIONARY));
525 DictionaryValue* copy_nested_dictionary = NULL;
526 ASSERT_TRUE(copy_value->GetAsDictionary(&copy_nested_dictionary));
527 ASSERT_TRUE(copy_nested_dictionary);
528 EXPECT_TRUE(copy_nested_dictionary->HasKey("key"));
531 TEST(ValuesTest, Equals) {
532 Value* null1 = Value::CreateNullValue();
533 Value* null2 = Value::CreateNullValue();
534 EXPECT_NE(null1, null2);
535 EXPECT_TRUE(null1->Equals(null2));
537 Value* boolean = new FundamentalValue(false);
538 EXPECT_FALSE(null1->Equals(boolean));
539 delete null1;
540 delete null2;
541 delete boolean;
543 DictionaryValue dv;
544 dv.SetBoolean("a", false);
545 dv.SetInteger("b", 2);
546 dv.SetDouble("c", 2.5);
547 dv.SetString("d1", "string");
548 dv.SetString("d2", ASCIIToUTF16("http://google.com"));
549 dv.Set("e", make_scoped_ptr(Value::CreateNullValue()));
551 scoped_ptr<DictionaryValue> copy;
552 copy.reset(dv.DeepCopy());
553 EXPECT_TRUE(dv.Equals(copy.get()));
555 ListValue* list = new ListValue;
556 list->Append(Value::CreateNullValue());
557 list->Append(new DictionaryValue);
558 dv.Set("f", make_scoped_ptr(list));
560 EXPECT_FALSE(dv.Equals(copy.get()));
561 copy->Set("f", list->DeepCopy());
562 EXPECT_TRUE(dv.Equals(copy.get()));
564 list->Append(new FundamentalValue(true));
565 EXPECT_FALSE(dv.Equals(copy.get()));
567 // Check if Equals detects differences in only the keys.
568 copy.reset(dv.DeepCopy());
569 EXPECT_TRUE(dv.Equals(copy.get()));
570 copy->Remove("a", NULL);
571 copy->SetBoolean("aa", false);
572 EXPECT_FALSE(dv.Equals(copy.get()));
575 TEST(ValuesTest, StaticEquals) {
576 scoped_ptr<Value> null1(Value::CreateNullValue());
577 scoped_ptr<Value> null2(Value::CreateNullValue());
578 EXPECT_TRUE(Value::Equals(null1.get(), null2.get()));
579 EXPECT_TRUE(Value::Equals(NULL, NULL));
581 scoped_ptr<Value> i42(new FundamentalValue(42));
582 scoped_ptr<Value> j42(new FundamentalValue(42));
583 scoped_ptr<Value> i17(new FundamentalValue(17));
584 EXPECT_TRUE(Value::Equals(i42.get(), i42.get()));
585 EXPECT_TRUE(Value::Equals(j42.get(), i42.get()));
586 EXPECT_TRUE(Value::Equals(i42.get(), j42.get()));
587 EXPECT_FALSE(Value::Equals(i42.get(), i17.get()));
588 EXPECT_FALSE(Value::Equals(i42.get(), NULL));
589 EXPECT_FALSE(Value::Equals(NULL, i42.get()));
591 // NULL and Value::CreateNullValue() are intentionally different: We need
592 // support for NULL as a return value for "undefined" without caring for
593 // ownership of the pointer.
594 EXPECT_FALSE(Value::Equals(null1.get(), NULL));
595 EXPECT_FALSE(Value::Equals(NULL, null1.get()));
598 TEST(ValuesTest, DeepCopyCovariantReturnTypes) {
599 DictionaryValue original_dict;
600 Value* original_null = Value::CreateNullValue();
601 original_dict.Set("null", original_null);
602 FundamentalValue* original_bool = new FundamentalValue(true);
603 original_dict.Set("bool", original_bool);
604 FundamentalValue* original_int = new FundamentalValue(42);
605 original_dict.Set("int", original_int);
606 FundamentalValue* original_double = new FundamentalValue(3.14);
607 original_dict.Set("double", original_double);
608 StringValue* original_string = new StringValue("hello");
609 original_dict.Set("string", original_string);
610 StringValue* original_string16 = new StringValue(ASCIIToUTF16("hello16"));
611 original_dict.Set("string16", original_string16);
613 scoped_ptr<char[]> original_buffer(new char[42]);
614 memset(original_buffer.get(), '!', 42);
615 BinaryValue* original_binary = new BinaryValue(original_buffer.Pass(), 42);
616 original_dict.Set("binary", original_binary);
618 ListValue* original_list = new ListValue();
619 FundamentalValue* original_list_element_0 = new FundamentalValue(0);
620 original_list->Append(original_list_element_0);
621 FundamentalValue* original_list_element_1 = new FundamentalValue(1);
622 original_list->Append(original_list_element_1);
623 original_dict.Set("list", original_list);
625 Value* original_dict_value = &original_dict;
626 Value* original_bool_value = original_bool;
627 Value* original_int_value = original_int;
628 Value* original_double_value = original_double;
629 Value* original_string_value = original_string;
630 Value* original_string16_value = original_string16;
631 Value* original_binary_value = original_binary;
632 Value* original_list_value = original_list;
634 scoped_ptr<Value> copy_dict_value(original_dict_value->DeepCopy());
635 scoped_ptr<Value> copy_bool_value(original_bool_value->DeepCopy());
636 scoped_ptr<Value> copy_int_value(original_int_value->DeepCopy());
637 scoped_ptr<Value> copy_double_value(original_double_value->DeepCopy());
638 scoped_ptr<Value> copy_string_value(original_string_value->DeepCopy());
639 scoped_ptr<Value> copy_string16_value(original_string16_value->DeepCopy());
640 scoped_ptr<Value> copy_binary_value(original_binary_value->DeepCopy());
641 scoped_ptr<Value> copy_list_value(original_list_value->DeepCopy());
643 EXPECT_TRUE(original_dict_value->Equals(copy_dict_value.get()));
644 EXPECT_TRUE(original_bool_value->Equals(copy_bool_value.get()));
645 EXPECT_TRUE(original_int_value->Equals(copy_int_value.get()));
646 EXPECT_TRUE(original_double_value->Equals(copy_double_value.get()));
647 EXPECT_TRUE(original_string_value->Equals(copy_string_value.get()));
648 EXPECT_TRUE(original_string16_value->Equals(copy_string16_value.get()));
649 EXPECT_TRUE(original_binary_value->Equals(copy_binary_value.get()));
650 EXPECT_TRUE(original_list_value->Equals(copy_list_value.get()));
653 TEST(ValuesTest, RemoveEmptyChildren) {
654 scoped_ptr<DictionaryValue> root(new DictionaryValue);
655 // Remove empty lists and dictionaries.
656 root->Set("empty_dict", make_scoped_ptr(new DictionaryValue));
657 root->Set("empty_list", make_scoped_ptr(new ListValue));
658 root->SetWithoutPathExpansion("a.b.c.d.e",
659 make_scoped_ptr(new DictionaryValue));
660 root.reset(root->DeepCopyWithoutEmptyChildren());
661 EXPECT_TRUE(root->empty());
663 // Make sure we don't prune too much.
664 root->SetBoolean("bool", true);
665 root->Set("empty_dict", new DictionaryValue);
666 root->SetString("empty_string", std::string());
667 root.reset(root->DeepCopyWithoutEmptyChildren());
668 EXPECT_EQ(2U, root->size());
670 // Should do nothing.
671 root.reset(root->DeepCopyWithoutEmptyChildren());
672 EXPECT_EQ(2U, root->size());
674 // Nested test cases. These should all reduce back to the bool and string
675 // set above.
677 root->Set("a.b.c.d.e", new DictionaryValue);
678 root.reset(root->DeepCopyWithoutEmptyChildren());
679 EXPECT_EQ(2U, root->size());
682 DictionaryValue* inner = new DictionaryValue;
683 root->Set("dict_with_emtpy_children", inner);
684 inner->Set("empty_dict", new DictionaryValue);
685 inner->Set("empty_list", new ListValue);
686 root.reset(root->DeepCopyWithoutEmptyChildren());
687 EXPECT_EQ(2U, root->size());
690 ListValue* inner = new ListValue;
691 root->Set("list_with_empty_children", inner);
692 inner->Append(new DictionaryValue);
693 inner->Append(new ListValue);
694 root.reset(root->DeepCopyWithoutEmptyChildren());
695 EXPECT_EQ(2U, root->size());
698 // Nested with siblings.
700 ListValue* inner = new ListValue;
701 root->Set("list_with_empty_children", inner);
702 inner->Append(new DictionaryValue);
703 inner->Append(new ListValue);
704 DictionaryValue* inner2 = new DictionaryValue;
705 root->Set("dict_with_empty_children", inner2);
706 inner2->Set("empty_dict", new DictionaryValue);
707 inner2->Set("empty_list", new ListValue);
708 root.reset(root->DeepCopyWithoutEmptyChildren());
709 EXPECT_EQ(2U, root->size());
712 // Make sure nested values don't get pruned.
714 ListValue* inner = new ListValue;
715 root->Set("list_with_empty_children", inner);
716 ListValue* inner2 = new ListValue;
717 inner->Append(new DictionaryValue);
718 inner->Append(inner2);
719 inner2->Append(new StringValue("hello"));
720 root.reset(root->DeepCopyWithoutEmptyChildren());
721 EXPECT_EQ(3U, root->size());
722 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner));
723 EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned.
724 EXPECT_TRUE(inner->GetList(0, &inner2));
725 EXPECT_EQ(1U, inner2->GetSize());
729 TEST(ValuesTest, MergeDictionary) {
730 scoped_ptr<DictionaryValue> base(new DictionaryValue);
731 base->SetString("base_key", "base_key_value_base");
732 base->SetString("collide_key", "collide_key_value_base");
733 DictionaryValue* base_sub_dict = new DictionaryValue;
734 base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base");
735 base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base");
736 base->Set("sub_dict_key", base_sub_dict);
738 scoped_ptr<DictionaryValue> merge(new DictionaryValue);
739 merge->SetString("merge_key", "merge_key_value_merge");
740 merge->SetString("collide_key", "collide_key_value_merge");
741 DictionaryValue* merge_sub_dict = new DictionaryValue;
742 merge_sub_dict->SetString("sub_merge_key", "sub_merge_key_value_merge");
743 merge_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_merge");
744 merge->Set("sub_dict_key", merge_sub_dict);
746 base->MergeDictionary(merge.get());
748 EXPECT_EQ(4U, base->size());
749 std::string base_key_value;
750 EXPECT_TRUE(base->GetString("base_key", &base_key_value));
751 EXPECT_EQ("base_key_value_base", base_key_value); // Base value preserved.
752 std::string collide_key_value;
753 EXPECT_TRUE(base->GetString("collide_key", &collide_key_value));
754 EXPECT_EQ("collide_key_value_merge", collide_key_value); // Replaced.
755 std::string merge_key_value;
756 EXPECT_TRUE(base->GetString("merge_key", &merge_key_value));
757 EXPECT_EQ("merge_key_value_merge", merge_key_value); // Merged in.
759 DictionaryValue* res_sub_dict;
760 EXPECT_TRUE(base->GetDictionary("sub_dict_key", &res_sub_dict));
761 EXPECT_EQ(3U, res_sub_dict->size());
762 std::string sub_base_key_value;
763 EXPECT_TRUE(res_sub_dict->GetString("sub_base_key", &sub_base_key_value));
764 EXPECT_EQ("sub_base_key_value_base", sub_base_key_value); // Preserved.
765 std::string sub_collide_key_value;
766 EXPECT_TRUE(res_sub_dict->GetString("sub_collide_key",
767 &sub_collide_key_value));
768 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced.
769 std::string sub_merge_key_value;
770 EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value));
771 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in.
774 TEST(ValuesTest, MergeDictionaryDeepCopy) {
775 DictionaryValue* child = new DictionaryValue;
776 child->SetString("test", "value");
777 EXPECT_EQ(1U, child->size());
779 std::string value;
780 EXPECT_TRUE(child->GetString("test", &value));
781 EXPECT_EQ("value", value);
783 scoped_ptr<DictionaryValue> base(new DictionaryValue);
784 base->Set("dict", child);
785 EXPECT_EQ(1U, base->size());
787 DictionaryValue* ptr;
788 EXPECT_TRUE(base->GetDictionary("dict", &ptr));
789 EXPECT_EQ(child, ptr);
791 scoped_ptr<DictionaryValue> merged(new DictionaryValue);
792 merged->MergeDictionary(base.get());
793 EXPECT_EQ(1U, merged->size());
794 EXPECT_TRUE(merged->GetDictionary("dict", &ptr));
795 EXPECT_NE(child, ptr);
796 EXPECT_TRUE(ptr->GetString("test", &value));
797 EXPECT_EQ("value", value);
799 child->SetString("test", "overwrite");
800 base.reset();
801 EXPECT_TRUE(ptr->GetString("test", &value));
802 EXPECT_EQ("value", value);
805 TEST(ValuesTest, DictionaryIterator) {
806 DictionaryValue dict;
807 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
808 ADD_FAILURE();
811 StringValue value1("value1");
812 dict.Set("key1", value1.DeepCopy());
813 bool seen1 = false;
814 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
815 EXPECT_FALSE(seen1);
816 EXPECT_EQ("key1", it.key());
817 EXPECT_TRUE(value1.Equals(&it.value()));
818 seen1 = true;
820 EXPECT_TRUE(seen1);
822 StringValue value2("value2");
823 dict.Set("key2", value2.DeepCopy());
824 bool seen2 = seen1 = false;
825 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
826 if (it.key() == "key1") {
827 EXPECT_FALSE(seen1);
828 EXPECT_TRUE(value1.Equals(&it.value()));
829 seen1 = true;
830 } else if (it.key() == "key2") {
831 EXPECT_FALSE(seen2);
832 EXPECT_TRUE(value2.Equals(&it.value()));
833 seen2 = true;
834 } else {
835 ADD_FAILURE();
838 EXPECT_TRUE(seen1);
839 EXPECT_TRUE(seen2);
842 // DictionaryValue/ListValue's Get*() methods should accept NULL as an out-value
843 // and still return true/false based on success.
844 TEST(ValuesTest, GetWithNullOutValue) {
845 DictionaryValue main_dict;
846 ListValue main_list;
848 FundamentalValue bool_value(false);
849 FundamentalValue int_value(1234);
850 FundamentalValue double_value(12.34567);
851 StringValue string_value("foo");
852 BinaryValue binary_value;
853 DictionaryValue dict_value;
854 ListValue list_value;
856 main_dict.Set("bool", bool_value.DeepCopy());
857 main_dict.Set("int", int_value.DeepCopy());
858 main_dict.Set("double", double_value.DeepCopy());
859 main_dict.Set("string", string_value.DeepCopy());
860 main_dict.Set("binary", binary_value.DeepCopy());
861 main_dict.Set("dict", dict_value.DeepCopy());
862 main_dict.Set("list", list_value.DeepCopy());
864 main_list.Append(bool_value.DeepCopy());
865 main_list.Append(int_value.DeepCopy());
866 main_list.Append(double_value.DeepCopy());
867 main_list.Append(string_value.DeepCopy());
868 main_list.Append(binary_value.DeepCopy());
869 main_list.Append(dict_value.DeepCopy());
870 main_list.Append(list_value.DeepCopy());
872 EXPECT_TRUE(main_dict.Get("bool", NULL));
873 EXPECT_TRUE(main_dict.Get("int", NULL));
874 EXPECT_TRUE(main_dict.Get("double", NULL));
875 EXPECT_TRUE(main_dict.Get("string", NULL));
876 EXPECT_TRUE(main_dict.Get("binary", NULL));
877 EXPECT_TRUE(main_dict.Get("dict", NULL));
878 EXPECT_TRUE(main_dict.Get("list", NULL));
879 EXPECT_FALSE(main_dict.Get("DNE", NULL));
881 EXPECT_TRUE(main_dict.GetBoolean("bool", NULL));
882 EXPECT_FALSE(main_dict.GetBoolean("int", NULL));
883 EXPECT_FALSE(main_dict.GetBoolean("double", NULL));
884 EXPECT_FALSE(main_dict.GetBoolean("string", NULL));
885 EXPECT_FALSE(main_dict.GetBoolean("binary", NULL));
886 EXPECT_FALSE(main_dict.GetBoolean("dict", NULL));
887 EXPECT_FALSE(main_dict.GetBoolean("list", NULL));
888 EXPECT_FALSE(main_dict.GetBoolean("DNE", NULL));
890 EXPECT_FALSE(main_dict.GetInteger("bool", NULL));
891 EXPECT_TRUE(main_dict.GetInteger("int", NULL));
892 EXPECT_FALSE(main_dict.GetInteger("double", NULL));
893 EXPECT_FALSE(main_dict.GetInteger("string", NULL));
894 EXPECT_FALSE(main_dict.GetInteger("binary", NULL));
895 EXPECT_FALSE(main_dict.GetInteger("dict", NULL));
896 EXPECT_FALSE(main_dict.GetInteger("list", NULL));
897 EXPECT_FALSE(main_dict.GetInteger("DNE", NULL));
899 // Both int and double values can be obtained from GetDouble.
900 EXPECT_FALSE(main_dict.GetDouble("bool", NULL));
901 EXPECT_TRUE(main_dict.GetDouble("int", NULL));
902 EXPECT_TRUE(main_dict.GetDouble("double", NULL));
903 EXPECT_FALSE(main_dict.GetDouble("string", NULL));
904 EXPECT_FALSE(main_dict.GetDouble("binary", NULL));
905 EXPECT_FALSE(main_dict.GetDouble("dict", NULL));
906 EXPECT_FALSE(main_dict.GetDouble("list", NULL));
907 EXPECT_FALSE(main_dict.GetDouble("DNE", NULL));
909 EXPECT_FALSE(main_dict.GetString("bool", static_cast<std::string*>(NULL)));
910 EXPECT_FALSE(main_dict.GetString("int", static_cast<std::string*>(NULL)));
911 EXPECT_FALSE(main_dict.GetString("double", static_cast<std::string*>(NULL)));
912 EXPECT_TRUE(main_dict.GetString("string", static_cast<std::string*>(NULL)));
913 EXPECT_FALSE(main_dict.GetString("binary", static_cast<std::string*>(NULL)));
914 EXPECT_FALSE(main_dict.GetString("dict", static_cast<std::string*>(NULL)));
915 EXPECT_FALSE(main_dict.GetString("list", static_cast<std::string*>(NULL)));
916 EXPECT_FALSE(main_dict.GetString("DNE", static_cast<std::string*>(NULL)));
918 EXPECT_FALSE(main_dict.GetString("bool", static_cast<string16*>(NULL)));
919 EXPECT_FALSE(main_dict.GetString("int", static_cast<string16*>(NULL)));
920 EXPECT_FALSE(main_dict.GetString("double", static_cast<string16*>(NULL)));
921 EXPECT_TRUE(main_dict.GetString("string", static_cast<string16*>(NULL)));
922 EXPECT_FALSE(main_dict.GetString("binary", static_cast<string16*>(NULL)));
923 EXPECT_FALSE(main_dict.GetString("dict", static_cast<string16*>(NULL)));
924 EXPECT_FALSE(main_dict.GetString("list", static_cast<string16*>(NULL)));
925 EXPECT_FALSE(main_dict.GetString("DNE", static_cast<string16*>(NULL)));
927 EXPECT_FALSE(main_dict.GetBinary("bool", NULL));
928 EXPECT_FALSE(main_dict.GetBinary("int", NULL));
929 EXPECT_FALSE(main_dict.GetBinary("double", NULL));
930 EXPECT_FALSE(main_dict.GetBinary("string", NULL));
931 EXPECT_TRUE(main_dict.GetBinary("binary", NULL));
932 EXPECT_FALSE(main_dict.GetBinary("dict", NULL));
933 EXPECT_FALSE(main_dict.GetBinary("list", NULL));
934 EXPECT_FALSE(main_dict.GetBinary("DNE", NULL));
936 EXPECT_FALSE(main_dict.GetDictionary("bool", NULL));
937 EXPECT_FALSE(main_dict.GetDictionary("int", NULL));
938 EXPECT_FALSE(main_dict.GetDictionary("double", NULL));
939 EXPECT_FALSE(main_dict.GetDictionary("string", NULL));
940 EXPECT_FALSE(main_dict.GetDictionary("binary", NULL));
941 EXPECT_TRUE(main_dict.GetDictionary("dict", NULL));
942 EXPECT_FALSE(main_dict.GetDictionary("list", NULL));
943 EXPECT_FALSE(main_dict.GetDictionary("DNE", NULL));
945 EXPECT_FALSE(main_dict.GetList("bool", NULL));
946 EXPECT_FALSE(main_dict.GetList("int", NULL));
947 EXPECT_FALSE(main_dict.GetList("double", NULL));
948 EXPECT_FALSE(main_dict.GetList("string", NULL));
949 EXPECT_FALSE(main_dict.GetList("binary", NULL));
950 EXPECT_FALSE(main_dict.GetList("dict", NULL));
951 EXPECT_TRUE(main_dict.GetList("list", NULL));
952 EXPECT_FALSE(main_dict.GetList("DNE", NULL));
954 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("bool", NULL));
955 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("int", NULL));
956 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("double", NULL));
957 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("string", NULL));
958 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("binary", NULL));
959 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("dict", NULL));
960 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("list", NULL));
961 EXPECT_FALSE(main_dict.GetWithoutPathExpansion("DNE", NULL));
963 EXPECT_TRUE(main_dict.GetBooleanWithoutPathExpansion("bool", NULL));
964 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("int", NULL));
965 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("double", NULL));
966 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("string", NULL));
967 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("binary", NULL));
968 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("dict", NULL));
969 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("list", NULL));
970 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("DNE", NULL));
972 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("bool", NULL));
973 EXPECT_TRUE(main_dict.GetIntegerWithoutPathExpansion("int", NULL));
974 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("double", NULL));
975 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("string", NULL));
976 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("binary", NULL));
977 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("dict", NULL));
978 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("list", NULL));
979 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("DNE", NULL));
981 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("bool", NULL));
982 EXPECT_TRUE(main_dict.GetDoubleWithoutPathExpansion("int", NULL));
983 EXPECT_TRUE(main_dict.GetDoubleWithoutPathExpansion("double", NULL));
984 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("string", NULL));
985 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("binary", NULL));
986 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("dict", NULL));
987 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("list", NULL));
988 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("DNE", NULL));
990 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
991 "bool", static_cast<std::string*>(NULL)));
992 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
993 "int", static_cast<std::string*>(NULL)));
994 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
995 "double", static_cast<std::string*>(NULL)));
996 EXPECT_TRUE(main_dict.GetStringWithoutPathExpansion(
997 "string", static_cast<std::string*>(NULL)));
998 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
999 "binary", static_cast<std::string*>(NULL)));
1000 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1001 "dict", static_cast<std::string*>(NULL)));
1002 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1003 "list", static_cast<std::string*>(NULL)));
1004 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1005 "DNE", static_cast<std::string*>(NULL)));
1007 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1008 "bool", static_cast<string16*>(NULL)));
1009 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1010 "int", static_cast<string16*>(NULL)));
1011 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1012 "double", static_cast<string16*>(NULL)));
1013 EXPECT_TRUE(main_dict.GetStringWithoutPathExpansion(
1014 "string", static_cast<string16*>(NULL)));
1015 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1016 "binary", static_cast<string16*>(NULL)));
1017 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1018 "dict", static_cast<string16*>(NULL)));
1019 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1020 "list", static_cast<string16*>(NULL)));
1021 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1022 "DNE", static_cast<string16*>(NULL)));
1024 // There is no GetBinaryWithoutPathExpansion for some reason, but if there
1025 // were it should be tested here...
1027 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("bool", NULL));
1028 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("int", NULL));
1029 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("double", NULL));
1030 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("string", NULL));
1031 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("binary", NULL));
1032 EXPECT_TRUE(main_dict.GetDictionaryWithoutPathExpansion("dict", NULL));
1033 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("list", NULL));
1034 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("DNE", NULL));
1036 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("bool", NULL));
1037 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("int", NULL));
1038 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("double", NULL));
1039 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("string", NULL));
1040 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("binary", NULL));
1041 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("dict", NULL));
1042 EXPECT_TRUE(main_dict.GetListWithoutPathExpansion("list", NULL));
1043 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("DNE", NULL));
1045 EXPECT_TRUE(main_list.Get(0, NULL));
1046 EXPECT_TRUE(main_list.Get(1, NULL));
1047 EXPECT_TRUE(main_list.Get(2, NULL));
1048 EXPECT_TRUE(main_list.Get(3, NULL));
1049 EXPECT_TRUE(main_list.Get(4, NULL));
1050 EXPECT_TRUE(main_list.Get(5, NULL));
1051 EXPECT_TRUE(main_list.Get(6, NULL));
1052 EXPECT_FALSE(main_list.Get(7, NULL));
1054 EXPECT_TRUE(main_list.GetBoolean(0, NULL));
1055 EXPECT_FALSE(main_list.GetBoolean(1, NULL));
1056 EXPECT_FALSE(main_list.GetBoolean(2, NULL));
1057 EXPECT_FALSE(main_list.GetBoolean(3, NULL));
1058 EXPECT_FALSE(main_list.GetBoolean(4, NULL));
1059 EXPECT_FALSE(main_list.GetBoolean(5, NULL));
1060 EXPECT_FALSE(main_list.GetBoolean(6, NULL));
1061 EXPECT_FALSE(main_list.GetBoolean(7, NULL));
1063 EXPECT_FALSE(main_list.GetInteger(0, NULL));
1064 EXPECT_TRUE(main_list.GetInteger(1, NULL));
1065 EXPECT_FALSE(main_list.GetInteger(2, NULL));
1066 EXPECT_FALSE(main_list.GetInteger(3, NULL));
1067 EXPECT_FALSE(main_list.GetInteger(4, NULL));
1068 EXPECT_FALSE(main_list.GetInteger(5, NULL));
1069 EXPECT_FALSE(main_list.GetInteger(6, NULL));
1070 EXPECT_FALSE(main_list.GetInteger(7, NULL));
1072 EXPECT_FALSE(main_list.GetDouble(0, NULL));
1073 EXPECT_TRUE(main_list.GetDouble(1, NULL));
1074 EXPECT_TRUE(main_list.GetDouble(2, NULL));
1075 EXPECT_FALSE(main_list.GetDouble(3, NULL));
1076 EXPECT_FALSE(main_list.GetDouble(4, NULL));
1077 EXPECT_FALSE(main_list.GetDouble(5, NULL));
1078 EXPECT_FALSE(main_list.GetDouble(6, NULL));
1079 EXPECT_FALSE(main_list.GetDouble(7, NULL));
1081 EXPECT_FALSE(main_list.GetString(0, static_cast<std::string*>(NULL)));
1082 EXPECT_FALSE(main_list.GetString(1, static_cast<std::string*>(NULL)));
1083 EXPECT_FALSE(main_list.GetString(2, static_cast<std::string*>(NULL)));
1084 EXPECT_TRUE(main_list.GetString(3, static_cast<std::string*>(NULL)));
1085 EXPECT_FALSE(main_list.GetString(4, static_cast<std::string*>(NULL)));
1086 EXPECT_FALSE(main_list.GetString(5, static_cast<std::string*>(NULL)));
1087 EXPECT_FALSE(main_list.GetString(6, static_cast<std::string*>(NULL)));
1088 EXPECT_FALSE(main_list.GetString(7, static_cast<std::string*>(NULL)));
1090 EXPECT_FALSE(main_list.GetString(0, static_cast<string16*>(NULL)));
1091 EXPECT_FALSE(main_list.GetString(1, static_cast<string16*>(NULL)));
1092 EXPECT_FALSE(main_list.GetString(2, static_cast<string16*>(NULL)));
1093 EXPECT_TRUE(main_list.GetString(3, static_cast<string16*>(NULL)));
1094 EXPECT_FALSE(main_list.GetString(4, static_cast<string16*>(NULL)));
1095 EXPECT_FALSE(main_list.GetString(5, static_cast<string16*>(NULL)));
1096 EXPECT_FALSE(main_list.GetString(6, static_cast<string16*>(NULL)));
1097 EXPECT_FALSE(main_list.GetString(7, static_cast<string16*>(NULL)));
1099 EXPECT_FALSE(main_list.GetBinary(0, NULL));
1100 EXPECT_FALSE(main_list.GetBinary(1, NULL));
1101 EXPECT_FALSE(main_list.GetBinary(2, NULL));
1102 EXPECT_FALSE(main_list.GetBinary(3, NULL));
1103 EXPECT_TRUE(main_list.GetBinary(4, NULL));
1104 EXPECT_FALSE(main_list.GetBinary(5, NULL));
1105 EXPECT_FALSE(main_list.GetBinary(6, NULL));
1106 EXPECT_FALSE(main_list.GetBinary(7, NULL));
1108 EXPECT_FALSE(main_list.GetDictionary(0, NULL));
1109 EXPECT_FALSE(main_list.GetDictionary(1, NULL));
1110 EXPECT_FALSE(main_list.GetDictionary(2, NULL));
1111 EXPECT_FALSE(main_list.GetDictionary(3, NULL));
1112 EXPECT_FALSE(main_list.GetDictionary(4, NULL));
1113 EXPECT_TRUE(main_list.GetDictionary(5, NULL));
1114 EXPECT_FALSE(main_list.GetDictionary(6, NULL));
1115 EXPECT_FALSE(main_list.GetDictionary(7, NULL));
1117 EXPECT_FALSE(main_list.GetList(0, NULL));
1118 EXPECT_FALSE(main_list.GetList(1, NULL));
1119 EXPECT_FALSE(main_list.GetList(2, NULL));
1120 EXPECT_FALSE(main_list.GetList(3, NULL));
1121 EXPECT_FALSE(main_list.GetList(4, NULL));
1122 EXPECT_FALSE(main_list.GetList(5, NULL));
1123 EXPECT_TRUE(main_list.GetList(6, NULL));
1124 EXPECT_FALSE(main_list.GetList(7, NULL));
1127 } // namespace base