Remove PlatformFile from dbus/file_descriptor
[chromium-blink-merge.git] / sync / internal_api / public / base / invalidation_test_util.cc
blob3c610dadedc1e5ff3222a82d4f0f25b02b19c9a6
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
3 // found in the LICENSE file.
5 #include "sync/internal_api/public/base/invalidation_test_util.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"
11 #include "sync/internal_api/public/base/invalidation.h"
13 namespace syncer {
15 using ::testing::MakeMatcher;
16 using ::testing::MatchResultListener;
17 using ::testing::Matcher;
18 using ::testing::MatcherInterface;
19 using ::testing::PrintToString;
21 namespace {
23 class AckHandleEqMatcher
24 : public MatcherInterface<const AckHandle&> {
25 public:
26 explicit AckHandleEqMatcher(const AckHandle& expected);
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;
33 private:
34 const AckHandle expected_;
36 DISALLOW_COPY_AND_ASSIGN(AckHandleEqMatcher);
39 AckHandleEqMatcher::AckHandleEqMatcher(const AckHandle& expected)
40 : expected_(expected) {
43 bool AckHandleEqMatcher::MatchAndExplain(const AckHandle& actual,
44 MatchResultListener* listener) const {
45 return expected_.Equals(actual);
48 void AckHandleEqMatcher::DescribeTo(::std::ostream* os) const {
49 *os << " is equal to " << PrintToString(expected_);
52 void AckHandleEqMatcher::DescribeNegationTo(::std::ostream* os) const {
53 *os << " isn't equal to " << PrintToString(expected_);
56 class InvalidationEqMatcher
57 : public MatcherInterface<const Invalidation&> {
58 public:
59 explicit InvalidationEqMatcher(const Invalidation& expected);
61 virtual bool MatchAndExplain(const Invalidation& actual,
62 MatchResultListener* listener) const;
63 virtual void DescribeTo(::std::ostream* os) const;
64 virtual void DescribeNegationTo(::std::ostream* os) const;
66 private:
67 const Invalidation expected_;
69 DISALLOW_COPY_AND_ASSIGN(InvalidationEqMatcher);
72 InvalidationEqMatcher::InvalidationEqMatcher(
73 const Invalidation& expected) : expected_(expected) {
76 bool InvalidationEqMatcher::MatchAndExplain(
77 const Invalidation& actual, MatchResultListener* listener) const {
78 if (!(expected_.object_id() == actual.object_id())) {
79 return false;
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();
92 void InvalidationEqMatcher::DescribeTo(::std::ostream* os) const {
93 *os << " is equal to " << PrintToString(expected_);
96 void InvalidationEqMatcher::DescribeNegationTo(::std::ostream* os) const {
97 *os << " isn't equal to " << PrintToString(expected_);
100 } // namespace
102 void PrintTo(const AckHandle& ack_handle, ::std::ostream* os ) {
103 scoped_ptr<base::Value> value(ack_handle.ToValue());
104 std::string printable_ack_handle;
105 base::JSONWriter::Write(value.get(), &printable_ack_handle);
106 *os << "{ ack_handle: " << printable_ack_handle << " }";
109 Matcher<const AckHandle&> Eq(const AckHandle& expected) {
110 return MakeMatcher(new AckHandleEqMatcher(expected));
113 void PrintTo(const Invalidation& inv, ::std::ostream* os) {
114 *os << "{ payload: " << inv.ToString() << " }";
117 Matcher<const Invalidation&> Eq(const Invalidation& expected) {
118 return MakeMatcher(new InvalidationEqMatcher(expected));
121 } // namespace syncer