| 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" | 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" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(InvalidationEqMatcher); | 69 DISALLOW_COPY_AND_ASSIGN(InvalidationEqMatcher); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 InvalidationEqMatcher::InvalidationEqMatcher( | 72 InvalidationEqMatcher::InvalidationEqMatcher( |
| 73 const Invalidation& expected) : expected_(expected) { | 73 const Invalidation& expected) : expected_(expected) { |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool InvalidationEqMatcher::MatchAndExplain( | 76 bool InvalidationEqMatcher::MatchAndExplain( |
| 77 const Invalidation& actual, MatchResultListener* listener) const { | 77 const Invalidation& actual, MatchResultListener* listener) const { |
| 78 return expected_.payload == actual.payload; | 78 if (!(expected_.object_id() == actual.object_id())) { |
| 79 return false; |
| 80 } |
| 81 if (expected_.is_unknown_version() && actual.is_unknown_version()) { |
| 82 return true; |
| 83 } else if (expected_.is_unknown_version() != actual.is_unknown_version()) { |
| 84 return false; |
| 85 } else { |
| 86 // Neither is unknown version. |
| 87 return expected_.payload() == actual.payload() |
| 88 && expected_.version() == actual.version(); |
| 89 } |
| 79 } | 90 } |
| 80 | 91 |
| 81 void InvalidationEqMatcher::DescribeTo(::std::ostream* os) const { | 92 void InvalidationEqMatcher::DescribeTo(::std::ostream* os) const { |
| 82 *os << " is equal to " << PrintToString(expected_); | 93 *os << " is equal to " << PrintToString(expected_); |
| 83 } | 94 } |
| 84 | 95 |
| 85 void InvalidationEqMatcher::DescribeNegationTo(::std::ostream* os) const { | 96 void InvalidationEqMatcher::DescribeNegationTo(::std::ostream* os) const { |
| 86 *os << " isn't equal to " << PrintToString(expected_); | 97 *os << " isn't equal to " << PrintToString(expected_); |
| 87 } | 98 } |
| 88 | 99 |
| 89 } // namespace | 100 } // namespace |
| 90 | 101 |
| 91 void PrintTo(const AckHandle& ack_handle, ::std::ostream* os ) { | 102 void PrintTo(const AckHandle& ack_handle, ::std::ostream* os ) { |
| 92 scoped_ptr<base::Value> value(ack_handle.ToValue()); | 103 scoped_ptr<base::Value> value(ack_handle.ToValue()); |
| 93 std::string printable_ack_handle; | 104 std::string printable_ack_handle; |
| 94 base::JSONWriter::Write(value.get(), &printable_ack_handle); | 105 base::JSONWriter::Write(value.get(), &printable_ack_handle); |
| 95 *os << "{ ack_handle: " << printable_ack_handle << " }"; | 106 *os << "{ ack_handle: " << printable_ack_handle << " }"; |
| 96 } | 107 } |
| 97 | 108 |
| 98 Matcher<const AckHandle&> Eq(const AckHandle& expected) { | 109 Matcher<const AckHandle&> Eq(const AckHandle& expected) { |
| 99 return MakeMatcher(new AckHandleEqMatcher(expected)); | 110 return MakeMatcher(new AckHandleEqMatcher(expected)); |
| 100 } | 111 } |
| 101 | 112 |
| 102 void PrintTo(const Invalidation& state, ::std::ostream* os) { | 113 void PrintTo(const Invalidation& inv, ::std::ostream* os) { |
| 103 std::string printable_payload; | 114 *os << "{ payload: " << inv.ToString() << " }"; |
| 104 base::JsonDoubleQuote(state.payload, | |
| 105 true /* put_in_quotes */, | |
| 106 &printable_payload); | |
| 107 *os << "{ payload: " << printable_payload << " }"; | |
| 108 } | 115 } |
| 109 | 116 |
| 110 Matcher<const Invalidation&> Eq(const Invalidation& expected) { | 117 Matcher<const Invalidation&> Eq(const Invalidation& expected) { |
| 111 return MakeMatcher(new InvalidationEqMatcher(expected)); | 118 return MakeMatcher(new InvalidationEqMatcher(expected)); |
| 112 } | 119 } |
| 113 | 120 |
| 114 } // namespace syncer | 121 } // namespace syncer |
| OLD | NEW |