255 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
256 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
261 #include <functional>
262 #include <initializer_list>
270 #include <type_traits>
280 #if defined(_MSC_VER) && _MSC_VER >= 1915
281 #define GMOCK_MAYBE_5046_ 5046
283 #define GMOCK_MAYBE_5046_
306 class StringMatchResultListener :
public MatchResultListener {
308 StringMatchResultListener() : MatchResultListener(&ss_) {}
311 std::string str()
const {
return ss_.str(); }
314 void Clear() { ss_.str(
""); }
317 ::std::stringstream ss_;
319 StringMatchResultListener(
const StringMatchResultListener&) =
delete;
320 StringMatchResultListener& operator=(
const StringMatchResultListener&) =
338 template <
typename T,
typename M>
339 class MatcherCastImpl {
341 static Matcher<T> Cast(
const M& polymorphic_matcher_or_value) {
355 return CastImpl(polymorphic_matcher_or_value,
356 std::is_convertible<M, Matcher<T>>{},
357 std::is_convertible<M, T>{});
361 template <
bool Ignore>
362 static Matcher<T> CastImpl(
const M& polymorphic_matcher_or_value,
364 std::integral_constant<bool, Ignore>) {
373 return polymorphic_matcher_or_value;
379 static Matcher<T> CastImpl(
const M&
value,
382 return Matcher<T>(ImplicitCast_<T>(
value));
395 static Matcher<T> CastImpl(
const M& value,
403 template <
typename T,
typename U>
404 class MatcherCastImpl<T, Matcher<U>> {
406 static Matcher<T> Cast(
const Matcher<U>& source_matcher) {
407 return Matcher<T>(
new Impl(source_matcher));
419 class Impl :
public MatcherInterface<ImplArgT> {
421 explicit Impl(
const Matcher<U>& source_matcher)
422 : source_matcher_(source_matcher) {}
425 bool MatchAndExplain(ImplArgT
x,
426 MatchResultListener* listener)
const override {
427 using FromType =
typename std::remove_cv<
typename std::remove_pointer<
428 typename std::remove_reference<T>::type>::type>::type;
429 using ToType =
typename std::remove_cv<
typename std::remove_pointer<
430 typename std::remove_reference<U>::type>::type>::type;
435 (std::is_pointer<
typename std::remove_reference<T>::type>::
value !=
436 std::is_pointer<
typename std::remove_reference<U>::type>::
value) ||
439 "Can't implicitly convert from <base> to <derived>");
443 using CastType =
typename std::conditional<
446 return source_matcher_.MatchAndExplain(static_cast<CastType>(x),
450 void DescribeTo(::std::ostream* os)
const override {
451 source_matcher_.DescribeTo(os);
454 void DescribeNegationTo(::std::ostream* os)
const override {
455 source_matcher_.DescribeNegationTo(os);
459 const Matcher<U> source_matcher_;
465 template <
typename T>
466 class MatcherCastImpl<T, Matcher<T>> {
468 static Matcher<T> Cast(
const Matcher<T>& matcher) {
return matcher; }
472 template <
typename Derived>
473 class MatcherBaseImpl {
475 MatcherBaseImpl() =
default;
477 template <
typename T>
478 operator ::testing::Matcher<T>()
const {
479 return ::testing::Matcher<T>(
new
480 typename Derived::template gmock_Impl<T>());
485 template <
template <
typename...>
class Derived,
typename... Ts>
486 class MatcherBaseImpl<Derived<Ts...>> {
490 template <
typename E = std::enable_if<
sizeof...(Ts) == 1>,
491 typename E::type* =
nullptr>
492 explicit MatcherBaseImpl(Ts... params)
493 : params_(std::forward<Ts>(params)...) {}
494 template <
typename E = std::enable_if<
sizeof...(Ts) != 1>,
495 typename =
typename E::type>
496 MatcherBaseImpl(Ts... params)
497 : params_(std::forward<Ts>(params)...) {}
499 template <
typename F>
500 operator ::testing::Matcher<F>()
const {
501 return Apply<F>(std::make_index_sequence<
sizeof...(Ts)>{});
505 template <
typename F, std::size_t... tuple_ids>
507 return ::testing::Matcher<F>(
508 new typename Derived<Ts...>::template gmock_Impl<F>(
509 std::get<tuple_ids>(params_)...));
512 const std::tuple<Ts...> params_;
521 template <
typename T,
typename M>
522 inline Matcher<T> MatcherCast(
const M& matcher) {
523 return internal::MatcherCastImpl<T, M>::Cast(matcher);
528 template <
typename T,
typename M>
529 inline Matcher<T> SafeMatcherCast(
const M& polymorphic_matcher_or_value) {
530 return MatcherCast<T>(polymorphic_matcher_or_value);
543 template <
typename T,
typename U>
544 inline Matcher<T> SafeMatcherCast(
const Matcher<U>& matcher) {
547 "T must be implicitly convertible to U (and T must be a "
548 "non-const reference if U is a non-const reference)");
556 kTIsOther || kUIsOther ||
558 "conversion of arithmetic types must be lossless");
559 return MatcherCast<T>(matcher);
563 template <
typename T>
572 struct Rank1 : Rank0 {};
573 using HighestRank = Rank1;
576 inline void PrintIfNotEmpty(
const std::string& explanation,
577 ::std::ostream* os) {
578 if (!explanation.empty() && os !=
nullptr) {
579 *os <<
", " << explanation;
586 inline bool IsReadableTypeName(
const std::string& type_name) {
589 return (type_name.length() <= 20 ||
590 type_name.find_first_of(
"<(") == std::string::npos);
598 template <
typename Value,
typename T>
599 bool MatchPrintAndExplain(Value&
value,
const Matcher<T>& matcher,
600 MatchResultListener* listener) {
601 if (!listener->IsInterested()) {
604 return matcher.Matches(value);
607 StringMatchResultListener inner_listener;
608 const bool match = matcher.MatchAndExplain(value, &inner_listener);
612 const std::string& type_name = GetTypeName<Value>();
613 if (IsReadableTypeName(type_name))
614 *listener->stream() <<
" (of type " << type_name <<
")";
616 PrintIfNotEmpty(inner_listener.str(), listener->stream());
629 template <
typename MatcherTuple,
typename ValueTuple>
630 static bool Matches(
const MatcherTuple& matcher_tuple,
631 const ValueTuple& value_tuple) {
632 return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple) &&
633 std::get<
N - 1>(matcher_tuple).Matches(std::get<N - 1>(value_tuple));
640 template <
typename MatcherTuple,
typename ValueTuple>
641 static void ExplainMatchFailuresTo(
const MatcherTuple& matchers,
642 const ValueTuple& values,
643 ::std::ostream* os) {
645 TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os);
649 typename std::tuple_element<
N - 1, MatcherTuple>::type matcher =
650 std::get<N - 1>(matchers);
651 typedef typename std::tuple_element<N - 1, ValueTuple>::type Value;
652 const Value& value = std::get<N - 1>(values);
653 StringMatchResultListener listener;
654 if (!matcher.MatchAndExplain(value, &listener)) {
655 *os <<
" Expected arg #" << N - 1 <<
": ";
656 std::get<N - 1>(matchers).DescribeTo(os);
657 *os <<
"\n Actual: ";
664 PrintIfNotEmpty(listener.str(), os);
672 class TuplePrefix<0> {
674 template <
typename MatcherTuple,
typename ValueTuple>
675 static bool Matches(
const MatcherTuple& ,
676 const ValueTuple& ) {
680 template <
typename MatcherTuple,
typename ValueTuple>
681 static void ExplainMatchFailuresTo(
const MatcherTuple& ,
691 template <
typename MatcherTuple,
typename ValueTuple>
692 bool TupleMatches(
const MatcherTuple& matcher_tuple,
693 const ValueTuple& value_tuple) {
698 "matcher and value have different numbers of fields");
705 template <
typename MatcherTuple,
typename ValueTuple>
706 void ExplainMatchFailureTupleTo(
const MatcherTuple& matchers,
707 const ValueTuple& values, ::std::ostream* os) {
709 matchers, values, os);
716 template <
typename Tuple,
typename Func,
typename OutIter>
717 class TransformTupleValuesHelper {
719 typedef ::std::tuple_size<Tuple> TupleSize;
724 static OutIter Run(Func
f,
const Tuple& t, OutIter out) {
725 return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out);
729 template <
typename Tup,
size_t kRemainingSize>
730 struct IterateOverTuple {
731 OutIter operator()(Func f,
const Tup& t, OutIter out)
const {
732 *out++ = f(::std::get<TupleSize::value - kRemainingSize>(t));
733 return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out);
736 template <
typename Tup>
737 struct IterateOverTuple<Tup, 0> {
738 OutIter operator()(Func ,
const Tup& , OutIter out)
const {
747 template <
typename Tuple,
typename Func,
typename OutIter>
748 OutIter TransformTupleValues(Func
f,
const Tuple& t, OutIter out) {
749 return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out);
756 class AnythingMatcher {
758 using is_gtest_matcher =
void;
760 template <
typename T>
761 bool MatchAndExplain(
const T& , std::ostream* )
const {
764 void DescribeTo(std::ostream* os)
const { *os <<
"is anything"; }
765 void DescribeNegationTo(::std::ostream* os)
const {
769 *os <<
"never matches";
775 class IsNullMatcher {
777 template <
typename Po
inter>
778 bool MatchAndExplain(
const Pointer&
p,
779 MatchResultListener* )
const {
783 void DescribeTo(::std::ostream* os)
const { *os <<
"is NULL"; }
784 void DescribeNegationTo(::std::ostream* os)
const { *os <<
"isn't NULL"; }
789 class NotNullMatcher {
791 template <
typename Po
inter>
792 bool MatchAndExplain(
const Pointer&
p,
793 MatchResultListener* )
const {
797 void DescribeTo(::std::ostream* os)
const { *os <<
"isn't NULL"; }
798 void DescribeNegationTo(::std::ostream* os)
const { *os <<
"is NULL"; }
814 template <
typename T>
817 template <
typename T>
818 class RefMatcher<T&> {
828 explicit RefMatcher(T&
x) : object_(x) {}
830 template <
typename Super>
831 operator Matcher<Super&>()
const {
837 return MakeMatcher(
new Impl<Super>(object_));
841 template <
typename Super>
842 class Impl :
public MatcherInterface<Super&> {
844 explicit Impl(Super& x) : object_(x) {}
848 bool MatchAndExplain(Super& x,
849 MatchResultListener* listener)
const override {
850 *listener <<
"which is located @" <<
static_cast<const void*
>(&
x);
851 return &x == &object_;
854 void DescribeTo(::std::ostream* os)
const override {
855 *os <<
"references the variable ";
859 void DescribeNegationTo(::std::ostream* os)
const override {
860 *os <<
"does not reference the variable ";
865 const Super& object_;
872 inline bool CaseInsensitiveCStringEquals(
const char* lhs,
const char* rhs) {
873 return String::CaseInsensitiveCStringEquals(lhs, rhs);
876 inline bool CaseInsensitiveCStringEquals(
const wchar_t* lhs,
877 const wchar_t* rhs) {
878 return String::CaseInsensitiveWideCStringEquals(lhs, rhs);
883 template <
typename StringType>
884 bool CaseInsensitiveStringEquals(
const StringType& s1,
const StringType& s2) {
886 if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) {
891 const typename StringType::value_type nul = 0;
892 const size_t i1 = s1.find(nul), i2 = s2.find(nul);
895 if (i1 == StringType::npos || i2 == StringType::npos) {
900 return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1));
906 template <
typename StringType>
907 class StrEqualityMatcher {
909 StrEqualityMatcher(StringType str,
bool expect_eq,
bool case_sensitive)
910 : string_(std::move(str)),
911 expect_eq_(expect_eq),
912 case_sensitive_(case_sensitive) {}
914 #if GTEST_INTERNAL_HAS_STRING_VIEW
915 bool MatchAndExplain(
const internal::StringView& s,
916 MatchResultListener* listener)
const {
919 const StringType& str = std::string(s);
920 return MatchAndExplain(str, listener);
922 #endif // GTEST_INTERNAL_HAS_STRING_VIEW
929 template <
typename CharType>
930 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
934 return MatchAndExplain(StringType(s), listener);
941 template <
typename MatcheeStringType>
942 bool MatchAndExplain(
const MatcheeStringType& s,
943 MatchResultListener* )
const {
944 const StringType s2(s);
945 const bool eq = case_sensitive_ ? s2 == string_
946 : CaseInsensitiveStringEquals(s2, string_);
947 return expect_eq_ == eq;
950 void DescribeTo(::std::ostream* os)
const {
951 DescribeToHelper(expect_eq_, os);
954 void DescribeNegationTo(::std::ostream* os)
const {
955 DescribeToHelper(!expect_eq_, os);
959 void DescribeToHelper(
bool expect_eq, ::std::ostream* os)
const {
960 *os << (expect_eq ?
"is " :
"isn't ");
962 if (!case_sensitive_) {
963 *os <<
"(ignoring case) ";
968 const StringType string_;
969 const bool expect_eq_;
970 const bool case_sensitive_;
976 template <
typename StringType>
977 class HasSubstrMatcher {
979 explicit HasSubstrMatcher(
const StringType& substring)
980 : substring_(substring) {}
982 #if GTEST_INTERNAL_HAS_STRING_VIEW
983 bool MatchAndExplain(
const internal::StringView& s,
984 MatchResultListener* listener)
const {
987 const StringType& str = std::string(s);
988 return MatchAndExplain(str, listener);
990 #endif // GTEST_INTERNAL_HAS_STRING_VIEW
997 template <
typename CharType>
998 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
999 return s !=
nullptr && MatchAndExplain(StringType(s), listener);
1006 template <
typename MatcheeStringType>
1007 bool MatchAndExplain(
const MatcheeStringType& s,
1008 MatchResultListener* )
const {
1009 return StringType(s).find(substring_) != StringType::npos;
1013 void DescribeTo(::std::ostream* os)
const {
1014 *os <<
"has substring ";
1018 void DescribeNegationTo(::std::ostream* os)
const {
1019 *os <<
"has no substring ";
1024 const StringType substring_;
1030 template <
typename StringType>
1031 class StartsWithMatcher {
1033 explicit StartsWithMatcher(
const StringType& prefix) : prefix_(prefix) {}
1035 #if GTEST_INTERNAL_HAS_STRING_VIEW
1036 bool MatchAndExplain(
const internal::StringView& s,
1037 MatchResultListener* listener)
const {
1040 const StringType& str = std::string(s);
1041 return MatchAndExplain(str, listener);
1043 #endif // GTEST_INTERNAL_HAS_STRING_VIEW
1050 template <
typename CharType>
1051 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
1052 return s !=
nullptr && MatchAndExplain(StringType(s), listener);
1059 template <
typename MatcheeStringType>
1060 bool MatchAndExplain(
const MatcheeStringType& s,
1061 MatchResultListener* )
const {
1062 const StringType s2(s);
1063 return s2.length() >= prefix_.length() &&
1064 s2.substr(0, prefix_.length()) == prefix_;
1067 void DescribeTo(::std::ostream* os)
const {
1068 *os <<
"starts with ";
1072 void DescribeNegationTo(::std::ostream* os)
const {
1073 *os <<
"doesn't start with ";
1078 const StringType prefix_;
1084 template <
typename StringType>
1085 class EndsWithMatcher {
1087 explicit EndsWithMatcher(
const StringType& suffix) : suffix_(suffix) {}
1089 #if GTEST_INTERNAL_HAS_STRING_VIEW
1090 bool MatchAndExplain(
const internal::StringView& s,
1091 MatchResultListener* listener)
const {
1094 const StringType& str = std::string(s);
1095 return MatchAndExplain(str, listener);
1097 #endif // GTEST_INTERNAL_HAS_STRING_VIEW
1104 template <
typename CharType>
1105 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
1106 return s !=
nullptr && MatchAndExplain(StringType(s), listener);
1113 template <
typename MatcheeStringType>
1114 bool MatchAndExplain(
const MatcheeStringType& s,
1115 MatchResultListener* )
const {
1116 const StringType s2(s);
1117 return s2.length() >= suffix_.length() &&
1118 s2.substr(s2.length() - suffix_.length()) == suffix_;
1121 void DescribeTo(::std::ostream* os)
const {
1122 *os <<
"ends with ";
1126 void DescribeNegationTo(::std::ostream* os)
const {
1127 *os <<
"doesn't end with ";
1132 const StringType suffix_;
1137 class WhenBase64UnescapedMatcher {
1139 using is_gtest_matcher =
void;
1141 explicit WhenBase64UnescapedMatcher(
1142 const Matcher<const std::string&>& internal_matcher)
1143 : internal_matcher_(internal_matcher) {}
1146 template <
typename MatcheeStringType>
1147 bool MatchAndExplain(
const MatcheeStringType& s,
1148 MatchResultListener* listener)
const {
1149 const std::string s2(s);
1150 std::string unescaped;
1152 if (listener !=
nullptr) {
1153 *listener <<
"is not a valid base64 escaped string";
1157 return MatchPrintAndExplain(unescaped, internal_matcher_, listener);
1160 void DescribeTo(::std::ostream* os)
const {
1161 *os <<
"matches after Base64Unescape ";
1162 internal_matcher_.DescribeTo(os);
1165 void DescribeNegationTo(::std::ostream* os)
const {
1166 *os <<
"does not match after Base64Unescape ";
1167 internal_matcher_.DescribeTo(os);
1171 const Matcher<const std::string&> internal_matcher_;
1182 template <
typename D,
typename Op>
1183 class PairMatchBase {
1185 template <
typename T1,
typename T2>
1186 operator Matcher<::std::tuple<T1, T2>>()
const {
1187 return Matcher<::std::tuple<T1, T2>>(
new Impl<const ::std::tuple<T1, T2>&>);
1189 template <
typename T1,
typename T2>
1190 operator Matcher<const ::std::tuple<T1, T2>&>()
const {
1191 return MakeMatcher(
new Impl<const ::std::tuple<T1, T2>&>);
1195 static ::std::ostream& GetDesc(::std::ostream& os) {
1196 return os << D::Desc();
1199 template <
typename Tuple>
1200 class Impl :
public MatcherInterface<Tuple> {
1202 bool MatchAndExplain(Tuple args,
1203 MatchResultListener* )
const override {
1204 return Op()(::std::get<0>(args), ::std::get<1>(args));
1206 void DescribeTo(::std::ostream* os)
const override {
1207 *os <<
"are " << GetDesc;
1209 void DescribeNegationTo(::std::ostream* os)
const override {
1210 *os <<
"aren't " << GetDesc;
1215 class Eq2Matcher :
public PairMatchBase<Eq2Matcher, std::equal_to<>> {
1217 static const char* Desc() {
return "an equal pair"; }
1219 class Ne2Matcher :
public PairMatchBase<Ne2Matcher, std::not_equal_to<>> {
1221 static const char* Desc() {
return "an unequal pair"; }
1223 class Lt2Matcher :
public PairMatchBase<Lt2Matcher, std::less<>> {
1225 static const char* Desc() {
return "a pair where the first < the second"; }
1227 class Gt2Matcher :
public PairMatchBase<Gt2Matcher, std::greater<>> {
1229 static const char* Desc() {
return "a pair where the first > the second"; }
1231 class Le2Matcher :
public PairMatchBase<Le2Matcher, std::less_equal<>> {
1233 static const char* Desc() {
return "a pair where the first <= the second"; }
1235 class Ge2Matcher :
public PairMatchBase<Ge2Matcher, std::greater_equal<>> {
1237 static const char* Desc() {
return "a pair where the first >= the second"; }
1244 template <
typename T>
1245 class NotMatcherImpl :
public MatcherInterface<const T&> {
1247 explicit NotMatcherImpl(
const Matcher<T>& matcher) : matcher_(matcher) {}
1249 bool MatchAndExplain(
const T&
x,
1250 MatchResultListener* listener)
const override {
1251 return !matcher_.MatchAndExplain(x, listener);
1254 void DescribeTo(::std::ostream* os)
const override {
1255 matcher_.DescribeNegationTo(os);
1258 void DescribeNegationTo(::std::ostream* os)
const override {
1259 matcher_.DescribeTo(os);
1263 const Matcher<T> matcher_;
1268 template <
typename InnerMatcher>
1271 explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
1275 template <
typename T>
1276 operator Matcher<T>()
const {
1277 return Matcher<T>(
new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_)));
1281 InnerMatcher matcher_;
1288 template <
typename T>
1289 class AllOfMatcherImpl :
public MatcherInterface<const T&> {
1291 explicit AllOfMatcherImpl(std::vector<Matcher<T>> matchers)
1292 : matchers_(std::move(matchers)) {}
1294 void DescribeTo(::std::ostream* os)
const override {
1296 for (
size_t i = 0;
i < matchers_.size(); ++
i) {
1297 if (
i != 0) *os <<
") and (";
1298 matchers_[
i].DescribeTo(os);
1303 void DescribeNegationTo(::std::ostream* os)
const override {
1305 for (
size_t i = 0;
i < matchers_.size(); ++
i) {
1306 if (
i != 0) *os <<
") or (";
1307 matchers_[
i].DescribeNegationTo(os);
1312 bool MatchAndExplain(
const T&
x,
1313 MatchResultListener* listener)
const override {
1317 std::string all_match_result;
1318 for (
const Matcher<T>& matcher : matchers_) {
1319 StringMatchResultListener slistener;
1321 if (!matcher.MatchAndExplain(x, &slistener)) {
1322 const std::string explanation = slistener.str();
1323 if (!explanation.empty()) {
1324 *listener << explanation;
1326 *listener <<
"which doesn't match (" <<
Describe(matcher) <<
")";
1331 std::string explanation = slistener.str();
1332 if (explanation.empty()) {
1335 if (all_match_result.empty()) {
1336 all_match_result = explanation;
1338 if (!explanation.empty()) {
1339 all_match_result +=
", and ";
1340 all_match_result += explanation;
1345 *listener << all_match_result;
1351 std::string
Describe(
const Matcher<T>& matcher)
const {
1352 StringMatchResultListener listener;
1353 matcher.DescribeTo(listener.stream());
1354 return listener.str();
1356 const std::vector<Matcher<T>> matchers_;
1363 template <
template <
typename T>
class CombiningMatcher,
typename... Args>
1364 class VariadicMatcher {
1366 VariadicMatcher(
const Args&... matchers)
1367 : matchers_(matchers...) {
1368 static_assert(
sizeof...(Args) > 0,
"Must have at least one matcher.");
1371 VariadicMatcher(
const VariadicMatcher&) =
default;
1372 VariadicMatcher& operator=(
const VariadicMatcher&) =
delete;
1377 template <
typename T>
1378 operator Matcher<T>()
const {
1379 std::vector<Matcher<T>> values;
1380 CreateVariadicMatcher<T>(&values, std::integral_constant<size_t, 0>());
1381 return Matcher<T>(
new CombiningMatcher<T>(std::move(values)));
1385 template <
typename T,
size_t I>
1386 void CreateVariadicMatcher(std::vector<Matcher<T>>* values,
1387 std::integral_constant<size_t, I>)
const {
1388 values->push_back(SafeMatcherCast<T>(std::get<I>(matchers_)));
1389 CreateVariadicMatcher<T>(values, std::integral_constant<size_t, I + 1>());
1392 template <
typename T>
1393 void CreateVariadicMatcher(
1394 std::vector<Matcher<T>>*,
1395 std::integral_constant<
size_t,
sizeof...(Args)>)
const {}
1397 std::tuple<Args...> matchers_;
1400 template <
typename... Args>
1401 using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>;
1407 template <
typename T>
1408 class AnyOfMatcherImpl :
public MatcherInterface<const T&> {
1410 explicit AnyOfMatcherImpl(std::vector<Matcher<T>> matchers)
1411 : matchers_(std::move(matchers)) {}
1413 void DescribeTo(::std::ostream* os)
const override {
1415 for (
size_t i = 0;
i < matchers_.size(); ++
i) {
1416 if (
i != 0) *os <<
") or (";
1417 matchers_[
i].DescribeTo(os);
1422 void DescribeNegationTo(::std::ostream* os)
const override {
1424 for (
size_t i = 0;
i < matchers_.size(); ++
i) {
1425 if (
i != 0) *os <<
") and (";
1426 matchers_[
i].DescribeNegationTo(os);
1431 bool MatchAndExplain(
const T&
x,
1432 MatchResultListener* listener)
const override {
1436 std::string no_match_result;
1437 for (
const Matcher<T>& matcher : matchers_) {
1438 StringMatchResultListener slistener;
1440 if (matcher.MatchAndExplain(x, &slistener)) {
1441 const std::string explanation = slistener.str();
1442 if (!explanation.empty()) {
1443 *listener << explanation;
1445 *listener <<
"which matches (" <<
Describe(matcher) <<
")";
1450 std::string explanation = slistener.str();
1451 if (explanation.empty()) {
1454 if (no_match_result.empty()) {
1455 no_match_result = explanation;
1457 if (!explanation.empty()) {
1458 no_match_result +=
", and ";
1459 no_match_result += explanation;
1464 *listener << no_match_result;
1470 std::string
Describe(
const Matcher<T>& matcher)
const {
1471 StringMatchResultListener listener;
1472 matcher.DescribeTo(listener.stream());
1473 return listener.str();
1477 StringMatchResultListener listener;
1478 matcher.DescribeNegationTo(listener.stream());
1479 return listener.str();
1482 const std::vector<Matcher<T>> matchers_;
1486 template <
typename... Args>
1487 using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>;
1490 template <
typename MatcherTrue,
typename MatcherFalse>
1491 class ConditionalMatcher {
1493 ConditionalMatcher(
bool condition, MatcherTrue matcher_true,
1494 MatcherFalse matcher_false)
1495 : condition_(condition),
1496 matcher_true_(std::move(matcher_true)),
1497 matcher_false_(std::move(matcher_false)) {}
1499 template <
typename T>
1500 operator Matcher<T>()
const {
1501 return condition_ ? SafeMatcherCast<T>(matcher_true_)
1502 : SafeMatcherCast<T>(matcher_false_);
1507 MatcherTrue matcher_true_;
1508 MatcherFalse matcher_false_;
1512 template <
template <
class>
class MatcherImpl,
typename T>
1513 class SomeOfArrayMatcher {
1517 template <
typename Iter>
1518 SomeOfArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
1520 template <
typename U>
1521 operator Matcher<U>()
const {
1522 using RawU =
typename std::decay<U>::type;
1523 std::vector<Matcher<RawU>> matchers;
1524 matchers.reserve(matchers_.size());
1525 for (
const auto& matcher : matchers_) {
1526 matchers.push_back(MatcherCast<RawU>(matcher));
1528 return Matcher<U>(
new MatcherImpl<RawU>(std::move(matchers)));
1532 const std::vector<std::remove_const_t<T>> matchers_;
1535 template <
typename T>
1536 using AllOfArrayMatcher = SomeOfArrayMatcher<AllOfMatcherImpl, T>;
1538 template <
typename T>
1539 using AnyOfArrayMatcher = SomeOfArrayMatcher<AnyOfMatcherImpl, T>;
1543 template <
typename Predicate>
1544 class TrulyMatcher {
1546 explicit TrulyMatcher(Predicate pred) : predicate_(pred) {}
1552 template <
typename T>
1553 bool MatchAndExplain(T&
x,
1554 MatchResultListener* listener)
const {
1561 if (predicate_(x))
return true;
1562 *listener <<
"didn't satisfy the given predicate";
1566 void DescribeTo(::std::ostream* os)
const {
1567 *os <<
"satisfies the given predicate";
1570 void DescribeNegationTo(::std::ostream* os)
const {
1571 *os <<
"doesn't satisfy the given predicate";
1575 Predicate predicate_;
1580 template <
typename M>
1581 class MatcherAsPredicate {
1583 explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
1591 template <
typename T>
1592 bool operator()(
const T&
x)
const {
1607 return MatcherCast<const T&>(matcher_).Matches(x);
1616 template <
typename M>
1617 class PredicateFormatterFromMatcher {
1619 explicit PredicateFormatterFromMatcher(M m) : matcher_(std::move(m)) {}
1624 template <
typename T>
1625 AssertionResult operator()(
const char* value_text,
const T&
x)
const {
1637 const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
1641 if (matcher.Matches(x)) {
1645 ::std::stringstream ss;
1646 ss <<
"Value of: " << value_text <<
"\n"
1648 matcher.DescribeTo(&ss);
1651 StringMatchResultListener listener;
1652 if (MatchPrintAndExplain(x, matcher, &listener)) {
1653 ss <<
"\n The matcher failed on the initial attempt; but passed when "
1654 "rerun to generate the explanation.";
1656 ss <<
"\n Actual: " << listener.str();
1668 template <
typename M>
1669 inline PredicateFormatterFromMatcher<M> MakePredicateFormatterFromMatcher(
1671 return PredicateFormatterFromMatcher<M>(std::move(matcher));
1676 class IsNanMatcher {
1678 template <
typename FloatType>
1679 bool MatchAndExplain(
const FloatType& f,
1680 MatchResultListener* )
const {
1681 return (::std::isnan)(f);
1684 void DescribeTo(::std::ostream* os)
const { *os <<
"is NaN"; }
1685 void DescribeNegationTo(::std::ostream* os)
const { *os <<
"isn't NaN"; }
1692 template <
typename FloatType>
1693 class FloatingEqMatcher {
1701 FloatingEqMatcher(FloatType
expected,
bool nan_eq_nan)
1702 : expected_(expected), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) {}
1707 FloatingEqMatcher(FloatType expected,
bool nan_eq_nan,
1708 FloatType max_abs_error)
1709 : expected_(expected),
1710 nan_eq_nan_(nan_eq_nan),
1711 max_abs_error_(max_abs_error) {
1713 <<
", where max_abs_error is" << max_abs_error;
1717 template <
typename T>
1718 class Impl :
public MatcherInterface<T> {
1720 Impl(FloatType expected,
bool nan_eq_nan, FloatType max_abs_error)
1721 : expected_(expected),
1722 nan_eq_nan_(nan_eq_nan),
1723 max_abs_error_(max_abs_error) {}
1725 bool MatchAndExplain(T value,
1726 MatchResultListener* listener)
const override {
1727 const FloatingPoint<FloatType> actual(value),
expected(expected_);
1730 if (actual.is_nan() || expected.is_nan()) {
1731 if (actual.is_nan() && expected.is_nan()) {
1737 if (HasMaxAbsError()) {
1742 if (value == expected_) {
1746 const FloatType
diff = value - expected_;
1747 if (::
std::fabs(diff) <= max_abs_error_) {
1751 if (listener->IsInterested()) {
1752 *listener <<
"which is " << diff <<
" from " << expected_;
1756 return actual.AlmostEquals(expected);
1760 void DescribeTo(::std::ostream* os)
const override {
1764 const ::std::streamsize old_precision =
1765 os->precision(::std::numeric_limits<FloatType>::digits10 + 2);
1766 if (FloatingPoint<FloatType>(expected_).is_nan()) {
1770 *os <<
"never matches";
1773 *os <<
"is approximately " << expected_;
1774 if (HasMaxAbsError()) {
1775 *os <<
" (absolute error <= " << max_abs_error_ <<
")";
1778 os->precision(old_precision);
1781 void DescribeNegationTo(::std::ostream* os)
const override {
1783 const ::std::streamsize old_precision =
1784 os->precision(::std::numeric_limits<FloatType>::digits10 + 2);
1785 if (FloatingPoint<FloatType>(expected_).is_nan()) {
1789 *os <<
"is anything";
1792 *os <<
"isn't approximately " << expected_;
1793 if (HasMaxAbsError()) {
1794 *os <<
" (absolute error > " << max_abs_error_ <<
")";
1798 os->precision(old_precision);
1802 bool HasMaxAbsError()
const {
return max_abs_error_ >= 0; }
1804 const FloatType expected_;
1805 const bool nan_eq_nan_;
1807 const FloatType max_abs_error_;
1813 operator Matcher<FloatType>()
const {
1815 new Impl<FloatType>(expected_, nan_eq_nan_, max_abs_error_));
1818 operator Matcher<const FloatType&>()
const {
1820 new Impl<const FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
1823 operator Matcher<FloatType&>()
const {
1825 new Impl<FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
1829 const FloatType expected_;
1830 const bool nan_eq_nan_;
1832 const FloatType max_abs_error_;
1840 template <
typename FloatType>
1841 class FloatingEq2Matcher {
1843 FloatingEq2Matcher() { Init(-1,
false); }
1845 explicit FloatingEq2Matcher(
bool nan_eq_nan) { Init(-1, nan_eq_nan); }
1847 explicit FloatingEq2Matcher(FloatType max_abs_error) {
1848 Init(max_abs_error,
false);
1851 FloatingEq2Matcher(FloatType max_abs_error,
bool nan_eq_nan) {
1852 Init(max_abs_error, nan_eq_nan);
1855 template <
typename T1,
typename T2>
1856 operator Matcher<::std::tuple<T1, T2>>()
const {
1858 new Impl<::std::tuple<T1, T2>>(max_abs_error_, nan_eq_nan_));
1860 template <
typename T1,
typename T2>
1861 operator Matcher<const ::std::tuple<T1, T2>&>()
const {
1863 new Impl<const ::std::tuple<T1, T2>&>(max_abs_error_, nan_eq_nan_));
1867 static ::std::ostream& GetDesc(::std::ostream& os) {
1868 return os <<
"an almost-equal pair";
1871 template <
typename Tuple>
1872 class Impl :
public MatcherInterface<Tuple> {
1874 Impl(FloatType max_abs_error,
bool nan_eq_nan)
1875 : max_abs_error_(max_abs_error), nan_eq_nan_(nan_eq_nan) {}
1877 bool MatchAndExplain(Tuple args,
1878 MatchResultListener* listener)
const override {
1879 if (max_abs_error_ == -1) {
1880 FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_);
1881 return static_cast<Matcher<FloatType>
>(fm).MatchAndExplain(
1882 ::std::get<1>(args), listener);
1884 FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_,
1886 return static_cast<Matcher<FloatType>
>(fm).MatchAndExplain(
1887 ::std::get<1>(args), listener);
1890 void DescribeTo(::std::ostream* os)
const override {
1891 *os <<
"are " << GetDesc;
1893 void DescribeNegationTo(::std::ostream* os)
const override {
1894 *os <<
"aren't " << GetDesc;
1898 FloatType max_abs_error_;
1899 const bool nan_eq_nan_;
1902 void Init(FloatType max_abs_error_val,
bool nan_eq_nan_val) {
1903 max_abs_error_ = max_abs_error_val;
1904 nan_eq_nan_ = nan_eq_nan_val;
1906 FloatType max_abs_error_;
1912 template <
typename InnerMatcher>
1913 class PointeeMatcher {
1915 explicit PointeeMatcher(
const InnerMatcher& matcher) : matcher_(matcher) {}
1925 template <
typename Po
inter>
1926 operator Matcher<Pointer>()
const {
1927 return Matcher<Pointer>(
new Impl<const Pointer&>(matcher_));
1932 template <
typename Po
inter>
1933 class Impl :
public MatcherInterface<Pointer> {
1937 Pointer)>::element_type;
1939 explicit Impl(
const InnerMatcher& matcher)
1940 : matcher_(MatcherCast<const Pointee&>(matcher)) {}
1942 void DescribeTo(::std::ostream* os)
const override {
1943 *os <<
"points to a value that ";
1944 matcher_.DescribeTo(os);
1947 void DescribeNegationTo(::std::ostream* os)
const override {
1948 *os <<
"does not point to a value that ";
1949 matcher_.DescribeTo(os);
1952 bool MatchAndExplain(Pointer pointer,
1953 MatchResultListener* listener)
const override {
1956 *listener <<
"which points to ";
1957 return MatchPrintAndExplain(*pointer, matcher_, listener);
1961 const Matcher<const Pointee&> matcher_;
1964 const InnerMatcher matcher_;
1971 template <
typename InnerMatcher>
1972 class PointerMatcher {
1974 explicit PointerMatcher(
const InnerMatcher& matcher) : matcher_(matcher) {}
1984 template <
typename Po
interType>
1985 operator Matcher<PointerType>()
const {
1986 return Matcher<PointerType>(
new Impl<const PointerType&>(matcher_));
1991 template <
typename Po
interType>
1992 class Impl :
public MatcherInterface<PointerType> {
1996 PointerType)>::element_type*;
1998 explicit Impl(
const InnerMatcher& matcher)
1999 : matcher_(MatcherCast<Pointer>(matcher)) {}
2001 void DescribeTo(::std::ostream* os)
const override {
2002 *os <<
"is a pointer that ";
2003 matcher_.DescribeTo(os);
2006 void DescribeNegationTo(::std::ostream* os)
const override {
2007 *os <<
"is not a pointer that ";
2008 matcher_.DescribeTo(os);
2011 bool MatchAndExplain(PointerType pointer,
2012 MatchResultListener* listener)
const override {
2013 *listener <<
"which is a pointer that ";
2015 return MatchPrintAndExplain(p, matcher_, listener);
2019 Matcher<Pointer> matcher_;
2022 const InnerMatcher matcher_;
2032 template <
typename To>
2033 class WhenDynamicCastToMatcherBase {
2035 explicit WhenDynamicCastToMatcherBase(
const Matcher<To>& matcher)
2036 : matcher_(matcher) {}
2038 void DescribeTo(::std::ostream* os)
const {
2039 GetCastTypeDescription(os);
2040 matcher_.DescribeTo(os);
2043 void DescribeNegationTo(::std::ostream* os)
const {
2044 GetCastTypeDescription(os);
2045 matcher_.DescribeNegationTo(os);
2049 const Matcher<To> matcher_;
2051 static std::string GetToName() {
return GetTypeName<To>(); }
2054 static void GetCastTypeDescription(::std::ostream* os) {
2055 *os <<
"when dynamic_cast to " << GetToName() <<
", ";
2061 template <
typename To>
2062 class WhenDynamicCastToMatcher :
public WhenDynamicCastToMatcherBase<To> {
2064 explicit WhenDynamicCastToMatcher(
const Matcher<To>& matcher)
2065 : WhenDynamicCastToMatcherBase<To>(matcher) {}
2067 template <
typename From>
2068 bool MatchAndExplain(From from, MatchResultListener* listener)
const {
2069 To to =
dynamic_cast<To
>(from);
2070 return MatchPrintAndExplain(to, this->matcher_, listener);
2076 template <
typename To>
2077 class WhenDynamicCastToMatcher<To&> :
public WhenDynamicCastToMatcherBase<To&> {
2079 explicit WhenDynamicCastToMatcher(
const Matcher<To&>& matcher)
2080 : WhenDynamicCastToMatcherBase<To&>(matcher) {}
2082 template <
typename From>
2083 bool MatchAndExplain(From& from, MatchResultListener* listener)
const {
2085 To* to =
dynamic_cast<To*
>(&from);
2086 if (to ==
nullptr) {
2087 *listener <<
"which cannot be dynamic_cast to " << this->GetToName();
2090 return MatchPrintAndExplain(*to, this->matcher_, listener);
2093 #endif // GTEST_HAS_RTTI
2097 template <
typename Class,
typename FieldType>
2098 class FieldMatcher {
2100 FieldMatcher(FieldType Class::*field,
2101 const Matcher<const FieldType&>& matcher)
2102 : field_(field), matcher_(matcher), whose_field_(
"whose given field ") {}
2104 FieldMatcher(
const std::string& field_name, FieldType Class::*field,
2105 const Matcher<const FieldType&>& matcher)
2108 whose_field_(
"whose field `" + field_name +
"` ") {}
2110 void DescribeTo(::std::ostream* os)
const {
2111 *os <<
"is an object " << whose_field_;
2112 matcher_.DescribeTo(os);
2115 void DescribeNegationTo(::std::ostream* os)
const {
2116 *os <<
"is an object " << whose_field_;
2117 matcher_.DescribeNegationTo(os);
2120 template <
typename T>
2121 bool MatchAndExplain(
const T& value, MatchResultListener* listener)
const {
2124 return MatchAndExplainImpl(
2125 typename std::is_pointer<
typename std::remove_const<T>::type>::type(),
2130 bool MatchAndExplainImpl(std::false_type ,
2132 MatchResultListener* listener)
const {
2133 *listener << whose_field_ <<
"is ";
2134 return MatchPrintAndExplain(obj.*field_, matcher_, listener);
2137 bool MatchAndExplainImpl(std::true_type ,
const Class*
p,
2138 MatchResultListener* listener)
const {
2139 if (p ==
nullptr)
return false;
2141 *listener <<
"which points to an object ";
2145 return MatchAndExplainImpl(std::false_type(), *p, listener);
2148 const FieldType Class::*field_;
2149 const Matcher<const FieldType&> matcher_;
2153 const std::string whose_field_;
2161 template <
typename Class,
typename PropertyType,
typename Property>
2162 class PropertyMatcher {
2164 typedef const PropertyType& RefToConstProperty;
2166 PropertyMatcher(Property property,
const Matcher<RefToConstProperty>& matcher)
2167 : property_(property),
2169 whose_property_(
"whose given property ") {}
2171 PropertyMatcher(
const std::string& property_name, Property property,
2172 const Matcher<RefToConstProperty>& matcher)
2173 : property_(property),
2175 whose_property_(
"whose property `" + property_name +
"` ") {}
2177 void DescribeTo(::std::ostream* os)
const {
2178 *os <<
"is an object " << whose_property_;
2179 matcher_.DescribeTo(os);
2182 void DescribeNegationTo(::std::ostream* os)
const {
2183 *os <<
"is an object " << whose_property_;
2184 matcher_.DescribeNegationTo(os);
2187 template <
typename T>
2188 bool MatchAndExplain(
const T& value, MatchResultListener* listener)
const {
2189 return MatchAndExplainImpl(
2190 typename std::is_pointer<
typename std::remove_const<T>::type>::type(),
2195 bool MatchAndExplainImpl(std::false_type ,
2197 MatchResultListener* listener)
const {
2198 *listener << whose_property_ <<
"is ";
2201 RefToConstProperty result = (obj.*property_)();
2202 return MatchPrintAndExplain(result, matcher_, listener);
2205 bool MatchAndExplainImpl(std::true_type ,
const Class*
p,
2206 MatchResultListener* listener)
const {
2207 if (p ==
nullptr)
return false;
2209 *listener <<
"which points to an object ";
2213 return MatchAndExplainImpl(std::false_type(), *p, listener);
2217 const Matcher<RefToConstProperty> matcher_;
2221 const std::string whose_property_;
2226 template <
typename Functor>
2227 struct CallableTraits {
2228 typedef Functor StorageType;
2230 static void CheckIsValid(Functor ) {}
2232 template <
typename T>
2233 static auto Invoke(Functor f,
const T& arg) -> decltype(f(arg)) {
2239 template <
typename ArgType,
typename ResType>
2240 struct CallableTraits<ResType (*)(ArgType)> {
2241 typedef ResType ResultType;
2242 typedef ResType (*StorageType)(ArgType);
2244 static void CheckIsValid(ResType (*f)(ArgType)) {
2246 <<
"NULL function pointer is passed into ResultOf().";
2248 template <
typename T>
2249 static ResType
Invoke(ResType (*f)(ArgType), T arg) {
2256 template <
typename Callable,
typename InnerMatcher>
2257 class ResultOfMatcher {
2259 ResultOfMatcher(Callable callable, InnerMatcher matcher)
2260 : ResultOfMatcher(
"", std::move(callable),
2261 std::move(matcher)) {}
2263 ResultOfMatcher(
const std::string& result_description, Callable callable,
2264 InnerMatcher matcher)
2265 : result_description_(result_description),
2266 callable_(std::move(callable)),
2267 matcher_(std::move(matcher)) {
2268 CallableTraits<Callable>::CheckIsValid(callable_);
2271 template <
typename T>
2272 operator Matcher<T>()
const {
2274 new Impl<const T&>(result_description_, callable_, matcher_));
2278 typedef typename CallableTraits<Callable>::StorageType CallableStorageType;
2280 template <
typename T>
2281 class Impl :
public MatcherInterface<T> {
2282 using ResultType = decltype(CallableTraits<Callable>::template Invoke<T>(
2283 std::declval<CallableStorageType>(), std::declval<T>()));
2284 using InnerType = std::conditional_t<
2286 const typename std::remove_reference<ResultType>::type&, ResultType>;
2289 template <
typename M>
2290 Impl(
const std::string& result_description,
2291 const CallableStorageType& callable,
const M& matcher)
2292 : result_description_(result_description),
2293 callable_(callable),
2294 matcher_(MatcherCast<InnerType>(matcher)) {}
2296 void DescribeTo(::std::ostream* os)
const override {
2297 if (result_description_.empty()) {
2298 *os <<
"is mapped by the given callable to a value that ";
2300 *os <<
"whose " << result_description_ <<
" ";
2302 matcher_.DescribeTo(os);
2305 void DescribeNegationTo(::std::ostream* os)
const override {
2306 if (result_description_.empty()) {
2307 *os <<
"is mapped by the given callable to a value that ";
2309 *os <<
"whose " << result_description_ <<
" ";
2311 matcher_.DescribeNegationTo(os);
2314 bool MatchAndExplain(T obj, MatchResultListener* listener)
const override {
2315 if (result_description_.empty()) {
2316 *listener <<
"which is mapped by the given callable to ";
2318 *listener <<
"whose " << result_description_ <<
" is ";
2325 CallableTraits<Callable>::template Invoke<T>(callable_, obj);
2326 return MatchPrintAndExplain(result, matcher_, listener);
2330 const std::string result_description_;
2336 mutable CallableStorageType callable_;
2337 const Matcher<InnerType> matcher_;
2340 const std::string result_description_;
2341 const CallableStorageType callable_;
2342 const InnerMatcher matcher_;
2346 template <
typename SizeMatcher>
2347 class SizeIsMatcher {
2349 explicit SizeIsMatcher(
const SizeMatcher& size_matcher)
2350 : size_matcher_(size_matcher) {}
2352 template <
typename Container>
2353 operator Matcher<Container>()
const {
2354 return Matcher<Container>(
new Impl<const Container&>(size_matcher_));
2357 template <
typename Container>
2358 class Impl :
public MatcherInterface<Container> {
2360 using SizeType = decltype(std::declval<Container>().size());
2361 explicit Impl(
const SizeMatcher& size_matcher)
2362 : size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
2364 void DescribeTo(::std::ostream* os)
const override {
2365 *os <<
"has a size that ";
2366 size_matcher_.DescribeTo(os);
2368 void DescribeNegationTo(::std::ostream* os)
const override {
2369 *os <<
"has a size that ";
2370 size_matcher_.DescribeNegationTo(os);
2373 bool MatchAndExplain(Container
container,
2374 MatchResultListener* listener)
const override {
2375 SizeType size = container.size();
2376 StringMatchResultListener size_listener;
2377 const bool result = size_matcher_.MatchAndExplain(size, &size_listener);
2378 *listener <<
"whose size " << size
2379 << (result ?
" matches" :
" doesn't match");
2380 PrintIfNotEmpty(size_listener.str(), listener->stream());
2385 const Matcher<SizeType> size_matcher_;
2389 const SizeMatcher size_matcher_;
2394 template <
typename DistanceMatcher>
2395 class BeginEndDistanceIsMatcher {
2397 explicit BeginEndDistanceIsMatcher(
const DistanceMatcher& distance_matcher)
2398 : distance_matcher_(distance_matcher) {}
2400 template <
typename Container>
2401 operator Matcher<Container>()
const {
2402 return Matcher<Container>(
new Impl<const Container&>(distance_matcher_));
2405 template <
typename Container>
2406 class Impl :
public MatcherInterface<Container> {
2411 typedef typename std::iterator_traits<
2412 typename ContainerView::type::const_iterator>::difference_type
2414 explicit Impl(
const DistanceMatcher& distance_matcher)
2415 : distance_matcher_(MatcherCast<DistanceType>(distance_matcher)) {}
2417 void DescribeTo(::std::ostream* os)
const override {
2418 *os <<
"distance between begin() and end() ";
2419 distance_matcher_.DescribeTo(os);
2421 void DescribeNegationTo(::std::ostream* os)
const override {
2422 *os <<
"distance between begin() and end() ";
2423 distance_matcher_.DescribeNegationTo(os);
2426 bool MatchAndExplain(Container
container,
2427 MatchResultListener* listener)
const override {
2430 DistanceType distance = std::distance(begin(container), end(container));
2431 StringMatchResultListener distance_listener;
2433 distance_matcher_.MatchAndExplain(distance, &distance_listener);
2434 *listener <<
"whose distance between begin() and end() " << distance
2435 << (result ?
" matches" :
" doesn't match");
2436 PrintIfNotEmpty(distance_listener.str(), listener->stream());
2441 const Matcher<DistanceType> distance_matcher_;
2445 const DistanceMatcher distance_matcher_;
2458 template <
typename Container>
2459 class ContainerEqMatcher {
2461 typedef internal::StlContainerView<Container>
View;
2462 typedef typename View::type StlContainer;
2463 typedef typename View::const_reference StlContainerReference;
2466 "Container type must not be const");
2468 "Container type must not be a reference");
2472 explicit ContainerEqMatcher(
const Container&
expected)
2473 : expected_(View::Copy(expected)) {}
2475 void DescribeTo(::std::ostream* os)
const {
2479 void DescribeNegationTo(::std::ostream* os)
const {
2480 *os <<
"does not equal ";
2484 template <
typename LhsContainer>
2485 bool MatchAndExplain(
const LhsContainer& lhs,
2486 MatchResultListener* listener)
const {
2487 typedef internal::StlContainerView<
2488 typename std::remove_const<LhsContainer>::type>
2490 StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
2491 if (lhs_stl_container == expected_)
return true;
2493 ::std::ostream*
const os = listener->stream();
2494 if (os !=
nullptr) {
2496 bool printed_header =
false;
2497 for (
auto it = lhs_stl_container.begin(); it != lhs_stl_container.end();
2501 if (printed_header) {
2504 *os <<
"which has these unexpected elements: ";
2505 printed_header =
true;
2512 bool printed_header2 =
false;
2513 for (
auto it = expected_.begin(); it != expected_.end(); ++it) {
2515 lhs_stl_container.end(),
2516 *it) == lhs_stl_container.end()) {
2517 if (printed_header2) {
2520 *os << (printed_header ?
",\nand" :
"which")
2521 <<
" doesn't have these expected elements: ";
2522 printed_header2 =
true;
2533 const StlContainer expected_;
2537 struct LessComparator {
2538 template <
typename T,
typename U>
2539 bool operator()(
const T& lhs,
const U& rhs)
const {
2545 template <
typename Comparator,
typename ContainerMatcher>
2546 class WhenSortedByMatcher {
2548 WhenSortedByMatcher(
const Comparator& comparator,
2549 const ContainerMatcher& matcher)
2550 : comparator_(comparator), matcher_(matcher) {}
2552 template <
typename LhsContainer>
2553 operator Matcher<LhsContainer>()
const {
2554 return MakeMatcher(
new Impl<LhsContainer>(comparator_, matcher_));
2557 template <
typename LhsContainer>
2558 class Impl :
public MatcherInterface<LhsContainer> {
2563 typedef typename LhsView::type LhsStlContainer;
2564 typedef typename LhsView::const_reference LhsStlContainerReference;
2568 typename RemoveConstFromKey<typename LhsStlContainer::value_type>::type
2571 Impl(
const Comparator& comparator,
const ContainerMatcher& matcher)
2572 : comparator_(comparator), matcher_(matcher) {}
2574 void DescribeTo(::std::ostream* os)
const override {
2575 *os <<
"(when sorted) ";
2576 matcher_.DescribeTo(os);
2579 void DescribeNegationTo(::std::ostream* os)
const override {
2580 *os <<
"(when sorted) ";
2581 matcher_.DescribeNegationTo(os);
2584 bool MatchAndExplain(LhsContainer lhs,
2585 MatchResultListener* listener)
const override {
2586 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
2587 ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
2588 lhs_stl_container.end());
2589 ::std::sort(sorted_container.begin(), sorted_container.end(),
2592 if (!listener->IsInterested()) {
2595 return matcher_.Matches(sorted_container);
2598 *listener <<
"which is ";
2600 *listener <<
" when sorted";
2602 StringMatchResultListener inner_listener;
2604 matcher_.MatchAndExplain(sorted_container, &inner_listener);
2605 PrintIfNotEmpty(inner_listener.str(), listener->stream());
2610 const Comparator comparator_;
2611 const Matcher<const ::std::vector<LhsValue>&> matcher_;
2613 Impl(
const Impl&) =
delete;
2614 Impl& operator=(
const Impl&) =
delete;
2618 const Comparator comparator_;
2619 const ContainerMatcher matcher_;
2626 template <
typename TupleMatcher,
typename RhsContainer>
2627 class PointwiseMatcher {
2630 "use UnorderedPointwise with hash tables");
2633 typedef internal::StlContainerView<RhsContainer> RhsView;
2634 typedef typename RhsView::type RhsStlContainer;
2635 typedef typename RhsStlContainer::value_type RhsValue;
2638 "RhsContainer type must not be const");
2640 "RhsContainer type must not be a reference");
2644 PointwiseMatcher(
const TupleMatcher& tuple_matcher,
const RhsContainer& rhs)
2645 : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {}
2647 template <
typename LhsContainer>
2648 operator Matcher<LhsContainer>()
const {
2651 "use UnorderedPointwise with hash tables");
2653 return Matcher<LhsContainer>(
2654 new Impl<const LhsContainer&>(tuple_matcher_, rhs_));
2657 template <
typename LhsContainer>
2658 class Impl :
public MatcherInterface<LhsContainer> {
2663 typedef typename LhsView::type LhsStlContainer;
2664 typedef typename LhsView::const_reference LhsStlContainerReference;
2665 typedef typename LhsStlContainer::value_type LhsValue;
2670 typedef ::std::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg;
2672 Impl(
const TupleMatcher& tuple_matcher,
const RhsStlContainer& rhs)
2674 : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)),
2677 void DescribeTo(::std::ostream* os)
const override {
2678 *os <<
"contains " << rhs_.size()
2679 <<
" values, where each value and its corresponding value in ";
2682 mono_tuple_matcher_.DescribeTo(os);
2684 void DescribeNegationTo(::std::ostream* os)
const override {
2685 *os <<
"doesn't contain exactly " << rhs_.size()
2686 <<
" values, or contains a value x at some index i"
2687 <<
" where x and the i-th value of ";
2690 mono_tuple_matcher_.DescribeNegationTo(os);
2693 bool MatchAndExplain(LhsContainer lhs,
2694 MatchResultListener* listener)
const override {
2695 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
2696 const size_t actual_size = lhs_stl_container.size();
2697 if (actual_size != rhs_.size()) {
2698 *listener <<
"which contains " << actual_size <<
" values";
2702 auto left = lhs_stl_container.begin();
2703 auto right = rhs_.begin();
2704 for (
size_t i = 0;
i != actual_size; ++
i, ++left, ++right) {
2705 if (listener->IsInterested()) {
2706 StringMatchResultListener inner_listener;
2710 if (!mono_tuple_matcher_.MatchAndExplain(
2711 InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
2712 ImplicitCast_<const RhsValue&>(*right)),
2714 *listener <<
"where the value pair (";
2718 *listener <<
") at index #" <<
i <<
" don't match";
2719 PrintIfNotEmpty(inner_listener.str(), listener->stream());
2723 if (!mono_tuple_matcher_.Matches(
2724 InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
2725 ImplicitCast_<const RhsValue&>(*right))))
2734 const Matcher<InnerMatcherArg> mono_tuple_matcher_;
2735 const RhsStlContainer rhs_;
2739 const TupleMatcher tuple_matcher_;
2740 const RhsStlContainer rhs_;
2744 template <
typename Container>
2745 class QuantifierMatcherImpl :
public MatcherInterface<Container> {
2748 typedef StlContainerView<RawContainer>
View;
2749 typedef typename View::type StlContainer;
2750 typedef typename View::const_reference StlContainerReference;
2751 typedef typename StlContainer::value_type Element;
2753 template <
typename InnerMatcher>
2754 explicit QuantifierMatcherImpl(InnerMatcher inner_matcher)
2756 testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
2761 bool MatchAndExplainImpl(
bool all_elements_should_match, Container
container,
2762 MatchResultListener* listener)
const {
2763 StlContainerReference stl_container = View::ConstReference(container);
2765 for (
auto it = stl_container.begin(); it != stl_container.end();
2767 StringMatchResultListener inner_listener;
2768 const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener);
2770 if (matches != all_elements_should_match) {
2771 *listener <<
"whose element #" << i
2772 << (matches ?
" matches" :
" doesn't match");
2773 PrintIfNotEmpty(inner_listener.str(), listener->stream());
2774 return !all_elements_should_match;
2777 return all_elements_should_match;
2780 bool MatchAndExplainImpl(
const Matcher<size_t>& count_matcher,
2781 Container container,
2782 MatchResultListener* listener)
const {
2783 StlContainerReference stl_container = View::ConstReference(container);
2785 std::vector<size_t> match_elements;
2786 for (
auto it = stl_container.begin(); it != stl_container.end();
2788 StringMatchResultListener inner_listener;
2789 const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener);
2791 match_elements.push_back(i);
2794 if (listener->IsInterested()) {
2795 if (match_elements.empty()) {
2796 *listener <<
"has no element that matches";
2797 }
else if (match_elements.size() == 1) {
2798 *listener <<
"whose element #" << match_elements[0] <<
" matches";
2800 *listener <<
"whose elements (";
2801 std::string sep =
"";
2802 for (
size_t e : match_elements) {
2803 *listener << sep << e;
2806 *listener <<
") match";
2809 StringMatchResultListener count_listener;
2810 if (count_matcher.MatchAndExplain(match_elements.size(), &count_listener)) {
2811 *listener <<
" and whose match quantity of " << match_elements.size()
2813 PrintIfNotEmpty(count_listener.str(), listener->stream());
2816 if (match_elements.empty()) {
2817 *listener <<
" and";
2819 *listener <<
" but";
2821 *listener <<
" whose match quantity of " << match_elements.size()
2822 <<
" does not match";
2823 PrintIfNotEmpty(count_listener.str(), listener->stream());
2829 const Matcher<const Element&> inner_matcher_;
2834 template <
typename Container>
2835 class ContainsMatcherImpl :
public QuantifierMatcherImpl<Container> {
2837 template <
typename InnerMatcher>
2838 explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
2839 : QuantifierMatcherImpl<Container>(inner_matcher) {}
2842 void DescribeTo(::std::ostream* os)
const override {
2843 *os <<
"contains at least one element that ";
2844 this->inner_matcher_.DescribeTo(os);
2847 void DescribeNegationTo(::std::ostream* os)
const override {
2848 *os <<
"doesn't contain any element that ";
2849 this->inner_matcher_.DescribeTo(os);
2852 bool MatchAndExplain(Container
container,
2853 MatchResultListener* listener)
const override {
2854 return this->MatchAndExplainImpl(
false, container, listener);
2860 template <
typename Container>
2861 class EachMatcherImpl :
public QuantifierMatcherImpl<Container> {
2863 template <
typename InnerMatcher>
2864 explicit EachMatcherImpl(InnerMatcher inner_matcher)
2865 : QuantifierMatcherImpl<Container>(inner_matcher) {}
2868 void DescribeTo(::std::ostream* os)
const override {
2869 *os <<
"only contains elements that ";
2870 this->inner_matcher_.DescribeTo(os);
2873 void DescribeNegationTo(::std::ostream* os)
const override {
2874 *os <<
"contains some element that ";
2875 this->inner_matcher_.DescribeNegationTo(os);
2878 bool MatchAndExplain(Container
container,
2879 MatchResultListener* listener)
const override {
2880 return this->MatchAndExplainImpl(
true, container, listener);
2886 template <
typename Container>
2887 class ContainsTimesMatcherImpl :
public QuantifierMatcherImpl<Container> {
2889 template <
typename InnerMatcher>
2890 explicit ContainsTimesMatcherImpl(InnerMatcher inner_matcher,
2891 Matcher<size_t> count_matcher)
2892 : QuantifierMatcherImpl<Container>(inner_matcher),
2893 count_matcher_(std::move(count_matcher)) {}
2895 void DescribeTo(::std::ostream* os)
const override {
2896 *os <<
"quantity of elements that match ";
2897 this->inner_matcher_.DescribeTo(os);
2899 count_matcher_.DescribeTo(os);
2902 void DescribeNegationTo(::std::ostream* os)
const override {
2903 *os <<
"quantity of elements that match ";
2904 this->inner_matcher_.DescribeTo(os);
2906 count_matcher_.DescribeNegationTo(os);
2909 bool MatchAndExplain(Container
container,
2910 MatchResultListener* listener)
const override {
2911 return this->MatchAndExplainImpl(count_matcher_, container, listener);
2915 const Matcher<size_t> count_matcher_;
2919 template <
typename M>
2920 class ContainsTimesMatcher {
2922 explicit ContainsTimesMatcher(M m, Matcher<size_t> count_matcher)
2923 : inner_matcher_(m), count_matcher_(std::move(count_matcher)) {}
2925 template <
typename Container>
2926 operator Matcher<Container>()
const {
2927 return Matcher<Container>(
new ContainsTimesMatcherImpl<const Container&>(
2928 inner_matcher_, count_matcher_));
2932 const M inner_matcher_;
2933 const Matcher<size_t> count_matcher_;
2937 template <
typename M>
2938 class ContainsMatcher {
2940 explicit ContainsMatcher(M m) : inner_matcher_(m) {}
2942 template <
typename Container>
2943 operator Matcher<Container>()
const {
2944 return Matcher<Container>(
2945 new ContainsMatcherImpl<const Container&>(inner_matcher_));
2948 ContainsTimesMatcher<M> Times(Matcher<size_t> count_matcher)
const {
2949 return ContainsTimesMatcher<M>(inner_matcher_, std::move(count_matcher));
2953 const M inner_matcher_;
2957 template <
typename M>
2960 explicit EachMatcher(M m) : inner_matcher_(m) {}
2962 template <
typename Container>
2963 operator Matcher<Container>()
const {
2964 return Matcher<Container>(
2965 new EachMatcherImpl<const Container&>(inner_matcher_));
2969 const M inner_matcher_;
2972 namespace pair_getters {
2974 template <
typename T>
2975 auto First(T&
x, Rank0) -> decltype(get<0>(x)) {
2978 template <
typename T>
2979 auto First(T& x, Rank1) -> decltype((x.first)) {
2983 template <
typename T>
2984 auto Second(T& x, Rank0) -> decltype(get<1>(x)) {
2987 template <
typename T>
2988 auto Second(T& x, Rank1) -> decltype((x.second)) {
2997 template <
typename PairType>
2998 class KeyMatcherImpl :
public MatcherInterface<PairType> {
3001 typedef typename RawPairType::first_type KeyType;
3003 template <
typename InnerMatcher>
3004 explicit KeyMatcherImpl(InnerMatcher inner_matcher)
3006 testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {}
3010 bool MatchAndExplain(PairType key_value,
3011 MatchResultListener* listener)
const override {
3012 StringMatchResultListener inner_listener;
3013 const bool match = inner_matcher_.MatchAndExplain(
3014 pair_getters::First(key_value, Rank1()), &inner_listener);
3015 const std::string explanation = inner_listener.str();
3016 if (!explanation.empty()) {
3017 *listener <<
"whose first field is a value " << explanation;
3023 void DescribeTo(::std::ostream* os)
const override {
3024 *os <<
"has a key that ";
3025 inner_matcher_.DescribeTo(os);
3029 void DescribeNegationTo(::std::ostream* os)
const override {
3030 *os <<
"doesn't have a key that ";
3031 inner_matcher_.DescribeTo(os);
3035 const Matcher<const KeyType&> inner_matcher_;
3039 template <
typename M>
3042 explicit KeyMatcher(M m) : matcher_for_key_(m) {}
3044 template <
typename PairType>
3045 operator Matcher<PairType>()
const {
3046 return Matcher<PairType>(
3047 new KeyMatcherImpl<const PairType&>(matcher_for_key_));
3051 const M matcher_for_key_;
3055 template <
typename InnerMatcher>
3056 class AddressMatcher {
3058 explicit AddressMatcher(InnerMatcher m) : matcher_(m) {}
3060 template <
typename Type>
3061 operator Matcher<Type>()
const {
3062 return Matcher<Type>(
new Impl<const Type&>(matcher_));
3067 template <
typename Type>
3068 class Impl :
public MatcherInterface<Type> {
3071 explicit Impl(
const InnerMatcher& matcher)
3072 : matcher_(MatcherCast<Address>(matcher)) {}
3074 void DescribeTo(::std::ostream* os)
const override {
3075 *os <<
"has address that ";
3076 matcher_.DescribeTo(os);
3079 void DescribeNegationTo(::std::ostream* os)
const override {
3080 *os <<
"does not have address that ";
3081 matcher_.DescribeTo(os);
3084 bool MatchAndExplain(Type
object,
3085 MatchResultListener* listener)
const override {
3086 *listener <<
"which has address ";
3087 Address address = std::addressof(
object);
3088 return MatchPrintAndExplain(address, matcher_, listener);
3092 const Matcher<Address> matcher_;
3094 const InnerMatcher matcher_;
3099 template <
typename PairType>
3100 class PairMatcherImpl :
public MatcherInterface<PairType> {
3103 typedef typename RawPairType::first_type FirstType;
3104 typedef typename RawPairType::second_type SecondType;
3106 template <
typename FirstMatcher,
typename SecondMatcher>
3107 PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
3109 testing::SafeMatcherCast<const FirstType&>(first_matcher)),
3111 testing::SafeMatcherCast<const SecondType&>(second_matcher)) {}
3114 void DescribeTo(::std::ostream* os)
const override {
3115 *os <<
"has a first field that ";
3116 first_matcher_.DescribeTo(os);
3117 *os <<
", and has a second field that ";
3118 second_matcher_.DescribeTo(os);
3122 void DescribeNegationTo(::std::ostream* os)
const override {
3123 *os <<
"has a first field that ";
3124 first_matcher_.DescribeNegationTo(os);
3125 *os <<
", or has a second field that ";
3126 second_matcher_.DescribeNegationTo(os);
3131 bool MatchAndExplain(PairType a_pair,
3132 MatchResultListener* listener)
const override {
3133 if (!listener->IsInterested()) {
3136 return first_matcher_.Matches(pair_getters::First(a_pair, Rank1())) &&
3137 second_matcher_.Matches(pair_getters::Second(a_pair, Rank1()));
3139 StringMatchResultListener first_inner_listener;
3140 if (!first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank1()),
3141 &first_inner_listener)) {
3142 *listener <<
"whose first field does not match";
3143 PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
3146 StringMatchResultListener second_inner_listener;
3147 if (!second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank1()),
3148 &second_inner_listener)) {
3149 *listener <<
"whose second field does not match";
3150 PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
3153 ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
3159 void ExplainSuccess(
const std::string& first_explanation,
3160 const std::string& second_explanation,
3161 MatchResultListener* listener)
const {
3162 *listener <<
"whose both fields match";
3163 if (!first_explanation.empty()) {
3164 *listener <<
", where the first field is a value " << first_explanation;
3166 if (!second_explanation.empty()) {
3168 if (!first_explanation.empty()) {
3169 *listener <<
"and ";
3171 *listener <<
"where ";
3173 *listener <<
"the second field is a value " << second_explanation;
3177 const Matcher<const FirstType&> first_matcher_;
3178 const Matcher<const SecondType&> second_matcher_;
3182 template <
typename FirstMatcher,
typename SecondMatcher>
3185 PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
3186 : first_matcher_(first_matcher), second_matcher_(second_matcher) {}
3188 template <
typename PairType>
3189 operator Matcher<PairType>()
const {
3190 return Matcher<PairType>(
3191 new PairMatcherImpl<const PairType&>(first_matcher_, second_matcher_));
3195 const FirstMatcher first_matcher_;
3196 const SecondMatcher second_matcher_;
3199 template <
typename T,
size_t... I>
3200 auto UnpackStructImpl(
const T& t, std::index_sequence<I...>,
3201 int) -> decltype(std::tie(get<I>(t)...)) {
3203 "Number of arguments doesn't match the number of fields.");
3204 return std::tie(get<I>(t)...);
3207 #if defined(__cpp_structured_bindings) && __cpp_structured_bindings >= 201606
3208 template <
typename T>
3209 auto UnpackStructImpl(
const T& t, std::make_index_sequence<1>,
char) {
3210 const auto& [
a] = t;
3213 template <
typename T>
3214 auto UnpackStructImpl(
const T& t, std::make_index_sequence<2>,
char) {
3215 const auto& [
a, b] = t;
3216 return std::tie(
a, b);
3218 template <
typename T>
3219 auto UnpackStructImpl(
const T& t, std::make_index_sequence<3>,
char) {
3220 const auto& [
a, b,
c] = t;
3221 return std::tie(
a, b,
c);
3223 template <
typename T>
3224 auto UnpackStructImpl(
const T& t, std::make_index_sequence<4>,
char) {
3225 const auto& [
a, b,
c, d] = t;
3226 return std::tie(
a, b, c, d);
3228 template <
typename T>
3229 auto UnpackStructImpl(
const T& t, std::make_index_sequence<5>,
char) {
3230 const auto& [
a, b,
c, d, e] = t;
3231 return std::tie(
a, b, c, d, e);
3233 template <
typename T>
3234 auto UnpackStructImpl(
const T& t, std::make_index_sequence<6>,
char) {
3235 const auto& [
a, b,
c, d, e, f] = t;
3236 return std::tie(
a, b, c, d, e, f);
3238 template <
typename T>
3239 auto UnpackStructImpl(
const T& t, std::make_index_sequence<7>,
char) {
3240 const auto& [
a, b,
c, d, e, f,
g] = t;
3241 return std::tie(
a, b, c, d, e, f,
g);
3243 template <
typename T>
3244 auto UnpackStructImpl(
const T& t, std::make_index_sequence<8>,
char) {
3245 const auto& [
a, b,
c, d, e, f,
g, h] = t;
3246 return std::tie(
a, b, c, d, e, f, g, h);
3248 template <
typename T>
3249 auto UnpackStructImpl(
const T& t, std::make_index_sequence<9>,
char) {
3250 const auto& [
a, b,
c, d, e, f,
g, h,
i] = t;
3251 return std::tie(
a, b, c, d, e, f, g, h,
i);
3253 template <
typename T>
3254 auto UnpackStructImpl(
const T& t, std::make_index_sequence<10>,
char) {
3255 const auto& [
a, b,
c, d, e, f,
g, h,
i, j] = t;
3256 return std::tie(
a, b, c, d, e, f, g, h, i, j);
3258 template <
typename T>
3259 auto UnpackStructImpl(
const T& t, std::make_index_sequence<11>,
char) {
3260 const auto& [
a, b,
c, d, e, f,
g, h,
i, j, k] = t;
3261 return std::tie(
a, b, c, d, e, f, g, h, i, j, k);
3263 template <
typename T>
3264 auto UnpackStructImpl(
const T& t, std::make_index_sequence<12>,
char) {
3265 const auto& [
a, b,
c, d, e, f,
g, h,
i, j, k, l] = t;
3266 return std::tie(
a, b, c, d, e, f, g, h, i, j, k, l);
3268 template <
typename T>
3269 auto UnpackStructImpl(
const T& t, std::make_index_sequence<13>,
char) {
3270 const auto& [
a, b,
c, d, e, f,
g, h,
i, j, k, l, m] = t;
3271 return std::tie(
a, b, c, d, e, f, g, h, i, j, k, l, m);
3273 template <
typename T>
3274 auto UnpackStructImpl(
const T& t, std::make_index_sequence<14>,
char) {
3275 const auto& [
a, b,
c, d, e, f,
g, h,
i, j, k, l, m,
n] = t;
3276 return std::tie(
a, b, c, d, e, f, g, h, i, j, k, l, m,
n);
3278 template <
typename T>
3279 auto UnpackStructImpl(
const T& t, std::make_index_sequence<15>,
char) {
3280 const auto& [
a, b,
c, d, e, f,
g, h,
i, j, k, l, m,
n, o] = t;
3281 return std::tie(
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
3283 template <
typename T>
3284 auto UnpackStructImpl(
const T& t, std::make_index_sequence<16>,
char) {
3285 const auto& [
a, b,
c, d, e, f,
g, h,
i, j, k, l, m,
n, o,
p] = t;
3286 return std::tie(
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o,
p);
3288 template <
typename T>
3289 auto UnpackStructImpl(
const T& t, std::make_index_sequence<17>,
char) {
3290 const auto& [
a, b,
c, d, e, f,
g, h,
i, j, k, l, m,
n, o,
p, q] = t;
3291 return std::tie(
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q);
3293 template <
typename T>
3294 auto UnpackStructImpl(
const T& t, std::make_index_sequence<18>,
char) {
3295 const auto& [
a, b,
c, d, e, f,
g, h,
i, j, k, l, m,
n, o,
p, q, r] = t;
3296 return std::tie(
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r);
3298 template <
typename T>
3299 auto UnpackStructImpl(
const T& t, std::make_index_sequence<19>,
char) {
3300 const auto& [
a, b,
c, d, e, f,
g, h,
i, j, k, l, m,
n, o,
p, q, r, s] = t;
3301 return std::tie(
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s);
3303 template <
typename T>
3304 auto UnpackStructImpl(
const T& u, std::make_index_sequence<20>,
char) {
3305 const auto& [
a, b,
c, d, e, f,
g, h,
i, j, k, l, m,
n, o,
p, q, r, s, t] = u;
3306 return std::tie(
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t);
3308 #endif // defined(__cpp_structured_bindings)
3310 template <
size_t I,
typename T>
3311 auto UnpackStruct(
const T& t)
3312 -> decltype((UnpackStructImpl)(t, std::make_index_sequence<I>{}, 0)) {
3313 return (UnpackStructImpl)(t, std::make_index_sequence<I>{}, 0);
3319 template <
typename T,
size_t N>
3320 void VariadicExpand(
const T (&)[
N]) {}
3322 template <
typename Struct,
typename StructSize>
3323 class FieldsAreMatcherImpl;
3325 template <
typename Struct,
size_t... I>
3326 class FieldsAreMatcherImpl<Struct, std::index_sequence<I...>>
3327 :
public MatcherInterface<Struct> {
3328 using UnpackedType =
3329 decltype(UnpackStruct<
sizeof...(I)>(std::declval<const Struct&>()));
3330 using MatchersType = std::tuple<
3331 Matcher<const typename std::tuple_element<I, UnpackedType>::type&>...>;
3334 template <
typename Inner>
3335 explicit FieldsAreMatcherImpl(
const Inner& matchers)
3336 : matchers_(testing::SafeMatcherCast<
3337 const typename std::tuple_element<I, UnpackedType>::type&>(
3338 std::get<I>(matchers))...) {}
3340 void DescribeTo(::std::ostream* os)
const override {
3341 const char* separator =
"";
3343 {(*os << separator <<
"has field #" << I <<
" that ",
3344 std::get<I>(matchers_).DescribeTo(os), separator =
", and ")...});
3347 void DescribeNegationTo(::std::ostream* os)
const override {
3348 const char* separator =
"";
3349 VariadicExpand({(*os << separator <<
"has field #" << I <<
" that ",
3350 std::get<I>(matchers_).DescribeNegationTo(os),
3351 separator =
", or ")...});
3354 bool MatchAndExplain(Struct t, MatchResultListener* listener)
const override {
3355 return MatchInternal((UnpackStruct<
sizeof...(I)>)(t), listener);
3359 bool MatchInternal(UnpackedType tuple, MatchResultListener* listener)
const {
3360 if (!listener->IsInterested()) {
3364 VariadicExpand({good = good && std::get<I>(matchers_).Matches(
3365 std::get<I>(tuple))...});
3369 size_t failed_pos = ~size_t{};
3371 std::vector<StringMatchResultListener> inner_listener(
sizeof...(I));
3374 {failed_pos == ~size_t{} && !std::get<I>(matchers_).MatchAndExplain(
3375 std::get<I>(tuple), &inner_listener[I])
3378 if (failed_pos != ~
size_t{}) {
3379 *listener <<
"whose field #" << failed_pos <<
" does not match";
3380 PrintIfNotEmpty(inner_listener[failed_pos].str(), listener->stream());
3384 *listener <<
"whose all elements match";
3385 const char* separator =
", where";
3386 for (
size_t index = 0; index <
sizeof...(I); ++index) {
3387 const std::string str = inner_listener[index].str();
3389 *listener << separator <<
" field #" << index <<
" is a value " << str;
3390 separator =
", and";
3397 MatchersType matchers_;
3400 template <
typename... Inner>
3401 class FieldsAreMatcher {
3403 explicit FieldsAreMatcher(Inner... inner) : matchers_(std::move(inner)...) {}
3405 template <
typename Struct>
3406 operator Matcher<Struct>()
const {
3407 return Matcher<Struct>(
3408 new FieldsAreMatcherImpl<
const Struct&,
3409 std::index_sequence_for<Inner...>>(matchers_));
3413 std::tuple<Inner...> matchers_;
3417 template <
typename Container>
3418 class ElementsAreMatcherImpl :
public MatcherInterface<Container> {
3421 typedef internal::StlContainerView<RawContainer>
View;
3422 typedef typename View::type StlContainer;
3423 typedef typename View::const_reference StlContainerReference;
3424 typedef typename StlContainer::value_type Element;
3428 template <
typename InputIter>
3429 ElementsAreMatcherImpl(InputIter first, InputIter last) {
3430 while (first != last) {
3431 matchers_.push_back(MatcherCast<const Element&>(*first++));
3436 void DescribeTo(::std::ostream* os)
const override {
3439 }
else if (
count() == 1) {
3440 *os <<
"has 1 element that ";
3441 matchers_[0].DescribeTo(os);
3443 *os <<
"has " << Elements(
count()) <<
" where\n";
3444 for (
size_t i = 0;
i !=
count(); ++
i) {
3445 *os <<
"element #" <<
i <<
" ";
3446 matchers_[
i].DescribeTo(os);
3447 if (i + 1 <
count()) {
3455 void DescribeNegationTo(::std::ostream* os)
const override {
3457 *os <<
"isn't empty";
3461 *os <<
"doesn't have " << Elements(
count()) <<
", or\n";
3462 for (
size_t i = 0;
i !=
count(); ++
i) {
3463 *os <<
"element #" <<
i <<
" ";
3464 matchers_[
i].DescribeNegationTo(os);
3465 if (i + 1 <
count()) {
3471 bool MatchAndExplain(Container
container,
3472 MatchResultListener* listener)
const override {
3476 const bool listener_interested = listener->IsInterested();
3479 ::std::vector<std::string> explanations(
count());
3480 StlContainerReference stl_container = View::ConstReference(container);
3481 auto it = stl_container.begin();
3482 size_t exam_pos = 0;
3483 bool mismatch_found =
false;
3488 for (; it != stl_container.end() && exam_pos !=
count(); ++it, ++exam_pos) {
3490 if (listener_interested) {
3491 StringMatchResultListener s;
3492 match = matchers_[exam_pos].MatchAndExplain(*it, &s);
3493 explanations[exam_pos] = s.str();
3495 match = matchers_[exam_pos].Matches(*it);
3499 mismatch_found =
true;
3508 size_t actual_count = exam_pos;
3509 for (; it != stl_container.end(); ++it) {
3513 if (actual_count !=
count()) {
3518 if (listener_interested && (actual_count != 0)) {
3519 *listener <<
"which has " << Elements(actual_count);
3524 if (mismatch_found) {
3526 if (listener_interested) {
3527 *listener <<
"whose element #" << exam_pos <<
" doesn't match";
3528 PrintIfNotEmpty(explanations[exam_pos], listener->stream());
3535 if (listener_interested) {
3536 bool reason_printed =
false;
3537 for (
size_t i = 0;
i !=
count(); ++
i) {
3538 const std::string& s = explanations[
i];
3540 if (reason_printed) {
3541 *listener <<
",\nand ";
3543 *listener <<
"whose element #" <<
i <<
" matches, " << s;
3544 reason_printed =
true;
3552 static Message Elements(
size_t count) {
3553 return Message() << count << (count == 1 ?
" element" :
" elements");
3556 size_t count()
const {
return matchers_.size(); }
3558 ::std::vector<Matcher<const Element&>> matchers_;
3567 MatchMatrix(
size_t num_elements,
size_t num_matchers)
3568 : num_elements_(num_elements),
3569 num_matchers_(num_matchers),
3570 matched_(num_elements_ * num_matchers_, 0) {}
3572 size_t LhsSize()
const {
return num_elements_; }
3573 size_t RhsSize()
const {
return num_matchers_; }
3574 bool HasEdge(
size_t ilhs,
size_t irhs)
const {
3575 return matched_[SpaceIndex(ilhs, irhs)] == 1;
3577 void SetEdge(
size_t ilhs,
size_t irhs,
bool b) {
3578 matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0;
3588 std::string DebugString()
const;
3591 size_t SpaceIndex(
size_t ilhs,
size_t irhs)
const {
3592 return ilhs * num_matchers_ + irhs;
3595 size_t num_elements_;
3596 size_t num_matchers_;
3601 ::std::vector<char> matched_;
3604 typedef ::std::pair<size_t, size_t> ElementMatcherPair;
3605 typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs;
3611 struct UnorderedMatcherRequire {
3615 ExactMatch = Superset | Subset,
3622 class GTEST_API_ UnorderedElementsAreMatcherImplBase {
3624 explicit UnorderedElementsAreMatcherImplBase(
3625 UnorderedMatcherRequire::Flags matcher_flags)
3626 : match_flags_(matcher_flags) {}
3631 typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec;
3634 void DescribeToImpl(::std::ostream* os)
const;
3637 void DescribeNegationToImpl(::std::ostream* os)
const;
3639 bool VerifyMatchMatrix(const ::std::vector<std::string>& element_printouts,
3640 const MatchMatrix& matrix,
3641 MatchResultListener* listener)
const;
3643 bool FindPairing(
const MatchMatrix& matrix,
3644 MatchResultListener* listener)
const;
3646 MatcherDescriberVec& matcher_describers() {
return matcher_describers_; }
3648 static Message Elements(
size_t n) {
3649 return Message() << n <<
" element" << (n == 1 ?
"" :
"s");
3652 UnorderedMatcherRequire::Flags match_flags()
const {
return match_flags_; }
3655 UnorderedMatcherRequire::Flags match_flags_;
3656 MatcherDescriberVec matcher_describers_;
3661 template <
typename Container>
3662 class UnorderedElementsAreMatcherImpl
3663 :
public MatcherInterface<Container>,
3664 public UnorderedElementsAreMatcherImplBase {
3667 typedef internal::StlContainerView<RawContainer>
View;
3668 typedef typename View::type StlContainer;
3669 typedef typename View::const_reference StlContainerReference;
3670 typedef typename StlContainer::value_type Element;
3672 template <
typename InputIter>
3673 UnorderedElementsAreMatcherImpl(UnorderedMatcherRequire::Flags matcher_flags,
3674 InputIter first, InputIter last)
3675 : UnorderedElementsAreMatcherImplBase(matcher_flags) {
3676 for (; first != last; ++first) {
3677 matchers_.push_back(MatcherCast<const Element&>(*first));
3679 for (
const auto& m : matchers_) {
3680 matcher_describers().push_back(m.GetDescriber());
3685 void DescribeTo(::std::ostream* os)
const override {
3686 return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os);
3690 void DescribeNegationTo(::std::ostream* os)
const override {
3691 return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os);
3694 bool MatchAndExplain(Container
container,
3695 MatchResultListener* listener)
const override {
3696 StlContainerReference stl_container = View::ConstReference(container);
3697 ::std::vector<std::string> element_printouts;
3698 MatchMatrix matrix =
3699 AnalyzeElements(stl_container.begin(), stl_container.end(),
3700 &element_printouts, listener);
3702 return VerifyMatchMatrix(element_printouts, matrix, listener) &&
3703 FindPairing(matrix, listener);
3707 template <
typename ElementIter>
3708 MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
3709 ::std::vector<std::string>* element_printouts,
3710 MatchResultListener* listener)
const {
3711 element_printouts->clear();
3712 ::std::vector<char> did_match;
3713 size_t num_elements = 0;
3714 DummyMatchResultListener dummy;
3715 for (; elem_first != elem_last; ++num_elements, ++elem_first) {
3716 if (listener->IsInterested()) {
3719 for (
size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
3720 did_match.push_back(
3721 matchers_[irhs].MatchAndExplain(*elem_first, &dummy));
3725 MatchMatrix matrix(num_elements, matchers_.size());
3726 ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
3727 for (
size_t ilhs = 0; ilhs != num_elements; ++ilhs) {
3728 for (
size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
3729 matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
3735 ::std::vector<Matcher<const Element&>> matchers_;
3740 template <
typename Target>
3741 struct CastAndAppendTransform {
3742 template <
typename Arg>
3743 Matcher<Target> operator()(
const Arg&
a)
const {
3744 return MatcherCast<Target>(
a);
3749 template <
typename MatcherTuple>
3750 class UnorderedElementsAreMatcher {
3752 explicit UnorderedElementsAreMatcher(
const MatcherTuple& args)
3753 : matchers_(args) {}
3755 template <
typename Container>
3756 operator Matcher<Container>()
const {
3758 typedef typename internal::StlContainerView<RawContainer>::type
View;
3759 typedef typename View::value_type Element;
3760 typedef ::std::vector<Matcher<const Element&>> MatcherVec;
3761 MatcherVec matchers;
3763 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
3764 ::std::back_inserter(matchers));
3765 return Matcher<Container>(
3766 new UnorderedElementsAreMatcherImpl<const Container&>(
3767 UnorderedMatcherRequire::ExactMatch, matchers.begin(),
3772 const MatcherTuple matchers_;
3776 template <
typename MatcherTuple>
3777 class ElementsAreMatcher {
3779 explicit ElementsAreMatcher(
const MatcherTuple& args) : matchers_(args) {}
3781 template <
typename Container>
3782 operator Matcher<Container>()
const {
3786 "use UnorderedElementsAre with hash tables");
3789 typedef typename internal::StlContainerView<RawContainer>::type
View;
3790 typedef typename View::value_type Element;
3791 typedef ::std::vector<Matcher<const Element&>> MatcherVec;
3792 MatcherVec matchers;
3794 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
3795 ::std::back_inserter(matchers));
3796 return Matcher<Container>(
new ElementsAreMatcherImpl<const Container&>(
3797 matchers.begin(), matchers.end()));
3801 const MatcherTuple matchers_;
3805 template <
typename T>
3806 class UnorderedElementsAreArrayMatcher {
3808 template <
typename Iter>
3809 UnorderedElementsAreArrayMatcher(UnorderedMatcherRequire::Flags match_flags,
3810 Iter first, Iter last)
3811 : match_flags_(match_flags), matchers_(first, last) {}
3813 template <
typename Container>
3814 operator Matcher<Container>()
const {
3815 return Matcher<Container>(
3816 new UnorderedElementsAreMatcherImpl<const Container&>(
3817 match_flags_, matchers_.begin(), matchers_.end()));
3821 UnorderedMatcherRequire::Flags match_flags_;
3822 std::vector<std::remove_const_t<T>> matchers_;
3826 template <
typename T>
3827 class ElementsAreArrayMatcher {
3829 template <
typename Iter>
3830 ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
3832 template <
typename Container>
3833 operator Matcher<Container>()
const {
3836 "use UnorderedElementsAreArray with hash tables");
3838 return Matcher<Container>(
new ElementsAreMatcherImpl<const Container&>(
3839 matchers_.begin(), matchers_.end()));
3843 const std::vector<std::remove_const_t<T>> matchers_;
3855 template <
typename Tuple2Matcher,
typename Second>
3856 class BoundSecondMatcher {
3858 BoundSecondMatcher(
const Tuple2Matcher& tm,
const Second& second)
3859 : tuple2_matcher_(tm), second_value_(second) {}
3861 BoundSecondMatcher(
const BoundSecondMatcher& other) =
default;
3863 template <
typename T>
3864 operator Matcher<T>()
const {
3865 return MakeMatcher(
new Impl<T>(tuple2_matcher_, second_value_));
3876 void operator=(
const BoundSecondMatcher& ) {
3877 GTEST_LOG_(FATAL) <<
"BoundSecondMatcher should never be assigned.";
3881 template <
typename T>
3882 class Impl :
public MatcherInterface<T> {
3884 typedef ::std::tuple<T, Second> ArgTuple;
3886 Impl(
const Tuple2Matcher& tm,
const Second& second)
3887 : mono_tuple2_matcher_(SafeMatcherCast<const ArgTuple&>(tm)),
3888 second_value_(second) {}
3890 void DescribeTo(::std::ostream* os)
const override {
3894 mono_tuple2_matcher_.DescribeTo(os);
3897 bool MatchAndExplain(T
x, MatchResultListener* listener)
const override {
3898 return mono_tuple2_matcher_.MatchAndExplain(ArgTuple(x, second_value_),
3903 const Matcher<const ArgTuple&> mono_tuple2_matcher_;
3904 const Second second_value_;
3907 const Tuple2Matcher tuple2_matcher_;
3908 const Second second_value_;
3915 template <
typename Tuple2Matcher,
typename Second>
3916 BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond(
3917 const Tuple2Matcher& tm,
const Second& second) {
3918 return BoundSecondMatcher<Tuple2Matcher, Second>(tm, second);
3927 bool negation,
const char* matcher_name,
3928 const std::vector<const char*>& param_names,
const Strings& param_values);
3932 template <
typename Optional>
3933 auto IsOptionalEngaged(
const Optional& optional,
3934 Rank1) -> decltype(!!optional) {
3937 return !
static_cast<bool>(!optional);
3939 template <
typename Optional>
3940 auto IsOptionalEngaged(
const Optional& optional,
3941 Rank0) -> decltype(!optional.has_value()) {
3942 return optional.has_value();
3946 template <
typename ValueMatcher>
3947 class OptionalMatcher {
3949 explicit OptionalMatcher(
const ValueMatcher& value_matcher)
3950 : value_matcher_(value_matcher) {}
3952 template <
typename Optional>
3953 operator Matcher<Optional>()
const {
3954 return Matcher<Optional>(
new Impl<const Optional&>(value_matcher_));
3957 template <
typename Optional>
3958 class Impl :
public MatcherInterface<Optional> {
3961 typedef typename OptionalView::value_type ValueType;
3962 explicit Impl(
const ValueMatcher& value_matcher)
3963 : value_matcher_(MatcherCast<ValueType>(value_matcher)) {}
3965 void DescribeTo(::std::ostream* os)
const override {
3967 value_matcher_.DescribeTo(os);
3970 void DescribeNegationTo(::std::ostream* os)
const override {
3972 value_matcher_.DescribeNegationTo(os);
3975 bool MatchAndExplain(Optional optional,
3976 MatchResultListener* listener)
const override {
3977 if (!IsOptionalEngaged(optional, HighestRank())) {
3978 *listener <<
"which is not engaged";
3981 const ValueType& value = *optional;
3982 StringMatchResultListener value_listener;
3983 const bool match = value_matcher_.MatchAndExplain(value, &value_listener);
3985 << (match ?
" matches" :
" doesn't match");
3986 PrintIfNotEmpty(value_listener.str(), listener->stream());
3991 const Matcher<ValueType> value_matcher_;
3995 const ValueMatcher value_matcher_;
3998 namespace variant_matcher {
4000 template <
typename T>
4001 void holds_alternative() {}
4002 template <
typename T>
4006 template <
typename T>
4007 class VariantMatcher {
4010 : matcher_(std::move(matcher)) {}
4012 template <
typename Variant>
4013 bool MatchAndExplain(
const Variant& value,
4014 ::testing::MatchResultListener* listener)
const {
4016 if (!listener->IsInterested()) {
4017 return holds_alternative<T>(
value) && matcher_.Matches(get<T>(value));
4020 if (!holds_alternative<T>(value)) {
4021 *listener <<
"whose value is not of type '" <<
GetTypeName() <<
"'";
4025 const T& elem = get<T>(
value);
4026 StringMatchResultListener elem_listener;
4027 const bool match = matcher_.MatchAndExplain(elem, &elem_listener);
4029 << (match ?
" matches" :
" doesn't match");
4030 PrintIfNotEmpty(elem_listener.str(), listener->stream());
4034 void DescribeTo(std::ostream* os)
const {
4035 *os <<
"is a variant<> with value of type '" <<
GetTypeName()
4036 <<
"' and the value ";
4037 matcher_.DescribeTo(os);
4040 void DescribeNegationTo(std::ostream* os)
const {
4041 *os <<
"is a variant<> with value of type other than '" <<
GetTypeName()
4042 <<
"' or the value ";
4043 matcher_.DescribeNegationTo(os);
4050 return internal::GetTypeName<T>());
4052 return "the element type";
4055 const ::testing::Matcher<const T&> matcher_;
4060 namespace any_cast_matcher {
4063 template <
typename T>
4067 template <
typename T>
4068 class AnyCastMatcher {
4070 explicit AnyCastMatcher(const ::testing::Matcher<const T&>& matcher)
4071 : matcher_(matcher) {}
4073 template <
typename AnyType>
4074 bool MatchAndExplain(
const AnyType& value,
4075 ::testing::MatchResultListener* listener)
const {
4076 if (!listener->IsInterested()) {
4077 const T* ptr = any_cast<T>(&
value);
4078 return ptr !=
nullptr && matcher_.Matches(*ptr);
4081 const T* elem = any_cast<T>(&
value);
4082 if (elem ==
nullptr) {
4083 *listener <<
"whose value is not of type '" <<
GetTypeName() <<
"'";
4087 StringMatchResultListener elem_listener;
4088 const bool match = matcher_.MatchAndExplain(*elem, &elem_listener);
4090 << (match ?
" matches" :
" doesn't match");
4091 PrintIfNotEmpty(elem_listener.str(), listener->stream());
4095 void DescribeTo(std::ostream* os)
const {
4096 *os <<
"is an 'any' type with value of type '" <<
GetTypeName()
4097 <<
"' and the value ";
4098 matcher_.DescribeTo(os);
4101 void DescribeNegationTo(std::ostream* os)
const {
4102 *os <<
"is an 'any' type with value of type other than '" <<
GetTypeName()
4103 <<
"' or the value ";
4104 matcher_.DescribeNegationTo(os);
4111 return internal::GetTypeName<T>());
4113 return "the element type";
4116 const ::testing::Matcher<const T&> matcher_;
4122 template <
class ArgsTuple,
size_t... k>
4123 class ArgsMatcherImpl :
public MatcherInterface<ArgsTuple> {
4125 using RawArgsTuple =
typename std::decay<ArgsTuple>::type;
4126 using SelectedArgs =
4127 std::tuple<typename std::tuple_element<k, RawArgsTuple>::type...>;
4128 using MonomorphicInnerMatcher = Matcher<const SelectedArgs&>;
4130 template <
typename InnerMatcher>
4131 explicit ArgsMatcherImpl(
const InnerMatcher& inner_matcher)
4132 : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
4134 bool MatchAndExplain(ArgsTuple args,
4135 MatchResultListener* listener)
const override {
4138 const SelectedArgs& selected_args =
4139 std::forward_as_tuple(std::get<k>(args)...);
4140 if (!listener->IsInterested())
return inner_matcher_.Matches(selected_args);
4142 PrintIndices(listener->stream());
4145 StringMatchResultListener inner_listener;
4147 inner_matcher_.MatchAndExplain(selected_args, &inner_listener);
4148 PrintIfNotEmpty(inner_listener.str(), listener->stream());
4152 void DescribeTo(::std::ostream* os)
const override {
4153 *os <<
"are a tuple ";
4155 inner_matcher_.DescribeTo(os);
4158 void DescribeNegationTo(::std::ostream* os)
const override {
4159 *os <<
"are a tuple ";
4161 inner_matcher_.DescribeNegationTo(os);
4166 static void PrintIndices(::std::ostream* os) {
4167 *os <<
"whose fields (";
4168 const char* sep =
"";
4175 const char* dummy[] = {
4176 "", (
static_cast<void>(*os << sep <<
"#" << k), sep =
", ")...};
4181 MonomorphicInnerMatcher inner_matcher_;
4184 template <
class InnerMatcher,
size_t... k>
4187 explicit ArgsMatcher(InnerMatcher inner_matcher)
4188 : inner_matcher_(std::move(inner_matcher)) {}
4190 template <
typename ArgsTuple>
4191 operator Matcher<ArgsTuple>()
const {
4192 return MakeMatcher(
new ArgsMatcherImpl<ArgsTuple, k...>(inner_matcher_));
4196 InnerMatcher inner_matcher_;
4216 template <
typename Iter>
4217 inline internal::ElementsAreArrayMatcher<
4218 typename ::std::iterator_traits<Iter>::value_type>
4219 ElementsAreArray(Iter first, Iter last) {
4220 typedef typename ::std::iterator_traits<Iter>::value_type
T;
4221 return internal::ElementsAreArrayMatcher<T>(first, last);
4224 template <
typename T>
4225 inline auto ElementsAreArray(
const T* pointer,
size_t count)
4226 -> decltype(ElementsAreArray(pointer, pointer + count)) {
4227 return ElementsAreArray(pointer, pointer + count);
4230 template <
typename T,
size_t N>
4231 inline auto ElementsAreArray(
const T (&array)[
N])
4232 -> decltype(ElementsAreArray(array, N)) {
4233 return ElementsAreArray(array, N);
4236 template <
typename Container>
4237 inline auto ElementsAreArray(
const Container&
container)
4238 -> decltype(ElementsAreArray(container.begin(), container.end())) {
4239 return ElementsAreArray(container.begin(), container.end());
4242 template <
typename T>
4243 inline auto ElementsAreArray(::std::initializer_list<T> xs)
4244 -> decltype(ElementsAreArray(xs.begin(), xs.end())) {
4245 return ElementsAreArray(xs.begin(), xs.end());
4261 template <
typename Iter>
4262 inline internal::UnorderedElementsAreArrayMatcher<
4263 typename ::std::iterator_traits<Iter>::value_type>
4264 UnorderedElementsAreArray(Iter first, Iter last) {
4265 typedef typename ::std::iterator_traits<Iter>::value_type
T;
4266 return internal::UnorderedElementsAreArrayMatcher<T>(
4267 internal::UnorderedMatcherRequire::ExactMatch, first, last);
4270 template <
typename T>
4271 inline internal::UnorderedElementsAreArrayMatcher<T> UnorderedElementsAreArray(
4272 const T* pointer,
size_t count) {
4273 return UnorderedElementsAreArray(pointer, pointer + count);
4276 template <
typename T,
size_t N>
4277 inline internal::UnorderedElementsAreArrayMatcher<T> UnorderedElementsAreArray(
4278 const T (&array)[N]) {
4279 return UnorderedElementsAreArray(array, N);
4282 template <
typename Container>
4283 inline internal::UnorderedElementsAreArrayMatcher<
4284 typename Container::value_type>
4285 UnorderedElementsAreArray(
const Container& container) {
4286 return UnorderedElementsAreArray(container.begin(), container.end());
4289 template <
typename T>
4290 inline internal::UnorderedElementsAreArrayMatcher<T> UnorderedElementsAreArray(
4291 ::std::initializer_list<T> xs) {
4292 return UnorderedElementsAreArray(xs.begin(), xs.end());
4304 const internal::AnythingMatcher
_ = {};
4306 template <
typename T>
4307 inline Matcher<T>
A() {
4312 template <
typename T>
4313 inline Matcher<T> An() {
4317 template <
typename T,
typename M>
4318 Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl(
4319 const M& value, std::false_type ,
4325 inline PolymorphicMatcher<internal::IsNullMatcher>
IsNull() {
4326 return MakePolymorphicMatcher(internal::IsNullMatcher());
4332 inline PolymorphicMatcher<internal::NotNullMatcher> NotNull() {
4333 return MakePolymorphicMatcher(internal::NotNullMatcher());
4338 template <
typename T>
4339 inline internal::RefMatcher<T&> Ref(T&
x) {
4340 return internal::RefMatcher<T&>(
x);
4344 inline PolymorphicMatcher<internal::IsNanMatcher> IsNan() {
4345 return MakePolymorphicMatcher(internal::IsNanMatcher());
4350 inline internal::FloatingEqMatcher<double> DoubleEq(
double rhs) {
4351 return internal::FloatingEqMatcher<double>(rhs,
false);
4356 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(
double rhs) {
4357 return internal::FloatingEqMatcher<double>(rhs,
true);
4363 inline internal::FloatingEqMatcher<double> DoubleNear(
double rhs,
4364 double max_abs_error) {
4365 return internal::FloatingEqMatcher<double>(rhs,
false, max_abs_error);
4371 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear(
4372 double rhs,
double max_abs_error) {
4373 return internal::FloatingEqMatcher<double>(rhs,
true, max_abs_error);
4378 inline internal::FloatingEqMatcher<float> FloatEq(
float rhs) {
4379 return internal::FloatingEqMatcher<float>(rhs,
false);
4384 inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(
float rhs) {
4385 return internal::FloatingEqMatcher<float>(rhs,
true);
4391 inline internal::FloatingEqMatcher<float> FloatNear(
float rhs,
4392 float max_abs_error) {
4393 return internal::FloatingEqMatcher<float>(rhs,
false, max_abs_error);
4399 inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear(
4400 float rhs,
float max_abs_error) {
4401 return internal::FloatingEqMatcher<float>(rhs,
true, max_abs_error);
4406 template <
typename InnerMatcher>
4407 inline internal::PointeeMatcher<InnerMatcher> Pointee(
4408 const InnerMatcher& inner_matcher) {
4409 return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
4419 template <
typename To>
4420 inline PolymorphicMatcher<internal::WhenDynamicCastToMatcher<To>>
4421 WhenDynamicCastTo(
const Matcher<To>& inner_matcher) {
4422 return MakePolymorphicMatcher(
4423 internal::WhenDynamicCastToMatcher<To>(inner_matcher));
4425 #endif // GTEST_HAS_RTTI
4431 template <
typename Class,
typename FieldType,
typename FieldMatcher>
4432 inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType>> Field(
4433 FieldType Class::*field,
const FieldMatcher& matcher) {
4434 return MakePolymorphicMatcher(internal::FieldMatcher<Class, FieldType>(
4435 field, MatcherCast<const FieldType&>(matcher)));
4444 template <
typename Class,
typename FieldType,
typename FieldMatcher>
4445 inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType>> Field(
4446 const std::string& field_name, FieldType Class::*field,
4447 const FieldMatcher& matcher) {
4448 return MakePolymorphicMatcher(internal::FieldMatcher<Class, FieldType>(
4449 field_name, field, MatcherCast<const FieldType&>(matcher)));
4456 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
4457 inline PolymorphicMatcher<internal::PropertyMatcher<
4458 Class, PropertyType, PropertyType (Class::*)()
const>>
4459 Property(PropertyType (Class::*property)()
const,
4460 const PropertyMatcher& matcher) {
4461 return MakePolymorphicMatcher(
4462 internal::PropertyMatcher<Class, PropertyType,
4463 PropertyType (Class::*)()
const>(
4464 property, MatcherCast<const PropertyType&>(matcher)));
4473 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
4474 inline PolymorphicMatcher<internal::PropertyMatcher<
4475 Class, PropertyType, PropertyType (Class::*)()
const>>
4476 Property(
const std::string& property_name,
4477 PropertyType (Class::*property)()
const,
4478 const PropertyMatcher& matcher) {
4479 return MakePolymorphicMatcher(
4480 internal::PropertyMatcher<Class, PropertyType,
4481 PropertyType (Class::*)()
const>(
4482 property_name, property, MatcherCast<const PropertyType&>(matcher)));
4486 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
4487 inline PolymorphicMatcher<internal::PropertyMatcher<
4488 Class, PropertyType, PropertyType (Class::*)()
const&>>
4489 Property(PropertyType (Class::*property)()
const&,
4490 const PropertyMatcher& matcher) {
4491 return MakePolymorphicMatcher(
4492 internal::PropertyMatcher<Class, PropertyType,
4493 PropertyType (Class::*)()
const&>(
4494 property, MatcherCast<const PropertyType&>(matcher)));
4498 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
4499 inline PolymorphicMatcher<internal::PropertyMatcher<
4500 Class, PropertyType, PropertyType (Class::*)()
const&>>
4501 Property(
const std::string& property_name,
4502 PropertyType (Class::*property)()
const&,
4503 const PropertyMatcher& matcher) {
4504 return MakePolymorphicMatcher(
4505 internal::PropertyMatcher<Class, PropertyType,
4506 PropertyType (Class::*)()
const&>(
4507 property_name, property, MatcherCast<const PropertyType&>(matcher)));
4518 template <
typename Callable,
typename InnerMatcher>
4519 internal::ResultOfMatcher<Callable, InnerMatcher> ResultOf(
4520 Callable callable, InnerMatcher matcher) {
4521 return internal::ResultOfMatcher<Callable, InnerMatcher>(std::move(callable),
4522 std::move(matcher));
4527 template <
typename Callable,
typename InnerMatcher>
4528 internal::ResultOfMatcher<Callable, InnerMatcher> ResultOf(
4529 const std::string& result_description, Callable callable,
4530 InnerMatcher matcher) {
4531 return internal::ResultOfMatcher<Callable, InnerMatcher>(
4532 result_description, std::move(callable), std::move(matcher));
4538 template <
typename T = std::
string>
4539 PolymorphicMatcher<internal::StrEqualityMatcher<std::string>> StrEq(
4540 const internal::StringLike<T>& str) {
4541 return MakePolymorphicMatcher(
4542 internal::StrEqualityMatcher<std::string>(std::string(str),
true,
true));
4546 template <
typename T = std::
string>
4547 PolymorphicMatcher<internal::StrEqualityMatcher<std::string>> StrNe(
4548 const internal::StringLike<T>& str) {
4549 return MakePolymorphicMatcher(
4550 internal::StrEqualityMatcher<std::string>(std::string(str),
false,
true));
4554 template <
typename T = std::
string>
4555 PolymorphicMatcher<internal::StrEqualityMatcher<std::string>> StrCaseEq(
4556 const internal::StringLike<T>& str) {
4557 return MakePolymorphicMatcher(
4558 internal::StrEqualityMatcher<std::string>(std::string(str),
true,
false));
4562 template <
typename T = std::
string>
4563 PolymorphicMatcher<internal::StrEqualityMatcher<std::string>> StrCaseNe(
4564 const internal::StringLike<T>& str) {
4565 return MakePolymorphicMatcher(internal::StrEqualityMatcher<std::string>(
4566 std::string(str),
false,
false));
4571 template <
typename T = std::
string>
4572 PolymorphicMatcher<internal::HasSubstrMatcher<std::string>> HasSubstr(
4573 const internal::StringLike<T>& substring) {
4574 return MakePolymorphicMatcher(
4575 internal::HasSubstrMatcher<std::string>(std::string(substring)));
4579 template <
typename T = std::
string>
4580 PolymorphicMatcher<internal::StartsWithMatcher<std::string>>
StartsWith(
4581 const internal::StringLike<T>& prefix) {
4582 return MakePolymorphicMatcher(
4583 internal::StartsWithMatcher<std::string>(std::string(prefix)));
4587 template <
typename T = std::
string>
4588 PolymorphicMatcher<internal::EndsWithMatcher<std::string>>
EndsWith(
4589 const internal::StringLike<T>& suffix) {
4590 return MakePolymorphicMatcher(
4591 internal::EndsWithMatcher<std::string>(std::string(suffix)));
4594 #if GTEST_HAS_STD_WSTRING
4598 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring>> StrEq(
4599 const std::wstring& str) {
4600 return MakePolymorphicMatcher(
4601 internal::StrEqualityMatcher<std::wstring>(str,
true,
true));
4605 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring>> StrNe(
4606 const std::wstring& str) {
4607 return MakePolymorphicMatcher(
4608 internal::StrEqualityMatcher<std::wstring>(str,
false,
true));
4612 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring>> StrCaseEq(
4613 const std::wstring& str) {
4614 return MakePolymorphicMatcher(
4615 internal::StrEqualityMatcher<std::wstring>(str,
true,
false));
4619 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring>> StrCaseNe(
4620 const std::wstring& str) {
4621 return MakePolymorphicMatcher(
4622 internal::StrEqualityMatcher<std::wstring>(str,
false,
false));
4627 inline PolymorphicMatcher<internal::HasSubstrMatcher<std::wstring>> HasSubstr(
4628 const std::wstring& substring) {
4629 return MakePolymorphicMatcher(
4630 internal::HasSubstrMatcher<std::wstring>(substring));
4634 inline PolymorphicMatcher<internal::StartsWithMatcher<std::wstring>>
StartsWith(
4635 const std::wstring& prefix) {
4636 return MakePolymorphicMatcher(
4637 internal::StartsWithMatcher<std::wstring>(prefix));
4641 inline PolymorphicMatcher<internal::EndsWithMatcher<std::wstring>>
EndsWith(
4642 const std::wstring& suffix) {
4643 return MakePolymorphicMatcher(
4644 internal::EndsWithMatcher<std::wstring>(suffix));
4647 #endif // GTEST_HAS_STD_WSTRING
4651 inline internal::Eq2Matcher Eq() {
return internal::Eq2Matcher(); }
4655 inline internal::Ge2Matcher Ge() {
return internal::Ge2Matcher(); }
4659 inline internal::Gt2Matcher Gt() {
return internal::Gt2Matcher(); }
4663 inline internal::Le2Matcher Le() {
return internal::Le2Matcher(); }
4667 inline internal::Lt2Matcher Lt() {
return internal::Lt2Matcher(); }
4671 inline internal::Ne2Matcher Ne() {
return internal::Ne2Matcher(); }
4675 inline internal::FloatingEq2Matcher<float> FloatEq() {
4676 return internal::FloatingEq2Matcher<float>();
4681 inline internal::FloatingEq2Matcher<double> DoubleEq() {
4682 return internal::FloatingEq2Matcher<double>();
4687 inline internal::FloatingEq2Matcher<float> NanSensitiveFloatEq() {
4688 return internal::FloatingEq2Matcher<float>(
true);
4693 inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleEq() {
4694 return internal::FloatingEq2Matcher<double>(
true);
4699 inline internal::FloatingEq2Matcher<float> FloatNear(
float max_abs_error) {
4700 return internal::FloatingEq2Matcher<float>(max_abs_error);
4705 inline internal::FloatingEq2Matcher<double> DoubleNear(
double max_abs_error) {
4706 return internal::FloatingEq2Matcher<double>(max_abs_error);
4712 inline internal::FloatingEq2Matcher<float> NanSensitiveFloatNear(
4713 float max_abs_error) {
4714 return internal::FloatingEq2Matcher<float>(max_abs_error,
true);
4720 inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleNear(
4721 double max_abs_error) {
4722 return internal::FloatingEq2Matcher<double>(max_abs_error,
true);
4727 template <
typename InnerMatcher>
4728 inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) {
4729 return internal::NotMatcher<InnerMatcher>(m);
4735 template <
typename Predicate>
4736 inline PolymorphicMatcher<internal::TrulyMatcher<Predicate>> Truly(
4738 return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred));
4747 template <
typename SizeMatcher>
4748 inline internal::SizeIsMatcher<SizeMatcher> SizeIs(
4749 const SizeMatcher& size_matcher) {
4750 return internal::SizeIsMatcher<SizeMatcher>(size_matcher);
4758 template <
typename DistanceMatcher>
4759 inline internal::BeginEndDistanceIsMatcher<DistanceMatcher> BeginEndDistanceIs(
4760 const DistanceMatcher& distance_matcher) {
4761 return internal::BeginEndDistanceIsMatcher<DistanceMatcher>(distance_matcher);
4768 template <
typename Container>
4769 inline PolymorphicMatcher<
4770 internal::ContainerEqMatcher<typename std::remove_const<Container>::type>>
4771 ContainerEq(
const Container& rhs) {
4772 return MakePolymorphicMatcher(internal::ContainerEqMatcher<Container>(rhs));
4777 template <
typename Comparator,
typename ContainerMatcher>
4778 inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher> WhenSortedBy(
4779 const Comparator& comparator,
const ContainerMatcher& container_matcher) {
4780 return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>(
4781 comparator, container_matcher);
4786 template <
typename ContainerMatcher>
4787 inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
4788 WhenSorted(
const ContainerMatcher& container_matcher) {
4789 return internal::WhenSortedByMatcher<internal::LessComparator,
4791 internal::LessComparator(), container_matcher);
4800 template <
typename TupleMatcher,
typename Container>
4801 inline internal::PointwiseMatcher<TupleMatcher,
4802 typename std::remove_const<Container>::type>
4803 Pointwise(
const TupleMatcher& tuple_matcher,
const Container& rhs) {
4804 return internal::PointwiseMatcher<TupleMatcher, Container>(tuple_matcher,
4809 template <
typename TupleMatcher,
typename T>
4810 inline internal::PointwiseMatcher<TupleMatcher,
4811 std::vector<std::remove_const_t<T>>>
4812 Pointwise(
const TupleMatcher& tuple_matcher, std::initializer_list<T> rhs) {
4813 return Pointwise(tuple_matcher, std::vector<std::remove_const_t<T>>(rhs));
4827 template <
typename Tuple2Matcher,
typename RhsContainer>
4828 inline internal::UnorderedElementsAreArrayMatcher<
4829 typename internal::BoundSecondMatcher<
4831 typename internal::StlContainerView<
4832 typename std::remove_const<RhsContainer>::type>::type::value_type>>
4833 UnorderedPointwise(
const Tuple2Matcher& tuple2_matcher,
4834 const RhsContainer& rhs_container) {
4837 typedef typename internal::StlContainerView<RhsContainer> RhsView;
4838 typedef typename RhsView::type RhsStlContainer;
4839 typedef typename RhsStlContainer::value_type Second;
4840 const RhsStlContainer& rhs_stl_container =
4841 RhsView::ConstReference(rhs_container);
4844 ::std::vector<internal::BoundSecondMatcher<Tuple2Matcher, Second>> matchers;
4845 for (
auto it = rhs_stl_container.begin(); it != rhs_stl_container.end();
4847 matchers.push_back(internal::MatcherBindSecond(tuple2_matcher, *it));
4851 return UnorderedElementsAreArray(matchers);
4855 template <
typename Tuple2Matcher,
typename T>
4856 inline internal::UnorderedElementsAreArrayMatcher<
4857 typename internal::BoundSecondMatcher<Tuple2Matcher, T>>
4858 UnorderedPointwise(
const Tuple2Matcher& tuple2_matcher,
4859 std::initializer_list<T> rhs) {
4860 return UnorderedPointwise(tuple2_matcher, std::vector<T>(rhs));
4894 template <
typename M>
4895 inline internal::ContainsMatcher<M> Contains(M matcher) {
4896 return internal::ContainsMatcher<M>(matcher);
4926 template <
typename Iter>
4927 inline internal::UnorderedElementsAreArrayMatcher<
4928 typename ::std::iterator_traits<Iter>::value_type>
4929 IsSupersetOf(Iter first, Iter last) {
4930 typedef typename ::std::iterator_traits<Iter>::value_type
T;
4931 return internal::UnorderedElementsAreArrayMatcher<T>(
4932 internal::UnorderedMatcherRequire::Superset, first, last);
4935 template <
typename T>
4936 inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
4937 const T* pointer,
size_t count) {
4938 return IsSupersetOf(pointer, pointer + count);
4941 template <
typename T,
size_t N>
4942 inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
4943 const T (&array)[N]) {
4944 return IsSupersetOf(array, N);
4947 template <
typename Container>
4948 inline internal::UnorderedElementsAreArrayMatcher<
4949 typename Container::value_type>
4950 IsSupersetOf(
const Container& container) {
4951 return IsSupersetOf(container.begin(), container.end());
4954 template <
typename T>
4955 inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
4956 ::std::initializer_list<T> xs) {
4957 return IsSupersetOf(xs.begin(), xs.end());
4983 template <
typename Iter>
4984 inline internal::UnorderedElementsAreArrayMatcher<
4985 typename ::std::iterator_traits<Iter>::value_type>
4986 IsSubsetOf(Iter first, Iter last) {
4987 typedef typename ::std::iterator_traits<Iter>::value_type
T;
4988 return internal::UnorderedElementsAreArrayMatcher<T>(
4989 internal::UnorderedMatcherRequire::Subset, first, last);
4992 template <
typename T>
4993 inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
4994 const T* pointer,
size_t count) {
4995 return IsSubsetOf(pointer, pointer + count);
4998 template <
typename T,
size_t N>
4999 inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
5000 const T (&array)[N]) {
5001 return IsSubsetOf(array, N);
5004 template <
typename Container>
5005 inline internal::UnorderedElementsAreArrayMatcher<
5006 typename Container::value_type>
5007 IsSubsetOf(
const Container& container) {
5008 return IsSubsetOf(container.begin(), container.end());
5011 template <
typename T>
5012 inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
5013 ::std::initializer_list<T> xs) {
5014 return IsSubsetOf(xs.begin(), xs.end());
5044 template <
typename M>
5045 inline internal::EachMatcher<M> Each(M matcher) {
5046 return internal::EachMatcher<M>(matcher);
5052 template <
typename M>
5053 inline internal::KeyMatcher<M> Key(M inner_matcher) {
5054 return internal::KeyMatcher<M>(inner_matcher);
5062 template <
typename FirstMatcher,
typename SecondMatcher>
5063 inline internal::PairMatcher<FirstMatcher, SecondMatcher> Pair(
5064 FirstMatcher first_matcher, SecondMatcher second_matcher) {
5065 return internal::PairMatcher<FirstMatcher, SecondMatcher>(first_matcher,
5075 template <
typename MatcherTrue,
typename MatcherFalse>
5076 internal::ConditionalMatcher<MatcherTrue, MatcherFalse> Conditional(
5077 bool condition, MatcherTrue matcher_true, MatcherFalse matcher_false) {
5078 return internal::ConditionalMatcher<MatcherTrue, MatcherFalse>(
5079 condition, std::move(matcher_true), std::move(matcher_false));
5086 template <
typename... M>
5087 internal::FieldsAreMatcher<typename std::decay<M>::type...> FieldsAre(
5089 return internal::FieldsAreMatcher<typename std::decay<M>::type...>(
5090 std::forward<M>(matchers)...);
5095 template <
typename InnerMatcher>
5096 inline internal::PointerMatcher<InnerMatcher> Pointer(
5097 const InnerMatcher& inner_matcher) {
5098 return internal::PointerMatcher<InnerMatcher>(inner_matcher);
5103 template <
typename InnerMatcher>
5104 inline internal::AddressMatcher<InnerMatcher> Address(
5105 const InnerMatcher& inner_matcher) {
5106 return internal::AddressMatcher<InnerMatcher>(inner_matcher);
5111 template <
typename MatcherType>
5112 internal::WhenBase64UnescapedMatcher WhenBase64Unescaped(
5113 const MatcherType& internal_matcher) {
5114 return internal::WhenBase64UnescapedMatcher(internal_matcher);
5120 template <
typename M>
5121 inline internal::MatcherAsPredicate<M> Matches(M matcher) {
5122 return internal::MatcherAsPredicate<M>(matcher);
5126 template <
typename T,
typename M>
5127 inline bool Value(
const T& value, M matcher) {
5128 return testing::Matches(matcher)(
value);
5133 template <
typename T,
typename M>
5134 inline bool ExplainMatchResult(M matcher,
const T& value,
5135 MatchResultListener* listener) {
5136 return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
5150 template <
typename T,
typename M>
5151 std::string DescribeMatcher(
const M& matcher,
bool negation =
false) {
5152 ::std::stringstream ss;
5153 Matcher<T> monomorphic_matcher = SafeMatcherCast<T>(matcher);
5155 monomorphic_matcher.DescribeNegationTo(&ss);
5157 monomorphic_matcher.DescribeTo(&ss);
5162 template <
typename... Args>
5163 internal::ElementsAreMatcher<
5164 std::tuple<typename std::decay<const Args&>::type...>>
5165 ElementsAre(
const Args&... matchers) {
5166 return internal::ElementsAreMatcher<
5167 std::tuple<typename std::decay<const Args&>::type...>>(
5168 std::make_tuple(matchers...));
5171 template <
typename... Args>
5172 internal::UnorderedElementsAreMatcher<
5173 std::tuple<typename std::decay<const Args&>::type...>>
5174 UnorderedElementsAre(
const Args&... matchers) {
5175 return internal::UnorderedElementsAreMatcher<
5176 std::tuple<typename std::decay<const Args&>::type...>>(
5177 std::make_tuple(matchers...));
5181 template <
typename... Args>
5182 internal::AllOfMatcher<typename std::decay<const Args&>::type...> AllOf(
5183 const Args&... matchers) {
5184 return internal::AllOfMatcher<typename std::decay<const Args&>::type...>(
5188 template <
typename... Args>
5189 internal::AnyOfMatcher<typename std::decay<const Args&>::type...> AnyOf(
5190 const Args&... matchers) {
5191 return internal::AnyOfMatcher<typename std::decay<const Args&>::type...>(
5217 template <
typename Iter>
5218 inline internal::AnyOfArrayMatcher<
5219 typename ::std::iterator_traits<Iter>::value_type>
5220 AnyOfArray(Iter first, Iter last) {
5221 return internal::AnyOfArrayMatcher<
5222 typename ::std::iterator_traits<Iter>::value_type>(first, last);
5225 template <
typename Iter>
5226 inline internal::AllOfArrayMatcher<
5227 typename ::std::iterator_traits<Iter>::value_type>
5228 AllOfArray(Iter first, Iter last) {
5229 return internal::AllOfArrayMatcher<
5230 typename ::std::iterator_traits<Iter>::value_type>(first, last);
5233 template <
typename T>
5234 inline internal::AnyOfArrayMatcher<T> AnyOfArray(
const T* ptr,
size_t count) {
5235 return AnyOfArray(ptr, ptr + count);
5238 template <
typename T>
5239 inline internal::AllOfArrayMatcher<T> AllOfArray(
const T* ptr,
size_t count) {
5240 return AllOfArray(ptr, ptr + count);
5243 template <
typename T,
size_t N>
5244 inline internal::AnyOfArrayMatcher<T> AnyOfArray(
const T (&array)[N]) {
5245 return AnyOfArray(array, N);
5248 template <
typename T,
size_t N>
5249 inline internal::AllOfArrayMatcher<T> AllOfArray(
const T (&array)[N]) {
5250 return AllOfArray(array, N);
5253 template <
typename Container>
5254 inline internal::AnyOfArrayMatcher<typename Container::value_type> AnyOfArray(
5255 const Container& container) {
5256 return AnyOfArray(container.begin(), container.end());
5259 template <
typename Container>
5260 inline internal::AllOfArrayMatcher<typename Container::value_type> AllOfArray(
5261 const Container& container) {
5262 return AllOfArray(container.begin(), container.end());
5265 template <
typename T>
5266 inline internal::AnyOfArrayMatcher<T> AnyOfArray(
5267 ::std::initializer_list<T> xs) {
5268 return AnyOfArray(xs.begin(), xs.end());
5271 template <
typename T>
5272 inline internal::AllOfArrayMatcher<T> AllOfArray(
5273 ::std::initializer_list<T> xs) {
5274 return AllOfArray(xs.begin(), xs.end());
5280 template <
size_t... k,
typename InnerMatcher>
5281 internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...> Args(
5282 InnerMatcher&& matcher) {
5283 return internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...>(
5284 std::forward<InnerMatcher>(matcher));
5294 template <
typename InnerMatcher>
5295 inline InnerMatcher AllArgs(
const InnerMatcher& matcher) {
5308 template <
typename ValueMatcher>
5309 inline internal::OptionalMatcher<ValueMatcher> Optional(
5310 const ValueMatcher& value_matcher) {
5311 return internal::OptionalMatcher<ValueMatcher>(value_matcher);
5315 template <
typename T>
5316 PolymorphicMatcher<internal::any_cast_matcher::AnyCastMatcher<T>> AnyWith(
5317 const Matcher<const T&>& matcher) {
5318 return MakePolymorphicMatcher(
5319 internal::any_cast_matcher::AnyCastMatcher<T>(matcher));
5326 template <
typename T>
5327 PolymorphicMatcher<internal::variant_matcher::VariantMatcher<T>> VariantWith(
5328 const Matcher<const T&>& matcher) {
5329 return MakePolymorphicMatcher(
5330 internal::variant_matcher::VariantMatcher<T>(matcher));
5333 #if GTEST_HAS_EXCEPTIONS
5337 namespace internal {
5339 class WithWhatMatcherImpl {
5341 WithWhatMatcherImpl(Matcher<std::string> matcher)
5342 : matcher_(std::move(matcher)) {}
5344 void DescribeTo(std::ostream* os)
const {
5345 *os <<
"contains .what() that ";
5346 matcher_.DescribeTo(os);
5349 void DescribeNegationTo(std::ostream* os)
const {
5350 *os <<
"contains .what() that does not ";
5351 matcher_.DescribeTo(os);
5354 template <
typename Err>
5355 bool MatchAndExplain(
const Err& err, MatchResultListener* listener)
const {
5356 *listener <<
"which contains .what() (of value = " << err.what()
5358 return matcher_.MatchAndExplain(err.what(), listener);
5362 const Matcher<std::string> matcher_;
5365 inline PolymorphicMatcher<WithWhatMatcherImpl> WithWhat(
5366 Matcher<std::string> m) {
5367 return MakePolymorphicMatcher(WithWhatMatcherImpl(std::move(m)));
5370 template <
typename Err>
5371 class ExceptionMatcherImpl {
5374 const char* what()
const noexcept {
5375 return "this exception should never be thrown";
5400 using DefaultExceptionType =
typename std::conditional<
5401 std::is_same<
typename std::remove_cv<
5402 typename std::remove_reference<Err>::type>::type,
5404 const NeverThrown&,
const std::exception&>::type;
5407 ExceptionMatcherImpl(Matcher<const Err&> matcher)
5408 : matcher_(std::move(matcher)) {}
5410 void DescribeTo(std::ostream* os)
const {
5411 *os <<
"throws an exception which is a " << GetTypeName<Err>();
5413 matcher_.DescribeTo(os);
5416 void DescribeNegationTo(std::ostream* os)
const {
5417 *os <<
"throws an exception which is not a " << GetTypeName<Err>();
5419 matcher_.DescribeNegationTo(os);
5422 template <
typename T>
5423 bool MatchAndExplain(T&& x, MatchResultListener* listener)
const {
5425 (
void)(std::forward<T>(x)());
5426 }
catch (
const Err& err) {
5427 *listener <<
"throws an exception which is a " << GetTypeName<Err>();
5429 return matcher_.MatchAndExplain(err, listener);
5430 }
catch (DefaultExceptionType err) {
5432 *listener <<
"throws an exception of type " <<
GetTypeName(
typeid(err));
5435 *listener <<
"throws an std::exception-derived type ";
5437 *listener <<
"with description \"" << err.what() <<
"\"";
5440 *listener <<
"throws an exception of an unknown type";
5444 *listener <<
"does not throw any exception";
5449 const Matcher<const Err&> matcher_;
5476 template <
typename Err>
5477 PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> Throws() {
5478 return MakePolymorphicMatcher(
5482 template <
typename Err,
typename ExceptionMatcher>
5483 PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> Throws(
5484 const ExceptionMatcher& exception_matcher) {
5488 return MakePolymorphicMatcher(internal::ExceptionMatcherImpl<Err>(
5489 SafeMatcherCast<const Err&>(exception_matcher)));
5492 template <
typename Err,
typename MessageMatcher>
5493 PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> ThrowsMessage(
5494 MessageMatcher&& message_matcher) {
5496 "expected an std::exception-derived type");
5497 return Throws<Err>(internal::WithWhat(
5498 MatcherCast<std::string>(std::forward<MessageMatcher>(message_matcher))));
5501 #endif // GTEST_HAS_EXCEPTIONS
5507 #define ASSERT_THAT(value, matcher) \
5508 ASSERT_PRED_FORMAT1( \
5509 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
5510 #define EXPECT_THAT(value, matcher) \
5511 EXPECT_PRED_FORMAT1( \
5512 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
5515 #define MATCHER(name, description) \
5516 class name##Matcher \
5517 : public ::testing::internal::MatcherBaseImpl<name##Matcher> { \
5519 template <typename arg_type> \
5520 class gmock_Impl : public ::testing::MatcherInterface<const arg_type&> { \
5523 bool MatchAndExplain( \
5524 const arg_type& arg, \
5525 ::testing::MatchResultListener* result_listener) const override; \
5526 void DescribeTo(::std::ostream* gmock_os) const override { \
5527 *gmock_os << FormatDescription(false); \
5529 void DescribeNegationTo(::std::ostream* gmock_os) const override { \
5530 *gmock_os << FormatDescription(true); \
5534 ::std::string FormatDescription(bool negation) const { \
5536 ::std::string gmock_description = (description); \
5537 if (!gmock_description.empty()) { \
5538 return gmock_description; \
5540 return ::testing::internal::FormatMatcherDescription(negation, #name, \
5545 inline name##Matcher GMOCK_INTERNAL_WARNING_PUSH() \
5546 GMOCK_INTERNAL_WARNING_CLANG(ignored, "-Wunused-function") \
5547 GMOCK_INTERNAL_WARNING_CLANG(ignored, "-Wunused-member-function") \
5548 name GMOCK_INTERNAL_WARNING_POP()() { \
5551 template <typename arg_type> \
5552 bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain( \
5553 const arg_type& arg, \
5554 GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED ::testing::MatchResultListener* \
5555 result_listener) const
5557 #define MATCHER_P(name, p0, description) \
5558 GMOCK_INTERNAL_MATCHER(name, name##MatcherP, description, (#p0), (p0))
5559 #define MATCHER_P2(name, p0, p1, description) \
5560 GMOCK_INTERNAL_MATCHER(name, name##MatcherP2, description, (#p0, #p1), \
5562 #define MATCHER_P3(name, p0, p1, p2, description) \
5563 GMOCK_INTERNAL_MATCHER(name, name##MatcherP3, description, (#p0, #p1, #p2), \
5565 #define MATCHER_P4(name, p0, p1, p2, p3, description) \
5566 GMOCK_INTERNAL_MATCHER(name, name##MatcherP4, description, \
5567 (#p0, #p1, #p2, #p3), (p0, p1, p2, p3))
5568 #define MATCHER_P5(name, p0, p1, p2, p3, p4, description) \
5569 GMOCK_INTERNAL_MATCHER(name, name##MatcherP5, description, \
5570 (#p0, #p1, #p2, #p3, #p4), (p0, p1, p2, p3, p4))
5571 #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description) \
5572 GMOCK_INTERNAL_MATCHER(name, name##MatcherP6, description, \
5573 (#p0, #p1, #p2, #p3, #p4, #p5), \
5574 (p0, p1, p2, p3, p4, p5))
5575 #define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description) \
5576 GMOCK_INTERNAL_MATCHER(name, name##MatcherP7, description, \
5577 (#p0, #p1, #p2, #p3, #p4, #p5, #p6), \
5578 (p0, p1, p2, p3, p4, p5, p6))
5579 #define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description) \
5580 GMOCK_INTERNAL_MATCHER(name, name##MatcherP8, description, \
5581 (#p0, #p1, #p2, #p3, #p4, #p5, #p6, #p7), \
5582 (p0, p1, p2, p3, p4, p5, p6, p7))
5583 #define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description) \
5584 GMOCK_INTERNAL_MATCHER(name, name##MatcherP9, description, \
5585 (#p0, #p1, #p2, #p3, #p4, #p5, #p6, #p7, #p8), \
5586 (p0, p1, p2, p3, p4, p5, p6, p7, p8))
5587 #define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description) \
5588 GMOCK_INTERNAL_MATCHER(name, name##MatcherP10, description, \
5589 (#p0, #p1, #p2, #p3, #p4, #p5, #p6, #p7, #p8, #p9), \
5590 (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9))
5592 #define GMOCK_INTERNAL_MATCHER(name, full_name, description, arg_names, args) \
5593 template <GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args)> \
5594 class full_name : public ::testing::internal::MatcherBaseImpl< \
5595 full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>> { \
5597 using full_name::MatcherBaseImpl::MatcherBaseImpl; \
5598 template <typename arg_type> \
5599 class gmock_Impl : public ::testing::MatcherInterface<const arg_type&> { \
5601 explicit gmock_Impl(GMOCK_INTERNAL_MATCHER_FUNCTION_ARGS(args)) \
5602 : GMOCK_INTERNAL_MATCHER_FORWARD_ARGS(args) {} \
5603 bool MatchAndExplain( \
5604 const arg_type& arg, \
5605 ::testing::MatchResultListener* result_listener) const override; \
5606 void DescribeTo(::std::ostream* gmock_os) const override { \
5607 *gmock_os << FormatDescription(false); \
5609 void DescribeNegationTo(::std::ostream* gmock_os) const override { \
5610 *gmock_os << FormatDescription(true); \
5612 GMOCK_INTERNAL_MATCHER_MEMBERS(args) \
5615 ::std::string FormatDescription(bool negation) const { \
5616 ::std::string gmock_description; \
5617 gmock_description = (description); \
5618 if (!gmock_description.empty()) { \
5619 return gmock_description; \
5621 return ::testing::internal::FormatMatcherDescription( \
5622 negation, #name, {GMOCK_PP_REMOVE_PARENS(arg_names)}, \
5623 ::testing::internal::UniversalTersePrintTupleFieldsToStrings( \
5624 ::std::tuple<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>( \
5625 GMOCK_INTERNAL_MATCHER_MEMBERS_USAGE(args)))); \
5629 template <GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args)> \
5630 inline full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)> name( \
5631 GMOCK_INTERNAL_MATCHER_FUNCTION_ARGS(args)) { \
5632 return full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>( \
5633 GMOCK_INTERNAL_MATCHER_ARGS_USAGE(args)); \
5635 template <GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args)> \
5636 template <typename arg_type> \
5637 bool full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>:: \
5638 gmock_Impl<arg_type>::MatchAndExplain( \
5639 const arg_type& arg, \
5640 GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED ::testing:: \
5641 MatchResultListener* result_listener) const
5643 #define GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args) \
5645 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAM, , args))
5646 #define GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAM(i_unused, data_unused, arg) \
5647 , typename arg##_type
5649 #define GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args) \
5650 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_TYPE_PARAM, , args))
5651 #define GMOCK_INTERNAL_MATCHER_TYPE_PARAM(i_unused, data_unused, arg) \
5654 #define GMOCK_INTERNAL_MATCHER_FUNCTION_ARGS(args) \
5655 GMOCK_PP_TAIL(dummy_first GMOCK_PP_FOR_EACH( \
5656 GMOCK_INTERNAL_MATCHER_FUNCTION_ARG, , args))
5657 #define GMOCK_INTERNAL_MATCHER_FUNCTION_ARG(i, data_unused, arg) \
5658 , arg##_type gmock_p##i
5660 #define GMOCK_INTERNAL_MATCHER_FORWARD_ARGS(args) \
5661 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_FORWARD_ARG, , args))
5662 #define GMOCK_INTERNAL_MATCHER_FORWARD_ARG(i, data_unused, arg) \
5663 , arg(::std::forward<arg##_type>(gmock_p##i))
5665 #define GMOCK_INTERNAL_MATCHER_MEMBERS(args) \
5666 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_MEMBER, , args)
5667 #define GMOCK_INTERNAL_MATCHER_MEMBER(i_unused, data_unused, arg) \
5668 const arg##_type arg;
5670 #define GMOCK_INTERNAL_MATCHER_MEMBERS_USAGE(args) \
5671 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_MEMBER_USAGE, , args))
5672 #define GMOCK_INTERNAL_MATCHER_MEMBER_USAGE(i_unused, data_unused, arg) , arg
5674 #define GMOCK_INTERNAL_MATCHER_ARGS_USAGE(args) \
5675 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_ARG_USAGE, , args))
5676 #define GMOCK_INTERNAL_MATCHER_ARG_USAGE(i, data_unused, arg) \
5677 , ::std::forward<arg##_type>(gmock_p##i)
5680 using namespace no_adl;
5689 #include "gmock/internal/custom/gmock-matchers.h"
5691 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
Sacado::Fad::DFad< double > F
constexpr bool StartsWith(const char(&prefix)[N], const char(&str)[M])
#define GMOCK_KIND_OF_(type)
GTEST_DISABLE_MSC_WARNINGS_POP_() TEST(LinkTest
AssertionResult AssertionFailure()
constexpr bool EndsWith(const char(&suffix)[N], const char(&str)[M])
::std::string PrintToString(const T &value)
#define GTEST_LOG_(severity)
std::string Print(const T &value)
::std::vector<::std::string > Strings
bool Base64Unescape(const std::string &encoded, std::string *decoded)
std::string Describe(const Matcher< T > &m)
std::string GetTypeName()
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
auto Apply(F &&f, Tuple &&args) -> decltype(ApplyImpl(std::forward< F >(f), std::forward< Tuple >(args), std::make_index_sequence< std::tuple_size< typename std::remove_reference< Tuple >::type >::value >()))
CacheTaylor< T > diff(const CacheTaylor< T > &x, int n=1)
Compute Taylor series of n-th derivative of x.
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
AssertionResult AssertionSuccess()
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
#define GTEST_CHECK_(condition)
void UniversalPrint(const T &value,::std::ostream *os)
#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
GTEST_API_ std::string FormatMatcherDescription(bool negation, const char *matcher_name, const std::vector< const char * > ¶m_names, const Strings ¶m_values)
std::string DescribeNegation(const Matcher< T > &m)
GTEST_API_ ElementMatcherPairs FindMaxBipartiteMatching(const MatchMatrix &g)
#define GMOCK_MAYBE_5046_
<< DiffStrings(str, arg);
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
const Pointer::element_type * GetRawPointer(const Pointer &p)
AssertionResult IsNull(const char *str)
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T)
static ExpectedAnswer expected[4]