| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 "base/property_bag.h" | |
| 6 #include "testing/gtest/include/gtest/gtest.h" | |
| 7 | |
| 8 namespace base { | |
| 9 | |
| 10 TEST(PropertyBagTest, AddQueryRemove) { | |
| 11 PropertyBag bag; | |
| 12 PropertyAccessor<int> adaptor; | |
| 13 | |
| 14 // Should be no match initially. | |
| 15 EXPECT_TRUE(adaptor.GetProperty(&bag) == NULL); | |
| 16 | |
| 17 // Add the value and make sure we get it back. | |
| 18 const int kFirstValue = 1; | |
| 19 adaptor.SetProperty(&bag, kFirstValue); | |
| 20 ASSERT_TRUE(adaptor.GetProperty(&bag)); | |
| 21 EXPECT_EQ(kFirstValue, *adaptor.GetProperty(&bag)); | |
| 22 | |
| 23 // Set it to a new value. | |
| 24 const int kSecondValue = 2; | |
| 25 adaptor.SetProperty(&bag, kSecondValue); | |
| 26 ASSERT_TRUE(adaptor.GetProperty(&bag)); | |
| 27 EXPECT_EQ(kSecondValue, *adaptor.GetProperty(&bag)); | |
| 28 | |
| 29 // Remove the value and make sure it's gone. | |
| 30 adaptor.DeleteProperty(&bag); | |
| 31 EXPECT_TRUE(adaptor.GetProperty(&bag) == NULL); | |
| 32 } | |
| 33 | |
| 34 TEST(PropertyBagTest, Copy) { | |
| 35 PropertyAccessor<int> adaptor1; | |
| 36 PropertyAccessor<double> adaptor2; | |
| 37 | |
| 38 // Create a bag with property type 1 in it. | |
| 39 PropertyBag copy; | |
| 40 adaptor1.SetProperty(©, 22); | |
| 41 | |
| 42 const int kType1Value = 10; | |
| 43 const double kType2Value = 2.7; | |
| 44 { | |
| 45 // Create a bag with property types 1 and 2 in it. | |
| 46 PropertyBag initial; | |
| 47 adaptor1.SetProperty(&initial, kType1Value); | |
| 48 adaptor2.SetProperty(&initial, kType2Value); | |
| 49 | |
| 50 // Assign to the original. | |
| 51 copy = initial; | |
| 52 } | |
| 53 | |
| 54 // Verify the copy got the two properties. | |
| 55 ASSERT_TRUE(adaptor1.GetProperty(©)); | |
| 56 ASSERT_TRUE(adaptor2.GetProperty(©)); | |
| 57 EXPECT_EQ(kType1Value, *adaptor1.GetProperty(©)); | |
| 58 EXPECT_EQ(kType2Value, *adaptor2.GetProperty(©)); | |
| 59 | |
| 60 // Clear it out, neither property should be left. | |
| 61 copy = PropertyBag(); | |
| 62 EXPECT_TRUE(adaptor1.GetProperty(©) == NULL); | |
| 63 EXPECT_TRUE(adaptor2.GetProperty(©) == NULL); | |
| 64 } | |
| 65 | |
| 66 } // namespace base | |
| OLD | NEW |