Commit c901f67d by Abseil Team Committed by Andy Soffer

Googletest export

Move part of functionality of Action* class to the base one. Reduce copypaste. Make constructor and conversion operator of Action* class independent of pump. PiperOrigin-RevId: 288907005
parent 8417b733
......@@ -1222,6 +1222,43 @@ class ActionHelper {
}
};
// A helper base class needed for implementing the ACTION* macros.
// Implements constructor and conversion operator for Action.
//
// Template specialization for parameterless Action.
template <typename Derived>
class ActionImpl {
public:
ActionImpl() = default;
template <typename F>
operator ::testing::Action<F>() const { // NOLINT(runtime/explicit)
return ::testing::Action<F>(new typename Derived::template gmock_Impl<F>());
}
};
// Template specialization for parameterized Action.
template <template <typename...> class Derived, typename... Ts>
class ActionImpl<Derived<Ts...>> {
public:
explicit ActionImpl(Ts... params) : params_(std::forward<Ts>(params)...) {}
template <typename F>
operator ::testing::Action<F>() const { // NOLINT(runtime/explicit)
return Apply<F>(MakeIndexSequence<sizeof...(Ts)>{});
}
private:
template <typename F, std::size_t... tuple_ids>
::testing::Action<F> Apply(IndexSequence<tuple_ids...>) const {
return ::testing::Action<F>(new
typename Derived<Ts...>::template gmock_Impl<F>(
std::get<tuple_ids>(params_)...));
}
std::tuple<Ts...> params_;
};
namespace invoke_argument {
// Appears in InvokeArgumentAdl's argument list to help avoid
......
......@@ -423,9 +423,10 @@ $var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]]
$else [[ACTION_P$i]]]]
#define $macro_name(name$for j [[, p$j]])\$template
class $class_name {\
class $class_name : public ::testing::internal::ActionImpl<$class_name$param_types> {\
using base_type = ::testing::internal::ActionImpl<$class_name>;\
public:\
[[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {}\
using base_type::base_type;\
template <typename F>\
class gmock_Impl : public ::testing::ActionInterface<F> {\
public:\
......@@ -444,9 +445,6 @@ $arg_types_and_names) const;\$param_field_decls
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\
template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>($params));\
}\$param_field_decls2
private:\
GTEST_DISALLOW_ASSIGN_($class_name);\
};\$template
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment