Fix style nits in gdata directory.
[chromium-blink-merge.git] / base / property_bag_unittest.cc
blobb267d0459842bf6255d2da890f87729943ba3ad0
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"
8 namespace base {
10 TEST(PropertyBagTest, AddQueryRemove) {
11 PropertyBag bag;
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.
39 PropertyBag copy;
40 adaptor1.SetProperty(&copy, 22);
42 const int kType1Value = 10;
43 const double kType2Value = 2.7;
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);
50 // Assign to the original.
51 copy = initial;
54 // Verify the copy got the two properties.
55 ASSERT_TRUE(adaptor1.GetProperty(&copy));
56 ASSERT_TRUE(adaptor2.GetProperty(&copy));
57 EXPECT_EQ(kType1Value, *adaptor1.GetProperty(&copy));
58 EXPECT_EQ(kType2Value, *adaptor2.GetProperty(&copy));
60 // Clear it out, neither property should be left.
61 copy = PropertyBag();
62 EXPECT_TRUE(adaptor1.GetProperty(&copy) == NULL);
63 EXPECT_TRUE(adaptor2.GetProperty(&copy) == NULL);
66 } // namespace base