Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
proto_matcher_impl.h
Go to the documentation of this file.
1 // Copyright 2016 Google Inc.
16 
18 
19 #ifndef PAGESPEED_KERNEL_BASE_PROTO_MATCHER_IMPL_H_
20 #define PAGESPEED_KERNEL_BASE_PROTO_MATCHER_IMPL_H_
21 
22 #include <memory>
23 
24 #include "base/logging.h"
28 
29 
30 #include "google/protobuf/util/message_differencer.h"
31 #include "gmock/gmock-matchers.h"
32 
33 using google::protobuf::util::MessageDifferencer;
34 
35 
36 namespace net_instaweb {
37 
39  public:
40  explicit EqualsProtoMatcher(const GoogleString& str)
41  : expected_proto_str_(str) {}
42 
43  template <typename Proto>
44  bool MatchAndExplain(const Proto& actual_proto,
45  testing::MatchResultListener* ) const {
46  std::unique_ptr<Proto> expected_proto(actual_proto.New());
47  CHECK(ParseTextFormatProtoFromString(expected_proto_str_,
48  expected_proto.get()));
49  return MessageDifferencer::Equals(*expected_proto, actual_proto);
50  }
51 
52  void DescribeTo(::std::ostream* os) const {
53  *os << "matches proto: " << expected_proto_str_;
54  }
55 
56  void DescribeNegationTo(::std::ostream* os) const {
57  *os << "does not match proto: " << expected_proto_str_;
58  }
59 
60  private:
61  const GoogleString expected_proto_str_;
62 };
63 
64 inline testing::PolymorphicMatcher<EqualsProtoMatcher>
65 EqualsProto(const GoogleString& x) {
66  return testing::MakePolymorphicMatcher(EqualsProtoMatcher(x));
67 }
68 
69 }
70 
71 #endif
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: proto_matcher_impl.h:38