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

Side by Side Diff: sync/internal_api/public/base/model_type_invalidation_map_test_util.cc

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

Powered by Google App Engine
This is Rietveld 408576698