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 "components/invalidation/invalidation_test_util.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "sync/internal_api/public/base/invalidation.h" | 11 #include "components/invalidation/invalidation.h" |
12 | 12 |
13 namespace syncer { | 13 namespace syncer { |
14 | 14 |
15 using ::testing::MakeMatcher; | 15 using ::testing::MakeMatcher; |
16 using ::testing::MatchResultListener; | 16 using ::testing::MatchResultListener; |
17 using ::testing::Matcher; | 17 using ::testing::Matcher; |
18 using ::testing::MatcherInterface; | 18 using ::testing::MatcherInterface; |
19 using ::testing::PrintToString; | 19 using ::testing::PrintToString; |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 class AckHandleEqMatcher | 23 class AckHandleEqMatcher : public MatcherInterface<const AckHandle&> { |
24 : public MatcherInterface<const AckHandle&> { | |
25 public: | 24 public: |
26 explicit AckHandleEqMatcher(const AckHandle& expected); | 25 explicit AckHandleEqMatcher(const AckHandle& expected); |
27 | 26 |
28 virtual bool MatchAndExplain(const AckHandle& actual, | 27 virtual bool MatchAndExplain(const AckHandle& actual, |
29 MatchResultListener* listener) const; | 28 MatchResultListener* listener) const; |
30 virtual void DescribeTo(::std::ostream* os) const; | 29 virtual void DescribeTo(::std::ostream* os) const; |
31 virtual void DescribeNegationTo(::std::ostream* os) const; | 30 virtual void DescribeNegationTo(::std::ostream* os) const; |
32 | 31 |
33 private: | 32 private: |
34 const AckHandle expected_; | 33 const AckHandle expected_; |
(...skipping 11 matching lines...) Expand all Loading... |
46 } | 45 } |
47 | 46 |
48 void AckHandleEqMatcher::DescribeTo(::std::ostream* os) const { | 47 void AckHandleEqMatcher::DescribeTo(::std::ostream* os) const { |
49 *os << " is equal to " << PrintToString(expected_); | 48 *os << " is equal to " << PrintToString(expected_); |
50 } | 49 } |
51 | 50 |
52 void AckHandleEqMatcher::DescribeNegationTo(::std::ostream* os) const { | 51 void AckHandleEqMatcher::DescribeNegationTo(::std::ostream* os) const { |
53 *os << " isn't equal to " << PrintToString(expected_); | 52 *os << " isn't equal to " << PrintToString(expected_); |
54 } | 53 } |
55 | 54 |
56 class InvalidationEqMatcher | 55 class InvalidationEqMatcher : public MatcherInterface<const Invalidation&> { |
57 : public MatcherInterface<const Invalidation&> { | |
58 public: | 56 public: |
59 explicit InvalidationEqMatcher(const Invalidation& expected); | 57 explicit InvalidationEqMatcher(const Invalidation& expected); |
60 | 58 |
61 virtual bool MatchAndExplain(const Invalidation& actual, | 59 virtual bool MatchAndExplain(const Invalidation& actual, |
62 MatchResultListener* listener) const; | 60 MatchResultListener* listener) const; |
63 virtual void DescribeTo(::std::ostream* os) const; | 61 virtual void DescribeTo(::std::ostream* os) const; |
64 virtual void DescribeNegationTo(::std::ostream* os) const; | 62 virtual void DescribeNegationTo(::std::ostream* os) const; |
65 | 63 |
66 private: | 64 private: |
67 const Invalidation expected_; | 65 const Invalidation expected_; |
68 | 66 |
69 DISALLOW_COPY_AND_ASSIGN(InvalidationEqMatcher); | 67 DISALLOW_COPY_AND_ASSIGN(InvalidationEqMatcher); |
70 }; | 68 }; |
71 | 69 |
72 InvalidationEqMatcher::InvalidationEqMatcher( | 70 InvalidationEqMatcher::InvalidationEqMatcher(const Invalidation& expected) |
73 const Invalidation& expected) : expected_(expected) { | 71 : expected_(expected) { |
74 } | 72 } |
75 | 73 |
76 bool InvalidationEqMatcher::MatchAndExplain( | 74 bool InvalidationEqMatcher::MatchAndExplain( |
77 const Invalidation& actual, MatchResultListener* listener) const { | 75 const Invalidation& actual, |
| 76 MatchResultListener* listener) const { |
78 if (!(expected_.object_id() == actual.object_id())) { | 77 if (!(expected_.object_id() == actual.object_id())) { |
79 return false; | 78 return false; |
80 } | 79 } |
81 if (expected_.is_unknown_version() && actual.is_unknown_version()) { | 80 if (expected_.is_unknown_version() && actual.is_unknown_version()) { |
82 return true; | 81 return true; |
83 } else if (expected_.is_unknown_version() != actual.is_unknown_version()) { | 82 } else if (expected_.is_unknown_version() != actual.is_unknown_version()) { |
84 return false; | 83 return false; |
85 } else { | 84 } else { |
86 // Neither is unknown version. | 85 // Neither is unknown version. |
87 return expected_.payload() == actual.payload() | 86 return expected_.payload() == actual.payload() && |
88 && expected_.version() == actual.version(); | 87 expected_.version() == actual.version(); |
89 } | 88 } |
90 } | 89 } |
91 | 90 |
92 void InvalidationEqMatcher::DescribeTo(::std::ostream* os) const { | 91 void InvalidationEqMatcher::DescribeTo(::std::ostream* os) const { |
93 *os << " is equal to " << PrintToString(expected_); | 92 *os << " is equal to " << PrintToString(expected_); |
94 } | 93 } |
95 | 94 |
96 void InvalidationEqMatcher::DescribeNegationTo(::std::ostream* os) const { | 95 void InvalidationEqMatcher::DescribeNegationTo(::std::ostream* os) const { |
97 *os << " isn't equal to " << PrintToString(expected_); | 96 *os << " isn't equal to " << PrintToString(expected_); |
98 } | 97 } |
99 | 98 |
100 } // namespace | 99 } // namespace |
101 | 100 |
102 void PrintTo(const AckHandle& ack_handle, ::std::ostream* os ) { | 101 void PrintTo(const AckHandle& ack_handle, ::std::ostream* os) { |
103 scoped_ptr<base::Value> value(ack_handle.ToValue()); | 102 scoped_ptr<base::Value> value(ack_handle.ToValue()); |
104 std::string printable_ack_handle; | 103 std::string printable_ack_handle; |
105 base::JSONWriter::Write(value.get(), &printable_ack_handle); | 104 base::JSONWriter::Write(value.get(), &printable_ack_handle); |
106 *os << "{ ack_handle: " << printable_ack_handle << " }"; | 105 *os << "{ ack_handle: " << printable_ack_handle << " }"; |
107 } | 106 } |
108 | 107 |
109 Matcher<const AckHandle&> Eq(const AckHandle& expected) { | 108 Matcher<const AckHandle&> Eq(const AckHandle& expected) { |
110 return MakeMatcher(new AckHandleEqMatcher(expected)); | 109 return MakeMatcher(new AckHandleEqMatcher(expected)); |
111 } | 110 } |
112 | 111 |
113 void PrintTo(const Invalidation& inv, ::std::ostream* os) { | 112 void PrintTo(const Invalidation& inv, ::std::ostream* os) { |
114 *os << "{ payload: " << inv.ToString() << " }"; | 113 *os << "{ payload: " << inv.ToString() << " }"; |
115 } | 114 } |
116 | 115 |
117 Matcher<const Invalidation&> Eq(const Invalidation& expected) { | 116 Matcher<const Invalidation&> Eq(const Invalidation& expected) { |
118 return MakeMatcher(new InvalidationEqMatcher(expected)); | 117 return MakeMatcher(new InvalidationEqMatcher(expected)); |
119 } | 118 } |
120 | 119 |
121 } // namespace syncer | 120 } // namespace syncer |
OLD | NEW |