diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/gmock/gmock-actions.h | 8 | ||||
-rw-r--r-- | include/gmock/gmock-cardinalities.h | 1 | ||||
-rw-r--r-- | include/gmock/gmock-generated-actions.h | 27 | ||||
-rw-r--r-- | include/gmock/gmock-generated-actions.h.pump | 9 | ||||
-rw-r--r-- | include/gmock/gmock-generated-matchers.h | 488 | ||||
-rw-r--r-- | include/gmock/gmock-generated-matchers.h.pump | 110 | ||||
-rw-r--r-- | include/gmock/gmock-matchers.h | 185 | ||||
-rw-r--r-- | include/gmock/gmock-spec-builders.h | 1 | ||||
-rw-r--r-- | include/gmock/internal/gmock-generated-internal-utils.h | 6 | ||||
-rw-r--r-- | include/gmock/internal/gmock-generated-internal-utils.h.pump | 2 | ||||
-rw-r--r-- | include/gmock/internal/gmock-internal-utils.h | 8 |
11 files changed, 553 insertions, 292 deletions
diff --git a/include/gmock/gmock-actions.h b/include/gmock/gmock-actions.h index d6a3e148..7e9708ec 100644 --- a/include/gmock/gmock-actions.h +++ b/include/gmock/gmock-actions.h @@ -36,13 +36,13 @@ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ -#include <algorithm> -#include <string> - #ifndef _WIN32_WCE # include <errno.h> #endif +#include <algorithm> +#include <string> + #include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-port.h" @@ -189,6 +189,7 @@ class DefaultValue { return value_ == NULL ? internal::BuiltInDefaultValue<T>::Get() : *value_; } + private: static const T* value_; }; @@ -224,6 +225,7 @@ class DefaultValue<T&> { return address_ == NULL ? internal::BuiltInDefaultValue<T&>::Get() : *address_; } + private: static T* address_; }; diff --git a/include/gmock/gmock-cardinalities.h b/include/gmock/gmock-cardinalities.h index 759dcf8c..fc315f92 100644 --- a/include/gmock/gmock-cardinalities.h +++ b/include/gmock/gmock-cardinalities.h @@ -117,6 +117,7 @@ class GTEST_API_ Cardinality { // Describes the given actual call count to an ostream. static void DescribeActualCallCountTo(int actual_call_count, ::std::ostream* os); + private: internal::linked_ptr<const CardinalityInterface> impl_; }; diff --git a/include/gmock/gmock-generated-actions.h b/include/gmock/gmock-generated-actions.h index 635bb595..3b599b36 100644 --- a/include/gmock/gmock-generated-actions.h +++ b/include/gmock/gmock-generated-actions.h @@ -381,7 +381,6 @@ class CallableHelper { A7 a7, A8 a8, A9 a9, A10 a10) { return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); } - }; // class CallableHelper // An INTERNAL macro for extracting the type of a tuple field. It's @@ -1018,16 +1017,16 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, // An internal macro needed for implementing ACTION*(). #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\ - const args_type& args GTEST_ATTRIBUTE_UNUSED_,\ - arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_,\ - arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_,\ - arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_,\ - arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_,\ - arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_,\ - arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_,\ - arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_,\ - arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_,\ - arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_,\ + const args_type& args GTEST_ATTRIBUTE_UNUSED_, \ + arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_, \ + arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_, \ + arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_, \ + arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_, \ + arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_, \ + arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_, \ + arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_, \ + arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_, \ + arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_, \ arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_ // Sometimes you want to give an action explicit template parameters @@ -1433,9 +1432,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, template <GMOCK_INTERNAL_DECL_##template_params\ GMOCK_INTERNAL_DECL_TYPE_##value_params>\ template <typename F>\ - template <typename arg0_type, typename arg1_type, typename arg2_type,\ - typename arg3_type, typename arg4_type, typename arg5_type,\ - typename arg6_type, typename arg7_type, typename arg8_type,\ + template <typename arg0_type, typename arg1_type, typename arg2_type, \ + typename arg3_type, typename arg4_type, typename arg5_type, \ + typename arg6_type, typename arg7_type, typename arg8_type, \ typename arg9_type>\ typename ::testing::internal::Function<F>::Result\ GMOCK_ACTION_CLASS_(name, value_params)<\ diff --git a/include/gmock/gmock-generated-actions.h.pump b/include/gmock/gmock-generated-actions.h.pump index 001fd7d0..57a7811a 100644 --- a/include/gmock/gmock-generated-actions.h.pump +++ b/include/gmock/gmock-generated-actions.h.pump @@ -136,7 +136,6 @@ $var Ts = [[$for j, [[T$j]]]] } ]] - }; // class CallableHelper // An INTERNAL macro for extracting the type of a tuple field. It's @@ -427,7 +426,7 @@ $range k 0..n-1 // An internal macro needed for implementing ACTION*(). #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\ const args_type& args GTEST_ATTRIBUTE_UNUSED_ -$for k [[,\ +$for k [[, \ arg$k[[]]_type arg$k GTEST_ATTRIBUTE_UNUSED_]] @@ -657,9 +656,9 @@ $for k [[, arg$k[[]]_type arg$k]]) const;\ template <GMOCK_INTERNAL_DECL_##template_params\ GMOCK_INTERNAL_DECL_TYPE_##value_params>\ template <typename F>\ - template <typename arg0_type, typename arg1_type, typename arg2_type,\ - typename arg3_type, typename arg4_type, typename arg5_type,\ - typename arg6_type, typename arg7_type, typename arg8_type,\ + template <typename arg0_type, typename arg1_type, typename arg2_type, \ + typename arg3_type, typename arg4_type, typename arg5_type, \ + typename arg6_type, typename arg7_type, typename arg8_type, \ typename arg9_type>\ typename ::testing::internal::Function<F>::Result\ GMOCK_ACTION_CLASS_(name, value_params)<\ diff --git a/include/gmock/gmock-generated-matchers.h b/include/gmock/gmock-generated-matchers.h index 6feaf1a2..5527ed3e 100644 --- a/include/gmock/gmock-generated-matchers.h +++ b/include/gmock/gmock-generated-matchers.h @@ -661,6 +661,182 @@ class ElementsAreMatcher10 { GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher10); }; +// A set of metafunctions for computing the result type of AllOf. +// AllOf(m1, ..., mN) returns +// AllOfResultN<decltype(m1), ..., decltype(mN)>::type. + +// Although AllOf isn't defined for one argument, AllOfResult1 is defined +// to simplify the implementation. +template <typename M1> +struct AllOfResult1 { + typedef M1 type; +}; + +template <typename M1, typename M2> +struct AllOfResult2 { + typedef BothOfMatcher< + typename AllOfResult1<M1>::type, + typename AllOfResult1<M2>::type + > type; +}; + +template <typename M1, typename M2, typename M3> +struct AllOfResult3 { + typedef BothOfMatcher< + typename AllOfResult1<M1>::type, + typename AllOfResult2<M2, M3>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4> +struct AllOfResult4 { + typedef BothOfMatcher< + typename AllOfResult2<M1, M2>::type, + typename AllOfResult2<M3, M4>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5> +struct AllOfResult5 { + typedef BothOfMatcher< + typename AllOfResult2<M1, M2>::type, + typename AllOfResult3<M3, M4, M5>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6> +struct AllOfResult6 { + typedef BothOfMatcher< + typename AllOfResult3<M1, M2, M3>::type, + typename AllOfResult3<M4, M5, M6>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7> +struct AllOfResult7 { + typedef BothOfMatcher< + typename AllOfResult3<M1, M2, M3>::type, + typename AllOfResult4<M4, M5, M6, M7>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8> +struct AllOfResult8 { + typedef BothOfMatcher< + typename AllOfResult4<M1, M2, M3, M4>::type, + typename AllOfResult4<M5, M6, M7, M8>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8, typename M9> +struct AllOfResult9 { + typedef BothOfMatcher< + typename AllOfResult4<M1, M2, M3, M4>::type, + typename AllOfResult5<M5, M6, M7, M8, M9>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8, typename M9, typename M10> +struct AllOfResult10 { + typedef BothOfMatcher< + typename AllOfResult5<M1, M2, M3, M4, M5>::type, + typename AllOfResult5<M6, M7, M8, M9, M10>::type + > type; +}; + +// A set of metafunctions for computing the result type of AnyOf. +// AnyOf(m1, ..., mN) returns +// AnyOfResultN<decltype(m1), ..., decltype(mN)>::type. + +// Although AnyOf isn't defined for one argument, AnyOfResult1 is defined +// to simplify the implementation. +template <typename M1> +struct AnyOfResult1 { + typedef M1 type; +}; + +template <typename M1, typename M2> +struct AnyOfResult2 { + typedef EitherOfMatcher< + typename AnyOfResult1<M1>::type, + typename AnyOfResult1<M2>::type + > type; +}; + +template <typename M1, typename M2, typename M3> +struct AnyOfResult3 { + typedef EitherOfMatcher< + typename AnyOfResult1<M1>::type, + typename AnyOfResult2<M2, M3>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4> +struct AnyOfResult4 { + typedef EitherOfMatcher< + typename AnyOfResult2<M1, M2>::type, + typename AnyOfResult2<M3, M4>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5> +struct AnyOfResult5 { + typedef EitherOfMatcher< + typename AnyOfResult2<M1, M2>::type, + typename AnyOfResult3<M3, M4, M5>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6> +struct AnyOfResult6 { + typedef EitherOfMatcher< + typename AnyOfResult3<M1, M2, M3>::type, + typename AnyOfResult3<M4, M5, M6>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7> +struct AnyOfResult7 { + typedef EitherOfMatcher< + typename AnyOfResult3<M1, M2, M3>::type, + typename AnyOfResult4<M4, M5, M6, M7>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8> +struct AnyOfResult8 { + typedef EitherOfMatcher< + typename AnyOfResult4<M1, M2, M3, M4>::type, + typename AnyOfResult4<M5, M6, M7, M8>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8, typename M9> +struct AnyOfResult9 { + typedef EitherOfMatcher< + typename AnyOfResult4<M1, M2, M3, M4>::type, + typename AnyOfResult5<M5, M6, M7, M8, M9>::type + > type; +}; + +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8, typename M9, typename M10> +struct AnyOfResult10 { + typedef EitherOfMatcher< + typename AnyOfResult5<M1, M2, M3, M4, M5>::type, + typename AnyOfResult5<M6, M7, M8, M9, M10>::type + > type; +}; + } // namespace internal // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected @@ -852,187 +1028,167 @@ ElementsAreArray(const T (&array)[N]) { // AllOf(m1, m2, ..., mk) matches any value that matches all of the given // sub-matchers. AllOf is called fully qualified to prevent ADL from firing. -template <typename Matcher1, typename Matcher2> -inline internal::BothOfMatcher<Matcher1, Matcher2> -AllOf(Matcher1 m1, Matcher2 m2) { - return internal::BothOfMatcher<Matcher1, Matcher2>(m1, m2); +template <typename M1, typename M2> +inline typename internal::AllOfResult2<M1, M2>::type +AllOf(M1 m1, M2 m2) { + return typename internal::AllOfResult2<M1, M2>::type( + m1, + m2); } -template <typename Matcher1, typename Matcher2, typename Matcher3> -inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, - Matcher3> > -AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) { - return ::testing::AllOf(m1, ::testing::AllOf(m2, m3)); +template <typename M1, typename M2, typename M3> +inline typename internal::AllOfResult3<M1, M2, M3>::type +AllOf(M1 m1, M2 m2, M3 m3) { + return typename internal::AllOfResult3<M1, M2, M3>::type( + m1, + ::testing::AllOf(m2, m3)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4> -inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, - internal::BothOfMatcher<Matcher3, Matcher4> > > -AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) { - return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4)); +template <typename M1, typename M2, typename M3, typename M4> +inline typename internal::AllOfResult4<M1, M2, M3, M4>::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4) { + return typename internal::AllOfResult4<M1, M2, M3, M4>::type( + ::testing::AllOf(m1, m2), + ::testing::AllOf(m3, m4)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5> -inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, - internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, - Matcher5> > > > -AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) { - return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5)); +template <typename M1, typename M2, typename M3, typename M4, typename M5> +inline typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) { + return typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type( + ::testing::AllOf(m1, m2), + ::testing::AllOf(m3, m4, m5)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5, typename Matcher6> -inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, - internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, - internal::BothOfMatcher<Matcher5, Matcher6> > > > > -AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, - Matcher6 m6) { - return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6)); +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6> +inline typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) { + return typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type( + ::testing::AllOf(m1, m2, m3), + ::testing::AllOf(m4, m5, m6)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7> -inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, - internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, - internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6, - Matcher7> > > > > > -AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, - Matcher6 m6, Matcher7 m7) { - return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7)); +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7> +inline typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) { + return typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type( + ::testing::AllOf(m1, m2, m3), + ::testing::AllOf(m4, m5, m6, m7)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, - typename Matcher8> -inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, - internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, - internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6, - internal::BothOfMatcher<Matcher7, Matcher8> > > > > > > -AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, - Matcher6 m6, Matcher7 m7, Matcher8 m8) { - return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8)); +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8> +inline typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) { + return typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type( + ::testing::AllOf(m1, m2, m3, m4), + ::testing::AllOf(m5, m6, m7, m8)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, - typename Matcher8, typename Matcher9> -inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, - internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, - internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6, - internal::BothOfMatcher<Matcher7, internal::BothOfMatcher<Matcher8, - Matcher9> > > > > > > > -AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, - Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9) { - return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8, m9)); +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8, typename M9> +inline typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) { + return typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, + M9>::type( + ::testing::AllOf(m1, m2, m3, m4), + ::testing::AllOf(m5, m6, m7, m8, m9)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, - typename Matcher8, typename Matcher9, typename Matcher10> -inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, - internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, - internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6, - internal::BothOfMatcher<Matcher7, internal::BothOfMatcher<Matcher8, - internal::BothOfMatcher<Matcher9, Matcher10> > > > > > > > > -AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, - Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9, Matcher10 m10) { - return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8, m9, - m10)); +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8, typename M9, typename M10> +inline typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9, + M10>::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { + return typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9, + M10>::type( + ::testing::AllOf(m1, m2, m3, m4, m5), + ::testing::AllOf(m6, m7, m8, m9, m10)); } // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given // sub-matchers. AnyOf is called fully qualified to prevent ADL from firing. -template <typename Matcher1, typename Matcher2> -inline internal::EitherOfMatcher<Matcher1, Matcher2> -AnyOf(Matcher1 m1, Matcher2 m2) { - return internal::EitherOfMatcher<Matcher1, Matcher2>(m1, m2); +template <typename M1, typename M2> +inline typename internal::AnyOfResult2<M1, M2>::type +AnyOf(M1 m1, M2 m2) { + return typename internal::AnyOfResult2<M1, M2>::type( + m1, + m2); } -template <typename Matcher1, typename Matcher2, typename Matcher3> -inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, - Matcher3> > -AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) { - return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3)); +template <typename M1, typename M2, typename M3> +inline typename internal::AnyOfResult3<M1, M2, M3>::type +AnyOf(M1 m1, M2 m2, M3 m3) { + return typename internal::AnyOfResult3<M1, M2, M3>::type( + m1, + ::testing::AnyOf(m2, m3)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4> -inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, - internal::EitherOfMatcher<Matcher3, Matcher4> > > -AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) { - return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4)); +template <typename M1, typename M2, typename M3, typename M4> +inline typename internal::AnyOfResult4<M1, M2, M3, M4>::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4) { + return typename internal::AnyOfResult4<M1, M2, M3, M4>::type( + ::testing::AnyOf(m1, m2), + ::testing::AnyOf(m3, m4)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5> -inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, - internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, - Matcher5> > > > -AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) { - return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5)); +template <typename M1, typename M2, typename M3, typename M4, typename M5> +inline typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) { + return typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type( + ::testing::AnyOf(m1, m2), + ::testing::AnyOf(m3, m4, m5)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5, typename Matcher6> -inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, - internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, - internal::EitherOfMatcher<Matcher5, Matcher6> > > > > -AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, - Matcher6 m6) { - return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6)); +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6> +inline typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) { + return typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type( + ::testing::AnyOf(m1, m2, m3), + ::testing::AnyOf(m4, m5, m6)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7> -inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, - internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, - internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6, - Matcher7> > > > > > -AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, - Matcher6 m6, Matcher7 m7) { - return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7)); +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7> +inline typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) { + return typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type( + ::testing::AnyOf(m1, m2, m3), + ::testing::AnyOf(m4, m5, m6, m7)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, - typename Matcher8> -inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, - internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, - internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6, - internal::EitherOfMatcher<Matcher7, Matcher8> > > > > > > -AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, - Matcher6 m6, Matcher7 m7, Matcher8 m8) { - return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8)); +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8> +inline typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) { + return typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type( + ::testing::AnyOf(m1, m2, m3, m4), + ::testing::AnyOf(m5, m6, m7, m8)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, - typename Matcher8, typename Matcher9> -inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, - internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, - internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6, - internal::EitherOfMatcher<Matcher7, internal::EitherOfMatcher<Matcher8, - Matcher9> > > > > > > > -AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, - Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9) { - return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8, m9)); +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8, typename M9> +inline typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) { + return typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, + M9>::type( + ::testing::AnyOf(m1, m2, m3, m4), + ::testing::AnyOf(m5, m6, m7, m8, m9)); } -template <typename Matcher1, typename Matcher2, typename Matcher3, - typename Matcher4, typename Matcher5, typename Matcher6, typename Matcher7, - typename Matcher8, typename Matcher9, typename Matcher10> -inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, - internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, - internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6, - internal::EitherOfMatcher<Matcher7, internal::EitherOfMatcher<Matcher8, - internal::EitherOfMatcher<Matcher9, Matcher10> > > > > > > > > -AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, - Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9, Matcher10 m10) { - return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8, m9, - m10)); +template <typename M1, typename M2, typename M3, typename M4, typename M5, + typename M6, typename M7, typename M8, typename M9, typename M10> +inline typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9, + M10>::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { + return typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9, + M10>::type( + ::testing::AnyOf(m1, m2, m3, m4, m5), + ::testing::AnyOf(m6, m7, m8, m9, m10)); } } // namespace testing @@ -1275,7 +1431,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<>()));\ }\ @@ -1296,7 +1452,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, }\ template <typename arg_type>\ bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1324,7 +1480,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<p0##_type>(p0)));\ }\ @@ -1348,7 +1504,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, template <typename p0##_type>\ template <typename arg_type>\ bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1377,7 +1533,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<p0##_type, p1##_type>(p0, p1)));\ }\ @@ -1405,7 +1561,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, template <typename arg_type>\ bool name##MatcherP2<p0##_type, \ p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1435,7 +1591,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \ p2)));\ @@ -1465,7 +1621,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, template <typename arg_type>\ bool name##MatcherP3<p0##_type, p1##_type, \ p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1498,7 +1654,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \ p3##_type>(p0, p1, p2, p3)));\ @@ -1534,7 +1690,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, template <typename arg_type>\ bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \ p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1569,7 +1725,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ p4##_type>(p0, p1, p2, p3, p4)));\ @@ -1607,7 +1763,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, template <typename arg_type>\ bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \ p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1643,7 +1799,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\ @@ -1682,7 +1838,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, template <typename arg_type>\ bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1721,7 +1877,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \ @@ -1766,7 +1922,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, template <typename arg_type>\ bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1806,7 +1962,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \ @@ -1855,7 +2011,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ p5##_type, p6##_type, \ p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1897,7 +2053,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ p4##_type, p5##_type, p6##_type, p7##_type, \ @@ -1948,7 +2104,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ p5##_type, p6##_type, p7##_type, \ p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1993,7 +2149,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ @@ -2047,7 +2203,7 @@ AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const diff --git a/include/gmock/gmock-generated-matchers.h.pump b/include/gmock/gmock-generated-matchers.h.pump index 8c09444c..7cdb84bf 100644 --- a/include/gmock/gmock-generated-matchers.h.pump +++ b/include/gmock/gmock-generated-matchers.h.pump @@ -242,6 +242,66 @@ $for j [[ ]] +// A set of metafunctions for computing the result type of AllOf. +// AllOf(m1, ..., mN) returns +// AllOfResultN<decltype(m1), ..., decltype(mN)>::type. + +// Although AllOf isn't defined for one argument, AllOfResult1 is defined +// to simplify the implementation. +template <typename M1> +struct AllOfResult1 { + typedef M1 type; +}; + +$range i 1..n + +$range i 2..n +$for i [[ +$range j 2..i +$var m = i/2 +$range k 1..m +$range t m+1..i + +template <typename M1$for j [[, typename M$j]]> +struct AllOfResult$i { + typedef BothOfMatcher< + typename AllOfResult$m<$for k, [[M$k]]>::type, + typename AllOfResult$(i-m)<$for t, [[M$t]]>::type + > type; +}; + +]] + +// A set of metafunctions for computing the result type of AnyOf. +// AnyOf(m1, ..., mN) returns +// AnyOfResultN<decltype(m1), ..., decltype(mN)>::type. + +// Although AnyOf isn't defined for one argument, AnyOfResult1 is defined +// to simplify the implementation. +template <typename M1> +struct AnyOfResult1 { + typedef M1 type; +}; + +$range i 1..n + +$range i 2..n +$for i [[ +$range j 2..i +$var m = i/2 +$range k 1..m +$range t m+1..i + +template <typename M1$for j [[, typename M$j]]> +struct AnyOfResult$i { + typedef EitherOfMatcher< + typename AnyOfResult$m<$for k, [[M$k]]>::type, + typename AnyOfResult$(i-m)<$for t, [[M$t]]>::type + > type; +}; + +]] + } // namespace internal // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected @@ -308,19 +368,16 @@ ElementsAreArray(const T (&array)[N]) { $range i 2..n $for i [[ $range j 1..i -$range k 1..i-1 - -template <$for j, [[typename Matcher$j]]> -inline $for k[[internal::BothOfMatcher<Matcher$k, ]]Matcher$i[[]]$for k [[> ]] - -AllOf($for j, [[Matcher$j m$j]]) { - -$if i == 2 [[ - return internal::BothOfMatcher<Matcher1, Matcher2>(m1, m2); -]] $else [[ - return ::testing::AllOf(m1, ::testing::AllOf($for k, [[m$(k + 1)]])); -]] - +$var m = i/2 +$range k 1..m +$range t m+1..i + +template <$for j, [[typename M$j]]> +inline typename internal::AllOfResult$i<$for j, [[M$j]]>::type +AllOf($for j, [[M$j m$j]]) { + return typename internal::AllOfResult$i<$for j, [[M$j]]>::type( + $if m == 1 [[m1]] $else [[::testing::AllOf($for k, [[m$k]])]], + $if m+1 == i [[m$i]] $else [[::testing::AllOf($for t, [[m$t]])]]); } ]] @@ -331,19 +388,16 @@ $if i == 2 [[ $range i 2..n $for i [[ $range j 1..i -$range k 1..i-1 - -template <$for j, [[typename Matcher$j]]> -inline $for k[[internal::EitherOfMatcher<Matcher$k, ]]Matcher$i[[]]$for k [[> ]] - -AnyOf($for j, [[Matcher$j m$j]]) { - -$if i == 2 [[ - return internal::EitherOfMatcher<Matcher1, Matcher2>(m1, m2); -]] $else [[ - return ::testing::AnyOf(m1, ::testing::AnyOf($for k, [[m$(k + 1)]])); -]] - +$var m = i/2 +$range k 1..m +$range t m+1..i + +template <$for j, [[typename M$j]]> +inline typename internal::AnyOfResult$i<$for j, [[M$j]]>::type +AnyOf($for j, [[M$j m$j]]) { + return typename internal::AnyOfResult$i<$for j, [[M$j]]>::type( + $if m == 1 [[m1]] $else [[::testing::AnyOf($for k, [[m$k]])]], + $if m+1 == i [[m$i]] $else [[::testing::AnyOf($for t, [[m$t]])]]); } ]] @@ -621,7 +675,7 @@ $var param_field_decls2 = [[$for j if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ - negation, #name,\ + negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::std::tr1::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\ }\ @@ -642,7 +696,7 @@ $var param_field_decls2 = [[$for j }\$template template <typename arg_type>\ bool $class_name$param_types::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg,\ + arg_type arg, \ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const ]] diff --git a/include/gmock/gmock-matchers.h b/include/gmock/gmock-matchers.h index 89a9e2ec..4f1c433c 100644 --- a/include/gmock/gmock-matchers.h +++ b/include/gmock/gmock-matchers.h @@ -384,12 +384,119 @@ inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) { return PolymorphicMatcher<Impl>(impl); } +// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION +// and MUST NOT BE USED IN USER CODE!!! +namespace internal { + +// The MatcherCastImpl class template is a helper for implementing +// MatcherCast(). We need this helper in order to partially +// specialize the implementation of MatcherCast() (C++ allows +// class/struct templates to be partially specialized, but not +// function templates.). + +// This general version is used when MatcherCast()'s argument is a +// polymorphic matcher (i.e. something that can be converted to a +// Matcher but is not one yet; for example, Eq(value)) or a value (for +// example, "hello"). +template <typename T, typename M> +class MatcherCastImpl { + public: + static Matcher<T> Cast(M polymorphic_matcher_or_value) { + // M can be a polymorhic matcher, in which case we want to use + // its conversion operator to create Matcher<T>. Or it can be a value + // that should be passed to the Matcher<T>'s constructor. + // + // We can't call Matcher<T>(polymorphic_matcher_or_value) when M is a + // polymorphic matcher because it'll be ambiguous if T has an implicit + // constructor from M (this usually happens when T has an implicit + // constructor from any type). + // + // It won't work to unconditionally implict_cast + // polymorphic_matcher_or_value to Matcher<T> because it won't trigger + // a user-defined conversion from M to T if one exists (assuming M is + // a value). + return CastImpl( + polymorphic_matcher_or_value, + BooleanConstant< + internal::ImplicitlyConvertible<M, Matcher<T> >::value>()); + } + + private: + static Matcher<T> CastImpl(M value, BooleanConstant<false>) { + // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic + // matcher. It must be a value then. Use direct initialization to create + // a matcher. + return Matcher<T>(ImplicitCast_<T>(value)); + } + + static Matcher<T> CastImpl(M polymorphic_matcher_or_value, + BooleanConstant<true>) { + // M is implicitly convertible to Matcher<T>, which means that either + // M is a polymorhpic matcher or Matcher<T> has an implicit constructor + // from M. In both cases using the implicit conversion will produce a + // matcher. + // + // Even if T has an implicit constructor from M, it won't be called because + // creating Matcher<T> would require a chain of two user-defined conversions + // (first to create T from M and then to create Matcher<T> from T). + return polymorphic_matcher_or_value; + } +}; + +// This more specialized version is used when MatcherCast()'s argument +// is already a Matcher. This only compiles when type T can be +// statically converted to type U. +template <typename T, typename U> +class MatcherCastImpl<T, Matcher<U> > { + public: + static Matcher<T> Cast(const Matcher<U>& source_matcher) { + return Matcher<T>(new Impl(source_matcher)); + } + + private: + class Impl : public MatcherInterface<T> { + public: + explicit Impl(const Matcher<U>& source_matcher) + : source_matcher_(source_matcher) {} + + // We delegate the matching logic to the source matcher. + virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + return source_matcher_.MatchAndExplain(static_cast<U>(x), listener); + } + + virtual void DescribeTo(::std::ostream* os) const { + source_matcher_.DescribeTo(os); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + source_matcher_.DescribeNegationTo(os); + } + + private: + const Matcher<U> source_matcher_; + + GTEST_DISALLOW_ASSIGN_(Impl); + }; +}; + +// This even more specialized version is used for efficiently casting +// a matcher to its own type. +template <typename T> +class MatcherCastImpl<T, Matcher<T> > { + public: + static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; } +}; + +} // namespace internal + // In order to be safe and clear, casting between different matcher // types is done explicitly via MatcherCast<T>(m), which takes a // matcher m and returns a Matcher<T>. It compiles only when T can be // statically converted to the argument type of m. template <typename T, typename M> -Matcher<T> MatcherCast(M m); +inline Matcher<T> MatcherCast(M matcher) { + return internal::MatcherCastImpl<T, M>::Cast(matcher); +} // Implements SafeMatcherCast(). // @@ -401,11 +508,11 @@ Matcher<T> MatcherCast(M m); template <typename T> class SafeMatcherCastImpl { public: - // This overload handles polymorphic matchers only since monomorphic - // matchers are handled by the next one. + // This overload handles polymorphic matchers and values only since + // monomorphic matchers are handled by the next one. template <typename M> - static inline Matcher<T> Cast(M polymorphic_matcher) { - return Matcher<T>(polymorphic_matcher); + static inline Matcher<T> Cast(M polymorphic_matcher_or_value) { + return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value); } // This overload handles monomorphic matchers. @@ -600,67 +707,6 @@ void ExplainMatchFailureTupleTo(const MatcherTuple& matchers, matchers, values, os); } -// The MatcherCastImpl class template is a helper for implementing -// MatcherCast(). We need this helper in order to partially -// specialize the implementation of MatcherCast() (C++ allows -// class/struct templates to be partially specialized, but not -// function templates.). - -// This general version is used when MatcherCast()'s argument is a -// polymorphic matcher (i.e. something that can be converted to a -// Matcher but is not one yet; for example, Eq(value)). -template <typename T, typename M> -class MatcherCastImpl { - public: - static Matcher<T> Cast(M polymorphic_matcher) { - return Matcher<T>(polymorphic_matcher); - } -}; - -// This more specialized version is used when MatcherCast()'s argument -// is already a Matcher. This only compiles when type T can be -// statically converted to type U. -template <typename T, typename U> -class MatcherCastImpl<T, Matcher<U> > { - public: - static Matcher<T> Cast(const Matcher<U>& source_matcher) { - return Matcher<T>(new Impl(source_matcher)); - } - - private: - class Impl : public MatcherInterface<T> { - public: - explicit Impl(const Matcher<U>& source_matcher) - : source_matcher_(source_matcher) {} - - // We delegate the matching logic to the source matcher. - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { - return source_matcher_.MatchAndExplain(static_cast<U>(x), listener); - } - - virtual void DescribeTo(::std::ostream* os) const { - source_matcher_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - source_matcher_.DescribeNegationTo(os); - } - - private: - const Matcher<U> source_matcher_; - - GTEST_DISALLOW_ASSIGN_(Impl); - }; -}; - -// This even more specialized version is used for efficiently casting -// a matcher to its own type. -template <typename T> -class MatcherCastImpl<T, Matcher<T> > { - public: - static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; } -}; - // Implements A<T>(). template <typename T> class AnyMatcherImpl : public MatcherInterface<T> { @@ -1596,6 +1642,7 @@ class FloatingEqMatcher { operator Matcher<FloatType&>() const { return MakeMatcher(new Impl<FloatType&>(rhs_, nan_eq_nan_)); } + private: const FloatType rhs_; const bool nan_eq_nan_; @@ -2633,12 +2680,6 @@ GTEST_API_ string FormatMatcherDescription(bool negation, } // namespace internal -// Implements MatcherCast(). -template <typename T, typename M> -inline Matcher<T> MatcherCast(M matcher) { - return internal::MatcherCastImpl<T, M>::Cast(matcher); -} - // _ is a matcher that matches anything of any type. // // This definition is fine as: diff --git a/include/gmock/gmock-spec-builders.h b/include/gmock/gmock-spec-builders.h index 36c47d67..30721ce6 100644 --- a/include/gmock/gmock-spec-builders.h +++ b/include/gmock/gmock-spec-builders.h @@ -384,6 +384,7 @@ class GTEST_API_ Mock { // verification was successful. static bool VerifyAndClear(void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); + private: friend class internal::UntypedFunctionMockerBase; diff --git a/include/gmock/internal/gmock-generated-internal-utils.h b/include/gmock/internal/gmock-generated-internal-utils.h index 1b52dceb..02258451 100644 --- a/include/gmock/internal/gmock-generated-internal-utils.h +++ b/include/gmock/internal/gmock-generated-internal-utils.h @@ -1,4 +1,6 @@ -// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! +// This file was GENERATED by command: +// pump.py gmock-generated-internal-utils.h.pump +// DO NOT EDIT BY HAND!!! // Copyright 2007, Google Inc. // All rights reserved. @@ -58,7 +60,7 @@ class IgnoredValue { // deliberately omit the 'explicit' keyword in order to allow the // conversion to be implicit. template <typename T> - IgnoredValue(const T&) {} + IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit) }; // MatcherTuple<T>::type is a tuple type where each field is a Matcher diff --git a/include/gmock/internal/gmock-generated-internal-utils.h.pump b/include/gmock/internal/gmock-generated-internal-utils.h.pump index 821e474e..e7ecc8b8 100644 --- a/include/gmock/internal/gmock-generated-internal-utils.h.pump +++ b/include/gmock/internal/gmock-generated-internal-utils.h.pump @@ -61,7 +61,7 @@ class IgnoredValue { // deliberately omit the 'explicit' keyword in order to allow the // conversion to be implicit. template <typename T> - IgnoredValue(const T&) {} + IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit) }; // MatcherTuple<T>::type is a tuple type where each field is a Matcher diff --git a/include/gmock/internal/gmock-internal-utils.h b/include/gmock/internal/gmock-internal-utils.h index 34131ef6..aef9388e 100644 --- a/include/gmock/internal/gmock-internal-utils.h +++ b/include/gmock/internal/gmock-internal-utils.h @@ -354,7 +354,8 @@ template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT // crashes). template <typename T> inline T Invalid() { - return *static_cast<typename remove_reference<T>::type*>(NULL); + return const_cast<typename remove_reference<T>::type&>( + *static_cast<volatile typename remove_reference<T>::type*>(NULL)); } template <> inline void Invalid<void>() {} @@ -459,6 +460,11 @@ class StlContainerView< ::std::tr1::tuple<ElementPointer, Size> > { // StlContainer with a reference type. template <typename T> class StlContainerView<T&>; +// Mapping from booleans to types. Similar to boost::bool_<kValue> and +// std::integral_constant<bool, kValue>. +template <bool kValue> +struct BooleanConstant {}; + } // namespace internal } // namespace testing |