1 // Copyright 2014 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 "components/invalidation/object_id_invalidation_map.h"
7 #include "google/cacheinvalidation/types.pb.h"
9 #include "testing/gtest/include/gtest/gtest.h"
15 class ObjectIdInvalidationMapTest
: public testing::Test
{
17 ObjectIdInvalidationMapTest()
18 : kIdOne(ipc::invalidation::ObjectSource::TEST
, "one"),
19 kIdTwo(ipc::invalidation::ObjectSource::TEST
, "two"),
20 kInv1(Invalidation::Init(kIdOne
, 10, "ten")) {
23 all_set
.insert(kIdOne
);
24 all_set
.insert(kIdTwo
);
26 one_invalidation
.Insert(kInv1
);
27 invalidate_all
= ObjectIdInvalidationMap::InvalidateAll(all_set
);
31 const invalidation::ObjectId kIdOne
;
32 const invalidation::ObjectId kIdTwo
;
33 const Invalidation kInv1
;
38 ObjectIdInvalidationMap empty
;
39 ObjectIdInvalidationMap one_invalidation
;
40 ObjectIdInvalidationMap invalidate_all
;
43 TEST_F(ObjectIdInvalidationMapTest
, Empty
) {
44 EXPECT_TRUE(empty
.Empty());
45 EXPECT_FALSE(one_invalidation
.Empty());
46 EXPECT_FALSE(invalidate_all
.Empty());
49 TEST_F(ObjectIdInvalidationMapTest
, Equality
) {
50 ObjectIdInvalidationMap empty2
;
51 EXPECT_TRUE(empty
== empty2
);
53 ObjectIdInvalidationMap one_invalidation2
;
54 one_invalidation2
.Insert(kInv1
);
55 EXPECT_TRUE(one_invalidation
== one_invalidation2
);
57 EXPECT_FALSE(empty
== invalidate_all
);
60 TEST_F(ObjectIdInvalidationMapTest
, GetObjectIds
) {
61 EXPECT_EQ(ObjectIdSet(), empty
.GetObjectIds());
62 EXPECT_EQ(set1
, one_invalidation
.GetObjectIds());
63 EXPECT_EQ(all_set
, invalidate_all
.GetObjectIds());
66 TEST_F(ObjectIdInvalidationMapTest
, GetSubsetWithObjectIds
) {
67 EXPECT_TRUE(empty
.GetSubsetWithObjectIds(set1
).Empty());
69 EXPECT_TRUE(one_invalidation
.GetSubsetWithObjectIds(set1
) ==
71 EXPECT_TRUE(one_invalidation
.GetSubsetWithObjectIds(all_set
) ==
73 EXPECT_TRUE(one_invalidation
.GetSubsetWithObjectIds(set2
).Empty());
75 EXPECT_TRUE(invalidate_all
.GetSubsetWithObjectIds(ObjectIdSet()).Empty());
78 TEST_F(ObjectIdInvalidationMapTest
, SerializeEmpty
) {
79 scoped_ptr
<base::ListValue
> value
= empty
.ToValue();
80 ASSERT_TRUE(value
.get());
81 ObjectIdInvalidationMap deserialized
;
82 deserialized
.ResetFromValue(*value
.get());
83 EXPECT_TRUE(empty
== deserialized
);
86 TEST_F(ObjectIdInvalidationMapTest
, SerializeOneInvalidation
) {
87 scoped_ptr
<base::ListValue
> value
= one_invalidation
.ToValue();
88 ASSERT_TRUE(value
.get());
89 ObjectIdInvalidationMap deserialized
;
90 deserialized
.ResetFromValue(*value
.get());
91 EXPECT_TRUE(one_invalidation
== deserialized
);
94 TEST_F(ObjectIdInvalidationMapTest
, SerializeInvalidateAll
) {
95 scoped_ptr
<base::ListValue
> value
= invalidate_all
.ToValue();
96 ASSERT_TRUE(value
.get());
97 ObjectIdInvalidationMap deserialized
;
98 deserialized
.ResetFromValue(*value
.get());
99 EXPECT_TRUE(invalidate_all
== deserialized
);
104 } // namespace syncer