123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298 |
- #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
- #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
- #ifndef _WIN32_WCE
- #include <errno.h>
- #endif
- #include <algorithm>
- #include <functional>
- #include <memory>
- #include <string>
- #include <tuple>
- #include <type_traits>
- #include <utility>
- #include "gmock/internal/gmock-internal-utils.h"
- #include "gmock/internal/gmock-port.h"
- #include "gmock/internal/gmock-pp.h"
- #ifdef _MSC_VER
- #pragma warning(push)
- #pragma warning(disable : 4100)
- #endif
- namespace testing {
- namespace internal {
- 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:
-
-
- static bool Exists() { return ::std::is_default_constructible<T>::value; }
- static T Get() {
- return BuiltInDefaultValueGetter<
- T, ::std::is_default_constructible<T>::value>::Get();
- }
- };
- 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 nullptr; }
- };
- #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, );
- 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_(unsigned long long, 0);
- GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long long, 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 P>
- struct negation
-
- : std::integral_constant<bool, bool(!P::value)> {};
- template <typename...>
- struct conjunction : std::true_type {};
- template <typename P1>
- struct conjunction<P1> : P1 {};
- template <typename P1, typename... Ps>
- struct conjunction<P1, Ps...>
- : std::conditional<bool(P1::value), conjunction<Ps...>, P1>::type {};
- template <typename...>
- struct disjunction : std::false_type {};
- template <typename P1>
- struct disjunction<P1> : P1 {};
- template <typename P1, typename... Ps>
- struct disjunction<P1, Ps...>
-
- : std::conditional<!bool(P1::value), disjunction<Ps...>, P1>::type {};
- template <typename...>
- using void_t = void;
- template <typename From, typename To>
- struct is_implicitly_convertible {
- private:
-
-
- template <typename T>
- static void Accept(T);
-
- template <typename T>
- static T Make();
-
- template <typename T, typename = decltype(Accept<To>(Make<T>()))>
- static std::true_type TestImplicitConversion(int);
-
- template <typename T>
- static std::false_type TestImplicitConversion(...);
- public:
- using type = decltype(TestImplicitConversion<From>(0));
- static constexpr bool value = type::value;
- };
- template <typename F, typename... Args>
- using call_result_t = decltype(std::declval<F>()(std::declval<Args>()...));
- template <typename Void, typename R, typename F, typename... Args>
- struct is_callable_r_impl : std::false_type {};
- template <typename R, typename F, typename... Args>
- struct is_callable_r_impl<void_t<call_result_t<F, Args...>>, R, F, Args...>
- : std::conditional<
- std::is_void<R>::value,
- std::true_type,
- is_implicitly_convertible<call_result_t<F, Args...>, R>>::type {};
- template <typename R, typename F, typename... Args>
- using is_callable_r = is_callable_r_impl<void, R, F, Args...>;
- template <typename T>
- typename std::add_const<T>::type& as_const(T& t) {
- return t;
- }
- }
- template <typename F>
- class OnceAction;
- template <typename Result, typename... Args>
- class OnceAction<Result(Args...)> final {
- private:
-
-
- template <typename Callable>
- using IsDirectlyCompatible = internal::conjunction<
- // It must be possible to capture the callable in StdFunctionAdaptor.
- std::is_constructible<typename std::decay<Callable>::type, Callable>,
-
- internal::is_callable_r<Result, typename std::decay<Callable>::type,
- Args...>>;
-
-
- template <typename Callable>
- using IsCompatibleAfterIgnoringArguments = internal::conjunction<
- // It must be possible to capture the callable in a lambda.
- std::is_constructible<typename std::decay<Callable>::type, Callable>,
-
-
- internal::is_callable_r<Result, typename std::decay<Callable>::type>>;
- public:
-
-
-
- template <typename Callable,
- typename std::enable_if<
- internal::conjunction<
- // Teach clang on macOS that we're not talking about a
- // copy/move constructor here. Otherwise it gets confused
- // when checking the is_constructible requirement of our
- // traits above.
- internal::negation<std::is_same<
- OnceAction, typename std::decay<Callable>::type>>,
- IsDirectlyCompatible<Callable>>
- ::value,
- int>::type = 0>
- OnceAction(Callable&& callable)
- : function_(StdFunctionAdaptor<typename std::decay<Callable>::type>(
- {}, std::forward<Callable>(callable))) {}
-
- template <typename Callable,
- typename std::enable_if<
- internal::conjunction<
- // Teach clang on macOS that we're not talking about a
- // copy/move constructor here. Otherwise it gets confused
- // when checking the is_constructible requirement of our
- // traits above.
- internal::negation<std::is_same<
- OnceAction, typename std::decay<Callable>::type>>,
-
-
- internal::negation<IsDirectlyCompatible<Callable>>,
- IsCompatibleAfterIgnoringArguments<Callable>>::value,
- int>::type = 0>
- OnceAction(Callable&& callable)
-
-
- : OnceAction(IgnoreIncomingArguments<typename std::decay<Callable>::type>{
- std::forward<Callable>(callable)}) {}
-
-
- OnceAction(const OnceAction&) = delete;
- OnceAction& operator=(const OnceAction&) = delete;
- OnceAction(OnceAction&&) = default;
-
-
- Result Call(Args... args) && {
- return function_(std::forward<Args>(args)...);
- }
- private:
-
-
-
-
-
-
-
- template <typename Callable>
- class StdFunctionAdaptor final {
- public:
-
-
-
- struct CallableTag final {};
- template <typename F>
- explicit StdFunctionAdaptor(CallableTag, F&& callable)
- : callable_(std::make_shared<Callable>(std::forward<F>(callable))) {}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <typename... ArgRefs>
- internal::call_result_t<Callable, ArgRefs...> operator()(
- ArgRefs&&... args) const {
- return std::move(*callable_)(std::forward<ArgRefs>(args)...);
- }
- private:
-
-
- std::shared_ptr<Callable> callable_;
- };
-
-
- template <typename Callable>
- struct IgnoreIncomingArguments {
- internal::call_result_t<Callable> operator()(Args&&...) {
- return std::move(callable)();
- }
- Callable callable;
- };
- std::function<Result(Args...)> function_;
- };
- 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_ = nullptr;
- }
-
- static bool IsSet() { return producer_ != nullptr; }
-
-
- static bool Exists() {
- return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
- }
-
-
-
- static T Get() {
- return producer_ == nullptr ? 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) {}
- T Produce() override { return value_; }
- private:
- const T value_;
- FixedValueProducer(const FixedValueProducer&) = delete;
- FixedValueProducer& operator=(const FixedValueProducer&) = delete;
- };
- class FactoryValueProducer : public ValueProducer {
- public:
- explicit FactoryValueProducer(FactoryFunction factory)
- : factory_(factory) {}
- T Produce() override { return factory_(); }
- private:
- const FactoryFunction factory_;
- FactoryValueProducer(const FactoryValueProducer&) = delete;
- FactoryValueProducer& operator=(const FactoryValueProducer&) = delete;
- };
- static ValueProducer* producer_;
- };
- template <typename T>
- class DefaultValue<T&> {
- public:
-
- static void Set(T& x) {
- address_ = &x;
- }
-
- static void Clear() { address_ = nullptr; }
-
- static bool IsSet() { return address_ != nullptr; }
-
-
- static bool Exists() {
- return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
- }
-
-
-
- static T& Get() {
- return address_ == nullptr ? 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_ = nullptr;
- template <typename T>
- T* DefaultValue<T&>::address_ = nullptr;
- 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:
- ActionInterface(const ActionInterface&) = delete;
- ActionInterface& operator=(const ActionInterface&) = delete;
- };
- template <typename F>
- class Action;
- template <typename R, typename... Args>
- class Action<R(Args...)> {
- private:
- using F = R(Args...);
-
-
- struct ActionAdapter {
-
- ::std::shared_ptr<ActionInterface<F>> impl_;
- template <typename... InArgs>
- typename internal::Function<F>::Result operator()(InArgs&&... args) {
- return impl_->Perform(
- ::std::forward_as_tuple(::std::forward<InArgs>(args)...));
- }
- };
- template <typename G>
- using IsCompatibleFunctor = std::is_constructible<std::function<F>, G>;
- public:
- typedef typename internal::Function<F>::Result Result;
- typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
-
-
- Action() {}
-
-
-
- template <
- typename G,
- typename = typename std::enable_if<internal::disjunction<
- IsCompatibleFunctor<G>, std::is_constructible<std::function<Result()>,
- G>>::value>::type>
- Action(G&& fun) {
- Init(::std::forward<G>(fun), IsCompatibleFunctor<G>());
- }
-
- explicit Action(ActionInterface<F>* impl)
- : fun_(ActionAdapter{::std::shared_ptr<ActionInterface<F>>(impl)}) {}
-
-
-
- template <typename Func>
- Action(const Action<Func>& action)
- : fun_(action.fun_) {}
-
- bool IsDoDefault() const { return fun_ == nullptr; }
-
-
-
-
-
-
- Result Perform(ArgumentTuple args) const {
- if (IsDoDefault()) {
- internal::IllegalDoDefault(__FILE__, __LINE__);
- }
- return internal::Apply(fun_, ::std::move(args));
- }
-
-
- operator OnceAction<F>() const {
-
-
-
- struct OA {
- Action<F> action;
- R operator()(Args... args) && {
- return action.Perform(
- std::forward_as_tuple(std::forward<Args>(args)...));
- }
- };
- return OA{*this};
- }
- private:
- template <typename G>
- friend class Action;
- template <typename G>
- void Init(G&& g, ::std::true_type) {
- fun_ = ::std::forward<G>(g);
- }
- template <typename G>
- void Init(G&& g, ::std::false_type) {
- fun_ = IgnoreArgs<typename ::std::decay<G>::type>{::std::forward<G>(g)};
- }
- template <typename FunctionImpl>
- struct IgnoreArgs {
- template <typename... InArgs>
- Result operator()(const InArgs&...) const {
- return function_impl();
- }
- FunctionImpl function_impl;
- };
-
- ::std::function<F> fun_;
- };
- 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) {}
- Result Perform(const ArgumentTuple& args) override {
- return impl_.template Perform<Result>(args);
- }
- private:
- Impl impl_;
- };
- Impl impl_;
- };
- 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 T>
- struct ByMoveWrapper {
- explicit ByMoveWrapper(T value) : payload(std::move(value)) {}
- T payload;
- };
- template <typename R>
- class ReturnAction final {
- public:
- explicit ReturnAction(R value) : value_(std::move(value)) {}
- template <typename U, typename... Args,
- typename = typename std::enable_if<conjunction<
- // See the requirements documented on Return.
- negation<std::is_same<void, U>>,
- negation<std::is_reference<U>>,
- std::is_convertible<R, U>,
- std::is_move_constructible<U>>::value>::type>
- operator OnceAction<U(Args...)>() && {
- return Impl<U>(std::move(value_));
- }
- template <typename U, typename... Args,
- typename = typename std::enable_if<conjunction<
- // See the requirements documented on Return.
- negation<std::is_same<void, U>>,
- negation<std::is_reference<U>>,
- std::is_convertible<const R&, U>,
- std::is_copy_constructible<U>>::value>::type>
- operator Action<U(Args...)>() const {
- return Impl<U>(value_);
- }
- private:
-
- template <typename U>
- class Impl final {
- public:
-
-
- explicit Impl(R&& input_value)
- : state_(new State(std::move(input_value))) {}
-
-
- explicit Impl(const R& input_value) : state_(new State(input_value)) {}
- U operator()() && { return std::move(state_->value); }
- U operator()() const& { return state_->value; }
- private:
-
-
-
-
-
-
-
-
-
-
-
- struct State {
- explicit State(const R& input_value_in)
- : input_value(input_value_in),
-
-
-
-
-
-
-
-
- value(ImplicitCast_<U>(internal::as_const(input_value))) {}
-
-
- explicit State(R&& input_value_in)
- : input_value(std::move(input_value_in)),
-
-
-
-
-
-
- value(ImplicitCast_<U>(std::move(input_value))) {}
-
-
-
-
- R input_value;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- U value;
- };
- const std::shared_ptr<State> state_;
- };
- R value_;
- };
- template <typename T>
- class ReturnAction<ByMoveWrapper<T>> final {
- public:
- explicit ReturnAction(ByMoveWrapper<T> wrapper)
- : state_(new State(std::move(wrapper.payload))) {}
- T operator()() const {
- GTEST_CHECK_(!state_->called)
- << "A ByMove() action must be performed at most once.";
- state_->called = true;
- return std::move(state_->value);
- }
- private:
-
-
- struct State {
- explicit State(T&& value_in) : value(std::move(value_in)) {}
- T value;
- bool called = false;
- };
- const std::shared_ptr<State> state_;
- };
- class ReturnNullAction {
- public:
-
-
-
- template <typename Result, typename ArgumentTuple>
- static Result Perform(const ArgumentTuple&) {
- return nullptr;
- }
- };
- class ReturnVoidAction {
- public:
-
- template <typename Result, typename ArgumentTuple>
- static void Perform(const ArgumentTuple&) {
- static_assert(std::is_void<Result>::value, "Result should be void.");
- }
- };
- 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;
-
-
-
- static_assert(std::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) {}
- Result Perform(const ArgumentTuple&) override { return ref_; }
- private:
- T& ref_;
- };
- T& ref_;
- };
- 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;
-
-
-
- static_assert(std::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) {}
- Result Perform(const ArgumentTuple&) override { return value_; }
- private:
- T value_;
- };
- const T value_;
- };
- template <typename T>
- class ReturnRoundRobinAction {
- public:
- explicit ReturnRoundRobinAction(std::vector<T> values) {
- GTEST_CHECK_(!values.empty())
- << "ReturnRoundRobin requires at least one element.";
- state_->values = std::move(values);
- }
- template <typename... Args>
- T operator()(Args&&...) const {
- return state_->Next();
- }
- private:
- struct State {
- T Next() {
- T ret_val = values[i++];
- if (i == values.size()) i = 0;
- return ret_val;
- }
- std::vector<T> values;
- size_t i = 0;
- };
- std::shared_ptr<State> state_ = std::make_shared<State>();
- };
- 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_;
- };
- #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_;
- };
- #endif
- template <size_t N, typename A, typename = void>
- struct SetArgumentPointeeAction {
- A value;
- template <typename... Args>
- void operator()(const Args&... args) const {
- *::std::get<N>(std::tie(args...)) = value;
- }
- };
- template <class Class, typename MethodPtr>
- struct InvokeMethodAction {
- Class* const obj_ptr;
- const MethodPtr method_ptr;
- template <typename... Args>
- auto operator()(Args&&... args) const
- -> decltype((obj_ptr->*method_ptr)(std::forward<Args>(args)...)) {
- return (obj_ptr->*method_ptr)(std::forward<Args>(args)...);
- }
- };
- template <typename FunctionImpl>
- struct InvokeWithoutArgsAction {
- FunctionImpl function_impl;
-
-
- template <typename... Args>
- auto operator()(const Args&...) -> decltype(function_impl()) {
- return function_impl();
- }
- };
- template <class Class, typename MethodPtr>
- struct InvokeMethodWithoutArgsAction {
- Class* const obj_ptr;
- const MethodPtr method_ptr;
- using ReturnType =
- decltype((std::declval<Class*>()->*std::declval<MethodPtr>())());
- template <typename... Args>
- ReturnType operator()(const Args&...) const {
- return (obj_ptr->*method_ptr)();
- }
- };
- 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;
-
- static_assert(std::is_void<Result>::value, "Result type should be void.");
- 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) {}
- void Perform(const ArgumentTuple& args) override {
-
- action_.Perform(args);
- }
- private:
-
-
- typedef
- typename internal::Function<F>::MakeResultIgnoredValue OriginalFunction;
- const Action<OriginalFunction> action_;
- };
- const A action_;
- };
- template <typename InnerAction, size_t... I>
- struct WithArgsAction {
- InnerAction inner_action;
-
-
- template <typename R, typename... Args>
- using InnerSignature =
- R(typename std::tuple_element<I, std::tuple<Args...>>::type...);
-
-
-
-
-
- template <typename R, typename... Args,
- typename std::enable_if<
- std::is_convertible<
- InnerAction,
- // Unfortunately we can't use the InnerSignature alias here;
- // MSVC complains about the I parameter pack not being
- // expanded (error C3520) despite it being expanded in the
- // type alias.
- OnceAction<R(typename std::tuple_element<
- I, std::tuple<Args...>>::type...)>>::value,
- int>::type = 0>
- operator OnceAction<R(Args...)>() && {
- struct OA {
- OnceAction<InnerSignature<R, Args...>> inner_action;
- R operator()(Args&&... args) && {
- return std::move(inner_action)
- .Call(std::get<I>(
- std::forward_as_tuple(std::forward<Args>(args)...))...);
- }
- };
- return OA{std::move(inner_action)};
- }
- template <typename R, typename... Args,
- typename std::enable_if<
- std::is_convertible<
- const InnerAction&,
- // Unfortunately we can't use the InnerSignature alias here;
- // MSVC complains about the I parameter pack not being
- // expanded (error C3520) despite it being expanded in the
- // type alias.
- Action<R(typename std::tuple_element<
- I, std::tuple<Args...>>::type...)>>::value,
- int>::type = 0>
- operator Action<R(Args...)>() const {
- Action<InnerSignature<R, Args...>> converted(inner_action);
- return [converted](Args&&... args) -> R {
- return converted.Perform(std::forward_as_tuple(
- std::get<I>(std::forward_as_tuple(std::forward<Args>(args)...))...));
- };
- }
- };
- template <typename... Actions>
- class DoAllAction;
- template <typename FinalAction>
- class DoAllAction<FinalAction> {
- public:
- struct UserConstructorTag {};
- template <typename T>
- explicit DoAllAction(UserConstructorTag, T&& action)
- : final_action_(std::forward<T>(action)) {}
-
-
-
-
-
- template <typename R, typename... Args,
- typename std::enable_if<
- std::is_convertible<FinalAction, OnceAction<R(Args...)>>::value,
- int>::type = 0>
- operator OnceAction<R(Args...)>() && {
- return std::move(final_action_);
- }
- template <
- typename R, typename... Args,
- typename std::enable_if<
- std::is_convertible<const FinalAction&, Action<R(Args...)>>::value,
- int>::type = 0>
- operator Action<R(Args...)>() const {
- return final_action_;
- }
- private:
- FinalAction final_action_;
- };
- template <typename InitialAction, typename... OtherActions>
- class DoAllAction<InitialAction, OtherActions...>
- : private DoAllAction<OtherActions...> {
- private:
- using Base = DoAllAction<OtherActions...>;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <typename T>
- using InitialActionArgType =
- typename std::conditional<std::is_scalar<T>::value, T, const T&>::type;
- public:
- struct UserConstructorTag {};
- template <typename T, typename... U>
- explicit DoAllAction(UserConstructorTag, T&& initial_action,
- U&&... other_actions)
- : Base({}, std::forward<U>(other_actions)...),
- initial_action_(std::forward<T>(initial_action)) {}
- template <typename R, typename... Args,
- typename std::enable_if<
- conjunction<
- // Both the initial action and the rest must support
- // conversion to OnceAction.
- std::is_convertible<
- InitialAction,
- OnceAction<void(InitialActionArgType<Args>...)>>,
- std::is_convertible<Base, OnceAction<R(Args...)>>>::value,
- int>::type = 0>
- operator OnceAction<R(Args...)>() && {
-
-
-
- struct OA {
- OnceAction<void(InitialActionArgType<Args>...)> initial_action;
- OnceAction<R(Args...)> remaining_actions;
- R operator()(Args... args) && {
- std::move(initial_action)
- .Call(static_cast<InitialActionArgType<Args>>(args)...);
- return std::move(remaining_actions).Call(std::forward<Args>(args)...);
- }
- };
- return OA{
- std::move(initial_action_),
- std::move(static_cast<Base&>(*this)),
- };
- }
- template <
- typename R, typename... Args,
- typename std::enable_if<
- conjunction<
- // Both the initial action and the rest must support conversion to
- // Action.
- std::is_convertible<const InitialAction&,
- Action<void(InitialActionArgType<Args>...)>>,
- std::is_convertible<const Base&, Action<R(Args...)>>>::value,
- int>::type = 0>
- operator Action<R(Args...)>() const {
-
-
-
- struct OA {
- Action<void(InitialActionArgType<Args>...)> initial_action;
- Action<R(Args...)> remaining_actions;
- R operator()(Args... args) const {
- initial_action.Perform(std::forward_as_tuple(
- static_cast<InitialActionArgType<Args>>(args)...));
- return remaining_actions.Perform(
- std::forward_as_tuple(std::forward<Args>(args)...));
- }
- };
- return OA{
- initial_action_,
- static_cast<const Base&>(*this),
- };
- }
- private:
- InitialAction initial_action_;
- };
- template <typename T, typename... Params>
- struct ReturnNewAction {
- T* operator()() const {
- return internal::Apply(
- [](const Params&... unpacked_params) {
- return new T(unpacked_params...);
- },
- params);
- }
- std::tuple<Params...> params;
- };
- template <size_t k>
- struct ReturnArgAction {
- template <typename... Args,
- typename = typename std::enable_if<(k < sizeof...(Args))>::type>
- auto operator()(Args&&... args) const -> decltype(std::get<k>(
- std::forward_as_tuple(std::forward<Args>(args)...))) {
- return std::get<k>(std::forward_as_tuple(std::forward<Args>(args)...));
- }
- };
- template <size_t k, typename Ptr>
- struct SaveArgAction {
- Ptr pointer;
- template <typename... Args>
- void operator()(const Args&... args) const {
- *pointer = std::get<k>(std::tie(args...));
- }
- };
- template <size_t k, typename Ptr>
- struct SaveArgPointeeAction {
- Ptr pointer;
- template <typename... Args>
- void operator()(const Args&... args) const {
- *pointer = *std::get<k>(std::tie(args...));
- }
- };
- template <size_t k, typename T>
- struct SetArgRefereeAction {
- T value;
- template <typename... Args>
- void operator()(Args&&... args) const {
- using argk_type =
- typename ::std::tuple_element<k, std::tuple<Args...>>::type;
- static_assert(std::is_lvalue_reference<argk_type>::value,
- "Argument must be a reference type.");
- std::get<k>(std::tie(args...)) = value;
- }
- };
- template <size_t k, typename I1, typename I2>
- struct SetArrayArgumentAction {
- I1 first;
- I2 last;
- template <typename... Args>
- void operator()(const Args&... args) const {
- auto value = std::get<k>(std::tie(args...));
- for (auto it = first; it != last; ++it, (void)++value) {
- *value = *it;
- }
- }
- };
- template <size_t k>
- struct DeleteArgAction {
- template <typename... Args>
- void operator()(const Args&... args) const {
- delete std::get<k>(std::tie(args...));
- }
- };
- template <typename Ptr>
- struct ReturnPointeeAction {
- Ptr pointer;
- template <typename... Args>
- auto operator()(const Args&...) const -> decltype(*pointer) {
- return *pointer;
- }
- };
- #if GTEST_HAS_EXCEPTIONS
- template <typename T>
- struct ThrowAction {
- T exception;
-
- template <typename R, typename... Args>
- operator Action<R(Args...)>() const {
- T copy = exception;
- return [copy](Args...) -> R { throw copy; };
- }
- };
- #endif
- }
- typedef internal::IgnoredValue Unused;
- template <typename... Action>
- internal::DoAllAction<typename std::decay<Action>::type...> DoAll(
- Action&&... action) {
- return internal::DoAllAction<typename std::decay<Action>::type...>(
- {}, std::forward<Action>(action)...);
- }
- template <size_t k, typename InnerAction>
- internal::WithArgsAction<typename std::decay<InnerAction>::type, k> WithArg(
- InnerAction&& action) {
- return {std::forward<InnerAction>(action)};
- }
- template <size_t k, size_t... ks, typename InnerAction>
- internal::WithArgsAction<typename std::decay<InnerAction>::type, k, ks...>
- WithArgs(InnerAction&& action) {
- return {std::forward<InnerAction>(action)};
- }
- template <typename InnerAction>
- internal::WithArgsAction<typename std::decay<InnerAction>::type> WithoutArgs(
- InnerAction&& action) {
- return {std::forward<InnerAction>(action)};
- }
- template <typename R>
- internal::ReturnAction<R> Return(R value) {
- return internal::ReturnAction<R>(std::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, R* = nullptr>
- internal::ReturnRefAction<R> ReturnRef(R&&) = delete;
- 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>(std::move(x));
- }
- template <typename T>
- internal::ReturnRoundRobinAction<T> ReturnRoundRobin(std::vector<T> vals) {
- return internal::ReturnRoundRobinAction<T>(std::move(vals));
- }
- template <typename T>
- internal::ReturnRoundRobinAction<T> ReturnRoundRobin(
- std::initializer_list<T> vals) {
- return internal::ReturnRoundRobinAction<T>(std::vector<T>(vals));
- }
- inline internal::DoDefaultAction DoDefault() {
- return internal::DoDefaultAction();
- }
- template <size_t N, typename T>
- internal::SetArgumentPointeeAction<N, T> SetArgPointee(T value) {
- return {std::move(value)};
- }
- template <size_t N, typename T>
- internal::SetArgumentPointeeAction<N, T> SetArgumentPointee(T value) {
- return {std::move(value)};
- }
- 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>
- typename std::decay<FunctionImpl>::type Invoke(FunctionImpl&& function_impl) {
- return std::forward<FunctionImpl>(function_impl);
- }
- template <class Class, typename MethodPtr>
- internal::InvokeMethodAction<Class, MethodPtr> Invoke(Class* obj_ptr,
- MethodPtr method_ptr) {
- return {obj_ptr, method_ptr};
- }
- template <typename FunctionImpl>
- internal::InvokeWithoutArgsAction<typename std::decay<FunctionImpl>::type>
- InvokeWithoutArgs(FunctionImpl function_impl) {
- return {std::move(function_impl)};
- }
- template <class Class, typename MethodPtr>
- internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> InvokeWithoutArgs(
- Class* obj_ptr, MethodPtr method_ptr) {
- return {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 ::std::reference_wrapper<T> ByRef(T& l_value) {
- return ::std::reference_wrapper<T>(l_value);
- }
- template <typename T, typename... Params>
- internal::ReturnNewAction<T, typename std::decay<Params>::type...> ReturnNew(
- Params&&... params) {
- return {std::forward_as_tuple(std::forward<Params>(params)...)};
- }
- template <size_t k>
- internal::ReturnArgAction<k> ReturnArg() {
- return {};
- }
- template <size_t k, typename Ptr>
- internal::SaveArgAction<k, Ptr> SaveArg(Ptr pointer) {
- return {pointer};
- }
- template <size_t k, typename Ptr>
- internal::SaveArgPointeeAction<k, Ptr> SaveArgPointee(Ptr pointer) {
- return {pointer};
- }
- template <size_t k, typename T>
- internal::SetArgRefereeAction<k, typename std::decay<T>::type> SetArgReferee(
- T&& value) {
- return {std::forward<T>(value)};
- }
- template <size_t k, typename I1, typename I2>
- internal::SetArrayArgumentAction<k, I1, I2> SetArrayArgument(I1 first,
- I2 last) {
- return {first, last};
- }
- template <size_t k>
- internal::DeleteArgAction<k> DeleteArg() {
- return {};
- }
- template <typename Ptr>
- internal::ReturnPointeeAction<Ptr> ReturnPointee(Ptr pointer) {
- return {pointer};
- }
- #if GTEST_HAS_EXCEPTIONS
- template <typename T>
- internal::ThrowAction<typename std::decay<T>::type> Throw(T&& exception) {
- return {std::forward<T>(exception)};
- }
- #endif
- namespace internal {
- struct ExcessiveArg {};
- template <typename F, typename Impl>
- struct ActionImpl;
- template <typename Impl>
- struct ImplBase {
- struct Holder {
-
- explicit operator const Impl&() const { return *ptr; }
- std::shared_ptr<Impl> ptr;
- };
- using type = typename std::conditional<std::is_constructible<Impl>::value,
- Impl, Holder>::type;
- };
- template <typename R, typename... Args, typename Impl>
- struct ActionImpl<R(Args...), Impl> : ImplBase<Impl>::type {
- using Base = typename ImplBase<Impl>::type;
- using function_type = R(Args...);
- using args_type = std::tuple<Args...>;
- ActionImpl() = default;
- explicit ActionImpl(std::shared_ptr<Impl> impl) : Base{std::move(impl)} {}
- R operator()(Args&&... arg) const {
- static constexpr size_t kMaxArgs =
- sizeof...(Args) <= 10 ? sizeof...(Args) : 10;
- return Apply(MakeIndexSequence<kMaxArgs>{},
- MakeIndexSequence<10 - kMaxArgs>{},
- args_type{std::forward<Args>(arg)...});
- }
- template <std::size_t... arg_id, std::size_t... excess_id>
- R Apply(IndexSequence<arg_id...>, IndexSequence<excess_id...>,
- const args_type& args) const {
-
-
-
-
-
- static constexpr ExcessiveArg kExcessArg{};
- return static_cast<const Impl&>(*this)
- .template gmock_PerformImpl<
- /*function_type=*/function_type, /*return_type=*/R,
- /*args_type=*/args_type,
- /*argN_type=*/
- typename std::tuple_element<arg_id, args_type>::type...>(
- args, std::get<arg_id>(args)...,
- ((void)excess_id, kExcessArg)...);
- }
- };
- template <typename F, typename Impl>
- ::testing::Action<F> MakeAction() {
- return ::testing::Action<F>(ActionImpl<F, Impl>());
- }
- template <typename F, typename Impl>
- ::testing::Action<F> MakeAction(std::shared_ptr<Impl> impl) {
- return ::testing::Action<F>(ActionImpl<F, Impl>(std::move(impl)));
- }
- #define GMOCK_INTERNAL_ARG_UNUSED(i, data, el) \
- , const arg##i##_type& arg##i GTEST_ATTRIBUTE_UNUSED_
- #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_ \
- const args_type& args GTEST_ATTRIBUTE_UNUSED_ GMOCK_PP_REPEAT( \
- GMOCK_INTERNAL_ARG_UNUSED, , 10)
- #define GMOCK_INTERNAL_ARG(i, data, el) , const arg##i##_type& arg##i
- #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_ \
- const args_type& args GMOCK_PP_REPEAT(GMOCK_INTERNAL_ARG, , 10)
- #define GMOCK_INTERNAL_TEMPLATE_ARG(i, data, el) , typename arg##i##_type
- #define GMOCK_ACTION_TEMPLATE_ARGS_NAMES_ \
- GMOCK_PP_TAIL(GMOCK_PP_REPEAT(GMOCK_INTERNAL_TEMPLATE_ARG, , 10))
- #define GMOCK_INTERNAL_TYPENAME_PARAM(i, data, param) , typename param##_type
- #define GMOCK_ACTION_TYPENAME_PARAMS_(params) \
- GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPENAME_PARAM, , params))
- #define GMOCK_INTERNAL_TYPE_PARAM(i, data, param) , param##_type
- #define GMOCK_ACTION_TYPE_PARAMS_(params) \
- GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_PARAM, , params))
- #define GMOCK_INTERNAL_TYPE_GVALUE_PARAM(i, data, param) \
- , param##_type gmock_p##i
- #define GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params) \
- GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_GVALUE_PARAM, , params))
- #define GMOCK_INTERNAL_GVALUE_PARAM(i, data, param) \
- , std::forward<param##_type>(gmock_p##i)
- #define GMOCK_ACTION_GVALUE_PARAMS_(params) \
- GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GVALUE_PARAM, , params))
- #define GMOCK_INTERNAL_INIT_PARAM(i, data, param) \
- , param(::std::forward<param##_type>(gmock_p##i))
- #define GMOCK_ACTION_INIT_PARAMS_(params) \
- GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_INIT_PARAM, , params))
- #define GMOCK_INTERNAL_FIELD_PARAM(i, data, param) param##_type param;
- #define GMOCK_ACTION_FIELD_PARAMS_(params) \
- GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_FIELD_PARAM, , params)
- #define GMOCK_INTERNAL_ACTION(name, full_name, params) \
- template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \
- class full_name { \
- public: \
- explicit full_name(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) \
- : impl_(std::make_shared<gmock_Impl>( \
- GMOCK_ACTION_GVALUE_PARAMS_(params))) {} \
- full_name(const full_name&) = default; \
- full_name(full_name&&) noexcept = default; \
- template <typename F> \
- operator ::testing::Action<F>() const { \
- return ::testing::internal::MakeAction<F>(impl_); \
- } \
- \
- private: \
- class gmock_Impl { \
- public: \
- explicit gmock_Impl(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) \
- : GMOCK_ACTION_INIT_PARAMS_(params) {} \
- template <typename function_type, typename return_type, \
- typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \
- return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \
- GMOCK_ACTION_FIELD_PARAMS_(params) \
- }; \
- std::shared_ptr<const gmock_Impl> impl_; \
- }; \
- template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \
- inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \
- GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) GTEST_MUST_USE_RESULT_; \
- template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \
- inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \
- GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) { \
- return full_name<GMOCK_ACTION_TYPE_PARAMS_(params)>( \
- GMOCK_ACTION_GVALUE_PARAMS_(params)); \
- } \
- template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \
- template <typename function_type, typename return_type, typename args_type, \
- GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \
- return_type \
- full_name<GMOCK_ACTION_TYPE_PARAMS_(params)>::gmock_Impl::gmock_PerformImpl( \
- GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
- }
- #define ACTION(name) \
- class name##Action { \
- public: \
- explicit name##Action() noexcept {} \
- name##Action(const name##Action&) noexcept {} \
- template <typename F> \
- operator ::testing::Action<F>() const { \
- return ::testing::internal::MakeAction<F, gmock_Impl>(); \
- } \
- \
- private: \
- class gmock_Impl { \
- public: \
- template <typename function_type, typename return_type, \
- typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \
- return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \
- }; \
- }; \
- inline name##Action name() GTEST_MUST_USE_RESULT_; \
- inline name##Action name() { return name##Action(); } \
- template <typename function_type, typename return_type, typename args_type, \
- GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \
- return_type name##Action::gmock_Impl::gmock_PerformImpl( \
- GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
- #define ACTION_P(name, ...) \
- GMOCK_INTERNAL_ACTION(name, name##ActionP, (__VA_ARGS__))
- #define ACTION_P2(name, ...) \
- GMOCK_INTERNAL_ACTION(name, name##ActionP2, (__VA_ARGS__))
- #define ACTION_P3(name, ...) \
- GMOCK_INTERNAL_ACTION(name, name##ActionP3, (__VA_ARGS__))
- #define ACTION_P4(name, ...) \
- GMOCK_INTERNAL_ACTION(name, name##ActionP4, (__VA_ARGS__))
- #define ACTION_P5(name, ...) \
- GMOCK_INTERNAL_ACTION(name, name##ActionP5, (__VA_ARGS__))
- #define ACTION_P6(name, ...) \
- GMOCK_INTERNAL_ACTION(name, name##ActionP6, (__VA_ARGS__))
- #define ACTION_P7(name, ...) \
- GMOCK_INTERNAL_ACTION(name, name##ActionP7, (__VA_ARGS__))
- #define ACTION_P8(name, ...) \
- GMOCK_INTERNAL_ACTION(name, name##ActionP8, (__VA_ARGS__))
- #define ACTION_P9(name, ...) \
- GMOCK_INTERNAL_ACTION(name, name##ActionP9, (__VA_ARGS__))
- #define ACTION_P10(name, ...) \
- GMOCK_INTERNAL_ACTION(name, name##ActionP10, (__VA_ARGS__))
- }
- #ifdef _MSC_VER
- #pragma warning(pop)
- #endif
- #endif
|