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 "base/values.h" | 5 #include "base/values.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 | 567 |
568 TEST(ValuesTest, DictionaryDeletion) { | 568 TEST(ValuesTest, DictionaryDeletion) { |
569 std::string key = "test"; | 569 std::string key = "test"; |
570 DictionaryValue dict; | 570 DictionaryValue dict; |
571 dict.Set(key, MakeUnique<Value>()); | 571 dict.Set(key, MakeUnique<Value>()); |
572 EXPECT_FALSE(dict.empty()); | 572 EXPECT_FALSE(dict.empty()); |
573 dict.Clear(); | 573 dict.Clear(); |
574 EXPECT_TRUE(dict.empty()); | 574 EXPECT_TRUE(dict.empty()); |
575 } | 575 } |
576 | 576 |
| 577 TEST(ValuesTest, DictionarySetReturnsPointer) { |
| 578 { |
| 579 DictionaryValue dict; |
| 580 Value* blank_ptr = dict.Set("foo.bar", base::MakeUnique<base::Value>()); |
| 581 EXPECT_EQ(Value::Type::NONE, blank_ptr->type()); |
| 582 } |
| 583 |
| 584 { |
| 585 DictionaryValue dict; |
| 586 Value* blank_ptr = dict.SetWithoutPathExpansion( |
| 587 "foo.bar", base::MakeUnique<base::Value>()); |
| 588 EXPECT_EQ(Value::Type::NONE, blank_ptr->type()); |
| 589 } |
| 590 |
| 591 { |
| 592 DictionaryValue dict; |
| 593 Value* bool_ptr = dict.SetBooleanWithoutPathExpansion("foo.bar", false); |
| 594 EXPECT_EQ(Value::Type::BOOLEAN, bool_ptr->type()); |
| 595 EXPECT_FALSE(bool_ptr->GetBool()); |
| 596 } |
| 597 |
| 598 { |
| 599 DictionaryValue dict; |
| 600 Value* int_ptr = dict.SetInteger("foo.bar", 42); |
| 601 EXPECT_EQ(Value::Type::INTEGER, int_ptr->type()); |
| 602 EXPECT_EQ(42, int_ptr->GetInt()); |
| 603 } |
| 604 |
| 605 { |
| 606 DictionaryValue dict; |
| 607 Value* int_ptr = dict.SetIntegerWithoutPathExpansion("foo.bar", 123); |
| 608 EXPECT_EQ(Value::Type::INTEGER, int_ptr->type()); |
| 609 EXPECT_EQ(123, int_ptr->GetInt()); |
| 610 } |
| 611 |
| 612 { |
| 613 DictionaryValue dict; |
| 614 Value* double_ptr = dict.SetDouble("foo.bar", 3.142); |
| 615 EXPECT_EQ(Value::Type::DOUBLE, double_ptr->type()); |
| 616 EXPECT_EQ(3.142, double_ptr->GetDouble()); |
| 617 } |
| 618 |
| 619 { |
| 620 DictionaryValue dict; |
| 621 Value* double_ptr = dict.SetDoubleWithoutPathExpansion("foo.bar", 2.718); |
| 622 EXPECT_EQ(Value::Type::DOUBLE, double_ptr->type()); |
| 623 EXPECT_EQ(2.718, double_ptr->GetDouble()); |
| 624 } |
| 625 |
| 626 { |
| 627 DictionaryValue dict; |
| 628 Value* string_ptr = dict.SetString("foo.bar", "foo"); |
| 629 EXPECT_EQ(Value::Type::STRING, string_ptr->type()); |
| 630 EXPECT_EQ("foo", string_ptr->GetString()); |
| 631 } |
| 632 |
| 633 { |
| 634 DictionaryValue dict; |
| 635 Value* string_ptr = dict.SetStringWithoutPathExpansion("foo.bar", "bar"); |
| 636 EXPECT_EQ(Value::Type::STRING, string_ptr->type()); |
| 637 EXPECT_EQ("bar", string_ptr->GetString()); |
| 638 } |
| 639 |
| 640 { |
| 641 DictionaryValue dict; |
| 642 Value* string16_ptr = dict.SetString("foo.bar", ASCIIToUTF16("baz")); |
| 643 EXPECT_EQ(Value::Type::STRING, string16_ptr->type()); |
| 644 EXPECT_EQ("baz", string16_ptr->GetString()); |
| 645 } |
| 646 |
| 647 { |
| 648 DictionaryValue dict; |
| 649 Value* string16_ptr = |
| 650 dict.SetStringWithoutPathExpansion("foo.bar", ASCIIToUTF16("qux")); |
| 651 EXPECT_EQ(Value::Type::STRING, string16_ptr->type()); |
| 652 EXPECT_EQ("qux", string16_ptr->GetString()); |
| 653 } |
| 654 |
| 655 { |
| 656 DictionaryValue dict; |
| 657 DictionaryValue* dict_ptr = dict.SetDictionary( |
| 658 "foo.bar", base::MakeUnique<base::DictionaryValue>()); |
| 659 EXPECT_EQ(Value::Type::DICTIONARY, dict_ptr->type()); |
| 660 } |
| 661 |
| 662 { |
| 663 DictionaryValue dict; |
| 664 DictionaryValue* dict_ptr = dict.SetDictionaryWithoutPathExpansion( |
| 665 "foo.bar", base::MakeUnique<base::DictionaryValue>()); |
| 666 EXPECT_EQ(Value::Type::DICTIONARY, dict_ptr->type()); |
| 667 } |
| 668 |
| 669 { |
| 670 DictionaryValue dict; |
| 671 ListValue* list_ptr = |
| 672 dict.SetList("foo.bar", base::MakeUnique<base::ListValue>()); |
| 673 EXPECT_EQ(Value::Type::LIST, list_ptr->type()); |
| 674 } |
| 675 |
| 676 { |
| 677 DictionaryValue dict; |
| 678 ListValue* list_ptr = dict.SetListWithoutPathExpansion( |
| 679 "foo.bar", base::MakeUnique<base::ListValue>()); |
| 680 EXPECT_EQ(Value::Type::LIST, list_ptr->type()); |
| 681 } |
| 682 } |
| 683 |
577 TEST(ValuesTest, DictionaryRemoval) { | 684 TEST(ValuesTest, DictionaryRemoval) { |
578 std::string key = "test"; | 685 std::string key = "test"; |
579 std::unique_ptr<Value> removed_item; | 686 std::unique_ptr<Value> removed_item; |
580 | 687 |
581 { | 688 { |
582 DictionaryValue dict; | 689 DictionaryValue dict; |
583 dict.Set(key, MakeUnique<Value>()); | 690 dict.Set(key, MakeUnique<Value>()); |
584 EXPECT_TRUE(dict.HasKey(key)); | 691 EXPECT_TRUE(dict.HasKey(key)); |
585 EXPECT_FALSE(dict.Remove("absent key", &removed_item)); | 692 EXPECT_FALSE(dict.Remove("absent key", &removed_item)); |
586 EXPECT_TRUE(dict.Remove(key, &removed_item)); | 693 EXPECT_TRUE(dict.Remove(key, &removed_item)); |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1531 EXPECT_FALSE(main_list.GetList(7, NULL)); | 1638 EXPECT_FALSE(main_list.GetList(7, NULL)); |
1532 } | 1639 } |
1533 | 1640 |
1534 TEST(ValuesTest, SelfSwap) { | 1641 TEST(ValuesTest, SelfSwap) { |
1535 base::Value test(1); | 1642 base::Value test(1); |
1536 std::swap(test, test); | 1643 std::swap(test, test); |
1537 EXPECT_TRUE(test.GetInt() == 1); | 1644 EXPECT_TRUE(test.GetInt() == 1); |
1538 } | 1645 } |
1539 | 1646 |
1540 } // namespace base | 1647 } // namespace base |
OLD | NEW |