| 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
|
|
|