Lines Matching full:action
32 // The ACTION* family of macros can be used in a namespace scope to
35 // ACTION(name) { statements; }
37 // will define an action with the given name that executes the
39 // the return value of the action. Inside the statements, you can
43 // ACTION(IncrementArg1) {
62 // Sometimes you'll want to parameterize the action. For that you can use
105 // While it's tempting to always use the ACTION* macros when defining
106 // a new action, you should also consider implementing ActionInterface
108 // use the action a lot. While these approaches require more work,
110 // arguments and the action parameters, which in general leads to
117 // ACTION*() can only be used in a namespace scope as templates cannot be
124 // To learn more about using these macros, please search for 'ACTION' on
156 // To implement an action Foo, define:
158 // 2. a factory function that creates an Action object from a
163 // management as Action objects can now be copied like plain values.
180 "Default action undefined for the function return type.");
242 // There's no need for a default action for signed wchar_t, as that
245 // There's also no need for a default action for unsigned wchar_t, as
384 // An action that can only be used once.
386 // This is accepted by WillOnce, which doesn't require the underlying action to
388 // an rvalue reference. This allows the action to work with move-only types like
397 // // We can define an action that provides a Foo to that API. Because It
408 // // This action can be used with WillOnce.
413 // // since the action cannot correctly be used repeatedly.
417 // A less-contrived example would be an action that returns an arbitrary type,
489 // Invoke the underlying action callable with which we were constructed,
698 // Implement this interface to define an action for function type F.
708 // Performs the action. This method is not const, as in general an
709 // action can have side effects and be stateful. For example, a
710 // get-the-next-element-from-the-collection action will need to
720 class Action;
722 // An Action<R(Args...)> is a copyable and IMMUTABLE (except by assignment)
723 // object that represents an action to be taken when a mock function of type
724 // R(Args...) is called. The implementation of Action<T> is just a
725 // std::shared_ptr to const ActionInterface<T>. Don't inherit from Action! You
726 // can view an object implementing ActionInterface<F> as a concrete action
727 // (including its current state), and an Action<F> object as a handle to it.
729 class Action<R(Args...)> {
733 // Adapter class to allow constructing Action from a legacy ActionInterface.
753 // Constructs a null Action. Needed for storing Action objects in
755 Action() {}
757 // Construct an Action from a specified callable.
758 // This cannot take std::function directly, because then Action would not be
765 Action(G&& fun) { // NOLINT
769 // Constructs an Action from its implementation.
770 explicit Action(ActionInterface<F>* impl)
773 // This constructor allows us to turn an Action<Func> object into an
774 // Action<F>, as long as F's arguments can be implicitly converted
777 Action(const Action<Func>& action) // NOLINT
778 : fun_(action.fun_) {}
780 // Returns true if and only if this is the DoDefault() action.
783 // Performs the action. Note that this method is const even though
785 // is that a const Action<F> means that it cannot be re-bound to
786 // another concrete action, not that the concrete action it binds to
796 // An action can be used as a OnceAction, since it's obviously safe to call it
803 Action<F> action;
806 return action.Perform(
816 friend class Action;
838 // fun_ is an empty function if and only if this is the DoDefault() action.
843 // polymorphic action (i.e. an action that can be used in mock
846 // To define a polymorphic action, a user first provides a COPYABLE
859 // Then the user creates the polymorphic action using
869 operator Action<F>() const {
870 return Action<F>(new MonomorphicImpl<F>(impl_));
893 // Creates an Action from its implementation and returns it. The
894 // created Action object owns the implementation.
896 Action<F> MakeAction(ActionInterface<F>* impl) {
897 return Action<F>(impl);
900 // Creates a polymorphic action from its implementation. This is
946 operator Action<U(Args...)>() const { // NOLINT
951 // Implements the Return(x) action for a mock function that returns type U.
961 // the input value (i.e. we are converting to Action).
1016 // made the Action<U()> conversion operator eagerly convert the R value to
1059 // auto action = Return(std::initializer_list<std::string>{
1064 // .WillOnce(action)
1065 // .WillOnce(action)
1097 << "A ByMove() action must be performed at most once.";
1105 // Action, despite the fact that we are stateful and T may not be copyable.
1116 // Implements the ReturnNull() action.
1128 // Implements the Return() action.
1138 // Implements the polymorphic ReturnRef(x) action, which can be used
1150 operator Action<F>() const {
1157 return Action<F>(new Impl<F>(ref_));
1161 // Implements the ReturnRef(x) action for a particular function type F.
1179 // Implements the polymorphic ReturnRefOfCopy(x) action, which can be
1192 operator Action<F>() const {
1199 return Action<F>(new Impl<F>(value_));
1203 // Implements the ReturnRefOfCopy(x) action for a particular function type F.
1221 // Implements the polymorphic ReturnRoundRobin(v) action, which can be
1251 // Implements the polymorphic DoDefault() action.
1257 operator Action<F>() const {
1258 return Action<F>();
1262 // Implements the Assign action to set a given pointer referent to a
1281 // Implements the SetErrnoAndReturn action to simulate return from
1301 // Implements the SetArgumentPointee<N>(x) action for any function
1313 // Implements the Invoke(object_ptr, &Class::Method) action.
1326 // Implements the InvokeWithoutArgs(f) action. The template argument
1329 // Action<F> as long as f's type is compatible with F.
1334 // Allows InvokeWithoutArgs(f) to be used as any action whose type is
1342 // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
1357 // Implements the IgnoreResult(action) action.
1361 explicit IgnoreResultAction(const A& action) : action_(action) {}
1364 operator Action<F>() const {
1378 return Action<F>(new Impl<F>(action_));
1388 explicit Impl(const A& action) : action_(action) {}
1391 // Performs the action and ignores its result.
1401 const Action<OriginalFunction> action_;
1411 // The signature of the function as seen by the inner action, given an out
1412 // action with the given result and argument types.
1418 // particular action types. This is necessary for embedded actions like
1419 // DoDefault(), which rely on an action conversion operators rather than
1460 Action<R(internal::TupleElement<
1463 operator Action<R(Args...)>() const { // NOLINT
1464 Action<InnerSignature<R, Args...>> converted(inner_action);
1476 // Base case: only a single action.
1483 explicit DoAllAction(UserConstructorTag, T&& action)
1484 : final_action_(std::forward<T>(action)) {}
1487 // particular action types. This is necessary for embedded actions like
1488 // DoDefault(), which rely on an action conversion operators rather than
1503 std::is_convertible<const FinalAction&, Action<R(Args...)>>::value,
1505 operator Action<R(Args...)>() const { // NOLINT
1513 // Recursive case: support N actions by calling the initial action and then
1521 // The type of reference that should be provided to an initial action for a
1532 // might seem surprising for the user's initial action to need to be
1533 // convertible to Action<void(const int&)>. This is perhaps less
1582 // Both the initial action and the rest must support
1590 // Return an action that first calls the initial action with arguments
1615 // Both the initial action and the rest must support conversion to
1616 // Action.
1618 Action<void(InitialActionArgType<Args>...)>>,
1619 std::is_convertible<const Base&, Action<R(Args...)>>>::value,
1621 operator Action<R(Args...)>() const { // NOLINT
1622 // Return an action that first calls the initial action with arguments
1626 Action<void(InitialActionArgType<Args>...)> initial_action;
1627 Action<R(Args...)> remaining_actions;
1741 operator Action<R(Args...)>() const { // NOLINT
1782 // Creates an action that does actions a1, a2, ..., sequentially in
1783 // each invocation. All but the last action will have a readonly view of the
1785 template <typename... Action>
1786 internal::DoAllAction<typename std::decay<Action>::type...> DoAll(
1787 Action&&... action) {
1788 return internal::DoAllAction<typename std::decay<Action>::type...>(
1789 {}, std::forward<Action>(action)...);
1792 // WithArg<k>(an_action) creates an action that passes the k-th
1794 // it. It adapts an action accepting one argument to one that accepts
1799 InnerAction&& action) {
1800 return {std::forward<InnerAction>(action)};
1803 // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
1809 WithArgs(InnerAction&& action) {
1810 return {std::forward<InnerAction>(action)};
1815 // argument. In other words, it adapts an action accepting no
1819 InnerAction&& action) {
1820 return {std::forward<InnerAction>(action)};
1823 // Creates an action that returns a value.
1828 // * If R is convertible to U and U is move-constructible, then the action can
1832 // action can be used with both WillOnce and WillRepeatedly.
1841 // // Return. The view is valid even after the action is performed.
1852 // Creates an action that returns NULL.
1857 // Creates an action that returns from a void function.
1862 // Creates an action that returns the reference to a variable.
1872 // Creates an action that returns the reference to a copy of the
1873 // argument. The copy is created when the action is constructed and
1874 // lives as long as the action.
1882 // Modifies the parent action (a Return() action) to perform a move of the
1891 // Creates an action that returns an element of `vals`. Calling this action will
1899 // Creates an action that returns an element of `vals`. Calling this action will
1908 // Creates an action that does the default action for the give mock function.
1913 // Creates an action that sets the variable pointed by the N-th
1926 // Creates an action that sets a pointer referent to a given value.
1934 // Creates an action that sets errno and returns the appropriate error.
1955 // Creates an action that invokes the given method on the given object
1963 // Creates an action that invokes 'function_impl' with no argument.
1970 // Creates an action that invokes the given method on the given object
1978 // Creates an action that performs an_action and throws away its
2001 // The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
2010 // Action ReturnArg<k>() returns the k-th argument of the mock function.
2016 // Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
2023 // Action SaveArgPointee<k>(pointer) saves the value pointed to
2030 // Action SetArgReferee<k>(value) assigns 'value' to the variable
2038 // Action SetArrayArgument<k>(first, last) copies the elements in
2041 // iterator. The action does not take ownership of the elements in the
2049 // Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
2056 // This action returns the value pointed to by 'pointer'.
2062 // Action Throw(exception) can be used in a mock function of any type
2073 // A macro from the ACTION* family (defined later in gmock-generated-actions.h)
2074 // defines an action that can be used in a mock function. Typically,
2076 // function. For example, if such an action only uses the second
2080 // Therefore, the action implementation must be prepared to take more
2089 // Builds an implementation of an Action<> for some particular signature, using
2090 // a class defined by an ACTION* macro.
2097 // Allows each copy of the Action<> to get to the Impl.
2125 // Impl need not be specific to the signature of action being implemented;
2142 // Stores a default-constructed Impl as part of the Action<>'s
2145 ::testing::Action<F> MakeAction() {
2146 return ::testing::Action<F>(ActionImpl<F, Impl>());
2151 ::testing::Action<F> MakeAction(std::shared_ptr<Impl> impl) {
2152 return ::testing::Action<F>(ActionImpl<F, Impl>(std::move(impl)));
2206 operator ::testing::Action<F>() const { \
2241 #define ACTION(name) \
2242 class name##Action { \
2244 explicit name##Action() noexcept {} \
2245 name##Action(const name##Action&) noexcept {} \
2247 operator ::testing::Action<F>() const { \
2259 inline name##Action name() GTEST_MUST_USE_RESULT_; \
2260 inline name##Action name() { return name##Action(); } \
2263 return_type name##Action::gmock_Impl::gmock_PerformImpl( \