// GOOGLETEST_CM0002 DO NOT DELETE #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ #include "gmock/internal/gmock-port.h" #if GTEST_GOOGLE3_MODE_ #include #include #include "base/callback.h" #include "gmock/gmock-actions.h" namespace testing { namespace internal { // Implements the Invoke(callback) action. template class InvokeCallbackAction; template class InvokeCallbackAction { public: // The c'tor takes ownership of the callback. explicit InvokeCallbackAction(CallbackType* callback) : callback_(callback) { callback->CheckIsRepeatable(); // Makes sure the callback is permanent. } R operator()(Args... args) const { return callback_->Run(std::forward(args)...); } private: const std::shared_ptr callback_; }; // Implements the InvokeWithoutArgs(callback) action. template class InvokeCallbackWithoutArgsAction { const std::shared_ptr callback_; public: // The c'tor takes ownership of the callback. explicit InvokeCallbackWithoutArgsAction(CallbackType* callback) : callback_(callback) { callback->CheckIsRepeatable(); // Makes sure the callback is permanent. } template auto operator()(const Args&...) -> decltype(this->callback_->Run()) { return callback_->Run(); } }; template struct TypeIdentity { using type = T; }; inline TypeIdentity CallbackSignatureImpl(Closure*); template TypeIdentity CallbackSignatureImpl(ResultCallback*); template TypeIdentity CallbackSignatureImpl(Callback1*); template TypeIdentity CallbackSignatureImpl(ResultCallback1*); template TypeIdentity CallbackSignatureImpl(Callback2*); template TypeIdentity CallbackSignatureImpl(ResultCallback2*); template TypeIdentity CallbackSignatureImpl(Callback3*); template TypeIdentity CallbackSignatureImpl(ResultCallback3*); template TypeIdentity CallbackSignatureImpl(Callback4*); template TypeIdentity CallbackSignatureImpl(ResultCallback4*); template TypeIdentity CallbackSignatureImpl(Callback5*); template TypeIdentity CallbackSignatureImpl(ResultCallback5*); template using CallbackSignature = typename decltype( internal::CallbackSignatureImpl(std::declval()))::type; // Specialization for protocol buffers. // We support setting a proto2::Message, which doesn't have an assignment // operator. template struct SetArgumentPointeeAction< N, A, typename std::enable_if::value>::type> { A value; template void operator()(const Args&... args) const { ::std::get(std::tie(args...))->CopyFrom(value); } }; // Add Invoke overloads for google3 Callback types. template > auto InvokeArgument(C* cb, Args... args) -> decltype(cb->Run(args...)) { return cb->Run(args...); } } // namespace internal // Add Invoke overloads for google3 Callback types. // Creates an action that invokes the given callback with the mock // function's arguments. The action takes ownership of the callback // and verifies that it's permanent. // // google3 doesn't support callbacks with more than 5 // arguments yet, so we only support invoking callbacks with up to // 5 arguments. template internal::InvokeCallbackAction> Invoke(Callback* callback) { return internal::InvokeCallbackAction>( callback); } // Creates an action that invokes the given callback with no argument. // The action takes ownership of the callback and verifies that it's // permanent. template > internal::InvokeCallbackWithoutArgsAction InvokeWithoutArgs( Callback* callback) { return internal::InvokeCallbackWithoutArgsAction(callback); } } // namespace testing #endif // GTEST_GOOGLE3_MODE_ #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_