1 // Copyright 2013 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 "sync/notifier/object_id_invalidation_map.h" 6 7 #include "google/cacheinvalidation/types.pb.h" 8 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 namespace syncer { 12 13 namespace { 14 15 class ObjectIdInvalidationMapTest : public testing::Test { 16 public: 17 ObjectIdInvalidationMapTest() 18 : kIdOne(ipc::invalidation::ObjectSource::TEST, "one"), 19 kIdTwo(ipc::invalidation::ObjectSource::TEST, "two"), 20 kInv1(Invalidation::Init(kIdOne, 10, "ten")) { 21 set1.insert(kIdOne); 22 set2.insert(kIdTwo); 23 all_set.insert(kIdOne); 24 all_set.insert(kIdTwo); 25 26 one_invalidation.Insert(kInv1); 27 invalidate_all = ObjectIdInvalidationMap::InvalidateAll(all_set); 28 } 29 30 protected: 31 const invalidation::ObjectId kIdOne; 32 const invalidation::ObjectId kIdTwo; 33 const Invalidation kInv1; 34 35 ObjectIdSet set1; 36 ObjectIdSet set2; 37 ObjectIdSet all_set; 38 ObjectIdInvalidationMap empty; 39 ObjectIdInvalidationMap one_invalidation; 40 ObjectIdInvalidationMap invalidate_all; 41 }; 42 43 TEST_F(ObjectIdInvalidationMapTest, Empty) { 44 EXPECT_TRUE(empty.Empty()); 45 EXPECT_FALSE(one_invalidation.Empty()); 46 EXPECT_FALSE(invalidate_all.Empty()); 47 } 48 49 TEST_F(ObjectIdInvalidationMapTest, Equality) { 50 ObjectIdInvalidationMap empty2; 51 EXPECT_TRUE(empty == empty2); 52 53 ObjectIdInvalidationMap one_invalidation2; 54 one_invalidation2.Insert(kInv1); 55 EXPECT_TRUE(one_invalidation == one_invalidation2); 56 57 EXPECT_FALSE(empty == invalidate_all); 58 } 59 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()); 64 } 65 66 TEST_F(ObjectIdInvalidationMapTest, GetSubsetWithObjectIds) { 67 EXPECT_TRUE(empty.GetSubsetWithObjectIds(set1).Empty()); 68 69 EXPECT_TRUE(one_invalidation.GetSubsetWithObjectIds(set1) == 70 one_invalidation); 71 EXPECT_TRUE(one_invalidation.GetSubsetWithObjectIds(all_set) == 72 one_invalidation); 73 EXPECT_TRUE(one_invalidation.GetSubsetWithObjectIds(set2).Empty()); 74 75 EXPECT_TRUE(invalidate_all.GetSubsetWithObjectIds(ObjectIdSet()).Empty()); 76 } 77 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); 84 } 85 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); 92 } 93 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); 100 } 101 102 } // namespace 103 104 } // namespace syncer 105