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