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

Unified Diff: sync/internal_api/public/base/model_type_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 side-by-side diff with in-line comments
Download patch
Index: sync/internal_api/public/base/model_type_state_map_test_util.cc
diff --git a/sync/internal_api/public/base/model_type_state_map_test_util.cc b/sync/internal_api/public/base/model_type_state_map_test_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..91c2229e1501ea072bdfa19ce9d97176c393d151
--- /dev/null
+++ b/sync/internal_api/public/base/model_type_state_map_test_util.cc
@@ -0,0 +1,89 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/internal_api/public/base/model_type_state_map_test_util.h"
+
+#include "base/basictypes.h"
+#include "sync/internal_api/public/base/invalidation_state_test_util.h"
+#include "sync/internal_api/public/base/model_type_test_util.h"
+
+using ::testing::MakeMatcher;
+using ::testing::MatchResultListener;
+using ::testing::Matcher;
+using ::testing::MatcherInterface;
+using ::testing::PrintToString;
+
+namespace syncer {
+
+namespace {
+
+class ModelTypeStateMapEqMatcher
+ : public MatcherInterface<const ModelTypeStateMap&> {
+ public:
+ explicit ModelTypeStateMapEqMatcher(const ModelTypeStateMap& expected);
+
+ virtual bool MatchAndExplain(const ModelTypeStateMap& lhs,
+ MatchResultListener* listener) const;
+ virtual void DescribeTo(::std::ostream* os) const;
+ virtual void DescribeNegationTo(::std::ostream* os) const;
+
+ private:
+ ModelTypeStateMap expected_;
+
+ DISALLOW_COPY_AND_ASSIGN(ModelTypeStateMapEqMatcher);
+};
+
+ModelTypeStateMapEqMatcher::ModelTypeStateMapEqMatcher(
+ const ModelTypeStateMap& expected) : expected_(expected) {
+}
+
+bool ModelTypeStateMapEqMatcher::MatchAndExplain(
+ const ModelTypeStateMap& actual, MatchResultListener* listener) const {
+ ModelTypeStateMap expected_only;
+ ModelTypeStateMap actual_only;
+
+ std::set_difference(expected_.begin(), expected_.end(),
+ actual.begin(), actual.end(),
+ std::inserter(expected_only, expected_only.begin()),
+ expected_.value_comp());
dcheng 2012/08/18 00:41:29 value_comp() isn't actually sufficient. I'll have
akalin 2012/08/20 21:00:07 oh? what's the issue?
dcheng 2012/08/21 01:23:39 This doesn't actually compare the values, only the
+ std::set_difference(actual.begin(), actual.end(),
+ expected_.begin(), expected_.end(),
+ std::inserter(actual_only, actual_only.begin()),
+ actual.value_comp());
+
+ if (expected_only.empty() && actual_only.empty())
+ return true;
+
+ bool printed_header = false;
+ if (!actual_only.empty()) {
+ *listener << " which has these unexpected elements: "
+ << PrintToString(actual_only);
+ printed_header = true;
+ }
+
+ if (!expected_only.empty()) {
+ *listener << (printed_header ? ",\nand" : "which")
+ << "doesn't have these expected elements: "
+ << PrintToString(expected_only);
+ printed_header = true;
+ }
+
+ return false;
+}
+
+void ModelTypeStateMapEqMatcher::DescribeTo(::std::ostream* os) const {
+ *os << " is equal to " << PrintToString(expected_);
+}
+
+void ModelTypeStateMapEqMatcher::DescribeNegationTo(::std::ostream* os) const {
+ *os << " isn't equal to " << PrintToString(expected_);
+}
+
+} // namespace
+
+Matcher<const ModelTypeStateMap&> Eq(const ModelTypeStateMap& expected) {
+ return MakeMatcher(new ModelTypeStateMapEqMatcher(expected));
+}
+
+} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698