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
154 // To implement an action Foo, define:
156 // 2. a factory function that creates an Action object from a
161 // management as Action objects can now be copied like plain values.
178 "Default action undefined for the function return type.");
246 // There's no need for a default action for signed wchar_t, as that
249 // There's also no need for a default action for unsigned wchar_t, as
388 // An action that can only be used once.
390 // This is accepted by WillOnce, which doesn't require the underlying action to
392 // an rvalue reference. This allows the action to work with move-only types like
401 // // We can define an action that provides a Foo to that API. Because It
412 // // This action can be used with WillOnce.
417 // // since the action cannot correctly be used repeatedly.
421 // A less-contrived example would be an action that returns an arbitrary type,
493 // Invoke the underlying action callable with which we were constructed,
702 // Implement this interface to define an action for function type F.
712 // Performs the action. This method is not const, as in general an
713 // action can have side effects and be stateful. For example, a
714 // get-the-next-element-from-the-collection action will need to
724 class Action;
726 // An Action<R(Args...)> is a copyable and IMMUTABLE (except by assignment)
727 // object that represents an action to be taken when a mock function of type
728 // R(Args...) is called. The implementation of Action<T> is just a
729 // std::shared_ptr to const ActionInterface<T>. Don't inherit from Action! You
730 // can view an object implementing ActionInterface<F> as a concrete action
731 // (including its current state), and an Action<F> object as a handle to it.
733 class Action<R(Args...)> {
737 // Adapter class to allow constructing Action from a legacy ActionInterface.
757 // Constructs a null Action. Needed for storing Action objects in
759 Action() = default;
761 // Construct an Action from a specified callable.
762 // This cannot take std::function directly, because then Action would not be
769 Action(G&& fun) { // NOLINT
773 // Constructs an Action from its implementation.
774 explicit Action(ActionInterface<F>* impl)
777 // This constructor allows us to turn an Action<Func> object into an
778 // Action<F>, as long as F's arguments can be implicitly converted
781 Action(const Action<Func>& action) // NOLINT
782 : fun_(action.fun_) {}
784 // Returns true if and only if this is the DoDefault() action.
787 // Performs the action. Note that this method is const even though
789 // is that a const Action<F> means that it cannot be re-bound to
790 // another concrete action, not that the concrete action it binds to
800 // An action can be used as a OnceAction, since it's obviously safe to call it
807 Action<F> action;
810 return action.Perform(
820 friend class Action;
842 // fun_ is an empty function if and only if this is the DoDefault() action.
847 // polymorphic action (i.e. an action that can be used in mock
850 // To define a polymorphic action, a user first provides a COPYABLE
863 // Then the user creates the polymorphic action using
873 operator Action<F>() const {
874 return Action<F>(new MonomorphicImpl<F>(impl_));
897 // Creates an Action from its implementation and returns it. The
898 // created Action object owns the implementation.
900 Action<F> MakeAction(ActionInterface<F>* impl) {
901 return Action<F>(impl);
904 // Creates a polymorphic action from its implementation. This is
950 operator Action<U(Args...)>() const { // NOLINT
955 // Implements the Return(x) action for a mock function that returns type U.
965 // the input value (i.e. we are converting to Action).
1020 // made the Action<U()> conversion operator eagerly convert the R value to
1063 // auto action = Return(std::initializer_list<std::string>{
1068 // .WillOnce(action)
1069 // .WillOnce(action)
1101 << "A ByMove() action must be performed at most once.";
1109 // Action, despite the fact that we are stateful and T may not be copyable.
1120 // Implements the ReturnNull() action.
1132 // Implements the Return() action.
1142 // Implements the polymorphic ReturnRef(x) action, which can be used
1154 operator Action<F>() const {
1161 return Action<F>(new Impl<F>(ref_));
1165 // Implements the ReturnRef(x) action for a particular function type F.
1183 // Implements the polymorphic ReturnRefOfCopy(x) action, which can be
1196 operator Action<F>() const {
1203 return Action<F>(new Impl<F>(value_));
1207 // Implements the ReturnRefOfCopy(x) action for a particular function type F.
1225 // Implements the polymorphic ReturnRoundRobin(v) action, which can be
1255 // Implements the polymorphic DoDefault() action.
1261 operator Action<F>() const {
1262 return Action<F>();
1266 // Implements the Assign action to set a given pointer referent to a
1285 // Implements the SetErrnoAndReturn action to simulate return from
1305 // Implements the SetArgumentPointee<N>(x) action for any function
1317 // Implements the Invoke(object_ptr, &Class::Method) action.
1330 // Implements the InvokeWithoutArgs(f) action. The template argument
1333 // Action<F> as long as f's type is compatible with F.
1338 // Allows InvokeWithoutArgs(f) to be used as any action whose type is
1346 // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
1361 // Implements the IgnoreResult(action) action.
1365 explicit IgnoreResultAction(const A& action) : action_(action) {}
1368 operator Action<F>() const {
1382 return Action<F>(new Impl<F>(action_));
1392 explicit Impl(const A& action) : action_(action) {}
1395 // Performs the action and ignores its result.
1405 const Action<OriginalFunction> action_;
1415 // The signature of the function as seen by the inner action, given an out
1416 // action with the given result and argument types.
1422 // particular action types. This is necessary for embedded actions like
1423 // DoDefault(), which rely on an action conversion operators rather than
1464 Action<R(internal::TupleElement<
1467 operator Action<R(Args...)>() const { // NOLINT
1468 Action<InnerSignature<R, Args...>> converted(inner_action);
1480 // Base case: only a single action.
1487 explicit DoAllAction(UserConstructorTag, T&& action)
1488 : final_action_(std::forward<T>(action)) {}
1491 // particular action types. This is necessary for embedded actions like
1492 // DoDefault(), which rely on an action conversion operators rather than
1507 std::is_convertible<const FinalAction&, Action<R(Args...)>>::value,
1509 operator Action<R(Args...)>() const { // NOLINT
1517 // Recursive case: support N actions by calling the initial action and then
1525 // The type of reference that should be provided to an initial action for a
1536 // might seem surprising for the user's initial action to need to be
1537 // convertible to Action<void(const int&)>. This is perhaps less
1586 // Both the initial action and the rest must support
1594 // Return an action that first calls the initial action with arguments
1619 // Both the initial action and the rest must support conversion to
1620 // Action.
1622 Action<void(InitialActionArgType<Args>...)>>,
1623 std::is_convertible<const Base&, Action<R(Args...)>>>::value,
1625 operator Action<R(Args...)>() const { // NOLINT
1626 // Return an action that first calls the initial action with arguments
1630 Action<void(InitialActionArgType<Args>...)> initial_action;
1631 Action<R(Args...)> remaining_actions;
1745 operator Action<R(Args...)>() const { // NOLINT
1753 operator Action<R(Args...)>() const { // NOLINT
1793 // Creates an action that does actions a1, a2, ..., sequentially in
1794 // each invocation. All but the last action will have a readonly view of the
1796 template <typename... Action>
1797 internal::DoAllAction<typename std::decay<Action>::type...> DoAll(
1798 Action&&... action) {
1799 return internal::DoAllAction<typename std::decay<Action>::type...>(
1800 {}, std::forward<Action>(action)...);
1803 // WithArg<k>(an_action) creates an action that passes the k-th
1805 // it. It adapts an action accepting one argument to one that accepts
1810 InnerAction&& action) {
1811 return {std::forward<InnerAction>(action)};
1814 // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
1820 WithArgs(InnerAction&& action) {
1821 return {std::forward<InnerAction>(action)};
1826 // argument. In other words, it adapts an action accepting no
1830 InnerAction&& action) {
1831 return {std::forward<InnerAction>(action)};
1834 // Creates an action that returns a value.
1839 // * If R is convertible to U and U is move-constructible, then the action can
1843 // action can be used with both WillOnce and WillRepeatedly.
1852 // // Return. The view is valid even after the action is performed.
1863 // Creates an action that returns NULL.
1868 // Creates an action that returns from a void function.
1873 // Creates an action that returns the reference to a variable.
1883 // Creates an action that returns the reference to a copy of the
1884 // argument. The copy is created when the action is constructed and
1885 // lives as long as the action.
1893 // Modifies the parent action (a Return() action) to perform a move of the
1902 // Creates an action that returns an element of `vals`. Calling this action will
1910 // Creates an action that returns an element of `vals`. Calling this action will
1919 // Creates an action that does the default action for the give mock function.
1924 // Creates an action that sets the variable pointed by the N-th
1937 // Creates an action that sets a pointer referent to a given value.
1945 // Creates an action that sets errno and returns the appropriate error.
1966 // Creates an action that invokes the given method on the given object
1974 // Creates an action that invokes 'function_impl' with no argument.
1981 // Creates an action that invokes the given method on the given object
1989 // Creates an action that performs an_action and throws away its
2012 // The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
2021 // Action ReturnArg<k>() returns the k-th argument of the mock function.
2027 // Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
2034 // Action SaveArgPointee<k>(pointer) saves the value pointed to
2041 // Action SetArgReferee<k>(value) assigns 'value' to the variable
2049 // Action SetArrayArgument<k>(first, last) copies the elements in
2052 // iterator. The action does not take ownership of the elements in the
2060 // Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
2067 // This action returns the value pointed to by 'pointer'.
2074 // Action Throw(exception) can be used in a mock function of any type
2085 // Action Rethrow(exception_ptr) can be used in a mock function of any type
2094 // A macro from the ACTION* family (defined later in gmock-generated-actions.h)
2095 // defines an action that can be used in a mock function. Typically,
2097 // function. For example, if such an action only uses the second
2101 // Therefore, the action implementation must be prepared to take more
2110 // Builds an implementation of an Action<> for some particular signature, using
2111 // a class defined by an ACTION* macro.
2118 // Allows each copy of the Action<> to get to the Impl.
2146 // Impl need not be specific to the signature of action being implemented;
2163 // Stores a default-constructed Impl as part of the Action<>'s
2166 ::testing::Action<F> MakeAction() {
2167 return ::testing::Action<F>(ActionImpl<F, Impl>());
2172 ::testing::Action<F> MakeAction(std::shared_ptr<Impl> impl) {
2173 return ::testing::Action<F>(ActionImpl<F, Impl>(std::move(impl)));
2227 operator ::testing::Action<F>() const { \
2262 #define ACTION(name) \
2263 class name##Action { \
2265 explicit name##Action() noexcept {} \
2266 name##Action(const name##Action&) noexcept {} \
2268 operator ::testing::Action<F>() const { \
2280 inline name##Action name() GTEST_MUST_USE_RESULT_; \
2281 inline name##Action name() { return name##Action(); } \
2284 return_type name##Action::gmock_Impl::gmock_PerformImpl( \