Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: sync/notifier/object_id_state_map_test_util.cc

Issue 10837214: Refactor ModelTypePayloadMap and ObjectIdPayloadMap to StateMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "sync/notifier/object_id_state_map_test_util.h"
6
7 #include <algorithm>
8 #include "base/basictypes.h"
9 #include "sync/internal_api/public/base/invalidation_state_test_util.h"
10
11 using ::testing::MakeMatcher;
12 using ::testing::MatchResultListener;
13 using ::testing::Matcher;
14 using ::testing::MatcherInterface;
15 using ::testing::PrintToString;
16
17 namespace syncer {
18
19 namespace {
20
21 class ObjectIdStateMapEqMatcher
22 : public MatcherInterface<const ObjectIdStateMap&> {
23 public:
24 explicit ObjectIdStateMapEqMatcher(const ObjectIdStateMap& expected);
25
26 virtual bool MatchAndExplain(const ObjectIdStateMap& actual,
27 MatchResultListener* listener) const;
28 virtual void DescribeTo(::std::ostream* os) const;
29 virtual void DescribeNegationTo(::std::ostream* os) const;
30
31 private:
32 ObjectIdStateMap expected_;
33
34 DISALLOW_COPY_AND_ASSIGN(ObjectIdStateMapEqMatcher);
35 };
36
37 ObjectIdStateMapEqMatcher::ObjectIdStateMapEqMatcher(
38 const ObjectIdStateMap& expected) : expected_(expected) {
39 }
40
41 bool ObjectIdStateMapEqMatcher::MatchAndExplain(
42 const ObjectIdStateMap& actual, MatchResultListener* listener) const {
dcheng 2012/08/18 00:41:29 I think it would be nice if I pulled this out into
43 ObjectIdStateMap expected_only;
44 ObjectIdStateMap actual_only;
45
46 std::set_difference(expected_.begin(), expected_.end(),
47 actual.begin(), actual.end(),
48 std::inserter(expected_only, expected_only.begin()),
49 expected_.value_comp());
50 std::set_difference(actual.begin(), actual.end(),
51 expected_.begin(), expected_.end(),
52 std::inserter(actual_only, actual_only.begin()),
53 actual.value_comp());
54
55 if (expected_only.empty() && actual_only.empty())
56 return true;
57
58 bool printed_header = false;
59 if (!actual_only.empty()) {
60 *listener << " which has these unexpected elements: "
61 << PrintToString(actual_only);
62 printed_header = true;
63 }
64
65 if (!expected_only.empty()) {
66 *listener << (printed_header ? ",\nand" : "which")
67 << "doesn't have these expected elements: "
68 << PrintToString(expected_only);
69 printed_header = true;
70 }
71
72
73 return false;
74 }
75
76 void ObjectIdStateMapEqMatcher::DescribeTo(::std::ostream* os) const {
77 *os << " is equal to " << PrintToString(expected_);
78 }
79
80 void ObjectIdStateMapEqMatcher::DescribeNegationTo(::std::ostream* os) const {
81 *os << " isn't equal to " << PrintToString(expected_);
82 }
83
84 } // namespace
85
86 Matcher<const ObjectIdStateMap&> Eq(const ObjectIdStateMap& expected) {
87 return MakeMatcher(new ObjectIdStateMapEqMatcher(expected));
88 }
89
90 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698