36 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 37 #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 46 #include "gmock/internal/gmock-internal-utils.h" 47 #include "gmock/internal/gmock-port.h" 49 #if GTEST_HAS_STD_TYPE_TRAITS_ // Defined by gtest-port.h via gmock-port.h. 50 #include <type_traits> 66 template <
typename F1,
typename F2>
74 template <
typename T,
bool kDefaultConstructible>
75 struct BuiltInDefaultValueGetter {
81 Assert(
false, __FILE__, __LINE__,
82 "Default action undefined for the function return type.");
83 return internal::Invalid<T>();
99 #if GTEST_HAS_STD_TYPE_TRAITS_ 101 static bool Exists() {
110 #else // GTEST_HAS_STD_TYPE_TRAITS_ 120 #endif // GTEST_HAS_STD_TYPE_TRAITS_ 125 template <
typename T>
134 template <
typename T>
138 static T*
Get() {
return NULL; }
143 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \ 145 class BuiltInDefaultValue<type> { \ 147 static bool Exists() { return true; } \ 148 static type Get() { return value; } \ 152 #if GTEST_HAS_GLOBAL_STRING 154 #endif // GTEST_HAS_GLOBAL_STRING 167 #if GMOCK_WCHAR_T_IS_NATIVE_ 182 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_ 199 template <
typename T>
212 typedef T (*FactoryFunction)();
225 static bool IsSet() {
return producer_ != NULL; }
237 return producer_ == NULL ?
245 virtual T Produce() = 0;
261 : factory_(factory) {}
265 const FactoryFunction factory_;
274 template <
typename T>
288 static bool IsSet() {
return address_ != NULL; }
300 return address_ == NULL ?
318 template <
typename T>
322 template <
typename T>
326 template <
typename F>
339 virtual Result Perform(
const ArgumentTuple& args) = 0;
354 template <
typename F>
375 template <
typename Func>
387 Result
Perform(
const ArgumentTuple& args)
const {
389 !IsDoDefault(), __FILE__, __LINE__,
390 "You are using DoDefault() inside a composite action like " 391 "DoAll() or WithArgs(). This is not supported for technical " 392 "reasons. Please instead spell out the default action, or " 393 "assign the default action to an Action variable and use " 394 "the variable in various places.");
395 return impl_->Perform(args);
399 template <
typename F1,
typename F2>
426 template <
typename Impl>
431 template <
typename F>
437 template <
typename F>
445 virtual Result
Perform(
const ArgumentTuple& args) {
446 return impl_.template Perform<Result>(args);
462 template <
typename F>
474 template <
typename Impl>
483 template <
typename F1,
typename F2>
491 virtual Result
Perform(
const ArgumentTuple& args) {
492 return impl_->Perform(args);
503 template <
typename T>
533 template <
typename R>
543 template <
typename F>
556 use_ReturnRef_instead_of_Return_to_return_a_reference);
562 template <
typename R_,
typename F>
576 : value_before_cast_(*value),
579 virtual Result
Perform(
const ArgumentTuple&) {
return value_; }
583 Result_cannot_be_a_reference_type);
586 R value_before_cast_;
594 template <
typename R_,
typename F>
601 : performed_(false), wrapper_(wrapper) {}
603 virtual Result
Perform(
const ArgumentTuple&) {
605 <<
"A ByMove() action should only be performed once.";
628 template <
typename Result,
typename ArgumentTuple>
634 ReturnNull_can_be_used_to_return_a_pointer_only);
636 #endif // GTEST_LANG_CXX11 644 template <
typename Result,
typename ArgumentTuple>
653 template <
typename T>
661 template <
typename F>
668 use_Return_instead_of_ReturnRef_to_return_a_value);
674 template <
typename F>
680 explicit Impl(T& ref) : ref_(ref) {}
682 virtual Result
Perform(
const ArgumentTuple&) {
700 template <
typename T>
709 template <
typename F>
717 use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
723 template <
typename F>
731 virtual Result
Perform(
const ArgumentTuple&) {
751 template <
typename F>
757 template <
typename T1,
typename T2>
762 template <
typename Result,
typename ArgumentTuple>
774 #if !GTEST_OS_WINDOWS_MOBILE 778 template <
typename T>
782 : errno_(errno_value),
784 template <
typename Result,
typename ArgumentTuple>
797 #endif // !GTEST_OS_WINDOWS_MOBILE 803 template <
size_t N,
typename A,
bool kIsProto>
810 template <
typename Result,
typename ArgumentTuple>
811 void Perform(
const ArgumentTuple& args)
const {
813 *::testing::get<N>(args) = value_;
822 template <
size_t N,
typename Proto>
830 proto_->CopyFrom(proto);
833 template <
typename Result,
typename ArgumentTuple>
834 void Perform(
const ArgumentTuple& args)
const {
836 ::testing::get<N>(args)->CopyFrom(*proto_);
850 template <
typename FunctionImpl>
856 : function_impl_(function_impl) {}
860 template <
typename Result,
typename ArgumentTuple>
861 Result
Perform(
const ArgumentTuple&) {
return function_impl_(); }
864 FunctionImpl function_impl_;
870 template <
class Class,
typename MethodPtr>
874 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
876 template <
typename Result,
typename ArgumentTuple>
878 return (obj_ptr_->*method_ptr_)();
882 Class*
const obj_ptr_;
883 const MethodPtr method_ptr_;
889 template <
typename A>
894 template <
typename F>
913 template <
typename F>
921 virtual void Perform(
const ArgumentTuple& args) {
923 action_.Perform(args);
949 template <
typename T>
957 operator T&()
const {
return *pointer_; }
963 template <
typename T>
971 template <
typename Action1,
typename Action2>
975 : action1_(action1), action2_(action2) {}
979 template <
typename F>
986 template <
typename F>
994 : action1_(action1), action2_(action2) {}
996 virtual Result
Perform(
const ArgumentTuple& args) {
997 action1_.Perform(args);
998 return action2_.Perform(args);
1052 template <
typename To>
1053 template <
typename From>
1060 template <
typename R>
1076 template <
typename R>
1084 template <
typename R>
1093 template <
typename R>
1105 template <
size_t N,
typename T>
1114 #if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) 1123 N,
const char*,
false>(p));
1131 N,
const wchar_t*,
false>(p));
1136 template <
size_t N,
typename T>
1146 template <
typename T1,
typename T2>
1151 #if !GTEST_OS_WINDOWS_MOBILE 1154 template <
typename T>
1161 #endif // !GTEST_OS_WINDOWS_MOBILE 1166 template <
typename FunctionImpl>
1175 template <
class Class,
typename MethodPtr>
1180 obj_ptr, method_ptr));
1186 template <
typename A>
1198 template <
typename T>
1205 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
TypeWithSize< 8 >::Int Int64
internal::Function< F >::Result Result
static Result Perform(const ArgumentTuple &)
virtual Result Perform(const ArgumentTuple &args)
internal::Function< F >::ArgumentTuple ArgumentTuple
internal::IgnoredValue Unused
static void SetFactory(FactoryFunction factory)
PolymorphicAction< internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage< T >::value > > SetArgumentPointee(const T &x)
internal::Function< F1 >::ArgumentTuple ArgumentTuple
AssignAction(T1 *ptr, T2 value)
Function< F >::Result Result
PolymorphicAction< Impl > MakePolymorphicAction(const Impl &impl)
PolymorphicAction(const Impl &impl)
DoBothAction(Action1 action1, Action2 action2)
#define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value)
IgnoreResultAction(const A &action)
InvokeMethodWithoutArgsAction(Class *obj_ptr, MethodPtr method_ptr)
TypeWithSize< 8 >::UInt UInt64
virtual Result Perform(const ArgumentTuple &args)
Function< F >::MakeResultVoid VoidResult
#define GTEST_COMPILE_ASSERT_(expr, msg)
void Perform(const ArgumentTuple &args) const
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
virtual Result Perform(const ArgumentTuple &)
internal::ReturnRefAction< R > ReturnRef(R &x)
Function< F >::ArgumentTuple ArgumentTuple
static void Perform(const ArgumentTuple &)
Function< F >::Result Result
internal::ByMoveWrapper< R > ByMove(R x)
Function< F >::ArgumentTuple ArgumentTuple
FixedValueProducer(T value)
Function< F >::ArgumentTuple ArgumentTuple
internal::Function< F >::MakeResultIgnoredValue OriginalFunction
#define GTEST_DISALLOW_ASSIGN_(type)
virtual Result Perform(const ArgumentTuple &)
internal::Function< F >::ArgumentTuple ArgumentTuple
boost::variant< DeliverAppData, WriteToSocket, ReportHandshakeSuccess, ReportEarlyHandshakeSuccess, ReportEarlyWriteFailed, ReportError, MutateState, WaitForData, NewCachedPsk > Action
Action< F > MakeAction(ActionInterface< F > *impl)
virtual void Perform(const ArgumentTuple &args)
virtual Result Perform(const ArgumentTuple &)
Action(ActionInterface< F > *impl)
virtual ~ActionInterface()
Impl(const linked_ptr< R > &wrapper)
PolymorphicAction< internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage< T >::value > > SetArgPointee(const T &x)
FactoryValueProducer(FactoryFunction factory)
Function< F >::ArgumentTuple ArgumentTuple
InvokeWithoutArgsAction(FunctionImpl function_impl)
Function< F >::Result Result
#define GTEST_CHECK_(condition)
Impl(const Action< VoidResult > &action1, const Action< F > &action2)
ReferenceWrapper(T &l_value)
SetErrnoAndReturnAction(int errno_value, T result)
virtual Result Perform(const ArgumentTuple &)
internal::Function< F >::Result Result
ReturnRefOfCopyAction(const T &value)
static const char *const value
internal::Function< F >::ArgumentTuple ArgumentTuple
internal::Function< F >::Result Result
void Perform(const ArgumentTuple &args) const
internal::Function< F1 >::Result Result
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
PolymorphicAction< internal::ReturnNullAction > ReturnNull()
internal::Function< F >::ArgumentTuple ArgumentTuple
const T & move(const T &t)
internal::DoDefaultAction DoDefault()
void Assert(bool condition, const char *file, int line)
Result Perform(const ArgumentTuple &args) const
Function< F >::Result Result
ActionAdaptor(const Action< F2 > &from)
Function< F >::ArgumentTuple ArgumentTuple
Result Perform(const ArgumentTuple &) const
MonomorphicImpl(const Impl &impl)
internal::ReferenceWrapper< T > ByRef(T &l_value)
Result Perform(const ArgumentTuple &)
virtual Result Perform(const ArgumentTuple &args)
Result Perform(const ArgumentTuple &) const
PolymorphicAction< internal::AssignAction< T1, T2 > > Assign(T1 *ptr, T2 val)
internal::Function< F >::Result Result
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
void Perform(const ArgumentTuple &) const
internal::IgnoreResultAction< A > IgnoreResult(const A &an_action)
PolymorphicAction< internal::SetErrnoAndReturnAction< T > > SetErrnoAndReturn(int errval, T result)
static void Print(const T &value,::std::ostream *os)
SetArgumentPointeeAction(const A &value)
Action(const Action &action)
internal::ReturnRefOfCopyAction< R > ReturnRefOfCopy(const R &x)
void PrintTo(const ReferenceWrapper< T > &ref,::std::ostream *os)
Impl(const linked_ptr< R > &value)
internal::ReturnAction< R > Return(R value)
SetArgumentPointeeAction(const Proto &proto)
Function< F >::Result Result