37 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_ 38 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_ 188 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 189 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 196 #include <functional> 200 #include <type_traits> 241 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ 242 #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ 247 #include <type_traits> 287 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 288 #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 303 #include "gtest/gtest.h" 339 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ 340 #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ 342 #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ 346 #if defined(_MSC_VER) && _MSC_VER < 1900 347 # error "At least Visual C++ 2015 (14.0) is required to compile Google Mock." 352 #define GMOCK_FLAG(name) FLAGS_gmock_##name 354 #if !defined(GMOCK_DECLARE_bool_) 357 # define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name) 358 # define GMOCK_DECLARE_int32_(name) extern GTEST_API_ int32_t GMOCK_FLAG(name) 359 # define GMOCK_DECLARE_string_(name) \ 360 extern GTEST_API_ ::std::string GMOCK_FLAG(name) 363 # define GMOCK_DEFINE_bool_(name, default_val, doc) \ 364 GTEST_API_ bool GMOCK_FLAG(name) = (default_val) 365 # define GMOCK_DEFINE_int32_(name, default_val, doc) \ 366 GTEST_API_ int32_t GMOCK_FLAG(name) = (default_val) 367 # define GMOCK_DEFINE_string_(name, default_val, doc) \ 368 GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val) 370 #endif // !defined(GMOCK_DECLARE_bool_) 372 #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 384 # pragma warning(push) 385 # pragma warning(disable:4100) 386 # pragma warning(disable:4805) 391 GTEST_API_ std::string JoinAsTuple(
const Strings& fields);
397 GTEST_API_ std::string ConvertIdentifierNameToWords(
const char* id_name);
402 template <
typename Po
inter>
403 inline const typename Pointer::element_type* GetRawPointer(
const Pointer& p) {
407 template <
typename Element>
408 inline Element* GetRawPointer(Element* p) {
return p; }
414 #if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED) 417 # define GMOCK_WCHAR_T_IS_NATIVE_ 1 426 kBool, kInteger, kFloatingPoint, kOther
430 template <
typename T>
struct KindOf {
431 enum { value = kOther };
435 #define GMOCK_DECLARE_KIND_(type, kind) \ 436 template <> struct KindOf<type> { enum { value = kind }; } 438 GMOCK_DECLARE_KIND_(
bool, kBool);
441 GMOCK_DECLARE_KIND_(
char, kInteger);
442 GMOCK_DECLARE_KIND_(
signed char, kInteger);
443 GMOCK_DECLARE_KIND_(
unsigned char, kInteger);
444 GMOCK_DECLARE_KIND_(
short, kInteger);
445 GMOCK_DECLARE_KIND_(
unsigned short, kInteger);
446 GMOCK_DECLARE_KIND_(
int, kInteger);
447 GMOCK_DECLARE_KIND_(
unsigned int, kInteger);
448 GMOCK_DECLARE_KIND_(
long, kInteger);
449 GMOCK_DECLARE_KIND_(
unsigned long, kInteger);
450 GMOCK_DECLARE_KIND_(
long long, kInteger);
451 GMOCK_DECLARE_KIND_(
unsigned long long, kInteger);
453 #if GMOCK_WCHAR_T_IS_NATIVE_ 454 GMOCK_DECLARE_KIND_(
wchar_t, kInteger);
458 GMOCK_DECLARE_KIND_(
float, kFloatingPoint);
459 GMOCK_DECLARE_KIND_(
double, kFloatingPoint);
460 GMOCK_DECLARE_KIND_(
long double, kFloatingPoint);
462 #undef GMOCK_DECLARE_KIND_ 465 #define GMOCK_KIND_OF_(type) \ 466 static_cast< ::testing::internal::TypeKind>( \ 467 ::testing::internal::KindOf<type>::value) 478 template <TypeKind kFromKind,
typename From, TypeKind kToKind,
typename To>
479 using LosslessArithmeticConvertibleImpl = std::integral_constant<
483 (kFromKind == kBool) ?
true 486 : (kFromKind != kToKind) ? false
487 : (kFromKind == kInteger &&
490 (((
sizeof(From) <
sizeof(To)) &&
491 !(std::is_signed<From>::value && !std::is_signed<To>::value)) ||
494 ((
sizeof(From) ==
sizeof(To)) &&
495 (std::is_signed<From>::value == std::is_signed<To>::value)))
499 : (kFromKind == kFloatingPoint && (
sizeof(From) <=
sizeof(To))) ? true
511 template <
typename From,
typename To>
512 using LosslessArithmeticConvertible =
513 LosslessArithmeticConvertibleImpl<GMOCK_KIND_OF_(From), From,
514 GMOCK_KIND_OF_(To), To>;
518 class FailureReporterInterface {
525 virtual ~FailureReporterInterface() {}
528 virtual void ReportFailure(FailureType type,
const char* file,
int line,
529 const std::string& message) = 0;
533 GTEST_API_ FailureReporterInterface* GetFailureReporter();
540 inline void Assert(
bool condition,
const char* file,
int line,
541 const std::string& msg) {
543 GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
547 inline void Assert(
bool condition,
const char* file,
int line) {
548 Assert(condition, file, line,
"Assertion failed.");
553 inline void Expect(
bool condition,
const char* file,
int line,
554 const std::string& msg) {
556 GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
560 inline void Expect(
bool condition,
const char* file,
int line) {
561 Expect(condition, file, line,
"Expectation failed.");
573 const char kInfoVerbosity[] =
"info";
575 const char kWarningVerbosity[] =
"warning";
577 const char kErrorVerbosity[] =
"error";
581 GTEST_API_
bool LogIsVisible(LogSeverity severity);
590 GTEST_API_
void Log(LogSeverity severity,
const std::string& message,
591 int stack_frames_to_skip);
599 class WithoutMatchers {
602 friend GTEST_API_ WithoutMatchers GetWithoutMatchers();
606 GTEST_API_ WithoutMatchers GetWithoutMatchers();
611 # pragma warning(push) 612 # pragma warning(disable:4717) 620 template <
typename T>
622 Assert(
false,
"", -1,
"Internal error: attempt to return invalid value");
630 # pragma warning(pop) 649 template <
class RawContainer>
650 class StlContainerView {
652 typedef RawContainer type;
653 typedef const type& const_reference;
655 static const_reference ConstReference(
const RawContainer& container) {
656 static_assert(!std::is_const<RawContainer>::value,
657 "RawContainer type must not be const");
660 static type Copy(
const RawContainer& container) {
return container; }
664 template <
typename Element,
size_t N>
665 class StlContainerView<Element[N]> {
667 typedef typename std::remove_const<Element>::type RawElement;
668 typedef internal::NativeArray<RawElement> type;
674 typedef const type const_reference;
676 static const_reference ConstReference(
const Element (&array)[N]) {
677 static_assert(std::is_same<Element, RawElement>::value,
678 "Element type must not be const");
679 return type(array, N, RelationToSourceReference());
681 static type Copy(
const Element (&array)[N]) {
682 return type(array, N, RelationToSourceCopy());
688 template <
typename ElementPo
inter,
typename Size>
689 class StlContainerView< ::std::tuple<ElementPointer, Size> > {
691 typedef typename std::remove_const<
692 typename std::pointer_traits<ElementPointer>::element_type>::type
694 typedef internal::NativeArray<RawElement> type;
695 typedef const type const_reference;
697 static const_reference ConstReference(
698 const ::std::tuple<ElementPointer, Size>& array) {
699 return type(std::get<0>(array), std::get<1>(array),
700 RelationToSourceReference());
702 static type Copy(const ::std::tuple<ElementPointer, Size>& array) {
703 return type(std::get<0>(array), std::get<1>(array), RelationToSourceCopy());
709 template <
typename T>
class StlContainerView<T&>;
714 template <
typename T>
715 struct RemoveConstFromKey {
720 template <
typename K,
typename V>
721 struct RemoveConstFromKey<
std::pair<const K, V> > {
722 typedef std::pair<K, V> type;
727 GTEST_API_
void IllegalDoDefault(
const char* file,
int line);
729 template <
typename F,
typename Tuple,
size_t... Idx>
730 auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>) -> decltype(
731 std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...)) {
732 return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...);
736 template <
typename F,
typename Tuple>
737 auto Apply(F&& f, Tuple&& args) -> decltype(
738 ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
739 MakeIndexSequence<std::tuple_size<
740 typename std::remove_reference<Tuple>::type>::value>())) {
741 return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
742 MakeIndexSequence<std::tuple_size<
743 typename std::remove_reference<Tuple>::type>::value>());
759 template <
typename T>
762 template <
typename R,
typename... Args>
763 struct Function<R(Args...)> {
765 static constexpr
size_t ArgumentCount =
sizeof...(Args);
767 using Arg = ElemFromList<I, Args...>;
768 using ArgumentTuple = std::tuple<Args...>;
769 using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
770 using MakeResultVoid = void(Args...);
771 using MakeResultIgnoredValue = IgnoredValue(Args...);
774 template <
typename R,
typename... Args>
775 constexpr
size_t Function<R(Args...)>::ArgumentCount;
778 # pragma warning(pop) 784 #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ 785 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PP_H_ 786 #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PP_H_ 789 #define GMOCK_PP_CAT(_1, _2) GMOCK_PP_INTERNAL_CAT(_1, _2) 792 #define GMOCK_PP_STRINGIZE(...) GMOCK_PP_INTERNAL_STRINGIZE(__VA_ARGS__) 795 #define GMOCK_PP_EMPTY(...) 798 #define GMOCK_PP_COMMA(...) , 801 #define GMOCK_PP_IDENTITY(_1) _1 813 #define GMOCK_PP_NARG(...) \ 814 GMOCK_PP_INTERNAL_16TH( \ 815 (__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)) 819 #define GMOCK_PP_HAS_COMMA(...) \ 820 GMOCK_PP_INTERNAL_16TH( \ 821 (__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0)) 824 #define GMOCK_PP_HEAD(...) GMOCK_PP_INTERNAL_HEAD((__VA_ARGS__, unusedArg)) 828 #define GMOCK_PP_TAIL(...) GMOCK_PP_INTERNAL_TAIL((__VA_ARGS__)) 831 #define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \ 833 GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__)) 863 #define GMOCK_PP_IS_EMPTY(...) \ 864 GMOCK_PP_INTERNAL_IS_EMPTY(GMOCK_PP_HAS_COMMA(__VA_ARGS__), \ 865 GMOCK_PP_HAS_COMMA(GMOCK_PP_COMMA __VA_ARGS__), \ 866 GMOCK_PP_HAS_COMMA(__VA_ARGS__()), \ 867 GMOCK_PP_HAS_COMMA(GMOCK_PP_COMMA __VA_ARGS__())) 870 #define GMOCK_PP_IF(_Cond, _Then, _Else) \ 871 GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IF_, _Cond)(_Then, _Else) 878 #define GMOCK_PP_GENERIC_IF(_Cond, _Then, _Else) \ 879 GMOCK_PP_REMOVE_PARENS(GMOCK_PP_IF(_Cond, _Then, _Else)) 894 #define GMOCK_PP_NARG0(...) \ 895 GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(__VA_ARGS__), 0, GMOCK_PP_NARG(__VA_ARGS__)) 899 #define GMOCK_PP_IS_BEGIN_PARENS(...) \ 900 GMOCK_PP_HEAD(GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_, \ 901 GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C __VA_ARGS__)) 904 #define GMOCK_PP_IS_ENCLOSED_PARENS(...) \ 905 GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(__VA_ARGS__), \ 906 GMOCK_PP_IS_EMPTY(GMOCK_PP_EMPTY __VA_ARGS__), 0) 909 #define GMOCK_PP_REMOVE_PARENS(...) GMOCK_PP_INTERNAL_REMOVE_PARENS __VA_ARGS__ 915 #define GMOCK_PP_FOR_EACH(_Macro, _Data, _Tuple) \ 916 GMOCK_PP_CAT(GMOCK_PP_INTERNAL_FOR_EACH_IMPL_, GMOCK_PP_NARG0 _Tuple) \ 917 (0, _Macro, _Data, _Tuple) 923 #define GMOCK_PP_REPEAT(_Macro, _Data, _N) \ 924 GMOCK_PP_CAT(GMOCK_PP_INTERNAL_FOR_EACH_IMPL_, _N) \ 925 (0, _Macro, _Data, GMOCK_PP_INTENRAL_EMPTY_TUPLE) 928 #define GMOCK_PP_INC(_i) GMOCK_PP_CAT(GMOCK_PP_INTERNAL_INC_, _i) 931 #define GMOCK_PP_COMMA_IF(_i) GMOCK_PP_CAT(GMOCK_PP_INTERNAL_COMMA_IF_, _i) 935 #define GMOCK_PP_INTENRAL_EMPTY_TUPLE (, , , , , , , , , , , , , , , ) 936 #define GMOCK_PP_INTERNAL_CAT(_1, _2) _1##_2 937 #define GMOCK_PP_INTERNAL_STRINGIZE(...) #__VA_ARGS__ 938 #define GMOCK_PP_INTERNAL_CAT_5(_1, _2, _3, _4, _5) _1##_2##_3##_4##_5 939 #define GMOCK_PP_INTERNAL_IS_EMPTY(_1, _2, _3, _4) \ 940 GMOCK_PP_HAS_COMMA(GMOCK_PP_INTERNAL_CAT_5(GMOCK_PP_INTERNAL_IS_EMPTY_CASE_, \ 942 #define GMOCK_PP_INTERNAL_IS_EMPTY_CASE_0001 , 943 #define GMOCK_PP_INTERNAL_IF_1(_Then, _Else) _Then 944 #define GMOCK_PP_INTERNAL_IF_0(_Then, _Else) _Else 951 #define GMOCK_PP_INTERNAL_INTERNAL_16TH(_1, _2, _3, _4, _5, _6, _7, _8, _9, \ 952 _10, _11, _12, _13, _14, _15, _16, \ 955 #define GMOCK_PP_INTERNAL_16TH(_Args) \ 956 GMOCK_PP_IDENTITY(GMOCK_PP_INTERNAL_INTERNAL_16TH _Args) 957 #define GMOCK_PP_INTERNAL_INTERNAL_HEAD(_1, ...) _1 958 #define GMOCK_PP_INTERNAL_HEAD(_Args) \ 959 GMOCK_PP_IDENTITY(GMOCK_PP_INTERNAL_INTERNAL_HEAD _Args) 960 #define GMOCK_PP_INTERNAL_INTERNAL_TAIL(_1, ...) __VA_ARGS__ 961 #define GMOCK_PP_INTERNAL_TAIL(_Args) \ 962 GMOCK_PP_IDENTITY(GMOCK_PP_INTERNAL_INTERNAL_TAIL _Args) 964 #define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C(...) 1 _ 965 #define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_1 1, 966 #define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C \ 968 #define GMOCK_PP_INTERNAL_REMOVE_PARENS(...) __VA_ARGS__ 969 #define GMOCK_PP_INTERNAL_INC_0 1 970 #define GMOCK_PP_INTERNAL_INC_1 2 971 #define GMOCK_PP_INTERNAL_INC_2 3 972 #define GMOCK_PP_INTERNAL_INC_3 4 973 #define GMOCK_PP_INTERNAL_INC_4 5 974 #define GMOCK_PP_INTERNAL_INC_5 6 975 #define GMOCK_PP_INTERNAL_INC_6 7 976 #define GMOCK_PP_INTERNAL_INC_7 8 977 #define GMOCK_PP_INTERNAL_INC_8 9 978 #define GMOCK_PP_INTERNAL_INC_9 10 979 #define GMOCK_PP_INTERNAL_INC_10 11 980 #define GMOCK_PP_INTERNAL_INC_11 12 981 #define GMOCK_PP_INTERNAL_INC_12 13 982 #define GMOCK_PP_INTERNAL_INC_13 14 983 #define GMOCK_PP_INTERNAL_INC_14 15 984 #define GMOCK_PP_INTERNAL_INC_15 16 985 #define GMOCK_PP_INTERNAL_COMMA_IF_0 986 #define GMOCK_PP_INTERNAL_COMMA_IF_1 , 987 #define GMOCK_PP_INTERNAL_COMMA_IF_2 , 988 #define GMOCK_PP_INTERNAL_COMMA_IF_3 , 989 #define GMOCK_PP_INTERNAL_COMMA_IF_4 , 990 #define GMOCK_PP_INTERNAL_COMMA_IF_5 , 991 #define GMOCK_PP_INTERNAL_COMMA_IF_6 , 992 #define GMOCK_PP_INTERNAL_COMMA_IF_7 , 993 #define GMOCK_PP_INTERNAL_COMMA_IF_8 , 994 #define GMOCK_PP_INTERNAL_COMMA_IF_9 , 995 #define GMOCK_PP_INTERNAL_COMMA_IF_10 , 996 #define GMOCK_PP_INTERNAL_COMMA_IF_11 , 997 #define GMOCK_PP_INTERNAL_COMMA_IF_12 , 998 #define GMOCK_PP_INTERNAL_COMMA_IF_13 , 999 #define GMOCK_PP_INTERNAL_COMMA_IF_14 , 1000 #define GMOCK_PP_INTERNAL_COMMA_IF_15 , 1001 #define GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, _element) \ 1002 _Macro(_i, _Data, _element) 1003 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_0(_i, _Macro, _Data, _Tuple) 1004 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1(_i, _Macro, _Data, _Tuple) \ 1005 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) 1006 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_2(_i, _Macro, _Data, _Tuple) \ 1007 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1008 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1(GMOCK_PP_INC(_i), _Macro, _Data, \ 1009 (GMOCK_PP_TAIL _Tuple)) 1010 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_3(_i, _Macro, _Data, _Tuple) \ 1011 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1012 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_2(GMOCK_PP_INC(_i), _Macro, _Data, \ 1013 (GMOCK_PP_TAIL _Tuple)) 1014 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_4(_i, _Macro, _Data, _Tuple) \ 1015 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1016 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_3(GMOCK_PP_INC(_i), _Macro, _Data, \ 1017 (GMOCK_PP_TAIL _Tuple)) 1018 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_5(_i, _Macro, _Data, _Tuple) \ 1019 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1020 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_4(GMOCK_PP_INC(_i), _Macro, _Data, \ 1021 (GMOCK_PP_TAIL _Tuple)) 1022 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_6(_i, _Macro, _Data, _Tuple) \ 1023 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1024 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_5(GMOCK_PP_INC(_i), _Macro, _Data, \ 1025 (GMOCK_PP_TAIL _Tuple)) 1026 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_7(_i, _Macro, _Data, _Tuple) \ 1027 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1028 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_6(GMOCK_PP_INC(_i), _Macro, _Data, \ 1029 (GMOCK_PP_TAIL _Tuple)) 1030 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_8(_i, _Macro, _Data, _Tuple) \ 1031 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1032 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_7(GMOCK_PP_INC(_i), _Macro, _Data, \ 1033 (GMOCK_PP_TAIL _Tuple)) 1034 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_9(_i, _Macro, _Data, _Tuple) \ 1035 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1036 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_8(GMOCK_PP_INC(_i), _Macro, _Data, \ 1037 (GMOCK_PP_TAIL _Tuple)) 1038 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_10(_i, _Macro, _Data, _Tuple) \ 1039 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1040 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_9(GMOCK_PP_INC(_i), _Macro, _Data, \ 1041 (GMOCK_PP_TAIL _Tuple)) 1042 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_11(_i, _Macro, _Data, _Tuple) \ 1043 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1044 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_10(GMOCK_PP_INC(_i), _Macro, _Data, \ 1045 (GMOCK_PP_TAIL _Tuple)) 1046 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_12(_i, _Macro, _Data, _Tuple) \ 1047 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1048 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_11(GMOCK_PP_INC(_i), _Macro, _Data, \ 1049 (GMOCK_PP_TAIL _Tuple)) 1050 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_13(_i, _Macro, _Data, _Tuple) \ 1051 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1052 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_12(GMOCK_PP_INC(_i), _Macro, _Data, \ 1053 (GMOCK_PP_TAIL _Tuple)) 1054 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_14(_i, _Macro, _Data, _Tuple) \ 1055 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1056 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_13(GMOCK_PP_INC(_i), _Macro, _Data, \ 1057 (GMOCK_PP_TAIL _Tuple)) 1058 #define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_15(_i, _Macro, _Data, _Tuple) \ 1059 GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ 1060 GMOCK_PP_INTERNAL_FOR_EACH_IMPL_14(GMOCK_PP_INC(_i), _Macro, _Data, \ 1061 (GMOCK_PP_TAIL _Tuple)) 1063 #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PP_H_ 1066 # pragma warning(push) 1067 # pragma warning(disable:4100) 1081 namespace internal {
1088 template <
typename T,
bool kDefaultConstructible>
1089 struct BuiltInDefaultValueGetter {
1090 static T Get() {
return T(); }
1092 template <
typename T>
1093 struct BuiltInDefaultValueGetter<T, false> {
1095 Assert(
false, __FILE__, __LINE__,
1096 "Default action undefined for the function return type.");
1097 return internal::Invalid<T>();
1110 template <
typename T>
1111 class BuiltInDefaultValue {
1115 static bool Exists() {
1116 return ::std::is_default_constructible<T>::value;
1120 return BuiltInDefaultValueGetter<
1121 T, ::std::is_default_constructible<T>::value>::Get();
1127 template <
typename T>
1128 class BuiltInDefaultValue<const T> {
1130 static bool Exists() {
return BuiltInDefaultValue<T>::Exists(); }
1131 static T Get() {
return BuiltInDefaultValue<T>::Get(); }
1136 template <
typename T>
1137 class BuiltInDefaultValue<T*> {
1139 static bool Exists() {
return true; }
1140 static T* Get() {
return nullptr; }
1145 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \ 1147 class BuiltInDefaultValue<type> { \ 1149 static bool Exists() { return true; } \ 1150 static type Get() { return value; } \ 1153 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
void, );
1154 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string,
"");
1155 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
bool,
false);
1156 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
unsigned char,
'\0');
1157 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
signed char,
'\0');
1158 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
char,
'\0');
1166 #if GMOCK_WCHAR_T_IS_NATIVE_ 1167 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
wchar_t, 0U);
1170 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
unsigned short, 0U);
1171 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
signed short, 0);
1172 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
unsigned int, 0U);
1173 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
signed int, 0);
1174 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
unsigned long, 0UL);
1175 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
signed long, 0L);
1176 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
unsigned long long, 0);
1177 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
signed long long, 0);
1178 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
float, 0);
1179 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(
double, 0);
1181 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_ 1184 template <
typename P,
typename Q>
1185 using disjunction = typename ::std::conditional<P::value, P, Q>::type;
1202 template <
typename T>
1203 class DefaultValue {
1207 static void Set(T x) {
1209 producer_ =
new FixedValueProducer(x);
1215 typedef T (*FactoryFunction)();
1216 static void SetFactory(FactoryFunction factory) {
1218 producer_ =
new FactoryValueProducer(factory);
1222 static void Clear() {
1224 producer_ =
nullptr;
1228 static bool IsSet() {
return producer_ !=
nullptr; }
1232 static bool Exists() {
1233 return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
1240 return producer_ ==
nullptr ? internal::BuiltInDefaultValue<T>::Get()
1241 : producer_->Produce();
1245 class ValueProducer {
1247 virtual ~ValueProducer() {}
1248 virtual T Produce() = 0;
1251 class FixedValueProducer :
public ValueProducer {
1253 explicit FixedValueProducer(T value) : value_(value) {}
1254 T Produce()
override {
return value_; }
1258 GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer);
1261 class FactoryValueProducer :
public ValueProducer {
1263 explicit FactoryValueProducer(FactoryFunction factory)
1264 : factory_(factory) {}
1265 T Produce()
override {
return factory_(); }
1268 const FactoryFunction factory_;
1269 GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer);
1272 static ValueProducer* producer_;
1277 template <
typename T>
1278 class DefaultValue<T&> {
1281 static void Set(T& x) {
1286 static void Clear() { address_ =
nullptr; }
1289 static bool IsSet() {
return address_ !=
nullptr; }
1293 static bool Exists() {
1294 return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
1301 return address_ ==
nullptr ? internal::BuiltInDefaultValue<T&>::Get()
1312 class DefaultValue<void> {
1314 static bool Exists() {
return true; }
1315 static void Get() {}
1319 template <
typename T>
1320 typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ =
nullptr;
1323 template <
typename T>
1324 T* DefaultValue<T&>::address_ =
nullptr;
1327 template <
typename F>
1328 class ActionInterface {
1330 typedef typename internal::Function<F>::Result Result;
1331 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1333 ActionInterface() {}
1334 virtual ~ActionInterface() {}
1340 virtual Result Perform(
const ArgumentTuple& args) = 0;
1343 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
1353 template <
typename F>
1357 struct ActionAdapter {
1359 ::std::shared_ptr<ActionInterface<F>> impl_;
1361 template <
typename... Args>
1362 typename internal::Function<F>::Result operator()(Args&&... args) {
1363 return impl_->Perform(
1364 ::std::forward_as_tuple(::std::forward<Args>(args)...));
1368 template <
typename G>
1369 using IsCompatibleFunctor = std::is_constructible<std::function<F>, G>;
1372 typedef typename internal::Function<F>::Result Result;
1373 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1384 typename =
typename std::enable_if<internal::disjunction<
1385 IsCompatibleFunctor<G>, std::is_constructible<std::function<Result()>,
1388 Init(::std::forward<G>(fun), IsCompatibleFunctor<G>());
1392 explicit Action(ActionInterface<F>* impl)
1393 : fun_(ActionAdapter{::std::shared_ptr<ActionInterface<F>>(impl)}) {}
1398 template <
typename Func>
1399 explicit Action(
const Action<Func>& action) : fun_(action.fun_) {}
1402 bool IsDoDefault()
const {
return fun_ ==
nullptr; }
1410 Result Perform(ArgumentTuple args)
const {
1411 if (IsDoDefault()) {
1412 internal::IllegalDoDefault(__FILE__, __LINE__);
1414 return internal::Apply(fun_, ::std::move(args));
1418 template <
typename G>
1419 friend class Action;
1421 template <
typename G>
1422 void Init(G&& g, ::std::true_type) {
1423 fun_ = ::std::forward<G>(g);
1426 template <
typename G>
1427 void Init(G&& g, ::std::false_type) {
1428 fun_ = IgnoreArgs<typename ::std::decay<G>::type>{::std::forward<G>(g)};
1431 template <
typename FunctionImpl>
1433 template <
typename... Args>
1434 Result operator()(
const Args&...)
const {
1435 return function_impl();
1438 FunctionImpl function_impl;
1442 ::std::function<F> fun_;
1466 template <
typename Impl>
1467 class PolymorphicAction {
1469 explicit PolymorphicAction(
const Impl& impl) : impl_(impl) {}
1471 template <
typename F>
1472 operator Action<F>()
const {
1473 return Action<F>(
new MonomorphicImpl<F>(impl_));
1477 template <
typename F>
1478 class MonomorphicImpl :
public ActionInterface<F> {
1480 typedef typename internal::Function<F>::Result Result;
1481 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1483 explicit MonomorphicImpl(
const Impl& impl) : impl_(impl) {}
1485 Result Perform(
const ArgumentTuple& args)
override {
1486 return impl_.template Perform<Result>(args);
1498 template <
typename F>
1499 Action<F> MakeAction(ActionInterface<F>* impl) {
1500 return Action<F>(impl);
1510 template <
typename Impl>
1511 inline PolymorphicAction<Impl> MakePolymorphicAction(
const Impl& impl) {
1512 return PolymorphicAction<Impl>(impl);
1515 namespace internal {
1519 template <
typename T>
1520 struct ByMoveWrapper {
1521 explicit ByMoveWrapper(T value) : payload(
std::move(value)) {}
1552 template <
typename R>
1553 class ReturnAction {
1558 explicit ReturnAction(R value) : value_(new R(
std::move(value))) {}
1562 template <
typename F>
1563 operator Action<F>()
const {
1572 typedef typename Function<F>::Result Result;
1573 GTEST_COMPILE_ASSERT_(
1574 !std::is_reference<Result>::value,
1575 use_ReturnRef_instead_of_Return_to_return_a_reference);
1576 static_assert(!std::is_void<Result>::value,
1577 "Can't use Return() on an action expected to return `void`.");
1578 return Action<F>(
new Impl<R, F>(value_));
1583 template <
typename R_,
typename F>
1584 class Impl :
public ActionInterface<F> {
1586 typedef typename Function<F>::Result Result;
1587 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1596 explicit Impl(
const std::shared_ptr<R>& value)
1597 : value_before_cast_(*value),
1598 value_(ImplicitCast_<Result>(value_before_cast_)) {}
1600 Result Perform(
const ArgumentTuple&)
override {
return value_; }
1603 GTEST_COMPILE_ASSERT_(!std::is_reference<Result>::value,
1604 Result_cannot_be_a_reference_type);
1607 R value_before_cast_;
1610 GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
1615 template <
typename R_,
typename F>
1616 class Impl<ByMoveWrapper<R_>, F> :
public ActionInterface<F> {
1618 typedef typename Function<F>::Result Result;
1619 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1621 explicit Impl(
const std::shared_ptr<R>& wrapper)
1622 : performed_(false), wrapper_(wrapper) {}
1624 Result Perform(
const ArgumentTuple&)
override {
1625 GTEST_CHECK_(!performed_)
1626 <<
"A ByMove() action should only be performed once.";
1628 return std::move(wrapper_->payload);
1633 const std::shared_ptr<R> wrapper_;
1636 const std::shared_ptr<R> value_;
1640 class ReturnNullAction {
1645 template <
typename Result,
typename ArgumentTuple>
1646 static Result Perform(
const ArgumentTuple&) {
1652 class ReturnVoidAction {
1655 template <
typename Result,
typename ArgumentTuple>
1656 static void Perform(
const ArgumentTuple&) {
1657 static_assert(std::is_void<Result>::value,
"Result should be void.");
1664 template <
typename T>
1665 class ReturnRefAction {
1668 explicit ReturnRefAction(T& ref) : ref_(ref) {}
1672 template <
typename F>
1673 operator Action<F>()
const {
1674 typedef typename Function<F>::Result Result;
1678 GTEST_COMPILE_ASSERT_(std::is_reference<Result>::value,
1679 use_Return_instead_of_ReturnRef_to_return_a_value);
1680 return Action<F>(
new Impl<F>(ref_));
1685 template <
typename F>
1686 class Impl :
public ActionInterface<F> {
1688 typedef typename Function<F>::Result Result;
1689 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1691 explicit Impl(T& ref) : ref_(ref) {}
1693 Result Perform(
const ArgumentTuple&)
override {
return ref_; }
1705 template <
typename T>
1706 class ReturnRefOfCopyAction {
1710 explicit ReturnRefOfCopyAction(
const T& value) : value_(value) {}
1714 template <
typename F>
1715 operator Action<F>()
const {
1716 typedef typename Function<F>::Result Result;
1720 GTEST_COMPILE_ASSERT_(
1721 std::is_reference<Result>::value,
1722 use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
1723 return Action<F>(
new Impl<F>(value_));
1728 template <
typename F>
1729 class Impl :
public ActionInterface<F> {
1731 typedef typename Function<F>::Result Result;
1732 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1734 explicit Impl(
const T& value) : value_(value) {}
1736 Result Perform(
const ArgumentTuple&)
override {
return value_; }
1747 template <
typename T>
1748 class ReturnRoundRobinAction {
1750 explicit ReturnRoundRobinAction(std::vector<T> values) {
1751 GTEST_CHECK_(!values.empty())
1752 <<
"ReturnRoundRobin requires at least one element.";
1753 state_->values = std::move(values);
1756 template <
typename... Args>
1757 T operator()(Args&&...)
const {
1758 return state_->Next();
1764 T ret_val = values[i++];
1765 if (i == values.size()) i = 0;
1769 std::vector<T> values;
1772 std::shared_ptr<State> state_ = std::make_shared<State>();
1776 class DoDefaultAction {
1780 template <
typename F>
1781 operator Action<F>()
const {
return Action<F>(); }
1786 template <
typename T1,
typename T2>
1787 class AssignAction {
1789 AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
1791 template <
typename Result,
typename ArgumentTuple>
1792 void Perform(
const ArgumentTuple& )
const {
1801 #if !GTEST_OS_WINDOWS_MOBILE 1805 template <
typename T>
1806 class SetErrnoAndReturnAction {
1808 SetErrnoAndReturnAction(
int errno_value, T result)
1809 : errno_(errno_value),
1811 template <
typename Result,
typename ArgumentTuple>
1812 Result Perform(
const ArgumentTuple& )
const {
1822 #endif // !GTEST_OS_WINDOWS_MOBILE 1826 template <
size_t N,
typename A,
typename =
void>
1827 struct SetArgumentPointeeAction {
1830 template <
typename... Args>
1831 void operator()(
const Args&... args)
const {
1832 *::std::get<N>(std::tie(args...)) = value;
1837 template <
class Class,
typename MethodPtr>
1838 struct InvokeMethodAction {
1839 Class*
const obj_ptr;
1840 const MethodPtr method_ptr;
1842 template <
typename... Args>
1843 auto operator()(Args&&... args)
const 1844 -> decltype((obj_ptr->*method_ptr)(std::forward<Args>(args)...)) {
1845 return (obj_ptr->*method_ptr)(std::forward<Args>(args)...);
1853 template <
typename FunctionImpl>
1854 struct InvokeWithoutArgsAction {
1855 FunctionImpl function_impl;
1859 template <
typename... Args>
1860 auto operator()(
const Args&...) -> decltype(function_impl()) {
1861 return function_impl();
1866 template <
class Class,
typename MethodPtr>
1867 struct InvokeMethodWithoutArgsAction {
1868 Class*
const obj_ptr;
1869 const MethodPtr method_ptr;
1872 decltype((std::declval<Class*>()->*std::declval<MethodPtr>())());
1874 template <
typename... Args>
1875 ReturnType operator()(
const Args&...)
const {
1876 return (obj_ptr->*method_ptr)();
1881 template <
typename A>
1882 class IgnoreResultAction {
1884 explicit IgnoreResultAction(
const A& action) : action_(action) {}
1886 template <
typename F>
1887 operator Action<F>()
const {
1896 typedef typename internal::Function<F>::Result Result;
1899 static_assert(std::is_void<Result>::value,
"Result type should be void.");
1901 return Action<F>(
new Impl<F>(action_));
1905 template <
typename F>
1906 class Impl :
public ActionInterface<F> {
1908 typedef typename internal::Function<F>::Result Result;
1909 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1911 explicit Impl(
const A& action) : action_(action) {}
1913 void Perform(
const ArgumentTuple& args)
override {
1915 action_.Perform(args);
1921 typedef typename internal::Function<F>::MakeResultIgnoredValue
1924 const Action<OriginalFunction> action_;
1930 template <
typename InnerAction,
size_t... I>
1931 struct WithArgsAction {
1936 template <
typename R,
typename... Args>
1937 operator Action<R(Args...)>()
const {
1938 using TupleType = std::tuple<Args...>;
1939 Action<R(typename std::tuple_element<I, TupleType>::type...)>
1942 return [converted](Args... args) -> R {
1943 return converted.Perform(std::forward_as_tuple(
1944 std::get<I>(std::forward_as_tuple(std::forward<Args>(args)...))...));
1949 template <
typename... Actions>
1950 struct DoAllAction {
1952 template <
typename T>
1953 using NonFinalType =
1954 typename std::conditional<std::is_scalar<T>::value, T,
const T&>::type;
1956 template <
typename ActionT,
size_t... I>
1957 std::vector<ActionT> Convert(IndexSequence<I...>)
const {
1958 return {ActionT(std::get<I>(actions))...};
1962 std::tuple<Actions...> actions;
1964 template <
typename R,
typename... Args>
1965 operator Action<R(Args...)>()
const {
1967 std::vector<Action<void(NonFinalType<Args>...)>> converted;
1968 Action<R(Args...)> last;
1969 R operator()(Args... args)
const {
1970 auto tuple_args = std::forward_as_tuple(std::forward<Args>(args)...);
1971 for (
auto& a : converted) {
1972 a.Perform(tuple_args);
1974 return last.Perform(std::move(tuple_args));
1977 return Op{Convert<Action<void(NonFinalType<Args>...)>>(
1978 MakeIndexSequence<
sizeof...(Actions) - 1>()),
1979 std::get<
sizeof...(Actions) - 1>(actions)};
1983 template <
typename T,
typename... Params>
1984 struct ReturnNewAction {
1985 T* operator()()
const {
1986 return internal::Apply(
1987 [](
const Params&... unpacked_params) {
1988 return new T(unpacked_params...);
1992 std::tuple<Params...> params;
1996 struct ReturnArgAction {
1997 template <
typename... Args>
1998 auto operator()(
const Args&... args)
const ->
1999 typename std::tuple_element<k, std::tuple<Args...>>::type {
2000 return std::get<k>(std::tie(args...));
2004 template <
size_t k,
typename Ptr>
2005 struct SaveArgAction {
2008 template <
typename... Args>
2009 void operator()(
const Args&... args)
const {
2010 *pointer = std::get<k>(std::tie(args...));
2014 template <
size_t k,
typename Ptr>
2015 struct SaveArgPointeeAction {
2018 template <
typename... Args>
2019 void operator()(
const Args&... args)
const {
2020 *pointer = *std::get<k>(std::tie(args...));
2024 template <
size_t k,
typename T>
2025 struct SetArgRefereeAction {
2028 template <
typename... Args>
2029 void operator()(Args&&... args)
const {
2031 typename ::std::tuple_element<k, std::tuple<Args...>>::type;
2032 static_assert(std::is_lvalue_reference<argk_type>::value,
2033 "Argument must be a reference type.");
2034 std::get<k>(std::tie(args...)) = value;
2038 template <
size_t k,
typename I1,
typename I2>
2039 struct SetArrayArgumentAction {
2043 template <
typename... Args>
2044 void operator()(
const Args&... args)
const {
2045 auto value = std::get<k>(std::tie(args...));
2046 for (
auto it = first; it != last; ++it, (void)++value) {
2053 struct DeleteArgAction {
2054 template <
typename... Args>
2055 void operator()(
const Args&... args)
const {
2056 delete std::get<k>(std::tie(args...));
2060 template <
typename Ptr>
2061 struct ReturnPointeeAction {
2063 template <
typename... Args>
2064 auto operator()(
const Args&...)
const -> decltype(*pointer) {
2069 #if GTEST_HAS_EXCEPTIONS 2070 template <
typename T>
2071 struct ThrowAction {
2074 template <
typename R,
typename... Args>
2075 operator Action<R(Args...)>()
const {
2077 return [copy](Args...) -> R {
throw copy; };
2080 #endif // GTEST_HAS_EXCEPTIONS 2114 typedef internal::IgnoredValue Unused;
2119 template <
typename... Action>
2120 internal::DoAllAction<typename std::decay<Action>::type...> DoAll(
2121 Action&&... action) {
2122 return {std::forward_as_tuple(std::forward<Action>(action)...)};
2130 template <
size_t k,
typename InnerAction>
2131 internal::WithArgsAction<typename std::decay<InnerAction>::type, k>
2132 WithArg(InnerAction&& action) {
2133 return {std::forward<InnerAction>(action)};
2140 template <
size_t k,
size_t... ks,
typename InnerAction>
2141 internal::WithArgsAction<typename std::decay<InnerAction>::type, k, ks...>
2142 WithArgs(InnerAction&& action) {
2143 return {std::forward<InnerAction>(action)};
2150 template <
typename InnerAction>
2151 internal::WithArgsAction<typename std::decay<InnerAction>::type>
2152 WithoutArgs(InnerAction&& action) {
2153 return {std::forward<InnerAction>(action)};
2159 template <
typename R>
2160 internal::ReturnAction<R> Return(R value) {
2161 return internal::ReturnAction<R>(std::move(value));
2165 inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() {
2166 return MakePolymorphicAction(internal::ReturnNullAction());
2170 inline PolymorphicAction<internal::ReturnVoidAction> Return() {
2171 return MakePolymorphicAction(internal::ReturnVoidAction());
2175 template <
typename R>
2176 inline internal::ReturnRefAction<R> ReturnRef(R& x) {
2177 return internal::ReturnRefAction<R>(x);
2181 template <
typename R, R* =
nullptr>
2182 internal::ReturnRefAction<R> ReturnRef(R&&) =
delete;
2187 template <
typename R>
2188 inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(
const R& x) {
2189 return internal::ReturnRefOfCopyAction<R>(x);
2196 template <
typename R>
2197 internal::ByMoveWrapper<R> ByMove(R x) {
2198 return internal::ByMoveWrapper<R>(std::move(x));
2204 template <
typename T>
2205 internal::ReturnRoundRobinAction<T> ReturnRoundRobin(std::vector<T> vals) {
2206 return internal::ReturnRoundRobinAction<T>(std::move(vals));
2212 template <
typename T>
2213 internal::ReturnRoundRobinAction<T> ReturnRoundRobin(
2214 std::initializer_list<T> vals) {
2215 return internal::ReturnRoundRobinAction<T>(std::vector<T>(vals));
2219 inline internal::DoDefaultAction DoDefault() {
2220 return internal::DoDefaultAction();
2225 template <
size_t N,
typename T>
2226 internal::SetArgumentPointeeAction<N, T> SetArgPointee(T value) {
2227 return {std::move(value)};
2231 template <
size_t N,
typename T>
2232 internal::SetArgumentPointeeAction<N, T> SetArgumentPointee(T value) {
2233 return {std::move(value)};
2237 template <
typename T1,
typename T2>
2238 PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) {
2239 return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
2242 #if !GTEST_OS_WINDOWS_MOBILE 2245 template <
typename T>
2246 PolymorphicAction<internal::SetErrnoAndReturnAction<T> >
2247 SetErrnoAndReturn(
int errval, T result) {
2248 return MakePolymorphicAction(
2249 internal::SetErrnoAndReturnAction<T>(errval, result));
2252 #endif // !GTEST_OS_WINDOWS_MOBILE 2260 template <
typename FunctionImpl>
2261 typename std::decay<FunctionImpl>::type Invoke(FunctionImpl&& function_impl) {
2262 return std::forward<FunctionImpl>(function_impl);
2267 template <
class Class,
typename MethodPtr>
2268 internal::InvokeMethodAction<Class, MethodPtr> Invoke(Class* obj_ptr,
2269 MethodPtr method_ptr) {
2270 return {obj_ptr, method_ptr};
2274 template <
typename FunctionImpl>
2275 internal::InvokeWithoutArgsAction<typename std::decay<FunctionImpl>::type>
2276 InvokeWithoutArgs(FunctionImpl function_impl) {
2277 return {std::move(function_impl)};
2282 template <
class Class,
typename MethodPtr>
2283 internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> InvokeWithoutArgs(
2284 Class* obj_ptr, MethodPtr method_ptr) {
2285 return {obj_ptr, method_ptr};
2291 template <
typename A>
2292 inline internal::IgnoreResultAction<A> IgnoreResult(
const A& an_action) {
2293 return internal::IgnoreResultAction<A>(an_action);
2306 template <
typename T>
2307 inline ::std::reference_wrapper<T> ByRef(T& l_value) {
2308 return ::std::reference_wrapper<T>(l_value);
2314 template <
typename T,
typename... Params>
2315 internal::ReturnNewAction<T, typename std::decay<Params>::type...> ReturnNew(
2316 Params&&... params) {
2317 return {std::forward_as_tuple(std::forward<Params>(params)...)};
2322 internal::ReturnArgAction<k> ReturnArg() {
2328 template <
size_t k,
typename Ptr>
2329 internal::SaveArgAction<k, Ptr> SaveArg(Ptr pointer) {
2335 template <
size_t k,
typename Ptr>
2336 internal::SaveArgPointeeAction<k, Ptr> SaveArgPointee(Ptr pointer) {
2342 template <
size_t k,
typename T>
2343 internal::SetArgRefereeAction<k, typename std::decay<T>::type> SetArgReferee(
2345 return {std::forward<T>(value)};
2353 template <
size_t k,
typename I1,
typename I2>
2354 internal::SetArrayArgumentAction<k, I1, I2> SetArrayArgument(I1 first,
2356 return {first, last};
2362 internal::DeleteArgAction<k> DeleteArg() {
2367 template <
typename Ptr>
2368 internal::ReturnPointeeAction<Ptr> ReturnPointee(Ptr pointer) {
2374 #if GTEST_HAS_EXCEPTIONS 2375 template <
typename T>
2376 internal::ThrowAction<typename std::decay<T>::type> Throw(T&& exception) {
2377 return {std::forward<T>(exception)};
2379 #endif // GTEST_HAS_EXCEPTIONS 2381 namespace internal {
2397 struct ExcessiveArg {};
2401 template <
typename F,
typename Impl>
struct ActionImpl;
2403 template <
typename Impl>
2407 explicit operator const Impl&()
const {
return *ptr; }
2408 std::shared_ptr<Impl> ptr;
2410 using type =
typename std::conditional<std::is_constructible<Impl>::value,
2411 Impl, Holder>::type;
2414 template <
typename R,
typename... Args,
typename Impl>
2415 struct ActionImpl<R(Args...), Impl> : ImplBase<Impl>::type {
2416 using Base =
typename ImplBase<Impl>::type;
2417 using function_type = R(Args...);
2418 using args_type = std::tuple<Args...>;
2420 ActionImpl() =
default;
2421 explicit ActionImpl(std::shared_ptr<Impl> impl) : Base{std::move(impl)} { }
2423 R operator()(Args&&... arg)
const {
2424 static constexpr
size_t kMaxArgs =
2425 sizeof...(Args) <= 10 ?
sizeof...(Args) : 10;
2426 return Apply(MakeIndexSequence<kMaxArgs>{},
2427 MakeIndexSequence<10 - kMaxArgs>{},
2428 args_type{std::forward<Args>(arg)...});
2431 template <std::size_t... arg_id, std::size_t... excess_id>
2432 R Apply(IndexSequence<arg_id...>, IndexSequence<excess_id...>,
2433 const args_type& args)
const {
2439 static constexpr ExcessiveArg kExcessArg{};
2440 return static_cast<const Impl&
>(*this).template gmock_PerformImpl<
2443 typename std::tuple_element<arg_id, args_type>::type...>(
2444 args, std::get<arg_id>(args)...,
2445 ((
void)excess_id, kExcessArg)...);
2451 template <
typename F,
typename Impl>
2452 ::testing::Action<F> MakeAction() {
2453 return ::testing::Action<F>(ActionImpl<F, Impl>());
2457 template <
typename F,
typename Impl>
2458 ::testing::Action<F> MakeAction(std::shared_ptr<Impl> impl) {
2459 return ::testing::Action<F>(ActionImpl<F, Impl>(std::move(impl)));
2462 #define GMOCK_INTERNAL_ARG_UNUSED(i, data, el) \ 2463 , const arg##i##_type& arg##i GTEST_ATTRIBUTE_UNUSED_ 2464 #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_ \ 2465 const args_type& args GTEST_ATTRIBUTE_UNUSED_ GMOCK_PP_REPEAT( \ 2466 GMOCK_INTERNAL_ARG_UNUSED, , 10) 2468 #define GMOCK_INTERNAL_ARG(i, data, el) , const arg##i##_type& arg##i 2469 #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_ \ 2470 const args_type& args GMOCK_PP_REPEAT(GMOCK_INTERNAL_ARG, , 10) 2472 #define GMOCK_INTERNAL_TEMPLATE_ARG(i, data, el) , typename arg##i##_type 2473 #define GMOCK_ACTION_TEMPLATE_ARGS_NAMES_ \ 2474 GMOCK_PP_TAIL(GMOCK_PP_REPEAT(GMOCK_INTERNAL_TEMPLATE_ARG, , 10)) 2476 #define GMOCK_INTERNAL_TYPENAME_PARAM(i, data, param) , typename param##_type 2477 #define GMOCK_ACTION_TYPENAME_PARAMS_(params) \ 2478 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPENAME_PARAM, , params)) 2480 #define GMOCK_INTERNAL_TYPE_PARAM(i, data, param) , param##_type 2481 #define GMOCK_ACTION_TYPE_PARAMS_(params) \ 2482 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_PARAM, , params)) 2484 #define GMOCK_INTERNAL_TYPE_GVALUE_PARAM(i, data, param) \ 2485 , param##_type gmock_p##i 2486 #define GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params) \ 2487 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_GVALUE_PARAM, , params)) 2489 #define GMOCK_INTERNAL_GVALUE_PARAM(i, data, param) \ 2490 , std::forward<param##_type>(gmock_p##i) 2491 #define GMOCK_ACTION_GVALUE_PARAMS_(params) \ 2492 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GVALUE_PARAM, , params)) 2494 #define GMOCK_INTERNAL_INIT_PARAM(i, data, param) \ 2495 , param(::std::forward<param##_type>(gmock_p##i)) 2496 #define GMOCK_ACTION_INIT_PARAMS_(params) \ 2497 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_INIT_PARAM, , params)) 2499 #define GMOCK_INTERNAL_FIELD_PARAM(i, data, param) param##_type param; 2500 #define GMOCK_ACTION_FIELD_PARAMS_(params) \ 2501 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_FIELD_PARAM, , params) 2503 #define GMOCK_INTERNAL_ACTION(name, full_name, params) \ 2504 template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \ 2507 explicit full_name(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) \ 2508 : impl_(std::make_shared<gmock_Impl>( \ 2509 GMOCK_ACTION_GVALUE_PARAMS_(params))) { } \ 2510 full_name(const full_name&) = default; \ 2511 full_name(full_name&&) noexcept = default; \ 2512 template <typename F> \ 2513 operator ::testing::Action<F>() const { \ 2514 return ::testing::internal::MakeAction<F>(impl_); \ 2517 class gmock_Impl { \ 2519 explicit gmock_Impl(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) \ 2520 : GMOCK_ACTION_INIT_PARAMS_(params) {} \ 2521 template <typename function_type, typename return_type, \ 2522 typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ 2523 return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ 2524 GMOCK_ACTION_FIELD_PARAMS_(params) \ 2526 std::shared_ptr<const gmock_Impl> impl_; \ 2528 template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \ 2529 inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \ 2530 GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) { \ 2531 return full_name<GMOCK_ACTION_TYPE_PARAMS_(params)>( \ 2532 GMOCK_ACTION_GVALUE_PARAMS_(params)); \ 2534 template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \ 2535 template <typename function_type, typename return_type, typename args_type, \ 2536 GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ 2537 return_type full_name<GMOCK_ACTION_TYPE_PARAMS_(params)>::gmock_Impl:: \ 2538 gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 2543 #define ACTION(name) \ 2544 class name##Action { \ 2546 explicit name##Action() noexcept {} \ 2547 name##Action(const name##Action&) noexcept {} \ 2548 template <typename F> \ 2549 operator ::testing::Action<F>() const { \ 2550 return ::testing::internal::MakeAction<F, gmock_Impl>(); \ 2553 class gmock_Impl { \ 2555 template <typename function_type, typename return_type, \ 2556 typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ 2557 return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ 2560 inline name##Action name() GTEST_MUST_USE_RESULT_; \ 2561 inline name##Action name() { return name##Action(); } \ 2562 template <typename function_type, typename return_type, typename args_type, \ 2563 GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ 2564 return_type name##Action::gmock_Impl::gmock_PerformImpl( \ 2565 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 2567 #define ACTION_P(name, ...) \ 2568 GMOCK_INTERNAL_ACTION(name, name##ActionP, (__VA_ARGS__)) 2570 #define ACTION_P2(name, ...) \ 2571 GMOCK_INTERNAL_ACTION(name, name##ActionP2, (__VA_ARGS__)) 2573 #define ACTION_P3(name, ...) \ 2574 GMOCK_INTERNAL_ACTION(name, name##ActionP3, (__VA_ARGS__)) 2576 #define ACTION_P4(name, ...) \ 2577 GMOCK_INTERNAL_ACTION(name, name##ActionP4, (__VA_ARGS__)) 2579 #define ACTION_P5(name, ...) \ 2580 GMOCK_INTERNAL_ACTION(name, name##ActionP5, (__VA_ARGS__)) 2582 #define ACTION_P6(name, ...) \ 2583 GMOCK_INTERNAL_ACTION(name, name##ActionP6, (__VA_ARGS__)) 2585 #define ACTION_P7(name, ...) \ 2586 GMOCK_INTERNAL_ACTION(name, name##ActionP7, (__VA_ARGS__)) 2588 #define ACTION_P8(name, ...) \ 2589 GMOCK_INTERNAL_ACTION(name, name##ActionP8, (__VA_ARGS__)) 2591 #define ACTION_P9(name, ...) \ 2592 GMOCK_INTERNAL_ACTION(name, name##ActionP9, (__VA_ARGS__)) 2594 #define ACTION_P10(name, ...) \ 2595 GMOCK_INTERNAL_ACTION(name, name##ActionP10, (__VA_ARGS__)) 2600 # pragma warning(pop) 2603 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 2642 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 2643 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 2649 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
2665 class CardinalityInterface {
2667 virtual ~CardinalityInterface() {}
2671 virtual int ConservativeLowerBound()
const {
return 0; }
2672 virtual int ConservativeUpperBound()
const {
return INT_MAX; }
2676 virtual bool IsSatisfiedByCallCount(
int call_count)
const = 0;
2680 virtual bool IsSaturatedByCallCount(
int call_count)
const = 0;
2683 virtual void DescribeTo(::std::ostream* os)
const = 0;
2690 class GTEST_API_ Cardinality {
2697 explicit Cardinality(
const CardinalityInterface* impl) : impl_(impl) {}
2701 int ConservativeLowerBound()
const {
return impl_->ConservativeLowerBound(); }
2702 int ConservativeUpperBound()
const {
return impl_->ConservativeUpperBound(); }
2706 bool IsSatisfiedByCallCount(
int call_count)
const {
2707 return impl_->IsSatisfiedByCallCount(call_count);
2712 bool IsSaturatedByCallCount(
int call_count)
const {
2713 return impl_->IsSaturatedByCallCount(call_count);
2718 bool IsOverSaturatedByCallCount(
int call_count)
const {
2719 return impl_->IsSaturatedByCallCount(call_count) &&
2720 !impl_->IsSatisfiedByCallCount(call_count);
2724 void DescribeTo(::std::ostream* os)
const { impl_->DescribeTo(os); }
2727 static void DescribeActualCallCountTo(
int actual_call_count,
2728 ::std::ostream* os);
2731 std::shared_ptr<const CardinalityInterface> impl_;
2735 GTEST_API_ Cardinality AtLeast(
int n);
2738 GTEST_API_ Cardinality AtMost(
int n);
2741 GTEST_API_ Cardinality AnyNumber();
2744 GTEST_API_ Cardinality Between(
int min,
int max);
2747 GTEST_API_ Cardinality Exactly(
int n);
2750 inline Cardinality MakeCardinality(
const CardinalityInterface* c) {
2751 return Cardinality(c);
2756 GTEST_DISABLE_MSC_WARNINGS_POP_()
2758 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 2794 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT 2795 #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT 2797 #include <type_traits> 2860 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ 2861 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ 2864 #include <functional> 2870 #include <type_traits> 3127 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ 3128 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ 3130 #include <algorithm> 3132 #include <initializer_list> 3139 #include <type_traits> 3145 #if defined(_MSC_VER) && _MSC_VER >= 1915 3146 #define GMOCK_MAYBE_5046_ 5046 3148 #define GMOCK_MAYBE_5046_ 3151 GTEST_DISABLE_MSC_WARNINGS_PUSH_(
3152 4251 GMOCK_MAYBE_5046_
3171 class StringMatchResultListener :
public MatchResultListener {
3173 StringMatchResultListener() : MatchResultListener(&ss_) {}
3176 std::string str()
const {
return ss_.str(); }
3179 void Clear() { ss_.str(
""); }
3182 ::std::stringstream ss_;
3184 GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener);
3189 namespace internal {
3201 template <
typename T,
typename M>
3202 class MatcherCastImpl {
3204 static Matcher<T> Cast(
const M& polymorphic_matcher_or_value) {
3218 return CastImpl(polymorphic_matcher_or_value,
3219 std::is_convertible<M, Matcher<T>>{},
3220 std::is_convertible<M, T>{});
3224 template <
bool Ignore>
3225 static Matcher<T> CastImpl(
const M& polymorphic_matcher_or_value,
3227 std::integral_constant<bool, Ignore>) {
3236 return polymorphic_matcher_or_value;
3242 static Matcher<T> CastImpl(
const M& value,
3245 return Matcher<T>(ImplicitCast_<T>(value));
3258 static Matcher<T> CastImpl(
const M& value,
3266 template <
typename T,
typename U>
3267 class MatcherCastImpl<T, Matcher<U> > {
3269 static Matcher<T> Cast(
const Matcher<U>& source_matcher) {
3270 return Matcher<T>(
new Impl(source_matcher));
3274 class Impl :
public MatcherInterface<T> {
3276 explicit Impl(
const Matcher<U>& source_matcher)
3277 : source_matcher_(source_matcher) {}
3280 bool MatchAndExplain(T x, MatchResultListener* listener)
const override {
3281 using FromType =
typename std::remove_cv<
typename std::remove_pointer<
3282 typename std::remove_reference<T>::type>::type>::type;
3283 using ToType =
typename std::remove_cv<
typename std::remove_pointer<
3284 typename std::remove_reference<U>::type>::type>::type;
3289 (std::is_pointer<
typename std::remove_reference<T>::type>::value !=
3290 std::is_pointer<
typename std::remove_reference<U>::type>::value) ||
3291 std::is_same<FromType, ToType>::value ||
3292 !std::is_base_of<FromType, ToType>::value,
3293 "Can't implicitly convert from <base> to <derived>");
3298 typename std::conditional<std::is_convertible<T&, const U&>::value,
3301 return source_matcher_.MatchAndExplain(static_cast<CastType>(x),
3305 void DescribeTo(::std::ostream* os)
const override {
3306 source_matcher_.DescribeTo(os);
3309 void DescribeNegationTo(::std::ostream* os)
const override {
3310 source_matcher_.DescribeNegationTo(os);
3314 const Matcher<U> source_matcher_;
3320 template <
typename T>
3321 class MatcherCastImpl<T, Matcher<T> > {
3323 static Matcher<T> Cast(
const Matcher<T>& matcher) {
return matcher; }
3327 template <
typename Derived>
3328 class MatcherBaseImpl {
3330 MatcherBaseImpl() =
default;
3332 template <
typename T>
3333 operator ::testing::Matcher<T>()
const {
3334 return ::testing::Matcher<T>(
new 3335 typename Derived::template gmock_Impl<T>());
3340 template <
template <
typename...>
class Derived,
typename... Ts>
3341 class MatcherBaseImpl<Derived<Ts...>> {
3345 template <
typename E = std::enable_if<
sizeof...(Ts) == 1>,
3346 typename E::type* =
nullptr>
3347 explicit MatcherBaseImpl(Ts... params)
3348 : params_(std::forward<Ts>(params)...) {}
3349 template <
typename E = std::enable_if<
sizeof...(Ts) != 1>,
3350 typename =
typename E::type>
3351 MatcherBaseImpl(Ts... params)
3352 : params_(std::forward<Ts>(params)...) {}
3354 template <
typename F>
3355 operator ::testing::Matcher<F>()
const {
3356 return Apply<F>(MakeIndexSequence<
sizeof...(Ts)>{});
3360 template <
typename F, std::size_t... tuple_ids>
3361 ::testing::Matcher<F> Apply(IndexSequence<tuple_ids...>)
const {
3362 return ::testing::Matcher<F>(
3363 new typename Derived<Ts...>::template gmock_Impl<F>(
3364 std::get<tuple_ids>(params_)...));
3367 const std::tuple<Ts...> params_;
3376 template <
typename T,
typename M>
3377 inline Matcher<T> MatcherCast(
const M& matcher) {
3378 return internal::MatcherCastImpl<T, M>::Cast(matcher);
3383 template <
typename T,
typename M>
3384 inline Matcher<T> SafeMatcherCast(
const M& polymorphic_matcher_or_value) {
3385 return MatcherCast<T>(polymorphic_matcher_or_value);
3397 template <
typename T,
typename U>
3398 inline Matcher<T> SafeMatcherCast(
const Matcher<U>& matcher) {
3400 static_assert(std::is_convertible<const T&, const U&>::value,
3401 "T must be implicitly convertible to U");
3404 GTEST_COMPILE_ASSERT_(
3405 std::is_reference<T>::value || !std::is_reference<U>::value,
3406 cannot_convert_non_reference_arg_to_reference);
3409 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
3410 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
3411 constexpr
bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
3412 constexpr
bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
3413 GTEST_COMPILE_ASSERT_(
3414 kTIsOther || kUIsOther ||
3415 (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
3416 conversion_of_arithmetic_types_must_be_lossless);
3417 return MatcherCast<T>(matcher);
3421 template <
typename T>
3426 namespace internal {
3429 inline void PrintIfNotEmpty(
const std::string& explanation,
3430 ::std::ostream* os) {
3431 if (explanation !=
"" && os !=
nullptr) {
3432 *os <<
", " << explanation;
3439 inline bool IsReadableTypeName(
const std::string& type_name) {
3442 return (type_name.length() <= 20 ||
3443 type_name.find_first_of(
"<(") == std::string::npos);
3451 template <
typename Value,
typename T>
3452 bool MatchPrintAndExplain(Value& value,
const Matcher<T>& matcher,
3453 MatchResultListener* listener) {
3454 if (!listener->IsInterested()) {
3457 return matcher.Matches(value);
3460 StringMatchResultListener inner_listener;
3461 const bool match = matcher.MatchAndExplain(value, &inner_listener);
3463 UniversalPrint(value, listener->stream());
3465 const std::string& type_name = GetTypeName<Value>();
3466 if (IsReadableTypeName(type_name))
3467 *listener->stream() <<
" (of type " << type_name <<
")";
3469 PrintIfNotEmpty(inner_listener.str(), listener->stream());
3482 template <
typename MatcherTuple,
typename ValueTuple>
3483 static bool Matches(
const MatcherTuple& matcher_tuple,
3484 const ValueTuple& value_tuple) {
3485 return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple) &&
3486 std::get<N - 1>(matcher_tuple).Matches(std::get<N - 1>(value_tuple));
3493 template <
typename MatcherTuple,
typename ValueTuple>
3494 static void ExplainMatchFailuresTo(
const MatcherTuple& matchers,
3495 const ValueTuple& values,
3496 ::std::ostream* os) {
3498 TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os);
3502 typename std::tuple_element<N - 1, MatcherTuple>::type matcher =
3504 typedef typename std::tuple_element<N - 1, ValueTuple>::type Value;
3505 const Value& value =
std::get<N - 1>(values);
3506 StringMatchResultListener listener;
3507 if (!matcher.MatchAndExplain(value, &listener)) {
3508 *os <<
" Expected arg #" << N - 1 <<
": ";
3509 std::get<N - 1>(matchers).DescribeTo(os);
3510 *os <<
"\n Actual: ";
3516 internal::UniversalPrint(value, os);
3517 PrintIfNotEmpty(listener.str(), os);
3525 class TuplePrefix<0> {
3527 template <
typename MatcherTuple,
typename ValueTuple>
3528 static bool Matches(
const MatcherTuple& ,
3529 const ValueTuple& ) {
3533 template <
typename MatcherTuple,
typename ValueTuple>
3534 static void ExplainMatchFailuresTo(
const MatcherTuple& ,
3536 ::std::ostream* ) {}
3544 template <
typename MatcherTuple,
typename ValueTuple>
3545 bool TupleMatches(
const MatcherTuple& matcher_tuple,
3546 const ValueTuple& value_tuple) {
3549 GTEST_COMPILE_ASSERT_(std::tuple_size<MatcherTuple>::value ==
3550 std::tuple_size<ValueTuple>::value,
3551 matcher_and_value_have_different_numbers_of_fields);
3552 return TuplePrefix<std::tuple_size<ValueTuple>::value>::Matches(matcher_tuple,
3558 template <
typename MatcherTuple,
typename ValueTuple>
3559 void ExplainMatchFailureTupleTo(
const MatcherTuple& matchers,
3560 const ValueTuple& values,
3561 ::std::ostream* os) {
3562 TuplePrefix<std::tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo(
3563 matchers, values, os);
3570 template <
typename Tuple,
typename Func,
typename OutIter>
3571 class TransformTupleValuesHelper {
3573 typedef ::std::tuple_size<Tuple> TupleSize;
3578 static OutIter Run(Func f,
const Tuple& t, OutIter out) {
3579 return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out);
3583 template <
typename Tup,
size_t kRemainingSize>
3584 struct IterateOverTuple {
3585 OutIter operator() (Func f,
const Tup& t, OutIter out)
const {
3586 *out++ = f(::std::get<TupleSize::value - kRemainingSize>(t));
3587 return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out);
3590 template <
typename Tup>
3591 struct IterateOverTuple<Tup, 0> {
3592 OutIter operator() (Func ,
const Tup& , OutIter out)
const {
3601 template <
typename Tuple,
typename Func,
typename OutIter>
3602 OutIter TransformTupleValues(Func f,
const Tuple& t, OutIter out) {
3603 return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out);
3610 class AnythingMatcher {
3612 using is_gtest_matcher = void;
3614 template <
typename T>
3615 bool MatchAndExplain(
const T& , std::ostream* )
const {
3618 void DescribeTo(std::ostream* os)
const { *os <<
"is anything"; }
3619 void DescribeNegationTo(::std::ostream* os)
const {
3623 *os <<
"never matches";
3629 class IsNullMatcher {
3631 template <
typename Po
inter>
3632 bool MatchAndExplain(
const Pointer& p,
3633 MatchResultListener* )
const {
3634 return p ==
nullptr;
3637 void DescribeTo(::std::ostream* os)
const { *os <<
"is NULL"; }
3638 void DescribeNegationTo(::std::ostream* os)
const {
3639 *os <<
"isn't NULL";
3645 class NotNullMatcher {
3647 template <
typename Po
inter>
3648 bool MatchAndExplain(
const Pointer& p,
3649 MatchResultListener* )
const {
3650 return p !=
nullptr;
3653 void DescribeTo(::std::ostream* os)
const { *os <<
"isn't NULL"; }
3654 void DescribeNegationTo(::std::ostream* os)
const {
3672 template <
typename T>
3675 template <
typename T>
3676 class RefMatcher<T&> {
3686 explicit RefMatcher(T& x) : object_(x) {}
3688 template <
typename Super>
3689 operator Matcher<Super&>()
const {
3695 return MakeMatcher(
new Impl<Super>(object_));
3699 template <
typename Super>
3700 class Impl :
public MatcherInterface<Super&> {
3702 explicit Impl(Super& x) : object_(x) {}
3706 bool MatchAndExplain(Super& x,
3707 MatchResultListener* listener)
const override {
3708 *listener <<
"which is located @" <<
static_cast<const void*
>(&x);
3709 return &x == &object_;
3712 void DescribeTo(::std::ostream* os)
const override {
3713 *os <<
"references the variable ";
3714 UniversalPrinter<Super&>::Print(object_, os);
3717 void DescribeNegationTo(::std::ostream* os)
const override {
3718 *os <<
"does not reference the variable ";
3719 UniversalPrinter<Super&>::Print(object_, os);
3723 const Super& object_;
3730 inline bool CaseInsensitiveCStringEquals(
const char* lhs,
const char* rhs) {
3731 return String::CaseInsensitiveCStringEquals(lhs, rhs);
3734 inline bool CaseInsensitiveCStringEquals(
const wchar_t* lhs,
3735 const wchar_t* rhs) {
3736 return String::CaseInsensitiveWideCStringEquals(lhs, rhs);
3741 template <
typename StringType>
3742 bool CaseInsensitiveStringEquals(
const StringType& s1,
3743 const StringType& s2) {
3745 if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) {
3750 const typename StringType::value_type nul = 0;
3751 const size_t i1 = s1.find(nul), i2 = s2.find(nul);
3754 if (i1 == StringType::npos || i2 == StringType::npos) {
3759 return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1));
3765 template <
typename StringType>
3766 class StrEqualityMatcher {
3768 StrEqualityMatcher(StringType str,
bool expect_eq,
bool case_sensitive)
3769 : string_(
std::move(str)),
3770 expect_eq_(expect_eq),
3771 case_sensitive_(case_sensitive) {}
3773 #if GTEST_INTERNAL_HAS_STRING_VIEW 3774 bool MatchAndExplain(
const internal::StringView& s,
3775 MatchResultListener* listener)
const {
3778 const StringType& str = std::string(s);
3779 return MatchAndExplain(str, listener);
3781 #endif // GTEST_INTERNAL_HAS_STRING_VIEW 3788 template <
typename CharType>
3789 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
3793 return MatchAndExplain(StringType(s), listener);
3800 template <
typename MatcheeStringType>
3801 bool MatchAndExplain(
const MatcheeStringType& s,
3802 MatchResultListener* )
const {
3803 const StringType s2(s);
3804 const bool eq = case_sensitive_ ? s2 == string_ :
3805 CaseInsensitiveStringEquals(s2, string_);
3806 return expect_eq_ == eq;
3809 void DescribeTo(::std::ostream* os)
const {
3810 DescribeToHelper(expect_eq_, os);
3813 void DescribeNegationTo(::std::ostream* os)
const {
3814 DescribeToHelper(!expect_eq_, os);
3818 void DescribeToHelper(
bool expect_eq, ::std::ostream* os)
const {
3819 *os << (expect_eq ?
"is " :
"isn't ");
3821 if (!case_sensitive_) {
3822 *os <<
"(ignoring case) ";
3824 UniversalPrint(string_, os);
3827 const StringType string_;
3828 const bool expect_eq_;
3829 const bool case_sensitive_;
3835 template <
typename StringType>
3836 class HasSubstrMatcher {
3838 explicit HasSubstrMatcher(
const StringType& substring)
3839 : substring_(substring) {}
3841 #if GTEST_INTERNAL_HAS_STRING_VIEW 3842 bool MatchAndExplain(
const internal::StringView& s,
3843 MatchResultListener* listener)
const {
3846 const StringType& str = std::string(s);
3847 return MatchAndExplain(str, listener);
3849 #endif // GTEST_INTERNAL_HAS_STRING_VIEW 3856 template <
typename CharType>
3857 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
3858 return s !=
nullptr && MatchAndExplain(StringType(s), listener);
3865 template <
typename MatcheeStringType>
3866 bool MatchAndExplain(
const MatcheeStringType& s,
3867 MatchResultListener* )
const {
3868 return StringType(s).find(substring_) != StringType::npos;
3872 void DescribeTo(::std::ostream* os)
const {
3873 *os <<
"has substring ";
3874 UniversalPrint(substring_, os);
3877 void DescribeNegationTo(::std::ostream* os)
const {
3878 *os <<
"has no substring ";
3879 UniversalPrint(substring_, os);
3883 const StringType substring_;
3889 template <
typename StringType>
3890 class StartsWithMatcher {
3892 explicit StartsWithMatcher(
const StringType& prefix) : prefix_(prefix) {
3895 #if GTEST_INTERNAL_HAS_STRING_VIEW 3896 bool MatchAndExplain(
const internal::StringView& s,
3897 MatchResultListener* listener)
const {
3900 const StringType& str = std::string(s);
3901 return MatchAndExplain(str, listener);
3903 #endif // GTEST_INTERNAL_HAS_STRING_VIEW 3910 template <
typename CharType>
3911 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
3912 return s !=
nullptr && MatchAndExplain(StringType(s), listener);
3919 template <
typename MatcheeStringType>
3920 bool MatchAndExplain(
const MatcheeStringType& s,
3921 MatchResultListener* )
const {
3922 const StringType& s2(s);
3923 return s2.length() >= prefix_.length() &&
3924 s2.substr(0, prefix_.length()) == prefix_;
3927 void DescribeTo(::std::ostream* os)
const {
3928 *os <<
"starts with ";
3929 UniversalPrint(prefix_, os);
3932 void DescribeNegationTo(::std::ostream* os)
const {
3933 *os <<
"doesn't start with ";
3934 UniversalPrint(prefix_, os);
3938 const StringType prefix_;
3944 template <
typename StringType>
3945 class EndsWithMatcher {
3947 explicit EndsWithMatcher(
const StringType& suffix) : suffix_(suffix) {}
3949 #if GTEST_INTERNAL_HAS_STRING_VIEW 3950 bool MatchAndExplain(
const internal::StringView& s,
3951 MatchResultListener* listener)
const {
3954 const StringType& str = std::string(s);
3955 return MatchAndExplain(str, listener);
3957 #endif // GTEST_INTERNAL_HAS_STRING_VIEW 3964 template <
typename CharType>
3965 bool MatchAndExplain(CharType* s, MatchResultListener* listener)
const {
3966 return s !=
nullptr && MatchAndExplain(StringType(s), listener);
3973 template <
typename MatcheeStringType>
3974 bool MatchAndExplain(
const MatcheeStringType& s,
3975 MatchResultListener* )
const {
3976 const StringType& s2(s);
3977 return s2.length() >= suffix_.length() &&
3978 s2.substr(s2.length() - suffix_.length()) == suffix_;
3981 void DescribeTo(::std::ostream* os)
const {
3982 *os <<
"ends with ";
3983 UniversalPrint(suffix_, os);
3986 void DescribeNegationTo(::std::ostream* os)
const {
3987 *os <<
"doesn't end with ";
3988 UniversalPrint(suffix_, os);
3992 const StringType suffix_;
4003 template <
typename D,
typename Op>
4004 class PairMatchBase {
4006 template <
typename T1,
typename T2>
4007 operator Matcher<::std::tuple<T1, T2>>()
const {
4008 return Matcher<::std::tuple<T1, T2>>(
new Impl<const ::std::tuple<T1, T2>&>);
4010 template <
typename T1,
typename T2>
4011 operator Matcher<const ::std::tuple<T1, T2>&>()
const {
4012 return MakeMatcher(
new Impl<const ::std::tuple<T1, T2>&>);
4016 static ::std::ostream& GetDesc(::std::ostream& os) {
4017 return os << D::Desc();
4020 template <
typename Tuple>
4021 class Impl :
public MatcherInterface<Tuple> {
4023 bool MatchAndExplain(Tuple args,
4024 MatchResultListener* )
const override {
4025 return Op()(::std::get<0>(args), ::std::get<1>(args));
4027 void DescribeTo(::std::ostream* os)
const override {
4028 *os <<
"are " << GetDesc;
4030 void DescribeNegationTo(::std::ostream* os)
const override {
4031 *os <<
"aren't " << GetDesc;
4036 class Eq2Matcher :
public PairMatchBase<Eq2Matcher, AnyEq> {
4038 static const char* Desc() {
return "an equal pair"; }
4040 class Ne2Matcher :
public PairMatchBase<Ne2Matcher, AnyNe> {
4042 static const char* Desc() {
return "an unequal pair"; }
4044 class Lt2Matcher :
public PairMatchBase<Lt2Matcher, AnyLt> {
4046 static const char* Desc() {
return "a pair where the first < the second"; }
4048 class Gt2Matcher :
public PairMatchBase<Gt2Matcher, AnyGt> {
4050 static const char* Desc() {
return "a pair where the first > the second"; }
4052 class Le2Matcher :
public PairMatchBase<Le2Matcher, AnyLe> {
4054 static const char* Desc() {
return "a pair where the first <= the second"; }
4056 class Ge2Matcher :
public PairMatchBase<Ge2Matcher, AnyGe> {
4058 static const char* Desc() {
return "a pair where the first >= the second"; }
4065 template <
typename T>
4066 class NotMatcherImpl :
public MatcherInterface<const T&> {
4068 explicit NotMatcherImpl(
const Matcher<T>& matcher)
4069 : matcher_(matcher) {}
4071 bool MatchAndExplain(
const T& x,
4072 MatchResultListener* listener)
const override {
4073 return !matcher_.MatchAndExplain(x, listener);
4076 void DescribeTo(::std::ostream* os)
const override {
4077 matcher_.DescribeNegationTo(os);
4080 void DescribeNegationTo(::std::ostream* os)
const override {
4081 matcher_.DescribeTo(os);
4085 const Matcher<T> matcher_;
4090 template <
typename InnerMatcher>
4093 explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
4097 template <
typename T>
4098 operator Matcher<T>()
const {
4099 return Matcher<T>(
new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_)));
4103 InnerMatcher matcher_;
4110 template <
typename T>
4111 class AllOfMatcherImpl :
public MatcherInterface<const T&> {
4113 explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers)
4114 : matchers_(
std::move(matchers)) {}
4116 void DescribeTo(::std::ostream* os)
const override {
4118 for (
size_t i = 0; i < matchers_.size(); ++i) {
4119 if (i != 0) *os <<
") and (";
4120 matchers_[i].DescribeTo(os);
4125 void DescribeNegationTo(::std::ostream* os)
const override {
4127 for (
size_t i = 0; i < matchers_.size(); ++i) {
4128 if (i != 0) *os <<
") or (";
4129 matchers_[i].DescribeNegationTo(os);
4134 bool MatchAndExplain(
const T& x,
4135 MatchResultListener* listener)
const override {
4138 std::string all_match_result;
4140 for (
size_t i = 0; i < matchers_.size(); ++i) {
4141 StringMatchResultListener slistener;
4142 if (matchers_[i].MatchAndExplain(x, &slistener)) {
4143 if (all_match_result.empty()) {
4144 all_match_result = slistener.str();
4146 std::string result = slistener.str();
4147 if (!result.empty()) {
4148 all_match_result +=
", and ";
4149 all_match_result += result;
4153 *listener << slistener.str();
4159 *listener << all_match_result;
4164 const std::vector<Matcher<T> > matchers_;
4171 template <
template <
typename T>
class CombiningMatcher,
typename... Args>
4172 class VariadicMatcher {
4174 VariadicMatcher(
const Args&... matchers)
4175 : matchers_(matchers...) {
4176 static_assert(
sizeof...(Args) > 0,
"Must have at least one matcher.");
4179 VariadicMatcher(
const VariadicMatcher&) =
default;
4180 VariadicMatcher& operator=(
const VariadicMatcher&) =
delete;
4185 template <
typename T>
4186 operator Matcher<T>()
const {
4187 std::vector<Matcher<T> > values;
4188 CreateVariadicMatcher<T>(&values, std::integral_constant<size_t, 0>());
4189 return Matcher<T>(
new CombiningMatcher<T>(std::move(values)));
4193 template <
typename T,
size_t I>
4194 void CreateVariadicMatcher(std::vector<Matcher<T> >* values,
4195 std::integral_constant<size_t, I>)
const {
4196 values->push_back(SafeMatcherCast<T>(std::get<I>(matchers_)));
4197 CreateVariadicMatcher<T>(values, std::integral_constant<size_t, I + 1>());
4200 template <
typename T>
4201 void CreateVariadicMatcher(
4202 std::vector<Matcher<T> >*,
4203 std::integral_constant<
size_t,
sizeof...(Args)>)
const {}
4205 std::tuple<Args...> matchers_;
4208 template <
typename... Args>
4209 using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>;
4215 template <
typename T>
4216 class AnyOfMatcherImpl :
public MatcherInterface<const T&> {
4218 explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers)
4219 : matchers_(
std::move(matchers)) {}
4221 void DescribeTo(::std::ostream* os)
const override {
4223 for (
size_t i = 0; i < matchers_.size(); ++i) {
4224 if (i != 0) *os <<
") or (";
4225 matchers_[i].DescribeTo(os);
4230 void DescribeNegationTo(::std::ostream* os)
const override {
4232 for (
size_t i = 0; i < matchers_.size(); ++i) {
4233 if (i != 0) *os <<
") and (";
4234 matchers_[i].DescribeNegationTo(os);
4239 bool MatchAndExplain(
const T& x,
4240 MatchResultListener* listener)
const override {
4241 std::string no_match_result;
4245 for (
size_t i = 0; i < matchers_.size(); ++i) {
4246 StringMatchResultListener slistener;
4247 if (matchers_[i].MatchAndExplain(x, &slistener)) {
4248 *listener << slistener.str();
4251 if (no_match_result.empty()) {
4252 no_match_result = slistener.str();
4254 std::string result = slistener.str();
4255 if (!result.empty()) {
4256 no_match_result +=
", and ";
4257 no_match_result += result;
4264 *listener << no_match_result;
4269 const std::vector<Matcher<T> > matchers_;
4273 template <
typename... Args>
4274 using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>;
4277 template <
template <
class>
class MatcherImpl,
typename T>
4278 class SomeOfArrayMatcher {
4282 template <
typename Iter>
4283 SomeOfArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
4285 template <
typename U>
4286 operator Matcher<U>()
const {
4287 using RawU =
typename std::decay<U>::type;
4288 std::vector<Matcher<RawU>> matchers;
4289 for (
const auto& matcher : matchers_) {
4290 matchers.push_back(MatcherCast<RawU>(matcher));
4292 return Matcher<U>(
new MatcherImpl<RawU>(std::move(matchers)));
4296 const ::std::vector<T> matchers_;
4299 template <
typename T>
4300 using AllOfArrayMatcher = SomeOfArrayMatcher<AllOfMatcherImpl, T>;
4302 template <
typename T>
4303 using AnyOfArrayMatcher = SomeOfArrayMatcher<AnyOfMatcherImpl, T>;
4307 template <
typename Predicate>
4308 class TrulyMatcher {
4310 explicit TrulyMatcher(Predicate pred) : predicate_(pred) {}
4316 template <
typename T>
4317 bool MatchAndExplain(T& x,
4318 MatchResultListener* listener)
const {
4327 *listener <<
"didn't satisfy the given predicate";
4331 void DescribeTo(::std::ostream* os)
const {
4332 *os <<
"satisfies the given predicate";
4335 void DescribeNegationTo(::std::ostream* os)
const {
4336 *os <<
"doesn't satisfy the given predicate";
4340 Predicate predicate_;
4345 template <
typename M>
4346 class MatcherAsPredicate {
4348 explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
4356 template <
typename T>
4357 bool operator()(
const T& x)
const {
4372 return MatcherCast<const T&>(matcher_).Matches(x);
4381 template <
typename M>
4382 class PredicateFormatterFromMatcher {
4384 explicit PredicateFormatterFromMatcher(M m) : matcher_(
std::move(m)) {}
4389 template <
typename T>
4390 AssertionResult operator()(
const char* value_text,
const T& x)
const {
4402 const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
4406 if (matcher.Matches(x)) {
4407 return AssertionSuccess();
4410 ::std::stringstream ss;
4411 ss <<
"Value of: " << value_text <<
"\n" 4413 matcher.DescribeTo(&ss);
4416 StringMatchResultListener listener;
4417 if (MatchPrintAndExplain(x, matcher, &listener)) {
4418 ss <<
"\n The matcher failed on the initial attempt; but passed when " 4419 "rerun to generate the explanation.";
4421 ss <<
"\n Actual: " << listener.str();
4422 return AssertionFailure() << ss.str();
4433 template <
typename M>
4434 inline PredicateFormatterFromMatcher<M>
4435 MakePredicateFormatterFromMatcher(M matcher) {
4436 return PredicateFormatterFromMatcher<M>(std::move(matcher));
4441 class IsNanMatcher {
4443 template <
typename FloatType>
4444 bool MatchAndExplain(
const FloatType& f,
4445 MatchResultListener* )
const {
4446 return (::std::isnan)(f);
4449 void DescribeTo(::std::ostream* os)
const { *os <<
"is NaN"; }
4450 void DescribeNegationTo(::std::ostream* os)
const {
4459 template <
typename FloatType>
4460 class FloatingEqMatcher {
4468 FloatingEqMatcher(FloatType expected,
bool nan_eq_nan) :
4469 expected_(expected), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) {
4475 FloatingEqMatcher(FloatType expected,
bool nan_eq_nan,
4476 FloatType max_abs_error)
4477 : expected_(expected),
4478 nan_eq_nan_(nan_eq_nan),
4479 max_abs_error_(max_abs_error) {
4480 GTEST_CHECK_(max_abs_error >= 0)
4481 <<
", where max_abs_error is" << max_abs_error;
4485 template <
typename T>
4486 class Impl :
public MatcherInterface<T> {
4488 Impl(FloatType expected,
bool nan_eq_nan, FloatType max_abs_error)
4489 : expected_(expected),
4490 nan_eq_nan_(nan_eq_nan),
4491 max_abs_error_(max_abs_error) {}
4493 bool MatchAndExplain(T value,
4494 MatchResultListener* listener)
const override {
4495 const FloatingPoint<FloatType> actual(value), expected(expected_);
4498 if (actual.is_nan() || expected.is_nan()) {
4499 if (actual.is_nan() && expected.is_nan()) {
4505 if (HasMaxAbsError()) {
4510 if (value == expected_) {
4514 const FloatType diff = value - expected_;
4515 if (::std::fabs(diff) <= max_abs_error_) {
4519 if (listener->IsInterested()) {
4520 *listener <<
"which is " << diff <<
" from " << expected_;
4524 return actual.AlmostEquals(expected);
4528 void DescribeTo(::std::ostream* os)
const override {
4532 const ::std::streamsize old_precision = os->precision(
4533 ::std::numeric_limits<FloatType>::digits10 + 2);
4534 if (FloatingPoint<FloatType>(expected_).is_nan()) {
4538 *os <<
"never matches";
4541 *os <<
"is approximately " << expected_;
4542 if (HasMaxAbsError()) {
4543 *os <<
" (absolute error <= " << max_abs_error_ <<
")";
4546 os->precision(old_precision);
4549 void DescribeNegationTo(::std::ostream* os)
const override {
4551 const ::std::streamsize old_precision = os->precision(
4552 ::std::numeric_limits<FloatType>::digits10 + 2);
4553 if (FloatingPoint<FloatType>(expected_).is_nan()) {
4557 *os <<
"is anything";
4560 *os <<
"isn't approximately " << expected_;
4561 if (HasMaxAbsError()) {
4562 *os <<
" (absolute error > " << max_abs_error_ <<
")";
4566 os->precision(old_precision);
4570 bool HasMaxAbsError()
const {
4571 return max_abs_error_ >= 0;
4574 const FloatType expected_;
4575 const bool nan_eq_nan_;
4577 const FloatType max_abs_error_;
4583 operator Matcher<FloatType>()
const {
4585 new Impl<FloatType>(expected_, nan_eq_nan_, max_abs_error_));
4588 operator Matcher<const FloatType&>()
const {
4590 new Impl<const FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
4593 operator Matcher<FloatType&>()
const {
4595 new Impl<FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
4599 const FloatType expected_;
4600 const bool nan_eq_nan_;
4602 const FloatType max_abs_error_;
4610 template <
typename FloatType>
4611 class FloatingEq2Matcher {
4613 FloatingEq2Matcher() { Init(-1,
false); }
4615 explicit FloatingEq2Matcher(
bool nan_eq_nan) { Init(-1, nan_eq_nan); }
4617 explicit FloatingEq2Matcher(FloatType max_abs_error) {
4618 Init(max_abs_error,
false);
4621 FloatingEq2Matcher(FloatType max_abs_error,
bool nan_eq_nan) {
4622 Init(max_abs_error, nan_eq_nan);
4625 template <
typename T1,
typename T2>
4626 operator Matcher<::std::tuple<T1, T2>>()
const {
4628 new Impl<::std::tuple<T1, T2>>(max_abs_error_, nan_eq_nan_));
4630 template <
typename T1,
typename T2>
4631 operator Matcher<const ::std::tuple<T1, T2>&>()
const {
4633 new Impl<const ::std::tuple<T1, T2>&>(max_abs_error_, nan_eq_nan_));
4637 static ::std::ostream& GetDesc(::std::ostream& os) {
4638 return os <<
"an almost-equal pair";
4641 template <
typename Tuple>
4642 class Impl :
public MatcherInterface<Tuple> {
4644 Impl(FloatType max_abs_error,
bool nan_eq_nan) :
4645 max_abs_error_(max_abs_error),
4646 nan_eq_nan_(nan_eq_nan) {}
4648 bool MatchAndExplain(Tuple args,
4649 MatchResultListener* listener)
const override {
4650 if (max_abs_error_ == -1) {
4651 FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_);
4652 return static_cast<Matcher<FloatType>
>(fm).MatchAndExplain(
4653 ::std::get<1>(args), listener);
4655 FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_,
4657 return static_cast<Matcher<FloatType>
>(fm).MatchAndExplain(
4658 ::std::get<1>(args), listener);
4661 void DescribeTo(::std::ostream* os)
const override {
4662 *os <<
"are " << GetDesc;
4664 void DescribeNegationTo(::std::ostream* os)
const override {
4665 *os <<
"aren't " << GetDesc;
4669 FloatType max_abs_error_;
4670 const bool nan_eq_nan_;
4673 void Init(FloatType max_abs_error_val,
bool nan_eq_nan_val) {
4674 max_abs_error_ = max_abs_error_val;
4675 nan_eq_nan_ = nan_eq_nan_val;
4677 FloatType max_abs_error_;
4683 template <
typename InnerMatcher>
4684 class PointeeMatcher {
4686 explicit PointeeMatcher(
const InnerMatcher& matcher) : matcher_(matcher) {}
4696 template <
typename Po
inter>
4697 operator Matcher<Pointer>()
const {
4698 return Matcher<Pointer>(
new Impl<const Pointer&>(matcher_));
4703 template <
typename Po
inter>
4704 class Impl :
public MatcherInterface<Pointer> {
4707 typename std::pointer_traits<GTEST_REMOVE_REFERENCE_AND_CONST_(
4708 Pointer)>::element_type;
4710 explicit Impl(
const InnerMatcher& matcher)
4711 : matcher_(MatcherCast<const Pointee&>(matcher)) {}
4713 void DescribeTo(::std::ostream* os)
const override {
4714 *os <<
"points to a value that ";
4715 matcher_.DescribeTo(os);
4718 void DescribeNegationTo(::std::ostream* os)
const override {
4719 *os <<
"does not point to a value that ";
4720 matcher_.DescribeTo(os);
4723 bool MatchAndExplain(Pointer pointer,
4724 MatchResultListener* listener)
const override {
4725 if (GetRawPointer(pointer) ==
nullptr)
return false;
4727 *listener <<
"which points to ";
4728 return MatchPrintAndExplain(*pointer, matcher_, listener);
4732 const Matcher<const Pointee&> matcher_;
4735 const InnerMatcher matcher_;
4742 template <
typename InnerMatcher>
4743 class PointerMatcher {
4745 explicit PointerMatcher(
const InnerMatcher& matcher) : matcher_(matcher) {}
4755 template <
typename Po
interType>
4756 operator Matcher<PointerType>()
const {
4757 return Matcher<PointerType>(
new Impl<const PointerType&>(matcher_));
4762 template <
typename Po
interType>
4763 class Impl :
public MatcherInterface<PointerType> {
4766 const typename std::pointer_traits<GTEST_REMOVE_REFERENCE_AND_CONST_(
4767 PointerType)>::element_type*;
4769 explicit Impl(
const InnerMatcher& matcher)
4770 : matcher_(MatcherCast<Pointer>(matcher)) {}
4772 void DescribeTo(::std::ostream* os)
const override {
4773 *os <<
"is a pointer that ";
4774 matcher_.DescribeTo(os);
4777 void DescribeNegationTo(::std::ostream* os)
const override {
4778 *os <<
"is not a pointer that ";
4779 matcher_.DescribeTo(os);
4782 bool MatchAndExplain(PointerType pointer,
4783 MatchResultListener* listener)
const override {
4784 *listener <<
"which is a pointer that ";
4785 Pointer p = GetRawPointer(pointer);
4786 return MatchPrintAndExplain(p, matcher_, listener);
4790 Matcher<Pointer> matcher_;
4793 const InnerMatcher matcher_;
4803 template <
typename To>
4804 class WhenDynamicCastToMatcherBase {
4806 explicit WhenDynamicCastToMatcherBase(
const Matcher<To>& matcher)
4807 : matcher_(matcher) {}
4809 void DescribeTo(::std::ostream* os)
const {
4810 GetCastTypeDescription(os);
4811 matcher_.DescribeTo(os);
4814 void DescribeNegationTo(::std::ostream* os)
const {
4815 GetCastTypeDescription(os);
4816 matcher_.DescribeNegationTo(os);
4820 const Matcher<To> matcher_;
4822 static std::string GetToName() {
4823 return GetTypeName<To>();
4827 static void GetCastTypeDescription(::std::ostream* os) {
4828 *os <<
"when dynamic_cast to " << GetToName() <<
", ";
4834 template <
typename To>
4835 class WhenDynamicCastToMatcher :
public WhenDynamicCastToMatcherBase<To> {
4837 explicit WhenDynamicCastToMatcher(
const Matcher<To>& matcher)
4838 : WhenDynamicCastToMatcherBase<To>(matcher) {}
4840 template <
typename From>
4841 bool MatchAndExplain(From from, MatchResultListener* listener)
const {
4842 To to =
dynamic_cast<To
>(from);
4843 return MatchPrintAndExplain(to, this->matcher_, listener);
4849 template <
typename To>
4850 class WhenDynamicCastToMatcher<To&> :
public WhenDynamicCastToMatcherBase<To&> {
4852 explicit WhenDynamicCastToMatcher(
const Matcher<To&>& matcher)
4853 : WhenDynamicCastToMatcherBase<To&>(matcher) {}
4855 template <
typename From>
4856 bool MatchAndExplain(From& from, MatchResultListener* listener)
const {
4858 To* to =
dynamic_cast<To*
>(&from);
4859 if (to ==
nullptr) {
4860 *listener <<
"which cannot be dynamic_cast to " << this->GetToName();
4863 return MatchPrintAndExplain(*to, this->matcher_, listener);
4866 #endif // GTEST_HAS_RTTI 4870 template <
typename Class,
typename FieldType>
4871 class FieldMatcher {
4873 FieldMatcher(FieldType Class::*field,
4874 const Matcher<const FieldType&>& matcher)
4875 : field_(field), matcher_(matcher), whose_field_(
"whose given field ") {}
4877 FieldMatcher(
const std::string& field_name, FieldType Class::*field,
4878 const Matcher<const FieldType&>& matcher)
4881 whose_field_(
"whose field `" + field_name +
"` ") {}
4883 void DescribeTo(::std::ostream* os)
const {
4884 *os <<
"is an object " << whose_field_;
4885 matcher_.DescribeTo(os);
4888 void DescribeNegationTo(::std::ostream* os)
const {
4889 *os <<
"is an object " << whose_field_;
4890 matcher_.DescribeNegationTo(os);
4893 template <
typename T>
4894 bool MatchAndExplain(
const T& value, MatchResultListener* listener)
const {
4897 return MatchAndExplainImpl(
4898 typename std::is_pointer<
typename std::remove_const<T>::type>::type(),
4903 bool MatchAndExplainImpl(std::false_type ,
4905 MatchResultListener* listener)
const {
4906 *listener << whose_field_ <<
"is ";
4907 return MatchPrintAndExplain(obj.*field_, matcher_, listener);
4910 bool MatchAndExplainImpl(std::true_type ,
const Class* p,
4911 MatchResultListener* listener)
const {
4912 if (p ==
nullptr)
return false;
4914 *listener <<
"which points to an object ";
4918 return MatchAndExplainImpl(std::false_type(), *p, listener);
4921 const FieldType Class::*field_;
4922 const Matcher<const FieldType&> matcher_;
4926 const std::string whose_field_;
4934 template <
typename Class,
typename PropertyType,
typename Property>
4935 class PropertyMatcher {
4937 typedef const PropertyType& RefToConstProperty;
4939 PropertyMatcher(Property property,
const Matcher<RefToConstProperty>& matcher)
4940 : property_(property),
4942 whose_property_(
"whose given property ") {}
4944 PropertyMatcher(
const std::string& property_name, Property property,
4945 const Matcher<RefToConstProperty>& matcher)
4946 : property_(property),
4948 whose_property_(
"whose property `" + property_name +
"` ") {}
4950 void DescribeTo(::std::ostream* os)
const {
4951 *os <<
"is an object " << whose_property_;
4952 matcher_.DescribeTo(os);
4955 void DescribeNegationTo(::std::ostream* os)
const {
4956 *os <<
"is an object " << whose_property_;
4957 matcher_.DescribeNegationTo(os);
4960 template <
typename T>
4961 bool MatchAndExplain(
const T&value, MatchResultListener* listener)
const {
4962 return MatchAndExplainImpl(
4963 typename std::is_pointer<
typename std::remove_const<T>::type>::type(),
4968 bool MatchAndExplainImpl(std::false_type ,
4970 MatchResultListener* listener)
const {
4971 *listener << whose_property_ <<
"is ";
4974 RefToConstProperty result = (obj.*property_)();
4975 return MatchPrintAndExplain(result, matcher_, listener);
4978 bool MatchAndExplainImpl(std::true_type ,
const Class* p,
4979 MatchResultListener* listener)
const {
4980 if (p ==
nullptr)
return false;
4982 *listener <<
"which points to an object ";
4986 return MatchAndExplainImpl(std::false_type(), *p, listener);
4990 const Matcher<RefToConstProperty> matcher_;
4994 const std::string whose_property_;
4999 template <
typename Functor>
5000 struct CallableTraits {
5001 typedef Functor StorageType;
5003 static void CheckIsValid(Functor ) {}
5005 template <
typename T>
5006 static auto Invoke(Functor f,
const T& arg) -> decltype(f(arg)) {
5012 template <
typename ArgType,
typename ResType>
5013 struct CallableTraits<ResType(*)(ArgType)> {
5014 typedef ResType ResultType;
5015 typedef ResType(*StorageType)(ArgType);
5017 static void CheckIsValid(ResType(*f)(ArgType)) {
5018 GTEST_CHECK_(f !=
nullptr)
5019 <<
"NULL function pointer is passed into ResultOf().";
5021 template <
typename T>
5022 static ResType Invoke(ResType(*f)(ArgType), T arg) {
5029 template <
typename Callable,
typename InnerMatcher>
5030 class ResultOfMatcher {
5032 ResultOfMatcher(Callable callable, InnerMatcher matcher)
5033 : callable_(
std::move(callable)), matcher_(
std::move(matcher)) {
5034 CallableTraits<Callable>::CheckIsValid(callable_);
5037 template <
typename T>
5038 operator Matcher<T>()
const {
5039 return Matcher<T>(
new Impl<const T&>(callable_, matcher_));
5043 typedef typename CallableTraits<Callable>::StorageType CallableStorageType;
5045 template <
typename T>
5046 class Impl :
public MatcherInterface<T> {
5047 using ResultType = decltype(CallableTraits<Callable>::template Invoke<T>(
5048 std::declval<CallableStorageType>(), std::declval<T>()));
5051 template <
typename M>
5052 Impl(
const CallableStorageType& callable,
const M& matcher)
5053 : callable_(callable), matcher_(MatcherCast<ResultType>(matcher)) {}
5055 void DescribeTo(::std::ostream* os)
const override {
5056 *os <<
"is mapped by the given callable to a value that ";
5057 matcher_.DescribeTo(os);
5060 void DescribeNegationTo(::std::ostream* os)
const override {
5061 *os <<
"is mapped by the given callable to a value that ";
5062 matcher_.DescribeNegationTo(os);
5065 bool MatchAndExplain(T obj, MatchResultListener* listener)
const override {
5066 *listener <<
"which is mapped by the given callable to ";
5072 CallableTraits<Callable>::template Invoke<T>(callable_, obj);
5073 return MatchPrintAndExplain(result, matcher_, listener);
5082 mutable CallableStorageType callable_;
5083 const Matcher<ResultType> matcher_;
5086 const CallableStorageType callable_;
5087 const InnerMatcher matcher_;
5091 template <
typename SizeMatcher>
5092 class SizeIsMatcher {
5094 explicit SizeIsMatcher(
const SizeMatcher& size_matcher)
5095 : size_matcher_(size_matcher) {
5098 template <
typename Container>
5099 operator Matcher<Container>()
const {
5100 return Matcher<Container>(
new Impl<const Container&>(size_matcher_));
5103 template <
typename Container>
5104 class Impl :
public MatcherInterface<Container> {
5106 using SizeType = decltype(std::declval<Container>().size());
5107 explicit Impl(
const SizeMatcher& size_matcher)
5108 : size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
5110 void DescribeTo(::std::ostream* os)
const override {
5112 size_matcher_.DescribeTo(os);
5114 void DescribeNegationTo(::std::ostream* os)
const override {
5116 size_matcher_.DescribeNegationTo(os);
5119 bool MatchAndExplain(Container container,
5120 MatchResultListener* listener)
const override {
5121 SizeType size = container.size();
5122 StringMatchResultListener size_listener;
5123 const bool result = size_matcher_.MatchAndExplain(size, &size_listener);
5125 <<
"whose size " << size << (result ?
" matches" :
" doesn't match");
5126 PrintIfNotEmpty(size_listener.str(), listener->stream());
5131 const Matcher<SizeType> size_matcher_;
5135 const SizeMatcher size_matcher_;
5140 template <
typename DistanceMatcher>
5141 class BeginEndDistanceIsMatcher {
5143 explicit BeginEndDistanceIsMatcher(
const DistanceMatcher& distance_matcher)
5144 : distance_matcher_(distance_matcher) {}
5146 template <
typename Container>
5147 operator Matcher<Container>()
const {
5148 return Matcher<Container>(
new Impl<const Container&>(distance_matcher_));
5151 template <
typename Container>
5152 class Impl :
public MatcherInterface<Container> {
5154 typedef internal::StlContainerView<
5155 GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
5156 typedef typename std::iterator_traits<
5157 typename ContainerView::type::const_iterator>::difference_type
5159 explicit Impl(
const DistanceMatcher& distance_matcher)
5160 : distance_matcher_(MatcherCast<DistanceType>(distance_matcher)) {}
5162 void DescribeTo(::std::ostream* os)
const override {
5163 *os <<
"distance between begin() and end() ";
5164 distance_matcher_.DescribeTo(os);
5166 void DescribeNegationTo(::std::ostream* os)
const override {
5167 *os <<
"distance between begin() and end() ";
5168 distance_matcher_.DescribeNegationTo(os);
5171 bool MatchAndExplain(Container container,
5172 MatchResultListener* listener)
const override {
5175 DistanceType distance = std::distance(begin(container), end(container));
5176 StringMatchResultListener distance_listener;
5178 distance_matcher_.MatchAndExplain(distance, &distance_listener);
5179 *listener <<
"whose distance between begin() and end() " << distance
5180 << (result ?
" matches" :
" doesn't match");
5181 PrintIfNotEmpty(distance_listener.str(), listener->stream());
5186 const Matcher<DistanceType> distance_matcher_;
5190 const DistanceMatcher distance_matcher_;
5203 template <
typename Container>
5204 class ContainerEqMatcher {
5206 typedef internal::StlContainerView<Container> View;
5207 typedef typename View::type StlContainer;
5208 typedef typename View::const_reference StlContainerReference;
5210 static_assert(!std::is_const<Container>::value,
5211 "Container type must not be const");
5212 static_assert(!std::is_reference<Container>::value,
5213 "Container type must not be a reference");
5217 explicit ContainerEqMatcher(
const Container& expected)
5218 : expected_(View::Copy(expected)) {}
5220 void DescribeTo(::std::ostream* os)
const {
5222 UniversalPrint(expected_, os);
5224 void DescribeNegationTo(::std::ostream* os)
const {
5225 *os <<
"does not equal ";
5226 UniversalPrint(expected_, os);
5229 template <
typename LhsContainer>
5230 bool MatchAndExplain(
const LhsContainer& lhs,
5231 MatchResultListener* listener)
const {
5232 typedef internal::StlContainerView<
5233 typename std::remove_const<LhsContainer>::type>
5235 typedef typename LhsView::type LhsStlContainer;
5236 StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
5237 if (lhs_stl_container == expected_)
5240 ::std::ostream*
const os = listener->stream();
5241 if (os !=
nullptr) {
5243 bool printed_header =
false;
5244 for (
typename LhsStlContainer::const_iterator it =
5245 lhs_stl_container.begin();
5246 it != lhs_stl_container.end(); ++it) {
5247 if (internal::ArrayAwareFind(expected_.begin(), expected_.end(), *it) ==
5249 if (printed_header) {
5252 *os <<
"which has these unexpected elements: ";
5253 printed_header =
true;
5255 UniversalPrint(*it, os);
5260 bool printed_header2 =
false;
5261 for (
typename StlContainer::const_iterator it = expected_.begin();
5262 it != expected_.end(); ++it) {
5263 if (internal::ArrayAwareFind(
5264 lhs_stl_container.begin(), lhs_stl_container.end(), *it) ==
5265 lhs_stl_container.end()) {
5266 if (printed_header2) {
5269 *os << (printed_header ?
",\nand" :
"which")
5270 <<
" doesn't have these expected elements: ";
5271 printed_header2 =
true;
5273 UniversalPrint(*it, os);
5282 const StlContainer expected_;
5286 struct LessComparator {
5287 template <
typename T,
typename U>
5288 bool operator()(
const T& lhs,
const U& rhs)
const {
return lhs < rhs; }
5292 template <
typename Comparator,
typename ContainerMatcher>
5293 class WhenSortedByMatcher {
5295 WhenSortedByMatcher(
const Comparator& comparator,
5296 const ContainerMatcher& matcher)
5297 : comparator_(comparator), matcher_(matcher) {}
5299 template <
typename LhsContainer>
5300 operator Matcher<LhsContainer>()
const {
5301 return MakeMatcher(
new Impl<LhsContainer>(comparator_, matcher_));
5304 template <
typename LhsContainer>
5305 class Impl :
public MatcherInterface<LhsContainer> {
5307 typedef internal::StlContainerView<
5308 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
5309 typedef typename LhsView::type LhsStlContainer;
5310 typedef typename LhsView::const_reference LhsStlContainerReference;
5313 typedef typename RemoveConstFromKey<
5314 typename LhsStlContainer::value_type>::type LhsValue;
5316 Impl(
const Comparator& comparator,
const ContainerMatcher& matcher)
5317 : comparator_(comparator), matcher_(matcher) {}
5319 void DescribeTo(::std::ostream* os)
const override {
5320 *os <<
"(when sorted) ";
5321 matcher_.DescribeTo(os);
5324 void DescribeNegationTo(::std::ostream* os)
const override {
5325 *os <<
"(when sorted) ";
5326 matcher_.DescribeNegationTo(os);
5329 bool MatchAndExplain(LhsContainer lhs,
5330 MatchResultListener* listener)
const override {
5331 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
5332 ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
5333 lhs_stl_container.end());
5335 sorted_container.begin(), sorted_container.end(), comparator_);
5337 if (!listener->IsInterested()) {
5340 return matcher_.Matches(sorted_container);
5343 *listener <<
"which is ";
5344 UniversalPrint(sorted_container, listener->stream());
5345 *listener <<
" when sorted";
5347 StringMatchResultListener inner_listener;
5348 const bool match = matcher_.MatchAndExplain(sorted_container,
5350 PrintIfNotEmpty(inner_listener.str(), listener->stream());
5355 const Comparator comparator_;
5356 const Matcher<const ::std::vector<LhsValue>&> matcher_;
5358 GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
5362 const Comparator comparator_;
5363 const ContainerMatcher matcher_;
5370 template <
typename TupleMatcher,
typename RhsContainer>
5371 class PointwiseMatcher {
5372 GTEST_COMPILE_ASSERT_(
5373 !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>::value,
5374 use_UnorderedPointwise_with_hash_tables);
5377 typedef internal::StlContainerView<RhsContainer> RhsView;
5378 typedef typename RhsView::type RhsStlContainer;
5379 typedef typename RhsStlContainer::value_type RhsValue;
5381 static_assert(!std::is_const<RhsContainer>::value,
5382 "RhsContainer type must not be const");
5383 static_assert(!std::is_reference<RhsContainer>::value,
5384 "RhsContainer type must not be a reference");
5388 PointwiseMatcher(
const TupleMatcher& tuple_matcher,
const RhsContainer& rhs)
5389 : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {}
5391 template <
typename LhsContainer>
5392 operator Matcher<LhsContainer>()
const {
5393 GTEST_COMPILE_ASSERT_(
5394 !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)>::value,
5395 use_UnorderedPointwise_with_hash_tables);
5397 return Matcher<LhsContainer>(
5398 new Impl<const LhsContainer&>(tuple_matcher_, rhs_));
5401 template <
typename LhsContainer>
5402 class Impl :
public MatcherInterface<LhsContainer> {
5404 typedef internal::StlContainerView<
5405 GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
5406 typedef typename LhsView::type LhsStlContainer;
5407 typedef typename LhsView::const_reference LhsStlContainerReference;
5408 typedef typename LhsStlContainer::value_type LhsValue;
5413 typedef ::std::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg;
5415 Impl(
const TupleMatcher& tuple_matcher,
const RhsStlContainer& rhs)
5417 : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)),
5420 void DescribeTo(::std::ostream* os)
const override {
5421 *os <<
"contains " << rhs_.size()
5422 <<
" values, where each value and its corresponding value in ";
5423 UniversalPrinter<RhsStlContainer>::Print(rhs_, os);
5425 mono_tuple_matcher_.DescribeTo(os);
5427 void DescribeNegationTo(::std::ostream* os)
const override {
5428 *os <<
"doesn't contain exactly " << rhs_.size()
5429 <<
" values, or contains a value x at some index i" 5430 <<
" where x and the i-th value of ";
5431 UniversalPrint(rhs_, os);
5433 mono_tuple_matcher_.DescribeNegationTo(os);
5436 bool MatchAndExplain(LhsContainer lhs,
5437 MatchResultListener* listener)
const override {
5438 LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
5439 const size_t actual_size = lhs_stl_container.size();
5440 if (actual_size != rhs_.size()) {
5441 *listener <<
"which contains " << actual_size <<
" values";
5445 typename LhsStlContainer::const_iterator left = lhs_stl_container.begin();
5446 typename RhsStlContainer::const_iterator right = rhs_.begin();
5447 for (
size_t i = 0; i != actual_size; ++i, ++left, ++right) {
5448 if (listener->IsInterested()) {
5449 StringMatchResultListener inner_listener;
5453 if (!mono_tuple_matcher_.MatchAndExplain(
5454 InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
5455 ImplicitCast_<const RhsValue&>(*right)),
5457 *listener <<
"where the value pair (";
5458 UniversalPrint(*left, listener->stream());
5460 UniversalPrint(*right, listener->stream());
5461 *listener <<
") at index #" << i <<
" don't match";
5462 PrintIfNotEmpty(inner_listener.str(), listener->stream());
5466 if (!mono_tuple_matcher_.Matches(
5467 InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
5468 ImplicitCast_<const RhsValue&>(*right))))
5477 const Matcher<InnerMatcherArg> mono_tuple_matcher_;
5478 const RhsStlContainer rhs_;
5482 const TupleMatcher tuple_matcher_;
5483 const RhsStlContainer rhs_;
5487 template <
typename Container>
5488 class QuantifierMatcherImpl :
public MatcherInterface<Container> {
5490 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
5491 typedef StlContainerView<RawContainer> View;
5492 typedef typename View::type StlContainer;
5493 typedef typename View::const_reference StlContainerReference;
5494 typedef typename StlContainer::value_type Element;
5496 template <
typename InnerMatcher>
5497 explicit QuantifierMatcherImpl(InnerMatcher inner_matcher)
5499 testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
5504 bool MatchAndExplainImpl(
bool all_elements_should_match,
5505 Container container,
5506 MatchResultListener* listener)
const {
5507 StlContainerReference stl_container = View::ConstReference(container);
5509 for (
typename StlContainer::const_iterator it = stl_container.begin();
5510 it != stl_container.end(); ++it, ++i) {
5511 StringMatchResultListener inner_listener;
5512 const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener);
5514 if (matches != all_elements_should_match) {
5515 *listener <<
"whose element #" << i
5516 << (matches ?
" matches" :
" doesn't match");
5517 PrintIfNotEmpty(inner_listener.str(), listener->stream());
5518 return !all_elements_should_match;
5521 return all_elements_should_match;
5525 const Matcher<const Element&> inner_matcher_;
5530 template <
typename Container>
5531 class ContainsMatcherImpl :
public QuantifierMatcherImpl<Container> {
5533 template <
typename InnerMatcher>
5534 explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
5535 : QuantifierMatcherImpl<Container>(inner_matcher) {}
5538 void DescribeTo(::std::ostream* os)
const override {
5539 *os <<
"contains at least one element that ";
5540 this->inner_matcher_.DescribeTo(os);
5543 void DescribeNegationTo(::std::ostream* os)
const override {
5544 *os <<
"doesn't contain any element that ";
5545 this->inner_matcher_.DescribeTo(os);
5548 bool MatchAndExplain(Container container,
5549 MatchResultListener* listener)
const override {
5550 return this->MatchAndExplainImpl(
false, container, listener);
5556 template <
typename Container>
5557 class EachMatcherImpl :
public QuantifierMatcherImpl<Container> {
5559 template <
typename InnerMatcher>
5560 explicit EachMatcherImpl(InnerMatcher inner_matcher)
5561 : QuantifierMatcherImpl<Container>(inner_matcher) {}
5564 void DescribeTo(::std::ostream* os)
const override {
5565 *os <<
"only contains elements that ";
5566 this->inner_matcher_.DescribeTo(os);
5569 void DescribeNegationTo(::std::ostream* os)
const override {
5570 *os <<
"contains some element that ";
5571 this->inner_matcher_.DescribeNegationTo(os);
5574 bool MatchAndExplain(Container container,
5575 MatchResultListener* listener)
const override {
5576 return this->MatchAndExplainImpl(
true, container, listener);
5581 template <
typename M>
5582 class ContainsMatcher {
5584 explicit ContainsMatcher(M m) : inner_matcher_(m) {}
5586 template <
typename Container>
5587 operator Matcher<Container>()
const {
5588 return Matcher<Container>(
5589 new ContainsMatcherImpl<const Container&>(inner_matcher_));
5593 const M inner_matcher_;
5597 template <
typename M>
5600 explicit EachMatcher(M m) : inner_matcher_(m) {}
5602 template <
typename Container>
5603 operator Matcher<Container>()
const {
5604 return Matcher<Container>(
5605 new EachMatcherImpl<const Container&>(inner_matcher_));
5609 const M inner_matcher_;
5613 struct Rank0 : Rank1 {};
5615 namespace pair_getters {
5617 template <
typename T>
5618 auto First(T& x, Rank1) -> decltype(get<0>(x)) {
5621 template <
typename T>
5622 auto First(T& x, Rank0) -> decltype((x.first)) {
5626 template <
typename T>
5627 auto Second(T& x, Rank1) -> decltype(get<1>(x)) {
5630 template <
typename T>
5631 auto Second(T& x, Rank0) -> decltype((x.second)) {
5640 template <
typename PairType>
5641 class KeyMatcherImpl :
public MatcherInterface<PairType> {
5643 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
5644 typedef typename RawPairType::first_type KeyType;
5646 template <
typename InnerMatcher>
5647 explicit KeyMatcherImpl(InnerMatcher inner_matcher)
5649 testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {
5654 bool MatchAndExplain(PairType key_value,
5655 MatchResultListener* listener)
const override {
5656 StringMatchResultListener inner_listener;
5657 const bool match = inner_matcher_.MatchAndExplain(
5658 pair_getters::First(key_value, Rank0()), &inner_listener);
5659 const std::string explanation = inner_listener.str();
5660 if (explanation !=
"") {
5661 *listener <<
"whose first field is a value " << explanation;
5667 void DescribeTo(::std::ostream* os)
const override {
5668 *os <<
"has a key that ";
5669 inner_matcher_.DescribeTo(os);
5673 void DescribeNegationTo(::std::ostream* os)
const override {
5674 *os <<
"doesn't have a key that ";
5675 inner_matcher_.DescribeTo(os);
5679 const Matcher<const KeyType&> inner_matcher_;
5683 template <
typename M>
5686 explicit KeyMatcher(M m) : matcher_for_key_(m) {}
5688 template <
typename PairType>
5689 operator Matcher<PairType>()
const {
5690 return Matcher<PairType>(
5691 new KeyMatcherImpl<const PairType&>(matcher_for_key_));
5695 const M matcher_for_key_;
5699 template <
typename InnerMatcher>
5700 class AddressMatcher {
5702 explicit AddressMatcher(InnerMatcher m) : matcher_(m) {}
5704 template <
typename Type>
5705 operator Matcher<Type>()
const {
5706 return Matcher<Type>(
new Impl<const Type&>(matcher_));
5711 template <
typename Type>
5712 class Impl :
public MatcherInterface<Type> {
5714 using Address =
const GTEST_REMOVE_REFERENCE_AND_CONST_(Type) *;
5715 explicit Impl(
const InnerMatcher& matcher)
5716 : matcher_(MatcherCast<Address>(matcher)) {}
5718 void DescribeTo(::std::ostream* os)
const override {
5719 *os <<
"has address that ";
5720 matcher_.DescribeTo(os);
5723 void DescribeNegationTo(::std::ostream* os)
const override {
5724 *os <<
"does not have address that ";
5725 matcher_.DescribeTo(os);
5728 bool MatchAndExplain(Type
object,
5729 MatchResultListener* listener)
const override {
5730 *listener <<
"which has address ";
5731 Address address = std::addressof(
object);
5732 return MatchPrintAndExplain(address, matcher_, listener);
5736 const Matcher<Address> matcher_;
5738 const InnerMatcher matcher_;
5743 template <
typename PairType>
5744 class PairMatcherImpl :
public MatcherInterface<PairType> {
5746 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
5747 typedef typename RawPairType::first_type FirstType;
5748 typedef typename RawPairType::second_type SecondType;
5750 template <
typename FirstMatcher,
typename SecondMatcher>
5751 PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
5753 testing::SafeMatcherCast<const FirstType&>(first_matcher)),
5755 testing::SafeMatcherCast<const SecondType&>(second_matcher)) {
5759 void DescribeTo(::std::ostream* os)
const override {
5760 *os <<
"has a first field that ";
5761 first_matcher_.DescribeTo(os);
5762 *os <<
", and has a second field that ";
5763 second_matcher_.DescribeTo(os);
5767 void DescribeNegationTo(::std::ostream* os)
const override {
5768 *os <<
"has a first field that ";
5769 first_matcher_.DescribeNegationTo(os);
5770 *os <<
", or has a second field that ";
5771 second_matcher_.DescribeNegationTo(os);
5776 bool MatchAndExplain(PairType a_pair,
5777 MatchResultListener* listener)
const override {
5778 if (!listener->IsInterested()) {
5781 return first_matcher_.Matches(pair_getters::First(a_pair, Rank0())) &&
5782 second_matcher_.Matches(pair_getters::Second(a_pair, Rank0()));
5784 StringMatchResultListener first_inner_listener;
5785 if (!first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank0()),
5786 &first_inner_listener)) {
5787 *listener <<
"whose first field does not match";
5788 PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
5791 StringMatchResultListener second_inner_listener;
5792 if (!second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank0()),
5793 &second_inner_listener)) {
5794 *listener <<
"whose second field does not match";
5795 PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
5798 ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
5804 void ExplainSuccess(
const std::string& first_explanation,
5805 const std::string& second_explanation,
5806 MatchResultListener* listener)
const {
5807 *listener <<
"whose both fields match";
5808 if (first_explanation !=
"") {
5809 *listener <<
", where the first field is a value " << first_explanation;
5811 if (second_explanation !=
"") {
5813 if (first_explanation !=
"") {
5814 *listener <<
"and ";
5816 *listener <<
"where ";
5818 *listener <<
"the second field is a value " << second_explanation;
5822 const Matcher<const FirstType&> first_matcher_;
5823 const Matcher<const SecondType&> second_matcher_;
5827 template <
typename FirstMatcher,
typename SecondMatcher>
5830 PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
5831 : first_matcher_(first_matcher), second_matcher_(second_matcher) {}
5833 template <
typename PairType>
5834 operator Matcher<PairType> ()
const {
5835 return Matcher<PairType>(
5836 new PairMatcherImpl<const PairType&>(first_matcher_, second_matcher_));
5840 const FirstMatcher first_matcher_;
5841 const SecondMatcher second_matcher_;
5844 template <
typename T,
size_t... I>
5845 auto UnpackStructImpl(
const T& t, IndexSequence<I...>,
int)
5846 -> decltype(std::tie(get<I>(t)...)) {
5847 static_assert(std::tuple_size<T>::value ==
sizeof...(I),
5848 "Number of arguments doesn't match the number of fields.");
5849 return std::tie(get<I>(t)...);
5852 #if defined(__cpp_structured_bindings) && __cpp_structured_bindings >= 201606 5853 template <
typename T>
5854 auto UnpackStructImpl(
const T& t, MakeIndexSequence<1>,
char) {
5855 const auto& [a] = t;
5858 template <
typename T>
5859 auto UnpackStructImpl(
const T& t, MakeIndexSequence<2>,
char) {
5860 const auto& [a, b] = t;
5861 return std::tie(a, b);
5863 template <
typename T>
5864 auto UnpackStructImpl(
const T& t, MakeIndexSequence<3>,
char) {
5865 const auto& [a, b, c] = t;
5866 return std::tie(a, b, c);
5868 template <
typename T>
5869 auto UnpackStructImpl(
const T& t, MakeIndexSequence<4>,
char) {
5870 const auto& [a, b, c, d] = t;
5871 return std::tie(a, b, c, d);
5873 template <
typename T>
5874 auto UnpackStructImpl(
const T& t, MakeIndexSequence<5>,
char) {
5875 const auto& [a, b, c, d, e] = t;
5876 return std::tie(a, b, c, d, e);
5878 template <
typename T>
5879 auto UnpackStructImpl(
const T& t, MakeIndexSequence<6>,
char) {
5880 const auto& [a, b, c, d, e, f] = t;
5881 return std::tie(a, b, c, d, e, f);
5883 template <
typename T>
5884 auto UnpackStructImpl(
const T& t, MakeIndexSequence<7>,
char) {
5885 const auto& [a, b, c, d, e, f, g] = t;
5886 return std::tie(a, b, c, d, e, f, g);
5888 template <
typename T>
5889 auto UnpackStructImpl(
const T& t, MakeIndexSequence<8>,
char) {
5890 const auto& [a, b, c, d, e, f, g, h] = t;
5891 return std::tie(a, b, c, d, e, f, g, h);
5893 template <
typename T>
5894 auto UnpackStructImpl(
const T& t, MakeIndexSequence<9>,
char) {
5895 const auto& [a, b, c, d, e, f, g, h, i] = t;
5896 return std::tie(a, b, c, d, e, f, g, h, i);
5898 template <
typename T>
5899 auto UnpackStructImpl(
const T& t, MakeIndexSequence<10>,
char) {
5900 const auto& [a, b, c, d, e, f, g, h, i, j] = t;
5901 return std::tie(a, b, c, d, e, f, g, h, i, j);
5903 template <
typename T>
5904 auto UnpackStructImpl(
const T& t, MakeIndexSequence<11>,
char) {
5905 const auto& [a, b, c, d, e, f, g, h, i, j, k] = t;
5906 return std::tie(a, b, c, d, e, f, g, h, i, j, k);
5908 template <
typename T>
5909 auto UnpackStructImpl(
const T& t, MakeIndexSequence<12>,
char) {
5910 const auto& [a, b, c, d, e, f, g, h, i, j, k, l] = t;
5911 return std::tie(a, b, c, d, e, f, g, h, i, j, k, l);
5913 template <
typename T>
5914 auto UnpackStructImpl(
const T& t, MakeIndexSequence<13>,
char) {
5915 const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m] = t;
5916 return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m);
5918 template <
typename T>
5919 auto UnpackStructImpl(
const T& t, MakeIndexSequence<14>,
char) {
5920 const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n] = t;
5921 return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
5923 template <
typename T>
5924 auto UnpackStructImpl(
const T& t, MakeIndexSequence<15>,
char) {
5925 const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o] = t;
5926 return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
5928 template <
typename T>
5929 auto UnpackStructImpl(
const T& t, MakeIndexSequence<16>,
char) {
5930 const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = t;
5931 return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p);
5933 #endif // defined(__cpp_structured_bindings) 5935 template <
size_t I,
typename T>
5936 auto UnpackStruct(
const T& t)
5937 -> decltype((UnpackStructImpl)(t, MakeIndexSequence<I>{}, 0)) {
5938 return (UnpackStructImpl)(t, MakeIndexSequence<I>{}, 0);
5944 template <
typename T,
size_t N>
5945 void VariadicExpand(
const T (&)[N]) {}
5947 template <
typename Struct,
typename StructSize>
5948 class FieldsAreMatcherImpl;
5950 template <
typename Struct,
size_t... I>
5951 class FieldsAreMatcherImpl<Struct, IndexSequence<I...>>
5952 :
public MatcherInterface<Struct> {
5953 using UnpackedType =
5954 decltype(UnpackStruct<
sizeof...(I)>(std::declval<const Struct&>()));
5955 using MatchersType = std::tuple<
5956 Matcher<const typename std::tuple_element<I, UnpackedType>::type&>...>;
5959 template <
typename Inner>
5960 explicit FieldsAreMatcherImpl(
const Inner& matchers)
5961 : matchers_(testing::SafeMatcherCast<
5962 const typename
std::tuple_element<I, UnpackedType>::type&>(
5963 std::
get<I>(matchers))...) {}
5965 void DescribeTo(::std::ostream* os)
const override {
5966 const char* separator =
"";
5968 {(*os << separator <<
"has field #" << I <<
" that ",
5969 std::get<I>(matchers_).DescribeTo(os), separator =
", and ")...});
5972 void DescribeNegationTo(::std::ostream* os)
const override {
5973 const char* separator =
"";
5974 VariadicExpand({(*os << separator <<
"has field #" << I <<
" that ",
5975 std::get<I>(matchers_).DescribeNegationTo(os),
5976 separator =
", or ")...});
5979 bool MatchAndExplain(Struct t, MatchResultListener* listener)
const override {
5980 return MatchInternal((UnpackStruct<
sizeof...(I)>)(t), listener);
5984 bool MatchInternal(UnpackedType tuple, MatchResultListener* listener)
const {
5985 if (!listener->IsInterested()) {
5989 VariadicExpand({good = good && std::get<I>(matchers_).Matches(
5990 std::get<I>(tuple))...});
5994 size_t failed_pos = ~size_t{};
5996 std::vector<StringMatchResultListener> inner_listener(
sizeof...(I));
5999 {failed_pos == ~size_t{} && !std::get<I>(matchers_).MatchAndExplain(
6000 std::get<I>(tuple), &inner_listener[I])
6003 if (failed_pos != ~
size_t{}) {
6004 *listener <<
"whose field #" << failed_pos <<
" does not match";
6005 PrintIfNotEmpty(inner_listener[failed_pos].str(), listener->stream());
6009 *listener <<
"whose all elements match";
6010 const char* separator =
", where";
6011 for (
size_t index = 0; index <
sizeof...(I); ++index) {
6012 const std::string str = inner_listener[index].str();
6014 *listener << separator <<
" field #" << index <<
" is a value " << str;
6015 separator =
", and";
6022 MatchersType matchers_;
6025 template <
typename... Inner>
6026 class FieldsAreMatcher {
6028 explicit FieldsAreMatcher(Inner... inner) : matchers_(
std::move(inner)...) {}
6030 template <
typename Struct>
6031 operator Matcher<Struct>()
const {
6032 return Matcher<Struct>(
6033 new FieldsAreMatcherImpl<
const Struct&, IndexSequenceFor<Inner...>>(
6038 std::tuple<Inner...> matchers_;
6042 template <
typename Container>
6043 class ElementsAreMatcherImpl :
public MatcherInterface<Container> {
6045 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
6046 typedef internal::StlContainerView<RawContainer> View;
6047 typedef typename View::type StlContainer;
6048 typedef typename View::const_reference StlContainerReference;
6049 typedef typename StlContainer::value_type Element;
6053 template <
typename InputIter>
6054 ElementsAreMatcherImpl(InputIter first, InputIter last) {
6055 while (first != last) {
6056 matchers_.push_back(MatcherCast<const Element&>(*first++));
6061 void DescribeTo(::std::ostream* os)
const override {
6064 }
else if (count() == 1) {
6065 *os <<
"has 1 element that ";
6066 matchers_[0].DescribeTo(os);
6068 *os <<
"has " << Elements(count()) <<
" where\n";
6069 for (
size_t i = 0; i != count(); ++i) {
6070 *os <<
"element #" << i <<
" ";
6071 matchers_[i].DescribeTo(os);
6072 if (i + 1 < count()) {
6080 void DescribeNegationTo(::std::ostream* os)
const override {
6082 *os <<
"isn't empty";
6086 *os <<
"doesn't have " << Elements(count()) <<
", or\n";
6087 for (
size_t i = 0; i != count(); ++i) {
6088 *os <<
"element #" << i <<
" ";
6089 matchers_[i].DescribeNegationTo(os);
6090 if (i + 1 < count()) {
6096 bool MatchAndExplain(Container container,
6097 MatchResultListener* listener)
const override {
6101 const bool listener_interested = listener->IsInterested();
6104 ::std::vector<std::string> explanations(count());
6105 StlContainerReference stl_container = View::ConstReference(container);
6106 typename StlContainer::const_iterator it = stl_container.begin();
6107 size_t exam_pos = 0;
6108 bool mismatch_found =
false;
6113 for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
6115 if (listener_interested) {
6116 StringMatchResultListener s;
6117 match = matchers_[exam_pos].MatchAndExplain(*it, &s);
6118 explanations[exam_pos] = s.str();
6120 match = matchers_[exam_pos].Matches(*it);
6124 mismatch_found =
true;
6133 size_t actual_count = exam_pos;
6134 for (; it != stl_container.end(); ++it) {
6138 if (actual_count != count()) {
6143 if (listener_interested && (actual_count != 0)) {
6144 *listener <<
"which has " << Elements(actual_count);
6149 if (mismatch_found) {
6151 if (listener_interested) {
6152 *listener <<
"whose element #" << exam_pos <<
" doesn't match";
6153 PrintIfNotEmpty(explanations[exam_pos], listener->stream());
6160 if (listener_interested) {
6161 bool reason_printed =
false;
6162 for (
size_t i = 0; i != count(); ++i) {
6163 const std::string& s = explanations[i];
6165 if (reason_printed) {
6166 *listener <<
",\nand ";
6168 *listener <<
"whose element #" << i <<
" matches, " << s;
6169 reason_printed =
true;
6177 static Message Elements(
size_t count) {
6178 return Message() << count << (count == 1 ?
" element" :
" elements");
6181 size_t count()
const {
return matchers_.size(); }
6183 ::std::vector<Matcher<const Element&> > matchers_;
6190 class GTEST_API_ MatchMatrix {
6192 MatchMatrix(
size_t num_elements,
size_t num_matchers)
6193 : num_elements_(num_elements),
6194 num_matchers_(num_matchers),
6195 matched_(num_elements_* num_matchers_, 0) {
6198 size_t LhsSize()
const {
return num_elements_; }
6199 size_t RhsSize()
const {
return num_matchers_; }
6200 bool HasEdge(
size_t ilhs,
size_t irhs)
const {
6201 return matched_[SpaceIndex(ilhs, irhs)] == 1;
6203 void SetEdge(
size_t ilhs,
size_t irhs,
bool b) {
6204 matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0;
6214 std::string DebugString()
const;
6217 size_t SpaceIndex(
size_t ilhs,
size_t irhs)
const {
6218 return ilhs * num_matchers_ + irhs;
6221 size_t num_elements_;
6222 size_t num_matchers_;
6227 ::std::vector<char> matched_;
6230 typedef ::std::pair<size_t, size_t> ElementMatcherPair;
6231 typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs;
6235 GTEST_API_ ElementMatcherPairs
6236 FindMaxBipartiteMatching(
const MatchMatrix& g);
6238 struct UnorderedMatcherRequire {
6242 ExactMatch = Superset | Subset,
6249 class GTEST_API_ UnorderedElementsAreMatcherImplBase {
6251 explicit UnorderedElementsAreMatcherImplBase(
6252 UnorderedMatcherRequire::Flags matcher_flags)
6253 : match_flags_(matcher_flags) {}
6258 typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec;
6261 void DescribeToImpl(::std::ostream* os)
const;
6264 void DescribeNegationToImpl(::std::ostream* os)
const;
6266 bool VerifyMatchMatrix(const ::std::vector<std::string>& element_printouts,
6267 const MatchMatrix& matrix,
6268 MatchResultListener* listener)
const;
6270 bool FindPairing(
const MatchMatrix& matrix,
6271 MatchResultListener* listener)
const;
6273 MatcherDescriberVec& matcher_describers() {
6274 return matcher_describers_;
6277 static Message Elements(
size_t n) {
6278 return Message() << n <<
" element" << (n == 1 ?
"" :
"s");
6281 UnorderedMatcherRequire::Flags match_flags()
const {
return match_flags_; }
6284 UnorderedMatcherRequire::Flags match_flags_;
6285 MatcherDescriberVec matcher_describers_;
6290 template <
typename Container>
6291 class UnorderedElementsAreMatcherImpl
6292 :
public MatcherInterface<Container>,
6293 public UnorderedElementsAreMatcherImplBase {
6295 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
6296 typedef internal::StlContainerView<RawContainer> View;
6297 typedef typename View::type StlContainer;
6298 typedef typename View::const_reference StlContainerReference;
6299 typedef typename StlContainer::const_iterator StlContainerConstIterator;
6300 typedef typename StlContainer::value_type Element;
6302 template <
typename InputIter>
6303 UnorderedElementsAreMatcherImpl(UnorderedMatcherRequire::Flags matcher_flags,
6304 InputIter first, InputIter last)
6305 : UnorderedElementsAreMatcherImplBase(matcher_flags) {
6306 for (; first != last; ++first) {
6307 matchers_.push_back(MatcherCast<const Element&>(*first));
6309 for (
const auto& m : matchers_) {
6310 matcher_describers().push_back(m.GetDescriber());
6315 void DescribeTo(::std::ostream* os)
const override {
6316 return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os);
6320 void DescribeNegationTo(::std::ostream* os)
const override {
6321 return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os);
6324 bool MatchAndExplain(Container container,
6325 MatchResultListener* listener)
const override {
6326 StlContainerReference stl_container = View::ConstReference(container);
6327 ::std::vector<std::string> element_printouts;
6328 MatchMatrix matrix =
6329 AnalyzeElements(stl_container.begin(), stl_container.end(),
6330 &element_printouts, listener);
6332 if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
6336 if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
6337 if (matrix.LhsSize() != matrix.RhsSize()) {
6342 if (matrix.LhsSize() != 0 && listener->IsInterested()) {
6343 *listener <<
"which has " << Elements(matrix.LhsSize());
6349 return VerifyMatchMatrix(element_printouts, matrix, listener) &&
6350 FindPairing(matrix, listener);
6354 template <
typename ElementIter>
6355 MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
6356 ::std::vector<std::string>* element_printouts,
6357 MatchResultListener* listener)
const {
6358 element_printouts->clear();
6359 ::std::vector<char> did_match;
6360 size_t num_elements = 0;
6361 DummyMatchResultListener dummy;
6362 for (; elem_first != elem_last; ++num_elements, ++elem_first) {
6363 if (listener->IsInterested()) {
6364 element_printouts->push_back(PrintToString(*elem_first));
6366 for (
size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
6367 did_match.push_back(
6368 matchers_[irhs].MatchAndExplain(*elem_first, &dummy));
6372 MatchMatrix matrix(num_elements, matchers_.size());
6373 ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
6374 for (
size_t ilhs = 0; ilhs != num_elements; ++ilhs) {
6375 for (
size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
6376 matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
6382 ::std::vector<Matcher<const Element&> > matchers_;
6387 template <
typename Target>
6388 struct CastAndAppendTransform {
6389 template <
typename Arg>
6390 Matcher<Target> operator()(
const Arg& a)
const {
6391 return MatcherCast<Target>(a);
6396 template <
typename MatcherTuple>
6397 class UnorderedElementsAreMatcher {
6399 explicit UnorderedElementsAreMatcher(
const MatcherTuple& args)
6400 : matchers_(args) {}
6402 template <
typename Container>
6403 operator Matcher<Container>()
const {
6404 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
6405 typedef typename internal::StlContainerView<RawContainer>::type View;
6406 typedef typename View::value_type Element;
6407 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
6408 MatcherVec matchers;
6409 matchers.reserve(::std::tuple_size<MatcherTuple>::value);
6410 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
6411 ::std::back_inserter(matchers));
6412 return Matcher<Container>(
6413 new UnorderedElementsAreMatcherImpl<const Container&>(
6414 UnorderedMatcherRequire::ExactMatch, matchers.begin(),
6419 const MatcherTuple matchers_;
6423 template <
typename MatcherTuple>
6424 class ElementsAreMatcher {
6426 explicit ElementsAreMatcher(
const MatcherTuple& args) : matchers_(args) {}
6428 template <
typename Container>
6429 operator Matcher<Container>()
const {
6430 GTEST_COMPILE_ASSERT_(
6431 !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value ||
6432 ::std::tuple_size<MatcherTuple>::value < 2,
6433 use_UnorderedElementsAre_with_hash_tables);
6435 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
6436 typedef typename internal::StlContainerView<RawContainer>::type View;
6437 typedef typename View::value_type Element;
6438 typedef ::std::vector<Matcher<const Element&> > MatcherVec;
6439 MatcherVec matchers;
6440 matchers.reserve(::std::tuple_size<MatcherTuple>::value);
6441 TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
6442 ::std::back_inserter(matchers));
6443 return Matcher<Container>(
new ElementsAreMatcherImpl<const Container&>(
6444 matchers.begin(), matchers.end()));
6448 const MatcherTuple matchers_;
6452 template <
typename T>
6453 class UnorderedElementsAreArrayMatcher {
6455 template <
typename Iter>
6456 UnorderedElementsAreArrayMatcher(UnorderedMatcherRequire::Flags match_flags,
6457 Iter first, Iter last)
6458 : match_flags_(match_flags), matchers_(first, last) {}
6460 template <
typename Container>
6461 operator Matcher<Container>()
const {
6462 return Matcher<Container>(
6463 new UnorderedElementsAreMatcherImpl<const Container&>(
6464 match_flags_, matchers_.begin(), matchers_.end()));
6468 UnorderedMatcherRequire::Flags match_flags_;
6469 ::std::vector<T> matchers_;
6473 template <
typename T>
6474 class ElementsAreArrayMatcher {
6476 template <
typename Iter>
6477 ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
6479 template <
typename Container>
6480 operator Matcher<Container>()
const {
6481 GTEST_COMPILE_ASSERT_(
6482 !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value,
6483 use_UnorderedElementsAreArray_with_hash_tables);
6485 return Matcher<Container>(
new ElementsAreMatcherImpl<const Container&>(
6486 matchers_.begin(), matchers_.end()));
6490 const ::std::vector<T> matchers_;
6502 template <
typename Tuple2Matcher,
typename Second>
6503 class BoundSecondMatcher {
6505 BoundSecondMatcher(
const Tuple2Matcher& tm,
const Second& second)
6506 : tuple2_matcher_(tm), second_value_(second) {}
6508 BoundSecondMatcher(
const BoundSecondMatcher& other) =
default;
6510 template <
typename T>
6511 operator Matcher<T>()
const {
6512 return MakeMatcher(
new Impl<T>(tuple2_matcher_, second_value_));
6523 void operator=(
const BoundSecondMatcher& ) {
6524 GTEST_LOG_(FATAL) <<
"BoundSecondMatcher should never be assigned.";
6528 template <
typename T>
6529 class Impl :
public MatcherInterface<T> {
6531 typedef ::std::tuple<T, Second> ArgTuple;
6533 Impl(
const Tuple2Matcher& tm,
const Second& second)
6534 : mono_tuple2_matcher_(SafeMatcherCast<const ArgTuple&>(tm)),
6535 second_value_(second) {}
6537 void DescribeTo(::std::ostream* os)
const override {
6539 UniversalPrint(second_value_, os);
6541 mono_tuple2_matcher_.DescribeTo(os);
6544 bool MatchAndExplain(T x, MatchResultListener* listener)
const override {
6545 return mono_tuple2_matcher_.MatchAndExplain(ArgTuple(x, second_value_),
6550 const Matcher<const ArgTuple&> mono_tuple2_matcher_;
6551 const Second second_value_;
6554 const Tuple2Matcher tuple2_matcher_;
6555 const Second second_value_;
6562 template <
typename Tuple2Matcher,
typename Second>
6563 BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond(
6564 const Tuple2Matcher& tm,
const Second& second) {
6565 return BoundSecondMatcher<Tuple2Matcher, Second>(tm, second);
6573 GTEST_API_ std::string FormatMatcherDescription(
bool negation,
6574 const char* matcher_name,
6575 const Strings& param_values);
6578 template <
typename ValueMatcher>
6579 class OptionalMatcher {
6581 explicit OptionalMatcher(
const ValueMatcher& value_matcher)
6582 : value_matcher_(value_matcher) {}
6584 template <
typename Optional>
6585 operator Matcher<Optional>()
const {
6586 return Matcher<Optional>(
new Impl<const Optional&>(value_matcher_));
6589 template <
typename Optional>
6590 class Impl :
public MatcherInterface<Optional> {
6592 typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Optional) OptionalView;
6593 typedef typename OptionalView::value_type ValueType;
6594 explicit Impl(
const ValueMatcher& value_matcher)
6595 : value_matcher_(MatcherCast<ValueType>(value_matcher)) {}
6597 void DescribeTo(::std::ostream* os)
const override {
6599 value_matcher_.DescribeTo(os);
6602 void DescribeNegationTo(::std::ostream* os)
const override {
6604 value_matcher_.DescribeNegationTo(os);
6607 bool MatchAndExplain(Optional optional,
6608 MatchResultListener* listener)
const override {
6610 *listener <<
"which is not engaged";
6613 const ValueType& value = *optional;
6614 StringMatchResultListener value_listener;
6615 const bool match = value_matcher_.MatchAndExplain(value, &value_listener);
6616 *listener <<
"whose value " << PrintToString(value)
6617 << (match ?
" matches" :
" doesn't match");
6618 PrintIfNotEmpty(value_listener.str(), listener->stream());
6623 const Matcher<ValueType> value_matcher_;
6627 const ValueMatcher value_matcher_;
6630 namespace variant_matcher {
6632 template <
typename T>
6633 void holds_alternative() {}
6634 template <
typename T>
6638 template <
typename T>
6639 class VariantMatcher {
6641 explicit VariantMatcher(::testing::Matcher<const T&> matcher)
6642 : matcher_(
std::move(matcher)) {}
6644 template <
typename Variant>
6645 bool MatchAndExplain(
const Variant& value,
6646 ::testing::MatchResultListener* listener)
const {
6648 if (!listener->IsInterested()) {
6649 return holds_alternative<T>(value) && matcher_.Matches(get<T>(value));
6652 if (!holds_alternative<T>(value)) {
6653 *listener <<
"whose value is not of type '" << GetTypeName() <<
"'";
6657 const T& elem = get<T>(value);
6658 StringMatchResultListener elem_listener;
6659 const bool match = matcher_.MatchAndExplain(elem, &elem_listener);
6660 *listener <<
"whose value " << PrintToString(elem)
6661 << (match ?
" matches" :
" doesn't match");
6662 PrintIfNotEmpty(elem_listener.str(), listener->stream());
6666 void DescribeTo(std::ostream* os)
const {
6667 *os <<
"is a variant<> with value of type '" << GetTypeName()
6668 <<
"' and the value ";
6669 matcher_.DescribeTo(os);
6672 void DescribeNegationTo(std::ostream* os)
const {
6673 *os <<
"is a variant<> with value of type other than '" << GetTypeName()
6674 <<
"' or the value ";
6675 matcher_.DescribeNegationTo(os);
6679 static std::string GetTypeName() {
6681 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
6682 return internal::GetTypeName<T>());
6684 return "the element type";
6687 const ::testing::Matcher<const T&> matcher_;
6692 namespace any_cast_matcher {
6695 template <
typename T>
6699 template <
typename T>
6700 class AnyCastMatcher {
6702 explicit AnyCastMatcher(const ::testing::Matcher<const T&>& matcher)
6703 : matcher_(matcher) {}
6705 template <
typename AnyType>
6706 bool MatchAndExplain(
const AnyType& value,
6707 ::testing::MatchResultListener* listener)
const {
6708 if (!listener->IsInterested()) {
6709 const T* ptr = any_cast<T>(&value);
6710 return ptr !=
nullptr && matcher_.Matches(*ptr);
6713 const T* elem = any_cast<T>(&value);
6714 if (elem ==
nullptr) {
6715 *listener <<
"whose value is not of type '" << GetTypeName() <<
"'";
6719 StringMatchResultListener elem_listener;
6720 const bool match = matcher_.MatchAndExplain(*elem, &elem_listener);
6721 *listener <<
"whose value " << PrintToString(*elem)
6722 << (match ?
" matches" :
" doesn't match");
6723 PrintIfNotEmpty(elem_listener.str(), listener->stream());
6727 void DescribeTo(std::ostream* os)
const {
6728 *os <<
"is an 'any' type with value of type '" << GetTypeName()
6729 <<
"' and the value ";
6730 matcher_.DescribeTo(os);
6733 void DescribeNegationTo(std::ostream* os)
const {
6734 *os <<
"is an 'any' type with value of type other than '" << GetTypeName()
6735 <<
"' or the value ";
6736 matcher_.DescribeNegationTo(os);
6740 static std::string GetTypeName() {
6742 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
6743 return internal::GetTypeName<T>());
6745 return "the element type";
6748 const ::testing::Matcher<const T&> matcher_;
6754 template <
class ArgsTuple,
size_t... k>
6755 class ArgsMatcherImpl :
public MatcherInterface<ArgsTuple> {
6757 using RawArgsTuple =
typename std::decay<ArgsTuple>::type;
6758 using SelectedArgs =
6759 std::tuple<typename std::tuple_element<k, RawArgsTuple>::type...>;
6760 using MonomorphicInnerMatcher = Matcher<const SelectedArgs&>;
6762 template <
typename InnerMatcher>
6763 explicit ArgsMatcherImpl(
const InnerMatcher& inner_matcher)
6764 : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
6766 bool MatchAndExplain(ArgsTuple args,
6767 MatchResultListener* listener)
const override {
6770 const SelectedArgs& selected_args =
6771 std::forward_as_tuple(std::get<k>(args)...);
6772 if (!listener->IsInterested())
return inner_matcher_.Matches(selected_args);
6774 PrintIndices(listener->stream());
6775 *listener <<
"are " << PrintToString(selected_args);
6777 StringMatchResultListener inner_listener;
6779 inner_matcher_.MatchAndExplain(selected_args, &inner_listener);
6780 PrintIfNotEmpty(inner_listener.str(), listener->stream());
6784 void DescribeTo(::std::ostream* os)
const override {
6785 *os <<
"are a tuple ";
6787 inner_matcher_.DescribeTo(os);
6790 void DescribeNegationTo(::std::ostream* os)
const override {
6791 *os <<
"are a tuple ";
6793 inner_matcher_.DescribeNegationTo(os);
6798 static void PrintIndices(::std::ostream* os) {
6799 *os <<
"whose fields (";
6800 const char* sep =
"";
6803 const char* dummy[] = {
"", (*os << sep <<
"#" << k, sep =
", ")...};
6808 MonomorphicInnerMatcher inner_matcher_;
6811 template <
class InnerMatcher,
size_t... k>
6814 explicit ArgsMatcher(InnerMatcher inner_matcher)
6815 : inner_matcher_(
std::move(inner_matcher)) {}
6817 template <
typename ArgsTuple>
6818 operator Matcher<ArgsTuple>()
const {
6819 return MakeMatcher(
new ArgsMatcherImpl<ArgsTuple, k...>(inner_matcher_));
6823 InnerMatcher inner_matcher_;
6843 template <
typename Iter>
6844 inline internal::ElementsAreArrayMatcher<
6845 typename ::std::iterator_traits<Iter>::value_type>
6846 ElementsAreArray(Iter first, Iter last) {
6847 typedef typename ::std::iterator_traits<Iter>::value_type T;
6848 return internal::ElementsAreArrayMatcher<T>(first, last);
6851 template <
typename T>
6852 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
6853 const T* pointer,
size_t count) {
6854 return ElementsAreArray(pointer, pointer + count);
6857 template <
typename T,
size_t N>
6858 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
6859 const T (&array)[N]) {
6860 return ElementsAreArray(array, N);
6863 template <
typename Container>
6864 inline internal::ElementsAreArrayMatcher<typename Container::value_type>
6865 ElementsAreArray(
const Container& container) {
6866 return ElementsAreArray(container.begin(), container.end());
6869 template <
typename T>
6870 inline internal::ElementsAreArrayMatcher<T>
6871 ElementsAreArray(::std::initializer_list<T> xs) {
6872 return ElementsAreArray(xs.begin(), xs.end());
6888 template <
typename Iter>
6889 inline internal::UnorderedElementsAreArrayMatcher<
6890 typename ::std::iterator_traits<Iter>::value_type>
6891 UnorderedElementsAreArray(Iter first, Iter last) {
6892 typedef typename ::std::iterator_traits<Iter>::value_type T;
6893 return internal::UnorderedElementsAreArrayMatcher<T>(
6894 internal::UnorderedMatcherRequire::ExactMatch, first, last);
6897 template <
typename T>
6898 inline internal::UnorderedElementsAreArrayMatcher<T>
6899 UnorderedElementsAreArray(
const T* pointer,
size_t count) {
6900 return UnorderedElementsAreArray(pointer, pointer + count);
6903 template <
typename T,
size_t N>
6904 inline internal::UnorderedElementsAreArrayMatcher<T>
6905 UnorderedElementsAreArray(
const T (&array)[N]) {
6906 return UnorderedElementsAreArray(array, N);
6909 template <
typename Container>
6910 inline internal::UnorderedElementsAreArrayMatcher<
6911 typename Container::value_type>
6912 UnorderedElementsAreArray(
const Container& container) {
6913 return UnorderedElementsAreArray(container.begin(), container.end());
6916 template <
typename T>
6917 inline internal::UnorderedElementsAreArrayMatcher<T>
6918 UnorderedElementsAreArray(::std::initializer_list<T> xs) {
6919 return UnorderedElementsAreArray(xs.begin(), xs.end());
6931 const internal::AnythingMatcher _ = {};
6933 template <
typename T>
6934 inline Matcher<T> A() {
6939 template <
typename T>
6940 inline Matcher<T> An() {
6944 template <
typename T,
typename M>
6945 Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl(
6946 const M& value, std::false_type ,
6952 inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() {
6953 return MakePolymorphicMatcher(internal::IsNullMatcher());
6959 inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() {
6960 return MakePolymorphicMatcher(internal::NotNullMatcher());
6965 template <
typename T>
6966 inline internal::RefMatcher<T&> Ref(T& x) {
6967 return internal::RefMatcher<T&>(x);
6971 inline PolymorphicMatcher<internal::IsNanMatcher> IsNan() {
6972 return MakePolymorphicMatcher(internal::IsNanMatcher());
6977 inline internal::FloatingEqMatcher<double> DoubleEq(
double rhs) {
6978 return internal::FloatingEqMatcher<double>(rhs,
false);
6983 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(
double rhs) {
6984 return internal::FloatingEqMatcher<double>(rhs,
true);
6990 inline internal::FloatingEqMatcher<double> DoubleNear(
6991 double rhs,
double max_abs_error) {
6992 return internal::FloatingEqMatcher<double>(rhs,
false, max_abs_error);
6998 inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear(
6999 double rhs,
double max_abs_error) {
7000 return internal::FloatingEqMatcher<double>(rhs,
true, max_abs_error);
7005 inline internal::FloatingEqMatcher<float> FloatEq(
float rhs) {
7006 return internal::FloatingEqMatcher<float>(rhs,
false);
7011 inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(
float rhs) {
7012 return internal::FloatingEqMatcher<float>(rhs,
true);
7018 inline internal::FloatingEqMatcher<float> FloatNear(
7019 float rhs,
float max_abs_error) {
7020 return internal::FloatingEqMatcher<float>(rhs,
false, max_abs_error);
7026 inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear(
7027 float rhs,
float max_abs_error) {
7028 return internal::FloatingEqMatcher<float>(rhs,
true, max_abs_error);
7033 template <
typename InnerMatcher>
7034 inline internal::PointeeMatcher<InnerMatcher> Pointee(
7035 const InnerMatcher& inner_matcher) {
7036 return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
7046 template <
typename To>
7047 inline PolymorphicMatcher<internal::WhenDynamicCastToMatcher<To> >
7048 WhenDynamicCastTo(
const Matcher<To>& inner_matcher) {
7049 return MakePolymorphicMatcher(
7050 internal::WhenDynamicCastToMatcher<To>(inner_matcher));
7052 #endif // GTEST_HAS_RTTI 7058 template <
typename Class,
typename FieldType,
typename FieldMatcher>
7059 inline PolymorphicMatcher<
7060 internal::FieldMatcher<Class, FieldType> > Field(
7061 FieldType Class::*field,
const FieldMatcher& matcher) {
7062 return MakePolymorphicMatcher(
7063 internal::FieldMatcher<Class, FieldType>(
7064 field, MatcherCast<const FieldType&>(matcher)));
7073 template <
typename Class,
typename FieldType,
typename FieldMatcher>
7074 inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType> > Field(
7075 const std::string& field_name, FieldType Class::*field,
7076 const FieldMatcher& matcher) {
7077 return MakePolymorphicMatcher(internal::FieldMatcher<Class, FieldType>(
7078 field_name, field, MatcherCast<const FieldType&>(matcher)));
7085 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
7086 inline PolymorphicMatcher<internal::PropertyMatcher<
7087 Class, PropertyType, PropertyType (Class::*)()
const> >
7088 Property(PropertyType (Class::*property)()
const,
7089 const PropertyMatcher& matcher) {
7090 return MakePolymorphicMatcher(
7091 internal::PropertyMatcher<Class, PropertyType,
7092 PropertyType (Class::*)()
const>(
7093 property, MatcherCast<const PropertyType&>(matcher)));
7102 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
7103 inline PolymorphicMatcher<internal::PropertyMatcher<
7104 Class, PropertyType, PropertyType (Class::*)()
const> >
7105 Property(
const std::string& property_name,
7106 PropertyType (Class::*property)()
const,
7107 const PropertyMatcher& matcher) {
7108 return MakePolymorphicMatcher(
7109 internal::PropertyMatcher<Class, PropertyType,
7110 PropertyType (Class::*)()
const>(
7111 property_name, property, MatcherCast<const PropertyType&>(matcher)));
7115 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
7116 inline PolymorphicMatcher<internal::PropertyMatcher<
7117 Class, PropertyType, PropertyType (Class::*)()
const &> >
7118 Property(PropertyType (Class::*property)()
const &,
7119 const PropertyMatcher& matcher) {
7120 return MakePolymorphicMatcher(
7121 internal::PropertyMatcher<Class, PropertyType,
7122 PropertyType (Class::*)()
const&>(
7123 property, MatcherCast<const PropertyType&>(matcher)));
7127 template <
typename Class,
typename PropertyType,
typename PropertyMatcher>
7128 inline PolymorphicMatcher<internal::PropertyMatcher<
7129 Class, PropertyType, PropertyType (Class::*)()
const &> >
7130 Property(
const std::string& property_name,
7131 PropertyType (Class::*property)()
const &,
7132 const PropertyMatcher& matcher) {
7133 return MakePolymorphicMatcher(
7134 internal::PropertyMatcher<Class, PropertyType,
7135 PropertyType (Class::*)()
const&>(
7136 property_name, property, MatcherCast<const PropertyType&>(matcher)));
7147 template <
typename Callable,
typename InnerMatcher>
7148 internal::ResultOfMatcher<Callable, InnerMatcher> ResultOf(
7149 Callable callable, InnerMatcher matcher) {
7150 return internal::ResultOfMatcher<Callable, InnerMatcher>(
7151 std::move(callable), std::move(matcher));
7157 template <
typename T = std::
string>
7158 PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrEq(
7159 const internal::StringLike<T>& str) {
7160 return MakePolymorphicMatcher(
7161 internal::StrEqualityMatcher<std::string>(std::string(str),
true,
true));
7165 template <
typename T = std::
string>
7166 PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrNe(
7167 const internal::StringLike<T>& str) {
7168 return MakePolymorphicMatcher(
7169 internal::StrEqualityMatcher<std::string>(std::string(str),
false,
true));
7173 template <
typename T = std::
string>
7174 PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseEq(
7175 const internal::StringLike<T>& str) {
7176 return MakePolymorphicMatcher(
7177 internal::StrEqualityMatcher<std::string>(std::string(str),
true,
false));
7181 template <
typename T = std::
string>
7182 PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseNe(
7183 const internal::StringLike<T>& str) {
7184 return MakePolymorphicMatcher(internal::StrEqualityMatcher<std::string>(
7185 std::string(str),
false,
false));
7190 template <
typename T = std::
string>
7191 PolymorphicMatcher<internal::HasSubstrMatcher<std::string> > HasSubstr(
7192 const internal::StringLike<T>& substring) {
7193 return MakePolymorphicMatcher(
7194 internal::HasSubstrMatcher<std::string>(std::string(substring)));
7198 template <
typename T = std::
string>
7199 PolymorphicMatcher<internal::StartsWithMatcher<std::string> > StartsWith(
7200 const internal::StringLike<T>& prefix) {
7201 return MakePolymorphicMatcher(
7202 internal::StartsWithMatcher<std::string>(std::string(prefix)));
7206 template <
typename T = std::
string>
7207 PolymorphicMatcher<internal::EndsWithMatcher<std::string> > EndsWith(
7208 const internal::StringLike<T>& suffix) {
7209 return MakePolymorphicMatcher(
7210 internal::EndsWithMatcher<std::string>(std::string(suffix)));
7213 #if GTEST_HAS_STD_WSTRING 7217 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrEq(
7218 const std::wstring& str) {
7219 return MakePolymorphicMatcher(
7220 internal::StrEqualityMatcher<std::wstring>(str,
true,
true));
7224 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrNe(
7225 const std::wstring& str) {
7226 return MakePolymorphicMatcher(
7227 internal::StrEqualityMatcher<std::wstring>(str,
false,
true));
7231 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> >
7232 StrCaseEq(
const std::wstring& str) {
7233 return MakePolymorphicMatcher(
7234 internal::StrEqualityMatcher<std::wstring>(str,
true,
false));
7238 inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> >
7239 StrCaseNe(
const std::wstring& str) {
7240 return MakePolymorphicMatcher(
7241 internal::StrEqualityMatcher<std::wstring>(str,
false,
false));
7246 inline PolymorphicMatcher<internal::HasSubstrMatcher<std::wstring> > HasSubstr(
7247 const std::wstring& substring) {
7248 return MakePolymorphicMatcher(
7249 internal::HasSubstrMatcher<std::wstring>(substring));
7253 inline PolymorphicMatcher<internal::StartsWithMatcher<std::wstring> >
7254 StartsWith(
const std::wstring& prefix) {
7255 return MakePolymorphicMatcher(
7256 internal::StartsWithMatcher<std::wstring>(prefix));
7260 inline PolymorphicMatcher<internal::EndsWithMatcher<std::wstring> > EndsWith(
7261 const std::wstring& suffix) {
7262 return MakePolymorphicMatcher(
7263 internal::EndsWithMatcher<std::wstring>(suffix));
7266 #endif // GTEST_HAS_STD_WSTRING 7270 inline internal::Eq2Matcher Eq() {
return internal::Eq2Matcher(); }
7274 inline internal::Ge2Matcher Ge() {
return internal::Ge2Matcher(); }
7278 inline internal::Gt2Matcher Gt() {
return internal::Gt2Matcher(); }
7282 inline internal::Le2Matcher Le() {
return internal::Le2Matcher(); }
7286 inline internal::Lt2Matcher Lt() {
return internal::Lt2Matcher(); }
7290 inline internal::Ne2Matcher Ne() {
return internal::Ne2Matcher(); }
7294 inline internal::FloatingEq2Matcher<float> FloatEq() {
7295 return internal::FloatingEq2Matcher<float>();
7300 inline internal::FloatingEq2Matcher<double> DoubleEq() {
7301 return internal::FloatingEq2Matcher<double>();
7306 inline internal::FloatingEq2Matcher<float> NanSensitiveFloatEq() {
7307 return internal::FloatingEq2Matcher<float>(
true);
7312 inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleEq() {
7313 return internal::FloatingEq2Matcher<double>(
true);
7318 inline internal::FloatingEq2Matcher<float> FloatNear(
float max_abs_error) {
7319 return internal::FloatingEq2Matcher<float>(max_abs_error);
7324 inline internal::FloatingEq2Matcher<double> DoubleNear(
double max_abs_error) {
7325 return internal::FloatingEq2Matcher<double>(max_abs_error);
7331 inline internal::FloatingEq2Matcher<float> NanSensitiveFloatNear(
7332 float max_abs_error) {
7333 return internal::FloatingEq2Matcher<float>(max_abs_error,
true);
7339 inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleNear(
7340 double max_abs_error) {
7341 return internal::FloatingEq2Matcher<double>(max_abs_error,
true);
7346 template <
typename InnerMatcher>
7347 inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) {
7348 return internal::NotMatcher<InnerMatcher>(m);
7354 template <
typename Predicate>
7355 inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> >
7356 Truly(Predicate pred) {
7357 return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred));
7366 template <
typename SizeMatcher>
7367 inline internal::SizeIsMatcher<SizeMatcher>
7368 SizeIs(
const SizeMatcher& size_matcher) {
7369 return internal::SizeIsMatcher<SizeMatcher>(size_matcher);
7377 template <
typename DistanceMatcher>
7378 inline internal::BeginEndDistanceIsMatcher<DistanceMatcher>
7379 BeginEndDistanceIs(
const DistanceMatcher& distance_matcher) {
7380 return internal::BeginEndDistanceIsMatcher<DistanceMatcher>(distance_matcher);
7387 template <
typename Container>
7388 inline PolymorphicMatcher<internal::ContainerEqMatcher<
7389 typename std::remove_const<Container>::type>>
7390 ContainerEq(
const Container& rhs) {
7391 return MakePolymorphicMatcher(internal::ContainerEqMatcher<Container>(rhs));
7396 template <
typename Comparator,
typename ContainerMatcher>
7397 inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher>
7398 WhenSortedBy(
const Comparator& comparator,
7399 const ContainerMatcher& container_matcher) {
7400 return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>(
7401 comparator, container_matcher);
7406 template <
typename ContainerMatcher>
7407 inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
7408 WhenSorted(
const ContainerMatcher& container_matcher) {
7410 internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>(
7411 internal::LessComparator(), container_matcher);
7420 template <
typename TupleMatcher,
typename Container>
7421 inline internal::PointwiseMatcher<TupleMatcher,
7422 typename std::remove_const<Container>::type>
7423 Pointwise(
const TupleMatcher& tuple_matcher,
const Container& rhs) {
7424 return internal::PointwiseMatcher<TupleMatcher, Container>(tuple_matcher,
7430 template <
typename TupleMatcher,
typename T>
7431 inline internal::PointwiseMatcher<TupleMatcher, std::vector<T> > Pointwise(
7432 const TupleMatcher& tuple_matcher, std::initializer_list<T> rhs) {
7433 return Pointwise(tuple_matcher, std::vector<T>(rhs));
7448 template <
typename Tuple2Matcher,
typename RhsContainer>
7449 inline internal::UnorderedElementsAreArrayMatcher<
7450 typename internal::BoundSecondMatcher<
7452 typename internal::StlContainerView<
7453 typename std::remove_const<RhsContainer>::type>::type::value_type>>
7454 UnorderedPointwise(
const Tuple2Matcher& tuple2_matcher,
7455 const RhsContainer& rhs_container) {
7458 typedef typename internal::StlContainerView<RhsContainer> RhsView;
7459 typedef typename RhsView::type RhsStlContainer;
7460 typedef typename RhsStlContainer::value_type Second;
7461 const RhsStlContainer& rhs_stl_container =
7462 RhsView::ConstReference(rhs_container);
7465 ::std::vector<internal::BoundSecondMatcher<Tuple2Matcher, Second> > matchers;
7466 for (
typename RhsStlContainer::const_iterator it = rhs_stl_container.begin();
7467 it != rhs_stl_container.end(); ++it) {
7469 internal::MatcherBindSecond(tuple2_matcher, *it));
7473 return UnorderedElementsAreArray(matchers);
7478 template <
typename Tuple2Matcher,
typename T>
7479 inline internal::UnorderedElementsAreArrayMatcher<
7480 typename internal::BoundSecondMatcher<Tuple2Matcher, T> >
7481 UnorderedPointwise(
const Tuple2Matcher& tuple2_matcher,
7482 std::initializer_list<T> rhs) {
7483 return UnorderedPointwise(tuple2_matcher, std::vector<T>(rhs));
7505 template <
typename M>
7506 inline internal::ContainsMatcher<M> Contains(M matcher) {
7507 return internal::ContainsMatcher<M>(matcher);
7537 template <
typename Iter>
7538 inline internal::UnorderedElementsAreArrayMatcher<
7539 typename ::std::iterator_traits<Iter>::value_type>
7540 IsSupersetOf(Iter first, Iter last) {
7541 typedef typename ::std::iterator_traits<Iter>::value_type T;
7542 return internal::UnorderedElementsAreArrayMatcher<T>(
7543 internal::UnorderedMatcherRequire::Superset, first, last);
7546 template <
typename T>
7547 inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
7548 const T* pointer,
size_t count) {
7549 return IsSupersetOf(pointer, pointer + count);
7552 template <
typename T,
size_t N>
7553 inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
7554 const T (&array)[N]) {
7555 return IsSupersetOf(array, N);
7558 template <
typename Container>
7559 inline internal::UnorderedElementsAreArrayMatcher<
7560 typename Container::value_type>
7561 IsSupersetOf(
const Container& container) {
7562 return IsSupersetOf(container.begin(), container.end());
7565 template <
typename T>
7566 inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
7567 ::std::initializer_list<T> xs) {
7568 return IsSupersetOf(xs.begin(), xs.end());
7594 template <
typename Iter>
7595 inline internal::UnorderedElementsAreArrayMatcher<
7596 typename ::std::iterator_traits<Iter>::value_type>
7597 IsSubsetOf(Iter first, Iter last) {
7598 typedef typename ::std::iterator_traits<Iter>::value_type T;
7599 return internal::UnorderedElementsAreArrayMatcher<T>(
7600 internal::UnorderedMatcherRequire::Subset, first, last);
7603 template <
typename T>
7604 inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
7605 const T* pointer,
size_t count) {
7606 return IsSubsetOf(pointer, pointer + count);
7609 template <
typename T,
size_t N>
7610 inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
7611 const T (&array)[N]) {
7612 return IsSubsetOf(array, N);
7615 template <
typename Container>
7616 inline internal::UnorderedElementsAreArrayMatcher<
7617 typename Container::value_type>
7618 IsSubsetOf(
const Container& container) {
7619 return IsSubsetOf(container.begin(), container.end());
7622 template <
typename T>
7623 inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
7624 ::std::initializer_list<T> xs) {
7625 return IsSubsetOf(xs.begin(), xs.end());
7655 template <
typename M>
7656 inline internal::EachMatcher<M> Each(M matcher) {
7657 return internal::EachMatcher<M>(matcher);
7663 template <
typename M>
7664 inline internal::KeyMatcher<M> Key(M inner_matcher) {
7665 return internal::KeyMatcher<M>(inner_matcher);
7673 template <
typename FirstMatcher,
typename SecondMatcher>
7674 inline internal::PairMatcher<FirstMatcher, SecondMatcher>
7675 Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) {
7676 return internal::PairMatcher<FirstMatcher, SecondMatcher>(
7677 first_matcher, second_matcher);
7685 template <
typename... M>
7686 internal::FieldsAreMatcher<typename std::decay<M>::type...> FieldsAre(
7688 return internal::FieldsAreMatcher<typename std::decay<M>::type...>(
7689 std::forward<M>(matchers)...);
7694 template <
typename InnerMatcher>
7695 inline internal::PointerMatcher<InnerMatcher> Pointer(
7696 const InnerMatcher& inner_matcher) {
7697 return internal::PointerMatcher<InnerMatcher>(inner_matcher);
7702 template <
typename InnerMatcher>
7703 inline internal::AddressMatcher<InnerMatcher> Address(
7704 const InnerMatcher& inner_matcher) {
7705 return internal::AddressMatcher<InnerMatcher>(inner_matcher);
7711 template <
typename M>
7712 inline internal::MatcherAsPredicate<M> Matches(M matcher) {
7713 return internal::MatcherAsPredicate<M>(matcher);
7717 template <
typename T,
typename M>
7718 inline bool Value(
const T& value, M matcher) {
7719 return testing::Matches(matcher)(value);
7724 template <
typename T,
typename M>
7725 inline bool ExplainMatchResult(
7726 M matcher,
const T& value, MatchResultListener* listener) {
7727 return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
7740 template <
typename T,
typename M>
7741 std::string DescribeMatcher(
const M& matcher,
bool negation =
false) {
7742 ::std::stringstream ss;
7743 Matcher<T> monomorphic_matcher = SafeMatcherCast<T>(matcher);
7745 monomorphic_matcher.DescribeNegationTo(&ss);
7747 monomorphic_matcher.DescribeTo(&ss);
7752 template <
typename... Args>
7753 internal::ElementsAreMatcher<
7754 std::tuple<typename std::decay<const Args&>::type...>>
7755 ElementsAre(
const Args&... matchers) {
7756 return internal::ElementsAreMatcher<
7757 std::tuple<typename std::decay<const Args&>::type...>>(
7758 std::make_tuple(matchers...));
7761 template <
typename... Args>
7762 internal::UnorderedElementsAreMatcher<
7763 std::tuple<typename std::decay<const Args&>::type...>>
7764 UnorderedElementsAre(
const Args&... matchers) {
7765 return internal::UnorderedElementsAreMatcher<
7766 std::tuple<typename std::decay<const Args&>::type...>>(
7767 std::make_tuple(matchers...));
7771 template <
typename... Args>
7772 internal::AllOfMatcher<typename std::decay<const Args&>::type...> AllOf(
7773 const Args&... matchers) {
7774 return internal::AllOfMatcher<typename std::decay<const Args&>::type...>(
7778 template <
typename... Args>
7779 internal::AnyOfMatcher<typename std::decay<const Args&>::type...> AnyOf(
7780 const Args&... matchers) {
7781 return internal::AnyOfMatcher<typename std::decay<const Args&>::type...>(
7807 template <
typename Iter>
7808 inline internal::AnyOfArrayMatcher<
7809 typename ::std::iterator_traits<Iter>::value_type>
7810 AnyOfArray(Iter first, Iter last) {
7811 return internal::AnyOfArrayMatcher<
7812 typename ::std::iterator_traits<Iter>::value_type>(first, last);
7815 template <
typename Iter>
7816 inline internal::AllOfArrayMatcher<
7817 typename ::std::iterator_traits<Iter>::value_type>
7818 AllOfArray(Iter first, Iter last) {
7819 return internal::AllOfArrayMatcher<
7820 typename ::std::iterator_traits<Iter>::value_type>(first, last);
7823 template <
typename T>
7824 inline internal::AnyOfArrayMatcher<T> AnyOfArray(
const T* ptr,
size_t count) {
7825 return AnyOfArray(ptr, ptr + count);
7828 template <
typename T>
7829 inline internal::AllOfArrayMatcher<T> AllOfArray(
const T* ptr,
size_t count) {
7830 return AllOfArray(ptr, ptr + count);
7833 template <
typename T,
size_t N>
7834 inline internal::AnyOfArrayMatcher<T> AnyOfArray(
const T (&array)[N]) {
7835 return AnyOfArray(array, N);
7838 template <
typename T,
size_t N>
7839 inline internal::AllOfArrayMatcher<T> AllOfArray(
const T (&array)[N]) {
7840 return AllOfArray(array, N);
7843 template <
typename Container>
7844 inline internal::AnyOfArrayMatcher<typename Container::value_type> AnyOfArray(
7845 const Container& container) {
7846 return AnyOfArray(container.begin(), container.end());
7849 template <
typename Container>
7850 inline internal::AllOfArrayMatcher<typename Container::value_type> AllOfArray(
7851 const Container& container) {
7852 return AllOfArray(container.begin(), container.end());
7855 template <
typename T>
7856 inline internal::AnyOfArrayMatcher<T> AnyOfArray(
7857 ::std::initializer_list<T> xs) {
7858 return AnyOfArray(xs.begin(), xs.end());
7861 template <
typename T>
7862 inline internal::AllOfArrayMatcher<T> AllOfArray(
7863 ::std::initializer_list<T> xs) {
7864 return AllOfArray(xs.begin(), xs.end());
7870 template <
size_t... k,
typename InnerMatcher>
7871 internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...> Args(
7872 InnerMatcher&& matcher) {
7873 return internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...>(
7874 std::forward<InnerMatcher>(matcher));
7884 template <
typename InnerMatcher>
7885 inline InnerMatcher AllArgs(
const InnerMatcher& matcher) {
return matcher; }
7895 template <
typename ValueMatcher>
7896 inline internal::OptionalMatcher<ValueMatcher> Optional(
7897 const ValueMatcher& value_matcher) {
7898 return internal::OptionalMatcher<ValueMatcher>(value_matcher);
7902 template <
typename T>
7903 PolymorphicMatcher<internal::any_cast_matcher::AnyCastMatcher<T> > AnyWith(
7904 const Matcher<const T&>& matcher) {
7905 return MakePolymorphicMatcher(
7906 internal::any_cast_matcher::AnyCastMatcher<T>(matcher));
7913 template <
typename T>
7914 PolymorphicMatcher<internal::variant_matcher::VariantMatcher<T> > VariantWith(
7915 const Matcher<const T&>& matcher) {
7916 return MakePolymorphicMatcher(
7917 internal::variant_matcher::VariantMatcher<T>(matcher));
7920 #if GTEST_HAS_EXCEPTIONS 7924 namespace internal {
7926 class WithWhatMatcherImpl {
7928 WithWhatMatcherImpl(Matcher<std::string> matcher)
7929 : matcher_(
std::move(matcher)) {}
7931 void DescribeTo(std::ostream* os)
const {
7932 *os <<
"contains .what() that ";
7933 matcher_.DescribeTo(os);
7936 void DescribeNegationTo(std::ostream* os)
const {
7937 *os <<
"contains .what() that does not ";
7938 matcher_.DescribeTo(os);
7941 template <
typename Err>
7942 bool MatchAndExplain(
const Err& err, MatchResultListener* listener)
const {
7943 *listener <<
"which contains .what() that ";
7944 return matcher_.MatchAndExplain(err.what(), listener);
7948 const Matcher<std::string> matcher_;
7951 inline PolymorphicMatcher<WithWhatMatcherImpl> WithWhat(
7952 Matcher<std::string> m) {
7953 return MakePolymorphicMatcher(WithWhatMatcherImpl(std::move(m)));
7956 template <
typename Err>
7957 class ExceptionMatcherImpl {
7960 const char* what() const noexcept {
7961 return "this exception should never be thrown";
7986 using DefaultExceptionType =
typename std::conditional<
7987 std::is_same<
typename std::remove_cv<
7988 typename std::remove_reference<Err>::type>::type,
7989 std::exception>::value,
7990 const NeverThrown&,
const std::exception&>::type;
7993 ExceptionMatcherImpl(Matcher<const Err&> matcher)
7994 : matcher_(
std::move(matcher)) {}
7996 void DescribeTo(std::ostream* os)
const {
7997 *os <<
"throws an exception which is a " << GetTypeName<Err>();
7999 matcher_.DescribeTo(os);
8002 void DescribeNegationTo(std::ostream* os)
const {
8003 *os <<
"throws an exception which is not a " << GetTypeName<Err>();
8005 matcher_.DescribeNegationTo(os);
8008 template <
typename T>
8009 bool MatchAndExplain(T&& x, MatchResultListener* listener)
const {
8011 (void)(std::forward<T>(x)());
8012 }
catch (
const Err& err) {
8013 *listener <<
"throws an exception which is a " << GetTypeName<Err>();
8015 return matcher_.MatchAndExplain(err, listener);
8016 }
catch (DefaultExceptionType err) {
8018 *listener <<
"throws an exception of type " << GetTypeName(
typeid(err));
8021 *listener <<
"throws an std::exception-derived type ";
8023 *listener <<
"with description \"" << err.what() <<
"\"";
8026 *listener <<
"throws an exception of an unknown type";
8030 *listener <<
"does not throw any exception";
8035 const Matcher<const Err&> matcher_;
8062 template <
typename Err>
8063 PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> Throws() {
8064 return MakePolymorphicMatcher(
8065 internal::ExceptionMatcherImpl<Err>(A<const Err&>()));
8068 template <
typename Err,
typename ExceptionMatcher>
8069 PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> Throws(
8070 const ExceptionMatcher& exception_matcher) {
8074 return MakePolymorphicMatcher(internal::ExceptionMatcherImpl<Err>(
8075 SafeMatcherCast<const Err&>(exception_matcher)));
8078 template <
typename Err,
typename MessageMatcher>
8079 PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> ThrowsMessage(
8080 MessageMatcher&& message_matcher) {
8081 static_assert(std::is_base_of<std::exception, Err>::value,
8082 "expected an std::exception-derived type");
8083 return Throws<Err>(internal::WithWhat(
8084 MatcherCast<std::string>(std::forward<MessageMatcher>(message_matcher))));
8087 #endif // GTEST_HAS_EXCEPTIONS 8093 #define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\ 8094 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) 8095 #define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\ 8096 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) 8099 #define MATCHER(name, description) \ 8100 class name##Matcher \ 8101 : public ::testing::internal::MatcherBaseImpl<name##Matcher> { \ 8103 template <typename arg_type> \ 8104 class gmock_Impl : public ::testing::MatcherInterface<const arg_type&> { \ 8107 bool MatchAndExplain( \ 8108 const arg_type& arg, \ 8109 ::testing::MatchResultListener* result_listener) const override; \ 8110 void DescribeTo(::std::ostream* gmock_os) const override { \ 8111 *gmock_os << FormatDescription(false); \ 8113 void DescribeNegationTo(::std::ostream* gmock_os) const override { \ 8114 *gmock_os << FormatDescription(true); \ 8118 ::std::string FormatDescription(bool negation) const { \ 8119 ::std::string gmock_description = (description); \ 8120 if (!gmock_description.empty()) { \ 8121 return gmock_description; \ 8123 return ::testing::internal::FormatMatcherDescription(negation, #name, \ 8128 GTEST_ATTRIBUTE_UNUSED_ inline name##Matcher name() { return {}; } \ 8129 template <typename arg_type> \ 8130 bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain( \ 8131 const arg_type& arg, \ 8132 ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_) \ 8135 #define MATCHER_P(name, p0, description) \ 8136 GMOCK_INTERNAL_MATCHER(name, name##MatcherP, description, (p0)) 8137 #define MATCHER_P2(name, p0, p1, description) \ 8138 GMOCK_INTERNAL_MATCHER(name, name##MatcherP2, description, (p0, p1)) 8139 #define MATCHER_P3(name, p0, p1, p2, description) \ 8140 GMOCK_INTERNAL_MATCHER(name, name##MatcherP3, description, (p0, p1, p2)) 8141 #define MATCHER_P4(name, p0, p1, p2, p3, description) \ 8142 GMOCK_INTERNAL_MATCHER(name, name##MatcherP4, description, (p0, p1, p2, p3)) 8143 #define MATCHER_P5(name, p0, p1, p2, p3, p4, description) \ 8144 GMOCK_INTERNAL_MATCHER(name, name##MatcherP5, description, \ 8145 (p0, p1, p2, p3, p4)) 8146 #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description) \ 8147 GMOCK_INTERNAL_MATCHER(name, name##MatcherP6, description, \ 8148 (p0, p1, p2, p3, p4, p5)) 8149 #define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description) \ 8150 GMOCK_INTERNAL_MATCHER(name, name##MatcherP7, description, \ 8151 (p0, p1, p2, p3, p4, p5, p6)) 8152 #define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description) \ 8153 GMOCK_INTERNAL_MATCHER(name, name##MatcherP8, description, \ 8154 (p0, p1, p2, p3, p4, p5, p6, p7)) 8155 #define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description) \ 8156 GMOCK_INTERNAL_MATCHER(name, name##MatcherP9, description, \ 8157 (p0, p1, p2, p3, p4, p5, p6, p7, p8)) 8158 #define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description) \ 8159 GMOCK_INTERNAL_MATCHER(name, name##MatcherP10, description, \ 8160 (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) 8162 #define GMOCK_INTERNAL_MATCHER(name, full_name, description, args) \ 8163 template <GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args)> \ 8164 class full_name : public ::testing::internal::MatcherBaseImpl< \ 8165 full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>> { \ 8167 using full_name::MatcherBaseImpl::MatcherBaseImpl; \ 8168 template <typename arg_type> \ 8169 class gmock_Impl : public ::testing::MatcherInterface<const arg_type&> { \ 8171 explicit gmock_Impl(GMOCK_INTERNAL_MATCHER_FUNCTION_ARGS(args)) \ 8172 : GMOCK_INTERNAL_MATCHER_FORWARD_ARGS(args) {} \ 8173 bool MatchAndExplain( \ 8174 const arg_type& arg, \ 8175 ::testing::MatchResultListener* result_listener) const override; \ 8176 void DescribeTo(::std::ostream* gmock_os) const override { \ 8177 *gmock_os << FormatDescription(false); \ 8179 void DescribeNegationTo(::std::ostream* gmock_os) const override { \ 8180 *gmock_os << FormatDescription(true); \ 8182 GMOCK_INTERNAL_MATCHER_MEMBERS(args) \ 8185 ::std::string FormatDescription(bool negation) const { \ 8186 ::std::string gmock_description = (description); \ 8187 if (!gmock_description.empty()) { \ 8188 return gmock_description; \ 8190 return ::testing::internal::FormatMatcherDescription( \ 8192 ::testing::internal::UniversalTersePrintTupleFieldsToStrings( \ 8193 ::std::tuple<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>( \ 8194 GMOCK_INTERNAL_MATCHER_MEMBERS_USAGE(args)))); \ 8198 template <GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args)> \ 8199 inline full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)> name( \ 8200 GMOCK_INTERNAL_MATCHER_FUNCTION_ARGS(args)) { \ 8201 return full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>( \ 8202 GMOCK_INTERNAL_MATCHER_ARGS_USAGE(args)); \ 8204 template <GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args)> \ 8205 template <typename arg_type> \ 8206 bool full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>::gmock_Impl< \ 8207 arg_type>::MatchAndExplain(const arg_type& arg, \ 8208 ::testing::MatchResultListener* \ 8209 result_listener GTEST_ATTRIBUTE_UNUSED_) \ 8212 #define GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args) \ 8214 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAM, , args)) 8215 #define GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAM(i_unused, data_unused, arg) \ 8216 , typename arg##_type 8218 #define GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args) \ 8219 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_TYPE_PARAM, , args)) 8220 #define GMOCK_INTERNAL_MATCHER_TYPE_PARAM(i_unused, data_unused, arg) \ 8223 #define GMOCK_INTERNAL_MATCHER_FUNCTION_ARGS(args) \ 8224 GMOCK_PP_TAIL(dummy_first GMOCK_PP_FOR_EACH( \ 8225 GMOCK_INTERNAL_MATCHER_FUNCTION_ARG, , args)) 8226 #define GMOCK_INTERNAL_MATCHER_FUNCTION_ARG(i, data_unused, arg) \ 8227 , arg##_type gmock_p##i 8229 #define GMOCK_INTERNAL_MATCHER_FORWARD_ARGS(args) \ 8230 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_FORWARD_ARG, , args)) 8231 #define GMOCK_INTERNAL_MATCHER_FORWARD_ARG(i, data_unused, arg) \ 8232 , arg(::std::forward<arg##_type>(gmock_p##i)) 8234 #define GMOCK_INTERNAL_MATCHER_MEMBERS(args) \ 8235 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_MEMBER, , args) 8236 #define GMOCK_INTERNAL_MATCHER_MEMBER(i_unused, data_unused, arg) \ 8237 const arg##_type arg; 8239 #define GMOCK_INTERNAL_MATCHER_MEMBERS_USAGE(args) \ 8240 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_MEMBER_USAGE, , args)) 8241 #define GMOCK_INTERNAL_MATCHER_MEMBER_USAGE(i_unused, data_unused, arg) , arg 8243 #define GMOCK_INTERNAL_MATCHER_ARGS_USAGE(args) \ 8244 GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_MATCHER_ARG_USAGE, , args)) 8245 #define GMOCK_INTERNAL_MATCHER_ARG_USAGE(i, data_unused, arg_unused) \ 8249 using namespace no_adl;
8253 GTEST_DISABLE_MSC_WARNINGS_POP_()
8291 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ 8292 #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ 8293 #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ 8295 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ 8297 #if GTEST_HAS_EXCEPTIONS 8298 # include <stdexcept> 8301 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
8310 class ExpectationSet;
8314 namespace internal {
8317 template <
typename F>
class FunctionMocker;
8320 class ExpectationBase;
8323 template <
typename F>
class TypedExpectation;
8326 class ExpectationTester;
8329 template <
typename MockClass>
8331 template <
typename MockClass>
8332 class StrictMockImpl;
8333 template <
typename MockClass>
8334 class NaggyMockImpl;
8347 GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
8350 class UntypedActionResultHolderBase;
8355 class GTEST_API_ UntypedFunctionMockerBase {
8357 UntypedFunctionMockerBase();
8358 virtual ~UntypedFunctionMockerBase();
8363 bool VerifyAndClearExpectationsLocked()
8364 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
8367 virtual
void ClearDefaultActionsLocked()
8368 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0;
8379 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
8380 void* untyped_args, const
std::
string& call_description) const = 0;
8385 virtual UntypedActionResultHolderBase* UntypedPerformAction(
8386 const
void* untyped_action,
void* untyped_args) const = 0;
8391 virtual
void UntypedDescribeUninterestingCall(
8392 const
void* untyped_args,
8393 ::
std::ostream* os) const
8394 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
8402 virtual const ExpectationBase* UntypedFindMatchingExpectation(
8403 const
void* untyped_args,
8404 const
void** untyped_action,
bool* is_excessive,
8405 ::
std::ostream* what, ::
std::ostream* why)
8406 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
8409 virtual
void UntypedPrintArgs(const
void* untyped_args,
8410 ::
std::ostream* os) const = 0;
8416 void RegisterOwner(const
void* mock_obj)
8417 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8422 void SetOwnerAndName(const
void* mock_obj, const
char* name)
8423 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8428 const
void* MockObject() const
8429 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8433 const
char* Name() const
8434 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8440 UntypedActionResultHolderBase* UntypedInvokeWith(
void* untyped_args)
8441 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
8444 typedef
std::vector<const
void*> UntypedOnCallSpecs;
8446 using UntypedExpectations =
std::vector<
std::shared_ptr<ExpectationBase>>;
8450 Expectation GetHandleOf(ExpectationBase* exp);
8455 const
void* mock_obj_;
8462 UntypedOnCallSpecs untyped_on_call_specs_;
8473 UntypedExpectations untyped_expectations_;
8477 class UntypedOnCallSpecBase {
8480 UntypedOnCallSpecBase(
const char* a_file,
int a_line)
8481 : file_(a_file), line_(a_line), last_clause_(kNone) {}
8484 const char* file()
const {
return file_; }
8485 int line()
const {
return line_; }
8498 void AssertSpecProperty(
bool property,
8499 const std::string& failure_message)
const {
8500 Assert(property, file_, line_, failure_message);
8504 void ExpectSpecProperty(
bool property,
8505 const std::string& failure_message)
const {
8506 Expect(property, file_, line_, failure_message);
8514 Clause last_clause_;
8518 template <
typename F>
8519 class OnCallSpec :
public UntypedOnCallSpecBase {
8521 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
8522 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
8526 OnCallSpec(
const char* a_file,
int a_line,
8527 const ArgumentMatcherTuple& matchers)
8528 : UntypedOnCallSpecBase(a_file, a_line),
8529 matchers_(matchers),
8533 extra_matcher_(A<const ArgumentTuple&>()) {}
8536 OnCallSpec& With(
const Matcher<const ArgumentTuple&>& m) {
8538 ExpectSpecProperty(last_clause_ < kWith,
8539 ".With() cannot appear " 8540 "more than once in an ON_CALL().");
8541 last_clause_ = kWith;
8548 OnCallSpec& WillByDefault(
const Action<F>& action) {
8549 ExpectSpecProperty(last_clause_ < kWillByDefault,
8550 ".WillByDefault() must appear " 8551 "exactly once in an ON_CALL().");
8552 last_clause_ = kWillByDefault;
8554 ExpectSpecProperty(!action.IsDoDefault(),
8555 "DoDefault() cannot be used in ON_CALL().");
8561 bool Matches(
const ArgumentTuple& args)
const {
8562 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
8566 const Action<F>& GetAction()
const {
8567 AssertSpecProperty(last_clause_ == kWillByDefault,
8568 ".WillByDefault() must appear exactly " 8569 "once in an ON_CALL().");
8587 ArgumentMatcherTuple matchers_;
8588 Matcher<const ArgumentTuple&> extra_matcher_;
8602 class GTEST_API_ Mock {
8608 static void AllowLeak(
const void* mock_obj)
8609 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8614 static bool VerifyAndClearExpectations(
void* mock_obj)
8615 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8620 static bool VerifyAndClear(
void* mock_obj)
8621 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8624 static bool IsNaggy(
void* mock_obj)
8625 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8627 static bool IsNice(
void* mock_obj)
8628 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8630 static bool IsStrict(
void* mock_obj)
8631 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8634 friend class internal::UntypedFunctionMockerBase;
8638 template <
typename F>
8639 friend class internal::FunctionMocker;
8641 template <
typename MockClass>
8642 friend class internal::NiceMockImpl;
8643 template <
typename MockClass>
8644 friend class internal::NaggyMockImpl;
8645 template <
typename MockClass>
8646 friend class internal::StrictMockImpl;
8650 static void AllowUninterestingCalls(uintptr_t mock_obj)
8651 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8655 static void WarnUninterestingCalls(uintptr_t mock_obj)
8656 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8660 static void FailUninterestingCalls(uintptr_t mock_obj)
8661 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8665 static void UnregisterCallReaction(uintptr_t mock_obj)
8666 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8670 static internal::CallReaction GetReactionOnUninterestingCalls(
8671 const void* mock_obj)
8672 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8677 static bool VerifyAndClearExpectationsLocked(
void* mock_obj)
8678 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
8681 static void ClearDefaultActionsLocked(
void* mock_obj)
8682 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
8685 static void Register(
8686 const void* mock_obj,
8687 internal::UntypedFunctionMockerBase* mocker)
8688 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8693 static void RegisterUseByOnCallOrExpectCall(
8694 const void* mock_obj,
const char* file,
int line)
8695 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
8701 static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
8702 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
8721 class GTEST_API_ Expectation {
8725 Expectation(Expectation&&) =
default;
8726 Expectation(
const Expectation&) =
default;
8727 Expectation& operator=(Expectation&&) =
default;
8728 Expectation& operator=(
const Expectation&) =
default;
8740 Expectation(internal::ExpectationBase& exp);
8747 bool operator==(
const Expectation& rhs)
const {
8748 return expectation_base_ == rhs.expectation_base_;
8751 bool operator!=(
const Expectation& rhs)
const {
return !(*
this == rhs); }
8754 friend class ExpectationSet;
8755 friend class Sequence;
8756 friend class ::testing::internal::ExpectationBase;
8757 friend class ::testing::internal::UntypedFunctionMockerBase;
8759 template <
typename F>
8760 friend class ::testing::internal::FunctionMocker;
8762 template <
typename F>
8763 friend class ::testing::internal::TypedExpectation;
8768 bool operator()(
const Expectation& lhs,
const Expectation& rhs)
const {
8769 return lhs.expectation_base_.get() < rhs.expectation_base_.get();
8773 typedef ::std::set<Expectation, Less> Set;
8776 const std::shared_ptr<internal::ExpectationBase>& expectation_base);
8779 const std::shared_ptr<internal::ExpectationBase>& expectation_base()
const {
8780 return expectation_base_;
8784 std::shared_ptr<internal::ExpectationBase> expectation_base_;
8800 class ExpectationSet {
8803 typedef Expectation::Set::const_iterator const_iterator;
8806 typedef Expectation::Set::value_type value_type;
8814 ExpectationSet(internal::ExpectationBase& exp) {
8815 *
this += Expectation(exp);
8821 ExpectationSet(
const Expectation& e) {
8830 bool operator==(
const ExpectationSet& rhs)
const {
8831 return expectations_ == rhs.expectations_;
8834 bool operator!=(
const ExpectationSet& rhs)
const {
return !(*
this == rhs); }
8838 ExpectationSet& operator+=(
const Expectation& e) {
8839 expectations_.insert(e);
8843 int size()
const {
return static_cast<int>(expectations_.size()); }
8845 const_iterator begin()
const {
return expectations_.
begin(); }
8846 const_iterator end()
const {
return expectations_.end(); }
8849 Expectation::Set expectations_;
8856 class GTEST_API_ Sequence {
8859 Sequence() : last_expectation_(new Expectation) {}
8863 void AddExpectation(
const Expectation& expectation)
const;
8867 std::shared_ptr<Expectation> last_expectation_;
8894 class GTEST_API_ InSequence {
8899 bool sequence_created_;
8901 GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence);
8902 } GTEST_ATTRIBUTE_UNUSED_;
8904 namespace internal {
8908 GTEST_API_
extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
8924 class GTEST_API_ ExpectationBase {
8927 ExpectationBase(
const char* file,
int line,
const std::string& source_text);
8929 virtual ~ExpectationBase();
8932 const char* file()
const {
return file_; }
8933 int line()
const {
return line_; }
8934 const char* source_text()
const {
return source_text_.c_str(); }
8936 const Cardinality& cardinality()
const {
return cardinality_; }
8939 void DescribeLocationTo(::std::ostream* os)
const {
8940 *os << FormatFileLocation(file(), line()) <<
" ";
8945 void DescribeCallCountTo(::std::ostream* os)
const 8946 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
8950 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0;
8953 friend class ::testing::Expectation;
8954 friend class UntypedFunctionMockerBase;
8965 kRetiresOnSaturation
8968 typedef std::vector<const void*> UntypedActions;
8972 virtual Expectation GetHandle() = 0;
8975 void AssertSpecProperty(
bool property,
8976 const std::string& failure_message)
const {
8977 Assert(property, file_, line_, failure_message);
8981 void ExpectSpecProperty(
bool property,
8982 const std::string& failure_message)
const {
8983 Expect(property, file_, line_, failure_message);
8988 void SpecifyCardinality(
const Cardinality& cardinality);
8992 bool cardinality_specified()
const {
return cardinality_specified_; }
8995 void set_cardinality(
const Cardinality& a_cardinality) {
8996 cardinality_ = a_cardinality;
9004 void RetireAllPreRequisites()
9005 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9008 bool is_retired() const
9009 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9010 g_gmock_mutex.AssertHeld();
9016 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9017 g_gmock_mutex.AssertHeld();
9022 bool IsSatisfied() const
9023 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9024 g_gmock_mutex.AssertHeld();
9025 return cardinality().IsSatisfiedByCallCount(call_count_);
9029 bool IsSaturated() const
9030 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9031 g_gmock_mutex.AssertHeld();
9032 return cardinality().IsSaturatedByCallCount(call_count_);
9036 bool IsOverSaturated() const
9037 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9038 g_gmock_mutex.AssertHeld();
9039 return cardinality().IsOverSaturatedByCallCount(call_count_);
9044 bool AllPrerequisitesAreSatisfied() const
9045 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9048 void FindUnsatisfiedPrerequisites(ExpectationSet* result) const
9049 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
9052 int call_count() const
9053 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9054 g_gmock_mutex.AssertHeld();
9059 void IncrementCallCount()
9060 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9061 g_gmock_mutex.AssertHeld();
9069 void CheckActionCountIfNotDone() const
9070 GTEST_LOCK_EXCLUDED_(mutex_);
9072 friend class ::testing::Sequence;
9073 friend class ::testing::internal::ExpectationTester;
9075 template <typename Function>
9076 friend class TypedExpectation;
9079 void UntypedTimes(const Cardinality& a_cardinality);
9085 const
std::
string source_text_;
9087 bool cardinality_specified_;
9088 Cardinality cardinality_;
9095 ExpectationSet immediate_prerequisites_;
9101 UntypedActions untyped_actions_;
9102 bool extra_matcher_specified_;
9103 bool repeated_action_specified_;
9104 bool retires_on_saturation_;
9105 Clause last_clause_;
9106 mutable
bool action_count_checked_;
9107 mutable Mutex mutex_;
9111 template <typename F>
9112 class TypedExpectation : public ExpectationBase {
9114 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
9115 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
9116 typedef typename Function<F>::Result Result;
9118 TypedExpectation(FunctionMocker<F>* owner,
const char* a_file,
int a_line,
9119 const std::string& a_source_text,
9120 const ArgumentMatcherTuple& m)
9121 : ExpectationBase(a_file, a_line, a_source_text),
9127 extra_matcher_(A<const ArgumentTuple&>()),
9128 repeated_action_(DoDefault()) {}
9130 ~TypedExpectation()
override {
9133 CheckActionCountIfNotDone();
9134 for (UntypedActions::const_iterator it = untyped_actions_.begin();
9135 it != untyped_actions_.end(); ++it) {
9136 delete static_cast<const Action<F>*
>(*it);
9141 TypedExpectation& With(
const Matcher<const ArgumentTuple&>& m) {
9142 if (last_clause_ == kWith) {
9143 ExpectSpecProperty(
false,
9144 ".With() cannot appear " 9145 "more than once in an EXPECT_CALL().");
9147 ExpectSpecProperty(last_clause_ < kWith,
9148 ".With() must be the first " 9149 "clause in an EXPECT_CALL().");
9151 last_clause_ = kWith;
9154 extra_matcher_specified_ =
true;
9159 TypedExpectation& Times(
const Cardinality& a_cardinality) {
9160 ExpectationBase::UntypedTimes(a_cardinality);
9165 TypedExpectation& Times(
int n) {
9166 return Times(Exactly(n));
9170 TypedExpectation& InSequence(
const Sequence& s) {
9171 ExpectSpecProperty(last_clause_ <= kInSequence,
9172 ".InSequence() cannot appear after .After()," 9173 " .WillOnce(), .WillRepeatedly(), or " 9174 ".RetiresOnSaturation().");
9175 last_clause_ = kInSequence;
9177 s.AddExpectation(GetHandle());
9180 TypedExpectation& InSequence(
const Sequence& s1,
const Sequence& s2) {
9181 return InSequence(s1).InSequence(s2);
9183 TypedExpectation& InSequence(
const Sequence& s1,
const Sequence& s2,
9184 const Sequence& s3) {
9185 return InSequence(s1, s2).InSequence(s3);
9187 TypedExpectation& InSequence(
const Sequence& s1,
const Sequence& s2,
9188 const Sequence& s3,
const Sequence& s4) {
9189 return InSequence(s1, s2, s3).InSequence(s4);
9191 TypedExpectation& InSequence(
const Sequence& s1,
const Sequence& s2,
9192 const Sequence& s3,
const Sequence& s4,
9193 const Sequence& s5) {
9194 return InSequence(s1, s2, s3, s4).InSequence(s5);
9198 TypedExpectation& After(
const ExpectationSet& s) {
9199 ExpectSpecProperty(last_clause_ <= kAfter,
9200 ".After() cannot appear after .WillOnce()," 9201 " .WillRepeatedly(), or " 9202 ".RetiresOnSaturation().");
9203 last_clause_ = kAfter;
9205 for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) {
9206 immediate_prerequisites_ += *it;
9210 TypedExpectation& After(
const ExpectationSet& s1,
const ExpectationSet& s2) {
9211 return After(s1).After(s2);
9213 TypedExpectation& After(
const ExpectationSet& s1,
const ExpectationSet& s2,
9214 const ExpectationSet& s3) {
9215 return After(s1, s2).After(s3);
9217 TypedExpectation& After(
const ExpectationSet& s1,
const ExpectationSet& s2,
9218 const ExpectationSet& s3,
const ExpectationSet& s4) {
9219 return After(s1, s2, s3).After(s4);
9221 TypedExpectation& After(
const ExpectationSet& s1,
const ExpectationSet& s2,
9222 const ExpectationSet& s3,
const ExpectationSet& s4,
9223 const ExpectationSet& s5) {
9224 return After(s1, s2, s3, s4).After(s5);
9228 TypedExpectation& WillOnce(
const Action<F>& action) {
9229 ExpectSpecProperty(last_clause_ <= kWillOnce,
9230 ".WillOnce() cannot appear after " 9231 ".WillRepeatedly() or .RetiresOnSaturation().");
9232 last_clause_ = kWillOnce;
9234 untyped_actions_.push_back(
new Action<F>(action));
9235 if (!cardinality_specified()) {
9236 set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
9242 TypedExpectation& WillRepeatedly(
const Action<F>& action) {
9243 if (last_clause_ == kWillRepeatedly) {
9244 ExpectSpecProperty(
false,
9245 ".WillRepeatedly() cannot appear " 9246 "more than once in an EXPECT_CALL().");
9248 ExpectSpecProperty(last_clause_ < kWillRepeatedly,
9249 ".WillRepeatedly() cannot appear " 9250 "after .RetiresOnSaturation().");
9252 last_clause_ = kWillRepeatedly;
9253 repeated_action_specified_ =
true;
9255 repeated_action_ = action;
9256 if (!cardinality_specified()) {
9257 set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size())));
9262 CheckActionCountIfNotDone();
9267 TypedExpectation& RetiresOnSaturation() {
9268 ExpectSpecProperty(last_clause_ < kRetiresOnSaturation,
9269 ".RetiresOnSaturation() cannot appear " 9271 last_clause_ = kRetiresOnSaturation;
9272 retires_on_saturation_ =
true;
9276 CheckActionCountIfNotDone();
9282 const ArgumentMatcherTuple& matchers()
const {
9287 const Matcher<const ArgumentTuple&>& extra_matcher()
const {
9288 return extra_matcher_;
9292 const Action<F>& repeated_action()
const {
return repeated_action_; }
9296 void MaybeDescribeExtraMatcherTo(::std::ostream* os)
override {
9297 if (extra_matcher_specified_) {
9298 *os <<
" Expected args: ";
9299 extra_matcher_.DescribeTo(os);
9305 template <
typename Function>
9306 friend class FunctionMocker;
9310 Expectation GetHandle()
override {
return owner_->GetHandleOf(
this); }
9317 bool Matches(
const ArgumentTuple& args)
const 9318 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9319 g_gmock_mutex.AssertHeld();
9320 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
9325 bool ShouldHandleArguments(
const ArgumentTuple& args)
const 9326 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9327 g_gmock_mutex.AssertHeld();
9333 CheckActionCountIfNotDone();
9334 return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args);
9339 void ExplainMatchResultTo(
9340 const ArgumentTuple& args,
9341 ::std::ostream* os)
const 9342 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9343 g_gmock_mutex.AssertHeld();
9346 *os <<
" Expected: the expectation is active\n" 9347 <<
" Actual: it is retired\n";
9348 }
else if (!Matches(args)) {
9349 if (!TupleMatches(matchers_, args)) {
9350 ExplainMatchFailureTupleTo(matchers_, args, os);
9352 StringMatchResultListener listener;
9353 if (!extra_matcher_.MatchAndExplain(args, &listener)) {
9354 *os <<
" Expected args: ";
9355 extra_matcher_.DescribeTo(os);
9356 *os <<
"\n Actual: don't match";
9358 internal::PrintIfNotEmpty(listener.str(), os);
9361 }
else if (!AllPrerequisitesAreSatisfied()) {
9362 *os <<
" Expected: all pre-requisites are satisfied\n" 9363 <<
" Actual: the following immediate pre-requisites " 9364 <<
"are not satisfied:\n";
9365 ExpectationSet unsatisfied_prereqs;
9366 FindUnsatisfiedPrerequisites(&unsatisfied_prereqs);
9368 for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin();
9369 it != unsatisfied_prereqs.end(); ++it) {
9370 it->expectation_base()->DescribeLocationTo(os);
9371 *os <<
"pre-requisite #" << i++ <<
"\n";
9373 *os <<
" (end of pre-requisites)\n";
9379 *os <<
"The call matches the expectation.\n";
9384 const Action<F>& GetCurrentAction(
const FunctionMocker<F>* mocker,
9385 const ArgumentTuple& args)
const 9386 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9387 g_gmock_mutex.AssertHeld();
9388 const int count = call_count();
9389 Assert(count >= 1, __FILE__, __LINE__,
9390 "call_count() is <= 0 when GetCurrentAction() is " 9391 "called - this should never happen.");
9393 const int action_count =
static_cast<int>(untyped_actions_.size());
9394 if (action_count > 0 && !repeated_action_specified_ &&
9395 count > action_count) {
9398 ::std::stringstream ss;
9399 DescribeLocationTo(&ss);
9400 ss <<
"Actions ran out in " << source_text() <<
"...\n" 9401 <<
"Called " << count <<
" times, but only " 9402 << action_count <<
" WillOnce()" 9403 << (action_count == 1 ?
" is" :
"s are") <<
" specified - ";
9404 mocker->DescribeDefaultActionTo(args, &ss);
9405 Log(kWarning, ss.str(), 1);
9408 return count <= action_count
9409 ? *
static_cast<const Action<F>*
>(
9410 untyped_actions_[
static_cast<size_t>(count - 1)])
9411 : repeated_action();
9421 const Action<F>* GetActionForArguments(
const FunctionMocker<F>* mocker,
9422 const ArgumentTuple& args,
9423 ::std::ostream* what,
9424 ::std::ostream* why)
9425 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9426 g_gmock_mutex.AssertHeld();
9427 if (IsSaturated()) {
9429 IncrementCallCount();
9430 *what <<
"Mock function called more times than expected - ";
9431 mocker->DescribeDefaultActionTo(args, what);
9432 DescribeCallCountTo(why);
9437 IncrementCallCount();
9438 RetireAllPreRequisites();
9440 if (retires_on_saturation_ && IsSaturated()) {
9445 *what <<
"Mock function call matches " << source_text() <<
"...\n";
9446 return &(GetCurrentAction(mocker, args));
9451 FunctionMocker<F>*
const owner_;
9452 ArgumentMatcherTuple matchers_;
9453 Matcher<const ArgumentTuple&> extra_matcher_;
9454 Action<F> repeated_action_;
9456 GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation);
9470 GTEST_API_
void LogWithLocation(testing::internal::LogSeverity severity,
9471 const char* file,
int line,
9472 const std::string& message);
9474 template <
typename F>
9477 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
9478 typedef typename internal::Function<F>::ArgumentMatcherTuple
9479 ArgumentMatcherTuple;
9483 MockSpec(internal::FunctionMocker<F>* function_mocker,
9484 const ArgumentMatcherTuple& matchers)
9485 : function_mocker_(function_mocker), matchers_(matchers) {}
9489 internal::OnCallSpec<F>& InternalDefaultActionSetAt(
9490 const char* file,
int line,
const char* obj,
const char* call) {
9491 LogWithLocation(internal::kInfo, file, line,
9492 std::string(
"ON_CALL(") + obj +
", " + call +
") invoked");
9493 return function_mocker_->AddNewOnCallSpec(file, line, matchers_);
9498 internal::TypedExpectation<F>& InternalExpectedAt(
9499 const char* file,
int line,
const char* obj,
const char* call) {
9500 const std::string source_text(std::string(
"EXPECT_CALL(") + obj +
", " +
9502 LogWithLocation(internal::kInfo, file, line, source_text +
" invoked");
9503 return function_mocker_->AddNewExpectation(
9504 file, line, source_text, matchers_);
9510 MockSpec<F>& operator()(
const internal::WithoutMatchers&,
void*
const) {
9515 template <
typename Function>
9516 friend class internal::FunctionMocker;
9519 internal::FunctionMocker<F>*
const function_mocker_;
9521 ArgumentMatcherTuple matchers_;
9533 template <
typename T>
9534 class ReferenceOrValueWrapper {
9537 explicit ReferenceOrValueWrapper(T value)
9538 : value_(
std::move(value)) {
9544 T Unwrap() {
return std::move(value_); }
9550 const T& Peek()
const {
9560 template <
typename T>
9561 class ReferenceOrValueWrapper<T&> {
9565 typedef T& reference;
9566 explicit ReferenceOrValueWrapper(reference ref)
9567 : value_ptr_(&ref) {}
9568 T& Unwrap() {
return *value_ptr_; }
9569 const T& Peek()
const {
return *value_ptr_; }
9584 class UntypedActionResultHolderBase {
9586 virtual ~UntypedActionResultHolderBase() {}
9589 virtual void PrintAsActionResult(::std::ostream* os)
const = 0;
9593 template <
typename T>
9594 class ActionResultHolder :
public UntypedActionResultHolderBase {
9598 return result_.Unwrap();
9602 void PrintAsActionResult(::std::ostream* os)
const override {
9603 *os <<
"\n Returns: ";
9605 UniversalPrinter<T>::Print(result_.Peek(), os);
9610 template <
typename F>
9611 static ActionResultHolder* PerformDefaultAction(
9612 const FunctionMocker<F>* func_mocker,
9613 typename Function<F>::ArgumentTuple&& args,
9614 const std::string& call_description) {
9615 return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction(
9616 std::move(args), call_description)));
9621 template <
typename F>
9622 static ActionResultHolder* PerformAction(
9623 const Action<F>& action,
typename Function<F>::ArgumentTuple&& args) {
9624 return new ActionResultHolder(
9625 Wrapper(action.Perform(std::move(args))));
9629 typedef ReferenceOrValueWrapper<T> Wrapper;
9631 explicit ActionResultHolder(Wrapper result)
9632 : result_(
std::move(result)) {
9637 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
9642 class ActionResultHolder<void> :
public UntypedActionResultHolderBase {
9646 void PrintAsActionResult(::std::ostream* )
const override {}
9650 template <
typename F>
9651 static ActionResultHolder* PerformDefaultAction(
9652 const FunctionMocker<F>* func_mocker,
9653 typename Function<F>::ArgumentTuple&& args,
9654 const std::string& call_description) {
9655 func_mocker->PerformDefaultAction(std::move(args), call_description);
9656 return new ActionResultHolder;
9661 template <
typename F>
9662 static ActionResultHolder* PerformAction(
9663 const Action<F>& action,
typename Function<F>::ArgumentTuple&& args) {
9664 action.Perform(std::move(args));
9665 return new ActionResultHolder;
9669 ActionResultHolder() {}
9670 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
9673 template <
typename F>
9674 class FunctionMocker;
9676 template <
typename R,
typename... Args>
9677 class FunctionMocker<R(Args...)> final :
public UntypedFunctionMockerBase {
9678 using F = R(Args...);
9682 using ArgumentTuple = std::tuple<Args...>;
9683 using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
9699 FunctionMocker(
const FunctionMocker&) =
delete;
9700 FunctionMocker& operator=(
const FunctionMocker&) =
delete;
9705 ~FunctionMocker() override GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
9706 MutexLock l(&g_gmock_mutex);
9707 VerifyAndClearExpectationsLocked();
9708 Mock::UnregisterLocked(
this);
9709 ClearDefaultActionsLocked();
9715 const OnCallSpec<F>* FindOnCallSpec(
9716 const ArgumentTuple& args)
const {
9717 for (UntypedOnCallSpecs::const_reverse_iterator it
9718 = untyped_on_call_specs_.rbegin();
9719 it != untyped_on_call_specs_.rend(); ++it) {
9720 const OnCallSpec<F>* spec =
static_cast<const OnCallSpec<F>*
>(*it);
9721 if (spec->Matches(args))
9735 Result PerformDefaultAction(ArgumentTuple&& args,
9736 const std::string& call_description)
const {
9737 const OnCallSpec<F>*
const spec =
9738 this->FindOnCallSpec(args);
9739 if (spec !=
nullptr) {
9740 return spec->GetAction().Perform(std::move(args));
9742 const std::string message =
9744 "\n The mock function has no default action " 9745 "set, and its return type has no default value set.";
9746 #if GTEST_HAS_EXCEPTIONS 9747 if (!DefaultValue<Result>::Exists()) {
9748 throw std::runtime_error(message);
9751 Assert(DefaultValue<Result>::Exists(),
"", -1, message);
9753 return DefaultValue<Result>::Get();
9761 UntypedActionResultHolderBase* UntypedPerformDefaultAction(
9763 const std::string& call_description)
const override {
9764 ArgumentTuple* args =
static_cast<ArgumentTuple*
>(untyped_args);
9765 return ResultHolder::PerformDefaultAction(
this, std::move(*args),
9773 UntypedActionResultHolderBase* UntypedPerformAction(
9774 const void* untyped_action,
void* untyped_args)
const override {
9777 const Action<F> action = *
static_cast<const Action<F>*
>(untyped_action);
9778 ArgumentTuple* args =
static_cast<ArgumentTuple*
>(untyped_args);
9779 return ResultHolder::PerformAction(action, std::move(*args));
9784 void ClearDefaultActionsLocked() override
9785 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9786 g_gmock_mutex.AssertHeld();
9795 UntypedOnCallSpecs specs_to_delete;
9796 untyped_on_call_specs_.swap(specs_to_delete);
9798 g_gmock_mutex.Unlock();
9799 for (UntypedOnCallSpecs::const_iterator it =
9800 specs_to_delete.begin();
9801 it != specs_to_delete.end(); ++it) {
9802 delete static_cast<const OnCallSpec<F>*
>(*it);
9807 g_gmock_mutex.Lock();
9813 Result Invoke(Args... args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
9814 ArgumentTuple tuple(std::forward<Args>(args)...);
9815 std::unique_ptr<ResultHolder> holder(DownCast_<ResultHolder*>(
9816 this->UntypedInvokeWith(static_cast<void*>(&tuple))));
9817 return holder->Unwrap();
9820 MockSpec<F> With(Matcher<Args>... m) {
9821 return MockSpec<F>(
this, ::std::make_tuple(std::move(m)...));
9825 template <
typename Function>
9826 friend class MockSpec;
9828 typedef ActionResultHolder<Result> ResultHolder;
9831 OnCallSpec<F>& AddNewOnCallSpec(
9832 const char* file,
int line,
9833 const ArgumentMatcherTuple& m)
9834 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
9835 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
9836 OnCallSpec<F>*
const on_call_spec =
new OnCallSpec<F>(file, line, m);
9837 untyped_on_call_specs_.push_back(on_call_spec);
9838 return *on_call_spec;
9842 TypedExpectation<F>& AddNewExpectation(
const char* file,
int line,
9843 const std::string& source_text,
9844 const ArgumentMatcherTuple& m)
9845 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
9846 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
9847 TypedExpectation<F>*
const expectation =
9848 new TypedExpectation<F>(
this, file, line, source_text, m);
9849 const std::shared_ptr<ExpectationBase> untyped_expectation(expectation);
9852 untyped_expectations_.push_back(untyped_expectation);
9855 Sequence*
const implicit_sequence = g_gmock_implicit_sequence.get();
9856 if (implicit_sequence !=
nullptr) {
9857 implicit_sequence->AddExpectation(Expectation(untyped_expectation));
9860 return *expectation;
9864 template <
typename Func>
friend class TypedExpectation;
9871 void DescribeDefaultActionTo(
const ArgumentTuple& args,
9872 ::std::ostream* os)
const {
9873 const OnCallSpec<F>*
const spec = FindOnCallSpec(args);
9875 if (spec ==
nullptr) {
9876 *os << (std::is_void<Result>::value ?
"returning directly.\n" 9877 :
"returning default value.\n");
9879 *os <<
"taking default action specified at:\n" 9880 << FormatFileLocation(spec->file(), spec->line()) <<
"\n";
9887 void UntypedDescribeUninterestingCall(
const void* untyped_args,
9888 ::std::ostream* os)
const override 9889 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
9890 const ArgumentTuple& args =
9891 *
static_cast<const ArgumentTuple*
>(untyped_args);
9892 *os <<
"Uninteresting mock function call - ";
9893 DescribeDefaultActionTo(args, os);
9894 *os <<
" Function call: " << Name();
9895 UniversalPrint(args, os);
9914 const ExpectationBase* UntypedFindMatchingExpectation(
9915 const void* untyped_args,
const void** untyped_action,
bool* is_excessive,
9916 ::std::ostream* what, ::std::ostream* why)
override 9917 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
9918 const ArgumentTuple& args =
9919 *
static_cast<const ArgumentTuple*
>(untyped_args);
9920 MutexLock l(&g_gmock_mutex);
9921 TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args);
9922 if (exp ==
nullptr) {
9923 this->FormatUnexpectedCallMessageLocked(args, what, why);
9930 *is_excessive = exp->IsSaturated();
9931 const Action<F>* action = exp->GetActionForArguments(
this, args, what, why);
9932 if (action !=
nullptr && action->IsDoDefault())
9934 *untyped_action = action;
9939 void UntypedPrintArgs(
const void* untyped_args,
9940 ::std::ostream* os)
const override {
9941 const ArgumentTuple& args =
9942 *
static_cast<const ArgumentTuple*
>(untyped_args);
9943 UniversalPrint(args, os);
9948 TypedExpectation<F>* FindMatchingExpectationLocked(
9949 const ArgumentTuple& args)
const 9950 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9951 g_gmock_mutex.AssertHeld();
9954 for (
typename UntypedExpectations::const_reverse_iterator it =
9955 untyped_expectations_.rbegin();
9956 it != untyped_expectations_.rend(); ++it) {
9957 TypedExpectation<F>*
const exp =
9958 static_cast<TypedExpectation<F>*
>(it->get());
9959 if (exp->ShouldHandleArguments(args)) {
9967 void FormatUnexpectedCallMessageLocked(
9968 const ArgumentTuple& args,
9970 ::std::ostream* why)
const 9971 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9972 g_gmock_mutex.AssertHeld();
9973 *os <<
"\nUnexpected mock function call - ";
9974 DescribeDefaultActionTo(args, os);
9975 PrintTriedExpectationsLocked(args, why);
9980 void PrintTriedExpectationsLocked(
9981 const ArgumentTuple& args,
9982 ::std::ostream* why)
const 9983 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
9984 g_gmock_mutex.AssertHeld();
9985 const size_t count = untyped_expectations_.size();
9986 *why <<
"Google Mock tried the following " << count <<
" " 9987 << (count == 1 ?
"expectation, but it didn't match" :
9988 "expectations, but none matched")
9990 for (
size_t i = 0; i < count; i++) {
9991 TypedExpectation<F>*
const expectation =
9992 static_cast<TypedExpectation<F>*
>(untyped_expectations_[i].get());
9994 expectation->DescribeLocationTo(why);
9996 *why <<
"tried expectation #" << i <<
": ";
9998 *why << expectation->source_text() <<
"...\n";
9999 expectation->ExplainMatchResultTo(args, why);
10000 expectation->DescribeCallCountTo(why);
10007 void ReportUninterestingCall(CallReaction reaction,
const std::string& msg);
10011 namespace internal {
10013 template <
typename F>
10014 class MockFunction;
10016 template <
typename R,
typename... Args>
10017 class MockFunction<R(Args...)> {
10019 MockFunction(
const MockFunction&) =
delete;
10020 MockFunction& operator=(
const MockFunction&) =
delete;
10022 std::function<R(Args...)> AsStdFunction() {
10023 return [
this](Args... args) -> R {
10024 return this->Call(std::forward<Args>(args)...);
10029 R Call(Args... args) {
10030 mock_.SetOwnerAndName(
this,
"Call");
10031 return mock_.Invoke(std::forward<Args>(args)...);
10034 MockSpec<R(Args...)> gmock_Call(Matcher<Args>... m) {
10035 mock_.RegisterOwner(
this);
10036 return mock_.With(std::move(m)...);
10039 MockSpec<R(Args...)> gmock_Call(
const WithoutMatchers&, R (*)(Args...)) {
10040 return this->gmock_Call(::testing::A<Args>()...);
10044 MockFunction() =
default;
10045 ~MockFunction() =
default;
10048 FunctionMocker<R(Args...)> mock_;
10063 template <
typename F>
10064 struct SignatureOf;
10066 template <
typename R,
typename... Args>
10067 struct SignatureOf<R(Args...)> {
10068 using type = R(Args...);
10071 template <
typename F>
10072 struct SignatureOf<
std::function<F>> : SignatureOf<F> {};
10074 template <
typename F>
10075 using SignatureOfT =
typename SignatureOf<F>::type;
10139 template <
typename F>
10140 class MockFunction :
public internal::MockFunction<internal::SignatureOfT<F>> {
10141 using Base = internal::MockFunction<internal::SignatureOfT<F>>;
10152 using internal::MockSpec;
10169 template <
typename T>
10170 inline const T& Const(
const T& x) {
return x; }
10173 inline Expectation::Expectation(internal::ExpectationBase& exp)
10174 : expectation_base_(exp.GetHandle().expectation_base()) {}
10178 GTEST_DISABLE_MSC_WARNINGS_POP_()
10242 #define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \ 10243 ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \ 10245 .Setter(__FILE__, __LINE__, #mock_expr, #call) 10247 #define ON_CALL(obj, call) \ 10248 GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call) 10250 #define EXPECT_CALL(obj, call) \ 10251 GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call) 10253 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ 10255 namespace testing {
10256 namespace internal {
10257 template <
typename T>
10258 using identity_t = T;
10260 template <
typename Pattern>
10261 struct ThisRefAdjuster {
10262 template <
typename T>
10263 using AdjustT =
typename std::conditional<
10264 std::is_const<typename std::remove_reference<Pattern>::type>::value,
10265 typename std::conditional<std::is_lvalue_reference<Pattern>::value,
10266 const T&,
const T&&>::type,
10267 typename std::conditional<std::is_lvalue_reference<Pattern>::value, T&,
10270 template <
typename MockType>
10271 static AdjustT<MockType> Adjust(
const MockType& mock) {
10272 return static_cast<AdjustT<MockType>
>(
const_cast<MockType&
>(mock));
10283 using internal::FunctionMocker;
10286 #define MOCK_METHOD(...) \ 10287 GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__) 10289 #define GMOCK_INTERNAL_MOCK_METHOD_ARG_1(...) \ 10290 GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) 10292 #define GMOCK_INTERNAL_MOCK_METHOD_ARG_2(...) \ 10293 GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) 10295 #define GMOCK_INTERNAL_MOCK_METHOD_ARG_3(_Ret, _MethodName, _Args) \ 10296 GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ()) 10298 #define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \ 10299 GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \ 10300 GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \ 10301 GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ 10302 GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \ 10303 GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ 10304 GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ 10305 GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \ 10306 GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \ 10307 GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Spec), \ 10308 GMOCK_INTERNAL_GET_CALLTYPE(_Spec), GMOCK_INTERNAL_GET_REF_SPEC(_Spec), \ 10309 (GMOCK_INTERNAL_SIGNATURE(_Ret, _Args))) 10311 #define GMOCK_INTERNAL_MOCK_METHOD_ARG_5(...) \ 10312 GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) 10314 #define GMOCK_INTERNAL_MOCK_METHOD_ARG_6(...) \ 10315 GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) 10317 #define GMOCK_INTERNAL_MOCK_METHOD_ARG_7(...) \ 10318 GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) 10320 #define GMOCK_INTERNAL_WRONG_ARITY(...) \ 10323 "MOCK_METHOD must be called with 3 or 4 arguments. _Ret, " \ 10324 "_MethodName, _Args and optionally _Spec. _Args and _Spec must be " \ 10325 "enclosed in parentheses. If _Ret is a type with unprotected commas, " \ 10326 "it must also be enclosed in parentheses.") 10328 #define GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Tuple) \ 10330 GMOCK_PP_IS_ENCLOSED_PARENS(_Tuple), \ 10331 GMOCK_PP_STRINGIZE(_Tuple) " should be enclosed in parentheses.") 10333 #define GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE(_N, ...) \ 10335 std::is_function<__VA_ARGS__>::value, \ 10336 "Signature must be a function type, maybe return type contains " \ 10337 "unprotected comma."); \ 10339 ::testing::tuple_size<typename ::testing::internal::Function< \ 10340 __VA_ARGS__>::ArgumentTuple>::value == _N, \ 10341 "This method does not take " GMOCK_PP_STRINGIZE( \ 10342 _N) " arguments. Parenthesize all types with unprotected commas.") 10344 #define GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ 10345 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT, ~, _Spec) 10347 #define GMOCK_INTERNAL_MOCK_METHOD_IMPL(_N, _MethodName, _Constness, \ 10348 _Override, _Final, _NoexceptSpec, \ 10349 _CallType, _RefSpec, _Signature) \ 10350 typename ::testing::internal::Function<GMOCK_PP_REMOVE_PARENS( \ 10351 _Signature)>::Result \ 10352 GMOCK_INTERNAL_EXPAND(_CallType) \ 10353 _MethodName(GMOCK_PP_REPEAT(GMOCK_INTERNAL_PARAMETER, _Signature, _N)) \ 10354 GMOCK_PP_IF(_Constness, const, ) _RefSpec _NoexceptSpec \ 10355 GMOCK_PP_IF(_Override, override, ) GMOCK_PP_IF(_Final, final, ) { \ 10356 GMOCK_MOCKER_(_N, _Constness, _MethodName) \ 10357 .SetOwnerAndName(this, #_MethodName); \ 10358 return GMOCK_MOCKER_(_N, _Constness, _MethodName) \ 10359 .Invoke(GMOCK_PP_REPEAT(GMOCK_INTERNAL_FORWARD_ARG, _Signature, _N)); \ 10361 ::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \ 10362 GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_PARAMETER, _Signature, _N)) \ 10363 GMOCK_PP_IF(_Constness, const, ) _RefSpec { \ 10364 GMOCK_MOCKER_(_N, _Constness, _MethodName).RegisterOwner(this); \ 10365 return GMOCK_MOCKER_(_N, _Constness, _MethodName) \ 10366 .With(GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_ARGUMENT, , _N)); \ 10368 ::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \ 10369 const ::testing::internal::WithoutMatchers&, \ 10370 GMOCK_PP_IF(_Constness, const, )::testing::internal::Function< \ 10371 GMOCK_PP_REMOVE_PARENS(_Signature)>*) const _RefSpec _NoexceptSpec { \ 10372 return ::testing::internal::ThisRefAdjuster<GMOCK_PP_IF( \ 10373 _Constness, const, ) int _RefSpec>::Adjust(*this) \ 10374 .gmock_##_MethodName(GMOCK_PP_REPEAT( \ 10375 GMOCK_INTERNAL_A_MATCHER_ARGUMENT, _Signature, _N)); \ 10377 mutable ::testing::FunctionMocker<GMOCK_PP_REMOVE_PARENS(_Signature)> \ 10378 GMOCK_MOCKER_(_N, _Constness, _MethodName) 10380 #define GMOCK_INTERNAL_EXPAND(...) __VA_ARGS__ 10383 #define GMOCK_INTERNAL_HAS_CONST(_Tuple) \ 10384 GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple)) 10386 #define GMOCK_INTERNAL_HAS_OVERRIDE(_Tuple) \ 10387 GMOCK_PP_HAS_COMMA( \ 10388 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_OVERRIDE, ~, _Tuple)) 10390 #define GMOCK_INTERNAL_HAS_FINAL(_Tuple) \ 10391 GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_FINAL, ~, _Tuple)) 10393 #define GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Tuple) \ 10394 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_NOEXCEPT_SPEC_IF_NOEXCEPT, ~, _Tuple) 10396 #define GMOCK_INTERNAL_NOEXCEPT_SPEC_IF_NOEXCEPT(_i, _, _elem) \ 10398 GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)), \ 10401 #define GMOCK_INTERNAL_GET_REF_SPEC(_Tuple) \ 10402 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_REF_SPEC_IF_REF, ~, _Tuple) 10404 #define GMOCK_INTERNAL_REF_SPEC_IF_REF(_i, _, _elem) \ 10405 GMOCK_PP_IF(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)), \ 10406 GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), ) 10408 #define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \ 10409 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple) 10411 #define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \ 10413 (GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \ 10414 GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \ 10415 GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \ 10416 GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \ 10417 GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)) + \ 10418 GMOCK_INTERNAL_IS_CALLTYPE(_elem)) == 1, \ 10419 GMOCK_PP_STRINGIZE( \ 10420 _elem) " cannot be recognized as a valid specification modifier."); 10423 #define GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem) \ 10424 GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CONST_I_, _elem) 10426 #define GMOCK_INTERNAL_DETECT_CONST_I_const , 10428 #define GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem) \ 10429 GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_OVERRIDE_I_, _elem) 10431 #define GMOCK_INTERNAL_DETECT_OVERRIDE_I_override , 10433 #define GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem) \ 10434 GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_FINAL_I_, _elem) 10436 #define GMOCK_INTERNAL_DETECT_FINAL_I_final , 10438 #define GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem) \ 10439 GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_NOEXCEPT_I_, _elem) 10441 #define GMOCK_INTERNAL_DETECT_NOEXCEPT_I_noexcept , 10443 #define GMOCK_INTERNAL_DETECT_REF(_i, _, _elem) \ 10444 GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_REF_I_, _elem) 10446 #define GMOCK_INTERNAL_DETECT_REF_I_ref , 10448 #define GMOCK_INTERNAL_UNPACK_ref(x) x 10450 #define GMOCK_INTERNAL_GET_CALLTYPE_IMPL(_i, _, _elem) \ 10451 GMOCK_PP_IF(GMOCK_INTERNAL_IS_CALLTYPE(_elem), \ 10452 GMOCK_INTERNAL_GET_VALUE_CALLTYPE, GMOCK_PP_EMPTY) \ 10458 #define GMOCK_INTERNAL_IS_CALLTYPE(_arg) \ 10459 GMOCK_INTERNAL_IS_CALLTYPE_I( \ 10460 GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) 10461 #define GMOCK_INTERNAL_IS_CALLTYPE_I(_arg) GMOCK_PP_IS_ENCLOSED_PARENS(_arg) 10463 #define GMOCK_INTERNAL_GET_VALUE_CALLTYPE(_arg) \ 10464 GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I( \ 10465 GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) 10466 #define GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I(_arg) \ 10467 GMOCK_PP_IDENTITY _arg 10469 #define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype 10484 #define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \ 10485 ::testing::internal::identity_t<GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), \ 10486 GMOCK_PP_REMOVE_PARENS, \ 10487 GMOCK_PP_IDENTITY)(_Ret)>( \ 10488 GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args)) 10490 #define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \ 10491 GMOCK_PP_COMMA_IF(_i) \ 10492 GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_elem), GMOCK_PP_REMOVE_PARENS, \ 10493 GMOCK_PP_IDENTITY) \ 10496 #define GMOCK_INTERNAL_PARAMETER(_i, _Signature, _) \ 10497 GMOCK_PP_COMMA_IF(_i) \ 10498 GMOCK_INTERNAL_ARG_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature)) \ 10501 #define GMOCK_INTERNAL_FORWARD_ARG(_i, _Signature, _) \ 10502 GMOCK_PP_COMMA_IF(_i) \ 10503 ::std::forward<GMOCK_INTERNAL_ARG_O( \ 10504 _i, GMOCK_PP_REMOVE_PARENS(_Signature))>(gmock_a##_i) 10506 #define GMOCK_INTERNAL_MATCHER_PARAMETER(_i, _Signature, _) \ 10507 GMOCK_PP_COMMA_IF(_i) \ 10508 GMOCK_INTERNAL_MATCHER_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature)) \ 10511 #define GMOCK_INTERNAL_MATCHER_ARGUMENT(_i, _1, _2) \ 10512 GMOCK_PP_COMMA_IF(_i) \ 10515 #define GMOCK_INTERNAL_A_MATCHER_ARGUMENT(_i, _Signature, _) \ 10516 GMOCK_PP_COMMA_IF(_i) \ 10517 ::testing::A<GMOCK_INTERNAL_ARG_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature))>() 10519 #define GMOCK_INTERNAL_ARG_O(_i, ...) \ 10520 typename ::testing::internal::Function<__VA_ARGS__>::template Arg<_i>::type 10522 #define GMOCK_INTERNAL_MATCHER_O(_i, ...) \ 10523 const ::testing::Matcher<typename ::testing::internal::Function< \ 10524 __VA_ARGS__>::template Arg<_i>::type>& 10526 #define MOCK_METHOD0(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 0, __VA_ARGS__) 10527 #define MOCK_METHOD1(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 1, __VA_ARGS__) 10528 #define MOCK_METHOD2(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 2, __VA_ARGS__) 10529 #define MOCK_METHOD3(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 3, __VA_ARGS__) 10530 #define MOCK_METHOD4(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 4, __VA_ARGS__) 10531 #define MOCK_METHOD5(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 5, __VA_ARGS__) 10532 #define MOCK_METHOD6(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 6, __VA_ARGS__) 10533 #define MOCK_METHOD7(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 7, __VA_ARGS__) 10534 #define MOCK_METHOD8(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 8, __VA_ARGS__) 10535 #define MOCK_METHOD9(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 9, __VA_ARGS__) 10536 #define MOCK_METHOD10(m, ...) \ 10537 GMOCK_INTERNAL_MOCK_METHODN(, , m, 10, __VA_ARGS__) 10539 #define MOCK_CONST_METHOD0(m, ...) \ 10540 GMOCK_INTERNAL_MOCK_METHODN(const, , m, 0, __VA_ARGS__) 10541 #define MOCK_CONST_METHOD1(m, ...) \ 10542 GMOCK_INTERNAL_MOCK_METHODN(const, , m, 1, __VA_ARGS__) 10543 #define MOCK_CONST_METHOD2(m, ...) \ 10544 GMOCK_INTERNAL_MOCK_METHODN(const, , m, 2, __VA_ARGS__) 10545 #define MOCK_CONST_METHOD3(m, ...) \ 10546 GMOCK_INTERNAL_MOCK_METHODN(const, , m, 3, __VA_ARGS__) 10547 #define MOCK_CONST_METHOD4(m, ...) \ 10548 GMOCK_INTERNAL_MOCK_METHODN(const, , m, 4, __VA_ARGS__) 10549 #define MOCK_CONST_METHOD5(m, ...) \ 10550 GMOCK_INTERNAL_MOCK_METHODN(const, , m, 5, __VA_ARGS__) 10551 #define MOCK_CONST_METHOD6(m, ...) \ 10552 GMOCK_INTERNAL_MOCK_METHODN(const, , m, 6, __VA_ARGS__) 10553 #define MOCK_CONST_METHOD7(m, ...) \ 10554 GMOCK_INTERNAL_MOCK_METHODN(const, , m, 7, __VA_ARGS__) 10555 #define MOCK_CONST_METHOD8(m, ...) \ 10556 GMOCK_INTERNAL_MOCK_METHODN(const, , m, 8, __VA_ARGS__) 10557 #define MOCK_CONST_METHOD9(m, ...) \ 10558 GMOCK_INTERNAL_MOCK_METHODN(const, , m, 9, __VA_ARGS__) 10559 #define MOCK_CONST_METHOD10(m, ...) \ 10560 GMOCK_INTERNAL_MOCK_METHODN(const, , m, 10, __VA_ARGS__) 10562 #define MOCK_METHOD0_T(m, ...) MOCK_METHOD0(m, __VA_ARGS__) 10563 #define MOCK_METHOD1_T(m, ...) MOCK_METHOD1(m, __VA_ARGS__) 10564 #define MOCK_METHOD2_T(m, ...) MOCK_METHOD2(m, __VA_ARGS__) 10565 #define MOCK_METHOD3_T(m, ...) MOCK_METHOD3(m, __VA_ARGS__) 10566 #define MOCK_METHOD4_T(m, ...) MOCK_METHOD4(m, __VA_ARGS__) 10567 #define MOCK_METHOD5_T(m, ...) MOCK_METHOD5(m, __VA_ARGS__) 10568 #define MOCK_METHOD6_T(m, ...) MOCK_METHOD6(m, __VA_ARGS__) 10569 #define MOCK_METHOD7_T(m, ...) MOCK_METHOD7(m, __VA_ARGS__) 10570 #define MOCK_METHOD8_T(m, ...) MOCK_METHOD8(m, __VA_ARGS__) 10571 #define MOCK_METHOD9_T(m, ...) MOCK_METHOD9(m, __VA_ARGS__) 10572 #define MOCK_METHOD10_T(m, ...) MOCK_METHOD10(m, __VA_ARGS__) 10574 #define MOCK_CONST_METHOD0_T(m, ...) MOCK_CONST_METHOD0(m, __VA_ARGS__) 10575 #define MOCK_CONST_METHOD1_T(m, ...) MOCK_CONST_METHOD1(m, __VA_ARGS__) 10576 #define MOCK_CONST_METHOD2_T(m, ...) MOCK_CONST_METHOD2(m, __VA_ARGS__) 10577 #define MOCK_CONST_METHOD3_T(m, ...) MOCK_CONST_METHOD3(m, __VA_ARGS__) 10578 #define MOCK_CONST_METHOD4_T(m, ...) MOCK_CONST_METHOD4(m, __VA_ARGS__) 10579 #define MOCK_CONST_METHOD5_T(m, ...) MOCK_CONST_METHOD5(m, __VA_ARGS__) 10580 #define MOCK_CONST_METHOD6_T(m, ...) MOCK_CONST_METHOD6(m, __VA_ARGS__) 10581 #define MOCK_CONST_METHOD7_T(m, ...) MOCK_CONST_METHOD7(m, __VA_ARGS__) 10582 #define MOCK_CONST_METHOD8_T(m, ...) MOCK_CONST_METHOD8(m, __VA_ARGS__) 10583 #define MOCK_CONST_METHOD9_T(m, ...) MOCK_CONST_METHOD9(m, __VA_ARGS__) 10584 #define MOCK_CONST_METHOD10_T(m, ...) MOCK_CONST_METHOD10(m, __VA_ARGS__) 10586 #define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \ 10587 GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 0, __VA_ARGS__) 10588 #define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \ 10589 GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 1, __VA_ARGS__) 10590 #define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \ 10591 GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 2, __VA_ARGS__) 10592 #define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \ 10593 GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 3, __VA_ARGS__) 10594 #define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \ 10595 GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 4, __VA_ARGS__) 10596 #define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \ 10597 GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 5, __VA_ARGS__) 10598 #define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \ 10599 GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 6, __VA_ARGS__) 10600 #define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \ 10601 GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 7, __VA_ARGS__) 10602 #define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \ 10603 GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 8, __VA_ARGS__) 10604 #define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \ 10605 GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 9, __VA_ARGS__) 10606 #define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \ 10607 GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 10, __VA_ARGS__) 10609 #define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \ 10610 GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 0, __VA_ARGS__) 10611 #define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \ 10612 GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 1, __VA_ARGS__) 10613 #define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \ 10614 GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 2, __VA_ARGS__) 10615 #define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \ 10616 GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 3, __VA_ARGS__) 10617 #define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \ 10618 GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 4, __VA_ARGS__) 10619 #define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \ 10620 GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 5, __VA_ARGS__) 10621 #define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \ 10622 GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 6, __VA_ARGS__) 10623 #define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \ 10624 GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 7, __VA_ARGS__) 10625 #define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \ 10626 GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 8, __VA_ARGS__) 10627 #define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \ 10628 GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 9, __VA_ARGS__) 10629 #define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \ 10630 GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 10, __VA_ARGS__) 10632 #define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \ 10633 MOCK_METHOD0_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10634 #define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \ 10635 MOCK_METHOD1_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10636 #define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \ 10637 MOCK_METHOD2_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10638 #define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \ 10639 MOCK_METHOD3_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10640 #define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \ 10641 MOCK_METHOD4_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10642 #define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \ 10643 MOCK_METHOD5_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10644 #define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \ 10645 MOCK_METHOD6_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10646 #define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \ 10647 MOCK_METHOD7_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10648 #define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \ 10649 MOCK_METHOD8_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10650 #define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \ 10651 MOCK_METHOD9_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10652 #define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \ 10653 MOCK_METHOD10_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10655 #define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \ 10656 MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10657 #define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \ 10658 MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10659 #define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \ 10660 MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10661 #define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \ 10662 MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10663 #define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \ 10664 MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10665 #define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \ 10666 MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10667 #define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \ 10668 MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10669 #define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \ 10670 MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10671 #define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \ 10672 MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10673 #define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \ 10674 MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10675 #define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \ 10676 MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, __VA_ARGS__) 10678 #define GMOCK_INTERNAL_MOCK_METHODN(constness, ct, Method, args_num, ...) \ 10679 GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ 10680 args_num, ::testing::internal::identity_t<__VA_ARGS__>); \ 10681 GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ 10682 args_num, Method, GMOCK_PP_NARG0(constness), 0, 0, , ct, , \ 10683 (::testing::internal::identity_t<__VA_ARGS__>)) 10685 #define GMOCK_MOCKER_(arity, constness, Method) \ 10686 GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) 10688 #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ 10725 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ 10726 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ 10735 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ 10736 #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ 10738 #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ 10822 #define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0 10823 #define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ 10824 name1) kind0 name0, kind1 name1 10825 #define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10826 kind2, name2) kind0 name0, kind1 name1, kind2 name2 10827 #define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10828 kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \ 10830 #define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10831 kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \ 10832 kind2 name2, kind3 name3, kind4 name4 10833 #define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10834 kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \ 10835 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5 10836 #define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10837 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ 10838 name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \ 10839 kind5 name5, kind6 name6 10840 #define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10841 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ 10842 kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \ 10843 kind4 name4, kind5 name5, kind6 name6, kind7 name7 10844 #define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10845 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ 10846 kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \ 10847 kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \ 10849 #define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ 10850 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ 10851 name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \ 10852 kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \ 10853 kind6 name6, kind7 name7, kind8 name8, kind9 name9 10856 #define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0 10857 #define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ 10858 name1) name0, name1 10859 #define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10860 kind2, name2) name0, name1, name2 10861 #define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10862 kind2, name2, kind3, name3) name0, name1, name2, name3 10863 #define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10864 kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \ 10866 #define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10867 kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \ 10868 name2, name3, name4, name5 10869 #define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10870 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ 10871 name6) name0, name1, name2, name3, name4, name5, name6 10872 #define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10873 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ 10874 kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7 10875 #define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ 10876 kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ 10877 kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \ 10878 name6, name7, name8 10879 #define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ 10880 name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ 10881 name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \ 10882 name3, name4, name5, name6, name7, name8, name9 10885 #define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS() 10886 #define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type 10887 #define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \ 10888 typename p0##_type, typename p1##_type 10889 #define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \ 10890 typename p0##_type, typename p1##_type, typename p2##_type 10891 #define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ 10892 typename p0##_type, typename p1##_type, typename p2##_type, \ 10894 #define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ 10895 typename p0##_type, typename p1##_type, typename p2##_type, \ 10896 typename p3##_type, typename p4##_type 10897 #define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ 10898 typename p0##_type, typename p1##_type, typename p2##_type, \ 10899 typename p3##_type, typename p4##_type, typename p5##_type 10900 #define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 10901 p6) , typename p0##_type, typename p1##_type, typename p2##_type, \ 10902 typename p3##_type, typename p4##_type, typename p5##_type, \ 10904 #define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 10905 p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \ 10906 typename p3##_type, typename p4##_type, typename p5##_type, \ 10907 typename p6##_type, typename p7##_type 10908 #define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 10909 p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \ 10910 typename p3##_type, typename p4##_type, typename p5##_type, \ 10911 typename p6##_type, typename p7##_type, typename p8##_type 10912 #define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 10913 p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \ 10914 typename p2##_type, typename p3##_type, typename p4##_type, \ 10915 typename p5##_type, typename p6##_type, typename p7##_type, \ 10916 typename p8##_type, typename p9##_type 10919 #define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\ 10921 #define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\ 10922 (p0##_type gmock_p0) : p0(::std::move(gmock_p0)) 10923 #define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\ 10924 (p0##_type gmock_p0, p1##_type gmock_p1) : p0(::std::move(gmock_p0)), \ 10925 p1(::std::move(gmock_p1)) 10926 #define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\ 10927 (p0##_type gmock_p0, p1##_type gmock_p1, \ 10928 p2##_type gmock_p2) : p0(::std::move(gmock_p0)), \ 10929 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)) 10930 #define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\ 10931 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 10932 p3##_type gmock_p3) : p0(::std::move(gmock_p0)), \ 10933 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ 10934 p3(::std::move(gmock_p3)) 10935 #define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\ 10936 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 10937 p3##_type gmock_p3, p4##_type gmock_p4) : p0(::std::move(gmock_p0)), \ 10938 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ 10939 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)) 10940 #define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\ 10941 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 10942 p3##_type gmock_p3, p4##_type gmock_p4, \ 10943 p5##_type gmock_p5) : p0(::std::move(gmock_p0)), \ 10944 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ 10945 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ 10946 p5(::std::move(gmock_p5)) 10947 #define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\ 10948 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 10949 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 10950 p6##_type gmock_p6) : p0(::std::move(gmock_p0)), \ 10951 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ 10952 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ 10953 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)) 10954 #define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\ 10955 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 10956 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 10957 p6##_type gmock_p6, p7##_type gmock_p7) : p0(::std::move(gmock_p0)), \ 10958 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ 10959 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ 10960 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ 10961 p7(::std::move(gmock_p7)) 10962 #define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 10964 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 10965 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 10966 p6##_type gmock_p6, p7##_type gmock_p7, \ 10967 p8##_type gmock_p8) : p0(::std::move(gmock_p0)), \ 10968 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ 10969 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ 10970 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ 10971 p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)) 10972 #define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 10974 (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ 10975 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ 10976 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ 10977 p9##_type gmock_p9) : p0(::std::move(gmock_p0)), \ 10978 p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ 10979 p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ 10980 p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ 10981 p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)), \ 10982 p9(::std::move(gmock_p9)) 10985 #define GMOCK_INTERNAL_DEFN_COPY_AND_0_VALUE_PARAMS() \ 10986 {} // Avoid https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134 10987 #define GMOCK_INTERNAL_DEFN_COPY_AND_1_VALUE_PARAMS(...) = default; 10988 #define GMOCK_INTERNAL_DEFN_COPY_AND_2_VALUE_PARAMS(...) = default; 10989 #define GMOCK_INTERNAL_DEFN_COPY_AND_3_VALUE_PARAMS(...) = default; 10990 #define GMOCK_INTERNAL_DEFN_COPY_AND_4_VALUE_PARAMS(...) = default; 10991 #define GMOCK_INTERNAL_DEFN_COPY_AND_5_VALUE_PARAMS(...) = default; 10992 #define GMOCK_INTERNAL_DEFN_COPY_AND_6_VALUE_PARAMS(...) = default; 10993 #define GMOCK_INTERNAL_DEFN_COPY_AND_7_VALUE_PARAMS(...) = default; 10994 #define GMOCK_INTERNAL_DEFN_COPY_AND_8_VALUE_PARAMS(...) = default; 10995 #define GMOCK_INTERNAL_DEFN_COPY_AND_9_VALUE_PARAMS(...) = default; 10996 #define GMOCK_INTERNAL_DEFN_COPY_AND_10_VALUE_PARAMS(...) = default; 10999 #define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS() 11000 #define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0; 11001 #define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \ 11003 #define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \ 11004 p1##_type p1; p2##_type p2; 11005 #define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \ 11006 p1##_type p1; p2##_type p2; p3##_type p3; 11007 #define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ 11008 p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; 11009 #define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ 11010 p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ 11012 #define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 11013 p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ 11014 p5##_type p5; p6##_type p6; 11015 #define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11016 p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ 11017 p5##_type p5; p6##_type p6; p7##_type p7; 11018 #define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11019 p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ 11020 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; 11021 #define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11022 p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ 11023 p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \ 11027 #define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS() 11028 #define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0 11029 #define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1 11030 #define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2 11031 #define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3 11032 #define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \ 11034 #define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \ 11036 #define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 11037 p6) p0, p1, p2, p3, p4, p5, p6 11038 #define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11039 p7) p0, p1, p2, p3, p4, p5, p6, p7 11040 #define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11041 p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8 11042 #define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11043 p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 11046 #define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS() 11047 #define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type 11048 #define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \ 11050 #define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \ 11051 p1##_type, p2##_type 11052 #define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ 11053 p0##_type, p1##_type, p2##_type, p3##_type 11054 #define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ 11055 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type 11056 #define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ 11057 p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type 11058 #define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 11059 p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \ 11061 #define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 11062 p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 11063 p5##_type, p6##_type, p7##_type 11064 #define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 11065 p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 11066 p5##_type, p6##_type, p7##_type, p8##_type 11067 #define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 11068 p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ 11069 p5##_type, p6##_type, p7##_type, p8##_type, p9##_type 11072 #define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS() 11073 #define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0 11074 #define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \ 11076 #define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \ 11077 p1##_type p1, p2##_type p2 11078 #define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \ 11079 p1##_type p1, p2##_type p2, p3##_type p3 11080 #define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ 11081 p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4 11082 #define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ 11083 p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ 11085 #define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ 11086 p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ 11087 p5##_type p5, p6##_type p6 11088 #define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11089 p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ 11090 p5##_type p5, p6##_type p6, p7##_type p7 11091 #define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11092 p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ 11093 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8 11094 #define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11095 p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ 11096 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ 11100 #define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS() 11101 #define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P 11102 #define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2 11103 #define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3 11104 #define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4 11105 #define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5 11106 #define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6 11107 #define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7 11108 #define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11110 #define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11112 #define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ 11116 #define GMOCK_ACTION_CLASS_(name, value_params)\ 11117 GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params) 11119 #define ACTION_TEMPLATE(name, template_params, value_params) \ 11120 template <GMOCK_INTERNAL_DECL_##template_params \ 11121 GMOCK_INTERNAL_DECL_TYPE_##value_params> \ 11122 class GMOCK_ACTION_CLASS_(name, value_params) { \ 11124 explicit GMOCK_ACTION_CLASS_(name, value_params)( \ 11125 GMOCK_INTERNAL_DECL_##value_params) \ 11126 GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ 11128 : impl_(std::make_shared<gmock_Impl>( \ 11129 GMOCK_INTERNAL_LIST_##value_params)) { }) \ 11130 GMOCK_ACTION_CLASS_(name, value_params)( \ 11131 const GMOCK_ACTION_CLASS_(name, value_params)&) noexcept \ 11132 GMOCK_INTERNAL_DEFN_COPY_##value_params \ 11133 GMOCK_ACTION_CLASS_(name, value_params)( \ 11134 GMOCK_ACTION_CLASS_(name, value_params)&&) noexcept \ 11135 GMOCK_INTERNAL_DEFN_COPY_##value_params \ 11136 template <typename F> \ 11137 operator ::testing::Action<F>() const { \ 11138 return GMOCK_PP_IF( \ 11139 GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ 11140 (::testing::internal::MakeAction<F, gmock_Impl>()), \ 11141 (::testing::internal::MakeAction<F>(impl_))); \ 11144 class gmock_Impl { \ 11146 explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {} \ 11147 template <typename function_type, typename return_type, \ 11148 typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ 11149 return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ 11150 GMOCK_INTERNAL_DEFN_##value_params \ 11152 GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ 11153 , std::shared_ptr<const gmock_Impl> impl_;) \ 11155 template <GMOCK_INTERNAL_DECL_##template_params \ 11156 GMOCK_INTERNAL_DECL_TYPE_##value_params> \ 11157 GMOCK_ACTION_CLASS_(name, value_params)< \ 11158 GMOCK_INTERNAL_LIST_##template_params \ 11159 GMOCK_INTERNAL_LIST_TYPE_##value_params> name( \ 11160 GMOCK_INTERNAL_DECL_##value_params) GTEST_MUST_USE_RESULT_; \ 11161 template <GMOCK_INTERNAL_DECL_##template_params \ 11162 GMOCK_INTERNAL_DECL_TYPE_##value_params> \ 11163 inline GMOCK_ACTION_CLASS_(name, value_params)< \ 11164 GMOCK_INTERNAL_LIST_##template_params \ 11165 GMOCK_INTERNAL_LIST_TYPE_##value_params> name( \ 11166 GMOCK_INTERNAL_DECL_##value_params) { \ 11167 return GMOCK_ACTION_CLASS_(name, value_params)< \ 11168 GMOCK_INTERNAL_LIST_##template_params \ 11169 GMOCK_INTERNAL_LIST_TYPE_##value_params>( \ 11170 GMOCK_INTERNAL_LIST_##value_params); \ 11172 template <GMOCK_INTERNAL_DECL_##template_params \ 11173 GMOCK_INTERNAL_DECL_TYPE_##value_params> \ 11174 template <typename function_type, typename return_type, typename args_type, \ 11175 GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ 11176 return_type GMOCK_ACTION_CLASS_(name, value_params)< \ 11177 GMOCK_INTERNAL_LIST_##template_params \ 11178 GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl::gmock_PerformImpl( \ 11179 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const 11181 namespace testing {
11189 # pragma warning(push) 11190 # pragma warning(disable:4100) 11193 namespace internal {
11199 template <
typename F,
typename... Args>
11200 auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) {
11204 template <std::size_t index,
typename... Params>
11205 struct InvokeArgumentAction {
11206 template <
typename... Args>
11207 auto operator()(Args&&... args)
const -> decltype(internal::InvokeArgument(
11208 std::get<index>(std::forward_as_tuple(std::forward<Args>(args)...)),
11209 std::declval<const Params&>()...)) {
11210 internal::FlatTuple<Args&&...> args_tuple(FlatTupleConstructTag{},
11211 std::forward<Args>(args)...);
11212 return params.Apply([&](
const Params&... unpacked_params) {
11213 auto&& callable = args_tuple.template Get<index>();
11214 return internal::InvokeArgument(
11215 std::forward<decltype(callable)>(callable), unpacked_params...);
11219 internal::FlatTuple<Params...> params;
11251 template <std::size_t index,
typename... Params>
11252 internal::InvokeArgumentAction<index, typename std::decay<Params>::type...>
11253 InvokeArgument(Params&&... params) {
11254 return {internal::FlatTuple<typename std::decay<Params>::type...>(
11255 internal::FlatTupleConstructTag{}, std::forward<Params>(params)...)};
11259 # pragma warning(pop) 11264 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ 11304 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ 11305 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ 11308 namespace testing {
11313 # pragma warning(push) 11314 # pragma warning(disable:4100) 11315 #if (_MSC_VER == 1900) 11318 # pragma warning(disable:4800) 11324 MATCHER(IsEmpty, negation ?
"isn't empty" :
"is empty") {
11328 *result_listener <<
"whose size is " << arg.size();
11336 MATCHER(IsTrue, negation ?
"is false" :
"is true") {
11337 return static_cast<bool>(arg);
11344 MATCHER(IsFalse, negation ?
"is true" :
"is false") {
11345 return !
static_cast<bool>(arg);
11349 # pragma warning(pop) 11355 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ 11418 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ 11419 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ 11422 #include <type_traits> 11425 namespace testing {
11426 template <
class MockClass>
11428 template <
class MockClass>
11430 template <
class MockClass>
11433 namespace internal {
11434 template <
typename T>
11435 std::true_type StrictnessModifierProbe(
const NiceMock<T>&);
11436 template <
typename T>
11437 std::true_type StrictnessModifierProbe(
const NaggyMock<T>&);
11438 template <
typename T>
11439 std::true_type StrictnessModifierProbe(
const StrictMock<T>&);
11440 std::false_type StrictnessModifierProbe(...);
11442 template <
typename T>
11443 constexpr
bool HasStrictnessModifier() {
11444 return decltype(StrictnessModifierProbe(std::declval<const T&>()))::value;
11454 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW && \ 11455 (defined(_MSC_VER) || defined(__clang__)) 11458 #define GTEST_INTERNAL_EMPTY_BASE_CLASS __declspec(empty_bases) 11460 #define GTEST_INTERNAL_EMPTY_BASE_CLASS 11463 template <
typename Base>
11464 class NiceMockImpl {
11467 ::testing::Mock::AllowUninterestingCalls(reinterpret_cast<uintptr_t>(
this));
11471 ::testing::Mock::UnregisterCallReaction(reinterpret_cast<uintptr_t>(
this));
11475 template <
typename Base>
11476 class NaggyMockImpl {
11479 ::testing::Mock::WarnUninterestingCalls(reinterpret_cast<uintptr_t>(
this));
11483 ::testing::Mock::UnregisterCallReaction(reinterpret_cast<uintptr_t>(
this));
11487 template <
typename Base>
11488 class StrictMockImpl {
11491 ::testing::Mock::FailUninterestingCalls(reinterpret_cast<uintptr_t>(
this));
11494 ~StrictMockImpl() {
11495 ::testing::Mock::UnregisterCallReaction(reinterpret_cast<uintptr_t>(
this));
11501 template <
class MockClass>
11502 class GTEST_INTERNAL_EMPTY_BASE_CLASS NiceMock
11503 :
private internal::NiceMockImpl<MockClass>,
11506 static_assert(!internal::HasStrictnessModifier<MockClass>(),
11507 "Can't apply NiceMock to a class hierarchy that already has a " 11508 "strictness modifier. See " 11509 "https://google.github.io/googletest/" 11510 "gmock_cook_book.html#NiceStrictNaggy");
11511 NiceMock() : MockClass() {
11512 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
11513 "The impl subclass shouldn't introduce any padding");
11523 template <
typename A>
11524 explicit NiceMock(A&& arg) : MockClass(
std::forward<A>(arg)) {
11525 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
11526 "The impl subclass shouldn't introduce any padding");
11529 template <
typename TArg1,
typename TArg2,
typename... An>
11530 NiceMock(TArg1&& arg1, TArg2&& arg2, An&&... args)
11531 : MockClass(
std::forward<TArg1>(arg1),
std::forward<TArg2>(arg2),
11532 std::forward<An>(args)...) {
11533 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
11534 "The impl subclass shouldn't introduce any padding");
11538 GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
11541 template <
class MockClass>
11542 class GTEST_INTERNAL_EMPTY_BASE_CLASS NaggyMock
11543 :
private internal::NaggyMockImpl<MockClass>,
11545 static_assert(!internal::HasStrictnessModifier<MockClass>(),
11546 "Can't apply NaggyMock to a class hierarchy that already has a " 11547 "strictness modifier. See " 11548 "https://google.github.io/googletest/" 11549 "gmock_cook_book.html#NiceStrictNaggy");
11552 NaggyMock() : MockClass() {
11553 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
11554 "The impl subclass shouldn't introduce any padding");
11564 template <
typename A>
11565 explicit NaggyMock(A&& arg) : MockClass(
std::forward<A>(arg)) {
11566 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
11567 "The impl subclass shouldn't introduce any padding");
11570 template <
typename TArg1,
typename TArg2,
typename... An>
11571 NaggyMock(TArg1&& arg1, TArg2&& arg2, An&&... args)
11572 : MockClass(
std::forward<TArg1>(arg1),
std::forward<TArg2>(arg2),
11573 std::forward<An>(args)...) {
11574 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
11575 "The impl subclass shouldn't introduce any padding");
11579 GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
11582 template <
class MockClass>
11583 class GTEST_INTERNAL_EMPTY_BASE_CLASS StrictMock
11584 :
private internal::StrictMockImpl<MockClass>,
11588 !internal::HasStrictnessModifier<MockClass>(),
11589 "Can't apply StrictMock to a class hierarchy that already has a " 11590 "strictness modifier. See " 11591 "https://google.github.io/googletest/" 11592 "gmock_cook_book.html#NiceStrictNaggy");
11593 StrictMock() : MockClass() {
11594 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
11595 "The impl subclass shouldn't introduce any padding");
11605 template <
typename A>
11606 explicit StrictMock(A&& arg) : MockClass(
std::forward<A>(arg)) {
11607 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
11608 "The impl subclass shouldn't introduce any padding");
11611 template <
typename TArg1,
typename TArg2,
typename... An>
11612 StrictMock(TArg1&& arg1, TArg2&& arg2, An&&... args)
11613 : MockClass(
std::forward<TArg1>(arg1),
std::forward<TArg2>(arg2),
11614 std::forward<An>(args)...) {
11615 static_assert(
sizeof(*
this) ==
sizeof(MockClass),
11616 "The impl subclass shouldn't introduce any padding");
11620 GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
11623 #undef GTEST_INTERNAL_EMPTY_BASE_CLASS 11627 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ 11629 namespace testing {
11632 GMOCK_DECLARE_bool_(catch_leaked_mocks);
11633 GMOCK_DECLARE_string_(verbose);
11634 GMOCK_DECLARE_int32_(default_mock_behavior);
11647 GTEST_API_
void InitGoogleMock(
int* argc,
char** argv);
11651 GTEST_API_
void InitGoogleMock(
int* argc,
wchar_t** argv);
11655 GTEST_API_
void InitGoogleMock();
11659 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_
iterator begin()
use to initialise an iterator to the first element of the vector
Definition: VectorWithOffset.inl:190
const Array< num_dimensions - num_dimensions2, elemT > & get(const Array< num_dimensions, elemT > &a, const BasicCoordinate< num_dimensions2, int > &c)
an alternative for array indexing using BasicCoordinate objects
Definition: array_index_functions.inl:114