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
3 // found in the LICENSE file.
4
5 #include "sync/internal_api/public/base/model_type_test_util.h"
6 #include "sync/internal_api/public/base/ack_handle.h"
7
8 namespace syncer {
9
BuildInvalidation(ModelType type,int version,const std::string & payload)10 syncer::Invalidation BuildInvalidation(
11 ModelType type,
12 int version,
13 const std::string& payload) {
14 invalidation::ObjectId id;
15 bool result = RealModelTypeToObjectId(type, &id);
16 DCHECK(result);
17 return Invalidation::Init(id, version, payload);
18 }
19
BuildInvalidationMap(ModelType type,int version,const std::string & payload)20 ObjectIdInvalidationMap BuildInvalidationMap(
21 ModelType type,
22 int version,
23 const std::string& payload) {
24 ObjectIdInvalidationMap map;
25 map.Insert(BuildInvalidation(type, version, payload));
26 return map;
27 }
28
PrintTo(ModelTypeSet model_types,::std::ostream * os)29 void PrintTo(ModelTypeSet model_types, ::std::ostream* os) {
30 *os << ModelTypeSetToString(model_types);
31 }
32
33 namespace {
34
35 // Matcher implementation for HasModelTypes().
36 class HasModelTypesMatcher
37 : public ::testing::MatcherInterface<ModelTypeSet> {
38 public:
HasModelTypesMatcher(ModelTypeSet expected_types)39 explicit HasModelTypesMatcher(ModelTypeSet expected_types)
40 : expected_types_(expected_types) {}
41
~HasModelTypesMatcher()42 virtual ~HasModelTypesMatcher() {}
43
MatchAndExplain(ModelTypeSet model_types,::testing::MatchResultListener * listener) const44 virtual bool MatchAndExplain(
45 ModelTypeSet model_types,
46 ::testing::MatchResultListener* listener) const {
47 // No need to annotate listener since we already define PrintTo().
48 return model_types.Equals(expected_types_);
49 }
50
DescribeTo(::std::ostream * os) const51 virtual void DescribeTo(::std::ostream* os) const {
52 *os << "has model types " << ModelTypeSetToString(expected_types_);
53 }
54
DescribeNegationTo(::std::ostream * os) const55 virtual void DescribeNegationTo(::std::ostream* os) const {
56 *os << "doesn't have model types "
57 << ModelTypeSetToString(expected_types_);
58 }
59
60 private:
61 const ModelTypeSet expected_types_;
62
63 DISALLOW_COPY_AND_ASSIGN(HasModelTypesMatcher);
64 };
65
66 } // namespace
67
HasModelTypes(ModelTypeSet expected_types)68 ::testing::Matcher<ModelTypeSet> HasModelTypes(ModelTypeSet expected_types) {
69 return ::testing::MakeMatcher(new HasModelTypesMatcher(expected_types));
70 }
71
72 } // namespace syncer
73