OLD | NEW |
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/json_writer.h" |
| 9 #include "base/json/string_escape.h" |
| 10 #include "base/values.h" |
8 #include "sync/internal_api/public/base/invalidation.h" | 11 #include "sync/internal_api/public/base/invalidation.h" |
9 | 12 |
10 namespace syncer { | 13 namespace syncer { |
11 | 14 |
12 using ::testing::MakeMatcher; | 15 using ::testing::MakeMatcher; |
13 using ::testing::MatchResultListener; | 16 using ::testing::MatchResultListener; |
14 using ::testing::Matcher; | 17 using ::testing::Matcher; |
15 using ::testing::MatcherInterface; | 18 using ::testing::MatcherInterface; |
16 using ::testing::PrintToString; | 19 using ::testing::PrintToString; |
17 | 20 |
18 namespace { | 21 namespace { |
19 | 22 |
| 23 class AckHandleEqMatcher |
| 24 : public MatcherInterface<const AckHandle&> { |
| 25 public: |
| 26 explicit AckHandleEqMatcher(const AckHandle& expected); |
| 27 |
| 28 virtual bool MatchAndExplain(const AckHandle& actual, |
| 29 MatchResultListener* listener) const; |
| 30 virtual void DescribeTo(::std::ostream* os) const; |
| 31 virtual void DescribeNegationTo(::std::ostream* os) const; |
| 32 |
| 33 private: |
| 34 const AckHandle expected_; |
| 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(AckHandleEqMatcher); |
| 37 }; |
| 38 |
| 39 AckHandleEqMatcher::AckHandleEqMatcher(const AckHandle& expected) |
| 40 : expected_(expected) { |
| 41 } |
| 42 |
| 43 bool AckHandleEqMatcher::MatchAndExplain(const AckHandle& actual, |
| 44 MatchResultListener* listener) const { |
| 45 return expected_.Equals(actual); |
| 46 } |
| 47 |
| 48 void AckHandleEqMatcher::DescribeTo(::std::ostream* os) const { |
| 49 *os << " is equal to " << PrintToString(expected_); |
| 50 } |
| 51 |
| 52 void AckHandleEqMatcher::DescribeNegationTo(::std::ostream* os) const { |
| 53 *os << " isn't equal to " << PrintToString(expected_); |
| 54 } |
| 55 |
20 class InvalidationEqMatcher | 56 class InvalidationEqMatcher |
21 : public MatcherInterface<const Invalidation&> { | 57 : public MatcherInterface<const Invalidation&> { |
22 public: | 58 public: |
23 explicit InvalidationEqMatcher(const Invalidation& expected); | 59 explicit InvalidationEqMatcher(const Invalidation& expected); |
24 | 60 |
25 virtual bool MatchAndExplain(const Invalidation& actual, | 61 virtual bool MatchAndExplain(const Invalidation& actual, |
26 MatchResultListener* listener) const; | 62 MatchResultListener* listener) const; |
27 virtual void DescribeTo(::std::ostream* os) const; | 63 virtual void DescribeTo(::std::ostream* os) const; |
28 virtual void DescribeNegationTo(::std::ostream* os) const; | 64 virtual void DescribeNegationTo(::std::ostream* os) const; |
29 | 65 |
(...skipping 15 matching lines...) Expand all Loading... |
45 void InvalidationEqMatcher::DescribeTo(::std::ostream* os) const { | 81 void InvalidationEqMatcher::DescribeTo(::std::ostream* os) const { |
46 *os << " is equal to " << PrintToString(expected_); | 82 *os << " is equal to " << PrintToString(expected_); |
47 } | 83 } |
48 | 84 |
49 void InvalidationEqMatcher::DescribeNegationTo(::std::ostream* os) const { | 85 void InvalidationEqMatcher::DescribeNegationTo(::std::ostream* os) const { |
50 *os << " isn't equal to " << PrintToString(expected_); | 86 *os << " isn't equal to " << PrintToString(expected_); |
51 } | 87 } |
52 | 88 |
53 } // namespace | 89 } // namespace |
54 | 90 |
55 void PrintTo(const Invalidation& invalidation, ::std::ostream* os) { | 91 void PrintTo(const AckHandle& ack_handle, ::std::ostream* os ) { |
56 *os << "{ payload: " << invalidation.payload << " }"; | 92 scoped_ptr<base::Value> value(ack_handle.ToValue()); |
| 93 std::string printable_ack_handle; |
| 94 base::JSONWriter::Write(value.get(), &printable_ack_handle); |
| 95 *os << "{ ack_handle: " << printable_ack_handle << " }"; |
| 96 } |
| 97 |
| 98 Matcher<const AckHandle&> Eq(const AckHandle& expected) { |
| 99 return MakeMatcher(new AckHandleEqMatcher(expected)); |
| 100 } |
| 101 |
| 102 void PrintTo(const Invalidation& state, ::std::ostream* os) { |
| 103 std::string printable_payload; |
| 104 base::JsonDoubleQuote(state.payload, |
| 105 true /* put_in_quotes */, |
| 106 &printable_payload); |
| 107 *os << "{ payload: " << printable_payload << " }"; |
57 } | 108 } |
58 | 109 |
59 Matcher<const Invalidation&> Eq(const Invalidation& expected) { | 110 Matcher<const Invalidation&> Eq(const Invalidation& expected) { |
60 return MakeMatcher(new InvalidationEqMatcher(expected)); | 111 return MakeMatcher(new InvalidationEqMatcher(expected)); |
61 } | 112 } |
62 | 113 |
63 } // namespace syncer | 114 } // namespace syncer |
OLD | NEW |