38 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
39 #define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
55 #if GTEST_HAS_STD_INITIALIZER_LIST_
56 # include <initializer_list>
142 template <
typename T>
203 template <
typename A,
typename B>
207 template <
typename A,
typename B>
211 template <
typename A,
typename B>
215 template <
typename A,
typename B>
219 template <
typename A,
typename B>
223 template <
typename A,
typename B>
251 template <
typename T>
257 return impl_->MatchAndExplain(x, listener);
271 impl_->DescribeNegationTo(os);
318 template <
typename T>
345 : internal::MatcherBase<const internal::
string&>(impl) {}
362 : internal::MatcherBase<internal::
string>(impl) {}
372 #if GTEST_HAS_STRING_PIECE_
378 :
public internal::MatcherBase<const StringPiece&> {
382 explicit Matcher(
const MatcherInterface<const StringPiece&>* impl)
383 : internal::MatcherBase<const StringPiece&>(impl) {}
390 Matcher(
const char*
s);
393 Matcher(StringPiece
s);
398 :
public internal::MatcherBase<StringPiece> {
402 explicit Matcher(
const MatcherInterface<StringPiece>* impl)
403 : internal::MatcherBase<StringPiece>(impl) {}
410 Matcher(
const char*
s);
413 Matcher(StringPiece
s);
415 #endif // GTEST_HAS_STRING_PIECE_
429 template <
class Impl>
442 template <
typename T>
448 template <
typename T>
454 impl_.DescribeTo(os);
458 impl_.DescribeNegationTo(os);
462 return impl_.MatchAndExplain(x, listener);
483 template <
typename T>
495 template <
class Impl>
514 template <
typename T,
typename M>
532 polymorphic_matcher_or_value,
555 return polymorphic_matcher_or_value;
562 template <
typename T,
typename U>
573 : source_matcher_(source_matcher) {}
577 return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
581 source_matcher_.DescribeTo(os);
585 source_matcher_.DescribeNegationTo(os);
597 template <
typename T>
609 template <
typename T,
typename M>
621 template <
typename T>
626 template <
typename M>
640 template <
typename U>
644 T_must_be_implicitly_convertible_to_U);
649 cannot_convert_non_referentce_arg_to_reference);
657 kTIsOther || kUIsOther ||
659 conversion_of_arithmetic_types_must_be_lossless);
660 return MatcherCast<T>(matcher);
664 template <
typename T,
typename M>
670 template <
typename T>
679 ::std::ostream*
os) {
680 if (explanation !=
"" && os != NULL) {
681 *os <<
", " << explanation;
691 return (type_name.length() <= 20 ||
692 type_name.find_first_of(
"<(") == string::npos);
700 template <
typename Value,
typename T>
714 const string& type_name = GetTypeName<Value>();
716 *listener->
stream() <<
" (of type " << type_name <<
")";
731 template <
typename MatcherTuple,
typename ValueTuple>
733 const ValueTuple& value_tuple) {
735 &&
get<
N - 1>(matcher_tuple).
Matches(get<N - 1>(value_tuple));
742 template <
typename MatcherTuple,
typename ValueTuple>
745 ::std::ostream*
os) {
752 get<N - 1>(matchers);
753 typedef typename tuple_element<N - 1, ValueTuple>
::type Value;
756 if (!matcher.MatchAndExplain(value, &listener)) {
759 *os <<
" Expected arg #" << N - 1 <<
": ";
760 get<N - 1>(matchers).DescribeTo(os);
761 *os <<
"\n Actual: ";
778 template <
typename MatcherTuple,
typename ValueTuple>
780 const ValueTuple& ) {
784 template <
typename MatcherTuple,
typename ValueTuple>
795 template <
typename MatcherTuple,
typename ValueTuple>
797 const ValueTuple& value_tuple) {
802 matcher_and_value_have_different_numbers_of_fields);
804 Matches(matcher_tuple, value_tuple);
809 template <
typename MatcherTuple,
typename ValueTuple>
812 ::std::ostream*
os) {
814 matchers, values, os);
821 template <
typename Tuple,
typename Func,
typename OutIter>
829 static OutIter
Run(Func
f,
const Tuple&
t, OutIter
out) {
834 template <
typename Tup,
size_t kRemainingSize>
837 *out++ =
f(::testing::get<TupleSize::value - kRemainingSize>(t));
841 template <
typename Tup>
852 template <
typename Tuple,
typename Func,
typename OutIter>
858 template <
typename T>
863 virtual void DescribeTo(::std::ostream*
os)
const { *os <<
"is anything"; }
868 *os <<
"never matches";
878 template <
typename T>
892 template <
typename D,
typename Rhs,
typename Op>
896 template <
typename Lhs>
902 template <
typename Lhs>
911 *os << D::Desc() <<
" ";
915 *os << D::NegatedDesc() <<
" ";
926 template <
typename Rhs>
931 static const char*
Desc() {
return "is equal to"; }
934 template <
typename Rhs>
939 static const char*
Desc() {
return "isn't equal to"; }
942 template <
typename Rhs>
947 static const char*
Desc() {
return "is <"; }
950 template <
typename Rhs>
955 static const char*
Desc() {
return "is >"; }
958 template <
typename Rhs>
963 static const char*
Desc() {
return "is <="; }
966 template <
typename Rhs>
971 static const char*
Desc() {
return "is >="; }
979 template <
typename Po
inter>
984 #else // GTEST_LANG_CXX11
986 #endif // GTEST_LANG_CXX11
999 template <
typename Po
inter>
1002 #if GTEST_LANG_CXX11
1003 return p !=
nullptr;
1004 #else // GTEST_LANG_CXX11
1006 #endif // GTEST_LANG_CXX11
1028 template <
typename T>
1031 template <
typename T>
1044 template <
typename Super>
1055 template <
typename Super>
1062 virtual bool MatchAndExplain(
1064 *listener <<
"which is located @" <<
static_cast<const void*
>(&
x);
1065 return &x == &object_;
1069 *os <<
"references the variable ";
1074 *os <<
"does not reference the variable ";
1095 const wchar_t*
rhs) {
1101 template <
typename StringType>
1103 const StringType& s2) {
1111 const size_t i1 = s1.find(nul), i2 = s2.find(nul);
1114 if (i1 == StringType::npos || i2 == StringType::npos) {
1125 template <
typename StringType>
1129 bool case_sensitive)
1137 template <
typename CharType>
1149 template <
typename MatcheeStringType>
1152 const StringType& s2(s);
1168 *os << (expect_eq ?
"is " :
"isn't ");
1171 *os <<
"(ignoring case) ";
1186 template <
typename StringType>
1197 template <
typename CharType>
1206 template <
typename MatcheeStringType>
1209 const StringType& s2(s);
1210 return s2.find(
substring_) != StringType::npos;
1215 *os <<
"has substring ";
1220 *os <<
"has no substring ";
1233 template <
typename StringType>
1244 template <
typename CharType>
1253 template <
typename MatcheeStringType>
1256 const StringType& s2(s);
1257 return s2.length() >=
prefix_.length() &&
1262 *os <<
"starts with ";
1267 *os <<
"doesn't start with ";
1280 template <
typename StringType>
1290 template <
typename CharType>
1299 template <
typename MatcheeStringType>
1302 const StringType& s2(s);
1303 return s2.length() >=
suffix_.length() &&
1308 *os <<
"ends with ";
1313 *os <<
"doesn't end with ";
1336 template <
typename CharType>
1345 template <
class MatcheeStringType>
1355 <<
" regular expression ";
1360 *os <<
"doesn't " << (
full_match_ ?
"match" :
"contain")
1361 <<
" regular expression ";
1380 template <
typename D,
typename Op>
1383 template <
typename T1,
typename T2>
1385 return MakeMatcher(
new Impl< ::testing::tuple<T1, T2> >);
1387 template <
typename T1,
typename T2>
1389 return MakeMatcher(
new Impl<const ::testing::tuple<T1, T2>&>);
1394 return os << D::Desc();
1397 template <
typename Tuple>
1403 return Op()(::testing::get<0>(
args), ::testing::get<1>(args));
1416 static const char*
Desc() {
return "an equal pair"; }
1420 static const char*
Desc() {
return "an unequal pair"; }
1424 static const char*
Desc() {
return "a pair where the first < the second"; }
1428 static const char*
Desc() {
return "a pair where the first > the second"; }
1432 static const char*
Desc() {
return "a pair where the first <= the second"; }
1436 static const char*
Desc() {
return "a pair where the first >= the second"; }
1443 template <
typename T>
1450 return !
matcher_.MatchAndExplain(x, listener);
1469 template <
typename InnerMatcher>
1476 template <
typename T>
1491 template <
typename T>
1517 if (!
matcher1_.MatchAndExplain(x, &listener1)) {
1518 *listener << listener1.
str();
1523 if (!
matcher2_.MatchAndExplain(x, &listener2)) {
1524 *listener << listener2.
str();
1537 *listener <<
", and " << s2;
1550 #if GTEST_LANG_CXX11
1558 template <
int kSize,
typename Head,
typename... Tail>
1559 struct MatcherList {
1560 typedef MatcherList<kSize - 1, Tail...> MatcherListTail;
1561 typedef ::std::pair<Head, typename MatcherListTail::ListType> ListType;
1567 static ListType BuildList(
const Head& matcher,
const Tail&... tail) {
1568 return ListType(matcher, MatcherListTail::BuildList(tail...));
1575 template <
typename T,
template <
typename >
class CombiningMatcher>
1576 static
Matcher<
T> CreateMatcher(const ListType& matchers) {
1578 SafeMatcherCast<T>(matchers.first),
1579 MatcherListTail::template CreateMatcher<T, CombiningMatcher>(
1586 template <
typename Matcher1,
typename Matcher2>
1587 struct MatcherList<2, Matcher1, Matcher2> {
1588 typedef ::std::pair<Matcher1, Matcher2> ListType;
1590 static ListType BuildList(
const Matcher1& matcher1,
1591 const Matcher2& matcher2) {
1592 return ::std::pair<Matcher1, Matcher2>(matcher1, matcher2);
1595 template <
typename T,
template <
typename >
class CombiningMatcher>
1596 static Matcher<
T> CreateMatcher(const ListType& matchers) {
1597 return Matcher<T>(
new CombiningMatcher<T>(
1598 SafeMatcherCast<T>(matchers.first),
1599 SafeMatcherCast<T>(matchers.second)));
1607 template <
template <
typename T>
class CombiningMatcher,
typename...
Args>
1608 class VariadicMatcher {
1610 VariadicMatcher(
const Args&... matchers)
1611 : matchers_(MatcherListType::BuildList(matchers...)) {}
1616 template <
typename T>
1617 operator Matcher<T>()
const {
1618 return MatcherListType::template CreateMatcher<T, CombiningMatcher>(
1623 typedef MatcherList<
sizeof...(Args),
Args...> MatcherListType;
1625 const typename MatcherListType::ListType matchers_;
1630 template <
typename...
Args>
1631 using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl,
Args...>;
1633 #endif // GTEST_LANG_CXX11
1637 template <
typename Matcher1,
typename Matcher2>
1646 template <
typename T>
1663 template <
typename T>
1689 if (
matcher1_.MatchAndExplain(x, &listener1)) {
1690 *listener << listener1.
str();
1695 if (
matcher2_.MatchAndExplain(x, &listener2)) {
1696 *listener << listener2.
str();
1709 *listener <<
", and " << s2;
1722 #if GTEST_LANG_CXX11
1724 template <
typename...
Args>
1727 #endif // GTEST_LANG_CXX11
1732 template <
typename Matcher1,
typename Matcher2>
1741 template <
typename T>
1756 template <
typename Predicate>
1765 template <
typename T>
1780 *os <<
"satisfies the given predicate";
1784 *os <<
"doesn't satisfy the given predicate";
1795 template <
typename M>
1806 template <
typename T>
1833 template <
typename M>
1841 template <
typename T>
1859 ::std::stringstream ss;
1860 ss <<
"Value of: " << value_text <<
"\n"
1863 ss <<
"\n Actual: " << listener.str();
1877 template <
typename M>
1887 template <
typename FloatType>
1904 FloatType max_abs_error)
1909 <<
", where max_abs_error is" << max_abs_error;
1913 template <
typename T>
1916 Impl(FloatType expected,
bool nan_eq_nan, FloatType max_abs_error)
1942 const FloatType diff = value -
expected_;
1948 *listener <<
"which is " << diff <<
" from " <<
expected_;
1952 return actual.AlmostEquals(expected);
1960 const ::std::streamsize old_precision = os->precision(
1961 ::std::numeric_limits<FloatType>::digits10 + 2);
1966 *os <<
"never matches";
1969 *os <<
"is approximately " <<
expected_;
1974 os->precision(old_precision);
1979 const ::std::streamsize old_precision = os->precision(
1980 ::std::numeric_limits<FloatType>::digits10 + 2);
1985 *os <<
"is anything";
1988 *os <<
"isn't approximately " <<
expected_;
1994 os->precision(old_precision);
2042 template <
typename InnerMatcher>
2055 template <
typename Po
inter>
2062 template <
typename Po
inter>
2068 explicit Impl(
const InnerMatcher& matcher)
2072 *os <<
"points to a value that ";
2077 *os <<
"does not point to a value that ";
2086 *listener <<
"which points to ";
2107 template <
typename To>
2128 return GetTypeName<To>();
2129 #else // GTEST_HAS_RTTI
2130 return "the target type";
2131 #endif // GTEST_HAS_RTTI
2136 *os <<
"when dynamic_cast to " <<
GetToName() <<
", ";
2144 template <
typename To>
2150 template <
typename From>
2153 To to =
dynamic_cast<To>(from);
2160 template <
typename To>
2166 template <
typename From>
2169 To* to =
dynamic_cast<To*
>(&from);
2171 *listener <<
"which cannot be dynamic_cast to " << this->GetToName();
2180 template <
typename Class,
typename FieldType>
2188 *os <<
"is an object whose given field ";
2193 *os <<
"is an object whose given field ";
2197 template <
typename T>
2200 typename ::testing::internal::
2211 *listener <<
"whose given field is ";
2220 *listener <<
"which points to an object ";
2235 template <
typename Class,
typename PropertyType>
2249 *os <<
"is an object whose given property ";
2254 *os <<
"is an object whose given property ";
2258 template <
typename T>
2261 typename ::testing::internal::
2272 *listener <<
"whose given property is ";
2275 #if defined(_PREFAST_ ) && _MSC_VER == 1800
2281 RefToConstProperty result = (obj.*
property_)();
2291 *listener <<
"which points to an object ";
2308 template <
typename Functor>
2314 template <
typename T>
2319 template <
typename ArgType,
typename ResType>
2322 typedef ResType(*StorageType)(ArgType);
2326 <<
"NULL function pointer is passed into ResultOf().";
2328 template <
typename T>
2336 template <
typename Callable>
2346 template <
typename T>
2354 template <
typename T>
2361 *os <<
"is mapped by the given callable to a value that ";
2366 *os <<
"is mapped by the given callable to a value that ";
2371 *listener <<
"which is mapped by the given callable to ";
2398 template <
typename SizeMatcher>
2405 template <
typename Container>
2410 template <
typename Container>
2415 typedef typename ContainerView::type::size_type
SizeType;
2416 explicit Impl(
const SizeMatcher& size_matcher)
2434 <<
"whose size " << size << (result ?
" matches" :
" doesn't match");
2451 template <
typename DistanceMatcher>
2457 template <
typename Container>
2462 template <
typename Container>
2467 typedef typename std::iterator_traits<
2468 typename ContainerView::type::const_iterator>::difference_type
2470 explicit Impl(
const DistanceMatcher& distance_matcher)
2474 *os <<
"distance between begin() and end() ";
2478 *os <<
"distance between begin() and end() ";
2484 #if GTEST_HAS_STD_BEGIN_AND_END_
2494 *listener <<
"whose distance between begin() and end() " << distance
2495 << (result ?
" matches" :
" doesn't match");
2520 template <
typename Container>
2542 *os <<
"does not equal ";
2546 template <
typename LhsContainer>
2558 ::std::ostream*
const os = listener->
stream();
2561 bool printed_header =
false;
2562 for (
typename LhsStlContainer::const_iterator
it =
2563 lhs_stl_container.begin();
2564 it != lhs_stl_container.end(); ++
it) {
2567 if (printed_header) {
2570 *os <<
"which has these unexpected elements: ";
2571 printed_header =
true;
2578 bool printed_header2 =
false;
2579 for (
typename StlContainer::const_iterator
it =
expected_.begin();
2582 lhs_stl_container.begin(), lhs_stl_container.end(), *
it) ==
2583 lhs_stl_container.end()) {
2584 if (printed_header2) {
2587 *os << (printed_header ?
",\nand" :
"which")
2588 <<
" doesn't have these expected elements: ";
2589 printed_header2 =
true;
2607 template <
typename T,
typename U>
2612 template <
typename Comparator,
typename ContainerMatcher>
2616 const ContainerMatcher& matcher)
2619 template <
typename LhsContainer>
2624 template <
typename LhsContainer>
2636 Impl(
const Comparator& comparator,
const ContainerMatcher& matcher)
2640 *os <<
"(when sorted) ";
2645 *os <<
"(when sorted) ";
2652 ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
2653 lhs_stl_container.end());
2655 sorted_container.begin(), sorted_container.end(),
comparator_);
2663 *listener <<
"which is ";
2665 *listener <<
" when sorted";
2692 template <
typename TupleMatcher,
typename RhsContainer>
2709 template <
typename LhsContainer>
2714 template <
typename LhsContainer>
2734 *os <<
"contains " <<
rhs_.size()
2735 <<
" values, where each value and its corresponding value in ";
2741 *os <<
"doesn't contain exactly " <<
rhs_.size()
2742 <<
" values, or contains a value x at some index i"
2743 <<
" where x and the i-th value of ";
2752 const size_t actual_size = lhs_stl_container.size();
2753 if (actual_size !=
rhs_.size()) {
2754 *listener <<
"which contains " << actual_size <<
" values";
2758 typename LhsStlContainer::const_iterator
left = lhs_stl_container.begin();
2759 typename RhsStlContainer::const_iterator right =
rhs_.begin();
2760 for (
size_t i = 0;
i != actual_size; ++
i, ++
left, ++right) {
2766 value_pair, &inner_listener)) {
2767 *listener <<
"where the value pair (";
2771 *listener <<
") at index #" <<
i <<
" don't match";
2799 template <
typename Container>
2808 template <
typename InnerMatcher>
2821 for (
typename StlContainer::const_iterator
it = stl_container.begin();
2822 it != stl_container.end(); ++
it, ++
i) {
2826 if (matches != all_elements_should_match) {
2827 *listener <<
"whose element #" << i
2828 << (matches ?
" matches" :
" doesn't match");
2830 return !all_elements_should_match;
2833 return all_elements_should_match;
2844 template <
typename Container>
2847 template <
typename InnerMatcher>
2853 *os <<
"contains at least one element that ";
2858 *os <<
"doesn't contain any element that ";
2873 template <
typename Container>
2876 template <
typename InnerMatcher>
2882 *os <<
"only contains elements that ";
2887 *os <<
"contains some element that ";
2901 template <
typename M>
2906 template <
typename Container>
2918 template <
typename M>
2923 template <
typename Container>
2938 template <
typename PairType>
2944 template <
typename InnerMatcher>
2957 if (explanation !=
"") {
2958 *listener <<
"whose first field is a value " << explanation;
2965 *os <<
"has a key that ";
2971 *os <<
"doesn't have a key that ";
2982 template <
typename M>
2987 template <
typename PairType>
3000 template <
typename PairType>
3007 template <
typename FirstMatcher,
typename SecondMatcher>
3017 *os <<
"has a first field that ";
3019 *os <<
", and has a second field that ";
3025 *os <<
"has a first field that ";
3027 *os <<
", or has a second field that ";
3043 &first_inner_listener)) {
3044 *listener <<
"whose first field does not match";
3050 &second_inner_listener)) {
3051 *listener <<
"whose second field does not match";
3064 *listener <<
"whose both fields match";
3065 if (first_explanation !=
"") {
3066 *listener <<
", where the first field is a value " << first_explanation;
3068 if (second_explanation !=
"") {
3070 if (first_explanation !=
"") {
3071 *listener <<
"and ";
3073 *listener <<
"where ";
3075 *listener <<
"the second field is a value " << second_explanation;
3086 template <
typename FirstMatcher,
typename SecondMatcher>
3092 template <
typename PairType>
3107 template <
typename Container>
3118 template <
typename InputIter>
3120 while (first != last) {
3121 matchers_.push_back(MatcherCast<const Element&>(*first++));
3129 }
else if (
count() == 1) {
3130 *os <<
"has 1 element that ";
3134 for (
size_t i = 0;
i !=
count(); ++
i) {
3135 *os <<
"element #" <<
i <<
" ";
3137 if (i + 1 <
count()) {
3147 *os <<
"isn't empty";
3152 for (
size_t i = 0;
i !=
count(); ++
i) {
3153 *os <<
"element #" <<
i <<
" ";
3155 if (i + 1 <
count()) {
3166 const bool listener_interested = listener->
IsInterested();
3169 ::std::vector<internal::string> explanations(
count());
3171 typename StlContainer::const_iterator
it = stl_container.begin();
3172 size_t exam_pos = 0;
3173 bool mismatch_found =
false;
3178 for (; it != stl_container.end() && exam_pos !=
count(); ++
it, ++exam_pos) {
3180 if (listener_interested) {
3182 match =
matchers_[exam_pos].MatchAndExplain(*it, &s);
3183 explanations[exam_pos] = s.
str();
3185 match =
matchers_[exam_pos].Matches(*it);
3189 mismatch_found =
true;
3198 size_t actual_count = exam_pos;
3199 for (; it != stl_container.end(); ++
it) {
3203 if (actual_count !=
count()) {
3208 if (listener_interested && (actual_count != 0)) {
3209 *listener <<
"which has " <<
Elements(actual_count);
3214 if (mismatch_found) {
3216 if (listener_interested) {
3217 *listener <<
"whose element #" << exam_pos <<
" doesn't match";
3225 if (listener_interested) {
3226 bool reason_printed =
false;
3227 for (
size_t i = 0;
i !=
count(); ++
i) {
3230 if (reason_printed) {
3231 *listener <<
",\nand ";
3233 *listener <<
"whose element #" <<
i <<
" matches, " <<
s;
3234 reason_printed =
true;
3243 return Message() << count << (count == 1 ?
" element" :
" elements");
3260 : num_elements_(num_elements),
3261 num_matchers_(num_matchers),
3262 matched_(num_elements_* num_matchers_, 0) {
3268 return matched_[SpaceIndex(ilhs, irhs)] == 1;
3271 matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0;
3281 string DebugString()
const;
3285 return ilhs * num_matchers_ + irhs;
3319 void DescribeToImpl(::std::ostream*
os)
const;
3322 void DescribeNegationToImpl(::std::ostream*
os)
const;
3324 bool VerifyAllElementsAndMatchersAreMatched(
3325 const ::std::vector<string>& element_printouts,
3330 return matcher_describers_;
3334 return Message() << n <<
" element" << (n == 1 ?
"" :
"s");
3344 template <
typename Container>
3358 template <
typename InputIter>
3360 for (; first != last; ++first) {
3361 matchers_.push_back(MatcherCast<const Element&>(*first));
3379 ::std::vector<string> element_printouts;
3381 stl_container.end(),
3385 const size_t actual_count = matrix.
LhsSize();
3386 if (actual_count == 0 &&
matchers_.empty()) {
3395 *listener <<
"which has " <<
Elements(actual_count);
3401 matrix, listener) &&
3408 template <
typename ElementIter>
3410 ::std::vector<string>* element_printouts,
3412 element_printouts->clear();
3413 ::std::vector<char> did_match;
3414 size_t num_elements = 0;
3415 for (; elem_first != elem_last; ++num_elements, ++elem_first) {
3419 for (
size_t irhs = 0; irhs !=
matchers_.size(); ++irhs) {
3425 ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
3426 for (
size_t ilhs = 0; ilhs != num_elements; ++ilhs) {
3427 for (
size_t irhs = 0; irhs !=
matchers_.size(); ++irhs) {
3428 matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
3441 template <
typename Target>
3443 template <
typename Arg>
3445 return MatcherCast<Target>(
a);
3450 template <
typename MatcherTuple>
3456 template <
typename Container>
3461 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
3462 MatcherVec matchers;
3465 ::std::back_inserter(matchers));
3467 matchers.begin(), matchers.end()));
3476 template <
typename MatcherTuple>
3481 template <
typename Container>
3486 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
3487 MatcherVec matchers;
3490 ::std::back_inserter(matchers));
3492 matchers.begin(), matchers.end()));
3501 template <
typename T>
3506 template <
typename Iter>
3510 template <
typename Container>
3524 template <
typename T>
3527 template <
typename Iter>
3530 template <
typename Container>
3551 template <
typename Tuple2Matcher,
typename Second>
3557 template <
typename T>
3575 template <
typename T>
3580 Impl(
const Tuple2Matcher& tm,
const Second& second)
3611 template <
typename Tuple2Matcher,
typename Second>
3613 const Tuple2Matcher& tm,
const Second& second) {
3623 const char* matcher_name,
3643 template <
typename Iter>
3644 inline internal::ElementsAreArrayMatcher<
3651 template <
typename T>
3653 const T* pointer,
size_t count) {
3657 template <
typename T,
size_t N>
3663 template <
typename Container>
3664 inline internal::ElementsAreArrayMatcher<typename Container::value_type>
3669 #if GTEST_HAS_STD_INITIALIZER_LIST_
3670 template <
typename T>
3671 inline internal::ElementsAreArrayMatcher<T>
3685 template <
typename Iter>
3686 inline internal::UnorderedElementsAreArrayMatcher<
3693 template <
typename T>
3694 inline internal::UnorderedElementsAreArrayMatcher<T>
3699 template <
typename T,
size_t N>
3700 inline internal::UnorderedElementsAreArrayMatcher<T>
3705 template <
typename Container>
3706 inline internal::UnorderedElementsAreArrayMatcher<
3712 #if GTEST_HAS_STD_INITIALIZER_LIST_
3713 template <
typename T>
3714 inline internal::UnorderedElementsAreArrayMatcher<T>
3731 template <
typename T>
3735 template <
typename T>
3741 template <
typename T>
3746 template <
typename T>
3761 template <
typename Lhs,
typename Rhs>
3765 template <
typename Rhs>
3771 template <
typename Rhs>
3777 template <
typename Rhs>
3783 template <
typename Rhs>
3789 template <
typename Rhs>
3808 template <
typename T>
3829 double rhs,
double max_abs_error) {
3837 double rhs,
double max_abs_error) {
3857 float rhs,
float max_abs_error) {
3865 float rhs,
float max_abs_error) {
3871 template <
typename InnerMatcher>
3873 const InnerMatcher& inner_matcher) {
3883 template <
typename To>
3884 inline PolymorphicMatcher<internal::WhenDynamicCastToMatcher<To> >
3894 template <
typename Class,
typename FieldType,
typename FieldMatcher>
3895 inline PolymorphicMatcher<
3897 FieldType Class::*
field,
const FieldMatcher& matcher) {
3900 field, MatcherCast<const FieldType&>(matcher)));
3911 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
3912 inline PolymorphicMatcher<
3914 PropertyType (Class::*property)()
const,
const PropertyMatcher& matcher) {
3938 template <
typename Callable,
typename ResultOfMatcher>
3940 Callable callable,
const ResultOfMatcher& matcher) {
3943 MatcherCast<typename internal::CallableTraits<Callable>::ResultType>(
3954 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
3961 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
3968 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
3975 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
3978 str,
false,
false));
3983 inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::string> >
3990 inline PolymorphicMatcher<internal::StartsWithMatcher<internal::string> >
3997 inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> >
4025 #if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
4029 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
4036 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
4043 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
4050 inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
4053 str,
false,
false));
4058 inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::wstring> >
4065 inline PolymorphicMatcher<internal::StartsWithMatcher<internal::wstring> >
4072 inline PolymorphicMatcher<internal::EndsWithMatcher<internal::wstring> >
4078 #endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
4106 template <
typename InnerMatcher>
4114 template <
typename Predicate>
4115 inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> >
4126 template <
typename SizeMatcher>
4127 inline internal::SizeIsMatcher<SizeMatcher>
4137 template <
typename DistanceMatcher>
4138 inline internal::BeginEndDistanceIsMatcher<DistanceMatcher>
4147 template <
typename Container>
4148 inline PolymorphicMatcher<internal::ContainerEqMatcher<
4160 template <
typename Comparator,
typename ContainerMatcher>
4161 inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher>
4163 const ContainerMatcher& container_matcher) {
4165 comparator, container_matcher);
4170 template <
typename ContainerMatcher>
4171 inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
4184 template <
typename TupleMatcher,
typename Container>
4185 inline internal::PointwiseMatcher<TupleMatcher,
4193 tuple_matcher,
rhs);
4196 #if GTEST_HAS_STD_INITIALIZER_LIST_
4199 template <
typename TupleMatcher,
typename T>
4200 inline internal::PointwiseMatcher<TupleMatcher, std::vector<T> >
Pointwise(
4201 const TupleMatcher& tuple_matcher, std::initializer_list<T>
rhs) {
4202 return Pointwise(tuple_matcher, std::vector<T>(rhs));
4205 #endif // GTEST_HAS_STD_INITIALIZER_LIST_
4218 template <
typename Tuple2Matcher,
typename RhsContainer>
4219 inline internal::UnorderedElementsAreArrayMatcher<
4220 typename internal::BoundSecondMatcher<
4224 const RhsContainer& rhs_container) {
4235 const RhsStlContainer& rhs_stl_container =
4236 RhsView::ConstReference(rhs_container);
4239 ::std::vector<internal::BoundSecondMatcher<Tuple2Matcher, Second> > matchers;
4240 for (
typename RhsStlContainer::const_iterator
it = rhs_stl_container.begin();
4241 it != rhs_stl_container.end(); ++
it) {
4250 #if GTEST_HAS_STD_INITIALIZER_LIST_
4253 template <
typename Tuple2Matcher,
typename T>
4254 inline internal::UnorderedElementsAreArrayMatcher<
4255 typename internal::BoundSecondMatcher<Tuple2Matcher, T> >
4257 std::initializer_list<T> rhs) {
4261 #endif // GTEST_HAS_STD_INITIALIZER_LIST_
4281 template <
typename M>
4313 template <
typename M>
4321 template <
typename M>
4331 template <
typename FirstMatcher,
typename SecondMatcher>
4332 inline internal::PairMatcher<FirstMatcher, SecondMatcher>
4333 Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) {
4335 first_matcher, second_matcher);
4340 template <
typename M>
4346 template <
typename T,
typename M>
4353 template <
typename T,
typename M>
4356 return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
4359 #if GTEST_LANG_CXX11
4362 template <
typename...
Args>
4363 inline internal::AllOfMatcher<
Args...>
AllOf(
const Args&... matchers) {
4364 return internal::AllOfMatcher<
Args...>(matchers...);
4367 template <
typename...
Args>
4368 inline internal::AnyOfMatcher<
Args...>
AnyOf(
const Args&... matchers) {
4369 return internal::AnyOfMatcher<
Args...>(matchers...);
4372 #endif // GTEST_LANG_CXX11
4381 template <
typename InnerMatcher>
4382 inline InnerMatcher
AllArgs(
const InnerMatcher& matcher) {
return matcher; }
4388 #define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\
4389 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
4390 #define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\
4391 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
4399 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_