| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <limits> | 5 #include <limits> |
| 6 #include <utility> |
| 6 | 7 |
| 7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 | 15 |
| 15 TEST(ValuesTest, Basic) { | 16 TEST(ValuesTest, Basic) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 27 homepage = "http://google.com"; | 28 homepage = "http://google.com"; |
| 28 ASSERT_TRUE(settings.GetString("global.homepage", &homepage)); | 29 ASSERT_TRUE(settings.GetString("global.homepage", &homepage)); |
| 29 ASSERT_EQ(std::string("http://scurvy.com"), homepage); | 30 ASSERT_EQ(std::string("http://scurvy.com"), homepage); |
| 30 | 31 |
| 31 // Test storing a dictionary in a list. | 32 // Test storing a dictionary in a list. |
| 32 ListValue* toolbar_bookmarks; | 33 ListValue* toolbar_bookmarks; |
| 33 ASSERT_FALSE( | 34 ASSERT_FALSE( |
| 34 settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks)); | 35 settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks)); |
| 35 | 36 |
| 36 scoped_ptr<ListValue> new_toolbar_bookmarks(new ListValue); | 37 scoped_ptr<ListValue> new_toolbar_bookmarks(new ListValue); |
| 37 settings.Set("global.toolbar.bookmarks", new_toolbar_bookmarks.Pass()); | 38 settings.Set("global.toolbar.bookmarks", std::move(new_toolbar_bookmarks)); |
| 38 ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks)); | 39 ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks)); |
| 39 | 40 |
| 40 scoped_ptr<DictionaryValue> new_bookmark(new DictionaryValue); | 41 scoped_ptr<DictionaryValue> new_bookmark(new DictionaryValue); |
| 41 new_bookmark->SetString("name", "Froogle"); | 42 new_bookmark->SetString("name", "Froogle"); |
| 42 new_bookmark->SetString("url", "http://froogle.com"); | 43 new_bookmark->SetString("url", "http://froogle.com"); |
| 43 toolbar_bookmarks->Append(new_bookmark.Pass()); | 44 toolbar_bookmarks->Append(std::move(new_bookmark)); |
| 44 | 45 |
| 45 ListValue* bookmark_list; | 46 ListValue* bookmark_list; |
| 46 ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &bookmark_list)); | 47 ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &bookmark_list)); |
| 47 DictionaryValue* bookmark; | 48 DictionaryValue* bookmark; |
| 48 ASSERT_EQ(1U, bookmark_list->GetSize()); | 49 ASSERT_EQ(1U, bookmark_list->GetSize()); |
| 49 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark)); | 50 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark)); |
| 50 std::string bookmark_name = "Unnamed"; | 51 std::string bookmark_name = "Unnamed"; |
| 51 ASSERT_TRUE(bookmark->GetString("name", &bookmark_name)); | 52 ASSERT_TRUE(bookmark->GetString("name", &bookmark_name)); |
| 52 ASSERT_EQ(std::string("Froogle"), bookmark_name); | 53 ASSERT_EQ(std::string("Froogle"), bookmark_name); |
| 53 std::string bookmark_url; | 54 std::string bookmark_url; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 TEST(ValuesTest, BinaryValue) { | 108 TEST(ValuesTest, BinaryValue) { |
| 108 // Default constructor creates a BinaryValue with a null buffer and size 0. | 109 // Default constructor creates a BinaryValue with a null buffer and size 0. |
| 109 scoped_ptr<BinaryValue> binary(new BinaryValue()); | 110 scoped_ptr<BinaryValue> binary(new BinaryValue()); |
| 110 ASSERT_TRUE(binary.get()); | 111 ASSERT_TRUE(binary.get()); |
| 111 ASSERT_EQ(NULL, binary->GetBuffer()); | 112 ASSERT_EQ(NULL, binary->GetBuffer()); |
| 112 ASSERT_EQ(0U, binary->GetSize()); | 113 ASSERT_EQ(0U, binary->GetSize()); |
| 113 | 114 |
| 114 // Test the common case of a non-empty buffer | 115 // Test the common case of a non-empty buffer |
| 115 scoped_ptr<char[]> buffer(new char[15]); | 116 scoped_ptr<char[]> buffer(new char[15]); |
| 116 char* original_buffer = buffer.get(); | 117 char* original_buffer = buffer.get(); |
| 117 binary.reset(new BinaryValue(buffer.Pass(), 15)); | 118 binary.reset(new BinaryValue(std::move(buffer), 15)); |
| 118 ASSERT_TRUE(binary.get()); | 119 ASSERT_TRUE(binary.get()); |
| 119 ASSERT_TRUE(binary->GetBuffer()); | 120 ASSERT_TRUE(binary->GetBuffer()); |
| 120 ASSERT_EQ(original_buffer, binary->GetBuffer()); | 121 ASSERT_EQ(original_buffer, binary->GetBuffer()); |
| 121 ASSERT_EQ(15U, binary->GetSize()); | 122 ASSERT_EQ(15U, binary->GetSize()); |
| 122 | 123 |
| 123 char stack_buffer[42]; | 124 char stack_buffer[42]; |
| 124 memset(stack_buffer, '!', 42); | 125 memset(stack_buffer, '!', 42); |
| 125 binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42)); | 126 binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42)); |
| 126 ASSERT_TRUE(binary.get()); | 127 ASSERT_TRUE(binary.get()); |
| 127 ASSERT_TRUE(binary->GetBuffer()); | 128 ASSERT_TRUE(binary->GetBuffer()); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 EXPECT_FALSE(deletion_flag); | 244 EXPECT_FALSE(deletion_flag); |
| 244 EXPECT_TRUE(list.Remove(0, NULL)); | 245 EXPECT_TRUE(list.Remove(0, NULL)); |
| 245 EXPECT_TRUE(deletion_flag); | 246 EXPECT_TRUE(deletion_flag); |
| 246 EXPECT_EQ(0U, list.GetSize()); | 247 EXPECT_EQ(0U, list.GetSize()); |
| 247 } | 248 } |
| 248 | 249 |
| 249 { | 250 { |
| 250 ListValue list; | 251 ListValue list; |
| 251 scoped_ptr<DeletionTestValue> value(new DeletionTestValue(&deletion_flag)); | 252 scoped_ptr<DeletionTestValue> value(new DeletionTestValue(&deletion_flag)); |
| 252 DeletionTestValue* original_value = value.get(); | 253 DeletionTestValue* original_value = value.get(); |
| 253 list.Append(value.Pass()); | 254 list.Append(std::move(value)); |
| 254 EXPECT_FALSE(deletion_flag); | 255 EXPECT_FALSE(deletion_flag); |
| 255 size_t index = 0; | 256 size_t index = 0; |
| 256 list.Remove(*original_value, &index); | 257 list.Remove(*original_value, &index); |
| 257 EXPECT_EQ(0U, index); | 258 EXPECT_EQ(0U, index); |
| 258 EXPECT_TRUE(deletion_flag); | 259 EXPECT_TRUE(deletion_flag); |
| 259 EXPECT_EQ(0U, list.GetSize()); | 260 EXPECT_EQ(0U, list.GetSize()); |
| 260 } | 261 } |
| 261 } | 262 } |
| 262 | 263 |
| 263 TEST(ValuesTest, DictionaryDeletion) { | 264 TEST(ValuesTest, DictionaryDeletion) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 EXPECT_TRUE(dict.RemovePath("a.long.key.path", &removed_item)); | 387 EXPECT_TRUE(dict.RemovePath("a.long.key.path", &removed_item)); |
| 387 ASSERT_TRUE(removed_item); | 388 ASSERT_TRUE(removed_item); |
| 388 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_BOOLEAN)); | 389 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_BOOLEAN)); |
| 389 EXPECT_TRUE(dict.empty()); | 390 EXPECT_TRUE(dict.empty()); |
| 390 } | 391 } |
| 391 | 392 |
| 392 TEST(ValuesTest, DeepCopy) { | 393 TEST(ValuesTest, DeepCopy) { |
| 393 DictionaryValue original_dict; | 394 DictionaryValue original_dict; |
| 394 scoped_ptr<Value> scoped_null = Value::CreateNullValue(); | 395 scoped_ptr<Value> scoped_null = Value::CreateNullValue(); |
| 395 Value* original_null = scoped_null.get(); | 396 Value* original_null = scoped_null.get(); |
| 396 original_dict.Set("null", scoped_null.Pass()); | 397 original_dict.Set("null", std::move(scoped_null)); |
| 397 scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true)); | 398 scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true)); |
| 398 FundamentalValue* original_bool = scoped_bool.get(); | 399 FundamentalValue* original_bool = scoped_bool.get(); |
| 399 original_dict.Set("bool", scoped_bool.Pass()); | 400 original_dict.Set("bool", std::move(scoped_bool)); |
| 400 scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42)); | 401 scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42)); |
| 401 FundamentalValue* original_int = scoped_int.get(); | 402 FundamentalValue* original_int = scoped_int.get(); |
| 402 original_dict.Set("int", scoped_int.Pass()); | 403 original_dict.Set("int", std::move(scoped_int)); |
| 403 scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14)); | 404 scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14)); |
| 404 FundamentalValue* original_double = scoped_double.get(); | 405 FundamentalValue* original_double = scoped_double.get(); |
| 405 original_dict.Set("double", scoped_double.Pass()); | 406 original_dict.Set("double", std::move(scoped_double)); |
| 406 scoped_ptr<StringValue> scoped_string(new StringValue("hello")); | 407 scoped_ptr<StringValue> scoped_string(new StringValue("hello")); |
| 407 StringValue* original_string = scoped_string.get(); | 408 StringValue* original_string = scoped_string.get(); |
| 408 original_dict.Set("string", scoped_string.Pass()); | 409 original_dict.Set("string", std::move(scoped_string)); |
| 409 scoped_ptr<StringValue> scoped_string16( | 410 scoped_ptr<StringValue> scoped_string16( |
| 410 new StringValue(ASCIIToUTF16("hello16"))); | 411 new StringValue(ASCIIToUTF16("hello16"))); |
| 411 StringValue* original_string16 = scoped_string16.get(); | 412 StringValue* original_string16 = scoped_string16.get(); |
| 412 original_dict.Set("string16", scoped_string16.Pass()); | 413 original_dict.Set("string16", std::move(scoped_string16)); |
| 413 | 414 |
| 414 scoped_ptr<char[]> original_buffer(new char[42]); | 415 scoped_ptr<char[]> original_buffer(new char[42]); |
| 415 memset(original_buffer.get(), '!', 42); | 416 memset(original_buffer.get(), '!', 42); |
| 416 scoped_ptr<BinaryValue> scoped_binary( | 417 scoped_ptr<BinaryValue> scoped_binary( |
| 417 new BinaryValue(original_buffer.Pass(), 42)); | 418 new BinaryValue(std::move(original_buffer), 42)); |
| 418 BinaryValue* original_binary = scoped_binary.get(); | 419 BinaryValue* original_binary = scoped_binary.get(); |
| 419 original_dict.Set("binary", scoped_binary.Pass()); | 420 original_dict.Set("binary", std::move(scoped_binary)); |
| 420 | 421 |
| 421 scoped_ptr<ListValue> scoped_list(new ListValue()); | 422 scoped_ptr<ListValue> scoped_list(new ListValue()); |
| 422 Value* original_list = scoped_list.get(); | 423 Value* original_list = scoped_list.get(); |
| 423 scoped_ptr<FundamentalValue> scoped_list_element_0(new FundamentalValue(0)); | 424 scoped_ptr<FundamentalValue> scoped_list_element_0(new FundamentalValue(0)); |
| 424 Value* original_list_element_0 = scoped_list_element_0.get(); | 425 Value* original_list_element_0 = scoped_list_element_0.get(); |
| 425 scoped_list->Append(scoped_list_element_0.Pass()); | 426 scoped_list->Append(std::move(scoped_list_element_0)); |
| 426 scoped_ptr<FundamentalValue> scoped_list_element_1(new FundamentalValue(1)); | 427 scoped_ptr<FundamentalValue> scoped_list_element_1(new FundamentalValue(1)); |
| 427 Value* original_list_element_1 = scoped_list_element_1.get(); | 428 Value* original_list_element_1 = scoped_list_element_1.get(); |
| 428 scoped_list->Append(scoped_list_element_1.Pass()); | 429 scoped_list->Append(std::move(scoped_list_element_1)); |
| 429 original_dict.Set("list", scoped_list.Pass()); | 430 original_dict.Set("list", std::move(scoped_list)); |
| 430 | 431 |
| 431 scoped_ptr<DictionaryValue> scoped_nested_dictionary(new DictionaryValue()); | 432 scoped_ptr<DictionaryValue> scoped_nested_dictionary(new DictionaryValue()); |
| 432 Value* original_nested_dictionary = scoped_nested_dictionary.get(); | 433 Value* original_nested_dictionary = scoped_nested_dictionary.get(); |
| 433 scoped_nested_dictionary->SetString("key", "value"); | 434 scoped_nested_dictionary->SetString("key", "value"); |
| 434 original_dict.Set("dictionary", scoped_nested_dictionary.Pass()); | 435 original_dict.Set("dictionary", std::move(scoped_nested_dictionary)); |
| 435 | 436 |
| 436 scoped_ptr<DictionaryValue> copy_dict = original_dict.CreateDeepCopy(); | 437 scoped_ptr<DictionaryValue> copy_dict = original_dict.CreateDeepCopy(); |
| 437 ASSERT_TRUE(copy_dict.get()); | 438 ASSERT_TRUE(copy_dict.get()); |
| 438 ASSERT_NE(copy_dict.get(), &original_dict); | 439 ASSERT_NE(copy_dict.get(), &original_dict); |
| 439 | 440 |
| 440 Value* copy_null = NULL; | 441 Value* copy_null = NULL; |
| 441 ASSERT_TRUE(copy_dict->Get("null", ©_null)); | 442 ASSERT_TRUE(copy_dict->Get("null", ©_null)); |
| 442 ASSERT_TRUE(copy_null); | 443 ASSERT_TRUE(copy_null); |
| 443 ASSERT_NE(copy_null, original_null); | 444 ASSERT_NE(copy_null, original_null); |
| 444 ASSERT_TRUE(copy_null->IsType(Value::TYPE_NULL)); | 445 ASSERT_TRUE(copy_null->IsType(Value::TYPE_NULL)); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 | 562 |
| 562 scoped_ptr<DictionaryValue> copy = dv.CreateDeepCopy(); | 563 scoped_ptr<DictionaryValue> copy = dv.CreateDeepCopy(); |
| 563 EXPECT_TRUE(dv.Equals(copy.get())); | 564 EXPECT_TRUE(dv.Equals(copy.get())); |
| 564 | 565 |
| 565 scoped_ptr<ListValue> list(new ListValue); | 566 scoped_ptr<ListValue> list(new ListValue); |
| 566 ListValue* original_list = list.get(); | 567 ListValue* original_list = list.get(); |
| 567 list->Append(Value::CreateNullValue()); | 568 list->Append(Value::CreateNullValue()); |
| 568 list->Append(make_scoped_ptr(new DictionaryValue)); | 569 list->Append(make_scoped_ptr(new DictionaryValue)); |
| 569 scoped_ptr<Value> list_copy(list->CreateDeepCopy()); | 570 scoped_ptr<Value> list_copy(list->CreateDeepCopy()); |
| 570 | 571 |
| 571 dv.Set("f", list.Pass()); | 572 dv.Set("f", std::move(list)); |
| 572 EXPECT_FALSE(dv.Equals(copy.get())); | 573 EXPECT_FALSE(dv.Equals(copy.get())); |
| 573 copy->Set("f", list_copy.Pass()); | 574 copy->Set("f", std::move(list_copy)); |
| 574 EXPECT_TRUE(dv.Equals(copy.get())); | 575 EXPECT_TRUE(dv.Equals(copy.get())); |
| 575 | 576 |
| 576 original_list->Append(make_scoped_ptr(new FundamentalValue(true))); | 577 original_list->Append(make_scoped_ptr(new FundamentalValue(true))); |
| 577 EXPECT_FALSE(dv.Equals(copy.get())); | 578 EXPECT_FALSE(dv.Equals(copy.get())); |
| 578 | 579 |
| 579 // Check if Equals detects differences in only the keys. | 580 // Check if Equals detects differences in only the keys. |
| 580 copy = dv.CreateDeepCopy(); | 581 copy = dv.CreateDeepCopy(); |
| 581 EXPECT_TRUE(dv.Equals(copy.get())); | 582 EXPECT_TRUE(dv.Equals(copy.get())); |
| 582 copy->Remove("a", NULL); | 583 copy->Remove("a", NULL); |
| 583 copy->SetBoolean("aa", false); | 584 copy->SetBoolean("aa", false); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 604 // support for NULL as a return value for "undefined" without caring for | 605 // support for NULL as a return value for "undefined" without caring for |
| 605 // ownership of the pointer. | 606 // ownership of the pointer. |
| 606 EXPECT_FALSE(Value::Equals(null1.get(), NULL)); | 607 EXPECT_FALSE(Value::Equals(null1.get(), NULL)); |
| 607 EXPECT_FALSE(Value::Equals(NULL, null1.get())); | 608 EXPECT_FALSE(Value::Equals(NULL, null1.get())); |
| 608 } | 609 } |
| 609 | 610 |
| 610 TEST(ValuesTest, DeepCopyCovariantReturnTypes) { | 611 TEST(ValuesTest, DeepCopyCovariantReturnTypes) { |
| 611 DictionaryValue original_dict; | 612 DictionaryValue original_dict; |
| 612 scoped_ptr<Value> scoped_null(Value::CreateNullValue()); | 613 scoped_ptr<Value> scoped_null(Value::CreateNullValue()); |
| 613 Value* original_null = scoped_null.get(); | 614 Value* original_null = scoped_null.get(); |
| 614 original_dict.Set("null", scoped_null.Pass()); | 615 original_dict.Set("null", std::move(scoped_null)); |
| 615 scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true)); | 616 scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true)); |
| 616 Value* original_bool = scoped_bool.get(); | 617 Value* original_bool = scoped_bool.get(); |
| 617 original_dict.Set("bool", scoped_bool.Pass()); | 618 original_dict.Set("bool", std::move(scoped_bool)); |
| 618 scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42)); | 619 scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42)); |
| 619 Value* original_int = scoped_int.get(); | 620 Value* original_int = scoped_int.get(); |
| 620 original_dict.Set("int", scoped_int.Pass()); | 621 original_dict.Set("int", std::move(scoped_int)); |
| 621 scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14)); | 622 scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14)); |
| 622 Value* original_double = scoped_double.get(); | 623 Value* original_double = scoped_double.get(); |
| 623 original_dict.Set("double", scoped_double.Pass()); | 624 original_dict.Set("double", std::move(scoped_double)); |
| 624 scoped_ptr<StringValue> scoped_string(new StringValue("hello")); | 625 scoped_ptr<StringValue> scoped_string(new StringValue("hello")); |
| 625 Value* original_string = scoped_string.get(); | 626 Value* original_string = scoped_string.get(); |
| 626 original_dict.Set("string", scoped_string.Pass()); | 627 original_dict.Set("string", std::move(scoped_string)); |
| 627 scoped_ptr<StringValue> scoped_string16( | 628 scoped_ptr<StringValue> scoped_string16( |
| 628 new StringValue(ASCIIToUTF16("hello16"))); | 629 new StringValue(ASCIIToUTF16("hello16"))); |
| 629 Value* original_string16 = scoped_string16.get(); | 630 Value* original_string16 = scoped_string16.get(); |
| 630 original_dict.Set("string16", scoped_string16.Pass()); | 631 original_dict.Set("string16", std::move(scoped_string16)); |
| 631 | 632 |
| 632 scoped_ptr<char[]> original_buffer(new char[42]); | 633 scoped_ptr<char[]> original_buffer(new char[42]); |
| 633 memset(original_buffer.get(), '!', 42); | 634 memset(original_buffer.get(), '!', 42); |
| 634 scoped_ptr<BinaryValue> scoped_binary( | 635 scoped_ptr<BinaryValue> scoped_binary( |
| 635 new BinaryValue(original_buffer.Pass(), 42)); | 636 new BinaryValue(std::move(original_buffer), 42)); |
| 636 Value* original_binary = scoped_binary.get(); | 637 Value* original_binary = scoped_binary.get(); |
| 637 original_dict.Set("binary", scoped_binary.Pass()); | 638 original_dict.Set("binary", std::move(scoped_binary)); |
| 638 | 639 |
| 639 scoped_ptr<ListValue> scoped_list(new ListValue()); | 640 scoped_ptr<ListValue> scoped_list(new ListValue()); |
| 640 Value* original_list = scoped_list.get(); | 641 Value* original_list = scoped_list.get(); |
| 641 scoped_ptr<FundamentalValue> scoped_list_element_0(new FundamentalValue(0)); | 642 scoped_ptr<FundamentalValue> scoped_list_element_0(new FundamentalValue(0)); |
| 642 scoped_list->Append(scoped_list_element_0.Pass()); | 643 scoped_list->Append(std::move(scoped_list_element_0)); |
| 643 scoped_ptr<FundamentalValue> scoped_list_element_1(new FundamentalValue(1)); | 644 scoped_ptr<FundamentalValue> scoped_list_element_1(new FundamentalValue(1)); |
| 644 scoped_list->Append(scoped_list_element_1.Pass()); | 645 scoped_list->Append(std::move(scoped_list_element_1)); |
| 645 original_dict.Set("list", scoped_list.Pass()); | 646 original_dict.Set("list", std::move(scoped_list)); |
| 646 | 647 |
| 647 scoped_ptr<Value> copy_dict = original_dict.CreateDeepCopy(); | 648 scoped_ptr<Value> copy_dict = original_dict.CreateDeepCopy(); |
| 648 scoped_ptr<Value> copy_null = original_null->CreateDeepCopy(); | 649 scoped_ptr<Value> copy_null = original_null->CreateDeepCopy(); |
| 649 scoped_ptr<Value> copy_bool = original_bool->CreateDeepCopy(); | 650 scoped_ptr<Value> copy_bool = original_bool->CreateDeepCopy(); |
| 650 scoped_ptr<Value> copy_int = original_int->CreateDeepCopy(); | 651 scoped_ptr<Value> copy_int = original_int->CreateDeepCopy(); |
| 651 scoped_ptr<Value> copy_double = original_double->CreateDeepCopy(); | 652 scoped_ptr<Value> copy_double = original_double->CreateDeepCopy(); |
| 652 scoped_ptr<Value> copy_string = original_string->CreateDeepCopy(); | 653 scoped_ptr<Value> copy_string = original_string->CreateDeepCopy(); |
| 653 scoped_ptr<Value> copy_string16 = original_string16->CreateDeepCopy(); | 654 scoped_ptr<Value> copy_string16 = original_string16->CreateDeepCopy(); |
| 654 scoped_ptr<Value> copy_binary = original_binary->CreateDeepCopy(); | 655 scoped_ptr<Value> copy_binary = original_binary->CreateDeepCopy(); |
| 655 scoped_ptr<Value> copy_list = original_list->CreateDeepCopy(); | 656 scoped_ptr<Value> copy_list = original_list->CreateDeepCopy(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 // set above. | 691 // set above. |
| 691 { | 692 { |
| 692 root->Set("a.b.c.d.e", make_scoped_ptr(new DictionaryValue)); | 693 root->Set("a.b.c.d.e", make_scoped_ptr(new DictionaryValue)); |
| 693 root = root->DeepCopyWithoutEmptyChildren(); | 694 root = root->DeepCopyWithoutEmptyChildren(); |
| 694 EXPECT_EQ(2U, root->size()); | 695 EXPECT_EQ(2U, root->size()); |
| 695 } | 696 } |
| 696 { | 697 { |
| 697 scoped_ptr<DictionaryValue> inner(new DictionaryValue); | 698 scoped_ptr<DictionaryValue> inner(new DictionaryValue); |
| 698 inner->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); | 699 inner->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); |
| 699 inner->Set("empty_list", make_scoped_ptr(new ListValue)); | 700 inner->Set("empty_list", make_scoped_ptr(new ListValue)); |
| 700 root->Set("dict_with_empty_children", inner.Pass()); | 701 root->Set("dict_with_empty_children", std::move(inner)); |
| 701 root = root->DeepCopyWithoutEmptyChildren(); | 702 root = root->DeepCopyWithoutEmptyChildren(); |
| 702 EXPECT_EQ(2U, root->size()); | 703 EXPECT_EQ(2U, root->size()); |
| 703 } | 704 } |
| 704 { | 705 { |
| 705 scoped_ptr<ListValue> inner(new ListValue); | 706 scoped_ptr<ListValue> inner(new ListValue); |
| 706 inner->Append(make_scoped_ptr(new DictionaryValue)); | 707 inner->Append(make_scoped_ptr(new DictionaryValue)); |
| 707 inner->Append(make_scoped_ptr(new ListValue)); | 708 inner->Append(make_scoped_ptr(new ListValue)); |
| 708 root->Set("list_with_empty_children", inner.Pass()); | 709 root->Set("list_with_empty_children", std::move(inner)); |
| 709 root = root->DeepCopyWithoutEmptyChildren(); | 710 root = root->DeepCopyWithoutEmptyChildren(); |
| 710 EXPECT_EQ(2U, root->size()); | 711 EXPECT_EQ(2U, root->size()); |
| 711 } | 712 } |
| 712 | 713 |
| 713 // Nested with siblings. | 714 // Nested with siblings. |
| 714 { | 715 { |
| 715 scoped_ptr<ListValue> inner(new ListValue()); | 716 scoped_ptr<ListValue> inner(new ListValue()); |
| 716 inner->Append(make_scoped_ptr(new DictionaryValue)); | 717 inner->Append(make_scoped_ptr(new DictionaryValue)); |
| 717 inner->Append(make_scoped_ptr(new ListValue)); | 718 inner->Append(make_scoped_ptr(new ListValue)); |
| 718 root->Set("list_with_empty_children", inner.Pass()); | 719 root->Set("list_with_empty_children", std::move(inner)); |
| 719 scoped_ptr<DictionaryValue> inner2(new DictionaryValue); | 720 scoped_ptr<DictionaryValue> inner2(new DictionaryValue); |
| 720 inner2->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); | 721 inner2->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); |
| 721 inner2->Set("empty_list", make_scoped_ptr(new ListValue)); | 722 inner2->Set("empty_list", make_scoped_ptr(new ListValue)); |
| 722 root->Set("dict_with_empty_children", inner2.Pass()); | 723 root->Set("dict_with_empty_children", std::move(inner2)); |
| 723 root = root->DeepCopyWithoutEmptyChildren(); | 724 root = root->DeepCopyWithoutEmptyChildren(); |
| 724 EXPECT_EQ(2U, root->size()); | 725 EXPECT_EQ(2U, root->size()); |
| 725 } | 726 } |
| 726 | 727 |
| 727 // Make sure nested values don't get pruned. | 728 // Make sure nested values don't get pruned. |
| 728 { | 729 { |
| 729 scoped_ptr<ListValue> inner(new ListValue); | 730 scoped_ptr<ListValue> inner(new ListValue); |
| 730 scoped_ptr<ListValue> inner2(new ListValue); | 731 scoped_ptr<ListValue> inner2(new ListValue); |
| 731 inner2->Append(make_scoped_ptr(new StringValue("hello"))); | 732 inner2->Append(make_scoped_ptr(new StringValue("hello"))); |
| 732 inner->Append(make_scoped_ptr(new DictionaryValue)); | 733 inner->Append(make_scoped_ptr(new DictionaryValue)); |
| 733 inner->Append(inner2.Pass()); | 734 inner->Append(std::move(inner2)); |
| 734 root->Set("list_with_empty_children", inner.Pass()); | 735 root->Set("list_with_empty_children", std::move(inner)); |
| 735 root = root->DeepCopyWithoutEmptyChildren(); | 736 root = root->DeepCopyWithoutEmptyChildren(); |
| 736 EXPECT_EQ(3U, root->size()); | 737 EXPECT_EQ(3U, root->size()); |
| 737 | 738 |
| 738 ListValue* inner_value, *inner_value2; | 739 ListValue* inner_value, *inner_value2; |
| 739 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner_value)); | 740 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner_value)); |
| 740 EXPECT_EQ(1U, inner_value->GetSize()); // Dictionary was pruned. | 741 EXPECT_EQ(1U, inner_value->GetSize()); // Dictionary was pruned. |
| 741 EXPECT_TRUE(inner_value->GetList(0, &inner_value2)); | 742 EXPECT_TRUE(inner_value->GetList(0, &inner_value2)); |
| 742 EXPECT_EQ(1U, inner_value2->GetSize()); | 743 EXPECT_EQ(1U, inner_value2->GetSize()); |
| 743 } | 744 } |
| 744 } | 745 } |
| 745 | 746 |
| 746 TEST(ValuesTest, MergeDictionary) { | 747 TEST(ValuesTest, MergeDictionary) { |
| 747 scoped_ptr<DictionaryValue> base(new DictionaryValue); | 748 scoped_ptr<DictionaryValue> base(new DictionaryValue); |
| 748 base->SetString("base_key", "base_key_value_base"); | 749 base->SetString("base_key", "base_key_value_base"); |
| 749 base->SetString("collide_key", "collide_key_value_base"); | 750 base->SetString("collide_key", "collide_key_value_base"); |
| 750 scoped_ptr<DictionaryValue> base_sub_dict(new DictionaryValue); | 751 scoped_ptr<DictionaryValue> base_sub_dict(new DictionaryValue); |
| 751 base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base"); | 752 base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base"); |
| 752 base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base"); | 753 base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base"); |
| 753 base->Set("sub_dict_key", base_sub_dict.Pass()); | 754 base->Set("sub_dict_key", std::move(base_sub_dict)); |
| 754 | 755 |
| 755 scoped_ptr<DictionaryValue> merge(new DictionaryValue); | 756 scoped_ptr<DictionaryValue> merge(new DictionaryValue); |
| 756 merge->SetString("merge_key", "merge_key_value_merge"); | 757 merge->SetString("merge_key", "merge_key_value_merge"); |
| 757 merge->SetString("collide_key", "collide_key_value_merge"); | 758 merge->SetString("collide_key", "collide_key_value_merge"); |
| 758 scoped_ptr<DictionaryValue> merge_sub_dict(new DictionaryValue); | 759 scoped_ptr<DictionaryValue> merge_sub_dict(new DictionaryValue); |
| 759 merge_sub_dict->SetString("sub_merge_key", "sub_merge_key_value_merge"); | 760 merge_sub_dict->SetString("sub_merge_key", "sub_merge_key_value_merge"); |
| 760 merge_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_merge"); | 761 merge_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_merge"); |
| 761 merge->Set("sub_dict_key", merge_sub_dict.Pass()); | 762 merge->Set("sub_dict_key", std::move(merge_sub_dict)); |
| 762 | 763 |
| 763 base->MergeDictionary(merge.get()); | 764 base->MergeDictionary(merge.get()); |
| 764 | 765 |
| 765 EXPECT_EQ(4U, base->size()); | 766 EXPECT_EQ(4U, base->size()); |
| 766 std::string base_key_value; | 767 std::string base_key_value; |
| 767 EXPECT_TRUE(base->GetString("base_key", &base_key_value)); | 768 EXPECT_TRUE(base->GetString("base_key", &base_key_value)); |
| 768 EXPECT_EQ("base_key_value_base", base_key_value); // Base value preserved. | 769 EXPECT_EQ("base_key_value_base", base_key_value); // Base value preserved. |
| 769 std::string collide_key_value; | 770 std::string collide_key_value; |
| 770 EXPECT_TRUE(base->GetString("collide_key", &collide_key_value)); | 771 EXPECT_TRUE(base->GetString("collide_key", &collide_key_value)); |
| 771 EXPECT_EQ("collide_key_value_merge", collide_key_value); // Replaced. | 772 EXPECT_EQ("collide_key_value_merge", collide_key_value); // Replaced. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 792 scoped_ptr<DictionaryValue> child(new DictionaryValue); | 793 scoped_ptr<DictionaryValue> child(new DictionaryValue); |
| 793 DictionaryValue* original_child = child.get(); | 794 DictionaryValue* original_child = child.get(); |
| 794 child->SetString("test", "value"); | 795 child->SetString("test", "value"); |
| 795 EXPECT_EQ(1U, child->size()); | 796 EXPECT_EQ(1U, child->size()); |
| 796 | 797 |
| 797 std::string value; | 798 std::string value; |
| 798 EXPECT_TRUE(child->GetString("test", &value)); | 799 EXPECT_TRUE(child->GetString("test", &value)); |
| 799 EXPECT_EQ("value", value); | 800 EXPECT_EQ("value", value); |
| 800 | 801 |
| 801 scoped_ptr<DictionaryValue> base(new DictionaryValue); | 802 scoped_ptr<DictionaryValue> base(new DictionaryValue); |
| 802 base->Set("dict", child.Pass()); | 803 base->Set("dict", std::move(child)); |
| 803 EXPECT_EQ(1U, base->size()); | 804 EXPECT_EQ(1U, base->size()); |
| 804 | 805 |
| 805 DictionaryValue* ptr; | 806 DictionaryValue* ptr; |
| 806 EXPECT_TRUE(base->GetDictionary("dict", &ptr)); | 807 EXPECT_TRUE(base->GetDictionary("dict", &ptr)); |
| 807 EXPECT_EQ(original_child, ptr); | 808 EXPECT_EQ(original_child, ptr); |
| 808 | 809 |
| 809 scoped_ptr<DictionaryValue> merged(new DictionaryValue); | 810 scoped_ptr<DictionaryValue> merged(new DictionaryValue); |
| 810 merged->MergeDictionary(base.get()); | 811 merged->MergeDictionary(base.get()); |
| 811 EXPECT_EQ(1U, merged->size()); | 812 EXPECT_EQ(1U, merged->size()); |
| 812 EXPECT_TRUE(merged->GetDictionary("dict", &ptr)); | 813 EXPECT_TRUE(merged->GetDictionary("dict", &ptr)); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 EXPECT_FALSE(main_list.GetList(1, NULL)); | 1137 EXPECT_FALSE(main_list.GetList(1, NULL)); |
| 1137 EXPECT_FALSE(main_list.GetList(2, NULL)); | 1138 EXPECT_FALSE(main_list.GetList(2, NULL)); |
| 1138 EXPECT_FALSE(main_list.GetList(3, NULL)); | 1139 EXPECT_FALSE(main_list.GetList(3, NULL)); |
| 1139 EXPECT_FALSE(main_list.GetList(4, NULL)); | 1140 EXPECT_FALSE(main_list.GetList(4, NULL)); |
| 1140 EXPECT_FALSE(main_list.GetList(5, NULL)); | 1141 EXPECT_FALSE(main_list.GetList(5, NULL)); |
| 1141 EXPECT_TRUE(main_list.GetList(6, NULL)); | 1142 EXPECT_TRUE(main_list.GetList(6, NULL)); |
| 1142 EXPECT_FALSE(main_list.GetList(7, NULL)); | 1143 EXPECT_FALSE(main_list.GetList(7, NULL)); |
| 1143 } | 1144 } |
| 1144 | 1145 |
| 1145 } // namespace base | 1146 } // namespace base |
| OLD | NEW |