Ensure low-memory renderers retry failed loads correctly.
[chromium-blink-merge.git] / base / values_unittest.cc
blob37ed7cecb7e723223fa45f015b20e80f1ff83cee
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.SetBoolean("global", 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 scoped_ptr<ListValue> new_toolbar_bookmarks(new ListValue);
37 settings.Set("global.toolbar.bookmarks", new_toolbar_bookmarks.Pass());
38 ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks));
40 scoped_ptr<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.Pass());
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, make_scoped_ptr(new FundamentalValue(true)));
61 mixed_list->Set(1, make_scoped_ptr(new FundamentalValue(42)));
62 mixed_list->Set(2, make_scoped_ptr(new FundamentalValue(88.8)));
63 mixed_list->Set(3, make_scoped_ptr(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 scoped_ptr<char[]> buffer(new char[15]);
116 char* original_buffer = buffer.get();
117 binary.reset(new BinaryValue(buffer.Pass(), 15));
118 ASSERT_TRUE(binary.get());
119 ASSERT_TRUE(binary->GetBuffer());
120 ASSERT_EQ(original_buffer, binary->GetBuffer());
121 ASSERT_EQ(15U, binary->GetSize());
123 char stack_buffer[42];
124 memset(stack_buffer, '!', 42);
125 binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42));
126 ASSERT_TRUE(binary.get());
127 ASSERT_TRUE(binary->GetBuffer());
128 ASSERT_NE(stack_buffer, binary->GetBuffer());
129 ASSERT_EQ(42U, binary->GetSize());
130 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize()));
132 // Test overloaded GetAsBinary.
133 Value* narrow_value = binary.get();
134 const BinaryValue* narrow_binary = NULL;
135 ASSERT_TRUE(narrow_value->GetAsBinary(&narrow_binary));
136 EXPECT_EQ(binary.get(), narrow_binary);
139 TEST(ValuesTest, StringValue) {
140 // Test overloaded StringValue constructor.
141 scoped_ptr<Value> narrow_value(new StringValue("narrow"));
142 ASSERT_TRUE(narrow_value.get());
143 ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING));
144 scoped_ptr<Value> utf16_value(new StringValue(ASCIIToUTF16("utf16")));
145 ASSERT_TRUE(utf16_value.get());
146 ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING));
148 // Test overloaded GetAsString.
149 std::string narrow = "http://google.com";
150 string16 utf16 = ASCIIToUTF16("http://google.com");
151 const StringValue* string_value = NULL;
152 ASSERT_TRUE(narrow_value->GetAsString(&narrow));
153 ASSERT_TRUE(narrow_value->GetAsString(&utf16));
154 ASSERT_TRUE(narrow_value->GetAsString(&string_value));
155 ASSERT_EQ(std::string("narrow"), narrow);
156 ASSERT_EQ(ASCIIToUTF16("narrow"), utf16);
157 ASSERT_EQ(string_value->GetString(), narrow);
159 ASSERT_TRUE(utf16_value->GetAsString(&narrow));
160 ASSERT_TRUE(utf16_value->GetAsString(&utf16));
161 ASSERT_TRUE(utf16_value->GetAsString(&string_value));
162 ASSERT_EQ(std::string("utf16"), narrow);
163 ASSERT_EQ(ASCIIToUTF16("utf16"), utf16);
164 ASSERT_EQ(string_value->GetString(), narrow);
166 // Don't choke on NULL values.
167 ASSERT_TRUE(narrow_value->GetAsString(static_cast<string16*>(NULL)));
168 ASSERT_TRUE(narrow_value->GetAsString(static_cast<std::string*>(NULL)));
169 ASSERT_TRUE(narrow_value->GetAsString(
170 static_cast<const StringValue**>(NULL)));
173 // This is a Value object that allows us to tell if it's been
174 // properly deleted by modifying the value of external flag on destruction.
175 class DeletionTestValue : public Value {
176 public:
177 explicit DeletionTestValue(bool* deletion_flag) : Value(TYPE_NULL) {
178 Init(deletion_flag); // Separate function so that we can use ASSERT_*
181 void Init(bool* deletion_flag) {
182 ASSERT_TRUE(deletion_flag);
183 deletion_flag_ = deletion_flag;
184 *deletion_flag_ = false;
187 ~DeletionTestValue() override { *deletion_flag_ = true; }
189 private:
190 bool* deletion_flag_;
193 TEST(ValuesTest, ListDeletion) {
194 bool deletion_flag = true;
197 ListValue list;
198 list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag)));
199 EXPECT_FALSE(deletion_flag);
201 EXPECT_TRUE(deletion_flag);
204 ListValue list;
205 list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag)));
206 EXPECT_FALSE(deletion_flag);
207 list.Clear();
208 EXPECT_TRUE(deletion_flag);
212 ListValue list;
213 list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag)));
214 EXPECT_FALSE(deletion_flag);
215 EXPECT_TRUE(list.Set(0, Value::CreateNullValue()));
216 EXPECT_TRUE(deletion_flag);
220 TEST(ValuesTest, ListRemoval) {
221 bool deletion_flag = true;
222 scoped_ptr<Value> removed_item;
225 ListValue list;
226 list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag)));
227 EXPECT_FALSE(deletion_flag);
228 EXPECT_EQ(1U, list.GetSize());
229 EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(),
230 &removed_item));
231 EXPECT_FALSE(list.Remove(1, &removed_item));
232 EXPECT_TRUE(list.Remove(0, &removed_item));
233 ASSERT_TRUE(removed_item);
234 EXPECT_EQ(0U, list.GetSize());
236 EXPECT_FALSE(deletion_flag);
237 removed_item.reset();
238 EXPECT_TRUE(deletion_flag);
241 ListValue list;
242 list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag)));
243 EXPECT_FALSE(deletion_flag);
244 EXPECT_TRUE(list.Remove(0, NULL));
245 EXPECT_TRUE(deletion_flag);
246 EXPECT_EQ(0U, list.GetSize());
250 ListValue list;
251 scoped_ptr<DeletionTestValue> value(new DeletionTestValue(&deletion_flag));
252 DeletionTestValue* original_value = value.get();
253 list.Append(value.Pass());
254 EXPECT_FALSE(deletion_flag);
255 size_t index = 0;
256 list.Remove(*original_value, &index);
257 EXPECT_EQ(0U, index);
258 EXPECT_TRUE(deletion_flag);
259 EXPECT_EQ(0U, list.GetSize());
263 TEST(ValuesTest, DictionaryDeletion) {
264 std::string key = "test";
265 bool deletion_flag = true;
268 DictionaryValue dict;
269 dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag)));
270 EXPECT_FALSE(deletion_flag);
272 EXPECT_TRUE(deletion_flag);
275 DictionaryValue dict;
276 dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag)));
277 EXPECT_FALSE(deletion_flag);
278 dict.Clear();
279 EXPECT_TRUE(deletion_flag);
283 DictionaryValue dict;
284 dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag)));
285 EXPECT_FALSE(deletion_flag);
286 dict.Set(key, Value::CreateNullValue());
287 EXPECT_TRUE(deletion_flag);
291 TEST(ValuesTest, DictionaryRemoval) {
292 std::string key = "test";
293 bool deletion_flag = true;
294 scoped_ptr<Value> removed_item;
297 DictionaryValue dict;
298 dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag)));
299 EXPECT_FALSE(deletion_flag);
300 EXPECT_TRUE(dict.HasKey(key));
301 EXPECT_FALSE(dict.Remove("absent key", &removed_item));
302 EXPECT_TRUE(dict.Remove(key, &removed_item));
303 EXPECT_FALSE(dict.HasKey(key));
304 ASSERT_TRUE(removed_item);
306 EXPECT_FALSE(deletion_flag);
307 removed_item.reset();
308 EXPECT_TRUE(deletion_flag);
311 DictionaryValue dict;
312 dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag)));
313 EXPECT_FALSE(deletion_flag);
314 EXPECT_TRUE(dict.HasKey(key));
315 EXPECT_TRUE(dict.Remove(key, NULL));
316 EXPECT_TRUE(deletion_flag);
317 EXPECT_FALSE(dict.HasKey(key));
321 TEST(ValuesTest, DictionaryWithoutPathExpansion) {
322 DictionaryValue dict;
323 dict.Set("this.is.expanded", Value::CreateNullValue());
324 dict.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue());
326 EXPECT_FALSE(dict.HasKey("this.is.expanded"));
327 EXPECT_TRUE(dict.HasKey("this"));
328 Value* value1;
329 EXPECT_TRUE(dict.Get("this", &value1));
330 DictionaryValue* value2;
331 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2));
332 EXPECT_EQ(value1, value2);
333 EXPECT_EQ(1U, value2->size());
335 EXPECT_TRUE(dict.HasKey("this.isnt.expanded"));
336 Value* value3;
337 EXPECT_FALSE(dict.Get("this.isnt.expanded", &value3));
338 Value* value4;
339 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4));
340 EXPECT_EQ(Value::TYPE_NULL, value4->GetType());
343 // Tests the deprecated version of SetWithoutPathExpansion.
344 // TODO(estade): remove.
345 TEST(ValuesTest, DictionaryWithoutPathExpansionDeprecated) {
346 DictionaryValue dict;
347 dict.Set("this.is.expanded", Value::CreateNullValue());
348 dict.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue());
350 EXPECT_FALSE(dict.HasKey("this.is.expanded"));
351 EXPECT_TRUE(dict.HasKey("this"));
352 Value* value1;
353 EXPECT_TRUE(dict.Get("this", &value1));
354 DictionaryValue* value2;
355 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2));
356 EXPECT_EQ(value1, value2);
357 EXPECT_EQ(1U, value2->size());
359 EXPECT_TRUE(dict.HasKey("this.isnt.expanded"));
360 Value* value3;
361 EXPECT_FALSE(dict.Get("this.isnt.expanded", &value3));
362 Value* value4;
363 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4));
364 EXPECT_EQ(Value::TYPE_NULL, value4->GetType());
367 TEST(ValuesTest, DictionaryRemovePath) {
368 DictionaryValue dict;
369 dict.SetInteger("a.long.way.down", 1);
370 dict.SetBoolean("a.long.key.path", true);
372 scoped_ptr<Value> removed_item;
373 EXPECT_TRUE(dict.RemovePath("a.long.way.down", &removed_item));
374 ASSERT_TRUE(removed_item);
375 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_INTEGER));
376 EXPECT_FALSE(dict.HasKey("a.long.way.down"));
377 EXPECT_FALSE(dict.HasKey("a.long.way"));
378 EXPECT_TRUE(dict.Get("a.long.key.path", NULL));
380 removed_item.reset();
381 EXPECT_FALSE(dict.RemovePath("a.long.way.down", &removed_item));
382 EXPECT_FALSE(removed_item);
383 EXPECT_TRUE(dict.Get("a.long.key.path", NULL));
385 removed_item.reset();
386 EXPECT_TRUE(dict.RemovePath("a.long.key.path", &removed_item));
387 ASSERT_TRUE(removed_item);
388 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_BOOLEAN));
389 EXPECT_TRUE(dict.empty());
392 TEST(ValuesTest, DeepCopy) {
393 DictionaryValue original_dict;
394 scoped_ptr<Value> scoped_null = Value::CreateNullValue();
395 Value* original_null = scoped_null.get();
396 original_dict.Set("null", scoped_null.Pass());
397 scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true));
398 FundamentalValue* original_bool = scoped_bool.get();
399 original_dict.Set("bool", scoped_bool.Pass());
400 scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42));
401 FundamentalValue* original_int = scoped_int.get();
402 original_dict.Set("int", scoped_int.Pass());
403 scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14));
404 FundamentalValue* original_double = scoped_double.get();
405 original_dict.Set("double", scoped_double.Pass());
406 scoped_ptr<StringValue> scoped_string(new StringValue("hello"));
407 StringValue* original_string = scoped_string.get();
408 original_dict.Set("string", scoped_string.Pass());
409 scoped_ptr<StringValue> scoped_string16(
410 new StringValue(ASCIIToUTF16("hello16")));
411 StringValue* original_string16 = scoped_string16.get();
412 original_dict.Set("string16", scoped_string16.Pass());
414 scoped_ptr<char[]> original_buffer(new char[42]);
415 memset(original_buffer.get(), '!', 42);
416 scoped_ptr<BinaryValue> scoped_binary(
417 new BinaryValue(original_buffer.Pass(), 42));
418 BinaryValue* original_binary = scoped_binary.get();
419 original_dict.Set("binary", scoped_binary.Pass());
421 scoped_ptr<ListValue> scoped_list(new ListValue());
422 Value* original_list = scoped_list.get();
423 scoped_ptr<FundamentalValue> scoped_list_element_0(new FundamentalValue(0));
424 Value* original_list_element_0 = scoped_list_element_0.get();
425 scoped_list->Append(scoped_list_element_0.Pass());
426 scoped_ptr<FundamentalValue> scoped_list_element_1(new FundamentalValue(1));
427 Value* original_list_element_1 = scoped_list_element_1.get();
428 scoped_list->Append(scoped_list_element_1.Pass());
429 original_dict.Set("list", scoped_list.Pass());
431 scoped_ptr<DictionaryValue> scoped_nested_dictionary(new DictionaryValue());
432 Value* original_nested_dictionary = scoped_nested_dictionary.get();
433 scoped_nested_dictionary->SetString("key", "value");
434 original_dict.Set("dictionary", scoped_nested_dictionary.Pass());
436 scoped_ptr<DictionaryValue> copy_dict = original_dict.CreateDeepCopy();
437 ASSERT_TRUE(copy_dict.get());
438 ASSERT_NE(copy_dict.get(), &original_dict);
440 Value* copy_null = NULL;
441 ASSERT_TRUE(copy_dict->Get("null", &copy_null));
442 ASSERT_TRUE(copy_null);
443 ASSERT_NE(copy_null, original_null);
444 ASSERT_TRUE(copy_null->IsType(Value::TYPE_NULL));
446 Value* copy_bool = NULL;
447 ASSERT_TRUE(copy_dict->Get("bool", &copy_bool));
448 ASSERT_TRUE(copy_bool);
449 ASSERT_NE(copy_bool, original_bool);
450 ASSERT_TRUE(copy_bool->IsType(Value::TYPE_BOOLEAN));
451 bool copy_bool_value = false;
452 ASSERT_TRUE(copy_bool->GetAsBoolean(&copy_bool_value));
453 ASSERT_TRUE(copy_bool_value);
455 Value* copy_int = NULL;
456 ASSERT_TRUE(copy_dict->Get("int", &copy_int));
457 ASSERT_TRUE(copy_int);
458 ASSERT_NE(copy_int, original_int);
459 ASSERT_TRUE(copy_int->IsType(Value::TYPE_INTEGER));
460 int copy_int_value = 0;
461 ASSERT_TRUE(copy_int->GetAsInteger(&copy_int_value));
462 ASSERT_EQ(42, copy_int_value);
464 Value* copy_double = NULL;
465 ASSERT_TRUE(copy_dict->Get("double", &copy_double));
466 ASSERT_TRUE(copy_double);
467 ASSERT_NE(copy_double, original_double);
468 ASSERT_TRUE(copy_double->IsType(Value::TYPE_DOUBLE));
469 double copy_double_value = 0;
470 ASSERT_TRUE(copy_double->GetAsDouble(&copy_double_value));
471 ASSERT_EQ(3.14, copy_double_value);
473 Value* copy_string = NULL;
474 ASSERT_TRUE(copy_dict->Get("string", &copy_string));
475 ASSERT_TRUE(copy_string);
476 ASSERT_NE(copy_string, original_string);
477 ASSERT_TRUE(copy_string->IsType(Value::TYPE_STRING));
478 std::string copy_string_value;
479 string16 copy_string16_value;
480 ASSERT_TRUE(copy_string->GetAsString(&copy_string_value));
481 ASSERT_TRUE(copy_string->GetAsString(&copy_string16_value));
482 ASSERT_EQ(std::string("hello"), copy_string_value);
483 ASSERT_EQ(ASCIIToUTF16("hello"), copy_string16_value);
485 Value* copy_string16 = NULL;
486 ASSERT_TRUE(copy_dict->Get("string16", &copy_string16));
487 ASSERT_TRUE(copy_string16);
488 ASSERT_NE(copy_string16, original_string16);
489 ASSERT_TRUE(copy_string16->IsType(Value::TYPE_STRING));
490 ASSERT_TRUE(copy_string16->GetAsString(&copy_string_value));
491 ASSERT_TRUE(copy_string16->GetAsString(&copy_string16_value));
492 ASSERT_EQ(std::string("hello16"), copy_string_value);
493 ASSERT_EQ(ASCIIToUTF16("hello16"), copy_string16_value);
495 Value* copy_binary = NULL;
496 ASSERT_TRUE(copy_dict->Get("binary", &copy_binary));
497 ASSERT_TRUE(copy_binary);
498 ASSERT_NE(copy_binary, original_binary);
499 ASSERT_TRUE(copy_binary->IsType(Value::TYPE_BINARY));
500 ASSERT_NE(original_binary->GetBuffer(),
501 static_cast<BinaryValue*>(copy_binary)->GetBuffer());
502 ASSERT_EQ(original_binary->GetSize(),
503 static_cast<BinaryValue*>(copy_binary)->GetSize());
504 ASSERT_EQ(0, memcmp(original_binary->GetBuffer(),
505 static_cast<BinaryValue*>(copy_binary)->GetBuffer(),
506 original_binary->GetSize()));
508 Value* copy_value = NULL;
509 ASSERT_TRUE(copy_dict->Get("list", &copy_value));
510 ASSERT_TRUE(copy_value);
511 ASSERT_NE(copy_value, original_list);
512 ASSERT_TRUE(copy_value->IsType(Value::TYPE_LIST));
513 ListValue* copy_list = NULL;
514 ASSERT_TRUE(copy_value->GetAsList(&copy_list));
515 ASSERT_TRUE(copy_list);
516 ASSERT_EQ(2U, copy_list->GetSize());
518 Value* copy_list_element_0;
519 ASSERT_TRUE(copy_list->Get(0, &copy_list_element_0));
520 ASSERT_TRUE(copy_list_element_0);
521 ASSERT_NE(copy_list_element_0, original_list_element_0);
522 int copy_list_element_0_value;
523 ASSERT_TRUE(copy_list_element_0->GetAsInteger(&copy_list_element_0_value));
524 ASSERT_EQ(0, copy_list_element_0_value);
526 Value* copy_list_element_1;
527 ASSERT_TRUE(copy_list->Get(1, &copy_list_element_1));
528 ASSERT_TRUE(copy_list_element_1);
529 ASSERT_NE(copy_list_element_1, original_list_element_1);
530 int copy_list_element_1_value;
531 ASSERT_TRUE(copy_list_element_1->GetAsInteger(&copy_list_element_1_value));
532 ASSERT_EQ(1, copy_list_element_1_value);
534 copy_value = NULL;
535 ASSERT_TRUE(copy_dict->Get("dictionary", &copy_value));
536 ASSERT_TRUE(copy_value);
537 ASSERT_NE(copy_value, original_nested_dictionary);
538 ASSERT_TRUE(copy_value->IsType(Value::TYPE_DICTIONARY));
539 DictionaryValue* copy_nested_dictionary = NULL;
540 ASSERT_TRUE(copy_value->GetAsDictionary(&copy_nested_dictionary));
541 ASSERT_TRUE(copy_nested_dictionary);
542 EXPECT_TRUE(copy_nested_dictionary->HasKey("key"));
545 TEST(ValuesTest, Equals) {
546 scoped_ptr<Value> null1(Value::CreateNullValue());
547 scoped_ptr<Value> null2(Value::CreateNullValue());
548 EXPECT_NE(null1.get(), null2.get());
549 EXPECT_TRUE(null1->Equals(null2.get()));
551 FundamentalValue boolean(false);
552 EXPECT_FALSE(null1->Equals(&boolean));
554 DictionaryValue dv;
555 dv.SetBoolean("a", false);
556 dv.SetInteger("b", 2);
557 dv.SetDouble("c", 2.5);
558 dv.SetString("d1", "string");
559 dv.SetString("d2", ASCIIToUTF16("http://google.com"));
560 dv.Set("e", Value::CreateNullValue());
562 scoped_ptr<DictionaryValue> copy = dv.CreateDeepCopy();
563 EXPECT_TRUE(dv.Equals(copy.get()));
565 scoped_ptr<ListValue> list(new ListValue);
566 ListValue* original_list = list.get();
567 list->Append(Value::CreateNullValue());
568 list->Append(make_scoped_ptr(new DictionaryValue));
569 scoped_ptr<Value> list_copy(list->CreateDeepCopy());
571 dv.Set("f", list.Pass());
572 EXPECT_FALSE(dv.Equals(copy.get()));
573 copy->Set("f", list_copy.Pass());
574 EXPECT_TRUE(dv.Equals(copy.get()));
576 original_list->Append(make_scoped_ptr(new FundamentalValue(true)));
577 EXPECT_FALSE(dv.Equals(copy.get()));
579 // Check if Equals detects differences in only the keys.
580 copy = dv.CreateDeepCopy();
581 EXPECT_TRUE(dv.Equals(copy.get()));
582 copy->Remove("a", NULL);
583 copy->SetBoolean("aa", false);
584 EXPECT_FALSE(dv.Equals(copy.get()));
587 TEST(ValuesTest, StaticEquals) {
588 scoped_ptr<Value> null1(Value::CreateNullValue());
589 scoped_ptr<Value> null2(Value::CreateNullValue());
590 EXPECT_TRUE(Value::Equals(null1.get(), null2.get()));
591 EXPECT_TRUE(Value::Equals(NULL, NULL));
593 scoped_ptr<Value> i42(new FundamentalValue(42));
594 scoped_ptr<Value> j42(new FundamentalValue(42));
595 scoped_ptr<Value> i17(new FundamentalValue(17));
596 EXPECT_TRUE(Value::Equals(i42.get(), i42.get()));
597 EXPECT_TRUE(Value::Equals(j42.get(), i42.get()));
598 EXPECT_TRUE(Value::Equals(i42.get(), j42.get()));
599 EXPECT_FALSE(Value::Equals(i42.get(), i17.get()));
600 EXPECT_FALSE(Value::Equals(i42.get(), NULL));
601 EXPECT_FALSE(Value::Equals(NULL, i42.get()));
603 // NULL and Value::CreateNullValue() are intentionally different: We need
604 // support for NULL as a return value for "undefined" without caring for
605 // ownership of the pointer.
606 EXPECT_FALSE(Value::Equals(null1.get(), NULL));
607 EXPECT_FALSE(Value::Equals(NULL, null1.get()));
610 TEST(ValuesTest, DeepCopyCovariantReturnTypes) {
611 DictionaryValue original_dict;
612 scoped_ptr<Value> scoped_null(Value::CreateNullValue());
613 Value* original_null = scoped_null.get();
614 original_dict.Set("null", scoped_null.Pass());
615 scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true));
616 Value* original_bool = scoped_bool.get();
617 original_dict.Set("bool", scoped_bool.Pass());
618 scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42));
619 Value* original_int = scoped_int.get();
620 original_dict.Set("int", scoped_int.Pass());
621 scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14));
622 Value* original_double = scoped_double.get();
623 original_dict.Set("double", scoped_double.Pass());
624 scoped_ptr<StringValue> scoped_string(new StringValue("hello"));
625 Value* original_string = scoped_string.get();
626 original_dict.Set("string", scoped_string.Pass());
627 scoped_ptr<StringValue> scoped_string16(
628 new StringValue(ASCIIToUTF16("hello16")));
629 Value* original_string16 = scoped_string16.get();
630 original_dict.Set("string16", scoped_string16.Pass());
632 scoped_ptr<char[]> original_buffer(new char[42]);
633 memset(original_buffer.get(), '!', 42);
634 scoped_ptr<BinaryValue> scoped_binary(
635 new BinaryValue(original_buffer.Pass(), 42));
636 Value* original_binary = scoped_binary.get();
637 original_dict.Set("binary", scoped_binary.Pass());
639 scoped_ptr<ListValue> scoped_list(new ListValue());
640 Value* original_list = scoped_list.get();
641 scoped_ptr<FundamentalValue> scoped_list_element_0(new FundamentalValue(0));
642 scoped_list->Append(scoped_list_element_0.Pass());
643 scoped_ptr<FundamentalValue> scoped_list_element_1(new FundamentalValue(1));
644 scoped_list->Append(scoped_list_element_1.Pass());
645 original_dict.Set("list", scoped_list.Pass());
647 scoped_ptr<Value> copy_dict = original_dict.CreateDeepCopy();
648 scoped_ptr<Value> copy_null = original_null->CreateDeepCopy();
649 scoped_ptr<Value> copy_bool = original_bool->CreateDeepCopy();
650 scoped_ptr<Value> copy_int = original_int->CreateDeepCopy();
651 scoped_ptr<Value> copy_double = original_double->CreateDeepCopy();
652 scoped_ptr<Value> copy_string = original_string->CreateDeepCopy();
653 scoped_ptr<Value> copy_string16 = original_string16->CreateDeepCopy();
654 scoped_ptr<Value> copy_binary = original_binary->CreateDeepCopy();
655 scoped_ptr<Value> copy_list = original_list->CreateDeepCopy();
657 EXPECT_TRUE(original_dict.Equals(copy_dict.get()));
658 EXPECT_TRUE(original_null->Equals(copy_null.get()));
659 EXPECT_TRUE(original_bool->Equals(copy_bool.get()));
660 EXPECT_TRUE(original_int->Equals(copy_int.get()));
661 EXPECT_TRUE(original_double->Equals(copy_double.get()));
662 EXPECT_TRUE(original_string->Equals(copy_string.get()));
663 EXPECT_TRUE(original_string16->Equals(copy_string16.get()));
664 EXPECT_TRUE(original_binary->Equals(copy_binary.get()));
665 EXPECT_TRUE(original_list->Equals(copy_list.get()));
668 TEST(ValuesTest, RemoveEmptyChildren) {
669 scoped_ptr<DictionaryValue> root(new DictionaryValue);
670 // Remove empty lists and dictionaries.
671 root->Set("empty_dict", make_scoped_ptr(new DictionaryValue));
672 root->Set("empty_list", make_scoped_ptr(new ListValue));
673 root->SetWithoutPathExpansion("a.b.c.d.e",
674 make_scoped_ptr(new DictionaryValue));
675 root = root->DeepCopyWithoutEmptyChildren();
676 EXPECT_TRUE(root->empty());
678 // Make sure we don't prune too much.
679 root->SetBoolean("bool", true);
680 root->Set("empty_dict", make_scoped_ptr(new DictionaryValue));
681 root->SetString("empty_string", std::string());
682 root = root->DeepCopyWithoutEmptyChildren();
683 EXPECT_EQ(2U, root->size());
685 // Should do nothing.
686 root = root->DeepCopyWithoutEmptyChildren();
687 EXPECT_EQ(2U, root->size());
689 // Nested test cases. These should all reduce back to the bool and string
690 // set above.
692 root->Set("a.b.c.d.e", make_scoped_ptr(new DictionaryValue));
693 root = root->DeepCopyWithoutEmptyChildren();
694 EXPECT_EQ(2U, root->size());
697 scoped_ptr<DictionaryValue> inner(new DictionaryValue);
698 inner->Set("empty_dict", make_scoped_ptr(new DictionaryValue));
699 inner->Set("empty_list", make_scoped_ptr(new ListValue));
700 root->Set("dict_with_empty_children", inner.Pass());
701 root = root->DeepCopyWithoutEmptyChildren();
702 EXPECT_EQ(2U, root->size());
705 scoped_ptr<ListValue> inner(new ListValue);
706 inner->Append(make_scoped_ptr(new DictionaryValue));
707 inner->Append(make_scoped_ptr(new ListValue));
708 root->Set("list_with_empty_children", inner.Pass());
709 root = root->DeepCopyWithoutEmptyChildren();
710 EXPECT_EQ(2U, root->size());
713 // Nested with siblings.
715 scoped_ptr<ListValue> inner(new ListValue());
716 inner->Append(make_scoped_ptr(new DictionaryValue));
717 inner->Append(make_scoped_ptr(new ListValue));
718 root->Set("list_with_empty_children", inner.Pass());
719 scoped_ptr<DictionaryValue> inner2(new DictionaryValue);
720 inner2->Set("empty_dict", make_scoped_ptr(new DictionaryValue));
721 inner2->Set("empty_list", make_scoped_ptr(new ListValue));
722 root->Set("dict_with_empty_children", inner2.Pass());
723 root = root->DeepCopyWithoutEmptyChildren();
724 EXPECT_EQ(2U, root->size());
727 // Make sure nested values don't get pruned.
729 scoped_ptr<ListValue> inner(new ListValue);
730 scoped_ptr<ListValue> inner2(new ListValue);
731 inner2->Append(make_scoped_ptr(new StringValue("hello")));
732 inner->Append(make_scoped_ptr(new DictionaryValue));
733 inner->Append(inner2.Pass());
734 root->Set("list_with_empty_children", inner.Pass());
735 root = root->DeepCopyWithoutEmptyChildren();
736 EXPECT_EQ(3U, root->size());
738 ListValue* inner_value, *inner_value2;
739 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner_value));
740 EXPECT_EQ(1U, inner_value->GetSize()); // Dictionary was pruned.
741 EXPECT_TRUE(inner_value->GetList(0, &inner_value2));
742 EXPECT_EQ(1U, inner_value2->GetSize());
746 TEST(ValuesTest, MergeDictionary) {
747 scoped_ptr<DictionaryValue> base(new DictionaryValue);
748 base->SetString("base_key", "base_key_value_base");
749 base->SetString("collide_key", "collide_key_value_base");
750 scoped_ptr<DictionaryValue> base_sub_dict(new DictionaryValue);
751 base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base");
752 base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base");
753 base->Set("sub_dict_key", base_sub_dict.Pass());
755 scoped_ptr<DictionaryValue> merge(new DictionaryValue);
756 merge->SetString("merge_key", "merge_key_value_merge");
757 merge->SetString("collide_key", "collide_key_value_merge");
758 scoped_ptr<DictionaryValue> merge_sub_dict(new DictionaryValue);
759 merge_sub_dict->SetString("sub_merge_key", "sub_merge_key_value_merge");
760 merge_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_merge");
761 merge->Set("sub_dict_key", merge_sub_dict.Pass());
763 base->MergeDictionary(merge.get());
765 EXPECT_EQ(4U, base->size());
766 std::string base_key_value;
767 EXPECT_TRUE(base->GetString("base_key", &base_key_value));
768 EXPECT_EQ("base_key_value_base", base_key_value); // Base value preserved.
769 std::string collide_key_value;
770 EXPECT_TRUE(base->GetString("collide_key", &collide_key_value));
771 EXPECT_EQ("collide_key_value_merge", collide_key_value); // Replaced.
772 std::string merge_key_value;
773 EXPECT_TRUE(base->GetString("merge_key", &merge_key_value));
774 EXPECT_EQ("merge_key_value_merge", merge_key_value); // Merged in.
776 DictionaryValue* res_sub_dict;
777 EXPECT_TRUE(base->GetDictionary("sub_dict_key", &res_sub_dict));
778 EXPECT_EQ(3U, res_sub_dict->size());
779 std::string sub_base_key_value;
780 EXPECT_TRUE(res_sub_dict->GetString("sub_base_key", &sub_base_key_value));
781 EXPECT_EQ("sub_base_key_value_base", sub_base_key_value); // Preserved.
782 std::string sub_collide_key_value;
783 EXPECT_TRUE(res_sub_dict->GetString("sub_collide_key",
784 &sub_collide_key_value));
785 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced.
786 std::string sub_merge_key_value;
787 EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value));
788 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in.
791 TEST(ValuesTest, MergeDictionaryDeepCopy) {
792 scoped_ptr<DictionaryValue> child(new DictionaryValue);
793 DictionaryValue* original_child = child.get();
794 child->SetString("test", "value");
795 EXPECT_EQ(1U, child->size());
797 std::string value;
798 EXPECT_TRUE(child->GetString("test", &value));
799 EXPECT_EQ("value", value);
801 scoped_ptr<DictionaryValue> base(new DictionaryValue);
802 base->Set("dict", child.Pass());
803 EXPECT_EQ(1U, base->size());
805 DictionaryValue* ptr;
806 EXPECT_TRUE(base->GetDictionary("dict", &ptr));
807 EXPECT_EQ(original_child, ptr);
809 scoped_ptr<DictionaryValue> merged(new DictionaryValue);
810 merged->MergeDictionary(base.get());
811 EXPECT_EQ(1U, merged->size());
812 EXPECT_TRUE(merged->GetDictionary("dict", &ptr));
813 EXPECT_NE(original_child, ptr);
814 EXPECT_TRUE(ptr->GetString("test", &value));
815 EXPECT_EQ("value", value);
817 original_child->SetString("test", "overwrite");
818 base.reset();
819 EXPECT_TRUE(ptr->GetString("test", &value));
820 EXPECT_EQ("value", value);
823 TEST(ValuesTest, DictionaryIterator) {
824 DictionaryValue dict;
825 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
826 ADD_FAILURE();
829 StringValue value1("value1");
830 dict.Set("key1", value1.CreateDeepCopy());
831 bool seen1 = false;
832 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
833 EXPECT_FALSE(seen1);
834 EXPECT_EQ("key1", it.key());
835 EXPECT_TRUE(value1.Equals(&it.value()));
836 seen1 = true;
838 EXPECT_TRUE(seen1);
840 StringValue value2("value2");
841 dict.Set("key2", value2.CreateDeepCopy());
842 bool seen2 = seen1 = false;
843 for (DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
844 if (it.key() == "key1") {
845 EXPECT_FALSE(seen1);
846 EXPECT_TRUE(value1.Equals(&it.value()));
847 seen1 = true;
848 } else if (it.key() == "key2") {
849 EXPECT_FALSE(seen2);
850 EXPECT_TRUE(value2.Equals(&it.value()));
851 seen2 = true;
852 } else {
853 ADD_FAILURE();
856 EXPECT_TRUE(seen1);
857 EXPECT_TRUE(seen2);
860 // DictionaryValue/ListValue's Get*() methods should accept NULL as an out-value
861 // and still return true/false based on success.
862 TEST(ValuesTest, GetWithNullOutValue) {
863 DictionaryValue main_dict;
864 ListValue main_list;
866 FundamentalValue bool_value(false);
867 FundamentalValue int_value(1234);
868 FundamentalValue double_value(12.34567);
869 StringValue string_value("foo");
870 BinaryValue binary_value;
871 DictionaryValue dict_value;
872 ListValue list_value;
874 main_dict.Set("bool", bool_value.CreateDeepCopy());
875 main_dict.Set("int", int_value.CreateDeepCopy());
876 main_dict.Set("double", double_value.CreateDeepCopy());
877 main_dict.Set("string", string_value.CreateDeepCopy());
878 main_dict.Set("binary", binary_value.CreateDeepCopy());
879 main_dict.Set("dict", dict_value.CreateDeepCopy());
880 main_dict.Set("list", list_value.CreateDeepCopy());
882 main_list.Append(bool_value.CreateDeepCopy());
883 main_list.Append(int_value.CreateDeepCopy());
884 main_list.Append(double_value.CreateDeepCopy());
885 main_list.Append(string_value.CreateDeepCopy());
886 main_list.Append(binary_value.CreateDeepCopy());
887 main_list.Append(dict_value.CreateDeepCopy());
888 main_list.Append(list_value.CreateDeepCopy());
890 EXPECT_TRUE(main_dict.Get("bool", NULL));
891 EXPECT_TRUE(main_dict.Get("int", NULL));
892 EXPECT_TRUE(main_dict.Get("double", NULL));
893 EXPECT_TRUE(main_dict.Get("string", NULL));
894 EXPECT_TRUE(main_dict.Get("binary", NULL));
895 EXPECT_TRUE(main_dict.Get("dict", NULL));
896 EXPECT_TRUE(main_dict.Get("list", NULL));
897 EXPECT_FALSE(main_dict.Get("DNE", NULL));
899 EXPECT_TRUE(main_dict.GetBoolean("bool", NULL));
900 EXPECT_FALSE(main_dict.GetBoolean("int", NULL));
901 EXPECT_FALSE(main_dict.GetBoolean("double", NULL));
902 EXPECT_FALSE(main_dict.GetBoolean("string", NULL));
903 EXPECT_FALSE(main_dict.GetBoolean("binary", NULL));
904 EXPECT_FALSE(main_dict.GetBoolean("dict", NULL));
905 EXPECT_FALSE(main_dict.GetBoolean("list", NULL));
906 EXPECT_FALSE(main_dict.GetBoolean("DNE", NULL));
908 EXPECT_FALSE(main_dict.GetInteger("bool", NULL));
909 EXPECT_TRUE(main_dict.GetInteger("int", NULL));
910 EXPECT_FALSE(main_dict.GetInteger("double", NULL));
911 EXPECT_FALSE(main_dict.GetInteger("string", NULL));
912 EXPECT_FALSE(main_dict.GetInteger("binary", NULL));
913 EXPECT_FALSE(main_dict.GetInteger("dict", NULL));
914 EXPECT_FALSE(main_dict.GetInteger("list", NULL));
915 EXPECT_FALSE(main_dict.GetInteger("DNE", NULL));
917 // Both int and double values can be obtained from GetDouble.
918 EXPECT_FALSE(main_dict.GetDouble("bool", NULL));
919 EXPECT_TRUE(main_dict.GetDouble("int", NULL));
920 EXPECT_TRUE(main_dict.GetDouble("double", NULL));
921 EXPECT_FALSE(main_dict.GetDouble("string", NULL));
922 EXPECT_FALSE(main_dict.GetDouble("binary", NULL));
923 EXPECT_FALSE(main_dict.GetDouble("dict", NULL));
924 EXPECT_FALSE(main_dict.GetDouble("list", NULL));
925 EXPECT_FALSE(main_dict.GetDouble("DNE", NULL));
927 EXPECT_FALSE(main_dict.GetString("bool", static_cast<std::string*>(NULL)));
928 EXPECT_FALSE(main_dict.GetString("int", static_cast<std::string*>(NULL)));
929 EXPECT_FALSE(main_dict.GetString("double", static_cast<std::string*>(NULL)));
930 EXPECT_TRUE(main_dict.GetString("string", static_cast<std::string*>(NULL)));
931 EXPECT_FALSE(main_dict.GetString("binary", static_cast<std::string*>(NULL)));
932 EXPECT_FALSE(main_dict.GetString("dict", static_cast<std::string*>(NULL)));
933 EXPECT_FALSE(main_dict.GetString("list", static_cast<std::string*>(NULL)));
934 EXPECT_FALSE(main_dict.GetString("DNE", static_cast<std::string*>(NULL)));
936 EXPECT_FALSE(main_dict.GetString("bool", static_cast<string16*>(NULL)));
937 EXPECT_FALSE(main_dict.GetString("int", static_cast<string16*>(NULL)));
938 EXPECT_FALSE(main_dict.GetString("double", static_cast<string16*>(NULL)));
939 EXPECT_TRUE(main_dict.GetString("string", static_cast<string16*>(NULL)));
940 EXPECT_FALSE(main_dict.GetString("binary", static_cast<string16*>(NULL)));
941 EXPECT_FALSE(main_dict.GetString("dict", static_cast<string16*>(NULL)));
942 EXPECT_FALSE(main_dict.GetString("list", static_cast<string16*>(NULL)));
943 EXPECT_FALSE(main_dict.GetString("DNE", static_cast<string16*>(NULL)));
945 EXPECT_FALSE(main_dict.GetBinary("bool", NULL));
946 EXPECT_FALSE(main_dict.GetBinary("int", NULL));
947 EXPECT_FALSE(main_dict.GetBinary("double", NULL));
948 EXPECT_FALSE(main_dict.GetBinary("string", NULL));
949 EXPECT_TRUE(main_dict.GetBinary("binary", NULL));
950 EXPECT_FALSE(main_dict.GetBinary("dict", NULL));
951 EXPECT_FALSE(main_dict.GetBinary("list", NULL));
952 EXPECT_FALSE(main_dict.GetBinary("DNE", NULL));
954 EXPECT_FALSE(main_dict.GetDictionary("bool", NULL));
955 EXPECT_FALSE(main_dict.GetDictionary("int", NULL));
956 EXPECT_FALSE(main_dict.GetDictionary("double", NULL));
957 EXPECT_FALSE(main_dict.GetDictionary("string", NULL));
958 EXPECT_FALSE(main_dict.GetDictionary("binary", NULL));
959 EXPECT_TRUE(main_dict.GetDictionary("dict", NULL));
960 EXPECT_FALSE(main_dict.GetDictionary("list", NULL));
961 EXPECT_FALSE(main_dict.GetDictionary("DNE", NULL));
963 EXPECT_FALSE(main_dict.GetList("bool", NULL));
964 EXPECT_FALSE(main_dict.GetList("int", NULL));
965 EXPECT_FALSE(main_dict.GetList("double", NULL));
966 EXPECT_FALSE(main_dict.GetList("string", NULL));
967 EXPECT_FALSE(main_dict.GetList("binary", NULL));
968 EXPECT_FALSE(main_dict.GetList("dict", NULL));
969 EXPECT_TRUE(main_dict.GetList("list", NULL));
970 EXPECT_FALSE(main_dict.GetList("DNE", NULL));
972 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("bool", NULL));
973 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("int", NULL));
974 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("double", NULL));
975 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("string", NULL));
976 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("binary", NULL));
977 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("dict", NULL));
978 EXPECT_TRUE(main_dict.GetWithoutPathExpansion("list", NULL));
979 EXPECT_FALSE(main_dict.GetWithoutPathExpansion("DNE", NULL));
981 EXPECT_TRUE(main_dict.GetBooleanWithoutPathExpansion("bool", NULL));
982 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("int", NULL));
983 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("double", NULL));
984 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("string", NULL));
985 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("binary", NULL));
986 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("dict", NULL));
987 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("list", NULL));
988 EXPECT_FALSE(main_dict.GetBooleanWithoutPathExpansion("DNE", NULL));
990 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("bool", NULL));
991 EXPECT_TRUE(main_dict.GetIntegerWithoutPathExpansion("int", NULL));
992 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("double", NULL));
993 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("string", NULL));
994 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("binary", NULL));
995 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("dict", NULL));
996 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("list", NULL));
997 EXPECT_FALSE(main_dict.GetIntegerWithoutPathExpansion("DNE", NULL));
999 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("bool", NULL));
1000 EXPECT_TRUE(main_dict.GetDoubleWithoutPathExpansion("int", NULL));
1001 EXPECT_TRUE(main_dict.GetDoubleWithoutPathExpansion("double", NULL));
1002 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("string", NULL));
1003 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("binary", NULL));
1004 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("dict", NULL));
1005 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("list", NULL));
1006 EXPECT_FALSE(main_dict.GetDoubleWithoutPathExpansion("DNE", NULL));
1008 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1009 "bool", static_cast<std::string*>(NULL)));
1010 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1011 "int", static_cast<std::string*>(NULL)));
1012 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1013 "double", static_cast<std::string*>(NULL)));
1014 EXPECT_TRUE(main_dict.GetStringWithoutPathExpansion(
1015 "string", static_cast<std::string*>(NULL)));
1016 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1017 "binary", static_cast<std::string*>(NULL)));
1018 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1019 "dict", static_cast<std::string*>(NULL)));
1020 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1021 "list", static_cast<std::string*>(NULL)));
1022 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1023 "DNE", static_cast<std::string*>(NULL)));
1025 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1026 "bool", static_cast<string16*>(NULL)));
1027 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1028 "int", static_cast<string16*>(NULL)));
1029 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1030 "double", static_cast<string16*>(NULL)));
1031 EXPECT_TRUE(main_dict.GetStringWithoutPathExpansion(
1032 "string", static_cast<string16*>(NULL)));
1033 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1034 "binary", static_cast<string16*>(NULL)));
1035 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1036 "dict", static_cast<string16*>(NULL)));
1037 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1038 "list", static_cast<string16*>(NULL)));
1039 EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
1040 "DNE", static_cast<string16*>(NULL)));
1042 // There is no GetBinaryWithoutPathExpansion for some reason, but if there
1043 // were it should be tested here...
1045 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("bool", NULL));
1046 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("int", NULL));
1047 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("double", NULL));
1048 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("string", NULL));
1049 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("binary", NULL));
1050 EXPECT_TRUE(main_dict.GetDictionaryWithoutPathExpansion("dict", NULL));
1051 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("list", NULL));
1052 EXPECT_FALSE(main_dict.GetDictionaryWithoutPathExpansion("DNE", NULL));
1054 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("bool", NULL));
1055 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("int", NULL));
1056 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("double", NULL));
1057 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("string", NULL));
1058 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("binary", NULL));
1059 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("dict", NULL));
1060 EXPECT_TRUE(main_dict.GetListWithoutPathExpansion("list", NULL));
1061 EXPECT_FALSE(main_dict.GetListWithoutPathExpansion("DNE", NULL));
1063 EXPECT_TRUE(main_list.Get(0, NULL));
1064 EXPECT_TRUE(main_list.Get(1, NULL));
1065 EXPECT_TRUE(main_list.Get(2, NULL));
1066 EXPECT_TRUE(main_list.Get(3, NULL));
1067 EXPECT_TRUE(main_list.Get(4, NULL));
1068 EXPECT_TRUE(main_list.Get(5, NULL));
1069 EXPECT_TRUE(main_list.Get(6, NULL));
1070 EXPECT_FALSE(main_list.Get(7, NULL));
1072 EXPECT_TRUE(main_list.GetBoolean(0, NULL));
1073 EXPECT_FALSE(main_list.GetBoolean(1, NULL));
1074 EXPECT_FALSE(main_list.GetBoolean(2, NULL));
1075 EXPECT_FALSE(main_list.GetBoolean(3, NULL));
1076 EXPECT_FALSE(main_list.GetBoolean(4, NULL));
1077 EXPECT_FALSE(main_list.GetBoolean(5, NULL));
1078 EXPECT_FALSE(main_list.GetBoolean(6, NULL));
1079 EXPECT_FALSE(main_list.GetBoolean(7, NULL));
1081 EXPECT_FALSE(main_list.GetInteger(0, NULL));
1082 EXPECT_TRUE(main_list.GetInteger(1, NULL));
1083 EXPECT_FALSE(main_list.GetInteger(2, NULL));
1084 EXPECT_FALSE(main_list.GetInteger(3, NULL));
1085 EXPECT_FALSE(main_list.GetInteger(4, NULL));
1086 EXPECT_FALSE(main_list.GetInteger(5, NULL));
1087 EXPECT_FALSE(main_list.GetInteger(6, NULL));
1088 EXPECT_FALSE(main_list.GetInteger(7, NULL));
1090 EXPECT_FALSE(main_list.GetDouble(0, NULL));
1091 EXPECT_TRUE(main_list.GetDouble(1, NULL));
1092 EXPECT_TRUE(main_list.GetDouble(2, NULL));
1093 EXPECT_FALSE(main_list.GetDouble(3, NULL));
1094 EXPECT_FALSE(main_list.GetDouble(4, NULL));
1095 EXPECT_FALSE(main_list.GetDouble(5, NULL));
1096 EXPECT_FALSE(main_list.GetDouble(6, NULL));
1097 EXPECT_FALSE(main_list.GetDouble(7, NULL));
1099 EXPECT_FALSE(main_list.GetString(0, static_cast<std::string*>(NULL)));
1100 EXPECT_FALSE(main_list.GetString(1, static_cast<std::string*>(NULL)));
1101 EXPECT_FALSE(main_list.GetString(2, static_cast<std::string*>(NULL)));
1102 EXPECT_TRUE(main_list.GetString(3, static_cast<std::string*>(NULL)));
1103 EXPECT_FALSE(main_list.GetString(4, static_cast<std::string*>(NULL)));
1104 EXPECT_FALSE(main_list.GetString(5, static_cast<std::string*>(NULL)));
1105 EXPECT_FALSE(main_list.GetString(6, static_cast<std::string*>(NULL)));
1106 EXPECT_FALSE(main_list.GetString(7, static_cast<std::string*>(NULL)));
1108 EXPECT_FALSE(main_list.GetString(0, static_cast<string16*>(NULL)));
1109 EXPECT_FALSE(main_list.GetString(1, static_cast<string16*>(NULL)));
1110 EXPECT_FALSE(main_list.GetString(2, static_cast<string16*>(NULL)));
1111 EXPECT_TRUE(main_list.GetString(3, static_cast<string16*>(NULL)));
1112 EXPECT_FALSE(main_list.GetString(4, static_cast<string16*>(NULL)));
1113 EXPECT_FALSE(main_list.GetString(5, static_cast<string16*>(NULL)));
1114 EXPECT_FALSE(main_list.GetString(6, static_cast<string16*>(NULL)));
1115 EXPECT_FALSE(main_list.GetString(7, static_cast<string16*>(NULL)));
1117 EXPECT_FALSE(main_list.GetBinary(0, NULL));
1118 EXPECT_FALSE(main_list.GetBinary(1, NULL));
1119 EXPECT_FALSE(main_list.GetBinary(2, NULL));
1120 EXPECT_FALSE(main_list.GetBinary(3, NULL));
1121 EXPECT_TRUE(main_list.GetBinary(4, NULL));
1122 EXPECT_FALSE(main_list.GetBinary(5, NULL));
1123 EXPECT_FALSE(main_list.GetBinary(6, NULL));
1124 EXPECT_FALSE(main_list.GetBinary(7, NULL));
1126 EXPECT_FALSE(main_list.GetDictionary(0, NULL));
1127 EXPECT_FALSE(main_list.GetDictionary(1, NULL));
1128 EXPECT_FALSE(main_list.GetDictionary(2, NULL));
1129 EXPECT_FALSE(main_list.GetDictionary(3, NULL));
1130 EXPECT_FALSE(main_list.GetDictionary(4, NULL));
1131 EXPECT_TRUE(main_list.GetDictionary(5, NULL));
1132 EXPECT_FALSE(main_list.GetDictionary(6, NULL));
1133 EXPECT_FALSE(main_list.GetDictionary(7, NULL));
1135 EXPECT_FALSE(main_list.GetList(0, NULL));
1136 EXPECT_FALSE(main_list.GetList(1, NULL));
1137 EXPECT_FALSE(main_list.GetList(2, NULL));
1138 EXPECT_FALSE(main_list.GetList(3, NULL));
1139 EXPECT_FALSE(main_list.GetList(4, NULL));
1140 EXPECT_FALSE(main_list.GetList(5, NULL));
1141 EXPECT_TRUE(main_list.GetList(6, NULL));
1142 EXPECT_FALSE(main_list.GetList(7, NULL));
1145 } // namespace base