]> git-server-git.apps.pok.os.sepia.ceph.com Git - googletest.git/commitdiff
Googletest export
authorAbseil Team <absl-team@google.com>
Thu, 9 Jan 2020 16:59:39 +0000 (11:59 -0500)
committerAndy Soffer <asoffer@google.com>
Thu, 9 Jan 2020 23:25:24 +0000 (18:25 -0500)
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

googlemock/include/gmock/gmock-actions.h
googlemock/include/gmock/gmock-generated-actions.h
googlemock/include/gmock/gmock-generated-actions.h.pump

index 11223cf280a3c3519bab64e6af146573d4b8428e..a7b84d1b95b12dc9ad9f9a674174520abd844f26 100644 (file)
@@ -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
index 8257fb19ba9c80ddbb7767857025d339bf5ec87f..2db4b3c113ad85a2e4dfa4402ba763c46305dd8a 100644 (file)
           GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
 
 #define ACTION(name)\
-  class name##Action {\
+  class name##Action : public ::testing::internal::ActionImpl<name##Action> {\
+    using base_type = ::testing::internal::ActionImpl<name##Action>;\
    public:\
-    name##Action() {}\
+    using base_type::base_type;\
     template <typename F>\
     class gmock_Impl : public ::testing::ActionInterface<F> {\
      public:\
      private:\
       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
     };\
-    template <typename F> operator ::testing::Action<F>() const {\
-      return ::testing::Action<F>(new gmock_Impl<F>());\
-    }\
    private:\
     GTEST_DISALLOW_ASSIGN_(name##Action);\
   };\
 
 #define ACTION_P(name, p0)\
   template <typename p0##_type>\
-  class name##ActionP {\
+  class name##ActionP : public \
+      ::testing::internal::ActionImpl<name##ActionP<p0##_type>> {\
+    using base_type = ::testing::internal::ActionImpl<name##ActionP>;\
    public:\
