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.
5 #include "base/property_bag.h"
6 #include "testing/gtest/include/gtest/gtest.h"
10 TEST(PropertyBagTest
, AddQueryRemove
) {
12 PropertyAccessor
<int> adaptor
;
14 // Should be no match initially.
15 EXPECT_TRUE(adaptor
.GetProperty(&bag
) == NULL
);
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
));
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
));
29 // Remove the value and make sure it's gone.
30 adaptor
.DeleteProperty(&bag
);
31 EXPECT_TRUE(adaptor
.GetProperty(&bag
) == NULL
);
34 TEST(PropertyBagTest
, Copy
) {
35 PropertyAccessor
<int> adaptor1
;
36 PropertyAccessor
<double> adaptor2
;
38 // Create a bag with property type 1 in it.
40 adaptor1
.SetProperty(©
, 22);
42 const int kType1Value
= 10;
43 const double kType2Value
= 2.7;
45 // Create a bag with property types 1 and 2 in it.
47 adaptor1
.SetProperty(&initial
, kType1Value
);
48 adaptor2
.SetProperty(&initial
, kType2Value
);
50 // Assign to the original.
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(©
));
60 // Clear it out, neither property should be left.
62 EXPECT_TRUE(adaptor1
.GetProperty(©
) == NULL
);
63 EXPECT_TRUE(adaptor2
.GetProperty(©
) == NULL
);