123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263 |
- #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
- #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
- #ifndef _WIN32_WCE
- # include <errno.h>
- #endif
- #include <algorithm>
- #include <string>
- #include "gmock/internal/gmock-internal-utils.h"
- #include "gmock/internal/gmock-port.h"
- #if GTEST_LANG_CXX11
- #include <functional>
- #include <type_traits>
- #endif
- namespace testing {
- namespace internal {
- template <typename F1, typename F2>
- class ActionAdaptor;
- template <typename T, bool kDefaultConstructible>
- struct BuiltInDefaultValueGetter {
- static T Get() { return T(); }
- };
- template <typename T>
- struct BuiltInDefaultValueGetter<T, false> {
- static T Get() {
- Assert(false, __FILE__, __LINE__,
- "Default action undefined for the function return type.");
- return internal::Invalid<T>();
-
-
- }
- };
- template <typename T>
- class BuiltInDefaultValue {
- public:
- #if GTEST_LANG_CXX11
-
- static bool Exists() {
- return ::std::is_default_constructible<T>::value;
- }
- static T Get() {
- return BuiltInDefaultValueGetter<
- T, ::std::is_default_constructible<T>::value>::Get();
- }
- #else
-
- static bool Exists() {
- return false;
- }
- static T Get() {
- return BuiltInDefaultValueGetter<T, false>::Get();
- }
- #endif
- };
- template <typename T>
- class BuiltInDefaultValue<const T> {
- public:
- static bool Exists() { return BuiltInDefaultValue<T>::Exists(); }
- static T Get() { return BuiltInDefaultValue<T>::Get(); }
- };
- template <typename T>
- class BuiltInDefaultValue<T*> {
- public:
- static bool Exists() { return true; }
- static T* Get() { return NULL; }
- };
- #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
- template <> \
- class BuiltInDefaultValue<type> { \
- public: \
- static bool Exists() { return true; } \
- static type Get() { return value; } \
- }
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, );
- #if GTEST_HAS_GLOBAL_STRING
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, "");
- #endif
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
- #if GMOCK_WCHAR_T_IS_NATIVE_
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U);
- #endif
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U);
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0);
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL);
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L);
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
- #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
- }
- template <typename T>
- class DefaultValue {
- public:
-
-
- static void Set(T x) {
- delete producer_;
- producer_ = new FixedValueProducer(x);
- }
-
-
-
- typedef T (*FactoryFunction)();
- static void SetFactory(FactoryFunction factory) {
- delete producer_;
- producer_ = new FactoryValueProducer(factory);
- }
-
- static void Clear() {
- delete producer_;
- producer_ = NULL;
- }
-
- static bool IsSet() { return producer_ != NULL; }
-
-
- static bool Exists() {
- return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
- }
-
-
-
- static T Get() {
- return producer_ == NULL ?
- internal::BuiltInDefaultValue<T>::Get() : producer_->Produce();
- }
- private:
- class ValueProducer {
- public:
- virtual ~ValueProducer() {}
- virtual T Produce() = 0;
- };
- class FixedValueProducer : public ValueProducer {
- public:
- explicit FixedValueProducer(T value) : value_(value) {}
- virtual T Produce() { return value_; }
- private:
- const T value_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer);
- };
- class FactoryValueProducer : public ValueProducer {
- public:
- explicit FactoryValueProducer(FactoryFunction factory)
- : factory_(factory) {}
- virtual T Produce() { return factory_(); }
- private:
- const FactoryFunction factory_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer);
- };
- static ValueProducer* producer_;
- };
- template <typename T>
- class DefaultValue<T&> {
- public:
-
- static void Set(T& x) {
- address_ = &x;
- }
-
- static void Clear() {
- address_ = NULL;
- }
-
- static bool IsSet() { return address_ != NULL; }
-
-
- static bool Exists() {
- return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
- }
-
-
-
- static T& Get() {
- return address_ == NULL ?
- internal::BuiltInDefaultValue<T&>::Get() : *address_;
- }
- private:
- static T* address_;
- };
- template <>
- class DefaultValue<void> {
- public:
- static bool Exists() { return true; }
- static void Get() {}
- };
- template <typename T>
- typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = NULL;
- template <typename T>
- T* DefaultValue<T&>::address_ = NULL;
- template <typename F>
- class ActionInterface {
- public:
- typedef typename internal::Function<F>::Result Result;
- typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
- ActionInterface() {}
- virtual ~ActionInterface() {}
-
-
-
-
- virtual Result Perform(const ArgumentTuple& args) = 0;
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
- };
- template <typename F>
- class Action {
- public:
- typedef typename internal::Function<F>::Result Result;
- typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
-
-
- Action() {}
- #if GTEST_LANG_CXX11
-
-
-
- template <typename G,
- typename = typename ::std::enable_if<
- ::std::is_constructible<::std::function<F>, G>::value>::type>
- Action(G&& fun) : fun_(::std::forward<G>(fun)) {}
- #endif
-
- explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
-
-
-
-
- template <typename Func>
- explicit Action(const Action<Func>& action);
-
- bool IsDoDefault() const {
- #if GTEST_LANG_CXX11
- return impl_ == nullptr && fun_ == nullptr;
- #else
- return impl_ == NULL;
- #endif
- }
-
-
-
-
-
-
- Result Perform(ArgumentTuple args) const {
- if (IsDoDefault()) {
- internal::IllegalDoDefault(__FILE__, __LINE__);
- }
- #if GTEST_LANG_CXX11
- if (fun_ != nullptr) {
- return internal::Apply(fun_, ::std::move(args));
- }
- #endif
- return impl_->Perform(args);
- }
- private:
- template <typename F1, typename F2>
- friend class internal::ActionAdaptor;
- template <typename G>
- friend class Action;
-
-
-
-
-
-
- #if GTEST_LANG_CXX11
- ::std::function<F> fun_;
- #endif
- internal::linked_ptr<ActionInterface<F> > impl_;
- };
- template <typename Impl>
- class PolymorphicAction {
- public:
- explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
- template <typename F>
- operator Action<F>() const {
- return Action<F>(new MonomorphicImpl<F>(impl_));
- }
- private:
- template <typename F>
- class MonomorphicImpl : public ActionInterface<F> {
- public:
- typedef typename internal::Function<F>::Result Result;
- typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
- explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
- virtual Result Perform(const ArgumentTuple& args) {
- return impl_.template Perform<Result>(args);
- }
- private:
- Impl impl_;
- GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
- };
- Impl impl_;
- GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
- };
- template <typename F>
- Action<F> MakeAction(ActionInterface<F>* impl) {
- return Action<F>(impl);
- }
- template <typename Impl>
- inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
- return PolymorphicAction<Impl>(impl);
- }
- namespace internal {
- template <typename F1, typename F2>
- class ActionAdaptor : public ActionInterface<F1> {
- public:
- typedef typename internal::Function<F1>::Result Result;
- typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple;
- explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {}
- virtual Result Perform(const ArgumentTuple& args) {
- return impl_->Perform(args);
- }
- private:
- const internal::linked_ptr<ActionInterface<F2> > impl_;
- GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
- };
- template <typename T>
- struct ByMoveWrapper {
- explicit ByMoveWrapper(T value) : payload(internal::move(value)) {}
- T payload;
- };
- template <typename R>
- class ReturnAction {
- public:
-
-
-
- explicit ReturnAction(R value) : value_(new R(internal::move(value))) {}
-
-
- template <typename F>
- operator Action<F>() const {
-
-
-
-
-
-
-
-
- typedef typename Function<F>::Result Result;
- GTEST_COMPILE_ASSERT_(
- !is_reference<Result>::value,
- use_ReturnRef_instead_of_Return_to_return_a_reference);
- return Action<F>(new Impl<R, F>(value_));
- }
- private:
-
- template <typename R_, typename F>
- class Impl : public ActionInterface<F> {
- public:
- typedef typename Function<F>::Result Result;
- typedef typename Function<F>::ArgumentTuple ArgumentTuple;
-
-
-
-
-
-
-
- explicit Impl(const linked_ptr<R>& value)
- : value_before_cast_(*value),
- value_(ImplicitCast_<Result>(value_before_cast_)) {}
- virtual Result Perform(const ArgumentTuple&) { return value_; }
- private:
- GTEST_COMPILE_ASSERT_(!is_reference<Result>::value,
- Result_cannot_be_a_reference_type);
-
-
- R value_before_cast_;
- Result value_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
- };
-
-
- template <typename R_, typename F>
- class Impl<ByMoveWrapper<R_>, F> : public ActionInterface<F> {
- public:
- typedef typename Function<F>::Result Result;
- typedef typename Function<F>::ArgumentTuple ArgumentTuple;
- explicit Impl(const linked_ptr<R>& wrapper)
- : performed_(false), wrapper_(wrapper) {}
- virtual Result Perform(const ArgumentTuple&) {
- GTEST_CHECK_(!performed_)
- << "A ByMove() action should only be performed once.";
- performed_ = true;
- return internal::move(wrapper_->payload);
- }
- private:
- bool performed_;
- const linked_ptr<R> wrapper_;
- GTEST_DISALLOW_ASSIGN_(Impl);
- };
- const linked_ptr<R> value_;
- GTEST_DISALLOW_ASSIGN_(ReturnAction);
- };
- class ReturnNullAction {
- public:
-
-
-
- template <typename Result, typename ArgumentTuple>
- static Result Perform(const ArgumentTuple&) {
- #if GTEST_LANG_CXX11
- return nullptr;
- #else
- GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value,
- ReturnNull_can_be_used_to_return_a_pointer_only);
- return NULL;
- #endif
- }
- };
- class ReturnVoidAction {
- public:
-
- template <typename Result, typename ArgumentTuple>
- static void Perform(const ArgumentTuple&) {
- CompileAssertTypesEqual<void, Result>();
- }
- };
- template <typename T>
- class ReturnRefAction {
- public:
-
- explicit ReturnRefAction(T& ref) : ref_(ref) {}
-
-
- template <typename F>
- operator Action<F>() const {
- typedef typename Function<F>::Result Result;
-
-
-
- GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value,
- use_Return_instead_of_ReturnRef_to_return_a_value);
- return Action<F>(new Impl<F>(ref_));
- }
- private:
-
- template <typename F>
- class Impl : public ActionInterface<F> {
- public:
- typedef typename Function<F>::Result Result;
- typedef typename Function<F>::ArgumentTuple ArgumentTuple;
- explicit Impl(T& ref) : ref_(ref) {}
- virtual Result Perform(const ArgumentTuple&) {
- return ref_;
- }
- private:
- T& ref_;
- GTEST_DISALLOW_ASSIGN_(Impl);
- };
- T& ref_;
- GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
- };
- template <typename T>
- class ReturnRefOfCopyAction {
- public:
-
-
- explicit ReturnRefOfCopyAction(const T& value) : value_(value) {}
-
-
- template <typename F>
- operator Action<F>() const {
- typedef typename Function<F>::Result Result;
-
-
-
- GTEST_COMPILE_ASSERT_(
- internal::is_reference<Result>::value,
- use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
- return Action<F>(new Impl<F>(value_));
- }
- private:
-
- template <typename F>
- class Impl : public ActionInterface<F> {
- public:
- typedef typename Function<F>::Result Result;
- typedef typename Function<F>::ArgumentTuple ArgumentTuple;
- explicit Impl(const T& value) : value_(value) {}
- virtual Result Perform(const ArgumentTuple&) {
- return value_;
- }
- private:
- T value_;
- GTEST_DISALLOW_ASSIGN_(Impl);
- };
- const T value_;
- GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
- };
- class DoDefaultAction {
- public:
-
-
- template <typename F>
- operator Action<F>() const { return Action<F>(); }
- };
- template <typename T1, typename T2>
- class AssignAction {
- public:
- AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
- template <typename Result, typename ArgumentTuple>
- void Perform(const ArgumentTuple& ) const {
- *ptr_ = value_;
- }
- private:
- T1* const ptr_;
- const T2 value_;
- GTEST_DISALLOW_ASSIGN_(AssignAction);
- };
- #if !GTEST_OS_WINDOWS_MOBILE
- template <typename T>
- class SetErrnoAndReturnAction {
- public:
- SetErrnoAndReturnAction(int errno_value, T result)
- : errno_(errno_value),
- result_(result) {}
- template <typename Result, typename ArgumentTuple>
- Result Perform(const ArgumentTuple& ) const {
- errno = errno_;
- return result_;
- }
- private:
- const int errno_;
- const T result_;
- GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
- };
- #endif
- template <size_t N, typename A, bool kIsProto>
- class SetArgumentPointeeAction {
- public:
-
-
- explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
- template <typename Result, typename ArgumentTuple>
- void Perform(const ArgumentTuple& args) const {
- CompileAssertTypesEqual<void, Result>();
- *::testing::get<N>(args) = value_;
- }
- private:
- const A value_;
- GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
- };
- template <size_t N, typename Proto>
- class SetArgumentPointeeAction<N, Proto, true> {
- public:
-
-
-
-
- explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
- proto_->CopyFrom(proto);
- }
- template <typename Result, typename ArgumentTuple>
- void Perform(const ArgumentTuple& args) const {
- CompileAssertTypesEqual<void, Result>();
- ::testing::get<N>(args)->CopyFrom(*proto_);
- }
- private:
- const internal::linked_ptr<Proto> proto_;
- GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
- };
- template <typename FunctionImpl>
- class InvokeWithoutArgsAction {
- public:
-
-
- explicit InvokeWithoutArgsAction(FunctionImpl function_impl)
- : function_impl_(function_impl) {}
-
-
- template <typename Result, typename ArgumentTuple>
- Result Perform(const ArgumentTuple&) { return function_impl_(); }
- private:
- FunctionImpl function_impl_;
- GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction);
- };
- template <class Class, typename MethodPtr>
- class InvokeMethodWithoutArgsAction {
- public:
- InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr)
- : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
- template <typename Result, typename ArgumentTuple>
- Result Perform(const ArgumentTuple&) const {
- return (obj_ptr_->*method_ptr_)();
- }
- private:
- Class* const obj_ptr_;
- const MethodPtr method_ptr_;
- GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
- };
- template <typename CallbackType>
- class InvokeCallbackWithoutArgsAction {
- public:
-
- explicit InvokeCallbackWithoutArgsAction(CallbackType* callback)
- : callback_(callback) {
- callback->CheckIsRepeatable();
- }
-
-
-
- template <typename Result, typename ArgumentTuple>
- Result Perform(const ArgumentTuple&) const { return callback_->Run(); }
- private:
- const internal::linked_ptr<CallbackType> callback_;
- GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction);
- };
- template <typename A>
- class IgnoreResultAction {
- public:
- explicit IgnoreResultAction(const A& action) : action_(action) {}
- template <typename F>
- operator Action<F>() const {
-
-
-
-
-
-
-
-
- typedef typename internal::Function<F>::Result Result;
-
- CompileAssertTypesEqual<void, Result>();
- return Action<F>(new Impl<F>(action_));
- }
- private:
- template <typename F>
- class Impl : public ActionInterface<F> {
- public:
- typedef typename internal::Function<F>::Result Result;
- typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
- explicit Impl(const A& action) : action_(action) {}
- virtual void Perform(const ArgumentTuple& args) {
-
- action_.Perform(args);
- }
- private:
-
-
- typedef typename internal::Function<F>::MakeResultIgnoredValue
- OriginalFunction;
- const Action<OriginalFunction> action_;
- GTEST_DISALLOW_ASSIGN_(Impl);
- };
- const A action_;
- GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
- };
- template <typename T>
- class ReferenceWrapper {
- public:
-
- explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {}
-
-
- operator T&() const { return *pointer_; }
- private:
- T* pointer_;
- };
- template <typename T>
- void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) {
- T& value = ref;
- UniversalPrinter<T&>::Print(value, os);
- }
- template <typename Action1, typename Action2>
- class DoBothAction {
- public:
- DoBothAction(Action1 action1, Action2 action2)
- : action1_(action1), action2_(action2) {}
-
-
- template <typename F>
- operator Action<F>() const {
- return Action<F>(new Impl<F>(action1_, action2_));
- }
- private:
-
- template <typename F>
- class Impl : public ActionInterface<F> {
- public:
- typedef typename Function<F>::Result Result;
- typedef typename Function<F>::ArgumentTuple ArgumentTuple;
- typedef typename Function<F>::MakeResultVoid VoidResult;
- Impl(const Action<VoidResult>& action1, const Action<F>& action2)
- : action1_(action1), action2_(action2) {}
- virtual Result Perform(const ArgumentTuple& args) {
- action1_.Perform(args);
- return action2_.Perform(args);
- }
- private:
- const Action<VoidResult> action1_;
- const Action<F> action2_;
- GTEST_DISALLOW_ASSIGN_(Impl);
- };
- Action1 action1_;
- Action2 action2_;
- GTEST_DISALLOW_ASSIGN_(DoBothAction);
- };
- }
- typedef internal::IgnoredValue Unused;
- template <typename To>
- template <typename From>
- Action<To>::Action(const Action<From>& from)
- :
- #if GTEST_LANG_CXX11
- fun_(from.fun_),
- #endif
- impl_(from.impl_ == NULL ? NULL
- : new internal::ActionAdaptor<To, From>(from)) {
- }
- template <typename R>
- internal::ReturnAction<R> Return(R value) {
- return internal::ReturnAction<R>(internal::move(value));
- }
- inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() {
- return MakePolymorphicAction(internal::ReturnNullAction());
- }
- inline PolymorphicAction<internal::ReturnVoidAction> Return() {
- return MakePolymorphicAction(internal::ReturnVoidAction());
- }
- template <typename R>
- inline internal::ReturnRefAction<R> ReturnRef(R& x) {
- return internal::ReturnRefAction<R>(x);
- }
- template <typename R>
- inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
- return internal::ReturnRefOfCopyAction<R>(x);
- }
- template <typename R>
- internal::ByMoveWrapper<R> ByMove(R x) {
- return internal::ByMoveWrapper<R>(internal::move(x));
- }
- inline internal::DoDefaultAction DoDefault() {
- return internal::DoDefaultAction();
- }
- template <size_t N, typename T>
- PolymorphicAction<
- internal::SetArgumentPointeeAction<
- N, T, internal::IsAProtocolMessage<T>::value> >
- SetArgPointee(const T& x) {
- return MakePolymorphicAction(internal::SetArgumentPointeeAction<
- N, T, internal::IsAProtocolMessage<T>::value>(x));
- }
- #if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN)
- template <size_t N>
- PolymorphicAction<
- internal::SetArgumentPointeeAction<N, const char*, false> >
- SetArgPointee(const char* p) {
- return MakePolymorphicAction(internal::SetArgumentPointeeAction<
- N, const char*, false>(p));
- }
- template <size_t N>
- PolymorphicAction<
- internal::SetArgumentPointeeAction<N, const wchar_t*, false> >
- SetArgPointee(const wchar_t* p) {
- return MakePolymorphicAction(internal::SetArgumentPointeeAction<
- N, const wchar_t*, false>(p));
- }
- #endif
- template <size_t N, typename T>
- PolymorphicAction<
- internal::SetArgumentPointeeAction<
- N, T, internal::IsAProtocolMessage<T>::value> >
- SetArgumentPointee(const T& x) {
- return MakePolymorphicAction(internal::SetArgumentPointeeAction<
- N, T, internal::IsAProtocolMessage<T>::value>(x));
- }
- template <typename T1, typename T2>
- PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) {
- return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
- }
- #if !GTEST_OS_WINDOWS_MOBILE
- template <typename T>
- PolymorphicAction<internal::SetErrnoAndReturnAction<T> >
- SetErrnoAndReturn(int errval, T result) {
- return MakePolymorphicAction(
- internal::SetErrnoAndReturnAction<T>(errval, result));
- }
- #endif
- template <typename FunctionImpl>
- PolymorphicAction<internal::InvokeWithoutArgsAction<FunctionImpl> >
- InvokeWithoutArgs(FunctionImpl function_impl) {
- return MakePolymorphicAction(
- internal::InvokeWithoutArgsAction<FunctionImpl>(function_impl));
- }
- template <class Class, typename MethodPtr>
- PolymorphicAction<internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> >
- InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) {
- return MakePolymorphicAction(
- internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>(
- obj_ptr, method_ptr));
- }
- template <typename A>
- inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
- return internal::IgnoreResultAction<A>(an_action);
- }
- template <typename T>
- inline internal::ReferenceWrapper<T> ByRef(T& l_value) {
- return internal::ReferenceWrapper<T>(l_value);
- }
- }
- #endif
|