-    explicit name##ActionP(p0##_type gmock_p0) : \
-        p0(::std::forward<p0##_type>(gmock_p0)) {}\
+    using base_type::base_type;\
     template <typename F>\
     class gmock_Impl : public ::testing::ActionInterface<F> {\
      public:\
      private:\
       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
     };\
-    template <typename F> operator ::testing::Action<F>() const {\
-      return ::testing::Action<F>(new gmock_Impl<F>(p0));\
-    }\
-    p0##_type p0;\
    private:\
     GTEST_DISALLOW_ASSIGN_(name##ActionP);\
   };\
 
 #define ACTION_P2(name, p0, p1)\
   template <typename p0##_type, typename p1##_type>\
-  class name##ActionP2 {\
+  class name##ActionP2 : public \
+      ::testing::internal::ActionImpl<name##ActionP2<p0##_type, \
+      p1##_type>> {\
+    using base_type = ::testing::internal::ActionImpl<name##ActionP2>;\
    public:\
-    name##ActionP2(p0##_type gmock_p0, \
-        p1##_type gmock_p1) : p0(::std::forward<p0##_type>(gmock_p0)), \
-        p1(::std::forward<p1##_type>(gmock_p1)) {}\
+    using base_type::base_type;\
     template <typename F>\
     class gmock_Impl : public ::testing::ActionInterface<F> {\
      public:\
      private:\
       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
     };\
-    template <typename F> operator ::testing::Action<F>() const {\
-      return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
-    }\
-    p0##_type p0;\
-    p1##_type p1;\
    private:\
     GTEST_DISALLOW_ASSIGN_(name##ActionP2);\
   };\
 
 #define ACTION_P3(name, p0, p1, p2)\
   template <typename p0##_type, typename p1##_type, typename p2##_type>\
-  class name##ActionP3 {\
+  class name##ActionP3 : public \
+      ::testing::internal::ActionImpl<name##ActionP3<p0##_type, p1##_type, \
+      p2##_type>> {\
+    using base_type = ::testing::internal::ActionImpl<name##ActionP3>;\
    public:\
-    name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
-        p2##_type gmock_p2) : p0(::std::forward<p0##_type>(gmock_p0)), \
-        p1(::std::forward<p1##_type>(gmock_p1)), \
-        p2(::std::forward<p2##_type>(gmock_p2)) {}\
+    using base_type::base_type;\
     template <typename F>\
     class gmock_Impl : public ::testing::ActionInterface<F> {\
      public:\
      private:\
       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
     };\
-    template <typename F> operator ::testing::Action<F>() const {\
-      return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
-    }\
-    p0##_type p0;\
-    p1##_type p1;\
-    p2##_type p2;\
    private:\
     GTEST_DISALLOW_ASSIGN_(name##ActionP3);\
   };\
 #define ACTION_P4(name, p0, p1, p2, p3)\
   template <typename p0##_type, typename p1##_type, typename p2##_type, \
       typename p3##_type>\
-  class name##ActionP4 {\
+  class name##ActionP4 : public \
+      ::testing::internal::ActionImpl<name##ActionP4<p0##_type, p1##_type, \
+      p2##_type, p3##_type>> {\
+    using base_type = ::testing::internal::ActionImpl<name##ActionP4>;\
    public:\
-    name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
-        p2##_type gmock_p2, \
-        p3##_type gmock_p3) : p0(::std::forward<p0##_type>(gmock_p0)), \
-        p1(::std::forward<p1##_type>(gmock_p1)), \
-        p2(::std::forward<p2##_type>(gmock_p2)), \
-        p3(::std::forward<p3##_type>(gmock_p3)) {}\
+    using base_type::base_type;\
     template <typename F>\
     class gmock_Impl : public ::testing::ActionInterface<F> {\
      public:\
      private:\
       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
     };\
-    template <typename F> operator ::testing::Action<F>() const {\
-      return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
-    }\
-    p0##_type p0;\
-    p1##_type p1;\
-    p2##_type p2;\
-    p3##_type p3;\
    private:\
     GTEST_DISALLOW_ASSIGN_(name##ActionP4);\
   };\
 #define ACTION_P5(name, p0, p1, p2, p3, p4)\
   template <typename p0##_type, typename p1##_type, typename p2##_type, \
       typename p3##_type, typename p4##_type>\
-  class name##ActionP5 {\
+  class name##ActionP5 : public \
+      ::testing::internal::ActionImpl<name##ActionP5<p0##_type, p1##_type, \
+      p2##_type, p3##_type, p4##_type>> {\
+    using base_type = ::testing::internal::ActionImpl<name##ActionP5>;\
    public:\
-    name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
-        p2##_type gmock_p2, p3##_type gmock_p3, \
-        p4##_type gmock_p4) : p0(::std::forward<p0##_type>(gmock_p0)), \
-        p1(::std::forward<p1##_type>(gmock_p1)), \
-        p2(::std::forward<p2##_type>(gmock_p2)), \
-        p3(::std::forward<p3##_type>(gmock_p3)), \
-        p4(::std::forward<p4##_type>(gmock_p4)) {}\
+    using base_type::base_type;\
     template <typename F>\
     class gmock_Impl : public ::testing::ActionInterface<F> {\
      public:\
      private:\
       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
     };\
-    template <typename F> operator ::testing::Action<F>() const {\
-      return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
-    }\
-    p0##_type p0;\
-    p1##_type p1;\
-    p2##_type p2;\
-    p3##_type p3;\
-    p4##_type p4;\
    private:\
     GTEST_DISALLOW_ASSIGN_(name##ActionP5);\
   };\
 #define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\
   template <typename p0##_type, typename p1##_type, typename p2##_type, \
       typename p3##_type, typename p4##_type, typename p5##_type>\
-  class name##ActionP6 {\
+  class name##ActionP6 : public \
+      ::testing::internal::ActionImpl<name##ActionP6<p0##_type, p1##_type, \
+      p2##_type, p3##_type, p4##_type, p5##_type>> {\
+    using base_type = ::testing::internal::ActionImpl<name##ActionP6>;\
    public:\
-    name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
-        p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
-        p5##_type gmock_p5) : p0(::std::forward<p0##_type>(gmock_p0)), \
-        p1(::std::forward<p1##_type>(gmock_p1)), \
-        p2(::std::forward<p2##_type>(gmock_p2)), \
-        p3(::std::forward<p3##_type>(gmock_p3)), \
-        p4(::std::forward<p4##_type>(gmock_p4)), \
-        p5(::std::forward<p5##_type>(gmock_p5)) {}\
+    using base_type::base_type;\
     template <typename F>\
     class gmock_Impl : public ::testing::ActionInterface<F> {\
      public:\
      private:\
       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
     };\
-    template <typename F> operator ::testing::Action<F>() const {\
-      return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5));\
-    }\
-    p0##_type p0;\
-    p1##_type p1;\
-    p2##_type p2;\
-    p3##_type p3;\
-    p4##_type p4;\
-    p5##_type p5;\
    private:\
     GTEST_DISALLOW_ASSIGN_(name##ActionP6);\
   };\
   template <typename p0##_type, typename p1##_type, typename p2##_type, \
       typename p3##_type, typename p4##_type, typename p5##_type, \
       typename p6##_type>\
-  class name##ActionP7 {\
+  class name##ActionP7 : public \
+      ::testing::internal::ActionImpl<name##ActionP7<p0##_type, p1##_type, \
+      p2##_type, p3##_type, p4##_type, p5##_type, p6##_type>> {\
+    using base_type = ::testing::internal::ActionImpl<name##ActionP7>;\
    public:\
-    name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
-        p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
-        p5##_type gmock_p5, \
-        p6##_type gmock_p6) : p0(::std::forward<p0##_type>(gmock_p0)), \
-        p1(::std::forward<p1##_type>(gmock_p1)), \
-        p2(::std::forward<p2##_type>(gmock_p2)), \
-        p3(::std::forward<p3##_type>(gmock_p3)), \
-        p4(::std::forward<p4##_type>(gmock_p4)), \
-        p5(::std::forward<p5##_type>(gmock_p5)), \
-        p6(::std::forward<p6##_type>(gmock_p6)) {}\
+    using base_type::base_type;\
     template <typename F>\
     class gmock_Impl : public ::testing::ActionInterface<F> {\
      public:\
      private:\
       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
     };\
-    template <typename F> operator ::testing::Action<F>() const {\
-      return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
-          p6));\
-    }\
-    p0##_type p0;\
-    p1##_type p1;\
-    p2##_type p2;\
-    p3##_type p3;\
-    p4##_type p4;\
-    p5##_type p5;\
-    p6##_type p6;\
    private:\
     GTEST_DISALLOW_ASSIGN_(name##ActionP7);\
   };\
   template <typename p0##_type, typename p1##_type, typename p2##_type, \
       typename p3##_type, typename p4##_type, typename p5##_type, \
       typename p6##_type, typename p7##_type>\
-  class name##ActionP8 {\
+  class name##ActionP8 : public \
+      ::testing::internal::ActionImpl<name##ActionP8<p0##_type, p1##_type, \
+      p2##_type, p3##_type, p4##_type, p5##_type, p6##_type, p7##_type>> {\
+    using base_type = ::testing::internal::ActionImpl<name##ActionP8>;\
    public:\
-    name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
-        p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
-        p5##_type gmock_p5, p6##_type gmock_p6, \
-        p7##_type gmock_p7) : p0(::std::forward<p0##_type>(gmock_p0)), \
-        p1(::std::forward<p1##_type>(gmock_p1)), \
-        p2(::std::forward<p2##_type>(gmock_p2)), \
-        p3(::std::forward<p3##_type>(gmock_p3)), \
-        p4(::std::forward<p4##_type>(gmock_p4)), \
-        p5(::std::forward<p5##_type>(gmock_p5)), \
-        p6(::std::forward<p6##_type>(gmock_p6)), \
-        p7(::std::forward<p7##_type>(gmock_p7)) {}\
+    using base_type::base_type;\
     template <typename F>\
     class gmock_Impl : public ::testing::ActionInterface<F> {\
      public:\
      private:\
       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
     };\
-    template <typename F> operator ::testing::Action<F>() const {\
-      return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
-          p6, p7));\
-    }\
-    p0##_type p0;\
-    p1##_type p1;\
-    p2##_type p2;\
-    p3##_type p3;\
-    p4##_type p4;\
-    p5##_type p5;\
-    p6##_type p6;\
-    p7##_type p7;\
    private:\
     GTEST_DISALLOW_ASSIGN_(name##ActionP8);\
   };\
   template <typename p0##_type, typename p1##_type, typename p2##_type, \
       typename p3##_type, typename p4##_type, typename p5##_type, \
       typename p6##_type, typename p7##_type, typename p8##_type>\
-  class name##ActionP9 {\
+  class name##ActionP9 : public \
+      ::testing::internal::ActionImpl<name##ActionP9<p0##_type, p1##_type, \
+      p2##_type, p3##_type, p4##_type, p5##_type, p6##_type, p7##_type, \
+      p8##_type>> {\
+    using base_type = ::testing::internal::ActionImpl<name##ActionP9>;\
    public:\
-    name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
-        p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
-        p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
-        p8##_type gmock_p8) : p0(::std::forward<p0##_type>(gmock_p0)), \
-        p1(::std::forward<p1##_type>(gmock_p1)), \
-        p2(::std::forward<p2##_type>(gmock_p2)), \
-        p3(::std::forward<p3##_type>(gmock_p3)), \
-        p4(::std::forward<p4##_type>(gmock_p4)), \
-        p5(::std::forward<p5##_type>(gmock_p5)), \
-        p6(::std::forward<p6##_type>(gmock_p6)), \
-        p7(::std::forward<p7##_type>(gmock_p7)), \
-        p8(::std::forward<p8##_type>(gmock_p8)) {}\
+    using base_type::base_type;\
     template <typename F>\
     class gmock_Impl : public ::testing::ActionInterface<F> {\
      public:\
      private:\
       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
     };\
-    template <typename F> operator ::testing::Action<F>() const {\
-      return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
-          p6, p7, p8));\
-    }\
-    p0##_type p0;\
-    p1##_type p1;\
-    p2##_type p2;\
-    p3##_type p3;\
-    p4##_type p4;\
-    p5##_type p5;\
-    p6##_type p6;\
-    p7##_type p7;\
-    p8##_type p8;\
    private:\
     GTEST_DISALLOW_ASSIGN_(name##ActionP9);\
   };\
       typename p3##_type, typename p4##_type, typename p5##_type, \
       typename p6##_type, typename p7##_type, typename p8##_type, \
       typename p9##_type>\
-  class name##ActionP10 {\
+  class name##ActionP10 : public \
+      ::testing::internal::ActionImpl<name##ActionP10<p0##_type, p1##_type, \
+      p2##_type, p3##_type, p4##_type, p5##_type, p6##_type, p7##_type, \
+      p8##_type, p9##_type>> {\
+    using base_type = ::testing::internal::ActionImpl<name##ActionP10>;\
    public:\
-    name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
-        p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
-        p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
-        p8##_type gmock_p8, \
-        p9##_type gmock_p9) : p0(::std::forward<p0##_type>(gmock_p0)), \
-        p1(::std::forward<p1##_type>(gmock_p1)), \
-        p2(::std::forward<p2##_type>(gmock_p2)), \
-        p3(::std::forward<p3##_type>(gmock_p3)), \
-        p4(::std::forward<p4##_type>(gmock_p4)), \
-        p5(::std::forward<p5##_type>(gmock_p5)), \
-        p6(::std::forward<p6##_type>(gmock_p6)), \
-        p7(::std::forward<p7##_type>(gmock_p7)), \
-        p8(::std::forward<p8##_type>(gmock_p8)), \
-        p9(::std::forward<p9##_type>(gmock_p9)) {}\
+    using base_type::base_type;\
     template <typename F>\
     class gmock_Impl : public ::testing::ActionInterface<F> {\
      public:\
      private:\
       GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
     };\
-    template <typename F> operator ::testing::Action<F>() const {\
-      return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
-          p6, p7, p8, p9));\
-    }\
-    p0##_type p0;\
-    p1##_type p1;\
-    p2##_type p2;\
-    p3##_type p3;\
-    p4##_type p4;\
-    p5##_type p5;\
-    p6##_type p6;\
-    p7##_type p7;\
-    p8##_type p8;\
-    p9##_type p9;\
    private:\
     GTEST_DISALLOW_ASSIGN_(name##ActionP10);\
   };\
index bd3eadb9eb06e51053420a8b114d3e7272ce55b5..45751c680bf81b49d6943fc860aa39d5a4207c72 100644 (file)
@@ -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