255 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
256 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
260 #include <initializer_list>
267 #include <type_traits>
271 #include "gmock/internal/gmock-internal-utils.h"
272 #include "gmock/internal/gmock-port.h"
273 #include "gmock/internal/gmock-pp.h"
274 #include "gtest/gtest.h"
277 #if defined(_MSC_VER) && _MSC_VER >= 1915
278 #define GMOCK_MAYBE_5046_ 5046
280 #define GMOCK_MAYBE_5046_
303 class StringMatchResultListener :
public MatchResultListener {
314 ::std::stringstream
ss_;
333 template <
typename T,
typename M>
334 class MatcherCastImpl {
336 static Matcher<T>
Cast(
const M& polymorphic_matcher_or_value) {
350 return CastImpl(polymorphic_matcher_or_value,
351 std::is_convertible<M, Matcher<T>>{},
352 std::is_convertible<M, T>{});
356 template <
bool Ignore>
357 static Matcher<T>
CastImpl(
const M& polymorphic_matcher_or_value,
359 std::integral_constant<bool, Ignore>) {
368 return polymorphic_matcher_or_value;
377 return Matcher<T>(ImplicitCast_<T>(
value));
398 template <
typename T,
typename U>
399 class MatcherCastImpl<
T, Matcher<U>> {
401 static Matcher<T>
Cast(
const Matcher<U>& source_matcher) {
402 return Matcher<T>(
new Impl(source_matcher));
406 class Impl :
public MatcherInterface<T> {
408 explicit Impl(
const Matcher<U>& source_matcher)
409 : source_matcher_(source_matcher) {}
412 bool MatchAndExplain(
T x, MatchResultListener* listener)
const override {
413 using FromType =
typename std::remove_cv<
typename std::remove_pointer<
415 using ToType =
typename std::remove_cv<
typename std::remove_pointer<
425 "Can't implicitly convert from <base> to <derived>");
433 return source_matcher_.MatchAndExplain(
static_cast<CastType
>(
x),
437 void DescribeTo(::std::ostream* os)
const override {
438 source_matcher_.DescribeTo(os);
441 void DescribeNegationTo(::std::ostream* os)
const override {
442 source_matcher_.DescribeNegationTo(os);
446 const Matcher<U> source_matcher_;
452 template <
typename T>
453 class MatcherCastImpl<
T, Matcher<
T>> {
455 static Matcher<T>
Cast(
const Matcher<T>& matcher) {
return matcher; }
459 template <
typename Derived>
460 class MatcherBaseImpl {
462 MatcherBaseImpl() =
default;
464 template <
typename T>
465 operator ::testing::Matcher<T>()
const {
466 return ::testing::Matcher<T>(
new
472 template <
template <
typename...>
class Derived,
typename... Ts>
473 class MatcherBaseImpl<Derived<Ts...>> {
477 template <
typename E = std::enable_if<
sizeof...(Ts) == 1>,
479 explicit MatcherBaseImpl(Ts... params)
480 : params_(std::forward<Ts>(params)...) {}
481 template <
typename E = std::enable_if<
sizeof...(Ts) != 1>,
483 MatcherBaseImpl(Ts... params)
484 : params_(std::forward<Ts>(params)...) {}
486 template <
typename F>
487 operator ::testing::Matcher<F>()
const {
492 template <
typename F, std::size_t... tuple_ids>
494 return ::testing::Matcher<F>(
496 std::get<tuple_ids>(params_)...));
499 const std::tuple<Ts...> params_;
508 template <
typename T,
typename M>
515 template <
typename T,
typename M>
516 inline Matcher<T>
SafeMatcherCast(
const M& polymorphic_matcher_or_value) {
517 return MatcherCast<T>(polymorphic_matcher_or_value);
529 template <
typename T,
typename U>
533 "T must be implicitly convertible to U");
538 cannot_convert_non_reference_arg_to_reference);
546 kTIsOther || kUIsOther ||
548 conversion_of_arithmetic_types_must_be_lossless);
549 return MatcherCast<T>(matcher);
553 template <
typename T>
562 ::std::ostream* os) {
563 if (explanation !=
"" && os !=
nullptr) {
564 *os <<
", " << explanation;
575 type_name.find_first_of(
"<(") == std::string::npos);
583 template <
typename Value,
typename T>
585 MatchResultListener* listener) {
586 if (!listener->IsInterested()) {
589 return matcher.Matches(
value);
592 StringMatchResultListener inner_listener;
593 const bool match = matcher.MatchAndExplain(
value, &inner_listener);
599 *listener->stream() <<
" (of type " <<
type_name <<
")";
614 template <
typename MatcherTuple,
typename ValueTuple>
615 static bool Matches(
const MatcherTuple& matcher_tuple,
616 const ValueTuple& value_tuple) {
625 template <
typename MatcherTuple,
typename ValueTuple>
628 ::std::ostream* os) {
634 typename std::tuple_element<
N - 1, MatcherTuple>
::type matcher =
636 typedef typename std::tuple_element<
N - 1, ValueTuple>
::type Value;
638 StringMatchResultListener listener;
639 if (!matcher.MatchAndExplain(
value, &listener)) {
640 *os <<
" Expected arg #" <<
N - 1 <<
": ";
642 *os <<
"\n Actual: ";
657 class TuplePrefix<0> {
659 template <
typename MatcherTuple,
typename ValueTuple>
660 static bool Matches(
const MatcherTuple& ,
661 const ValueTuple& ) {
665 template <
typename MatcherTuple,
typename ValueTuple>
676 template <
typename MatcherTuple,
typename ValueTuple>
678 const ValueTuple& value_tuple) {
683 matcher_and_value_have_different_numbers_of_fields);
690 template <
typename MatcherTuple,
typename ValueTuple>
692 const ValueTuple&
values, ::std::ostream* os) {
701 template <
typename Tuple,
typename Func,
typename OutIter>
702 class TransformTupleValuesHelper {
704 typedef ::std::tuple_size<Tuple>
TupleSize;
709 static OutIter
Run(
Func f,
const Tuple& t, OutIter
out) {
710 return IterateOverTuple<Tuple, TupleSize::value>()(f, t,
out);
714 template <
typename Tup,
size_t kRemainingSize>
715 struct IterateOverTuple {
717 *
out++ = f(::std::get<TupleSize::value - kRemainingSize>(t));
718 return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t,
out);
721 template <
typename Tup>
722 struct IterateOverTuple<Tup, 0> {
732 template <
typename Tuple,
typename Func,
typename OutIter>
741 class AnythingMatcher {
743 using is_gtest_matcher = void;
745 template <
typename T>
746 bool MatchAndExplain(
const T& , std::ostream* )
const {
749 void DescribeTo(std::ostream* os)
const { *os <<
"is anything"; }
750 void DescribeNegationTo(::std::ostream* os)
const {
754 *os <<
"never matches";
760 class IsNullMatcher {
762 template <
typename Po
inter>
764 MatchResultListener* )
const {
768 void DescribeTo(::std::ostream* os)
const { *os <<
"is NULL"; }
774 class NotNullMatcher {
776 template <
typename Po
inter>
778 MatchResultListener* )
const {
782 void DescribeTo(::std::ostream* os)
const { *os <<
"isn't NULL"; }
799 template <
typename T>
802 template <
typename T>
803 class RefMatcher<
T&> {
813 explicit RefMatcher(
T&
x) : object_(
x) {}
815 template <
typename Super>
816 operator Matcher<Super&>()
const {
826 template <
typename Super>
827 class Impl :
public MatcherInterface<Super&> {
829 explicit Impl(Super&
x) : object_(
x) {}
833 bool MatchAndExplain(Super&
x,
834 MatchResultListener* listener)
const override {
835 *listener <<
"which is located @" <<
static_cast<const void*
>(&
x);
836 return &
x == &object_;
839 void DescribeTo(::std::ostream* os)
const override {
840 *os <<
"references the variable ";
844 void DescribeNegationTo(::std::ostream* os)
const override {
845 *os <<
"does not reference the variable ";
850 const Super& object_;
862 const wchar_t* rhs) {
868 template <
typename StringType>
877 const size_t i1 = s1.find(nul),
i2 = s2.find(nul);
880 if (
i1 == StringType::npos ||
i2 == StringType::npos) {
891 template <
typename StringType>
892 class StrEqualityMatcher {
899 #if GTEST_INTERNAL_HAS_STRING_VIEW
901 MatchResultListener* listener)
const {
907 #endif // GTEST_INTERNAL_HAS_STRING_VIEW
914 template <
typename CharType>
915 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
926 template <
typename MatcheeStringType>
928 MatchResultListener* )
const {
945 *os << (expect_eq ?
"is " :
"isn't ");
948 *os <<
"(ignoring case) ";
961 template <
typename StringType>
962 class HasSubstrMatcher {
967 #if GTEST_INTERNAL_HAS_STRING_VIEW
969 MatchResultListener* listener)
const {
975 #endif // GTEST_INTERNAL_HAS_STRING_VIEW
982 template <
typename CharType>
983 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
991 template <
typename MatcheeStringType>
993 MatchResultListener* )
const {
999 *os <<
"has substring ";
1004 *os <<
"has no substring ";
1015 template <
typename StringType>
1016 class StartsWithMatcher {
1020 #if GTEST_INTERNAL_HAS_STRING_VIEW
1022 MatchResultListener* listener)
const {
1028 #endif // GTEST_INTERNAL_HAS_STRING_VIEW
1035 template <
typename CharType>
1036 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
1044 template <
typename MatcheeStringType>
1046 MatchResultListener* )
const {
1048 return s2.length() >=
prefix_.length() &&
1053 *os <<
"starts with ";
1058 *os <<
"doesn't start with ";
1069 template <
typename StringType>
1070 class EndsWithMatcher {
1074 #if GTEST_INTERNAL_HAS_STRING_VIEW
1076 MatchResultListener* listener)
const {
1082 #endif // GTEST_INTERNAL_HAS_STRING_VIEW
1089 template <
typename CharType>
1090 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
1098 template <
typename MatcheeStringType>
1100 MatchResultListener* )
const {
1102 return s2.length() >=
suffix_.length() &&
1107 *os <<
"ends with ";
1112 *os <<
"doesn't end with ";
1122 class WhenBase64UnescapedMatcher {
1124 using is_gtest_matcher = void;
1126 explicit WhenBase64UnescapedMatcher(
1127 const Matcher<const std::string&>& internal_matcher)
1128 : internal_matcher_(internal_matcher) {}
1131 template <
typename MatcheeStringType>
1132 bool MatchAndExplain(
const MatcheeStringType& s,
1133 MatchResultListener* listener)
const {
1137 if (listener !=
nullptr) {
1138 *listener <<
"is not a valid base64 escaped string";
1145 void DescribeTo(::std::ostream* os)
const {
1146 *os <<
"matches after Base64Unescape ";
1147 internal_matcher_.DescribeTo(os);
1150 void DescribeNegationTo(::std::ostream* os)
const {
1151 *os <<
"does not match after Base64Unescape ";
1152 internal_matcher_.DescribeTo(os);
1156 const Matcher<const std::string&> internal_matcher_;
1167 template <
typename D,
typename Op>
1168 class PairMatchBase {
1170 template <
typename T1,
typename T2>
1171 operator Matcher<::std::tuple<T1, T2>>()
const {
1172 return Matcher<::std::tuple<T1, T2>>(
new Impl<const ::std::tuple<T1, T2>&>);
1174 template <
typename T1,
typename T2>
1175 operator Matcher<const ::std::tuple<T1, T2>&>()
const {
1176 return MakeMatcher(
new Impl<const ::std::tuple<T1, T2>&>);
1180 static ::std::ostream&
GetDesc(::std::ostream& os) {
1181 return os << D::Desc();
1184 template <
typename Tuple>
1185 class Impl :
public MatcherInterface<Tuple> {
1188 MatchResultListener* )
const override {
1189 return Op()(::std::get<0>(
args), ::std::get<1>(
args));
1191 void DescribeTo(::std::ostream* os)
const override {
1200 class Eq2Matcher :
public PairMatchBase<Eq2Matcher, AnyEq> {
1202 static const char*
Desc() {
return "an equal pair"; }
1204 class Ne2Matcher :
public PairMatchBase<Ne2Matcher, AnyNe> {
1206 static const char*
Desc() {
return "an unequal pair"; }
1208 class Lt2Matcher :
public PairMatchBase<Lt2Matcher, AnyLt> {
1210 static const char*
Desc() {
return "a pair where the first < the second"; }
1212 class Gt2Matcher :
public PairMatchBase<Gt2Matcher, AnyGt> {
1214 static const char*
Desc() {
return "a pair where the first > the second"; }
1216 class Le2Matcher :
public PairMatchBase<Le2Matcher, AnyLe> {
1218 static const char*
Desc() {
return "a pair where the first <= the second"; }
1220 class Ge2Matcher :
public PairMatchBase<Ge2Matcher, AnyGe> {
1222 static const char*
Desc() {
return "a pair where the first >= the second"; }
1229 template <
typename T>
1230 class NotMatcherImpl :
public MatcherInterface<const T&> {
1235 MatchResultListener* listener)
const override {
1236 return !
matcher_.MatchAndExplain(
x, listener);
1239 void DescribeTo(::std::ostream* os)
const override {
1253 template <
typename InnerMatcher>
1260 template <
typename T>
1261 operator Matcher<T>()
const {
1262 return Matcher<T>(
new NotMatcherImpl<T>(SafeMatcherCast<T>(
matcher_)));
1273 template <
typename T>
1274 class AllOfMatcherImpl :
public MatcherInterface<const T&> {
1276 explicit AllOfMatcherImpl(std::vector<Matcher<T>>
matchers)
1279 void DescribeTo(::std::ostream* os)
const override {
1282 if (
i != 0) *os <<
") and (";
1288 void DescribeNegationTo(::std::ostream* os)
const override {
1291 if (
i != 0) *os <<
") or (";
1297 bool MatchAndExplain(
const T&
x,
1298 MatchResultListener* listener)
const override {
1304 StringMatchResultListener slistener;
1305 if (
matchers_[
i].MatchAndExplain(
x, &slistener)) {
1306 if (all_match_result.empty()) {
1307 all_match_result = slistener.str();
1311 all_match_result +=
", and ";
1312 all_match_result +=
result;
1316 *listener << slistener.str();
1322 *listener << all_match_result;
1327 const std::vector<Matcher<T>>
matchers_;
1334 template <
template <
typename T>
class CombiningMatcher,
typename...
Args>
1335 class VariadicMatcher {
1339 static_assert(
sizeof...(
Args) > 0,
"Must have at least one matcher.");
1342 VariadicMatcher(
const VariadicMatcher&) =
default;
1343 VariadicMatcher& operator=(
const VariadicMatcher&) =
delete;
1348 template <
typename T>
1349 operator Matcher<T>()
const {
1350 std::vector<Matcher<T>>
values;
1351 CreateVariadicMatcher<T>(&
values, std::integral_constant<size_t, 0>());
1356 template <
typename T,
size_t I>
1357 void CreateVariadicMatcher(std::vector<Matcher<T>>*
values,
1358 std::integral_constant<size_t, I>)
const {
1360 CreateVariadicMatcher<T>(
values, std::integral_constant<size_t, I + 1>());
1363 template <
typename T>
1364 void CreateVariadicMatcher(
1365 std::vector<Matcher<T>>*,
1366 std::integral_constant<
size_t,
sizeof...(
Args)>)
const {}
1371 template <
typename...
Args>
1372 using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl,
Args...>;
1378 template <
typename T>
1379 class AnyOfMatcherImpl :
public MatcherInterface<const T&> {
1381 explicit AnyOfMatcherImpl(std::vector<Matcher<T>>
matchers)
1384 void DescribeTo(::std::ostream* os)
const override {
1387 if (
i != 0) *os <<
") or (";
1393 void DescribeNegationTo(::std::ostream* os)
const override {
1396 if (
i != 0) *os <<
") and (";
1402 bool MatchAndExplain(
const T&
x,
1403 MatchResultListener* listener)
const override {
1409 StringMatchResultListener slistener;
1410 if (
matchers_[
i].MatchAndExplain(
x, &slistener)) {
1411 *listener << slistener.str();
1414 if (no_match_result.empty()) {
1415 no_match_result = slistener.str();
1419 no_match_result +=
", and ";
1420 no_match_result +=
result;
1427 *listener << no_match_result;
1432 const std::vector<Matcher<T>>
matchers_;
1436 template <
typename...
Args>
1437 using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl,
Args...>;
1440 template <
typename MatcherTrue,
typename MatcherFalse>
1441 class ConditionalMatcher {
1443 ConditionalMatcher(
bool condition, MatcherTrue matcher_true,
1444 MatcherFalse matcher_false)
1445 : condition_(condition),
1447 matcher_false_(
std::move(matcher_false)) {}
1449 template <
typename T>
1450 operator Matcher<T>()
const {
1451 return condition_ ? SafeMatcherCast<T>(matcher_true_)
1452 : SafeMatcherCast<T>(matcher_false_);
1457 MatcherTrue matcher_true_;
1458 MatcherFalse matcher_false_;
1462 template <
template <
class>
class MatcherImpl,
typename T>
1463 class SomeOfArrayMatcher {
1467 template <
typename Iter>
1470 template <
typename U>
1471 operator Matcher<U>()
const {
1473 std::vector<Matcher<RawU>>
matchers;
1475 matchers.push_back(MatcherCast<RawU>(matcher));
1484 template <
typename T>
1485 using AllOfArrayMatcher = SomeOfArrayMatcher<AllOfMatcherImpl, T>;
1487 template <
typename T>
1488 using AnyOfArrayMatcher = SomeOfArrayMatcher<AnyOfMatcherImpl, T>;
1492 template <
typename Predicate>
1493 class TrulyMatcher {
1501 template <
typename T>
1503 MatchResultListener* listener)
const {
1511 *listener <<
"didn't satisfy the given predicate";
1516 *os <<
"satisfies the given predicate";
1520 *os <<
"doesn't satisfy the given predicate";
1529 template <
typename M>
1530 class MatcherAsPredicate {
1540 template <
typename T>
1556 return MatcherCast<const T&>(
matcher_).Matches(
x);
1565 template <
typename M>
1566 class PredicateFormatterFromMatcher {
1573 template <
typename T>
1574 AssertionResult
operator()(
const char* value_text,
const T&
x)
const {
1586 const Matcher<const T&> matcher = SafeMatcherCast<const T&>(
matcher_);
1590 if (matcher.Matches(
x)) {
1594 ::std::stringstream ss;
1595 ss <<
"Value of: " << value_text <<
"\n"
1597 matcher.DescribeTo(&ss);
1600 StringMatchResultListener listener;
1602 ss <<
"\n The matcher failed on the initial attempt; but passed when "
1603 "rerun to generate the explanation.";
1605 ss <<
"\n Actual: " << listener.str();
1617 template <
typename M>
1620 return PredicateFormatterFromMatcher<M>(
std::move(matcher));
1625 class IsNanMatcher {
1627 template <
typename FloatType>
1628 bool MatchAndExplain(
const FloatType& f,
1629 MatchResultListener* )
const {
1633 void DescribeTo(::std::ostream* os)
const { *os <<
"is NaN"; }
1634 void DescribeNegationTo(::std::ostream* os)
const { *os <<
"isn't NaN"; }
1641 template <
typename FloatType>
1642 class FloatingEqMatcher {
1662 <<
", where max_abs_error is" << max_abs_error;
1666 template <
typename T>
1667 class Impl :
public MatcherInterface<T> {
1675 MatchResultListener* listener)
const override {
1676 const FloatingPoint<FloatType> actual(
value), expected(
expected_);
1679 if (actual.is_nan() || expected.is_nan()) {
1680 if (actual.is_nan() && expected.is_nan()) {
1700 if (listener->IsInterested()) {
1705 return actual.AlmostEquals(expected);
1709 void DescribeTo(::std::ostream* os)
const override {
1713 const ::std::streamsize old_precision =
1714 os->precision(::std::numeric_limits<FloatType>::digits10 + 2);
1715 if (FloatingPoint<FloatType>(
expected_).is_nan()) {
1719 *os <<
"never matches";
1722 *os <<
"is approximately " <<
expected_;
1727 os->precision(old_precision);
1732 const ::std::streamsize old_precision =
1733 os->precision(::std::numeric_limits<FloatType>::digits10 + 2);
1734 if (FloatingPoint<FloatType>(
expected_).is_nan()) {
1738 *os <<
"is anything";
1741 *os <<
"isn't approximately " <<
expected_;
1747 os->precision(old_precision);
1762 operator Matcher<FloatType>()
const {
1767 operator Matcher<const FloatType&>()
const {
1772 operator Matcher<FloatType&>()
const {
1789 template <
typename FloatType>
1790 class FloatingEq2Matcher {
1792 FloatingEq2Matcher() {
Init(-1,
false); }
1794 explicit FloatingEq2Matcher(
bool nan_eq_nan) {
Init(-1, nan_eq_nan); }
1796 explicit FloatingEq2Matcher(
FloatType max_abs_error) {
1797 Init(max_abs_error,
false);
1800 FloatingEq2Matcher(
FloatType max_abs_error,
bool nan_eq_nan) {
1801 Init(max_abs_error, nan_eq_nan);
1804 template <
typename T1,
typename T2>
1805 operator Matcher<::std::tuple<T1, T2>>()
const {
1807 new Impl<::std::tuple<T1, T2>>(max_abs_error_, nan_eq_nan_));
1809 template <
typename T1,
typename T2>
1810 operator Matcher<const ::std::tuple<T1, T2>&>()
const {
1812 new Impl<const ::std::tuple<T1, T2>&>(max_abs_error_, nan_eq_nan_));
1816 static ::std::ostream& GetDesc(::std::ostream& os) {
1817 return os <<
"an almost-equal pair";
1820 template <
typename Tuple>
1821 class Impl :
public MatcherInterface<Tuple> {
1823 Impl(
FloatType max_abs_error,
bool nan_eq_nan)
1824 : max_abs_error_(max_abs_error), nan_eq_nan_(nan_eq_nan) {}
1826 bool MatchAndExplain(Tuple
args,
1827 MatchResultListener* listener)
const override {
1828 if (max_abs_error_ == -1) {
1829 FloatingEqMatcher<FloatType> fm(::std::get<0>(
args), nan_eq_nan_);
1830 return static_cast<Matcher<FloatType>
>(fm).MatchAndExplain(
1831 ::std::get<1>(
args), listener);
1833 FloatingEqMatcher<FloatType> fm(::std::get<0>(
args), nan_eq_nan_,
1835 return static_cast<Matcher<FloatType>
>(fm).MatchAndExplain(
1836 ::std::get<1>(
args), listener);
1839 void DescribeTo(::std::ostream* os)
const override {
1840 *os <<
"are " << GetDesc;
1842 void DescribeNegationTo(::std::ostream* os)
const override {
1843 *os <<
"aren't " << GetDesc;
1848 const bool nan_eq_nan_;
1851 void Init(
FloatType max_abs_error_val,
bool nan_eq_nan_val) {
1852 max_abs_error_ = max_abs_error_val;
1853 nan_eq_nan_ = nan_eq_nan_val;
1861 template <
typename InnerMatcher>
1862 class PointeeMatcher {
1874 template <
typename Po
inter>
1875 operator Matcher<Pointer>()
const {
1876 return Matcher<Pointer>(
new Impl<const Pointer&>(
matcher_));
1881 template <
typename Po
inter>
1882 class Impl :
public MatcherInterface<Pointer> {
1888 explicit Impl(
const InnerMatcher& matcher)
1889 :
matcher_(MatcherCast<const Pointee&>(matcher)) {}
1891 void DescribeTo(::std::ostream* os)
const override {
1892 *os <<
"points to a value that ";
1897 *os <<
"does not point to a value that ";
1902 MatchResultListener* listener)
const override {
1905 *listener <<
"which points to ";
1910 const Matcher<const Pointee&>
matcher_;
1920 template <
typename InnerMatcher>
1921 class PointerMatcher {
1923 explicit PointerMatcher(
const InnerMatcher& matcher) : matcher_(matcher) {}
1933 template <
typename Po
interType>
1934 operator Matcher<PointerType>()
const {
1935 return Matcher<PointerType>(
new Impl<const PointerType&>(matcher_));
1940 template <
typename Po
interType>
1941 class Impl :
public MatcherInterface<PointerType> {
1945 PointerType)>::element_type*;
1947 explicit Impl(
const InnerMatcher& matcher)
1948 : matcher_(MatcherCast<Pointer>(matcher)) {}
1950 void DescribeTo(::std::ostream* os)
const override {
1951 *os <<
"is a pointer that ";
1952 matcher_.DescribeTo(os);
1955 void DescribeNegationTo(::std::ostream* os)
const override {
1956 *os <<
"is not a pointer that ";
1957 matcher_.DescribeTo(os);
1960 bool MatchAndExplain(PointerType pointer,
1961 MatchResultListener* listener)
const override {
1962 *listener <<
"which is a pointer that ";
1968 Matcher<Pointer> matcher_;
1971 const InnerMatcher matcher_;
1981 template <
typename To>
1982 class WhenDynamicCastToMatcherBase {
2004 *os <<
"when dynamic_cast to " <<
GetToName() <<
", ";
2010 template <
typename To>
2011 class WhenDynamicCastToMatcher :
public WhenDynamicCastToMatcherBase<To> {
2014 : WhenDynamicCastToMatcherBase<To>(matcher) {}
2016 template <
typename From>
2018 To
to =
dynamic_cast<To
>(
from);
2025 template <
typename To>
2026 class WhenDynamicCastToMatcher<To&> :
public WhenDynamicCastToMatcherBase<To&> {
2028 explicit WhenDynamicCastToMatcher(
const Matcher<To&>& matcher)
2029 : WhenDynamicCastToMatcherBase<To&>(matcher) {}
2031 template <
typename From>
2032 bool MatchAndExplain(From&
from, MatchResultListener* listener)
const {
2034 To*
to =
dynamic_cast<To*
>(&
from);
2035 if (
to ==
nullptr) {
2036 *listener <<
"which cannot be dynamic_cast to " << this->GetToName();
2042 #endif // GTEST_HAS_RTTI
2046 template <
typename Class,
typename FieldType>
2047 class FieldMatcher {
2050 const Matcher<const FieldType&>& matcher)
2054 const Matcher<const FieldType&>& matcher)
2057 whose_field_(
"whose field `" + field_name +
"` ") {}
2060 *os <<
"is an object " << whose_field_;
2065 *os <<
"is an object " << whose_field_;
2069 template <
typename T>
2081 MatchResultListener* listener)
const {
2082 *listener << whose_field_ <<
"is ";
2087 MatchResultListener* listener)
const {
2088 if (p ==
nullptr)
return false;
2090 *listener <<
"which points to an object ";
2098 const Matcher<const FieldType&>
matcher_;
2110 template <
typename Class,
typename PropertyType,
typename Property>
2111 class PropertyMatcher {
2113 typedef const PropertyType& RefToConstProperty;
2118 whose_property_(
"whose given property ") {}
2121 const Matcher<RefToConstProperty>& matcher)
2124 whose_property_(
"whose property `" + property_name +
"` ") {}
2127 *os <<
"is an object " << whose_property_;
2132 *os <<
"is an object " << whose_property_;
2136 template <
typename T>
2146 MatchResultListener* listener)
const {
2147 *listener << whose_property_ <<
"is ";
2155 MatchResultListener* listener)
const {
2156 if (p ==
nullptr)
return false;
2158 *listener <<
"which points to an object ";
2166 const Matcher<RefToConstProperty>
matcher_;
2175 template <
typename Functor>
2176 struct CallableTraits {
2181 template <
typename T>
2182 static auto Invoke(Functor f,
const T&
arg) -> decltype(f(
arg)) {
2188 template <
typename ArgType,
typename ResType>
2189 struct CallableTraits<ResType (*)(ArgType)> {
2190 typedef ResType ResultType;
2191 typedef ResType (*StorageType)(ArgType);
2193 static void CheckIsValid(ResType (*
f)(ArgType)) {
2195 <<
"NULL function pointer is passed into ResultOf().";
2197 template <
typename T>
2198 static ResType
Invoke(ResType (*
f)(ArgType),
T arg) {
2205 template <
typename Callable,
typename InnerMatcher>
2206 class ResultOfMatcher {
2213 InnerMatcher matcher)
2214 : result_description_(result_description),
2220 template <
typename T>
2221 operator Matcher<T>()
const {
2229 template <
typename T>
2230 class Impl :
public MatcherInterface<T> {
2232 std::declval<CallableStorageType>(), std::declval<T>()));
2235 template <
typename M>
2238 : result_description_(result_description),
2240 matcher_(MatcherCast<ResultType>(matcher)) {}
2242 void DescribeTo(::std::ostream* os)
const override {
2243 if (result_description_.empty()) {
2244 *os <<
"is mapped by the given callable to a value that ";
2246 *os <<
"whose " << result_description_ <<
" ";
2252 if (result_description_.empty()) {
2253 *os <<
"is mapped by the given callable to a value that ";
2255 *os <<
"whose " << result_description_ <<
" ";
2261 *listener <<
"which is mapped by the given callable to ";
2279 const Matcher<ResultType>
matcher_;
2288 template <
typename SizeMatcher>
2289 class SizeIsMatcher {
2294 template <
typename Container>
2295 operator Matcher<Container>()
const {
2296 return Matcher<Container>(
new Impl<const Container&>(
size_matcher_));
2299 template <
typename Container>
2300 class Impl :
public MatcherInterface<Container> {
2302 using SizeType = decltype(std::declval<Container>().
size());
2303 explicit Impl(
const SizeMatcher& size_matcher)
2306 void DescribeTo(::std::ostream* os)
const override {
2316 MatchResultListener* listener)
const override {
2318 StringMatchResultListener size_listener;
2320 *listener <<
"whose size " <<
size
2321 << (
result ?
" matches" :
" doesn't match");
2336 template <
typename DistanceMatcher>
2337 class BeginEndDistanceIsMatcher {
2342 template <
typename Container>
2343 operator Matcher<Container>()
const {
2347 template <
typename Container>
2348 class Impl :
public MatcherInterface<Container> {
2353 typedef typename std::iterator_traits<
2354 typename ContainerView::type::const_iterator>::difference_type
2356 explicit Impl(
const DistanceMatcher& distance_matcher)
2359 void DescribeTo(::std::ostream* os)
const override {
2360 *os <<
"distance between begin() and end() ";
2364 *os <<
"distance between begin() and end() ";
2369 MatchResultListener* listener)
const override {
2373 StringMatchResultListener distance_listener;
2376 *listener <<
"whose distance between begin() and end() " << distance
2377 << (
result ?
" matches" :
" doesn't match");
2400 template <
typename Container>
2401 class ContainerEqMatcher {
2403 typedef internal::StlContainerView<Container>
View;
2408 "Container type must not be const");
2410 "Container type must not be a reference");
2422 *os <<
"does not equal ";
2426 template <
typename LhsContainer>
2428 MatchResultListener* listener)
const {
2429 typedef internal::StlContainerView<
2433 if (lhs_stl_container ==
expected_)
return true;
2435 ::std::ostream*
const os = listener->stream();
2436 if (os !=
nullptr) {
2438 bool printed_header =
false;
2439 for (
auto it = lhs_stl_container.begin();
it != lhs_stl_container.end();
2443 if (printed_header) {
2446 *os <<
"which has these unexpected elements: ";
2447 printed_header =
true;
2454 bool printed_header2 =
false;
2457 lhs_stl_container.end(),
2458 *
it) == lhs_stl_container.end()) {
2459 if (printed_header2) {
2462 *os << (printed_header ?
",\nand" :
"which")
2463 <<
" doesn't have these expected elements: ";
2464 printed_header2 =
true;
2479 struct LessComparator {
2480 template <
typename T,
typename U>
2481 bool operator()(
const T& lhs,
const U& rhs)
const {
2487 template <
typename Comparator,
typename ContainerMatcher>
2488 class WhenSortedByMatcher {
2491 const ContainerMatcher& matcher)
2494 template <
typename LhsContainer>
2495 operator Matcher<LhsContainer>()
const {
2499 template <
typename LhsContainer>
2500 class Impl :
public MatcherInterface<LhsContainer> {
2513 Impl(
const Comparator& comparator,
const ContainerMatcher& matcher)
2516 void DescribeTo(::std::ostream* os)
const override {
2517 *os <<
"(when sorted) ";
2522 *os <<
"(when sorted) ";
2527 MatchResultListener* listener)
const override {
2529 ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
2530 lhs_stl_container.end());
2531 ::std::sort(sorted_container.begin(), sorted_container.end(),
2534 if (!listener->IsInterested()) {
2537 return matcher_.Matches(sorted_container);
2540 *listener <<
"which is ";
2542 *listener <<
" when sorted";
2544 StringMatchResultListener inner_listener;
2546 matcher_.MatchAndExplain(sorted_container, &inner_listener);
2553 const Matcher<const ::std::vector<LhsValue>&>
matcher_;
2567 template <
typename TupleMatcher,
typename RhsContainer>
2568 class PointwiseMatcher {
2571 use_UnorderedPointwise_with_hash_tables);
2574 typedef internal::StlContainerView<RhsContainer>
RhsView;
2579 "RhsContainer type must not be const");
2581 "RhsContainer type must not be a reference");
2585 PointwiseMatcher(
const TupleMatcher& tuple_matcher,
const RhsContainer& rhs)
2588 template <
typename LhsContainer>
2589 operator Matcher<LhsContainer>()
const {
2592 use_UnorderedPointwise_with_hash_tables);
2594 return Matcher<LhsContainer>(
2598 template <
typename LhsContainer>
2599 class Impl :
public MatcherInterface<LhsContainer> {
2611 typedef ::std::tuple<const LhsValue&, const RhsValue&>
InnerMatcherArg;
2618 void DescribeTo(::std::ostream* os)
const override {
2619 *os <<
"contains " <<
rhs_.size()
2620 <<
" values, where each value and its corresponding value in ";
2626 *os <<
"doesn't contain exactly " <<
rhs_.size()
2627 <<
" values, or contains a value x at some index i"
2628 <<
" where x and the i-th value of ";
2635 MatchResultListener* listener)
const override {
2637 const size_t actual_size = lhs_stl_container.size();
2638 if (actual_size !=
rhs_.size()) {
2639 *listener <<
"which contains " << actual_size <<
" values";
2643 auto left = lhs_stl_container.begin();
2644 auto right =
rhs_.begin();
2645 for (
size_t i = 0;
i != actual_size; ++
i, ++left, ++right) {
2646 if (listener->IsInterested()) {
2647 StringMatchResultListener inner_listener;
2653 ImplicitCast_<const RhsValue&>(*right)),
2655 *listener <<
"where the value pair (";
2659 *listener <<
") at index #" <<
i <<
" don't match";
2666 ImplicitCast_<const RhsValue&>(*right))))
2685 template <
typename Container>
2686 class QuantifierMatcherImpl :
public MatcherInterface<Container> {
2689 typedef StlContainerView<RawContainer>
View;
2694 template <
typename InnerMatcher>
2697 testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
2703 MatchResultListener* listener)
const {
2706 for (
auto it = stl_container.begin();
it != stl_container.end();
2708 StringMatchResultListener inner_listener;
2711 if (matches != all_elements_should_match) {
2712 *listener <<
"whose element #" <<
i
2713 << (matches ?
" matches" :
" doesn't match");
2715 return !all_elements_should_match;
2718 return all_elements_should_match;
2723 MatchResultListener* listener)
const {
2726 std::vector<size_t> match_elements;
2727 for (
auto it = stl_container.begin();
it != stl_container.end();
2729 StringMatchResultListener inner_listener;
2732 match_elements.push_back(
i);
2735 if (listener->IsInterested()) {
2736 if (match_elements.empty()) {
2737 *listener <<
"has no element that matches";
2738 }
else if (match_elements.size() == 1) {
2739 *listener <<
"whose element #" << match_elements[0] <<
" matches";
2741 *listener <<
"whose elements (";
2743 for (
size_t e : match_elements) {
2744 *listener <<
sep << e;
2747 *listener <<
") match";
2750 StringMatchResultListener count_listener;
2751 if (count_matcher.MatchAndExplain(match_elements.size(), &count_listener)) {
2752 *listener <<
" and whose match quantity of " << match_elements.size()
2757 if (match_elements.empty()) {
2758 *listener <<
" and";
2760 *listener <<
" but";
2762 *listener <<
" whose match quantity of " << match_elements.size()
2763 <<
" does not match";
2775 template <
typename Container>
2776 class ContainsMatcherImpl :
public QuantifierMatcherImpl<Container> {
2778 template <
typename InnerMatcher>
2780 : QuantifierMatcherImpl<Container>(inner_matcher) {}
2783 void DescribeTo(::std::ostream* os)
const override {
2784 *os <<
"contains at least one element that ";
2789 *os <<
"doesn't contain any element that ";
2794 MatchResultListener* listener)
const override {
2801 template <
typename Container>
2802 class EachMatcherImpl :
public QuantifierMatcherImpl<Container> {
2804 template <
typename InnerMatcher>
2806 : QuantifierMatcherImpl<Container>(inner_matcher) {}
2809 void DescribeTo(::std::ostream* os)
const override {
2810 *os <<
"only contains elements that ";
2815 *os <<
"contains some element that ";
2820 MatchResultListener* listener)
const override {
2827 template <
typename Container>
2828 class ContainsTimesMatcherImpl :
public QuantifierMatcherImpl<Container> {
2830 template <
typename InnerMatcher>
2831 explicit ContainsTimesMatcherImpl(InnerMatcher inner_matcher,
2832 Matcher<size_t> count_matcher)
2833 : QuantifierMatcherImpl<Container>(inner_matcher),
2834 count_matcher_(
std::move(count_matcher)) {}
2836 void DescribeTo(::std::ostream* os)
const override {
2837 *os <<
"quantity of elements that match ";
2838 this->inner_matcher_.DescribeTo(os);
2840 count_matcher_.DescribeTo(os);
2843 void DescribeNegationTo(::std::ostream* os)
const override {
2844 *os <<
"quantity of elements that match ";
2845 this->inner_matcher_.DescribeTo(os);
2847 count_matcher_.DescribeNegationTo(os);
2850 bool MatchAndExplain(Container
container,
2851 MatchResultListener* listener)
const override {
2852 return this->MatchAndExplainImpl(count_matcher_,
container, listener);
2856 const Matcher<size_t> count_matcher_;
2860 template <
typename M>
2861 class ContainsTimesMatcher {
2863 explicit ContainsTimesMatcher(M
m, Matcher<size_t> count_matcher)
2864 : inner_matcher_(
m), count_matcher_(
std::move(count_matcher)) {}
2866 template <
typename Container>
2867 operator Matcher<Container>()
const {
2868 return Matcher<Container>(
new ContainsTimesMatcherImpl<const Container&>(
2869 inner_matcher_, count_matcher_));
2873 const M inner_matcher_;
2874 const Matcher<size_t> count_matcher_;
2878 template <
typename M>
2879 class ContainsMatcher {
2883 template <
typename Container>
2884 operator Matcher<Container>()
const {
2885 return Matcher<Container>(
2889 ContainsTimesMatcher<M> Times(Matcher<size_t> count_matcher)
const {
2898 template <
typename M>
2903 template <
typename Container>
2904 operator Matcher<Container>()
const {
2905 return Matcher<Container>(
2914 struct Rank0 : Rank1 {};
2916 namespace pair_getters {
2918 template <
typename T>
2919 auto First(
T&
x, Rank1) -> decltype(get<0>(
x)) {
2922 template <
typename T>
2923 auto First(
T&
x, Rank0) -> decltype((
x.first)) {
2927 template <
typename T>
2928 auto Second(
T&
x, Rank1) -> decltype(get<1>(
x)) {
2931 template <
typename T>
2932 auto Second(
T&
x, Rank0) -> decltype((
x.second)) {
2941 template <
typename PairType>
2942 class KeyMatcherImpl :
public MatcherInterface<PairType> {
2945 typedef typename RawPairType::first_type
KeyType;
2947 template <
typename InnerMatcher>
2950 testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {}
2955 MatchResultListener* listener)
const override {
2956 StringMatchResultListener inner_listener;
2958 pair_getters::First(key_value, Rank0()), &inner_listener);
2959 const std::string explanation = inner_listener.str();
2960 if (explanation !=
"") {
2961 *listener <<
"whose first field is a value " << explanation;
2967 void DescribeTo(::std::ostream* os)
const override {
2968 *os <<
"has a key that ";
2974 *os <<
"doesn't have a key that ";
2983 template <
typename M>
2988 template <
typename PairType>
2989 operator Matcher<PairType>()
const {
2990 return Matcher<PairType>(
2999 template <
typename InnerMatcher>
3000 class AddressMatcher {
3002 explicit AddressMatcher(InnerMatcher
m) : matcher_(
m) {}
3004 template <
typename Type>
3005 operator Matcher<Type>()
const {
3006 return Matcher<Type>(
new Impl<const Type&>(matcher_));
3011 template <
typename Type>
3012 class Impl :
public MatcherInterface<Type> {
3015 explicit Impl(
const InnerMatcher& matcher)
3016 : matcher_(MatcherCast<Address>(matcher)) {}
3018 void DescribeTo(::std::ostream* os)
const override {
3019 *os <<
"has address that ";
3020 matcher_.DescribeTo(os);
3023 void DescribeNegationTo(::std::ostream* os)
const override {
3024 *os <<
"does not have address that ";
3025 matcher_.DescribeTo(os);
3028 bool MatchAndExplain(
Type object,
3029 MatchResultListener* listener)
const override {
3030 *listener <<
"which has address ";
3031 Address address = std::addressof(
object);
3036 const Matcher<Address> matcher_;
3038 const InnerMatcher matcher_;
3043 template <
typename PairType>
3044 class PairMatcherImpl :
public MatcherInterface<PairType> {
3047 typedef typename RawPairType::first_type
FirstType;
3048 typedef typename RawPairType::second_type
SecondType;
3050 template <
typename FirstMatcher,
typename SecondMatcher>
3051 PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
3053 testing::SafeMatcherCast<const FirstType&>(first_matcher)),
3055 testing::SafeMatcherCast<const SecondType&>(second_matcher)) {}
3058 void DescribeTo(::std::ostream* os)
const override {
3059 *os <<
"has a first field that ";
3061 *os <<
", and has a second field that ";
3067 *os <<
"has a first field that ";
3069 *os <<
", or has a second field that ";
3076 MatchResultListener* listener)
const override {
3077 if (!listener->IsInterested()) {
3080 return first_matcher_.Matches(pair_getters::First(a_pair, Rank0())) &&
3083 StringMatchResultListener first_inner_listener;
3084 if (!
first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank0()),
3085 &first_inner_listener)) {
3086 *listener <<
"whose first field does not match";
3090 StringMatchResultListener second_inner_listener;
3091 if (!
second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank0()),
3092 &second_inner_listener)) {
3093 *listener <<
"whose second field does not match";
3097 ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
3105 MatchResultListener* listener)
const {
3106 *listener <<
"whose both fields match";
3107 if (first_explanation !=
"") {
3108 *listener <<
", where the first field is a value " << first_explanation;
3110 if (second_explanation !=
"") {
3112 if (first_explanation !=
"") {
3113 *listener <<
"and ";
3115 *listener <<
"where ";
3117 *listener <<
"the second field is a value " << second_explanation;
3126 template <
typename FirstMatcher,
typename SecondMatcher>
3129 PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
3132 template <
typename PairType>
3133 operator Matcher<PairType>()
const {
3134 return Matcher<PairType>(
3143 template <
typename T,
size_t...
I>
3144 auto UnpackStructImpl(
const T& t, IndexSequence<I...>,
int)
3145 -> decltype(std::tie(get<I>(t)...)) {
3147 "Number of arguments doesn't match the number of fields.");
3148 return std::tie(get<I>(t)...);
3151 #if defined(__cpp_structured_bindings) && __cpp_structured_bindings >= 201606
3152 template <
typename T>
3153 auto UnpackStructImpl(
const T& t, MakeIndexSequence<1>,
char) {
3154 const auto& [
a] = t;
3157 template <
typename T>
3158 auto UnpackStructImpl(
const T& t, MakeIndexSequence<2>,
char) {
3159 const auto& [
a,
b] = t;
3160 return std::tie(
a,
b);
3162 template <
typename T>
3163 auto UnpackStructImpl(
const T& t, MakeIndexSequence<3>,
char) {
3164 const auto& [
a,
b, c] = t;
3165 return std::tie(
a,
b, c);
3167 template <
typename T>
3168 auto UnpackStructImpl(
const T& t, MakeIndexSequence<4>,
char) {
3169 const auto& [
a,
b, c, d] = t;
3170 return std::tie(
a,
b, c, d);
3172 template <
typename T>
3173 auto UnpackStructImpl(
const T& t, MakeIndexSequence<5>,
char) {
3174 const auto& [
a,
b, c, d, e] = t;
3175 return std::tie(
a,
b, c, d, e);
3177 template <
typename T>
3178 auto UnpackStructImpl(
const T& t, MakeIndexSequence<6>,
char) {
3179 const auto& [
a,
b, c, d, e, f] = t;
3180 return std::tie(
a,
b, c, d, e, f);
3182 template <
typename T>
3183 auto UnpackStructImpl(
const T& t, MakeIndexSequence<7>,
char) {
3184 const auto& [
a,
b, c, d, e, f,
g] = t;
3185 return std::tie(
a,
b, c, d, e, f,
g);
3187 template <
typename T>
3188 auto UnpackStructImpl(
const T& t, MakeIndexSequence<8>,
char) {
3189 const auto& [
a,
b, c, d, e, f,
g, h] = t;
3190 return std::tie(
a,
b, c, d, e, f,
g, h);
3192 template <
typename T>
3193 auto UnpackStructImpl(
const T& t, MakeIndexSequence<9>,
char) {
3194 const auto& [
a,
b, c, d, e, f,
g, h,
i] = t;
3195 return std::tie(
a,
b, c, d, e, f,
g, h,
i);
3197 template <
typename T>
3198 auto UnpackStructImpl(
const T& t, MakeIndexSequence<10>,
char) {
3199 const auto& [
a,
b, c, d, e, f,
g, h,
i, j] = t;
3200 return std::tie(
a,
b, c, d, e, f,
g, h,
i, j);
3202 template <
typename T>
3203 auto UnpackStructImpl(
const T& t, MakeIndexSequence<11>,
char) {
3204 const auto& [
a,
b, c, d, e, f,
g, h,
i, j,
k] = t;
3205 return std::tie(
a,
b, c, d, e, f,
g, h,
i, j,
k);
3207 template <
typename T>
3208 auto UnpackStructImpl(
const T& t, MakeIndexSequence<12>,
char) {
3209 const auto& [
a,
b, c, d, e, f,
g, h,
i, j,
k, l] = t;
3210 return std::tie(
a,
b, c, d, e, f,
g, h,
i, j,
k, l);
3212 template <
typename T>
3213 auto UnpackStructImpl(
const T& t, MakeIndexSequence<13>,
char) {
3214 const auto& [
a,
b, c, d, e, f,
g, h,
i, j,
k, l,
m] = t;
3215 return std::tie(
a,
b, c, d, e, f,
g, h,
i, j,
k, l,
m);
3217 template <
typename T>
3218 auto UnpackStructImpl(
const T& t, MakeIndexSequence<14>,
char) {
3219 const auto& [
a,
b, c, d, e, f,
g, h,
i, j,
k, l,
m,
n] = t;
3220 return std::tie(
a,
b, c, d, e, f,
g, h,
i, j,
k, l,
m,
n);
3222 template <
typename T>
3223 auto UnpackStructImpl(
const T& t, MakeIndexSequence<15>,
char) {
3224 const auto& [
a,
b, c, d, e, f,
g, h,
i, j,
k, l,
m,
n,
o] = t;
3225 return std::tie(
a,
b, c, d, e, f,
g, h,
i, j,
k, l,
m,
n,
o);
3227 template <
typename T>
3228 auto UnpackStructImpl(
const T& t, MakeIndexSequence<16>,
char) {
3229 const auto& [
a,
b, c, d, e, f,
g, h,
i, j,
k, l,
m,
n,
o, p] = t;
3230 return std::tie(
a,
b, c, d, e, f,
g, h,
i, j,
k, l,
m,
n,
o, p);
3232 #endif // defined(__cpp_structured_bindings)
3234 template <
size_t I,
typename T>
3235 auto UnpackStruct(
const T& t)
3236 -> decltype((UnpackStructImpl)(t, MakeIndexSequence<I>{}, 0)) {
3237 return (UnpackStructImpl)(t, MakeIndexSequence<I>{}, 0);
3243 template <
typename T,
size_t N>
3244 void VariadicExpand(
const T (&)[
N]) {}
3246 template <
typename Struct,
typename StructSize>
3247 class FieldsAreMatcherImpl;
3249 template <
typename Struct,
size_t...
I>
3250 class FieldsAreMatcherImpl<
Struct, IndexSequence<
I...>>
3251 :
public MatcherInterface<Struct> {
3252 using UnpackedType =
3253 decltype(UnpackStruct<
sizeof...(
I)>(std::declval<const Struct&>()));
3254 using MatchersType = std::tuple<
3258 template <
typename Inner>
3259 explicit FieldsAreMatcherImpl(
const Inner&
matchers)
3264 void DescribeTo(::std::ostream* os)
const override {
3265 const char* separator =
"";
3267 {(*os << separator <<
"has field #" <<
I <<
" that ",
3268 std::get<I>(
matchers_).DescribeTo(os), separator =
", and ")...});
3271 void DescribeNegationTo(::std::ostream* os)
const override {
3272 const char* separator =
"";
3273 VariadicExpand({(*os << separator <<
"has field #" <<
I <<
" that ",
3274 std::get<I>(
matchers_).DescribeNegationTo(os),
3275 separator =
", or ")...});
3278 bool MatchAndExplain(
Struct t, MatchResultListener* listener)
const override {
3279 return MatchInternal((UnpackStruct<
sizeof...(
I)>)(t), listener);
3283 bool MatchInternal(UnpackedType tuple, MatchResultListener* listener)
const {
3284 if (!listener->IsInterested()) {
3288 VariadicExpand({good = good && std::get<I>(
matchers_).Matches(
3289 std::get<I>(tuple))...});
3293 size_t failed_pos = ~size_t{};
3295 std::vector<StringMatchResultListener> inner_listener(
sizeof...(
I));
3298 {failed_pos == ~size_t{} && !std::get<I>(
matchers_).MatchAndExplain(
3299 std::get<I>(tuple), &inner_listener[
I])
3302 if (failed_pos != ~
size_t{}) {
3303 *listener <<
"whose field #" << failed_pos <<
" does not match";
3308 *listener <<
"whose all elements match";
3309 const char* separator =
", where";
3313 *listener << separator <<
" field #" <<
index <<
" is a value " <<
str;
3314 separator =
", and";
3324 template <
typename... Inner>
3325 class FieldsAreMatcher {
3329 template <
typename Struct>
3330 operator Matcher<Struct>()
const {
3331 return Matcher<Struct>(
3332 new FieldsAreMatcherImpl<
const Struct&, IndexSequenceFor<Inner...>>(
3341 template <
typename Container>
3342 class ElementsAreMatcherImpl :
public MatcherInterface<Container> {
3345 typedef internal::StlContainerView<RawContainer>
View;
3352 template <
typename InputIter>
3354 while (
first != last) {
3360 void DescribeTo(::std::ostream* os)
const override {
3363 }
else if (
count() == 1) {
3364 *os <<
"has 1 element that ";
3368 for (
size_t i = 0;
i !=
count(); ++
i) {
3369 *os <<
"element #" <<
i <<
" ";
3381 *os <<
"isn't empty";
3386 for (
size_t i = 0;
i !=
count(); ++
i) {
3387 *os <<
"element #" <<
i <<
" ";
3396 MatchResultListener* listener)
const override {
3400 const bool listener_interested = listener->IsInterested();
3403 ::std::vector<std::string> explanations(
count());
3405 auto it = stl_container.begin();
3406 size_t exam_pos = 0;
3407 bool mismatch_found =
false;
3412 for (;
it != stl_container.end() && exam_pos !=
count(); ++
it, ++exam_pos) {
3414 if (listener_interested) {
3415 StringMatchResultListener s;
3417 explanations[exam_pos] = s.str();
3423 mismatch_found =
true;
3432 size_t actual_count = exam_pos;
3433 for (;
it != stl_container.end(); ++
it) {
3437 if (actual_count !=
count()) {
3442 if (listener_interested && (actual_count != 0)) {
3443 *listener <<
"which has " <<
Elements(actual_count);
3448 if (mismatch_found) {
3450 if (listener_interested) {
3451 *listener <<
"whose element #" << exam_pos <<
" doesn't match";
3459 if (listener_interested) {
3460 bool reason_printed =
false;
3461 for (
size_t i = 0;
i !=
count(); ++
i) {
3464 if (reason_printed) {
3465 *listener <<
",\nand ";
3467 *listener <<
"whose element #" <<
i <<
" matches, " << s;
3468 reason_printed =
true;
3482 ::std::vector<Matcher<const Element&>>
matchers_;
3493 num_matchers_(num_matchers),
3494 matched_(num_elements_ * num_matchers_, 0) {}
3496 size_t LhsSize()
const {
return num_elements_; }
3497 size_t RhsSize()
const {
return num_matchers_; }
3498 bool HasEdge(
size_t ilhs,
size_t irhs)
const {
3499 return matched_[SpaceIndex(ilhs, irhs)] == 1;
3501 void SetEdge(
size_t ilhs,
size_t irhs,
bool b) {
3502 matched_[SpaceIndex(ilhs, irhs)] =
b ? 1 : 0;
3515 size_t SpaceIndex(
size_t ilhs,
size_t irhs)
const {
3516 return ilhs * num_matchers_ + irhs;
3519 size_t num_elements_;
3520 size_t num_matchers_;
3525 ::std::vector<char> matched_;
3535 struct UnorderedMatcherRequire {
3539 ExactMatch = Superset | Subset,
3546 class GTEST_API_ UnorderedElementsAreMatcherImplBase {
3548 explicit UnorderedElementsAreMatcherImplBase(
3550 : match_flags_(matcher_flags) {}
3555 typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec;
3558 void DescribeToImpl(::std::ostream* os)
const;
3561 void DescribeNegationToImpl(::std::ostream* os)
const;
3563 bool VerifyMatchMatrix(const ::std::vector<std::string>& element_printouts,
3564 const MatchMatrix& matrix,
3565 MatchResultListener* listener)
const;
3568 MatchResultListener* listener)
const;
3570 MatcherDescriberVec& matcher_describers() {
return matcher_describers_; }
3572 static Message Elements(
size_t n) {
3573 return Message() <<
n <<
" element" << (
n == 1 ?
"" :
"s");
3580 MatcherDescriberVec matcher_describers_;
3585 template <
typename Container>
3586 class UnorderedElementsAreMatcherImpl
3587 :
public MatcherInterface<Container>,
3588 public UnorderedElementsAreMatcherImplBase {
3591 typedef internal::StlContainerView<RawContainer>
View;
3596 template <
typename InputIter>
3598 InputIter
first, InputIter last)
3599 : UnorderedElementsAreMatcherImplBase(matcher_flags) {
3609 void DescribeTo(::std::ostream* os)
const override {
3619 MatchResultListener* listener)
const override {
3621 ::std::vector<std::string> element_printouts;
3622 MatchMatrix matrix =
3624 &element_printouts, listener);
3626 if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
3630 if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
3631 if (matrix.LhsSize() != matrix.RhsSize()) {
3636 if (matrix.LhsSize() != 0 && listener->IsInterested()) {
3637 *listener <<
"which has " <<
Elements(matrix.LhsSize());
3643 return VerifyMatchMatrix(element_printouts, matrix, listener) &&
3648 template <
typename ElementIter>
3649 MatchMatrix
AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
3650 ::std::vector<std::string>* element_printouts,
3651 MatchResultListener* listener)
const {
3652 element_printouts->clear();
3653 ::std::vector<char> did_match;
3655 DummyMatchResultListener
dummy;
3656 for (; elem_first != elem_last; ++
num_elements, ++elem_first) {
3657 if (listener->IsInterested()) {
3660 for (
size_t irhs = 0; irhs !=
matchers_.size(); ++irhs) {
3661 did_match.push_back(
3667 ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
3669 for (
size_t irhs = 0; irhs !=
matchers_.size(); ++irhs) {
3670 matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
3676 ::std::vector<Matcher<const Element&>>
matchers_;
3681 template <
typename Target>
3682 struct CastAndAppendTransform {
3683 template <
typename Arg>
3685 return MatcherCast<Target>(
a);
3690 template <
typename MatcherTuple>
3691 class UnorderedElementsAreMatcher {
3696 template <
typename Container>
3697 operator Matcher<Container>()
const {
3701 typedef ::std::vector<Matcher<const Element&>> MatcherVec;
3706 return Matcher<Container>(
3707 new UnorderedElementsAreMatcherImpl<const Container&>(
3708 UnorderedMatcherRequire::ExactMatch,
matchers.begin(),
3717 template <
typename MatcherTuple>
3718 class ElementsAreMatcher {
3722 template <
typename Container>
3723 operator Matcher<Container>()
const {
3727 use_UnorderedElementsAre_with_hash_tables);
3732 typedef ::std::vector<Matcher<const Element&>> MatcherVec;
3737 return Matcher<Container>(
new ElementsAreMatcherImpl<const Container&>(
3746 template <
typename T>
3747 class UnorderedElementsAreArrayMatcher {
3749 template <
typename Iter>
3754 template <
typename Container>
3755 operator Matcher<Container>()
const {
3756 return Matcher<Container>(
3757 new UnorderedElementsAreMatcherImpl<const Container&>(
3767 template <
typename T>
3768 class ElementsAreArrayMatcher {
3770 template <
typename Iter>
3773 template <
typename Container>
3774 operator Matcher<Container>()
const {
3777 use_UnorderedElementsAreArray_with_hash_tables);
3779 return Matcher<Container>(
new ElementsAreMatcherImpl<const Container&>(
3796 template <
typename Tuple2Matcher,
typename Second>
3797 class BoundSecondMatcher {
3804 template <
typename T>
3805 operator Matcher<T>()
const {
3822 template <
typename T>
3823 class Impl :
public MatcherInterface<T> {
3825 typedef ::std::tuple<T, Second>
ArgTuple;
3831 void DescribeTo(::std::ostream* os)
const override {
3856 template <
typename Tuple2Matcher,
typename Second>
3858 const Tuple2Matcher&
tm,
const Second&
second) {
3859 return BoundSecondMatcher<Tuple2Matcher, Second>(
tm,
second);
3868 bool negation,
const char* matcher_name,
3869 const std::vector<const char*>& param_names,
const Strings& param_values);
3872 template <
typename ValueMatcher>
3873 class OptionalMatcher {
3875 explicit OptionalMatcher(
const ValueMatcher& value_matcher)
3876 : value_matcher_(value_matcher) {}
3878 template <
typename Optional>
3879 operator Matcher<Optional>()
const {
3880 return Matcher<Optional>(
new Impl<const Optional&>(value_matcher_));
3883 template <
typename Optional>
3884 class Impl :
public MatcherInterface<Optional> {
3888 explicit Impl(
const ValueMatcher& value_matcher)
3889 : value_matcher_(MatcherCast<ValueType>(value_matcher)) {}
3891 void DescribeTo(::std::ostream* os)
const override {
3893 value_matcher_.DescribeTo(os);
3896 void DescribeNegationTo(::std::ostream* os)
const override {
3898 value_matcher_.DescribeNegationTo(os);
3901 bool MatchAndExplain(
Optional optional,
3902 MatchResultListener* listener)
const override {
3904 *listener <<
"which is not engaged";
3908 StringMatchResultListener value_listener;
3909 const bool match = value_matcher_.MatchAndExplain(
value, &value_listener);
3911 << (
match ?
" matches" :
" doesn't match");
3917 const Matcher<ValueType> value_matcher_;
3921 const ValueMatcher value_matcher_;
3924 namespace variant_matcher {
3926 template <
typename T>
3928 template <
typename T>
3932 template <
typename T>
3933 class VariantMatcher {
3938 template <
typename Variant>
3939 bool MatchAndExplain(
const Variant&
value,
3943 return holds_alternative<T>(
value) && matcher_.Matches(get<T>(
value));
3946 if (!holds_alternative<T>(
value)) {
3947 *listener <<
"whose value is not of type '" <<
GetTypeName() <<
"'";
3952 StringMatchResultListener elem_listener;
3953 const bool match = matcher_.MatchAndExplain(
elem, &elem_listener);
3955 << (
match ?
" matches" :
" doesn't match");
3960 void DescribeTo(std::ostream* os)
const {
3961 *os <<
"is a variant<> with value of type '" <<
GetTypeName()
3962 <<
"' and the value ";
3963 matcher_.DescribeTo(os);
3966 void DescribeNegationTo(std::ostream* os)
const {
3967 *os <<
"is a variant<> with value of type other than '" <<
GetTypeName()
3968 <<
"' or the value ";
3969 matcher_.DescribeNegationTo(os);
3976 return internal::GetTypeName<T>());
3978 return "the element type";
3981 const ::testing::Matcher<const T&> matcher_;
3986 namespace any_cast_matcher {
3989 template <
typename T>
3993 template <
typename T>
3994 class AnyCastMatcher {
3996 explicit AnyCastMatcher(const ::testing::Matcher<const T&>& matcher)
3997 : matcher_(matcher) {}
3999 template <
typename AnyType>
4000 bool MatchAndExplain(
const AnyType&
value,
4004 return ptr !=
nullptr && matcher_.Matches(*
ptr);
4008 if (
elem ==
nullptr) {
4009 *listener <<
"whose value is not of type '" <<
GetTypeName() <<
"'";
4013 StringMatchResultListener elem_listener;
4014 const bool match = matcher_.MatchAndExplain(*
elem, &elem_listener);
4016 << (
match ?
" matches" :
" doesn't match");
4021 void DescribeTo(std::ostream* os)
const {
4022 *os <<
"is an 'any' type with value of type '" <<
GetTypeName()
4023 <<
"' and the value ";
4024 matcher_.DescribeTo(os);
4027 void DescribeNegationTo(std::ostream* os)
const {
4028 *os <<
"is an 'any' type with value of type other than '" <<
GetTypeName()
4029 <<
"' or the value ";
4030 matcher_.DescribeNegationTo(os);
4037 return internal::GetTypeName<T>());
4039 return "the element type";
4042 const ::testing::Matcher<const T&> matcher_;
4048 template <
class ArgsTuple,
size_t...
k>
4049 class ArgsMatcherImpl :
public MatcherInterface<ArgsTuple> {
4056 template <
typename InnerMatcher>
4058 :
inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
4061 MatchResultListener* listener)
const override {
4065 std::forward_as_tuple(std::get<k>(
args)...);
4066 if (!listener->IsInterested())
return inner_matcher_.Matches(selected_args);
4071 StringMatchResultListener inner_listener;
4078 void DescribeTo(::std::ostream* os)
const override {
4079 *os <<
"are a tuple ";
4085 *os <<
"are a tuple ";
4093 *os <<
"whose fields (";
4094 const char*
sep =
"";
4097 const char*
dummy[] = {
"", (*os <<
sep <<
"#" <<
k,
sep =
", ")...};
4105 template <
class InnerMatcher,
size_t...
k>
4111 template <
typename ArgsTuple>
4112 operator Matcher<ArgsTuple>()
const {
4137 template <
typename Iter>
4138 inline internal::ElementsAreArrayMatcher<
4142 return internal::ElementsAreArrayMatcher<T>(
first, last);
4145 template <
typename T>
4151 template <
typename T,
size_t N>
4157 template <
typename Container>
4163 template <
typename T>
4182 template <
typename Iter>
4183 inline internal::UnorderedElementsAreArrayMatcher<
4187 return internal::UnorderedElementsAreArrayMatcher<T>(
4188 internal::UnorderedMatcherRequire::ExactMatch,
first, last);
4191 template <
typename T>
4193 const T* pointer,
size_t count) {
4197 template <
typename T,
size_t N>
4203 template <
typename Container>
4204 inline internal::UnorderedElementsAreArrayMatcher<
4210 template <
typename T>
4212 ::std::initializer_list<T> xs) {
4225 const internal::AnythingMatcher
_ = {};
4227 template <
typename T>
4228 inline Matcher<T>
A() {
4233 template <
typename T>
4234 inline Matcher<T>
An() {
4238 template <
typename T,
typename M>
4246 inline PolymorphicMatcher<internal::IsNullMatcher>
IsNull() {
4253 inline PolymorphicMatcher<internal::NotNullMatcher>
NotNull() {
4259 template <
typename T>
4260 inline internal::RefMatcher<T&>
Ref(
T&
x) {
4261 return internal::RefMatcher<T&>(
x);
4265 inline PolymorphicMatcher<internal::IsNanMatcher>
IsNan() {
4271 inline internal::FloatingEqMatcher<double>
DoubleEq(
double rhs) {
4272 return internal::FloatingEqMatcher<double>(rhs,
false);
4278 return internal::FloatingEqMatcher<double>(rhs,
true);
4284 inline internal::FloatingEqMatcher<double>
DoubleNear(
double rhs,
4285 double max_abs_error) {
4286 return internal::FloatingEqMatcher<double>(rhs,
false, max_abs_error);
4293 double rhs,
double max_abs_error) {
4294 return internal::FloatingEqMatcher<double>(rhs,
true, max_abs_error);
4299 inline internal::FloatingEqMatcher<float>
FloatEq(
float rhs) {
4300 return internal::FloatingEqMatcher<float>(rhs,
false);
4306 return internal::FloatingEqMatcher<float>(rhs,
true);
4312 inline internal::FloatingEqMatcher<float>
FloatNear(
float rhs,
4313 float max_abs_error) {
4314 return internal::FloatingEqMatcher<float>(rhs,
false, max_abs_error);
4321 float rhs,
float max_abs_error) {
4322 return internal::FloatingEqMatcher<float>(rhs,
true, max_abs_error);
4327 template <
typename InnerMatcher>
4328 inline internal::PointeeMatcher<InnerMatcher>
Pointee(
4329 const InnerMatcher& inner_matcher) {
4330 return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
4340 template <
typename To>
4341 inline PolymorphicMatcher<internal::WhenDynamicCastToMatcher<To>>
4344 internal::WhenDynamicCastToMatcher<To>(inner_matcher));
4346 #endif // GTEST_HAS_RTTI
4352 template <
typename Class,
typename FieldType,
typename FieldMatcher>
4353 inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType>>
Field(
4356 field, MatcherCast<const FieldType&>(matcher)));
4365 template <
typename Class,
typename FieldType,
typename FieldMatcher>
4366 inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType>>
Field(
4368 const FieldMatcher& matcher) {
4370 field_name,
field, MatcherCast<const FieldType&>(matcher)));
4377 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
4378 inline PolymorphicMatcher<internal::PropertyMatcher<
4379 Class, PropertyType, PropertyType (Class::*)()
const>>
4380 Property(PropertyType (Class::*property)()
const,
4381 const PropertyMatcher& matcher) {
4383 internal::PropertyMatcher<Class, PropertyType,
4384 PropertyType (Class::*)()
const>(
4385 property, MatcherCast<const PropertyType&>(matcher)));
4394 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
4395 inline PolymorphicMatcher<internal::PropertyMatcher<
4396 Class, PropertyType, PropertyType (Class::*)()
const>>
4398 PropertyType (Class::*property)()
const,
4399 const PropertyMatcher& matcher) {
4401 internal::PropertyMatcher<Class, PropertyType,
4402 PropertyType (Class::*)()
const>(
4403 property_name, property, MatcherCast<const PropertyType&>(matcher)));
4407 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
4408 inline PolymorphicMatcher<internal::PropertyMatcher<
4409 Class, PropertyType, PropertyType (Class::*)()
const&>>
4410 Property(PropertyType (Class::*property)()
const&,
4411 const PropertyMatcher& matcher) {
4413 internal::PropertyMatcher<Class, PropertyType,
4414 PropertyType (Class::*)()
const&>(
4415 property, MatcherCast<const PropertyType&>(matcher)));
4419 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
4420 inline PolymorphicMatcher<internal::PropertyMatcher<
4421 Class, PropertyType, PropertyType (Class::*)()
const&>>
4423 PropertyType (Class::*property)()
const&,
4424 const PropertyMatcher& matcher) {
4426 internal::PropertyMatcher<Class, PropertyType,
4427 PropertyType (Class::*)()
const&>(
4428 property_name, property, MatcherCast<const PropertyType&>(matcher)));
4439 template <
typename Callable,
typename InnerMatcher>
4440 internal::ResultOfMatcher<Callable, InnerMatcher>
ResultOf(
4441 Callable callable, InnerMatcher matcher) {
4442 return internal::ResultOfMatcher<Callable, InnerMatcher>(
std::move(callable),
4448 template <
typename Callable,
typename InnerMatcher>
4449 internal::ResultOfMatcher<Callable, InnerMatcher>
ResultOf(
4450 const std::string& result_description, Callable callable,
4451 InnerMatcher matcher) {
4452 return internal::ResultOfMatcher<Callable, InnerMatcher>(
4459 template <
typename T = std::
string>
4460 PolymorphicMatcher<internal::StrEqualityMatcher<std::string>>
StrEq(
4461 const internal::StringLike<T>&
str) {
4463 internal::StrEqualityMatcher<std::string>(
std::string(
str),
true,
true));
4467 template <
typename T = std::
string>
4468 PolymorphicMatcher<internal::StrEqualityMatcher<std::string>>
StrNe(
4469 const internal::StringLike<T>&
str) {
4471 internal::StrEqualityMatcher<std::string>(
std::string(
str),
false,
true));
4475 template <
typename T = std::
string>
4476 PolymorphicMatcher<internal::StrEqualityMatcher<std::string>>
StrCaseEq(
4477 const internal::StringLike<T>&
str) {
4479 internal::StrEqualityMatcher<std::string>(
std::string(
str),
true,
false));
4483 template <
typename T = std::
string>
4484 PolymorphicMatcher<internal::StrEqualityMatcher<std::string>>
StrCaseNe(
4485 const internal::StringLike<T>&
str) {
4492 template <
typename T = std::
string>
4493 PolymorphicMatcher<internal::HasSubstrMatcher<std::string>>
HasSubstr(
4494 const internal::StringLike<T>& substring) {
4496 internal::HasSubstrMatcher<std::string>(
std::string(substring)));
4500 template <
typename T = std::
string>
4501 PolymorphicMatcher<internal::StartsWithMatcher<std::string>>
StartsWith(
4502 const internal::StringLike<T>&
prefix) {
4508 template <
typename T = std::
string>
4509 PolymorphicMatcher<internal::EndsWithMatcher<std::string>>
EndsWith(
4510 const internal::StringLike<T>&
suffix) {
4515 #if GTEST_HAS_STD_WSTRING
4519 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring>>
StrEq(
4522 internal::StrEqualityMatcher<std::wstring>(
str,
true,
true));
4526 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring>>
StrNe(
4529 internal::StrEqualityMatcher<std::wstring>(
str,
false,
true));
4533 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring>>
StrCaseEq(
4536 internal::StrEqualityMatcher<std::wstring>(
str,
true,
false));
4540 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring>>
StrCaseNe(
4543 internal::StrEqualityMatcher<std::wstring>(
str,
false,
false));
4548 inline PolymorphicMatcher<internal::HasSubstrMatcher<std::wstring>>
HasSubstr(
4551 internal::HasSubstrMatcher<std::wstring>(substring));
4555 inline PolymorphicMatcher<internal::StartsWithMatcher<std::wstring>>
StartsWith(
4558 internal::StartsWithMatcher<std::wstring>(
prefix));
4562 inline PolymorphicMatcher<internal::EndsWithMatcher<std::wstring>>
EndsWith(
4565 internal::EndsWithMatcher<std::wstring>(
suffix));
4568 #endif // GTEST_HAS_STD_WSTRING
4572 inline internal::Eq2Matcher
Eq() {
return internal::Eq2Matcher(); }
4576 inline internal::Ge2Matcher
Ge() {
return internal::Ge2Matcher(); }
4580 inline internal::Gt2Matcher
Gt() {
return internal::Gt2Matcher(); }
4584 inline internal::Le2Matcher
Le() {
return internal::Le2Matcher(); }
4588 inline internal::Lt2Matcher
Lt() {
return internal::Lt2Matcher(); }
4592 inline internal::Ne2Matcher
Ne() {
return internal::Ne2Matcher(); }
4596 inline internal::FloatingEq2Matcher<float>
FloatEq() {
4597 return internal::FloatingEq2Matcher<float>();
4602 inline internal::FloatingEq2Matcher<double>
DoubleEq() {
4603 return internal::FloatingEq2Matcher<double>();
4609 return internal::FloatingEq2Matcher<float>(
true);
4615 return internal::FloatingEq2Matcher<double>(
true);
4620 inline internal::FloatingEq2Matcher<float>
FloatNear(
float max_abs_error) {
4621 return internal::FloatingEq2Matcher<float>(max_abs_error);
4626 inline internal::FloatingEq2Matcher<double>
DoubleNear(
double max_abs_error) {
4627 return internal::FloatingEq2Matcher<double>(max_abs_error);
4634 float max_abs_error) {
4635 return internal::FloatingEq2Matcher<float>(max_abs_error,
true);
4642 double max_abs_error) {
4643 return internal::FloatingEq2Matcher<double>(max_abs_error,
true);
4648 template <
typename InnerMatcher>
4649 inline internal::NotMatcher<InnerMatcher>
Not(InnerMatcher
m) {
4650 return internal::NotMatcher<InnerMatcher>(
m);
4656 template <
typename Predicate>
4657 inline PolymorphicMatcher<internal::TrulyMatcher<Predicate>>
Truly(
4668 template <
typename SizeMatcher>
4669 inline internal::SizeIsMatcher<SizeMatcher>
SizeIs(
4670 const SizeMatcher& size_matcher) {
4671 return internal::SizeIsMatcher<SizeMatcher>(size_matcher);
4679 template <
typename DistanceMatcher>
4681 const DistanceMatcher& distance_matcher) {
4682 return internal::BeginEndDistanceIsMatcher<DistanceMatcher>(distance_matcher);
4689 template <
typename Container>
4690 inline PolymorphicMatcher<
4698 template <
typename Comparator,
typename ContainerMatcher>
4699 inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher>
WhenSortedBy(
4700 const Comparator& comparator,
const ContainerMatcher& container_matcher) {
4701 return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>(
4702 comparator, container_matcher);
4707 template <
typename ContainerMatcher>
4708 inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
4709 WhenSorted(
const ContainerMatcher& container_matcher) {
4710 return internal::WhenSortedByMatcher<internal::LessComparator,
4712 internal::LessComparator(), container_matcher);
4721 template <
typename TupleMatcher,
typename Container>
4722 inline internal::PointwiseMatcher<TupleMatcher,
4724 Pointwise(
const TupleMatcher& tuple_matcher,
const Container& rhs) {
4725 return internal::PointwiseMatcher<TupleMatcher, Container>(tuple_matcher,
4730 template <
typename TupleMatcher,
typename T>
4731 inline internal::PointwiseMatcher<TupleMatcher, std::vector<T>>
Pointwise(
4732 const TupleMatcher& tuple_matcher, std::initializer_list<T> rhs) {
4733 return Pointwise(tuple_matcher, std::vector<T>(rhs));
4747 template <
typename Tuple2Matcher,
typename RhsContainer>
4748 inline internal::UnorderedElementsAreArrayMatcher<
4749 typename internal::BoundSecondMatcher<
4751 typename internal::StlContainerView<
4754 const RhsContainer& rhs_container) {
4757 typedef typename internal::StlContainerView<RhsContainer> RhsView;
4760 const RhsStlContainer& rhs_stl_container =
4764 ::std::vector<internal::BoundSecondMatcher<Tuple2Matcher, Second>>
matchers;
4765 for (
auto it = rhs_stl_container.begin();
it != rhs_stl_container.end();
4775 template <
typename Tuple2Matcher,
typename T>
4776 inline internal::UnorderedElementsAreArrayMatcher<
4777 typename internal::BoundSecondMatcher<Tuple2Matcher, T>>
4779 std::initializer_list<T> rhs) {
4814 template <
typename M>
4815 inline internal::ContainsMatcher<M>
Contains(M matcher) {
4816 return internal::ContainsMatcher<M>(matcher);
4846 template <
typename Iter>
4847 inline internal::UnorderedElementsAreArrayMatcher<
4851 return internal::UnorderedElementsAreArrayMatcher<T>(
4852 internal::UnorderedMatcherRequire::Superset,
first, last);
4855 template <
typename T>
4856 inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
4857 const T* pointer,
size_t count) {
4858 return IsSupersetOf(pointer, pointer +
count);
4861 template <
typename T,
size_t N>
4862 inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
4864 return IsSupersetOf(
array,
N);
4867 template <
typename Container>
4868 inline internal::UnorderedElementsAreArrayMatcher<
4870 IsSupersetOf(
const Container&
container) {
4874 template <
typename T>
4875 inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
4876 ::std::initializer_list<T> xs) {
4877 return IsSupersetOf(xs.begin(), xs.end());
4903 template <
typename Iter>
4904 inline internal::UnorderedElementsAreArrayMatcher<
4908 return internal::UnorderedElementsAreArrayMatcher<T>(
4909 internal::UnorderedMatcherRequire::Subset,
first, last);
4912 template <
typename T>
4913 inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
4914 const T* pointer,
size_t count) {
4915 return IsSubsetOf(pointer, pointer +
count);
4918 template <
typename T,
size_t N>
4919 inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
4921 return IsSubsetOf(
array,
N);
4924 template <
typename Container>
4925 inline internal::UnorderedElementsAreArrayMatcher<
4927 IsSubsetOf(
const Container&
container) {
4931 template <
typename T>
4932 inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
4933 ::std::initializer_list<T> xs) {
4934 return IsSubsetOf(xs.begin(), xs.end());
4964 template <
typename M>
4965 inline internal::EachMatcher<M>
Each(M matcher) {
4966 return internal::EachMatcher<M>(matcher);
4972 template <
typename M>
4973 inline internal::KeyMatcher<M>
Key(M inner_matcher) {
4974 return internal::KeyMatcher<M>(inner_matcher);
4982 template <
typename FirstMatcher,
typename SecondMatcher>
4983 inline internal::PairMatcher<FirstMatcher, SecondMatcher>
Pair(
4984 FirstMatcher first_matcher, SecondMatcher second_matcher) {
4985 return internal::PairMatcher<FirstMatcher, SecondMatcher>(first_matcher,
4995 template <
typename MatcherTrue,
typename MatcherFalse>
4996 internal::ConditionalMatcher<MatcherTrue, MatcherFalse> Conditional(
4997 bool condition, MatcherTrue matcher_true, MatcherFalse matcher_false) {
4998 return internal::ConditionalMatcher<MatcherTrue, MatcherFalse>(
5006 template <
typename... M>
5015 template <
typename InnerMatcher>
5016 inline internal::PointerMatcher<InnerMatcher>
Pointer(
5017 const InnerMatcher& inner_matcher) {
5018 return internal::PointerMatcher<InnerMatcher>(inner_matcher);
5023 template <
typename InnerMatcher>
5024 inline internal::AddressMatcher<InnerMatcher>
Address(
5025 const InnerMatcher& inner_matcher) {
5026 return internal::AddressMatcher<InnerMatcher>(inner_matcher);
5031 template <
typename MatcherType>
5032 internal::WhenBase64UnescapedMatcher WhenBase64Unescaped(
5033 const MatcherType& internal_matcher) {
5034 return internal::WhenBase64UnescapedMatcher(internal_matcher);
5040 template <
typename M>
5041 inline internal::MatcherAsPredicate<M>
Matches(M matcher) {
5042 return internal::MatcherAsPredicate<M>(matcher);
5046 template <
typename T,
typename M>
5053 template <
typename T,
typename M>
5055 MatchResultListener* listener) {
5056 return SafeMatcherCast<const T&>(matcher).MatchAndExplain(
value, listener);
5069 template <
typename T,
typename M>
5070 std::string DescribeMatcher(
const M& matcher,
bool negation =
false) {
5071 ::std::stringstream ss;
5072 Matcher<T> monomorphic_matcher = SafeMatcherCast<T>(matcher);
5074 monomorphic_matcher.DescribeNegationTo(&ss);
5076 monomorphic_matcher.DescribeTo(&ss);
5081 template <
typename...
Args>
5082 internal::ElementsAreMatcher<
5085 return internal::ElementsAreMatcher<
5090 template <
typename...
Args>
5091 internal::UnorderedElementsAreMatcher<
5094 return internal::UnorderedElementsAreMatcher<
5100 template <
typename...
Args>
5107 template <
typename...
Args>
5136 template <
typename Iter>
5137 inline internal::AnyOfArrayMatcher<
5140 return internal::AnyOfArrayMatcher<
5144 template <
typename Iter>
5145 inline internal::AllOfArrayMatcher<
5148 return internal::AllOfArrayMatcher<
5152 template <
typename T>
5153 inline internal::AnyOfArrayMatcher<T> AnyOfArray(
const T*
ptr,
size_t count) {
5157 template <
typename T>
5158 inline internal::AllOfArrayMatcher<T> AllOfArray(
const T*
ptr,
size_t count) {
5162 template <
typename T,
size_t N>
5163 inline internal::AnyOfArrayMatcher<T> AnyOfArray(
const T (&
array)[
N]) {
5164 return AnyOfArray(
array,
N);
5167 template <
typename T,
size_t N>
5168 inline internal::AllOfArrayMatcher<T> AllOfArray(
const T (&
array)[
N]) {
5169 return AllOfArray(
array,
N);
5172 template <
typename Container>
5173 inline internal::AnyOfArrayMatcher<typename Container::value_type> AnyOfArray(
5178 template <
typename Container>
5179 inline internal::AllOfArrayMatcher<typename Container::value_type> AllOfArray(
5184 template <
typename T>
5185 inline internal::AnyOfArrayMatcher<T> AnyOfArray(
5186 ::std::initializer_list<T> xs) {
5187 return AnyOfArray(xs.begin(), xs.end());
5190 template <
typename T>
5191 inline internal::AllOfArrayMatcher<T> AllOfArray(
5192 ::std::initializer_list<T> xs) {
5193 return AllOfArray(xs.begin(), xs.end());
5199 template <
size_t...
k,
typename InnerMatcher>
5201 InnerMatcher&& matcher) {
5203 std::forward<InnerMatcher>(matcher));
5213 template <
typename InnerMatcher>
5214 inline InnerMatcher
AllArgs(
const InnerMatcher& matcher) {
5226 template <
typename ValueMatcher>
5227 inline internal::OptionalMatcher<ValueMatcher>
Optional(
5228 const ValueMatcher& value_matcher) {
5229 return internal::OptionalMatcher<ValueMatcher>(value_matcher);
5233 template <
typename T>
5234 PolymorphicMatcher<internal::any_cast_matcher::AnyCastMatcher<T>> AnyWith(
5235 const Matcher<const T&>& matcher) {
5237 internal::any_cast_matcher::AnyCastMatcher<T>(matcher));
5244 template <
typename T>
5245 PolymorphicMatcher<internal::variant_matcher::VariantMatcher<T>> VariantWith(
5246 const Matcher<const T&>& matcher) {
5248 internal::variant_matcher::VariantMatcher<T>(matcher));
5251 #if GTEST_HAS_EXCEPTIONS
5257 class WithWhatMatcherImpl {
5259 WithWhatMatcherImpl(Matcher<std::string> matcher)
5262 void DescribeTo(std::ostream* os)
const {
5263 *os <<
"contains .what() that ";
5264 matcher_.DescribeTo(os);
5267 void DescribeNegationTo(std::ostream* os)
const {
5268 *os <<
"contains .what() that does not ";
5269 matcher_.DescribeTo(os);
5272 template <
typename Err>
5273 bool MatchAndExplain(
const Err&
err, MatchResultListener* listener)
const {
5274 *listener <<
"which contains .what() (of value = " <<
err.what()
5276 return matcher_.MatchAndExplain(
err.what(), listener);
5280 const Matcher<std::string> matcher_;
5283 inline PolymorphicMatcher<WithWhatMatcherImpl> WithWhat(
5284 Matcher<std::string>
m) {
5288 template <
typename Err>
5289 class ExceptionMatcherImpl {
5292 const char* what()
const noexcept {
5293 return "this exception should never be thrown";
5318 using DefaultExceptionType =
typename std::conditional<
5319 std::is_same<
typename std::remove_cv<
5322 const NeverThrown&,
const std::exception&>
::type;
5325 ExceptionMatcherImpl(Matcher<const Err&> matcher)
5328 void DescribeTo(std::ostream* os)
const {
5329 *os <<
"throws an exception which is a " << GetTypeName<Err>();
5331 matcher_.DescribeTo(os);
5334 void DescribeNegationTo(std::ostream* os)
const {
5335 *os <<
"throws an exception which is not a " << GetTypeName<Err>();
5337 matcher_.DescribeNegationTo(os);
5340 template <
typename T>
5341 bool MatchAndExplain(
T&&
x, MatchResultListener* listener)
const {
5343 (void)(std::forward<T>(
x)());
5344 }
catch (
const Err&
err) {
5345 *listener <<
"throws an exception which is a " << GetTypeName<Err>();
5347 return matcher_.MatchAndExplain(
err, listener);
5348 }
catch (DefaultExceptionType
err) {
5350 *listener <<
"throws an exception of type " <<
GetTypeName(
typeid(
err));
5353 *listener <<
"throws an std::exception-derived type ";
5355 *listener <<
"with description \"" <<
err.what() <<
"\"";
5358 *listener <<
"throws an exception of an unknown type";
5362 *listener <<
"does not throw any exception";
5367 const Matcher<const Err&> matcher_;
5394 template <
typename Err>
5395 PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> Throws() {
5400 template <
typename Err,
typename ExceptionMatcher>
5401 PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> Throws(
5402 const ExceptionMatcher& exception_matcher) {
5407 SafeMatcherCast<const Err&>(exception_matcher)));
5410 template <
typename Err,
typename MessageMatcher>
5411 PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> ThrowsMessage(
5412 MessageMatcher&& message_matcher) {
5414 "expected an std::exception-derived type");
5415 return Throws<Err>(internal::WithWhat(
5416 MatcherCast<std::string>(std::forward<MessageMatcher>(message_matcher))));
5419 #endif // GTEST_HAS_EXCEPTIONS
5425 #define ASSERT_THAT(value, matcher) \
5426 ASSERT_PRED_FORMAT1( \
5427 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
5428 #define EXPECT_THAT(value, matcher) \
5429 EXPECT_PRED_FORMAT1( \
5430 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
5433 #define MATCHER(name, description) \
5434 class name##Matcher \
5435 : public ::testing::internal::MatcherBaseImpl<name##Matcher> { \
5437 template <typename arg_type> \
5438 class gmock_Impl : public ::testing::MatcherInterface<const arg_type&> { \
5441 bool MatchAndExplain( \
5442 const arg_type& arg, \
5443 ::testing::MatchResultListener* result_listener) const override; \
5444 void DescribeTo(::std::ostream* gmock_os) const override { \
5445 *gmock_os << FormatDescription(false); \
5447 void DescribeNegationTo(::std::ostream* gmock_os) const override { \
5448 *gmock_os << FormatDescription(true); \
5452 ::std::string FormatDescription(bool negation) const { \
5454 ::std::string gmock_description = (description); \
5455 if (!gmock_description.empty()) { \
5456 return gmock_description; \
5458 return ::testing::internal::FormatMatcherDescription(negation, #name, \
5463 GTEST_ATTRIBUTE_UNUSED_ inline name##Matcher name() { return {}; } \
5464 template <typename arg_type> \
5465 bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain( \
5466 const arg_type& arg, \
5467 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_) \
5470 #define MATCHER_P(name, p0, description) \
5471 GMOCK_INTERNAL_MATCHER(name, name##MatcherP, description, (#p0), (p0))
5472 #define MATCHER_P2(name, p0, p1, description) \
5473 GMOCK_INTERNAL_MATCHER(name, name##MatcherP2, description, (#p0, #p1), \
5475 #define MATCHER_P3(name, p0, p1, p2, description) \
5476 GMOCK_INTERNAL_MATCHER(name, name##MatcherP3, description, (#p0, #p1, #p2), \
5478 #define MATCHER_P4(name, p0, p1, p2, p3, description) \
5479 GMOCK_INTERNAL_MATCHER(name, name##MatcherP4, description, \
5480 (#p0, #p1, #p2, #p3), (p0, p1, p2, p3))
5481 #define MATCHER_P5(name, p0, p1, p2, p3, p4, description) \
5482 GMOCK_INTERNAL_MATCHER(name, name##MatcherP5, description, \
5483 (#p0, #p1, #p2, #p3, #p4), (p0, p1, p2, p3, p4))
5484 #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description) \
5485 GMOCK_INTERNAL_MATCHER(name, name##MatcherP6, description, \
5486 (#p0, #p1, #p2, #p3, #p4, #p5), \
5487 (p0, p1, p2, p3, p4, p5))
5488 #define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description) \
5489 GMOCK_INTERNAL_MATCHER(name, name##MatcherP7, description, \
5490 (#p0, #p1, #p2, #p3, #p4, #p5, #p6), \
5491 (p0, p1, p2, p3, p4, p5, p6))
5492 #define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description) \
5493 GMOCK_INTERNAL_MATCHER(name, name##MatcherP8, description, \
5494 (#p0, #p1, #p2, #p3, #p4, #p5, #p6, #p7), \
5495 (p0, p1, p2, p3, p4, p5, p6, p7))
5496 #define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description) \
5497 GMOCK_INTERNAL_MATCHER(name, name##MatcherP9, description, \
5498 (#p0, #p1, #p2, #p3, #p4, #p5, #p6, #p7, #p8), \
5499 (p0, p1, p2, p3, p4, p5, p6, p7, p8))
5500 #define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description) \
5501 GMOCK_INTERNAL_MATCHER(name, name##MatcherP10, description, \
5502 (#p0, #p1, #p2, #p3, #p4, #p5, #p6, #p7, #p8, #p9), \
5503 (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9))
5505 #define GMOCK_INTERNAL_MATCHER(name, full_name, description, arg_names, args) \
5506 template <GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args)> \
5507 class full_name : public ::testing::internal::MatcherBaseImpl< \
5508 full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>> { \
5510 using full_name::MatcherBaseImpl::MatcherBaseImpl; \
5511 template <typename arg_type> \
5512 class gmock_Impl : public ::testing::MatcherInterface<const arg_type&> { \
5514 explicit gmock_Impl(GMOCK_INTERNAL_MATCHER_FUNCTION_ARGS(args)) \
5515 : GMOCK_INTERNAL_MATCHER_FORWARD_ARGS(args) {} \
5516 bool MatchAndExplain( \
5517 const arg_type& arg, \
5518 ::testing::MatchResultListener* result_listener) const override; \
5519 void DescribeTo(::std::ostream* gmock_os) const override { \
5520 *gmock_os << FormatDescription(false); \
5522 void DescribeNegationTo(::std::ostream* gmock_os) const override { \
5523 *gmock_os << FormatDescription(true); \
5525 GMOCK_INTERNAL_MATCHER_MEMBERS(args) \
5528 ::std::string FormatDescription(bool negation) const { \
5529 ::std::string gmock_description = (description); \
5530 if (!gmock_description.empty()) { \
5531 return gmock_description; \
5533 return ::testing::internal::FormatMatcherDescription( \
5534 negation, #name, {GMOCK_PP_REMOVE_PARENS(arg_names)}, \
5535 ::testing::internal::UniversalTersePrintTupleFieldsToStrings( \
5536 ::std::tuple<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>( \
5537 GMOCK_INTERNAL_MATCHER_MEMBERS_USAGE(args)))); \
5541 template <GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args)> \
5542 inline full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)> name( \
5543 GMOCK_INTERNAL_MATCHER_FUNCTION_ARGS(args)) { \
5544 return full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>( \
5545 GMOCK_INTERNAL_MATCHER_ARGS_USAGE(args)); \
5547 template <GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args)> \
5548 template <typename arg_type> \
5549 bool full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>::gmock_Impl< \
5550 arg_type>::MatchAndExplain(const arg_type& arg, \
5551 ::testing::MatchResultListener* \
5552 result_listener GTEST_ATTRIBUTE_UNUSED_) \
5555 #define GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args) \
5557 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAM, , args))
5558 #define GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAM(i_unused, data_unused, arg) \
5559 , typename arg##_type
5561 #define GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args) \
5562 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_TYPE_PARAM, , args))
5563 #define GMOCK_INTERNAL_MATCHER_TYPE_PARAM(i_unused, data_unused, arg) \
5566 #define GMOCK_INTERNAL_MATCHER_FUNCTION_ARGS(args) \
5567 GMOCK_PP_TAIL(dummy_first GMOCK_PP_FOR_EACH( \
5568 GMOCK_INTERNAL_MATCHER_FUNCTION_ARG, , args))
5569 #define GMOCK_INTERNAL_MATCHER_FUNCTION_ARG(i, data_unused, arg) \
5570 , arg##_type gmock_p##i
5572 #define GMOCK_INTERNAL_MATCHER_FORWARD_ARGS(args) \
5573 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_FORWARD_ARG, , args))
5574 #define GMOCK_INTERNAL_MATCHER_FORWARD_ARG(i, data_unused, arg) \
5575 , arg(::std::forward<arg##_type>(gmock_p##i))
5577 #define GMOCK_INTERNAL_MATCHER_MEMBERS(args) \
5578 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_MEMBER, , args)
5579 #define GMOCK_INTERNAL_MATCHER_MEMBER(i_unused, data_unused, arg) \
5580 const arg##_type arg;
5582 #define GMOCK_INTERNAL_MATCHER_MEMBERS_USAGE(args) \
5583 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_MEMBER_USAGE, , args))
5584 #define GMOCK_INTERNAL_MATCHER_MEMBER_USAGE(i_unused, data_unused, arg) , arg
5586 #define GMOCK_INTERNAL_MATCHER_ARGS_USAGE(args) \
5587 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_ARG_USAGE, , args))
5588 #define GMOCK_INTERNAL_MATCHER_ARG_USAGE(i, data_unused, arg_unused) \
5592 using namespace no_adl;
5601 #include "gmock/internal/custom/gmock-matchers.h"
5603 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_