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

Side by Side Diff: sync/internal_api/public/base/invalidation_test_util.cc

Issue 11415049: Implement features needed for local ack handling in InvalidationStateTracker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/internal_api/public/base/invalidation_test_util.h" 5 #include "sync/internal_api/public/base/invalidation_test_util.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/json/string_escape.h"
9 #include "base/values.h"
8 #include "sync/internal_api/public/base/invalidation.h" 10 #include "sync/internal_api/public/base/invalidation.h"
9 11
10 namespace syncer { 12 namespace syncer {
11 13
12 using ::testing::MakeMatcher; 14 using ::testing::MakeMatcher;
13 using ::testing::MatchResultListener; 15 using ::testing::MatchResultListener;
14 using ::testing::Matcher; 16 using ::testing::Matcher;
15 using ::testing::MatcherInterface; 17 using ::testing::MatcherInterface;
16 using ::testing::PrintToString; 18 using ::testing::PrintToString;
17 19
18 namespace { 20 namespace {
19 21
22 class AckHandleEqMatcher
23 : public MatcherInterface<const AckHandle&> {
24 public:
25 explicit AckHandleEqMatcher(const AckHandle& expected);
26
27 virtual bool MatchAndExplain(const AckHandle& actual,
28 MatchResultListener* listener) const;
29 virtual void DescribeTo(::std::ostream* os) const;
30 virtual void DescribeNegationTo(::std::ostream* os) const;
31
32 private:
33 const AckHandle expected_;
34
35 DISALLOW_COPY_AND_ASSIGN(AckHandleEqMatcher);
36 };
37
38 AckHandleEqMatcher::AckHandleEqMatcher(const AckHandle& expected)
39 : expected_(expected) {
40 }
41
42 bool AckHandleEqMatcher::MatchAndExplain(const AckHandle& actual,
43 MatchResultListener* listener) const {
44 scoped_ptr<base::Value> expected_value(expected_.ToValue());
45 scoped_ptr<base::Value> actual_value(actual.ToValue());
46 return expected_value->Equals(actual_value.get());
47 }
48
49 void AckHandleEqMatcher::DescribeTo(::std::ostream* os) const {
50 *os << " is equal to " << PrintToString(expected_);
51 }
52
53 void AckHandleEqMatcher::DescribeNegationTo(::std::ostream* os) const {
54 *os << " isn't equal to " << PrintToString(expected_);
55 }
56
20 class InvalidationEqMatcher 57 class InvalidationEqMatcher
21 : public MatcherInterface<const Invalidation&> { 58 : public MatcherInterface<const Invalidation&> {
22 public: 59 public:
23 explicit InvalidationEqMatcher(const Invalidation& expected); 60 explicit InvalidationEqMatcher(const Invalidation& expected);
24 61
25 virtual bool MatchAndExplain(const Invalidation& actual, 62 virtual bool MatchAndExplain(const Invalidation& actual,
26 MatchResultListener* listener) const; 63 MatchResultListener* listener) const;
27 virtual void DescribeTo(::std::ostream* os) const; 64 virtual void DescribeTo(::std::ostream* os) const;
28 virtual void DescribeNegationTo(::std::ostream* os) const; 65 virtual void DescribeNegationTo(::std::ostream* os) const;
29 66
(...skipping 15 matching lines...) Expand all
45 void InvalidationEqMatcher::DescribeTo(::std::ostream* os) const { 82 void InvalidationEqMatcher::DescribeTo(::std::ostream* os) const {
46 *os << " is equal to " << PrintToString(expected_); 83 *os << " is equal to " << PrintToString(expected_);
47 } 84 }
48 85
49 void InvalidationEqMatcher::DescribeNegationTo(::std::ostream* os) const { 86 void InvalidationEqMatcher::DescribeNegationTo(::std::ostream* os) const {
50 *os << " isn't equal to " << PrintToString(expected_); 87 *os << " isn't equal to " << PrintToString(expected_);
51 } 88 }
52 89
53 } // namespace 90 } // namespace
54 91
55 void PrintTo(const Invalidation& invalidation, ::std::ostream* os) { 92 void PrintTo(const AckHandle& ack_handle, ::std::ostream* os ) {
56 *os << "{ payload: " << invalidation.payload << " }"; 93 scoped_ptr<base::Value> value(ack_handle.ToValue());
94 std::string raw_ack_handle;
95 std::string printable_ack_handle;
96 if (value->GetAsString(&raw_ack_handle)) {
97 base::JsonDoubleQuote(raw_ack_handle,
98 true /* put_in_quotes */,
99 &printable_ack_handle);
100 } else {
101 printable_ack_handle = "bad handle";
102 }
103 *os << "{ ack_handle: " << printable_ack_handle << " }";
104 }
105
106 Matcher<const AckHandle&> Eq(const AckHandle& expected) {
107 return MakeMatcher(new AckHandleEqMatcher(expected));
108 }
109
110 void PrintTo(const Invalidation& state, ::std::ostream* os) {
111 std::string printable_payload;
112 base::JsonDoubleQuote(state.payload,
113 true /* put_in_quotes */,
114 &printable_payload);
115 *os << "{ payload: " << printable_payload << " }";
57 } 116 }
58 117
59 Matcher<const Invalidation&> Eq(const Invalidation& expected) { 118 Matcher<const Invalidation&> Eq(const Invalidation& expected) {
60 return MakeMatcher(new InvalidationEqMatcher(expected)); 119 return MakeMatcher(new InvalidationEqMatcher(expected));
61 } 120 }
62 121
63 } // namespace syncer 122 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698