Commit 87061810 by Abseil Team Committed by Andy Getz

Googletest export

Move part of functionality of Matcher* class to the base one. Reduce copypaste. Make constructor and conversion operator of Matcher* class independent of pump. PiperOrigin-RevId: 291405510
parent f1a6db9d
......@@ -275,10 +275,8 @@ $var template = [[$if i==0 [[]] $else [[
template <$for j, [[typename p$j##_type]]>\
]]]]
$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
$var impl_ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
$var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::std::move(gmock_p$j))]]]]]]
$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::std::move(gmock_p$j))]]]]]]
$var params = [[$for j, [[p$j]]]]
$var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]]
$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
......@@ -294,8 +292,10 @@ $var param_field_decls2 = [[$for j
]]]]
#define $macro_name(name$for j [[, p$j]], description)\$template
class $class_name {\
class $class_name : public ::testing::internal::MatcherBaseImpl<$class_name$param_types> {\
using __internal_base_type = ::testing::internal::MatcherBaseImpl<$class_name>;\
public:\
using __internal_base_type::__internal_base_type;\
template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<\
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
......@@ -323,14 +323,6 @@ $var param_field_decls2 = [[$for j
::std::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\
}\
};\
template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>($params));\
}\
[[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {\
}\$param_field_decls2
private:\
};\$template
inline $class_name$param_types name($param_types_and_names) {\
return $class_name$param_types($params);\
......
......@@ -236,6 +236,58 @@ class MatcherCastImpl<T, Matcher<T> > {
static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; }
};
// Template specialization for parameterless Matcher.
template <typename Derived>
class MatcherBaseImpl {
public:
MatcherBaseImpl() = default;
template <typename T>
operator ::testing::Matcher<T>() const { // NOLINT(runtime/explicit)
return ::testing::Matcher<T>(new
typename Derived::template gmock_Impl<T>());
}
};
// Template specialization for Matcher with 1 parameter.
template <template <typename...> class Derived, typename T>
class MatcherBaseImpl<Derived<T>> {
public:
explicit MatcherBaseImpl(T param) : param_(std::move(param)) {}
template <typename F>
operator ::testing::Matcher<F>() const { // NOLINT(runtime/explicit)
return ::testing::Matcher<F>(
new typename Derived<T>::template gmock_Impl<F>(param_));
}
private:
const T param_;
};
// Template specialization for Matcher with multiple parameters.
template <template <typename...> class Derived, typename... Ts>
class MatcherBaseImpl<Derived<Ts...>> {
public:
MatcherBaseImpl(Ts... params)
: params_(std::move(params)...) {} // NOLINT(runtime/explicit)
template <typename F>
operator ::testing::Matcher<F>() const { // NOLINT(runtime/explicit)
return Apply<F>(MakeIndexSequence<sizeof...(Ts)>{});
}
private:
template <typename F, std::size_t... tuple_ids>
::testing::Matcher<F> Apply(IndexSequence<tuple_ids...>) const {
return ::testing::Matcher<F>(
new typename Derived<Ts...>::template gmock_Impl<F>(
std::get<tuple_ids>(params_)...));
}
const std::tuple<Ts...> params_;
};
} // namespace internal
// In order to be safe and clear, casting between different matcher
......
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