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