14#ifndef OR_TOOLS_BASE_MESSAGE_MATCHERS_H_
15#define OR_TOOLS_BASE_MESSAGE_MATCHERS_H_
19#include "absl/strings/string_view.h"
20#include "gmock/gmock-matchers.h"
21#include "gmock/gmock.h"
22#include "google/protobuf/message.h"
23#include "google/protobuf/util/message_differencer.h"
29typedef ::google::protobuf::util::MessageDifferencer::MessageFieldComparison
33typedef ::google::protobuf::util::DefaultFieldComparator::FloatComparison
37typedef ::google::protobuf::util::MessageDifferencer::RepeatedFieldComparison
42typedef ::google::protobuf::util::MessageDifferencer::Scope
46 ::google::protobuf::util::MessageDifferencer::EQUAL;
48 ::google::protobuf::util::MessageDifferencer::EQUIVALENT;
50 ::google::protobuf::util::DefaultFieldComparator::EXACT;
52 ::google::protobuf::util::DefaultFieldComparator::APPROXIMATE;
54 ::google::protobuf::util::MessageDifferencer::AS_LIST;
56 ::google::protobuf::util::MessageDifferencer::AS_SET;
58 ::google::protobuf::util::MessageDifferencer::FULL;
60 ::google::protobuf::util::MessageDifferencer::PARTIAL;
105 : message_(CloneMessage(
message)) {}
108 : message_(CloneMessage(
message)) {}
111 testing::MatchResultListener*)
const {
112 return EqualsMessage(*message_, m);
115 testing::MatchResultListener*)
const {
116 return EqualsMessage(*message_, *m);
120 *os <<
"has the same serialization as " << ExpectedMessageDescription();
124 *os <<
"does not have the same serialization as "
125 << ExpectedMessageDescription();
130 std::unique_ptr<MessageType> clone(
message.New());
131 clone->CheckTypeAndMergeFrom(
message);
135 bool EqualsMessage(const ::google::protobuf::Message& m_1,
136 const ::google::protobuf::Message& m_2)
const {
137 std::string s_1, s_2;
138 m_1.SerializeToString(&s_1);
139 m_2.SerializeToString(&s_2);
143 std::string ExpectedMessageDescription()
const {
144 return message_->DebugString();
147 const std::shared_ptr<MessageType> message_;
154 const ::google::protobuf::Message&
message) {
160 const auto&
a = ::testing::get<0>(arg);
161 const auto&
b = ::testing::get<1>(arg);
162 return ::testing::ExplainMatchResult(
EqualsProto(
b),
a, result_listener);
168 const ::google::protobuf::Message&
x) {
171 return MakePolymorphicMatcher(
ProtoMatcher(const MessageType &message, bool, ProtoComparison &)
bool MatchAndExplain(const MessageType *m, testing::MatchResultListener *) const
void DescribeNegationTo(std::ostream *os) const
ProtoMatcher(const MessageType &message)
bool MatchAndExplain(const MessageType &m, testing::MatchResultListener *) const
::google::protobuf::Message MessageType
void DescribeTo(std::ostream *os) const
::google::protobuf::util::MessageDifferencer::Scope ProtoComparisonScope
const ProtoFieldComparison kProtoEqual
const ProtoFieldComparison kProtoEquiv
::google::protobuf::util::DefaultFieldComparator::FloatComparison ProtoFloatComparison
How to compare two floating-points (exact vs. approximate).
const ProtoComparisonScope kProtoPartial
const ProtoFloatComparison kProtoExact
PolymorphicMatcher< ProtoMatcher > PolymorphicProtoMatcher
::google::protobuf::util::MessageDifferencer::MessageFieldComparison ProtoFieldComparison
const RepeatedFieldComparison kProtoCompareRepeatedFieldsIgnoringOrdering
::google::protobuf::util::MessageDifferencer::RepeatedFieldComparison RepeatedFieldComparison
How to compare repeated fields (whether the order of elements matters).
const bool kMayBeUninitialized
const ProtoComparisonScope kProtoFull
const RepeatedFieldComparison kProtoCompareRepeatedFieldsRespectOrdering
const ProtoFloatComparison kProtoApproximate
const bool kMustBeInitialized
Whether the protobuf must be initialized.
internal::ProtoMatcher EqualsProto(const ::google::protobuf::Message &message)
internal::PolymorphicProtoMatcher EquivToProto(const ::google::protobuf::Message &x)
MATCHER(EqualsProto, "")
for Pointwise
Options for comparing two protobufs.
bool ignore_debug_string_format
bool treating_nan_as_equal
std::vector< std::string > unordered_fields
ProtoFieldComparison field_comp
ProtoFloatComparison float_comp
RepeatedFieldComparison repeated_field_comp
std::vector< std::string > ignore_fields
bool verified_presence_in_string
std::vector< std::string > ignore_field_paths
ProtoComparisonScope scope
bool fail_on_no_presence_default_values