Index: sync/internal_api/public/base/invalidation_test_util.cc |
diff --git a/sync/internal_api/public/base/invalidation_test_util.cc b/sync/internal_api/public/base/invalidation_test_util.cc |
index a95b65795df827439e3050e015170c983ce17127..de3d79d0e2b407d89954e723d3c180880dee7899 100644 |
--- a/sync/internal_api/public/base/invalidation_test_util.cc |
+++ b/sync/internal_api/public/base/invalidation_test_util.cc |
@@ -5,6 +5,8 @@ |
#include "sync/internal_api/public/base/invalidation_test_util.h" |
#include "base/basictypes.h" |
+#include "base/json/string_escape.h" |
+#include "base/values.h" |
#include "sync/internal_api/public/base/invalidation.h" |
namespace syncer { |
@@ -17,6 +19,41 @@ using ::testing::PrintToString; |
namespace { |
+class AckHandleEqMatcher |
+ : public MatcherInterface<const AckHandle&> { |
+ public: |
+ explicit AckHandleEqMatcher(const AckHandle& expected); |
+ |
+ virtual bool MatchAndExplain(const AckHandle& actual, |
+ MatchResultListener* listener) const; |
+ virtual void DescribeTo(::std::ostream* os) const; |
+ virtual void DescribeNegationTo(::std::ostream* os) const; |
+ |
+ private: |
+ const AckHandle expected_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AckHandleEqMatcher); |
+}; |
+ |
+AckHandleEqMatcher::AckHandleEqMatcher(const AckHandle& expected) |
+ : expected_(expected) { |
+} |
+ |
+bool AckHandleEqMatcher::MatchAndExplain(const AckHandle& actual, |
+ MatchResultListener* listener) const { |
+ scoped_ptr<base::Value> expected_value(expected_.ToValue()); |
+ scoped_ptr<base::Value> actual_value(actual.ToValue()); |
+ return expected_value->Equals(actual_value.get()); |
+} |
+ |
+void AckHandleEqMatcher::DescribeTo(::std::ostream* os) const { |
+ *os << " is equal to " << PrintToString(expected_); |
+} |
+ |
+void AckHandleEqMatcher::DescribeNegationTo(::std::ostream* os) const { |
+ *os << " isn't equal to " << PrintToString(expected_); |
+} |
+ |
class InvalidationEqMatcher |
: public MatcherInterface<const Invalidation&> { |
public: |
@@ -52,8 +89,30 @@ void InvalidationEqMatcher::DescribeNegationTo(::std::ostream* os) const { |
} // namespace |
-void PrintTo(const Invalidation& invalidation, ::std::ostream* os) { |
- *os << "{ payload: " << invalidation.payload << " }"; |
+void PrintTo(const AckHandle& ack_handle, ::std::ostream* os ) { |
+ scoped_ptr<base::Value> value(ack_handle.ToValue()); |
+ std::string raw_ack_handle; |
+ std::string printable_ack_handle; |
+ if (value->GetAsString(&raw_ack_handle)) { |
+ base::JsonDoubleQuote(raw_ack_handle, |
+ true /* put_in_quotes */, |
+ &printable_ack_handle); |
+ } else { |
+ printable_ack_handle = "bad handle"; |
+ } |
+ *os << "{ ack_handle: " << printable_ack_handle << " }"; |
+} |
+ |
+Matcher<const AckHandle&> Eq(const AckHandle& expected) { |
+ return MakeMatcher(new AckHandleEqMatcher(expected)); |
+} |
+ |
+void PrintTo(const Invalidation& state, ::std::ostream* os) { |
+ std::string printable_payload; |
+ base::JsonDoubleQuote(state.payload, |
+ true /* put_in_quotes */, |
+ &printable_payload); |
+ *os << "{ payload: " << printable_payload << " }"; |
} |
Matcher<const Invalidation&> Eq(const Invalidation& expected) { |