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.
5 #include "sync/notifier/single_object_invalidation_set.h"
7 #include "google/cacheinvalidation/types.pb.h"
8 #include "sync/internal_api/public/base/invalidation_test_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
15 class SingleObjectInvalidationSetTest
: public testing::Test
{
17 SingleObjectInvalidationSetTest()
18 : kId(ipc::invalidation::ObjectSource::TEST
, "one") {
21 const invalidation::ObjectId kId
;
24 TEST_F(SingleObjectInvalidationSetTest
, InsertionAndOrdering
) {
25 SingleObjectInvalidationSet l1
;
26 SingleObjectInvalidationSet l2
;
28 Invalidation inv0
= Invalidation::InitUnknownVersion(kId
);
29 Invalidation inv1
= Invalidation::Init(kId
, 1, "one");
30 Invalidation inv2
= Invalidation::Init(kId
, 5, "five");
40 ASSERT_EQ(3U, l1
.GetSize());
41 ASSERT_EQ(3U, l2
.GetSize());
43 SingleObjectInvalidationSet::const_iterator it1
= l1
.begin();
44 SingleObjectInvalidationSet::const_iterator it2
= l2
.begin();
45 EXPECT_THAT(inv0
, Eq(*it1
));
46 EXPECT_THAT(inv0
, Eq(*it2
));
49 EXPECT_THAT(inv1
, Eq(*it1
));
50 EXPECT_THAT(inv1
, Eq(*it2
));
53 EXPECT_THAT(inv2
, Eq(*it1
));
54 EXPECT_THAT(inv2
, Eq(*it2
));
57 EXPECT_TRUE(it1
== l1
.end());
58 EXPECT_TRUE(it2
== l2
.end());
61 TEST_F(SingleObjectInvalidationSetTest
, StartWithUnknownVersion
) {
62 SingleObjectInvalidationSet list
;
63 EXPECT_FALSE(list
.StartsWithUnknownVersion());
65 list
.Insert(Invalidation::Init(kId
, 1, "one"));
66 EXPECT_FALSE(list
.StartsWithUnknownVersion());
68 list
.Insert(Invalidation::InitUnknownVersion(kId
));
69 EXPECT_TRUE(list
.StartsWithUnknownVersion());
72 EXPECT_FALSE(list
.StartsWithUnknownVersion());
75 TEST_F(SingleObjectInvalidationSetTest
, SerializeEmpty
) {
76 SingleObjectInvalidationSet list
;
78 scoped_ptr
<base::ListValue
> value
= list
.ToValue();
79 ASSERT_TRUE(value
.get());
80 SingleObjectInvalidationSet deserialized
;
81 deserialized
.ResetFromValue(*value
.get());
82 EXPECT_TRUE(list
== deserialized
);
85 TEST_F(SingleObjectInvalidationSetTest
, SerializeOne
) {
86 SingleObjectInvalidationSet list
;
87 list
.Insert(Invalidation::Init(kId
, 1, "one"));
89 scoped_ptr
<base::ListValue
> value
= list
.ToValue();
90 ASSERT_TRUE(value
.get());
91 SingleObjectInvalidationSet deserialized
;
92 deserialized
.ResetFromValue(*value
.get());
93 EXPECT_TRUE(list
== deserialized
);
96 TEST_F(SingleObjectInvalidationSetTest
, SerializeMany
) {
97 SingleObjectInvalidationSet list
;
98 list
.Insert(Invalidation::Init(kId
, 1, "one"));
99 list
.Insert(Invalidation::InitUnknownVersion(kId
));
101 scoped_ptr
<base::ListValue
> value
= list
.ToValue();
102 ASSERT_TRUE(value
.get());
103 SingleObjectInvalidationSet deserialized
;
104 deserialized
.ResetFromValue(*value
.get());
105 EXPECT_TRUE(list
== deserialized
);
110 } // namespace syncer