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

Unified Diff: sync/notifier/unacked_invalidation_storage_test_util.cc

Issue 23754021: Invalidation trickles mega-patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
« no previous file with comments | « sync/notifier/unacked_invalidation_storage_test_util.h ('k') | sync/sessions/data_type_tracker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/notifier/unacked_invalidation_storage_test_util.cc
diff --git a/sync/notifier/unacked_invalidation_storage_test_util.cc b/sync/notifier/unacked_invalidation_storage_test_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..74475516f5a41986aa3b85c4292a9b8de0c00480
--- /dev/null
+++ b/sync/notifier/unacked_invalidation_storage_test_util.cc
@@ -0,0 +1,102 @@
+// Copyright (c) 2013 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/notifier/unacked_invalidation_storage_test_util.h"
+
+#include "base/json/json_string_value_serializer.h"
+#include "sync/notifier/object_id_invalidation_map.h"
+#include "testing/gmock/include/gmock/gmock-matchers.h"
+
+namespace syncer {
+
+using ::testing::MakeMatcher;
+using ::testing::MatchResultListener;
+using ::testing::Matcher;
+using ::testing::MatcherInterface;
+using ::testing::PrintToString;
+
+namespace {
+
+ObjectIdInvalidationMap UnackedInvalidationStorageMapToObjectIdInvalidationMap(
+ const UnackedInvalidationStorageMap& state_map) {
+ ObjectIdInvalidationMap object_id_invalidation_map;
+ for (UnackedInvalidationStorageMap::const_iterator it = state_map.begin();
+ it != state_map.end(); ++it) {
+ it->second.UnpackRecordedInvalidations(&object_id_invalidation_map,
+ syncer::WeakHandle<AckHandler>());
+ }
+ return object_id_invalidation_map;
+}
+
+class UnackedInvalidationStorageMapEqMatcher
+ : public testing::MatcherInterface<const UnackedInvalidationStorageMap&> {
+ public:
+ explicit UnackedInvalidationStorageMapEqMatcher(
+ const UnackedInvalidationStorageMap& expected);
+
+ virtual bool MatchAndExplain(const UnackedInvalidationStorageMap& actual,
+ MatchResultListener* listener) const;
+ virtual void DescribeTo(::std::ostream* os) const;
+ virtual void DescribeNegationTo(::std::ostream* os) const;
+
+ private:
+ const UnackedInvalidationStorageMap expected_;
+
+ DISALLOW_COPY_AND_ASSIGN(UnackedInvalidationStorageMapEqMatcher);
+};
+
+UnackedInvalidationStorageMapEqMatcher::UnackedInvalidationStorageMapEqMatcher(
+ const UnackedInvalidationStorageMap& expected)
+ : expected_(expected) {
+}
+
+bool UnackedInvalidationStorageMapEqMatcher::MatchAndExplain(
+ const UnackedInvalidationStorageMap& actual,
+ MatchResultListener* listener) const {
+ ObjectIdInvalidationMap expected_inv =
+ UnackedInvalidationStorageMapToObjectIdInvalidationMap(expected_);
+ ObjectIdInvalidationMap actual_inv =
+ UnackedInvalidationStorageMapToObjectIdInvalidationMap(actual);
+
+ return expected_inv == actual_inv;
+}
+
+void UnackedInvalidationStorageMapEqMatcher::DescribeTo(
+ ::std::ostream* os) const {
+ *os << " is equal to " << PrintToString(expected_);
+}
+
+void UnackedInvalidationStorageMapEqMatcher::DescribeNegationTo(
+ ::std::ostream* os) const {
+ *os << " isn't equal to " << PrintToString(expected_);
+}
+
+Matcher<const UnackedInvalidationStorageMap&> Eq(
+ const UnackedInvalidationStorageMap& expected) {
+ return MakeMatcher(new UnackedInvalidationStorageMapEqMatcher(expected));
+}
+
+} // namespace
+
+Matcher<const UnackedInvalidationStorageMap&> Eq(
+ const UnackedInvalidationStorageMap& expected) {
+ return MakeMatcher(new UnackedInvalidationStorageMapEqMatcher(expected));
+}
+
+void PrintTo(const UnackedInvalidationStorageMap& map, ::std::ostream* os) {
+ scoped_ptr<base::ListValue> list(new base::ListValue);
+ for (UnackedInvalidationStorageMap::const_iterator it = map.begin();
+ it != map.end(); ++it) {
+ list->Append(it->second.ToValue().release());
+ }
+
+ std::string output;
+ JSONStringValueSerializer serializer(&output);
+ serializer.set_pretty_print(true);
+ serializer.Serialize(*list.get());
+
+ (*os) << output;
+}
+
+} // namespace syncer
« no previous file with comments | « sync/notifier/unacked_invalidation_storage_test_util.h ('k') | sync/sessions/data_type_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698