Googletest export
Stop using pump for generating internal/custom/gmock-generated-actions.h PiperOrigin-RevId: 352660735
This commit is contained in:
		@@ -1,149 +1,6 @@
 | 
			
		||||
// 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 <memory>
 | 
			
		||||
#include <type_traits>
 | 
			
		||||
 | 
			
		||||
#include "base/callback.h"
 | 
			
		||||
#include "gmock/gmock-actions.h"
 | 
			
		||||
 | 
			
		||||
namespace testing {
 | 
			
		||||
namespace internal {
 | 
			
		||||
 | 
			
		||||
// Implements the Invoke(callback) action.
 | 
			
		||||
template <typename CallbackType, typename Signature>
 | 
			
		||||
class InvokeCallbackAction;
 | 
			
		||||
 | 
			
		||||
template <typename CallbackType, typename R, typename... Args>
 | 
			
		||||
class InvokeCallbackAction<CallbackType, R(Args...)> {
 | 
			
		||||
 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>(args)...);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  const std::shared_ptr<CallbackType> callback_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Implements the InvokeWithoutArgs(callback) action.
 | 
			
		||||
template <typename CallbackType>
 | 
			
		||||
class InvokeCallbackWithoutArgsAction {
 | 
			
		||||
  const std::shared_ptr<CallbackType> 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 <typename... Args>
 | 
			
		||||
  auto operator()(const Args&...) -> decltype(this->callback_->Run()) {
 | 
			
		||||
    return callback_->Run();
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
struct TypeIdentity {
 | 
			
		||||
  using type = T;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
inline TypeIdentity<void()> CallbackSignatureImpl(Closure*);
 | 
			
		||||
template <typename R>
 | 
			
		||||
TypeIdentity<R()> CallbackSignatureImpl(ResultCallback<R>*);
 | 
			
		||||
 | 
			
		||||
template <typename... Args>
 | 
			
		||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback1<Args...>*);
 | 
			
		||||
template <typename R, typename... Args>
 | 
			
		||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback1<R, Args...>*);
 | 
			
		||||
 | 
			
		||||
template <typename... Args>
 | 
			
		||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback2<Args...>*);
 | 
			
		||||
template <typename R, typename... Args>
 | 
			
		||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback2<R, Args...>*);
 | 
			
		||||
 | 
			
		||||
template <typename... Args>
 | 
			
		||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback3<Args...>*);
 | 
			
		||||
template <typename R, typename... Args>
 | 
			
		||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback3<R, Args...>*);
 | 
			
		||||
 | 
			
		||||
template <typename... Args>
 | 
			
		||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback4<Args...>*);
 | 
			
		||||
template <typename R, typename... Args>
 | 
			
		||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback4<R, Args...>*);
 | 
			
		||||
 | 
			
		||||
template <typename... Args>
 | 
			
		||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback5<Args...>*);
 | 
			
		||||
template <typename R, typename... Args>
 | 
			
		||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback5<R, Args...>*);
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
using CallbackSignature = typename decltype(
 | 
			
		||||
    internal::CallbackSignatureImpl(std::declval<T*>()))::type;
 | 
			
		||||
 | 
			
		||||
// Specialization for protocol buffers.
 | 
			
		||||
// We support setting a proto2::Message, which doesn't have an assignment
 | 
			
		||||
// operator.
 | 
			
		||||
template <size_t N, typename A>
 | 
			
		||||
