36 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 37 #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 64 template <
typename F1,
typename F2>
73 class BuiltInDefaultValue
77 static bool Exists() {
return false; }
80 Assert(
false, __FILE__, __LINE__,
81 "Default action undefined for the function return type.");
82 return internal::Invalid<T>();
100 template <
typename T>
105 static T *
Get() {
return NULL; }
110 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \ 112 class BuiltInDefaultValue<type> { \ 114 static bool Exists() { return true; } \ 115 static type Get() { return value; } \ 119 #if GTEST_HAS_GLOBAL_STRING 121 #endif // GTEST_HAS_GLOBAL_STRING 134 #if GMOCK_WCHAR_T_IS_NATIVE_ 149 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_ 166 template <
typename T>
186 static bool IsSet() {
return value_ != NULL; }
200 return value_ == NULL ?
205 static const T * value_;
210 template <
typename T>
227 static bool IsSet() {
return address_ != NULL; }
241 return address_ == NULL ?
260 template <
typename T>
264 template <
typename T>
268 template <
typename F>
282 virtual Result Perform(
const ArgumentTuple & args) = 0;
297 template <
typename F>
319 template <
typename Func>
331 Result
Perform(
const ArgumentTuple & args)
const 334 !IsDoDefault(), __FILE__, __LINE__,
335 "You are using DoDefault() inside a composite action like " 336 "DoAll() or WithArgs(). This is not supported for technical " 337 "reasons. Please instead spell out the default action, or " 338 "assign the default action to an Action variable and use " 339 "the variable in various places.");
340 return impl_->Perform(args);
344 template <
typename F1,
typename F2>
371 template <
typename Impl>
377 template <
typename F>
384 template <
typename F>
393 virtual Result
Perform(
const ArgumentTuple & args)
395 return impl_.template Perform<Result>(args);
411 template <
typename F>
424 template <
typename Impl>
435 template <
typename F1,
typename F2>
444 virtual Result
Perform(
const ArgumentTuple & args)
446 return impl_->Perform(args);
479 template <
typename R>
490 template <
typename F>
504 use_ReturnRef_instead_of_Return_to_return_a_reference);
510 template <
typename F>
527 virtual Result
Perform(
const ArgumentTuple &) {
return value_; }
531 Result_cannot_be_a_reference_type);
547 template <
typename Result,
typename ArgumentTuple>
551 ReturnNull_can_be_used_to_return_a_pointer_only);
561 template <
typename Result,
typename ArgumentTuple>
571 template <
typename T>
580 template <
typename F>
588 use_Return_instead_of_ReturnRef_to_return_a_value);
594 template <
typename F>
601 explicit Impl(T & ref) : ref_(ref) {}
622 template <
typename T>
632 template <
typename F>
641 use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
647 template <
typename F>
654 explicit Impl(
const T & value) : value_(value) {}
678 template <
typename F>
684 template <
typename T1,
typename T2>
690 template <
typename Result,
typename ArgumentTuple>
703 #if !GTEST_OS_WINDOWS_MOBILE 707 template <
typename T>
712 : errno_(errno_value),
714 template <
typename Result,
typename ArgumentTuple>
728 #endif // !GTEST_OS_WINDOWS_MOBILE 734 template <
size_t N,
typename A,
bool kIsProto>
742 template <
typename Result,
typename ArgumentTuple>
743 void Perform(
const ArgumentTuple & args)
const 746 *::std::tr1::get<N>(args) = value_;
755 template <
size_t N,
typename Proto>
765 proto_->CopyFrom(proto);
768 template <
typename Result,
typename ArgumentTuple>
769 void Perform(
const ArgumentTuple & args)
const 772 ::std::tr1::get<N>(args)->CopyFrom(*proto_);
786 template <
typename FunctionImpl>
793 : function_impl_(function_impl) {}
797 template <
typename Result,
typename ArgumentTuple>
798 Result
Perform(
const ArgumentTuple &) {
return function_impl_(); }
801 FunctionImpl function_impl_;
807 template <
class Class,
typename MethodPtr>
812 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
814 template <
typename Result,
typename ArgumentTuple>
817 return (obj_ptr_->*method_ptr_)();
821 Class *
const obj_ptr_;
822 const MethodPtr method_ptr_;
828 template <
typename A>
834 template <
typename F>
854 template <
typename F>
861 explicit Impl(
const A & action) : action_(action) {}
863 virtual void Perform(
const ArgumentTuple & args)
866 action_.Perform(args);
892 template <
typename T>
901 operator T & ()
const {
return *pointer_; }
907 template <
typename T>
916 template <
typename Action1,
typename Action2>
921 : action1_(action1), action2_(action2) {}
925 template <
typename F>
933 template <
typename F>
942 : action1_(action1), action2_(action2) {}
944 virtual Result
Perform(
const ArgumentTuple & args)
946 action1_.Perform(args);
947 return action2_.Perform(args);
1001 template <
typename To>
1002 template <
typename From>
1009 template <
typename R>
1028 template <
typename R>
1037 template <
typename R>
1051 template <
size_t N,
typename T>
1061 #if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) 1071 N,
const char *,
false > (p));
1080 N,
const wchar_t *,
false > (p));
1085 template <
size_t N,
typename T>
1096 template <
typename T1,
typename T2>
1102 #if !GTEST_OS_WINDOWS_MOBILE 1105 template <
typename T>
1113 #endif // !GTEST_OS_WINDOWS_MOBILE 1118 template <
typename FunctionImpl>
1128 template <
class Class,
typename MethodPtr>
1134 obj_ptr, method_ptr));
1140 template <
typename A>
1153 template <
typename T>
1161 #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)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
internal::Function< F >::ArgumentTuple ArgumentTuple
internal::IgnoredValue Unused
virtual Result Perform(const ArgumentTuple &)
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)
IgnoreResultAction(const A &action)
InvokeMethodWithoutArgsAction(Class *obj_ptr, MethodPtr method_ptr)
TypeWithSize< 8 >::UInt UInt64
virtual Result Perform(const ArgumentTuple &args)
#define GTEST_COMPILE_ASSERT_(expr, msg)
Function< F >::MakeResultVoid VoidResult
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 >::ArgumentTuple ArgumentTuple
Function< F >::ArgumentTuple ArgumentTuple
internal::Function< F >::MakeResultIgnoredValue OriginalFunction
internal::Function< F >::ArgumentTuple ArgumentTuple
Action< F > MakeAction(ActionInterface< F > *impl)
virtual void Perform(const ArgumentTuple &args)
virtual Result Perform(const ArgumentTuple &)
Action(ActionInterface< F > *impl)
virtual ~ActionInterface()
PolymorphicAction< internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage< T >::value > > SetArgPointee(const T &x)
InvokeWithoutArgsAction(FunctionImpl function_impl)
Impl(const Action< VoidResult > &action1, const Action< F > &action2)
ReferenceWrapper(T &l_value)
SetErrnoAndReturnAction(int errno_value, T result)
Function< F >::Result Result
#define GTEST_DISALLOW_ASSIGN_(type)
internal::Function< F >::Result Result
ReturnRefOfCopyAction(const T &value)
internal::Function< F >::ArgumentTuple ArgumentTuple
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void,)
internal::Function< F >::Result Result
void Perform(const ArgumentTuple &args) const
internal::Function< F1 >::Result Result
PolymorphicAction< internal::ReturnNullAction > ReturnNull()
internal::Function< F >::ArgumentTuple ArgumentTuple
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)
Result Perform(const ArgumentTuple &) const
Function< F >::ArgumentTuple ArgumentTuple
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
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)
internal::ReturnAction< R > Return(R value)
SetArgumentPointeeAction(const Proto &proto)
Function< F >::Result Result