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.
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"
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
;
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());
67 bool bool_value
= false;
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
{
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; }
190 bool* deletion_flag_
;
193 TEST(ValuesTest
, ListDeletion
) {
194 bool deletion_flag
= true;
198 list
.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag
)));
199 EXPECT_FALSE(deletion_flag
);
201 EXPECT_TRUE(deletion_flag
);
205 list
.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag
)));
206 EXPECT_FALSE(deletion_flag
);
208 EXPECT_TRUE(deletion_flag
);
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
;
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(),
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
);
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());
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
);
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
);
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", make_scoped_ptr(Value::CreateNullValue()));
324 dict
.SetWithoutPathExpansion("this.isnt.expanded",
325 make_scoped_ptr(Value::CreateNullValue()));
327 EXPECT_FALSE(dict
.HasKey("this.is.expanded"));
328 EXPECT_TRUE(dict
.HasKey("this"));
330 EXPECT_TRUE(dict
.Get("this", &value1
));
331 DictionaryValue
* value2
;
332 ASSERT_TRUE(dict
.GetDictionaryWithoutPathExpansion("this", &value2
));
333 EXPECT_EQ(value1
, value2
);
334 EXPECT_EQ(1U, value2
->size());
336 EXPECT_TRUE(dict
.HasKey("this.isnt.expanded"));
338 EXPECT_FALSE(dict
.Get("this.isnt.expanded", &value3
));
340 ASSERT_TRUE(dict
.GetWithoutPathExpansion("this.isnt.expanded", &value4
));
341 EXPECT_EQ(Value::TYPE_NULL
, value4
->GetType());
344 // Tests the deprecated version of SetWithoutPathExpansion.
345 // TODO(estade): remove.
346 TEST(ValuesTest
, DictionaryWithoutPathExpansionDeprecated
) {
347 DictionaryValue dict
;
348 dict
.Set("this.is.expanded", Value::CreateNullValue());
349 dict
.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue());
351 EXPECT_FALSE(dict
.HasKey("this.is.expanded"));
352 EXPECT_TRUE(dict
.HasKey("this"));
354 EXPECT_TRUE(dict
.Get("this", &value1
));
355 DictionaryValue
* value2
;
356 ASSERT_TRUE(dict
.GetDictionaryWithoutPathExpansion("this", &value2
));
357 EXPECT_EQ(value1
, value2
);
358 EXPECT_EQ(1U, value2
->size());
360 EXPECT_TRUE(dict
.HasKey("this.isnt.expanded"));
362 EXPECT_FALSE(dict
.Get("this.isnt.expanded", &value3
));
364 ASSERT_TRUE(dict
.GetWithoutPathExpansion("this.isnt.expanded", &value4
));
365 EXPECT_EQ(Value::TYPE_NULL
, value4
->GetType());
368 TEST(ValuesTest
, DictionaryRemovePath
) {
369 DictionaryValue dict
;
370 dict
.SetInteger("a.long.way.down", 1);
371 dict
.SetBoolean("a.long.key.path", true);
373 scoped_ptr
<Value
> removed_item
;
374 EXPECT_TRUE(dict
.RemovePath("a.long.way.down", &removed_item
));
375 ASSERT_TRUE(removed_item
);
376 EXPECT_TRUE(removed_item
->IsType(base::Value::TYPE_INTEGER
));
377 EXPECT_FALSE(dict
.HasKey("a.long.way.down"));
378 EXPECT_FALSE(dict
.HasKey("a.long.way"));
379 EXPECT_TRUE(dict
.Get("a.long.key.path", NULL
));
381 removed_item
.reset();
382 EXPECT_FALSE(dict
.RemovePath("a.long.way.down", &removed_item
));
383 EXPECT_FALSE(removed_item
);
384 EXPECT_TRUE(dict
.Get("a.long.key.path", NULL
));
386 removed_item
.reset();
387 EXPECT_TRUE(dict
.RemovePath("a.long.key.path", &removed_item
));
388 ASSERT_TRUE(removed_item
);
389 EXPECT_TRUE(removed_item
->IsType(base::Value::TYPE_BOOLEAN
));
390 EXPECT_TRUE(dict
.empty());
393 TEST(ValuesTest
, DeepCopy
) {
394 DictionaryValue original_dict
;
395 scoped_ptr
<Value
> scoped_null(Value::CreateNullValue());
396 Value
* original_null
= scoped_null
.get();
397 original_dict
.Set("null", scoped_null
.Pass());
398 scoped_ptr
<FundamentalValue
> scoped_bool(new FundamentalValue(true));
399 FundamentalValue
* original_bool
= scoped_bool
.get();
400 original_dict
.Set("bool", scoped_bool
.Pass());
401 scoped_ptr
<FundamentalValue
> scoped_int(new FundamentalValue(42));
402 FundamentalValue
* original_int
= scoped_int
.get();
403 original_dict
.Set("int", scoped_int
.Pass());
404 scoped_ptr
<FundamentalValue
> scoped_double(new FundamentalValue(3.14));
405 FundamentalValue
* original_double
= scoped_double
.get();
406 original_dict
.Set("double", scoped_double
.Pass());
407 scoped_ptr
<StringValue
> scoped_string(new StringValue("hello"));
408 StringValue
* original_string
= scoped_string
.get();
409 original_dict
.Set("string", scoped_string
.Pass());
410 scoped_ptr
<StringValue
> scoped_string16(
411 new StringValue(ASCIIToUTF16("hello16")));
412 StringValue
* original_string16
= scoped_string16
.get();
413 original_dict
.Set("string16", scoped_string16
.Pass());
415 scoped_ptr
<char[]> original_buffer(new char[42]);
416 memset(original_buffer
.get(), '!', 42);
417 scoped_ptr
<BinaryValue
> scoped_binary(
418 new BinaryValue(original_buffer
.Pass(), 42));
419 BinaryValue
* original_binary
= scoped_binary
.get();
420 original_dict
.Set("binary", scoped_binary
.Pass());
422 scoped_ptr
<ListValue
> scoped_list(new ListValue());
423 Value
* original_list
= scoped_list
.get();
424 scoped_ptr
<FundamentalValue
> scoped_list_element_0(new FundamentalValue(0));
425 Value
* original_list_element_0
= scoped_list_element_0
.get();
426 scoped_list
->Append(scoped_list_element_0
.Pass());
427 scoped_ptr
<FundamentalValue
> scoped_list_element_1(new FundamentalValue(1));
428 Value
* original_list_element_1
= scoped_list_element_1
.get();
429 scoped_list
->Append(scoped_list_element_1
.Pass());
430 original_dict
.Set("list", scoped_list
.Pass());
432 scoped_ptr
<DictionaryValue
> scoped_nested_dictionary(new DictionaryValue());
433 Value
* original_nested_dictionary
= scoped_nested_dictionary
.get();
434 scoped_nested_dictionary
->SetString("key", "value");
435 original_dict
.Set("dictionary", scoped_nested_dictionary
.Pass());
437 scoped_ptr
<DictionaryValue
> copy_dict
= original_dict
.CreateDeepCopy();
438 ASSERT_TRUE(copy_dict
.get());
439 ASSERT_NE(copy_dict
.get(), &original_dict
);
441 Value
* copy_null
= NULL
;
442 ASSERT_TRUE(copy_dict
->Get("null", ©_null
));
443 ASSERT_TRUE(copy_null
);
444 ASSERT_NE(copy_null
, original_null
);
445 ASSERT_TRUE(copy_null
->IsType(Value::TYPE_NULL
));
447 Value
* copy_bool
= NULL
;
448 ASSERT_TRUE(copy_dict
->Get("bool", ©_bool
));
449 ASSERT_TRUE(copy_bool
);
450 ASSERT_NE(copy_bool
, original_bool
);
451 ASSERT_TRUE(copy_bool
->IsType(Value::TYPE_BOOLEAN
));
452 bool copy_bool_value
= false;
453 ASSERT_TRUE(copy_bool
->GetAsBoolean(©_bool_value
));
454 ASSERT_TRUE(copy_bool_value
);
456 Value
* copy_int
= NULL
;
457 ASSERT_TRUE(copy_dict
->Get("int", ©_int
));
458 ASSERT_TRUE(copy_int
);
459 ASSERT_NE(copy_int
, original_int
);
460 ASSERT_TRUE(copy_int
->IsType(Value::TYPE_INTEGER
));
461 int copy_int_value
= 0;
462 ASSERT_TRUE(copy_int
->GetAsInteger(©_int_value
));
463 ASSERT_EQ(42, copy_int_value
);
465 Value
* copy_double
= NULL
;
466 ASSERT_TRUE(copy_dict
->Get("double", ©_double
));
467 ASSERT_TRUE(copy_double
);
468 ASSERT_NE(copy_double
, original_double
);
469 ASSERT_TRUE(copy_double
->IsType(Value::TYPE_DOUBLE
));
470 double copy_double_value
= 0;
471 ASSERT_TRUE(copy_double
->GetAsDouble(©_double_value
));
472 ASSERT_EQ(3.14, copy_double_value
);
474 Value
* copy_string
= NULL
;
475 ASSERT_TRUE(copy_dict
->Get("string", ©_string
));
476 ASSERT_TRUE(copy_string
);
477 ASSERT_NE(copy_string
, original_string
);
478 ASSERT_TRUE(copy_string
->IsType(Value::TYPE_STRING
));
479 std::string copy_string_value
;
480 string16 copy_string16_value
;
481 ASSERT_TRUE(copy_string
->GetAsString(©_string_value
));
482 ASSERT_TRUE(copy_string
->GetAsString(©_string16_value
));
483 ASSERT_EQ(std::string("hello"), copy_string_value
);
484 ASSERT_EQ(ASCIIToUTF16("hello"), copy_string16_value
);
486 Value
* copy_string16
= NULL
;
487 ASSERT_TRUE(copy_dict
->Get("string16", ©_string16
));
488 ASSERT_TRUE(copy_string16
);
489 ASSERT_NE(copy_string16
, original_string16
);
490 ASSERT_TRUE(copy_string16
->IsType(Value::TYPE_STRING
));
491 ASSERT_TRUE(copy_string16
->GetAsString(©_string_value
));
492 ASSERT_TRUE(copy_string16
->GetAsString(©_string16_value
));
493 ASSERT_EQ(std::string("hello16"), copy_string_value
);
494 ASSERT_EQ(ASCIIToUTF16("hello16"), copy_string16_value
);
496 Value
* copy_binary
= NULL
;
497 ASSERT_TRUE(copy_dict
->Get("binary", ©_binary
));
498 ASSERT_TRUE(copy_binary
);
499 ASSERT_NE(copy_binary
, original_binary
);
500 ASSERT_TRUE(copy_binary
->IsType(Value::TYPE_BINARY
));
501 ASSERT_NE(original_binary
->GetBuffer(),
502 static_cast<BinaryValue
*>(copy_binary
)->GetBuffer());
503 ASSERT_EQ(original_binary
->GetSize(),
504 static_cast<BinaryValue
*>(copy_binary
)->GetSize());
505 ASSERT_EQ(0, memcmp(original_binary
->GetBuffer(),
506 static_cast<BinaryValue
*>(copy_binary
)->GetBuffer(),
507 original_binary
->GetSize()));
509 Value
* copy_value
= NULL
;
510 ASSERT_TRUE(copy_dict
->Get("list", ©_value
));
511 ASSERT_TRUE(copy_value
);
512 ASSERT_NE(copy_value
, original_list
);
513 ASSERT_TRUE(copy_value
->IsType(Value::TYPE_LIST
));
514 ListValue
* copy_list
= NULL
;
515 ASSERT_TRUE(copy_value
->GetAsList(©_list
));
516 ASSERT_TRUE(copy_list
);
517 ASSERT_EQ(2U, copy_list
->GetSize());
519 Value
* copy_list_element_0
;
520 ASSERT_TRUE(copy_list
->Get(0, ©_list_element_0
));
521 ASSERT_TRUE(copy_list_element_0
);
522 ASSERT_NE(copy_list_element_0
, original_list_element_0
);
523 int copy_list_element_0_value
;
524 ASSERT_TRUE(copy_list_element_0
->GetAsInteger(©_list_element_0_value
));
525 ASSERT_EQ(0, copy_list_element_0_value
);
527 Value
* copy_list_element_1
;
528 ASSERT_TRUE(copy_list
->Get(1, ©_list_element_1
));
529 ASSERT_TRUE(copy_list_element_1
);
530 ASSERT_NE(copy_list_element_1
, original_list_element_1
);
531 int copy_list_element_1_value
;
532 ASSERT_TRUE(copy_list_element_1
->GetAsInteger(©_list_element_1_value
));
533 ASSERT_EQ(1, copy_list_element_1_value
);
536 ASSERT_TRUE(copy_dict
->Get("dictionary", ©_value
));
537 ASSERT_TRUE(copy_value
);
538 ASSERT_NE(copy_value
, original_nested_dictionary
);
539 ASSERT_TRUE(copy_value
->IsType(Value::TYPE_DICTIONARY
));
540 DictionaryValue
* copy_nested_dictionary
= NULL
;
541 ASSERT_TRUE(copy_value
->GetAsDictionary(©_nested_dictionary
));
542 ASSERT_TRUE(copy_nested_dictionary
);
543 EXPECT_TRUE(copy_nested_dictionary
->HasKey("key"));
546 TEST(ValuesTest
, Equals
) {
547 scoped_ptr
<Value
> null1(Value::CreateNullValue());
548 scoped_ptr
<Value
> null2(Value::CreateNullValue());
549 EXPECT_NE(null1
.get(), null2
.get());
550 EXPECT_TRUE(null1
->Equals(null2
.get()));
552 scoped_ptr
<Value
> boolean(new FundamentalValue(false));
553 EXPECT_FALSE(null1
->Equals(boolean
.get()));
556 dv
.SetBoolean("a", false);
557 dv
.SetInteger("b", 2);
558 dv
.SetDouble("c", 2.5);
559 dv
.SetString("d1", "string");
560 dv
.SetString("d2", ASCIIToUTF16("http://google.com"));
561 dv
.Set("e", make_scoped_ptr(Value::CreateNullValue()));
563 scoped_ptr
<DictionaryValue
> copy
= dv
.CreateDeepCopy();
564 EXPECT_TRUE(dv
.Equals(copy
.get()));
566 scoped_ptr
<ListValue
> list(new ListValue
);
567 ListValue
* original_list
= list
.get();
568 list
->Append(make_scoped_ptr(Value::CreateNullValue()));
569 list
->Append(make_scoped_ptr(new DictionaryValue
));
570 scoped_ptr
<Value
> list_copy(list
->CreateDeepCopy());
572 dv
.Set("f", list
.Pass());
573 EXPECT_FALSE(dv
.Equals(copy
.get()));
574 copy
->Set("f", list_copy
.Pass());
575 EXPECT_TRUE(dv
.Equals(copy
.get()));
577 original_list
->Append(make_scoped_ptr(new FundamentalValue(true)));
578 EXPECT_FALSE(dv
.Equals(copy
.get()));
580 // Check if Equals detects differences in only the keys.
581 copy
= dv
.CreateDeepCopy();
582 EXPECT_TRUE(dv
.Equals(copy
.get()));
583 copy
->Remove("a", NULL
);
584 copy
->SetBoolean("aa", false);
585 EXPECT_FALSE(dv
.Equals(copy
.get()));
588 TEST(ValuesTest
, StaticEquals
) {
589 scoped_ptr
<Value
> null1(Value::CreateNullValue());
590 scoped_ptr
<Value
> null2(Value::CreateNullValue());
591 EXPECT_TRUE(Value::Equals(null1
.get(), null2
.get()));
592 EXPECT_TRUE(Value::Equals(NULL
, NULL
));
594 scoped_ptr
<Value
> i42(new FundamentalValue(42));
595 scoped_ptr
<Value
> j42(new FundamentalValue(42));
596 scoped_ptr
<Value
> i17(new FundamentalValue(17));
597 EXPECT_TRUE(Value::Equals(i42
.get(), i42
.get()));
598 EXPECT_TRUE(Value::Equals(j42
.get(), i42
.get()));
599 EXPECT_TRUE(Value::Equals(i42
.get(), j42
.get()));
600 EXPECT_FALSE(Value::Equals(i42
.get(), i17
.get()));
601 EXPECT_FALSE(Value::Equals(i42
.get(), NULL
));
602 EXPECT_FALSE(Value::Equals(NULL
, i42
.get()));
604 // NULL and Value::CreateNullValue() are intentionally different: We need
605 // support for NULL as a return value for "undefined" without caring for
606 // ownership of the pointer.
607 EXPECT_FALSE(Value::Equals(null1
.get(), NULL
));
608 EXPECT_FALSE(Value::Equals(NULL
, null1
.get()));
611 TEST(ValuesTest
, DeepCopyCovariantReturnTypes
) {
612 DictionaryValue original_dict
;
613 scoped_ptr
<Value
> scoped_null(Value::CreateNullValue());
614 Value
* original_null
= scoped_null
.get();
615 original_dict
.Set("null", scoped_null
.Pass());
616 scoped_ptr
<FundamentalValue
> scoped_bool(new FundamentalValue(true));
617 Value
* original_bool
= scoped_bool
.get();
618 original_dict
.Set("bool", scoped_bool
.Pass());
619 scoped_ptr
<FundamentalValue
> scoped_int(new FundamentalValue(42));
620 Value
* original_int
= scoped_int
.get();
621 original_dict
.Set("int", scoped_int
.Pass());
622 scoped_ptr
<FundamentalValue
> scoped_double(new FundamentalValue(3.14));
623 Value
* original_double
= scoped_double
.get();
624 original_dict
.Set("double", scoped_double
.Pass());
625 scoped_ptr
<StringValue
> scoped_string(new StringValue("hello"));
626 Value
* original_string
= scoped_string
.get();
627 original_dict
.Set("string", scoped_string
.Pass());
628 scoped_ptr
<StringValue
> scoped_string16(
629 new StringValue(ASCIIToUTF16("hello16")));
630 Value
* original_string16
= scoped_string16
.get();
631 original_dict
.Set("string16", scoped_string16
.Pass());
633 scoped_ptr
<char[]> original_buffer(new char[42]);
634 memset(original_buffer
.get(), '!', 42);
635 scoped_ptr
<BinaryValue
> scoped_binary(
636 new BinaryValue(original_buffer
.Pass(), 42));
637 Value
* original_binary
= scoped_binary
.get();
638 original_dict
.Set("binary", scoped_binary
.Pass());
640 scoped_ptr
<ListValue
> scoped_list(new ListValue());
641 Value
* original_list
= scoped_list
.get();
642 scoped_ptr
<FundamentalValue
> scoped_list_element_0(new FundamentalValue(0));
643 scoped_list
->Append(scoped_list_element_0
.Pass());
644 scoped_ptr
<FundamentalValue
> scoped_list_element_1(new FundamentalValue(1));
645 scoped_list
->Append(scoped_list_element_1
.Pass());
646 original_dict
.Set("list", scoped_list
.Pass());
648 scoped_ptr
<Value
> copy_dict
= original_dict
.CreateDeepCopy();
649 scoped_ptr
<Value
> copy_null
= original_null
->CreateDeepCopy();
650 scoped_ptr
<Value
> copy_bool
= original_bool
->CreateDeepCopy();
651 scoped_ptr
<Value
> copy_int
= original_int
->CreateDeepCopy();
652 scoped_ptr
<Value
> copy_double
= original_double
->CreateDeepCopy();
653 scoped_ptr
<Value
> copy_string
= original_string
->CreateDeepCopy();
654 scoped_ptr
<Value
> copy_string16
= original_string16
->CreateDeepCopy();
655 scoped_ptr
<Value
> copy_binary
= original_binary
->CreateDeepCopy();
656 scoped_ptr
<Value
> copy_list
= original_list
->CreateDeepCopy();
658 EXPECT_TRUE(original_dict
.Equals(copy_dict
.get()));
659 EXPECT_TRUE(original_null
->Equals(copy_null
.get()));
660 EXPECT_TRUE(original_bool
->Equals(copy_bool
.get()));
661 EXPECT_TRUE(original_int
->Equals(copy_int
.get()));
662 EXPECT_TRUE(original_double
->Equals(copy_double
.get()));
663 EXPECT_TRUE(original_string
->Equals(copy_string
.get()));
664 EXPECT_TRUE(original_string16
->Equals(copy_string16
.get()));
665 EXPECT_TRUE(original_binary
->Equals(copy_binary
.get()));
666 EXPECT_TRUE(original_list
->Equals(copy_list
.get()));
669 TEST(ValuesTest
, RemoveEmptyChildren
) {
670 scoped_ptr
<DictionaryValue
> root(new DictionaryValue
);
671 // Remove empty lists and dictionaries.
672 root
->Set("empty_dict", make_scoped_ptr(new DictionaryValue
));
673 root
->Set("empty_list", make_scoped_ptr(new ListValue
));
674 root
->SetWithoutPathExpansion("a.b.c.d.e",
675 make_scoped_ptr(new DictionaryValue
));
676 root
.reset(root
->DeepCopyWithoutEmptyChildren());
677 EXPECT_TRUE(root
->empty());
679 // Make sure we don't prune too much.
680 root
->SetBoolean("bool", true);
681 root
->Set("empty_dict", make_scoped_ptr(new DictionaryValue
));
682 root
->SetString("empty_string", std::string());
683 root
.reset(root
->DeepCopyWithoutEmptyChildren());
684 EXPECT_EQ(2U, root
->size());
686 // Should do nothing.
687 root
.reset(root
->DeepCopyWithoutEmptyChildren());
688 EXPECT_EQ(2U, root
->size());
690 // Nested test cases. These should all reduce back to the bool and string
693 root
->Set("a.b.c.d.e", make_scoped_ptr(new DictionaryValue
));
694 root
.reset(root
->DeepCopyWithoutEmptyChildren());
695 EXPECT_EQ(2U, root
->size());
698 scoped_ptr
<DictionaryValue
> inner(new DictionaryValue
);
699 inner
->Set("empty_dict", make_scoped_ptr(new DictionaryValue
));
700 inner
->Set("empty_list", make_scoped_ptr(new ListValue
));
701 root
->Set("dict_with_empty_children", inner
.Pass());
702 root
.reset(root
->DeepCopyWithoutEmptyChildren());
703 EXPECT_EQ(2U, root
->size());
706 scoped_ptr
<ListValue
> inner(new ListValue
);
707 inner
->Append(make_scoped_ptr(new DictionaryValue
));
708 inner
->Append(make_scoped_ptr(new ListValue
));
709 root
->Set("list_with_empty_children", inner
.Pass());
710 root
.reset(root
->DeepCopyWithoutEmptyChildren());
711 EXPECT_EQ(2U, root
->size());
714 // Nested with siblings.
716 scoped_ptr
<ListValue
> inner(new ListValue());
717 inner
->Append(make_scoped_ptr(new DictionaryValue
));
718 inner
->Append(make_scoped_ptr(new ListValue
));
719 root
->Set("list_with_empty_children", inner
.Pass());
720 scoped_ptr
<DictionaryValue
> inner2(new DictionaryValue
);
721 inner2
->Set("empty_dict", make_scoped_ptr(new DictionaryValue
));
722 inner2
->Set("empty_list", make_scoped_ptr(new ListValue
));
723 root
->Set("dict_with_empty_children", inner2
.Pass());
724 root
.reset(root
->DeepCopyWithoutEmptyChildren());
725 EXPECT_EQ(2U, root
->size());
728 // Make sure nested values don't get pruned.
730 scoped_ptr
<ListValue
> inner(new ListValue
);
731 scoped_ptr
<ListValue
> inner2(new ListValue
);
732 inner2
->Append(make_scoped_ptr(new StringValue("hello")));
733 inner
->Append(make_scoped_ptr(new DictionaryValue
));
734 inner
->Append(inner2
.Pass());
735 root
->Set("list_with_empty_children", inner
.Pass());
736 root
.reset(root
->DeepCopyWithoutEmptyChildren());
737 EXPECT_EQ(3U, root
->size());
739 ListValue
* inner_value
, *inner_value2
;
740 EXPECT_TRUE(root
->GetList("list_with_empty_children", &inner_value
));
741 EXPECT_EQ(1U, inner_value
->GetSize()); // Dictionary was pruned.
742 EXPECT_TRUE(inner_value
->GetList(0, &inner_value2
));
743 EXPECT_EQ(1U, inner_value2
->GetSize());
747 TEST(ValuesTest
, MergeDictionary
) {
748 scoped_ptr
<DictionaryValue
> base(new DictionaryValue
);
749 base
->SetString("base_key", "base_key_value_base");
750 base
->SetString("collide_key", "collide_key_value_base");
751 scoped_ptr
<DictionaryValue
> base_sub_dict(new DictionaryValue
);
752 base_sub_dict
->SetString("sub_base_key", "sub_base_key_value_base");
753 base_sub_dict
->SetString("sub_collide_key", "sub_collide_key_value_base");
754 base
->Set("sub_dict_key", base_sub_dict
.Pass());
756 scoped_ptr
<DictionaryValue
> merge(new DictionaryValue
);
757 merge
->SetString("merge_key", "merge_key_value_merge");
758 merge
->SetString("collide_key", "collide_key_value_merge");
759 scoped_ptr
<DictionaryValue
> merge_sub_dict(new DictionaryValue
);
760 merge_sub_dict
->SetString("sub_merge_key", "sub_merge_key_value_merge");
761 merge_sub_dict
->SetString("sub_collide_key", "sub_collide_key_value_merge");
762 merge
->Set("sub_dict_key", merge_sub_dict
.Pass());
764 base
->MergeDictionary(merge
.get());
766 EXPECT_EQ(4U, base
->size());
767 std::string base_key_value
;
768 EXPECT_TRUE(base
->GetString("base_key", &base_key_value
));
769 EXPECT_EQ("base_key_value_base", base_key_value
); // Base value preserved.
770 std::string collide_key_value
;
771 EXPECT_TRUE(base
->GetString("collide_key", &collide_key_value
));
772 EXPECT_EQ("collide_key_value_merge", collide_key_value
); // Replaced.
773 std::string merge_key_value
;
774 EXPECT_TRUE(base
->GetString("merge_key", &merge_key_value
));
775 EXPECT_EQ("merge_key_value_merge", merge_key_value
); // Merged in.
777 DictionaryValue
* res_sub_dict
;
778 EXPECT_TRUE(base
->GetDictionary("sub_dict_key", &res_sub_dict
));
779 EXPECT_EQ(3U, res_sub_dict
->size());
780 std::string sub_base_key_value
;
781 EXPECT_TRUE(res_sub_dict
->GetString("sub_base_key", &sub_base_key_value
));
782 EXPECT_EQ("sub_base_key_value_base", sub_base_key_value
); // Preserved.
783 std::string sub_collide_key_value
;
784 EXPECT_TRUE(res_sub_dict
->GetString("sub_collide_key",
785 &sub_collide_key_value
));
786 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value
); // Replaced.
787 std::string sub_merge_key_value
;
788 EXPECT_TRUE(res_sub_dict
->GetString("sub_merge_key", &sub_merge_key_value
));
789 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value
); // Merged in.
792 TEST(ValuesTest
, MergeDictionaryDeepCopy
) {
793 scoped_ptr
<DictionaryValue
> child(new DictionaryValue
);
794 DictionaryValue
* original_child
= child
.get();
795 child
->SetString("test", "value");
796 EXPECT_EQ(1U, child
->size());
799 EXPECT_TRUE(child
->GetString("test", &value
));
800 EXPECT_EQ("value", value
);
802 scoped_ptr
<DictionaryValue
> base(new DictionaryValue
);
803 base
->Set("dict", child
.Pass());
804 EXPECT_EQ(1U, base
->size());
806 DictionaryValue
* ptr
;
807 EXPECT_TRUE(base
->GetDictionary("dict", &ptr
));
808 EXPECT_EQ(original_child
, ptr
);
810 scoped_ptr
<DictionaryValue
> merged(new DictionaryValue
);
811 merged
->MergeDictionary(base
.get());
812 EXPECT_EQ(1U, merged
->size());
813 EXPECT_TRUE(merged
->GetDictionary("dict", &ptr
));
814 EXPECT_NE(original_child
, ptr
);
815 EXPECT_TRUE(ptr
->GetString("test", &value
));
816 EXPECT_EQ("value", value
);
818 original_child
->SetString("test", "overwrite");
820 EXPECT_TRUE(ptr
->GetString("test", &value
));
821 EXPECT_EQ("value", value
);
824 TEST(ValuesTest
, DictionaryIterator
) {
825 DictionaryValue dict
;
826 for (DictionaryValue::Iterator
it(dict
); !it
.IsAtEnd(); it
.Advance()) {
830 StringValue
value1("value1");
831 dict
.Set("key1", value1
.CreateDeepCopy());
833 for (DictionaryValue::Iterator
it(dict
); !it
.IsAtEnd(); it
.Advance()) {
835 EXPECT_EQ("key1", it
.key());
836 EXPECT_TRUE(value1
.Equals(&it
.value()));
841 StringValue
value2("value2");
842 dict
.Set("key2", value2
.CreateDeepCopy());
843 bool seen2
= seen1
= false;
844 for (DictionaryValue::Iterator
it(dict
); !it
.IsAtEnd(); it
.Advance()) {
845 if (it
.key() == "key1") {
847 EXPECT_TRUE(value1
.Equals(&it
.value()));
849 } else if (it
.key() == "key2") {
851 EXPECT_TRUE(value2
.Equals(&it
.value()));
861 // DictionaryValue/ListValue's Get*() methods should accept NULL as an out-value
862 // and still return true/false based on success.
863 TEST(ValuesTest
, GetWithNullOutValue
) {
864 DictionaryValue main_dict
;
867 FundamentalValue
bool_value(false);
868 FundamentalValue
int_value(1234);
869 FundamentalValue
double_value(12.34567);
870 StringValue
string_value("foo");
871 BinaryValue binary_value
;
872 DictionaryValue dict_value
;
873 ListValue list_value
;
875 main_dict
.Set("bool", bool_value
.CreateDeepCopy());
876 main_dict
.Set("int", int_value
.CreateDeepCopy());
877 main_dict
.Set("double", double_value
.CreateDeepCopy());
878 main_dict
.Set("string", string_value
.CreateDeepCopy());
879 main_dict
.Set("binary", binary_value
.CreateDeepCopy());
880 main_dict
.Set("dict", dict_value
.CreateDeepCopy());
881 main_dict
.Set("list", list_value
.CreateDeepCopy());
883 main_list
.Append(bool_value
.CreateDeepCopy());
884 main_list
.Append(int_value
.CreateDeepCopy());
885 main_list
.Append(double_value
.CreateDeepCopy());
886 main_list
.Append(string_value
.CreateDeepCopy());
887 main_list
.Append(binary_value
.CreateDeepCopy());
888 main_list
.Append(dict_value
.CreateDeepCopy());
889 main_list
.Append(list_value
.CreateDeepCopy());
891 EXPECT_TRUE(main_dict
.Get("bool", NULL
));
892 EXPECT_TRUE(main_dict
.Get("int", NULL
));
893 EXPECT_TRUE(main_dict
.Get("double", NULL
));
894 EXPECT_TRUE(main_dict
.Get("string", NULL
));
895 EXPECT_TRUE(main_dict
.Get("binary", NULL
));
896 EXPECT_TRUE(main_dict
.Get("dict", NULL
));
897 EXPECT_TRUE(main_dict
.Get("list", NULL
));
898 EXPECT_FALSE(main_dict
.Get("DNE", NULL
));
900 EXPECT_TRUE(main_dict
.GetBoolean("bool", NULL
));
901 EXPECT_FALSE(main_dict
.GetBoolean("int", NULL
));
902 EXPECT_FALSE(main_dict
.GetBoolean("double", NULL
));
903 EXPECT_FALSE(main_dict
.GetBoolean("string", NULL
));
904 EXPECT_FALSE(main_dict
.GetBoolean("binary", NULL
));
905 EXPECT_FALSE(main_dict
.GetBoolean("dict", NULL
));
906 EXPECT_FALSE(main_dict
.GetBoolean("list", NULL
));
907 EXPECT_FALSE(main_dict
.GetBoolean("DNE", NULL
));
909 EXPECT_FALSE(main_dict
.GetInteger("bool", NULL
));
910 EXPECT_TRUE(main_dict
.GetInteger("int", NULL
));
911 EXPECT_FALSE(main_dict
.GetInteger("double", NULL
));
912 EXPECT_FALSE(main_dict
.GetInteger("string", NULL
));
913 EXPECT_FALSE(main_dict
.GetInteger("binary", NULL
));
914 EXPECT_FALSE(main_dict
.GetInteger("dict", NULL
));
915 EXPECT_FALSE(main_dict
.GetInteger("list", NULL
));
916 EXPECT_FALSE(main_dict
.GetInteger("DNE", NULL
));
918 // Both int and double values can be obtained from GetDouble.
919 EXPECT_FALSE(main_dict
.GetDouble("bool", NULL
));
920 EXPECT_TRUE(main_dict
.GetDouble("int", NULL
));
921 EXPECT_TRUE(main_dict
.GetDouble("double", NULL
));
922 EXPECT_FALSE(main_dict
.GetDouble("string", NULL
));
923 EXPECT_FALSE(main_dict
.GetDouble("binary", NULL
));
924 EXPECT_FALSE(main_dict
.GetDouble("dict", NULL
));
925 EXPECT_FALSE(main_dict
.GetDouble("list", NULL
));
926 EXPECT_FALSE(main_dict
.GetDouble("DNE", NULL
));
928 EXPECT_FALSE(main_dict
.GetString("bool", static_cast<std::string
*>(NULL
)));
929 EXPECT_FALSE(main_dict
.GetString("int", static_cast<std::string
*>(NULL
)));
930 EXPECT_FALSE(main_dict
.GetString("double", static_cast<std::string
*>(NULL
)));
931 EXPECT_TRUE(main_dict
.GetString("string", static_cast<std::string
*>(NULL
)));
932 EXPECT_FALSE(main_dict
.GetString("binary", static_cast<std::string
*>(NULL
)));
933 EXPECT_FALSE(main_dict
.GetString("dict", static_cast<std::string
*>(NULL
)));
934 EXPECT_FALSE(main_dict
.GetString("list", static_cast<std::string
*>(NULL
)));
935 EXPECT_FALSE(main_dict
.GetString("DNE", static_cast<std::string
*>(NULL
)));
937 EXPECT_FALSE(main_dict
.GetString("bool", static_cast<string16
*>(NULL
)));
938 EXPECT_FALSE(main_dict
.GetString("int", static_cast<string16
*>(NULL
)));
939 EXPECT_FALSE(main_dict
.GetString("double", static_cast<string16
*>(NULL
)));
940 EXPECT_TRUE(main_dict
.GetString("string", static_cast<string16
*>(NULL
)));
941 EXPECT_FALSE(main_dict
.GetString("binary", static_cast<string16
*>(NULL
)));
942 EXPECT_FALSE(main_dict
.GetString("dict", static_cast<string16
*>(NULL
)));
943 EXPECT_FALSE(main_dict
.GetString("list", static_cast<string16
*>(NULL
)));
944 EXPECT_FALSE(main_dict
.GetString("DNE", static_cast<string16
*>(NULL
)));
946 EXPECT_FALSE(main_dict
.GetBinary("bool", NULL
));
947 EXPECT_FALSE(main_dict
.GetBinary("int", NULL
));
948 EXPECT_FALSE(main_dict
.GetBinary("double", NULL
));
949 EXPECT_FALSE(main_dict
.GetBinary("string", NULL
));
950 EXPECT_TRUE(main_dict
.GetBinary("binary", NULL
));
951 EXPECT_FALSE(main_dict
.GetBinary("dict", NULL
));
952 EXPECT_FALSE(main_dict
.GetBinary("list", NULL
));
953 EXPECT_FALSE(main_dict
.GetBinary("DNE", NULL
));
955 EXPECT_FALSE(main_dict
.GetDictionary("bool", NULL
));
956 EXPECT_FALSE(main_dict
.GetDictionary("int", NULL
));
957 EXPECT_FALSE(main_dict
.GetDictionary("double", NULL
));
958 EXPECT_FALSE(main_dict
.GetDictionary("string", NULL
));
959 EXPECT_FALSE(main_dict
.GetDictionary("binary", NULL
));
960 EXPECT_TRUE(main_dict
.GetDictionary("dict", NULL
));
961 EXPECT_FALSE(main_dict
.GetDictionary("list", NULL
));
962 EXPECT_FALSE(main_dict
.GetDictionary("DNE", NULL
));
964 EXPECT_FALSE(main_dict
.GetList("bool", NULL
));
965 EXPECT_FALSE(main_dict
.GetList("int", NULL
));
966 EXPECT_FALSE(main_dict
.GetList("double", NULL
));
967 EXPECT_FALSE(main_dict
.GetList("string", NULL
));
968 EXPECT_FALSE(main_dict
.GetList("binary", NULL
));
969 EXPECT_FALSE(main_dict
.GetList("dict", NULL
));
970 EXPECT_TRUE(main_dict
.GetList("list", NULL
));
971 EXPECT_FALSE(main_dict
.GetList("DNE", NULL
));
973 EXPECT_TRUE(main_dict
.GetWithoutPathExpansion("bool", NULL
));
974 EXPECT_TRUE(main_dict
.GetWithoutPathExpansion("int", NULL
));
975 EXPECT_TRUE(main_dict
.GetWithoutPathExpansion("double", NULL
));
976 EXPECT_TRUE(main_dict
.GetWithoutPathExpansion("string", NULL
));
977 EXPECT_TRUE(main_dict
.GetWithoutPathExpansion("binary", NULL
));
978 EXPECT_TRUE(main_dict
.GetWithoutPathExpansion("dict", NULL
));
979 EXPECT_TRUE(main_dict
.GetWithoutPathExpansion("list", NULL
));
980 EXPECT_FALSE(main_dict
.GetWithoutPathExpansion("DNE", NULL
));
982 EXPECT_TRUE(main_dict
.GetBooleanWithoutPathExpansion("bool", NULL
));
983 EXPECT_FALSE(main_dict
.GetBooleanWithoutPathExpansion("int", NULL
));
984 EXPECT_FALSE(main_dict
.GetBooleanWithoutPathExpansion("double", NULL
));
985 EXPECT_FALSE(main_dict
.GetBooleanWithoutPathExpansion("string", NULL
));
986 EXPECT_FALSE(main_dict
.GetBooleanWithoutPathExpansion("binary", NULL
));
987 EXPECT_FALSE(main_dict
.GetBooleanWithoutPathExpansion("dict", NULL
));
988 EXPECT_FALSE(main_dict
.GetBooleanWithoutPathExpansion("list", NULL
));
989 EXPECT_FALSE(main_dict
.GetBooleanWithoutPathExpansion("DNE", NULL
));
991 EXPECT_FALSE(main_dict
.GetIntegerWithoutPathExpansion("bool", NULL
));
992 EXPECT_TRUE(main_dict
.GetIntegerWithoutPathExpansion("int", NULL
));
993 EXPECT_FALSE(main_dict
.GetIntegerWithoutPathExpansion("double", NULL
));
994 EXPECT_FALSE(main_dict
.GetIntegerWithoutPathExpansion("string", NULL
));
995 EXPECT_FALSE(main_dict
.GetIntegerWithoutPathExpansion("binary", NULL
));
996 EXPECT_FALSE(main_dict
.GetIntegerWithoutPathExpansion("dict", NULL
));
997 EXPECT_FALSE(main_dict
.GetIntegerWithoutPathExpansion("list", NULL
));
998 EXPECT_FALSE(main_dict
.GetIntegerWithoutPathExpansion("DNE", NULL
));
1000 EXPECT_FALSE(main_dict
.GetDoubleWithoutPathExpansion("bool", NULL
));
1001 EXPECT_TRUE(main_dict
.GetDoubleWithoutPathExpansion("int", NULL
));
1002 EXPECT_TRUE(main_dict
.GetDoubleWithoutPathExpansion("double", NULL
));
1003 EXPECT_FALSE(main_dict
.GetDoubleWithoutPathExpansion("string", NULL
));
1004 EXPECT_FALSE(main_dict
.GetDoubleWithoutPathExpansion("binary", NULL
));
1005 EXPECT_FALSE(main_dict
.GetDoubleWithoutPathExpansion("dict", NULL
));
1006 EXPECT_FALSE(main_dict
.GetDoubleWithoutPathExpansion("list", NULL
));
1007 EXPECT_FALSE(main_dict
.GetDoubleWithoutPathExpansion("DNE", NULL
));
1009 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1010 "bool", static_cast<std::string
*>(NULL
)));
1011 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1012 "int", static_cast<std::string
*>(NULL
)));
1013 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1014 "double", static_cast<std::string
*>(NULL
)));
1015 EXPECT_TRUE(main_dict
.GetStringWithoutPathExpansion(
1016 "string", static_cast<std::string
*>(NULL
)));
1017 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1018 "binary", static_cast<std::string
*>(NULL
)));
1019 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1020 "dict", static_cast<std::string
*>(NULL
)));
1021 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1022 "list", static_cast<std::string
*>(NULL
)));
1023 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1024 "DNE", static_cast<std::string
*>(NULL
)));
1026 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1027 "bool", static_cast<string16
*>(NULL
)));
1028 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1029 "int", static_cast<string16
*>(NULL
)));
1030 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1031 "double", static_cast<string16
*>(NULL
)));
1032 EXPECT_TRUE(main_dict
.GetStringWithoutPathExpansion(
1033 "string", static_cast<string16
*>(NULL
)));
1034 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1035 "binary", static_cast<string16
*>(NULL
)));
1036 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1037 "dict", static_cast<string16
*>(NULL
)));
1038 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1039 "list", static_cast<string16
*>(NULL
)));
1040 EXPECT_FALSE(main_dict
.GetStringWithoutPathExpansion(
1041 "DNE", static_cast<string16
*>(NULL
)));
1043 // There is no GetBinaryWithoutPathExpansion for some reason, but if there
1044 // were it should be tested here...
1046 EXPECT_FALSE(main_dict
.GetDictionaryWithoutPathExpansion("bool", NULL
));
1047 EXPECT_FALSE(main_dict
.GetDictionaryWithoutPathExpansion("int", NULL
));
1048 EXPECT_FALSE(main_dict
.GetDictionaryWithoutPathExpansion("double", NULL
));
1049 EXPECT_FALSE(main_dict
.GetDictionaryWithoutPathExpansion("string", NULL
));
1050 EXPECT_FALSE(main_dict
.GetDictionaryWithoutPathExpansion("binary", NULL
));
1051 EXPECT_TRUE(main_dict
.GetDictionaryWithoutPathExpansion("dict", NULL
));
1052 EXPECT_FALSE(main_dict
.GetDictionaryWithoutPathExpansion("list", NULL
));
1053 EXPECT_FALSE(main_dict
.GetDictionaryWithoutPathExpansion("DNE", NULL
));
1055 EXPECT_FALSE(main_dict
.GetListWithoutPathExpansion("bool", NULL
));
1056 EXPECT_FALSE(main_dict
.GetListWithoutPathExpansion("int", NULL
));
1057 EXPECT_FALSE(main_dict
.GetListWithoutPathExpansion("double", NULL
));
1058 EXPECT_FALSE(main_dict
.GetListWithoutPathExpansion("string", NULL
));
1059 EXPECT_FALSE(main_dict
.GetListWithoutPathExpansion("binary", NULL
));
1060 EXPECT_FALSE(main_dict
.GetListWithoutPathExpansion("dict", NULL
));
1061 EXPECT_TRUE(main_dict
.GetListWithoutPathExpansion("list", NULL
));
1062 EXPECT_FALSE(main_dict
.GetListWithoutPathExpansion("DNE", NULL
));
1064 EXPECT_TRUE(main_list
.Get(0, NULL
));
1065 EXPECT_TRUE(main_list
.Get(1, NULL
));
1066 EXPECT_TRUE(main_list
.Get(2, NULL
));
1067 EXPECT_TRUE(main_list
.Get(3, NULL
));
1068 EXPECT_TRUE(main_list
.Get(4, NULL
));
1069 EXPECT_TRUE(main_list
.Get(5, NULL
));
1070 EXPECT_TRUE(main_list
.Get(6, NULL
));
1071 EXPECT_FALSE(main_list
.Get(7, NULL
));
1073 EXPECT_TRUE(main_list
.GetBoolean(0, NULL
));
1074 EXPECT_FALSE(main_list
.GetBoolean(1, NULL
));
1075 EXPECT_FALSE(main_list
.GetBoolean(2, NULL
));
1076 EXPECT_FALSE(main_list
.GetBoolean(3, NULL
));
1077 EXPECT_FALSE(main_list
.GetBoolean(4, NULL
));
1078 EXPECT_FALSE(main_list
.GetBoolean(5, NULL
));
1079 EXPECT_FALSE(main_list
.GetBoolean(6, NULL
));
1080 EXPECT_FALSE(main_list
.GetBoolean(7, NULL
));
1082 EXPECT_FALSE(main_list
.GetInteger(0, NULL
));
1083 EXPECT_TRUE(main_list
.GetInteger(1, NULL
));
1084 EXPECT_FALSE(main_list
.GetInteger(2, NULL
));
1085 EXPECT_FALSE(main_list
.GetInteger(3, NULL
));
1086 EXPECT_FALSE(main_list
.GetInteger(4, NULL
));
1087 EXPECT_FALSE(main_list
.GetInteger(5, NULL
));
1088 EXPECT_FALSE(main_list
.GetInteger(6, NULL
));
1089 EXPECT_FALSE(main_list
.GetInteger(7, NULL
));
1091 EXPECT_FALSE(main_list
.GetDouble(0, NULL
));
1092 EXPECT_TRUE(main_list
.GetDouble(1, NULL
));
1093 EXPECT_TRUE(main_list
.GetDouble(2, NULL
));
1094 EXPECT_FALSE(main_list
.GetDouble(3, NULL
));
1095 EXPECT_FALSE(main_list
.GetDouble(4, NULL
));
1096 EXPECT_FALSE(main_list
.GetDouble(5, NULL
));
1097 EXPECT_FALSE(main_list
.GetDouble(6, NULL
));
1098 EXPECT_FALSE(main_list
.GetDouble(7, NULL
));
1100 EXPECT_FALSE(main_list
.GetString(0, static_cast<std::string
*>(NULL
)));
1101 EXPECT_FALSE(main_list
.GetString(1, static_cast<std::string
*>(NULL
)));
1102 EXPECT_FALSE(main_list
.GetString(2, static_cast<std::string
*>(NULL
)));
1103 EXPECT_TRUE(main_list
.GetString(3, static_cast<std::string
*>(NULL
)));
1104 EXPECT_FALSE(main_list
.GetString(4, static_cast<std::string
*>(NULL
)));
1105 EXPECT_FALSE(main_list
.GetString(5, static_cast<std::string
*>(NULL
)));
1106 EXPECT_FALSE(main_list
.GetString(6, static_cast<std::string
*>(NULL
)));
1107 EXPECT_FALSE(main_list
.GetString(7, static_cast<std::string
*>(NULL
)));
1109 EXPECT_FALSE(main_list
.GetString(0, static_cast<string16
*>(NULL
)));
1110 EXPECT_FALSE(main_list
.GetString(1, static_cast<string16
*>(NULL
)));
1111 EXPECT_FALSE(main_list
.GetString(2, static_cast<string16
*>(NULL
)));
1112 EXPECT_TRUE(main_list
.GetString(3, static_cast<string16
*>(NULL
)));
1113 EXPECT_FALSE(main_list
.GetString(4, static_cast<string16
*>(NULL
)));
1114 EXPECT_FALSE(main_list
.GetString(5, static_cast<string16
*>(NULL
)));
1115 EXPECT_FALSE(main_list
.GetString(6, static_cast<string16
*>(NULL
)));
1116 EXPECT_FALSE(main_list
.GetString(7, static_cast<string16
*>(NULL
)));
1118 EXPECT_FALSE(main_list
.GetBinary(0, NULL
));
1119 EXPECT_FALSE(main_list
.GetBinary(1, NULL
));
1120 EXPECT_FALSE(main_list
.GetBinary(2, NULL
));
1121 EXPECT_FALSE(main_list
.GetBinary(3, NULL
));
1122 EXPECT_TRUE(main_list
.GetBinary(4, NULL
));
1123 EXPECT_FALSE(main_list
.GetBinary(5, NULL
));
1124 EXPECT_FALSE(main_list
.GetBinary(6, NULL
));
1125 EXPECT_FALSE(main_list
.GetBinary(7, NULL
));
1127 EXPECT_FALSE(main_list
.GetDictionary(0, NULL
));
1128 EXPECT_FALSE(main_list
.GetDictionary(1, NULL
));
1129 EXPECT_FALSE(main_list
.GetDictionary(2, NULL
));
1130 EXPECT_FALSE(main_list
.GetDictionary(3, NULL
));
1131 EXPECT_FALSE(main_list
.GetDictionary(4, NULL
));
1132 EXPECT_TRUE(main_list
.GetDictionary(5, NULL
));
1133 EXPECT_FALSE(main_list
.GetDictionary(6, NULL
));
1134 EXPECT_FALSE(main_list
.GetDictionary(7, NULL
));
1136 EXPECT_FALSE(main_list
.GetList(0, NULL
));
1137 EXPECT_FALSE(main_list
.GetList(1, NULL
));
1138 EXPECT_FALSE(main_list
.GetList(2, NULL
));
1139 EXPECT_FALSE(main_list
.GetList(3, NULL
));
1140 EXPECT_FALSE(main_list
.GetList(4, NULL
));
1141 EXPECT_FALSE(main_list
.GetList(5, NULL
));
1142 EXPECT_TRUE(main_list
.GetList(6, NULL
));
1143 EXPECT_FALSE(main_list
.GetList(7, NULL
));