struct SetArgumentPointeeAction<
 | 
			
		||||
    N, A,
 | 
			
		||||
    typename std::enable_if<std::is_base_of<proto2::Message, A>::value>::type> {
 | 
			
		||||
  A value;
 | 
			
		||||
 | 
			
		||||
  template <typename... Args>
 | 
			
		||||
  void operator()(const Args&... args) const {
 | 
			
		||||
    ::std::get<N>(std::tie(args...))->CopyFrom(value);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Add Invoke overloads for google3 Callback types.
 | 
			
		||||
 | 
			
		||||
template <typename C, typename... Args,
 | 
			
		||||
          typename = internal::CallbackSignature<C>>
 | 
			
		||||
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 <typename Callback>
 | 
			
		||||
internal::InvokeCallbackAction<Callback, internal::CallbackSignature<Callback>>
 | 
			
		||||
Invoke(Callback* callback) {
 | 
			
		||||
  return internal::InvokeCallbackAction<Callback,
 | 
			
		||||
                                        internal::CallbackSignature<Callback>>(
 | 
			
		||||
      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 <typename Callback, typename = internal::CallbackSignature<Callback>>
 | 
			
		||||
internal::InvokeCallbackWithoutArgsAction<Callback> InvokeWithoutArgs(
 | 
			
		||||
    Callback* callback) {
 | 
			
		||||
  return internal::InvokeCallbackWithoutArgsAction<Callback>(callback);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace testing
 | 
			
		||||
 | 
			
		||||
#endif  // GTEST_GOOGLE3_MODE_
 | 
			
		||||
 | 
			
		||||
#endif  // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
$$ -*- mode: c++; -*-
 | 
			
		||||
$$ This is a Pump source file. Please use Pump to convert
 | 
			
		||||
$$ it to callback-actions.h.
 | 
			
		||||
$$
 | 
			
		||||
$var max_callback_arity = 5
 | 
			
		||||
$$}} This meta comment fixes auto-indentation in editors.
 | 
			
		||||
 | 
			
		||||
// 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_
 | 
			
		||||
 | 
			
		||||
#endif  // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
 | 
			
		||||
@@ -33,39 +33,4 @@
 | 
			
		||||
 | 
			
		||||
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
 | 
			
		||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
 | 
			
		||||
 | 
			
		||||
#include <memory>
 | 
			
		||||
 | 
			
		||||
#include "gmock/internal/gmock-port.h"
 | 
			
		||||
#if GTEST_GOOGLE3_MODE_
 | 
			
		||||
#include "base/callback.h"
 | 
			
		||||
 | 
			
		||||
// Realistically this file should be included from gmock-matchers.h
 | 
			
		||||
#include "gmock/gmock-matchers.h"
 | 
			
		||||
 | 
			
		||||
namespace testing {
 | 
			
		||||
namespace internal {
 | 
			
		||||
 | 
			
		||||
// Specialization for permanent callbacks.
 | 
			
		||||
template <typename ArgType, typename ResType>
 | 
			
		||||
struct CallableTraits<ResultCallback1<ResType, ArgType>*> {
 | 
			
		||||
  typedef ResType ResultType;
 | 
			
		||||
  using StorageType = std::shared_ptr<ResultCallback1<ResType, ArgType>>;
 | 
			
		||||
  typedef ResultCallback1<ResType, ArgType> Callback;
 | 
			
		||||
 | 
			
		||||
  static void CheckIsValid(const StorageType& callback) {
 | 
			
		||||
    GTEST_CHECK_(callback != nullptr)
 | 
			
		||||
        << "NULL callback is passed into ResultOf().";
 | 
			
		||||
    callback->CheckIsRepeatable();
 | 
			
		||||
  }
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  static ResType Invoke(const StorageType& callback, T arg) {
 | 
			
		||||
    return callback->Run(arg);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace internal
 | 
			
		||||
}  // namespace testing
 | 
			
		||||
#endif  // GTEST_GOOGLE3_MODE_
 | 
			
		||||
 | 
			
		||||
#endif  // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
 | 
			
		||||
 
 | 
			
		||||
@@ -36,29 +36,4 @@
 | 
			
		||||
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
 | 
			
		||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
 | 
			
		||||
 | 
			
		||||
#include "gtest/internal/gtest-port.h"
 | 
			
		||||
 | 
			
		||||
#if GTEST_GOOGLE3_MODE_
 | 
			
		||||
 | 
			
		||||
// Defines this iff Google Mock can use google3 callbacks.  This is
 | 
			
		||||
// internal as a user shouldn't rely on Google Mock to tell him
 | 
			
		||||
// whether he can use google3 callbacks.
 | 
			
		||||
# include "base/callback.h"
 | 
			
		||||
# define GMOCK_HAS_GOOGLE3_CALLBACK_ 1
 | 
			
		||||
 | 
			
		||||
// Macros for declaring flags.
 | 
			
		||||
# define GMOCK_DECLARE_bool_(name)   DECLARE_bool(gmock_##name)
 | 
			
		||||
# define GMOCK_DECLARE_int32_(name)  DECLARE_int32(gmock_##name)
 | 
			
		||||
# define GMOCK_DECLARE_string_(name) DECLARE_string(gmock_##name)
 | 
			
		||||
 | 
			
		||||
// Macros for defining flags.
 | 
			
		||||
# define GMOCK_DEFINE_bool_(name, default_val, doc) \
 | 
			
		||||
    DEFINE_bool(gmock_##name, default_val, doc)
 | 
			
		||||
# define GMOCK_DEFINE_int32_(name, default_val, doc) \
 | 
			
		||||
    DEFINE_int32(gmock_##name, default_val, doc)
 | 
			
		||||
# define GMOCK_DEFINE_string_(name, default_val, doc) \
 | 
			
		||||
    DEFINE_string(gmock_##name, default_val, doc)
 | 
			
		||||
 | 
			
		||||
#endif  // GTEST_GOOGLE3_MODE_
 | 
			
		||||
 | 
			
		||||
#endif  // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user