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/notifier/object_id_state_map_test_util.h" | 5 #include "sync/notifier/object_id_invalidation_map_test_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 | 10 |
11 namespace syncer { | 11 namespace syncer { |
12 | 12 |
13 using ::testing::MakeMatcher; | 13 using ::testing::MakeMatcher; |
14 using ::testing::MatchResultListener; | 14 using ::testing::MatchResultListener; |
15 using ::testing::Matcher; | 15 using ::testing::Matcher; |
16 using ::testing::MatcherInterface; | 16 using ::testing::MatcherInterface; |
17 using ::testing::PrintToString; | 17 using ::testing::PrintToString; |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 class ObjectIdStateMapEqMatcher | 21 class ObjectIdInvalidationMapEqMatcher |
22 : public MatcherInterface<const ObjectIdStateMap&> { | 22 : public MatcherInterface<const ObjectIdInvalidationMap&> { |
23 public: | 23 public: |
24 explicit ObjectIdStateMapEqMatcher(const ObjectIdStateMap& expected); | 24 explicit ObjectIdInvalidationMapEqMatcher( |
| 25 const ObjectIdInvalidationMap& expected); |
25 | 26 |
26 virtual bool MatchAndExplain(const ObjectIdStateMap& actual, | 27 virtual bool MatchAndExplain(const ObjectIdInvalidationMap& actual, |
27 MatchResultListener* listener) const; | 28 MatchResultListener* listener) const; |
28 virtual void DescribeTo(::std::ostream* os) const; | 29 virtual void DescribeTo(::std::ostream* os) const; |
29 virtual void DescribeNegationTo(::std::ostream* os) const; | 30 virtual void DescribeNegationTo(::std::ostream* os) const; |
30 | 31 |
31 private: | 32 private: |
32 const ObjectIdStateMap expected_; | 33 const ObjectIdInvalidationMap expected_; |
33 | 34 |
34 DISALLOW_COPY_AND_ASSIGN(ObjectIdStateMapEqMatcher); | 35 DISALLOW_COPY_AND_ASSIGN(ObjectIdInvalidationMapEqMatcher); |
35 }; | 36 }; |
36 | 37 |
37 ObjectIdStateMapEqMatcher::ObjectIdStateMapEqMatcher( | 38 ObjectIdInvalidationMapEqMatcher::ObjectIdInvalidationMapEqMatcher( |
38 const ObjectIdStateMap& expected) : expected_(expected) { | 39 const ObjectIdInvalidationMap& expected) : expected_(expected) { |
39 } | 40 } |
40 | 41 |
41 bool ObjectIdStateMapEqMatcher::MatchAndExplain( | 42 bool ObjectIdInvalidationMapEqMatcher::MatchAndExplain( |
42 const ObjectIdStateMap& actual, MatchResultListener* listener) const { | 43 const ObjectIdInvalidationMap& actual, |
43 ObjectIdStateMap expected_only; | 44 MatchResultListener* listener) const { |
44 ObjectIdStateMap actual_only; | 45 ObjectIdInvalidationMap expected_only; |
| 46 ObjectIdInvalidationMap actual_only; |
45 typedef std::pair<invalidation::ObjectId, | 47 typedef std::pair<invalidation::ObjectId, |
46 std::pair<InvalidationState, InvalidationState> > | 48 std::pair<Invalidation, Invalidation> > |
47 ValueDifference; | 49 ValueDifference; |
48 std::vector<ValueDifference> value_differences; | 50 std::vector<ValueDifference> value_differences; |
49 | 51 |
50 std::set_difference(expected_.begin(), expected_.end(), | 52 std::set_difference(expected_.begin(), expected_.end(), |
51 actual.begin(), actual.end(), | 53 actual.begin(), actual.end(), |
52 std::inserter(expected_only, expected_only.begin()), | 54 std::inserter(expected_only, expected_only.begin()), |
53 expected_.value_comp()); | 55 expected_.value_comp()); |
54 std::set_difference(actual.begin(), actual.end(), | 56 std::set_difference(actual.begin(), actual.end(), |
55 expected_.begin(), expected_.end(), | 57 expected_.begin(), expected_.end(), |
56 std::inserter(actual_only, actual_only.begin()), | 58 std::inserter(actual_only, actual_only.begin()), |
57 actual.value_comp()); | 59 actual.value_comp()); |
58 | 60 |
59 for (ObjectIdStateMap::const_iterator it = expected_.begin(); | 61 for (ObjectIdInvalidationMap::const_iterator it = expected_.begin(); |
60 it != expected_.end(); ++it) { | 62 it != expected_.end(); ++it) { |
61 ObjectIdStateMap::const_iterator find_it = | 63 ObjectIdInvalidationMap::const_iterator find_it = |
62 actual.find(it->first); | 64 actual.find(it->first); |
63 if (find_it != actual.end() && | 65 if (find_it != actual.end() && |
64 !Matches(Eq(it->second))(find_it->second)) { | 66 !Matches(Eq(it->second))(find_it->second)) { |
65 value_differences.push_back(std::make_pair( | 67 value_differences.push_back(std::make_pair( |
66 it->first, std::make_pair(it->second, find_it->second))); | 68 it->first, std::make_pair(it->second, find_it->second))); |
67 } | 69 } |
68 } | 70 } |
69 | 71 |
70 if (expected_only.empty() && actual_only.empty() && value_differences.empty()) | 72 if (expected_only.empty() && actual_only.empty() && value_differences.empty()) |
71 return true; | 73 return true; |
(...skipping 14 matching lines...) Expand all Loading... |
86 | 88 |
87 if (!value_differences.empty()) { | 89 if (!value_differences.empty()) { |
88 *listener << (printed_header ? ",\nand" : "which") | 90 *listener << (printed_header ? ",\nand" : "which") |
89 << " differ in the following values: " | 91 << " differ in the following values: " |
90 << PrintToString(value_differences); | 92 << PrintToString(value_differences); |
91 } | 93 } |
92 | 94 |
93 return false; | 95 return false; |
94 } | 96 } |
95 | 97 |
96 void ObjectIdStateMapEqMatcher::DescribeTo(::std::ostream* os) const { | 98 void ObjectIdInvalidationMapEqMatcher::DescribeTo(::std::ostream* os) const { |
97 *os << " is equal to " << PrintToString(expected_); | 99 *os << " is equal to " << PrintToString(expected_); |
98 } | 100 } |
99 | 101 |
100 void ObjectIdStateMapEqMatcher::DescribeNegationTo(::std::ostream* os) const { | 102 void ObjectIdInvalidationMapEqMatcher::DescribeNegationTo |
| 103 (::std::ostream* os) const { |
101 *os << " isn't equal to " << PrintToString(expected_); | 104 *os << " isn't equal to " << PrintToString(expected_); |
102 } | 105 } |
103 | 106 |
104 } // namespace | 107 } // namespace |
105 | 108 |
106 Matcher<const ObjectIdStateMap&> Eq(const ObjectIdStateMap& expected) { | 109 Matcher<const ObjectIdInvalidationMap&> Eq( |
107 return MakeMatcher(new ObjectIdStateMapEqMatcher(expected)); | 110 const ObjectIdInvalidationMap& expected) { |
| 111 return MakeMatcher(new ObjectIdInvalidationMapEqMatcher(expected)); |
108 } | 112 } |
109 | 113 |
110 } // namespace syncer | 114 } // namespace syncer |
OLD | NEW |