Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: sync/notifier/unacked_invalidation_storage_test_util.cc

Issue 23754021: Invalidation trickles mega-patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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/unacked_invalidation_storage_test_util.h"
6
7 #include "base/json/json_string_value_serializer.h"
8 #include "sync/notifier/object_id_invalidation_map.h"
9 #include "testing/gmock/include/gmock/gmock-matchers.h"
10
11 namespace syncer {
12
13 using ::testing::MakeMatcher;
14 using ::testing::MatchResultListener;
15 using ::testing::Matcher;
16 using ::testing::MatcherInterface;
17 using ::testing::PrintToString;
18
19 namespace {
20
21 ObjectIdInvalidationMap UnackedInvalidationStorageMapToObjectIdInvalidationMap(
22 const UnackedInvalidationStorageMap& state_map) {
23 ObjectIdInvalidationMap object_id_invalidation_map;
24 for (UnackedInvalidationStorageMap::const_iterator it = state_map.begin();
25 it != state_map.end(); ++it) {
26 it->second.UnpackRecordedInvalidations(&object_id_invalidation_map,
27 syncer::WeakHandle<AckHandler>());
28 }
29 return object_id_invalidation_map;
30 }
31
32 class UnackedInvalidationStorageMapEqMatcher
33 : public testing::MatcherInterface<const UnackedInvalidationStorageMap&> {
34 public:
35 explicit UnackedInvalidationStorageMapEqMatcher(
36 const UnackedInvalidationStorageMap& expected);
37
38 virtual bool MatchAndExplain(const UnackedInvalidationStorageMap& actual,
39 MatchResultListener* listener) const;
40 virtual void DescribeTo(::std::ostream* os) const;
41 virtual void DescribeNegationTo(::std::ostream* os) const;
42
43 private:
44 const UnackedInvalidationStorageMap expected_;
45
46 DISALLOW_COPY_AND_ASSIGN(UnackedInvalidationStorageMapEqMatcher);
47 };
48
49 UnackedInvalidationStorageMapEqMatcher::UnackedInvalidationStorageMapEqMatcher(
50 const UnackedInvalidationStorageMap& expected)
51 : expected_(expected) {
52 }
53
54 bool UnackedInvalidationStorageMapEqMatcher::MatchAndExplain(
55 const UnackedInvalidationStorageMap& actual,
56 MatchResultListener* listener) const {
57 ObjectIdInvalidationMap expected_inv =
58 UnackedInvalidationStorageMapToObjectIdInvalidationMap(expected_);
59 ObjectIdInvalidationMap actual_inv =
60 UnackedInvalidationStorageMapToObjectIdInvalidationMap(actual);
61
62 return expected_inv == actual_inv;
63 }
64
65 void UnackedInvalidationStorageMapEqMatcher::DescribeTo(
66 ::std::ostream* os) const {
67 *os << " is equal to " << PrintToString(expected_);
68 }
69
70 void UnackedInvalidationStorageMapEqMatcher::DescribeNegationTo(
71 ::std::ostream* os) const {
72 *os << " isn't equal to " << PrintToString(expected_);
73 }
74
75 Matcher<const UnackedInvalidationStorageMap&> Eq(
76 const UnackedInvalidationStorageMap& expected) {
77 return MakeMatcher(new UnackedInvalidationStorageMapEqMatcher(expected));
78 }
79
80 } // namespace
81
82 Matcher<const UnackedInvalidationStorageMap&> Eq(
83 const UnackedInvalidationStorageMap& expected) {
84 return MakeMatcher(new UnackedInvalidationStorageMapEqMatcher(expected));
85 }
86
87 void PrintTo(const UnackedInvalidationStorageMap& map, ::std::ostream* os) {
88 scoped_ptr<base::ListValue> list(new base::ListValue);
89 for (UnackedInvalidationStorageMap::const_iterator it = map.begin();
90 it != map.end(); ++it) {
91 list->Append(it->second.ToValue().release());
92 }
93
94 std::string output;
95 JSONStringValueSerializer serializer(&output);
96 serializer.set_pretty_print(true);
97 serializer.Serialize(*list.get());
98
99 (*os) << output;
100 }
101
102 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/unacked_invalidation_storage_test_util.h ('k') | sync/sessions/data_type_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698