37 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 38 #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ 48 #include <type_traits> 55 # pragma warning(push) 56 # pragma warning(disable:4100) 77 template <
typename T,
bool kDefaultConstructible>
79 static T
Get() {
return T(); }
84 Assert(
false, __FILE__, __LINE__,
85 "Default action undefined for the function return type.");
86 return internal::Invalid<T>();
115 template <
typename T>
124 template <
typename T>
128 static T*
Get() {
return nullptr; }
133 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \ 135 class BuiltInDefaultValue<type> { \ 137 static bool Exists() { return true; } \ 138 static type Get() { return value; } \ 154 #if GMOCK_WCHAR_T_IS_NATIVE_ 169 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_ 186 template <
typename T>
193 producer_ =
new FixedValueProducer(x);
199 typedef T (*FactoryFunction)();
202 producer_ =
new FactoryValueProducer(factory);
212 static bool IsSet() {
return producer_ !=
nullptr; }
225 : producer_->Produce();
229 class ValueProducer {
231 virtual ~ValueProducer() {}
232 virtual T Produce() = 0;
235 class FixedValueProducer :
public ValueProducer {
237 explicit FixedValueProducer(T
value) : value_(value) {}
238 T Produce()
override {
return value_; }
245 class FactoryValueProducer :
public ValueProducer {
247 explicit FactoryValueProducer(FactoryFunction factory)
248 : factory_(factory) {}
249 T Produce()
override {
return factory_(); }
252 const FactoryFunction factory_;
256 static ValueProducer* producer_;
261 template <
typename T>
270 static void Clear() { address_ =
nullptr; }
273 static bool IsSet() {
return address_ !=
nullptr; }
303 template <
typename T>
307 template <
typename T>
311 template <
typename F>
324 virtual Result Perform(
const ArgumentTuple& args) = 0;
337 template <
typename F>
341 struct ActionAdapter {
343 ::std::shared_ptr<ActionInterface<F>> impl_;
345 template <
typename... Args>
347 return impl_->Perform(
348 ::std::forward_as_tuple(::std::forward<Args>(args)...));
363 template <
typename G,
364 typename = typename ::std::enable_if<
365 ::std::is_constructible<::std::function<F>, G>
::value>
::type>
370 : fun_(ActionAdapter{::std::shared_ptr<ActionInterface<F>>(impl)}) {}
375 template <
typename Func>
395 template <
typename G>
399 ::std::function<F> fun_;
423 template <
typename Impl>
428 template <
typename F>
430 return Action<F>(
new MonomorphicImpl<F>(impl_));
434 template <
typename F>
440 explicit MonomorphicImpl(
const Impl& impl) : impl_(impl) {}
442 Result Perform(
const ArgumentTuple& args)
override {
443 return impl_.template Perform<Result>(args);
459 template <
typename F>
471 template <
typename Impl>
480 template <
typename T>
513 template <
typename R>
523 template <
typename F>
536 use_ReturnRef_instead_of_Return_to_return_a_reference);
538 "Can't use Return() on an action expected to return `void`.");
539 return Action<F>(
new Impl<R, F>(value_));
544 template <
typename R_,
typename F>
557 explicit Impl(
const std::shared_ptr<R>&
value)
558 : value_before_cast_(*value),
559 value_(ImplicitCast_<Result>(value_before_cast_)) {}
561 Result Perform(
const ArgumentTuple&)
override {
return value_; }
565 Result_cannot_be_a_reference_type);
568 R value_before_cast_;
576 template <
typename R_,
typename F>
582 explicit Impl(
const std::shared_ptr<R>& wrapper)
583 : performed_(
false), wrapper_(wrapper) {}
585 Result Perform(
const ArgumentTuple&)
override {
587 <<
"A ByMove() action should only be performed once.";
589 return std::move(wrapper_->payload);
594 const std::shared_ptr<R> wrapper_;
599 const std::shared_ptr<R> value_;
610 template <
typename Result,
typename ArgumentTuple>
620 template <
typename Result,
typename ArgumentTuple>
629 template <
typename T>
637 template <
typename F>
644 use_Return_instead_of_ReturnRef_to_return_a_value);
650 template <
typename F>
656 explicit Impl(T& ref) : ref_(ref) {}
658 Result Perform(
const ArgumentTuple&)
override {
return ref_; }
674 template <
typename T>
683 template <
typename F>
691 use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
697 template <
typename F>
703 explicit Impl(
const T&
value) : value_(value) {}
705 Result Perform(
const ArgumentTuple&)
override {
return value_; }
723 template <
typename F>
729 template <
typename T1,
typename T2>
734 template <
typename Result,
typename ArgumentTuple>
746 #if !GTEST_OS_WINDOWS_MOBILE 750 template <
typename T>
754 : errno_(errno_value),
756 template <
typename Result,
typename ArgumentTuple>
769 #endif // !GTEST_OS_WINDOWS_MOBILE 773 template <
size_t N,
typename A,
typename =
void>
777 template <
typename... Args>
779 *::std::get<N>(std::tie(args...)) = value;
784 template <
class Class,
typename MethodPtr>
789 template <
typename... Args>
791 -> decltype((obj_ptr->*method_ptr)(
std::forward<Args>(args)...)) {
792 return (obj_ptr->*method_ptr)(std::forward<Args>(args)...);
800 template <
typename FunctionImpl>
806 template <
typename... Args>
807 auto operator()(
const Args&...) -> decltype(function_impl()) {
808 return function_impl();
813 template <
class Class,
typename MethodPtr>
820 template <
typename... Args>
822 return (obj_ptr->*method_ptr)();
827 template <
typename A>
832 template <
typename F>
851 template <
typename F>
857 explicit Impl(
const A&
action) : action_(action) {}
859 void Perform(
const ArgumentTuple& args)
override {
861 action_.Perform(args);
880 template <
typename InnerAction,
size_t... I>
886 template <
typename R,
typename... Args>
888 Action<R(
typename std::tuple_element<I, std::tuple<Args...>>::
type...)>
891 return [converted](Args... args) -> R {
892 return converted.
Perform(std::forward_as_tuple(
893 std::get<I>(std::forward_as_tuple(std::forward<Args>(args)...))...));
898 template <
typename... Actions>
901 template <
typename... Args,
size_t... I>
903 return {std::get<I>(actions)...};
909 template <
typename R,
typename... Args>
912 std::vector<
Action<void(Args...)>> converted;
914 R operator()(Args... args)
const {
915 auto tuple_args = std::forward_as_tuple(std::forward<Args>(args)...);
916 for (
auto& a : converted) {
917 a.Perform(tuple_args);
919 return last.
Perform(tuple_args);
923 std::get<
sizeof...(Actions) - 1>(actions)};
963 template <
typename...
Action>
966 return {std::forward_as_tuple(std::forward<Action>(
action)...)};
974 template <
size_t k,
typename InnerAction>
977 return {std::forward<InnerAction>(
action)};
984 template <
size_t k,
size_t... ks,
typename InnerAction>
985 internal::WithArgsAction<typename std::decay<InnerAction>::type, k, ks...>
987 return {std::forward<InnerAction>(
action)};
994 template <
typename InnerAction>
995 internal::WithArgsAction<typename std::decay<InnerAction>::type>
997 return {std::forward<InnerAction>(
action)};
1003 template <
typename R>
1019 template <
typename R>
1027 template <
typename R>
1036 template <
typename R>
1048 template <
size_t N,
typename T>
1050 return {std::move(x)};
1054 template <
size_t N,
typename T>
1056 return {std::move(x)};
1060 template <
typename T1,
typename T2>
1065 #if !GTEST_OS_WINDOWS_MOBILE 1068 template <
typename T>
1075 #endif // !GTEST_OS_WINDOWS_MOBILE 1083 template <
typename FunctionImpl>
1085 return std::forward<FunctionImpl>(function_impl);
1090 template <
class Class,
typename MethodPtr>
1092 MethodPtr method_ptr) {
1093 return {obj_ptr, method_ptr};
1097 template <
typename FunctionImpl>
1100 return {std::move(function_impl)};
1105 template <
class Class,
typename MethodPtr>
1107 Class* obj_ptr, MethodPtr method_ptr) {
1108 return {obj_ptr, method_ptr};
1114 template <
typename A>
1129 template <
typename T>
1130 inline ::std::reference_wrapper<T>
ByRef(T& l_value) {
1131 return ::std::reference_wrapper<T>(l_value);
1137 # pragma warning(pop) 1141 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ auto Apply(F &&f, Tuple &&args) -> decltype(ApplyImpl(std::forward< F >(f), std::forward< Tuple >(args), make_int_pack< std::tuple_size< Tuple >::value >()))
Definition: gmock-internal-utils.h:525
static Result Perform(const ArgumentTuple &)
Definition: gmock-actions.h:611
Definition: gmock-actions.h:78
PolymorphicAction< internal::ReturnNullAction > ReturnNull()
Definition: gmock-actions.h:1009
ByMoveWrapper(T value)
Definition: gmock-actions.h:482
Definition: gmock-actions.h:59
internal::IgnoredValue Unused
Definition: gmock-actions.h:959
static bool Exists()
Definition: gmock-actions.h:118
static T * Get()
Definition: gmock-actions.h:128
static bool Exists()
Definition: gmock-actions.h:103
GTEST_API_ void IllegalDoDefault(const char *file, int line)
Definition: gmock-internal-utils.cc:189
static void SetFactory(FactoryFunction factory)
Definition: gmock-actions.h:200
PolymorphicAction< internal::AssignAction< T1, T2 > > Assign(T1 *ptr, T2 val)
Definition: gmock-actions.h:1061
const MethodPtr method_ptr
Definition: gmock-actions.h:787
static void Set(T x)
Definition: gmock-actions.h:191
AssignAction(T1 *ptr, T2 value)
Definition: gmock-actions.h:732
Action(const Action< Func > &action)
Definition: gmock-actions.h:376
PolymorphicAction(const Impl &impl)
Definition: gmock-actions.h:426
internal::DoAllAction< typename std::decay< Action >::type... > DoAll(Action &&...action)
Definition: gmock-actions.h:964
IgnoreResultAction(const A &action)
Definition: gmock-actions.h:830
static void Set(T &x)
Definition: gmock-actions.h:265
Definition: gmock-actions.h:814
ReturnType operator()(const Args &...) const
Definition: gmock-actions.h:821
static T Get()
Definition: gmock-actions.h:107
Definition: gtest-internal.h:853
std::tuple< Actions... > actions
Definition: gmock-actions.h:907
internal::InvokeWithoutArgsAction< typename std::decay< FunctionImpl >::type > InvokeWithoutArgs(FunctionImpl function_impl)
Definition: gmock-actions.h:1099
auto operator()(Args &&...args) const -> decltype((obj_ptr-> *method_ptr)(std::forward< Args >(args)...))
Definition: gmock-actions.h:790
static void Get()
Definition: gmock-actions.h:299
Definition: gmock-actions.h:630
internal::WithArgsAction< typename std::decay< InnerAction >::type, k, ks... > WithArgs(InnerAction &&action)
Definition: gmock-actions.h:986
static void Perform(const ArgumentTuple &)
Definition: gmock-actions.h:621
usr bin c fPIC pthread std
Definition: link.txt:1
static bool IsSet()
Definition: gmock-actions.h:212
PolymorphicAction< Impl > MakePolymorphicAction(const Impl &impl)
Definition: gmock-actions.h:472
#define GTEST_DISALLOW_ASSIGN_(type)
Definition: gtest-port.h:683
static T Get()
Definition: gmock-actions.h:79
inline::std::reference_wrapper< T > ByRef(T &l_value)
Definition: gmock-actions.h:1130
PolymorphicAction< internal::SetErrnoAndReturnAction< T > > SetErrnoAndReturn(int errval, T result)
Definition: gmock-actions.h:1070
Definition: gmock-actions.h:514
internal::ReturnRefAction< R > ReturnRef(R &x)
Definition: gmock-actions.h:1020
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
Definition: gmock-actions.h:1084
void operator()(const Args &...args) const
Definition: gmock-actions.h:778
Definition: gmock-actions.h:187
Definition: gmock-actions.h:338
const MethodPtr method_ptr
Definition: gmock-actions.h:816
static bool Exists()
Definition: gmock-actions.h:127
static T Get()
Definition: gmock-actions.h:119
internal::SetArgumentPointeeAction< N, T > SetArgPointee(T x)
Definition: gmock-actions.h:1049
Definition: gmock-actions.h:774
Action(ActionInterface< F > *impl)
Definition: gmock-actions.h:369
#define GTEST_COMPILE_ASSERT_(expr, msg)
Definition: gtest-port.h:859
virtual ~ActionInterface()
Definition: gmock-actions.h:318
static T & Get()
Definition: gmock-actions.h:284
Definition: gmock-actions.h:719
static bool Exists()
Definition: gmock-actions.h:216
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:1014
internal::WithArgsAction< typename std::decay< InnerAction >::type > WithoutArgs(InnerAction &&action)
Definition: gmock-actions.h:996
internal::ReturnRefOfCopyAction< R > ReturnRefOfCopy(const R &x)
Definition: gmock-actions.h:1028
Definition: gmock-actions.h:605
Definition: gmock-actions.h:801
SetErrnoAndReturnAction(int errno_value, T result)
Definition: gmock-actions.h:753
FunctionImpl function_impl
Definition: gmock-actions.h:802
Class *const obj_ptr
Definition: gmock-actions.h:815
static bool Exists()
Definition: gmock-actions.h:277
Definition: gtest-internal.h:1172
Class *const obj_ptr
Definition: gmock-actions.h:786
internal::SetArgumentPointeeAction< N, T > SetArgumentPointee(T x)
Definition: gmock-actions.h:1055
Definition: gmock-internal-utils.h:356
Definition: gmock-actions.h:312
Definition: gtest-internal.h:1153
ReturnRefOfCopyAction(const T &value)
Definition: gmock-actions.h:679
internal::Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:354
Definition: gmock-actions.h:881
Definition: gmock-actions.h:730
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void,)
internal::Function< F >::Result Result
Definition: gmock-actions.h:314
Definition: gmock-actions.h:828
bool IsDoDefault() const
Definition: gmock-actions.h:379
InnerAction action
Definition: gmock-actions.h:882
int value
Definition: gmock-matchers_test.cc:657
T payload
Definition: gmock-actions.h:483
Definition: gmock-actions.h:617
internal::Function< F >::ArgumentTuple ArgumentTuple
Definition: gmock-actions.h:315
static void Clear()
Definition: gmock-actions.h:270
Definition: gmock-actions.h:751
Definition: gmock-actions.h:424
auto operator()(const Args &...) -> decltype(function_impl())
Definition: gmock-actions.h:807
internal::DoDefaultAction DoDefault()
Definition: gmock-actions.h:1042
internal::ReturnAction< R > Return(R value)
Definition: gmock-actions.h:1004
int x
Definition: gmock-matchers_test.cc:3610
void Assert(bool condition, const char *file, int line)
Definition: gmock-internal-utils.h:292
Definition: gmock-actions.h:481
type
Definition: upload.py:443
Definition: gmock-internal-utils.h:546
const
Definition: upload.py:398
Result Perform(const ArgumentTuple &) const
Definition: gmock-actions.h:757
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:688
internal::ByMoveWrapper< R > ByMove(R x)
Definition: gmock-actions.h:1037
TypeWithSize< 8 >::UInt UInt64
Definition: gtest-port.h:2219
internal::WithArgsAction< typename std::decay< InnerAction >::type, k > WithArg(InnerAction &&action)
Definition: gmock-actions.h:976
static bool IsSet()
Definition: gmock-actions.h:273
static void Clear()
Definition: gmock-actions.h:206
Definition: gmock-actions.h:899
internal::Function< F >::Result Result
Definition: gmock-actions.h:353
ReturnRefAction(T &ref)
Definition: gmock-actions.h:633
void Perform(const ArgumentTuple &) const
Definition: gmock-actions.h:735
ReturnAction(R value)
Definition: gmock-actions.h:519
internal::IgnoreResultAction< A > IgnoreResult(const A &an_action)
Definition: gmock-actions.h:1115
TypeWithSize< 8 >::Int Int64
Definition: gtest-port.h:2218
Definition: gmock-actions.h:100
A value
Definition: gmock-actions.h:775
Definition: gmock-actions.h:675
static T Get()
Definition: gmock-actions.h:83
Action()
Definition: gmock-actions.h:358
Result Perform(ArgumentTuple args) const
Definition: gmock-actions.h:387
Definition: gmock-actions.h:785
ActionInterface()
Definition: gmock-actions.h:317
typename std::result_of< MethodPtr(Class *)>::type ReturnType
Definition: gmock-actions.h:818
Action(G &&fun)
Definition: gmock-actions.h:366
static bool Exists()
Definition: gmock-actions.h:298
static T Get()
Definition: gmock-actions.h:223
Action< F > MakeAction(ActionInterface< F > *impl)
Definition: gmock-actions.h:460
Definition: gtest-internal.h:110
action
Definition: upload.py:393