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