diff options
Diffstat (limited to 'googlemock/include/gmock')
23 files changed, 3129 insertions, 1249 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index b3f654af..42648ada 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -33,6 +33,8 @@ // // This file implements some commonly used actions. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ @@ -46,9 +48,10 @@ #include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-port.h" -#if GTEST_HAS_STD_TYPE_TRAITS_ // Defined by gtest-port.h via gmock-port.h. +#if GTEST_LANG_CXX11 // Defined by gtest-port.h via gmock-port.h. +#include <functional> #include <type_traits> -#endif +#endif // GTEST_LANG_CXX11 namespace testing { @@ -96,7 +99,7 @@ struct BuiltInDefaultValueGetter<T, false> { template <typename T> class BuiltInDefaultValue { public: -#if GTEST_HAS_STD_TYPE_TRAITS_ +#if GTEST_LANG_CXX11 // This function returns true iff type T has a built-in default value. static bool Exists() { return ::std::is_default_constructible<T>::value; @@ -107,7 +110,7 @@ class BuiltInDefaultValue { T, ::std::is_default_constructible<T>::value>::Get(); } -#else // GTEST_HAS_STD_TYPE_TRAITS_ +#else // GTEST_LANG_CXX11 // This function returns true iff type T has a built-in default value. static bool Exists() { return false; @@ -117,7 +120,7 @@ class BuiltInDefaultValue { return BuiltInDefaultValueGetter<T, false>::Get(); } -#endif // GTEST_HAS_STD_TYPE_TRAITS_ +#endif // GTEST_LANG_CXX11 }; // This partial specialization says that we use the same built-in @@ -359,14 +362,20 @@ class Action { // Constructs a null Action. Needed for storing Action objects in // STL containers. - Action() : impl_(NULL) {} + Action() {} - // Constructs an Action from its implementation. A NULL impl is - // used to represent the "do-default" action. - explicit Action(ActionInterface<F>* impl) : impl_(impl) {} +#if GTEST_LANG_CXX11 + // Construct an Action from a specified callable. + // This cannot take std::function directly, because then Action would not be + // directly constructible from lambda (it would require two conversions). + template <typename G, + typename = typename ::std::enable_if< + ::std::is_constructible<::std::function<F>, G>::value>::type> + Action(G&& fun) : fun_(::std::forward<G>(fun)) {} // NOLINT +#endif - // Copy constructor. - Action(const Action& action) : impl_(action.impl_) {} + // Constructs an Action from its implementation. + explicit Action(ActionInterface<F>* impl) : impl_(impl) {} // This constructor allows us to turn an Action<Func> object into an // Action<F>, as long as F's arguments can be implicitly converted @@ -376,7 +385,13 @@ class Action { explicit Action(const Action<Func>& action); // Returns true iff this is the DoDefault() action. - bool IsDoDefault() const { return impl_.get() == NULL; } + bool IsDoDefault() const { +#if GTEST_LANG_CXX11 + return impl_ == nullptr && fun_ == nullptr; +#else + return impl_ == NULL; +#endif + } // Performs the action. Note that this method is const even though // the corresponding method in ActionInterface is not. The reason @@ -384,14 +399,15 @@ class Action { // another concrete action, not that the concrete action it binds to // cannot change state. (Think of the difference between a const // pointer and a pointer to const.) - Result Perform(const ArgumentTuple& args) const { - internal::Assert( - !IsDoDefault(), __FILE__, __LINE__, - "You are using DoDefault() inside a composite action like " - "DoAll() or WithArgs(). This is not supported for technical " - "reasons. Please instead spell out the default action, or " - "assign the default action to an Action variable and use " - "the variable in various places."); + Result Perform(ArgumentTuple args) const { + if (IsDoDefault()) { + internal::IllegalDoDefault(__FILE__, __LINE__); + } +#if GTEST_LANG_CXX11 + if (fun_ != nullptr) { + return internal::Apply(fun_, ::std::move(args)); + } +#endif return impl_->Perform(args); } @@ -399,6 +415,18 @@ class Action { template <typename F1, typename F2> friend class internal::ActionAdaptor; + template <typename G> + friend class Action; + + // In C++11, Action can be implemented either as a generic functor (through + // std::function), or legacy ActionInterface. In C++98, only ActionInterface + // is available. The invariants are as follows: + // * in C++98, impl_ is null iff this is the default action + // * in C++11, at most one of fun_ & impl_ may be nonnull; both are null iff + // this is the default action +#if GTEST_LANG_CXX11 + ::std::function<F> fun_; +#endif internal::linked_ptr<ActionInterface<F> > impl_; }; @@ -530,6 +558,9 @@ struct ByMoveWrapper { // statement, and conversion of the result of Return to Action<T(U)> is a // good place for that. // +// The real life example of the above scenario happens when an invocation +// of gtl::Container() is passed into Return. +// template <typename R> class ReturnAction { public: @@ -749,7 +780,7 @@ class DoDefaultAction { // This template type conversion operator allows DoDefault() to be // used in any function. template <typename F> - operator Action<F>() const { return Action<F>(NULL); } + operator Action<F>() const { return Action<F>(); } // NOLINT }; // Implements the Assign action to set a given pointer referent to a @@ -885,6 +916,28 @@ class InvokeMethodWithoutArgsAction { GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction); }; +// Implements the InvokeWithoutArgs(callback) action. +template <typename CallbackType> +class InvokeCallbackWithoutArgsAction { + public: + // The c'tor takes ownership of the callback. + explicit InvokeCallbackWithoutArgsAction(CallbackType* callback) + : callback_(callback) { + callback->CheckIsRepeatable(); // Makes sure the callback is permanent. + } + + // This type conversion operator template allows Invoke(callback) to + // be used wherever the callback's return type can be implicitly + // converted to that of the mock function. + template <typename Result, typename ArgumentTuple> + Result Perform(const ArgumentTuple&) const { return callback_->Run(); } + + private: + const internal::linked_ptr<CallbackType> callback_; + + GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction); +}; + // Implements the IgnoreResult(action) action. template <typename A> class IgnoreResultAction { @@ -1029,9 +1082,9 @@ class DoBothAction { // return sqrt(x*x + y*y); // } // ... -// EXEPCT_CALL(mock, Foo("abc", _, _)) +// EXPECT_CALL(mock, Foo("abc", _, _)) // .WillOnce(Invoke(DistanceToOriginWithLabel)); -// EXEPCT_CALL(mock, Bar(5, _, _)) +// EXPECT_CALL(mock, Bar(5, _, _)) // .WillOnce(Invoke(DistanceToOriginWithIndex)); // // you could write @@ -1041,8 +1094,8 @@ class DoBothAction { // return sqrt(x*x + y*y); // } // ... -// EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin)); -// EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin)); +// EXPECT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin)); +// EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin)); typedef internal::IgnoredValue Unused; // This constructor allows us to turn an Action<From> object into an @@ -1052,7 +1105,13 @@ typedef internal::IgnoredValue Unused; template <typename To> template <typename From> Action<To>::Action(const Action<From>& from) - : impl_(new internal::ActionAdaptor<To, From>(from)) {} + : +#if GTEST_LANG_CXX11 + fun_(from.fun_), +#endif + impl_(from.impl_ == NULL ? NULL + : new internal::ActionAdaptor<To, From>(from)) { +} // Creates an action that returns 'value'. 'value' is passed by value // instead of const reference - otherwise Return("string literal") diff --git a/googlemock/include/gmock/gmock-cardinalities.h b/googlemock/include/gmock/gmock-cardinalities.h index fc315f92..2ce16afe 100644 --- a/googlemock/include/gmock/gmock-cardinalities.h +++ b/googlemock/include/gmock/gmock-cardinalities.h @@ -35,6 +35,8 @@ // cardinalities can be defined by the user implementing the // CardinalityInterface interface if necessary. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h index b5a889c0..4ce7d350 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h +++ b/googlemock/include/gmock/gmock-generated-actions.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-actions.h.pump +// DO NOT EDIT BY HAND!!! // Copyright 2007, Google Inc. // All rights reserved. @@ -35,6 +37,8 @@ // // This file implements some commonly used variadic actions. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ @@ -45,8 +49,8 @@ namespace testing { namespace internal { // InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary -// function or method with the unpacked values, where F is a function -// type that takes N arguments. +// function, method, or callback with the unpacked values, where F is +// a function type that takes N arguments. template <typename Result, typename ArgumentTuple> class InvokeHelper; @@ -64,6 +68,12 @@ class InvokeHelper<R, ::testing::tuple<> > { const ::testing::tuple<>&) { return (obj_ptr->*method_ptr)(); } + + template <typename CallbackType> + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple<>&) { + return callback->Run(); + } }; template <typename R, typename A1> @@ -80,6 +90,12 @@ class InvokeHelper<R, ::testing::tuple<A1> > { const ::testing::tuple<A1>& args) { return (obj_ptr->*method_ptr)(get<0>(args)); } + + template <typename CallbackType> + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple<A1>& args) { + return callback->Run(get<0>(args)); + } }; template <typename R, typename A1, typename A2> @@ -96,6 +112,12 @@ class InvokeHelper<R, ::testing::tuple<A1, A2> > { const ::testing::tuple<A1, A2>& args) { return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args)); } + + template <typename CallbackType> + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple<A1, A2>& args) { + return callback->Run(get<0>(args), get<1>(args)); + } }; template <typename R, typename A1, typename A2, typename A3> @@ -113,6 +135,12 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3> > { return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args)); } + + template <typename CallbackType> + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple<A1, A2, A3>& args) { + return callback->Run(get<0>(args), get<1>(args), get<2>(args)); + } }; template <typename R, typename A1, typename A2, typename A3, typename A4> @@ -132,6 +160,13 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4> > { return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), get<3>(args)); } + + template <typename CallbackType> + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple<A1, A2, A3, A4>& args) { + return callback->Run(get<0>(args), get<1>(args), get<2>(args), + get<3>(args)); + } }; template <typename R, typename A1, typename A2, typename A3, typename A4, @@ -152,6 +187,13 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5> > { return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args)); } + + template <typename CallbackType> + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple<A1, A2, A3, A4, A5>& args) { + return callback->Run(get<0>(args), get<1>(args), get<2>(args), + get<3>(args), get<4>(args)); + } }; template <typename R, typename A1, typename A2, typename A3, typename A4, @@ -172,6 +214,9 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6> > { return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), get<5>(args)); } + + // There is no InvokeCallback() for 6-tuples, as google3 callbacks + // support 5 arguments at most. }; template <typename R, typename A1, typename A2, typename A3, typename A4, @@ -194,6 +239,9 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7> > { get<2>(args), get<3>(args), get<4>(args), get<5>(args), get<6>(args)); } + + // There is no InvokeCallback() for 7-tuples, as google3 callbacks + // support 5 arguments at most. }; template <typename R, typename A1, typename A2, typename A3, typename A4, @@ -217,6 +265,9 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > { get<2>(args), get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args)); } + + // There is no InvokeCallback() for 8-tuples, as google3 callbacks + // support 5 arguments at most. }; template <typename R, typename A1, typename A2, typename A3, typename A4, @@ -240,6 +291,9 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > { get<2>(args), get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args)); } + + // There is no InvokeCallback() for 9-tuples, as google3 callbacks + // support 5 arguments at most. }; template <typename R, typename A1, typename A2, typename A3, typename A4, @@ -265,6 +319,34 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, get<2>(args), get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), get<9>(args)); } + + // There is no InvokeCallback() for 10-tuples, as google3 callbacks + // support 5 arguments at most. +}; + +// Implements the Invoke(callback) action. +template <typename CallbackType> +class InvokeCallbackAction { + public: + // The c'tor takes ownership of the callback. + explicit InvokeCallbackAction(CallbackType* callback) + : callback_(callback) { + callback->CheckIsRepeatable(); // Makes sure the callback is permanent. + } + + // This type conversion operator template allows Invoke(callback) to + // be used wherever the callback's type is compatible with that of + // the mock function, i.e. if the mock function's arguments can be + // implicitly converted to the callback's arguments and the + // callback's result can be implicitly converted to the mock + // function's result. + template <typename Result, typename ArgumentTuple> + Result Perform(const ArgumentTuple& args) const { + return InvokeHelper<Result, ArgumentTuple>::InvokeCallback( + callback_.get(), args); + } + private: + const linked_ptr<CallbackType> callback_; }; // An INTERNAL macro for extracting the type of a tuple field. It's @@ -875,7 +957,7 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, // MORE INFORMATION: // // To learn more about using these macros, please search for 'ACTION' -// on http://code.google.com/p/googlemock/wiki/CookBook. +// on https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md // An internal macro needed for implementing ACTION*(). #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\ @@ -1073,52 +1155,90 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, #define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\ () #define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\ - (p0##_type gmock_p0) : p0(gmock_p0) + (p0##_type gmock_p0) : p0(::testing::internal::move(gmock_p0)) #define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\ - (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1) + (p0##_type gmock_p0, \ + p1##_type gmock_p1) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)) #define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\ (p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) + p2##_type gmock_p2) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)) #define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\ (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3) + p3##_type gmock_p3) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)) #define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\ (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) + p3##_type gmock_p3, \ + p4##_type gmock_p4) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)) #define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\ (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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) + p5##_type gmock_p5) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)) #define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\ (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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) + p6##_type gmock_p6) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)) #define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\ (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(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7) + p6##_type gmock_p6, \ + p7##_type gmock_p7) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)) #define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ p7, p8)\ (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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8) + p8##_type gmock_p8) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_p8)) #define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ p7, p8, p9)\ (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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8), p9(gmock_p9) + p9##_type gmock_p9) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_p8)), \ + p9(::testing::internal::move(gmock_p9)) // Declares the fields for storing the value parameters. #define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS() @@ -1354,7 +1474,8 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, template <typename p0##_type>\ class name##ActionP {\ public:\ - explicit name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\ + explicit name##ActionP(p0##_type gmock_p0) : \ + p0(::testing::internal::forward<p0##_type>(gmock_p0)) {}\ template <typename F>\ class gmock_Impl : public ::testing::ActionInterface<F> {\ public:\ @@ -1362,7 +1483,8 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, typedef typename ::testing::internal::Function<F>::Result return_type;\ typedef typename ::testing::internal::Function<F>::ArgumentTuple\ args_type;\ - explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\ + explicit gmock_Impl(p0##_type gmock_p0) : \ + p0(::testing::internal::forward<p0##_type>(gmock_p0)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ @@ -1404,8 +1526,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, template <typename p0##_type, typename p1##_type>\ class name##ActionP2 {\ public:\ - name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ - p1(gmock_p1) {}\ + name##ActionP2(p0##_type gmock_p0, \ + p1##_type gmock_p1) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)) {}\ template <typename F>\ class gmock_Impl : public ::testing::ActionInterface<F> {\ public:\ @@ -1413,8 +1536,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, typedef typename ::testing::internal::Function<F>::Result return_type;\ typedef typename ::testing::internal::Function<F>::ArgumentTuple\ args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ - p1(gmock_p1) {}\ + gmock_Impl(p0##_type gmock_p0, \ + p1##_type gmock_p1) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ @@ -1460,7 +1584,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, class name##ActionP3 {\ public:\ name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ + p2##_type gmock_p2) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)) {}\ template <typename F>\ class gmock_Impl : public ::testing::ActionInterface<F> {\ public:\ @@ -1469,7 +1595,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, typedef typename ::testing::internal::Function<F>::ArgumentTuple\ args_type;\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ + p2##_type gmock_p2) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ @@ -1519,8 +1647,11 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, class name##ActionP4 {\ public:\ name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3) {}\ + p2##_type gmock_p2, \ + p3##_type gmock_p3) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)) {}\ template <typename F>\ class gmock_Impl : public ::testing::ActionInterface<F> {\ public:\ @@ -1529,8 +1660,10 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, typedef typename ::testing::internal::Function<F>::ArgumentTuple\ args_type;\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3) {}\ + p3##_type gmock_p3) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ @@ -1587,8 +1720,11 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, public:\ name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2, p3##_type gmock_p3, \ - p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4) {}\ + p4##_type gmock_p4) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)) {}\ template <typename F>\ class gmock_Impl : public ::testing::ActionInterface<F> {\ public:\ @@ -1597,8 +1733,12 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, typedef typename ::testing::internal::Function<F>::ArgumentTuple\ args_type;\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \ - p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\ + p3##_type gmock_p3, \ + p4##_type gmock_p4) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ @@ -1657,8 +1797,12 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ + p5##_type gmock_p5) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)), \ + p5(::testing::internal::forward<p5##_type>(gmock_p5)) {}\ template <typename F>\ class gmock_Impl : public ::testing::ActionInterface<F> {\ public:\ @@ -1668,8 +1812,12 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, args_type;\ gmock_Impl(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ + p5##_type gmock_p5) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)), \ + p5(::testing::internal::forward<p5##_type>(gmock_p5)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ @@ -1731,9 +1879,14 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ - p6(gmock_p6) {}\ + p5##_type gmock_p5, \ + p6##_type gmock_p6) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)), \ + p5(::testing::internal::forward<p5##_type>(gmock_p5)), \ + p6(::testing::internal::forward<p6##_type>(gmock_p6)) {}\ template <typename F>\ class gmock_Impl : public ::testing::ActionInterface<F> {\ public:\ @@ -1743,8 +1896,13 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, args_type;\ gmock_Impl(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ + p6##_type gmock_p6) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)), \ + p5(::testing::internal::forward<p5##_type>(gmock_p5)), \ + p6(::testing::internal::forward<p6##_type>(gmock_p6)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ @@ -1813,9 +1971,14 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7) {}\ + p7##_type gmock_p7) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)), \ + p5(::testing::internal::forward<p5##_type>(gmock_p5)), \ + p6(::testing::internal::forward<p6##_type>(gmock_p6)), \ + p7(::testing::internal::forward<p7##_type>(gmock_p7)) {}\ template <typename F>\ class gmock_Impl : public ::testing::ActionInterface<F> {\ public:\ @@ -1825,9 +1988,15 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, args_type;\ gmock_Impl(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(gmock_p0), \ - p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \ - p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\ + p6##_type gmock_p6, \ + p7##_type gmock_p7) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)), \ + p5(::testing::internal::forward<p5##_type>(gmock_p5)), \ + p6(::testing::internal::forward<p6##_type>(gmock_p6)), \ + p7(::testing::internal::forward<p7##_type>(gmock_p7)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ @@ -1900,9 +2069,15 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8) {}\ + p8##_type gmock_p8) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)), \ + p5(::testing::internal::forward<p5##_type>(gmock_p5)), \ + p6(::testing::internal::forward<p6##_type>(gmock_p6)), \ + p7(::testing::internal::forward<p7##_type>(gmock_p7)), \ + p8(::testing::internal::forward<p8##_type>(gmock_p8)) {}\ template <typename F>\ class gmock_Impl : public ::testing::ActionInterface<F> {\ public:\ @@ -1913,9 +2088,15 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, gmock_Impl(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7), p8(gmock_p8) {}\ + p8##_type gmock_p8) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)), \ + p5(::testing::internal::forward<p5##_type>(gmock_p5)), \ + p6(::testing::internal::forward<p6##_type>(gmock_p6)), \ + p7(::testing::internal::forward<p7##_type>(gmock_p7)), \ + p8(::testing::internal::forward<p8##_type>(gmock_p8)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ @@ -1992,9 +2173,17 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ + p8##_type gmock_p8, \ + p9##_type gmock_p9) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)), \ + p5(::testing::internal::forward<p5##_type>(gmock_p5)), \ + p6(::testing::internal::forward<p6##_type>(gmock_p6)), \ + p7(::testing::internal::forward<p7##_type>(gmock_p7)), \ + p8(::testing::internal::forward<p8##_type>(gmock_p8)), \ + p9(::testing::internal::forward<p9##_type>(gmock_p9)) {}\ template <typename F>\ class gmock_Impl : public ::testing::ActionInterface<F> {\ public:\ @@ -2005,9 +2194,16 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, gmock_Impl(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ + p9##_type gmock_p9) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \ + p1(::testing::internal::forward<p1##_type>(gmock_p1)), \ + p2(::testing::internal::forward<p2##_type>(gmock_p2)), \ + p3(::testing::internal::forward<p3##_type>(gmock_p3)), \ + p4(::testing::internal::forward<p4##_type>(gmock_p4)), \ + p5(::testing::internal::forward<p5##_type>(gmock_p5)), \ + p6(::testing::internal::forward<p6##_type>(gmock_p6)), \ + p7(::testing::internal::forward<p7##_type>(gmock_p7)), \ + p8(::testing::internal::forward<p8##_type>(gmock_p8)), \ + p9(::testing::internal::forward<p9##_type>(gmock_p9)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ @@ -2369,7 +2565,7 @@ ACTION_TEMPLATE(ReturnNew, } // namespace testing -// Include any custom actions added by the local installation. +// Include any custom callback actions added by the local installation. // We must include this header at the end to make sure it can use the // declarations from this file. #include "gmock/internal/custom/gmock-generated-actions.h" diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump index 66d9f9d5..4ec66791 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/gmock-generated-actions.h.pump @@ -1,5 +1,5 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to +$$ This is a Pump source file. Please use Pump to convert it to $$ gmock-generated-actions.h. $$ $var n = 10 $$ The maximum arity we support. @@ -39,6 +39,8 @@ $$}} This meta comment fixes auto-indentation in editors. // // This file implements some commonly used variadic actions. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ @@ -49,12 +51,13 @@ namespace testing { namespace internal { // InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary -// function or method with the unpacked values, where F is a function -// type that takes N arguments. +// function, method, or callback with the unpacked values, where F is +// a function type that takes N arguments. template <typename Result, typename ArgumentTuple> class InvokeHelper; +$var max_callback_arity = 5 $range i 0..n $for i [[ $range j 1..i @@ -76,10 +79,48 @@ class InvokeHelper<R, ::testing::tuple<$as> > { const ::testing::tuple<$as>&$args) { return (obj_ptr->*method_ptr)($gets); } + + +$if i <= max_callback_arity [[ + template <typename CallbackType> + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple<$as>&$args) { + return callback->Run($gets); + } +]] $else [[ + // There is no InvokeCallback() for $i-tuples, as google3 callbacks + // support $max_callback_arity arguments at most. +]] + }; ]] +// Implements the Invoke(callback) action. +template <typename CallbackType> +class InvokeCallbackAction { + public: + // The c'tor takes ownership of the callback. + explicit InvokeCallbackAction(CallbackType* callback) + : callback_(callback) { + callback->CheckIsRepeatable(); // Makes sure the callback is permanent. + } + + // This type conversion operator template allows Invoke(callback) to + // be used wherever the callback's type is compatible with that of + // the mock function, i.e. if the mock function's arguments can be + // implicitly converted to the callback's arguments and the + // callback's result can be implicitly converted to the mock + // function's result. + template <typename Result, typename ArgumentTuple> + Result Perform(const ArgumentTuple& args) const { + return InvokeHelper<Result, ArgumentTuple>::InvokeCallback( + callback_.get(), args); + } + private: + const linked_ptr<CallbackType> callback_; +}; + // An INTERNAL macro for extracting the type of a tuple field. It's // subject to change without notice - DO NOT USE IN USER CODE! #define GMOCK_FIELD_(Tuple, N) \ @@ -357,7 +398,7 @@ $range j2 2..i // MORE INFORMATION: // // To learn more about using these macros, please search for 'ACTION' -// on http://code.google.com/p/googlemock/wiki/CookBook. +// on https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md $range i 0..n $range k 0..n-1 @@ -486,7 +527,7 @@ _VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]] $for i [[ $range j 0..i-1 #define GMOCK_INTERNAL_INIT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])\ - ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(gmock_p$j)]] + ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(::testing::internal::move(gmock_p$j))]] ]] @@ -619,7 +660,7 @@ $var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]] $range j 0..i-1 $var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] $var param_types_and_names = [[$for j, [[p$j##_type p$j]]]] -$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]] +$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::forward<p$j##_type>(gmock_p$j))]]]]]] $var param_field_decls = [[$for j [[ diff --git a/googlemock/include/gmock/gmock-generated-function-mockers.h b/googlemock/include/gmock/gmock-generated-function-mockers.h index 4fa5ca94..0474c896 100644 --- a/googlemock/include/gmock/gmock-generated-function-mockers.h +++ b/googlemock/include/gmock/gmock-generated-function-mockers.h @@ -37,6 +37,8 @@ // // This file implements function mockers of various arities. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ @@ -68,8 +70,8 @@ class FunctionMocker<R()> : public typedef R F(); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With() { - return this->current_spec(); + MockSpec<F> With() { + return MockSpec<F>(this, ::testing::make_tuple()); } R Invoke() { @@ -88,9 +90,8 @@ class FunctionMocker<R(A1)> : public typedef R F(A1); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With(const Matcher<A1>& m1) { - this->current_spec().SetMatchers(::testing::make_tuple(m1)); - return this->current_spec(); + MockSpec<F> With(const Matcher<A1>& m1) { + return MockSpec<F>(this, ::testing::make_tuple(m1)); } R Invoke(A1 a1) { @@ -98,7 +99,7 @@ class FunctionMocker<R(A1)> : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1)); + return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1))); } }; @@ -109,9 +110,8 @@ class FunctionMocker<R(A1, A2)> : public typedef R F(A1, A2); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2)); - return this->current_spec(); + MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2) { + return MockSpec<F>(this, ::testing::make_tuple(m1, m2)); } R Invoke(A1 a1, A2 a2) { @@ -119,7 +119,8 @@ class FunctionMocker<R(A1, A2)> : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2)); + return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1), + internal::forward<A2>(a2))); } }; @@ -130,10 +131,9 @@ class FunctionMocker<R(A1, A2, A3)> : public typedef R F(A1, A2, A3); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, + MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2, const Matcher<A3>& m3) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3)); - return this->current_spec(); + return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3)); } R Invoke(A1 a1, A2 a2, A3 a3) { @@ -141,7 +141,8 @@ class FunctionMocker<R(A1, A2, A3)> : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3)); + return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1), + internal::forward<A2>(a2), internal::forward<A3>(a3))); } }; @@ -152,10 +153,9 @@ class FunctionMocker<R(A1, A2, A3, A4)> : public typedef R F(A1, A2, A3, A4); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, + MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2, const Matcher<A3>& m3, const Matcher<A4>& m4) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4)); - return this->current_spec(); + return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) { @@ -163,7 +163,9 @@ class FunctionMocker<R(A1, A2, A3, A4)> : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4)); + return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1), + internal::forward<A2>(a2), internal::forward<A3>(a3), + internal::forward<A4>(a4))); } }; @@ -175,10 +177,9 @@ class FunctionMocker<R(A1, A2, A3, A4, A5)> : public typedef R F(A1, A2, A3, A4, A5); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, + MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5)); - return this->current_spec(); + return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { @@ -186,7 +187,9 @@ class FunctionMocker<R(A1, A2, A3, A4, A5)> : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5)); + return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1), + internal::forward<A2>(a2), internal::forward<A3>(a3), + internal::forward<A4>(a4), internal::forward<A5>(a5))); } }; @@ -198,12 +201,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public typedef R F(A1, A2, A3, A4, A5, A6); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, + MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A6>& m6) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, - m6)); - return this->current_spec(); + return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { @@ -211,7 +212,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6)); + return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1), + internal::forward<A2>(a2), internal::forward<A3>(a3), + internal::forward<A4>(a4), internal::forward<A5>(a5), + internal::forward<A6>(a6))); } }; @@ -223,12 +227,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public typedef R F(A1, A2, A3, A4, A5, A6, A7); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, + MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A6>& m6, const Matcher<A7>& m7) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, - m6, m7)); - return this->current_spec(); + return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { @@ -236,7 +238,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7)); + return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1), + internal::forward<A2>(a2), internal::forward<A3>(a3), + internal::forward<A4>(a4), internal::forward<A5>(a5), + internal::forward<A6>(a6), internal::forward<A7>(a7))); } }; @@ -248,12 +253,11 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public typedef R F(A1, A2, A3, A4, A5, A6, A7, A8); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, + MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, - m6, m7, m8)); - return this->current_spec(); + return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7, + m8)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { @@ -261,7 +265,11 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8)); + return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1), + internal::forward<A2>(a2), internal::forward<A3>(a3), + internal::forward<A4>(a4), internal::forward<A5>(a5), + internal::forward<A6>(a6), internal::forward<A7>(a7), + internal::forward<A8>(a8))); } }; @@ -273,13 +281,12 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, + MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8, const Matcher<A9>& m9) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, - m6, m7, m8, m9)); - return this->current_spec(); + return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7, + m8, m9)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { @@ -287,7 +294,11 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9)); + return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1), + internal::forward<A2>(a2), internal::forward<A3>(a3), + internal::forward<A4>(a4), internal::forward<A5>(a5), + internal::forward<A6>(a6), internal::forward<A7>(a7), + internal::forward<A8>(a8), internal::forward<A9>(a9))); } }; @@ -300,13 +311,12 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, + MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8, const Matcher<A9>& m9, const Matcher<A10>& m10) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, - m6, m7, m8, m9, m10)); - return this->current_spec(); + return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7, + m8, m9, m10)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, @@ -315,11 +325,67 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9, - a10)); + return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1), + internal::forward<A2>(a2), internal::forward<A3>(a3), + internal::forward<A4>(a4), internal::forward<A5>(a5), + internal::forward<A6>(a6), internal::forward<A7>(a7), + internal::forward<A8>(a8), internal::forward<A9>(a9), + internal::forward<A10>(a10))); } }; +// Removes the given pointer; this is a helper for the expectation setter method +// for parameterless matchers. +// +// We want to make sure that the user cannot set a parameterless expectation on +// overloaded methods, including methods which are overloaded on const. Example: +// +// class MockClass { +// MOCK_METHOD0(GetName, string&()); +// MOCK_CONST_METHOD0(GetName, const string&()); +// }; +// +// TEST() { +// // This should be an error, as it's not clear which overload is expected. +// EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value)); +// } +// +// Here are the generated expectation-setter methods: +// +// class MockClass { +// // Overload 1 +// MockSpec<string&()> gmock_GetName() { ... } +// // Overload 2. Declared const so that the compiler will generate an +// // error when trying to resolve between this and overload 4 in +// // 'gmock_GetName(WithoutMatchers(), nullptr)'. +// MockSpec<string&()> gmock_GetName( +// const WithoutMatchers&, const Function<string&()>*) const { +// // Removes const from this, calls overload 1 +// return AdjustConstness_(this)->gmock_GetName(); +// } +// +// // Overload 3 +// const string& gmock_GetName() const { ... } +// // Overload 4 +// MockSpec<const string&()> gmock_GetName( +// const WithoutMatchers&, const Function<const string&()>*) const { +// // Does not remove const, calls overload 3 +// return AdjustConstness_const(this)->gmock_GetName(); +// } +// } +// +template <typename MockType> +const MockType* AdjustConstness_const(const MockType* mock) { + return mock; +} + +// Removes const from and returns the given pointer; this is a helper for the +// expectation setter method for parameterless matchers. +template <typename MockType> +MockType* AdjustConstness_(const MockType* mock) { + return const_cast<MockType*>(mock); +} + } // namespace internal // The style guide prohibits "using" statements in a namespace scope @@ -353,324 +419,534 @@ using internal::FunctionMocker; GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - ) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 0), \ - this_method_does_not_take_0_arguments); \ - GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ - } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method() constness { \ - GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(0, constness, Method).With(); \ - } \ +#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method() constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size<tn ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == 0), \ + this_method_does_not_take_0_arguments); \ + GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method() constness { \ + GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(0, constness, Method).With(); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \ - Method) + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 1), \ - this_method_does_not_take_1_argument); \ - GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \ - } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ - GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \ - Method) +#define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size<tn ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == 1), \ + this_method_does_not_take_1_argument); \ + GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(1, constness, Method) \ + .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \ + gmock_a1)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ + GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 2), \ - this_method_does_not_take_2_arguments); \ - GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \ - } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ - GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \ - Method) +#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size<tn ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == 2), \ + this_method_does_not_take_2_arguments); \ + GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(2, constness, Method) \ + .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \ + gmock_a1), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \ + gmock_a2)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ + GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 3), \ - this_method_does_not_take_3_arguments); \ - GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3); \ - } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ - GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \ - Method) +#define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size<tn ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == 3), \ + this_method_does_not_take_3_arguments); \ + GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(3, constness, Method) \ + .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \ + gmock_a1), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \ + gmock_a2), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \ + gmock_a3)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ + GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(3, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 4), \ - this_method_does_not_take_4_arguments); \ - GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4); \ - } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ - GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \ - Method) +#define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size<tn ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == 4), \ + this_method_does_not_take_4_arguments); \ + GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(4, constness, Method) \ + .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \ + gmock_a1), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \ + gmock_a2), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \ + gmock_a3), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \ + gmock_a4)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ + GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(4, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 5), \ - this_method_does_not_take_5_arguments); \ - GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5); \ - } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ - GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \ - Method) +#define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size<tn ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == 5), \ + this_method_does_not_take_5_arguments); \ + GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(5, constness, Method) \ + .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \ + gmock_a1), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \ + gmock_a2), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \ + gmock_a3), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \ + gmock_a4), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \ + gmock_a5)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ + GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(5, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 6), \ - this_method_does_not_take_6_arguments); \ - GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ - } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ - GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \ - Method) +#define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size<tn ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == 6), \ + this_method_does_not_take_6_arguments); \ + GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(6, constness, Method) \ + .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \ + gmock_a1), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \ + gmock_a2), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \ + gmock_a3), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \ + gmock_a4), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \ + gmock_a5), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>( \ + gmock_a6)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ + GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(6, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 7), \ - this_method_does_not_take_7_arguments); \ - GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ - } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ - GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \ - Method) +#define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size<tn ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == 7), \ + this_method_does_not_take_7_arguments); \ + GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(7, constness, Method) \ + .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \ + gmock_a1), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \ + gmock_a2), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \ + gmock_a3), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \ + gmock_a4), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \ + gmock_a5), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>( \ + gmock_a6), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>( \ + gmock_a7)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ + GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(7, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \ + gmock_a7); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 8), \ - this_method_does_not_take_8_arguments); \ - GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ - } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ - GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \ - Method) +#define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size<tn ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == 8), \ + this_method_does_not_take_8_arguments); \ + GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(8, constness, Method) \ + .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \ + gmock_a1), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \ + gmock_a2), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \ + gmock_a3), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \ + gmock_a4), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \ + gmock_a5), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>( \ + gmock_a6), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>( \ + gmock_a7), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>( \ + gmock_a8)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ + GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(8, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \ + gmock_a7, gmock_a8); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 8, __VA_ARGS__)>()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ - GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 9), \ - this_method_does_not_take_9_arguments); \ - GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ - gmock_a9); \ - } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ - GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ - GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ - gmock_a9); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \ - Method) +#define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size<tn ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == 9), \ + this_method_does_not_take_9_arguments); \ + GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(9, constness, Method) \ + .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \ + gmock_a1), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \ + gmock_a2), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \ + gmock_a3), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \ + gmock_a4), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \ + gmock_a5), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>( \ + gmock_a6), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>( \ + gmock_a7), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>( \ + gmock_a8), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>( \ + gmock_a9)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ + GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(9, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \ + gmock_a7, gmock_a8, gmock_a9); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 9, __VA_ARGS__)>()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ - GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \ - GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 10), \ - this_method_does_not_take_10_arguments); \ - GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ - gmock_a10); \ - } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ - GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \ - GMOCK_MATCHER_(tn, 10, \ - __VA_ARGS__) gmock_a10) constness { \ - GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ - gmock_a10); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \ - Method) +#define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \ + GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size<tn ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == 10), \ + this_method_does_not_take_10_arguments); \ + GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(10, constness, Method) \ + .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \ + gmock_a1), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \ + gmock_a2), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \ + gmock_a3), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \ + gmock_a4), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \ + gmock_a5), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>( \ + gmock_a6), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>( \ + gmock_a7), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>( \ + gmock_a8), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>( \ + gmock_a9), \ + ::testing::internal::forward<GMOCK_ARG_(tn, 10, __VA_ARGS__)>( \ + gmock_a10)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \ + GMOCK_MATCHER_(tn, 10, __VA_ARGS__) gmock_a10) constness { \ + GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(10, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \ + gmock_a7, gmock_a8, gmock_a9, gmock_a10); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 9, __VA_ARGS__)>(), \ + ::testing::A<GMOCK_ARG_(tn, 10, __VA_ARGS__)>()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \ + Method) #define MOCK_METHOD0(m, ...) GMOCK_METHOD0_(, , , m, __VA_ARGS__) #define MOCK_METHOD1(m, ...) GMOCK_METHOD1_(, , , m, __VA_ARGS__) @@ -880,7 +1156,7 @@ class MockFunction<R()> { MOCK_METHOD0_T(Call, R()); #if GTEST_HAS_STD_FUNCTION_ - std::function<R()> AsStdFunction() { + ::std::function<R()> AsStdFunction() { return [this]() -> R { return this->Call(); }; @@ -899,9 +1175,9 @@ class MockFunction<R(A0)> { MOCK_METHOD1_T(Call, R(A0)); #if GTEST_HAS_STD_FUNCTION_ - std::function<R(A0)> AsStdFunction() { + ::std::function<R(A0)> AsStdFunction() { return [this](A0 a0) -> R { - return this->Call(a0); + return this->Call(::std::move(a0)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -918,9 +1194,9 @@ class MockFunction<R(A0, A1)> { MOCK_METHOD2_T(Call, R(A0, A1)); #if GTEST_HAS_STD_FUNCTION_ - std::function<R(A0, A1)> AsStdFunction() { + ::std::function<R(A0, A1)> AsStdFunction() { return [this](A0 a0, A1 a1) -> R { - return this->Call(a0, a1); + return this->Call(::std::move(a0), ::std::move(a1)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -937,9 +1213,9 @@ class MockFunction<R(A0, A1, A2)> { MOCK_METHOD3_T(Call, R(A0, A1, A2)); #if GTEST_HAS_STD_FUNCTION_ - std::function<R(A0, A1, A2)> AsStdFunction() { + ::std::function<R(A0, A1, A2)> AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2) -> R { - return this->Call(a0, a1, a2); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -956,9 +1232,10 @@ class MockFunction<R(A0, A1, A2, A3)> { MOCK_METHOD4_T(Call, R(A0, A1, A2, A3)); #if GTEST_HAS_STD_FUNCTION_ - std::function<R(A0, A1, A2, A3)> AsStdFunction() { + ::std::function<R(A0, A1, A2, A3)> AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3) -> R { - return this->Call(a0, a1, a2, a3); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -976,9 +1253,10 @@ class MockFunction<R(A0, A1, A2, A3, A4)> { MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4)); #if GTEST_HAS_STD_FUNCTION_ - std::function<R(A0, A1, A2, A3, A4)> AsStdFunction() { + ::std::function<R(A0, A1, A2, A3, A4)> AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) -> R { - return this->Call(a0, a1, a2, a3, a4); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -996,9 +1274,10 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5)> { MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5)); #if GTEST_HAS_STD_FUNCTION_ - std::function<R(A0, A1, A2, A3, A4, A5)> AsStdFunction() { + ::std::function<R(A0, A1, A2, A3, A4, A5)> AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) -> R { - return this->Call(a0, a1, a2, a3, a4, a5); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4), ::std::move(a5)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -1016,9 +1295,10 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> { MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6)); #if GTEST_HAS_STD_FUNCTION_ - std::function<R(A0, A1, A2, A3, A4, A5, A6)> AsStdFunction() { + ::std::function<R(A0, A1, A2, A3, A4, A5, A6)> AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) -> R { - return this->Call(a0, a1, a2, a3, a4, a5, a6); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -1036,9 +1316,11 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> { MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7)); #if GTEST_HAS_STD_FUNCTION_ - std::function<R(A0, A1, A2, A3, A4, A5, A6, A7)> AsStdFunction() { + ::std::function<R(A0, A1, A2, A3, A4, A5, A6, A7)> AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) -> R { - return this->Call(a0, a1, a2, a3, a4, a5, a6, a7); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6), + ::std::move(a7)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -1056,10 +1338,12 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> { MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8)); #if GTEST_HAS_STD_FUNCTION_ - std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> AsStdFunction() { + ::std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) -> R { - return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6), + ::std::move(a7), ::std::move(a8)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -1078,10 +1362,12 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> { MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)); #if GTEST_HAS_STD_FUNCTION_ - std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> AsStdFunction() { + ::std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) -> R { - return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6), + ::std::move(a7), ::std::move(a8), ::std::move(a9)); }; } #endif // GTEST_HAS_STD_FUNCTION_ diff --git a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump index 811502d0..f6e17817 100644 --- a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump +++ b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump @@ -1,6 +1,6 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-function-mockers.h. +$$ This is a Pump source file. Please use Pump to convert +$$ it to gmock-generated-function-mockers.h. $$ $var n = 10 $$ The maximum arity we support. // Copyright 2007, Google Inc. @@ -38,6 +38,8 @@ $var n = 10 $$ The maximum arity we support. // // This file implements function mockers of various arities. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ @@ -68,7 +70,7 @@ $for i [[ $range j 1..i $var typename_As = [[$for j [[, typename A$j]]]] $var As = [[$for j, [[A$j]]]] -$var as = [[$for j, [[a$j]]]] +$var as = [[$for j, [[internal::forward<A$j>(a$j)]]]] $var Aas = [[$for j, [[A$j a$j]]]] $var ms = [[$for j, [[m$j]]]] $var matchers = [[$for j, [[const Matcher<A$j>& m$j]]]] @@ -79,13 +81,8 @@ class FunctionMocker<R($As)> : public typedef R F($As); typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - MockSpec<F>& With($matchers) { - -$if i >= 1 [[ - this->current_spec().SetMatchers(::testing::make_tuple($ms)); - -]] - return this->current_spec(); + MockSpec<F> With($matchers) { + return MockSpec<F>(this, ::testing::make_tuple($ms)); } R Invoke($Aas) { @@ -99,6 +96,58 @@ $if i >= 1 [[ ]] +// Removes the given pointer; this is a helper for the expectation setter method +// for parameterless matchers. +// +// We want to make sure that the user cannot set a parameterless expectation on +// overloaded methods, including methods which are overloaded on const. Example: +// +// class MockClass { +// MOCK_METHOD0(GetName, string&()); +// MOCK_CONST_METHOD0(GetName, const string&()); +// }; +// +// TEST() { +// // This should be an error, as it's not clear which overload is expected. +// EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value)); +// } +// +// Here are the generated expectation-setter methods: +// +// class MockClass { +// // Overload 1 +// MockSpec<string&()> gmock_GetName() { ... } +// // Overload 2. Declared const so that the compiler will generate an +// // error when trying to resolve between this and overload 4 in +// // 'gmock_GetName(WithoutMatchers(), nullptr)'. +// MockSpec<string&()> gmock_GetName( +// const WithoutMatchers&, const Function<string&()>*) const { +// // Removes const from this, calls overload 1 +// return AdjustConstness_(this)->gmock_GetName(); +// } +// +// // Overload 3 +// const string& gmock_GetName() const { ... } +// // Overload 4 +// MockSpec<const string&()> gmock_GetName( +// const WithoutMatchers&, const Function<const string&()>*) const { +// // Does not remove const, calls overload 3 +// return AdjustConstness_const(this)->gmock_GetName(); +// } +// } +// +template <typename MockType> +const MockType* AdjustConstness_const(const MockType* mock) { + return mock; +} + +// Removes const from and returns the given pointer; this is a helper for the +// expectation setter method for parameterless matchers. +template <typename MockType> +MockType* AdjustConstness_(const MockType* mock) { + return const_cast<MockType*>(mock); +} + } // namespace internal // The style guide prohibits "using" statements in a namespace scope @@ -134,11 +183,14 @@ using internal::FunctionMocker; $for i [[ $range j 1..i -$var arg_as = [[$for j, \ - [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]] -$var as = [[$for j, [[gmock_a$j]]]] -$var matcher_as = [[$for j, \ +$var arg_as = [[$for j, [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]] +$var as = [[$for j, \ + [[::testing::internal::forward<GMOCK_ARG_(tn, $j, __VA_ARGS__)>(gmock_a$j)]]]] +$var matcher_arg_as = [[$for j, \ [[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]] +$var matcher_as = [[$for j, [[gmock_a$j]]]] +$var anything_matchers = [[$for j, \ + [[::testing::A<GMOCK_ARG_(tn, $j, __VA_ARGS__)>()]]]] // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ @@ -149,11 +201,17 @@ $var matcher_as = [[$for j, \ GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \ return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method($matcher_as) constness { \ + ::testing::MockSpec<__VA_ARGS__> \ + gmock_##Method($matcher_arg_as) constness { \ GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_($i, constness, Method).With($as); \ + return GMOCK_MOCKER_($i, constness, Method).With($matcher_as); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method($anything_matchers); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method) @@ -263,7 +321,7 @@ class MockFunction; $for i [[ $range j 0..i-1 $var ArgTypes = [[$for j, [[A$j]]]] -$var ArgNames = [[$for j, [[a$j]]]] +$var ArgValues = [[$for j, [[::std::move(a$j)]]]] $var ArgDecls = [[$for j, [[A$j a$j]]]] template <typename R$for j [[, typename A$j]]> class MockFunction<R($ArgTypes)> { @@ -273,9 +331,9 @@ class MockFunction<R($ArgTypes)> { MOCK_METHOD$i[[]]_T(Call, R($ArgTypes)); #if GTEST_HAS_STD_FUNCTION_ - std::function<R($ArgTypes)> AsStdFunction() { + ::std::function<R($ArgTypes)> AsStdFunction() { return [this]($ArgDecls) -> R { - return this->Call($ArgNames); + return this->Call($ArgValues); }; } #endif // GTEST_HAS_STD_FUNCTION_ diff --git a/googlemock/include/gmock/gmock-generated-matchers.h b/googlemock/include/gmock/gmock-generated-matchers.h index 57056fd9..0d46d23b 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h +++ b/googlemock/include/gmock/gmock-generated-matchers.h @@ -35,6 +35,8 @@ // // This file implements some commonly used variadic matchers. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ @@ -779,6 +781,9 @@ ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension // that matches n elements in any order. We support up to n=10 arguments. +// +// If you have >10 elements, consider UnorderedElementsAreArray() or +// UnorderedPointwise() instead. inline internal::UnorderedElementsAreMatcher< ::testing::tuple<> > @@ -1268,7 +1273,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { // using testing::PrintToString; // // MATCHER_P2(InClosedRange, low, hi, -// string(negation ? "is not" : "is") + " in range [" + +// std::string(negation ? "is not" : "is") + " in range [" + // PrintToString(low) + ", " + PrintToString(hi) + "]") { // return low <= arg && arg <= hi; // } @@ -1376,18 +1381,21 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { // ================ // // To learn more about using these macros, please search for 'MATCHER' -// on http://code.google.com/p/googlemock/wiki/CookBook. +// on https://github.com/google/googletest/blob/master/googlemock/docs/ +// CookBook.md #define MATCHER(name, description)\ class name##Matcher {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl()\ {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ @@ -1395,8 +1403,8 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { *gmock_os << FormatDescription(true);\ }\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -1404,7 +1412,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple<>()));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ @@ -1414,14 +1421,13 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { name##Matcher() {\ }\ private:\ - GTEST_DISALLOW_ASSIGN_(name##Matcher);\ };\ inline name##Matcher name() {\ return name##Matcher();\ }\ template <typename arg_type>\ bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1430,22 +1436,24 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ explicit gmock_Impl(p0##_type gmock_p0)\ - : p0(gmock_p0) {}\ + : p0(::testing::internal::move(gmock_p0)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ + p0##_type const p0;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -1453,18 +1461,17 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple<p0##_type>(p0)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ return ::testing::Matcher<arg_type>(\ new gmock_Impl<arg_type>(p0));\ }\ - explicit name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\ + explicit name##MatcherP(p0##_type gmock_p0) : \ + p0(::testing::internal::move(gmock_p0)) {\ }\ - p0##_type p0;\ + p0##_type const p0;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP);\ };\ template <typename p0##_type>\ inline name##MatcherP<p0##_type> name(p0##_type p0) {\ @@ -1473,7 +1480,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { template <typename p0##_type>\ template <typename arg_type>\ bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1482,23 +1489,26 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP2 {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\ - : p0(gmock_p0), p1(gmock_p1) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ + p0##_type const p0;\ + p1##_type const p1;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -1506,20 +1516,19 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple<p0##_type, p1##_type>(p0, p1)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ return ::testing::Matcher<arg_type>(\ new gmock_Impl<arg_type>(p0, p1));\ }\ - name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ - p1(gmock_p1) {\ + name##MatcherP2(p0##_type gmock_p0, \ + p1##_type gmock_p1) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ + p0##_type const p0;\ + p1##_type const p1;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\ };\ template <typename p0##_type, typename p1##_type>\ inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \ @@ -1530,7 +1539,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { template <typename arg_type>\ bool name##MatcherP2<p0##_type, \ p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1539,24 +1548,28 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP3 {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -1565,7 +1578,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { ::testing::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \ p2)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ @@ -1573,13 +1585,14 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { new gmock_Impl<arg_type>(p0, p1, p2));\ }\ name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\ + p2##_type gmock_p2) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\ };\ template <typename p0##_type, typename p1##_type, typename p2##_type>\ inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \ @@ -1590,7 +1603,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { template <typename arg_type>\ bool name##MatcherP3<p0##_type, p1##_type, \ p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1600,26 +1613,31 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP4 {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ p3##_type gmock_p3)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -1628,7 +1646,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { ::testing::tuple<p0##_type, p1##_type, p2##_type, \ p3##_type>(p0, p1, p2, p3)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ @@ -1636,15 +1653,17 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { new gmock_Impl<arg_type>(p0, p1, p2, p3));\ }\ name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3) {\ + p2##_type gmock_p2, \ + p3##_type gmock_p3) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\ };\ template <typename p0##_type, typename p1##_type, typename p2##_type, \ typename p3##_type>\ @@ -1659,7 +1678,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { template <typename arg_type>\ bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \ p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1669,28 +1688,33 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP5 {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ p3##_type gmock_p3, p4##_type gmock_p4)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -1699,7 +1723,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ p4##_type>(p0, p1, p2, p3, p4)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ @@ -1708,16 +1731,18 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { }\ name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2, p3##_type gmock_p3, \ - p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4) {\ + p4##_type gmock_p4) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\ };\ template <typename p0##_type, typename p1##_type, typename p2##_type, \ typename p3##_type, typename p4##_type>\ @@ -1732,7 +1757,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 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, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1742,29 +1767,35 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP6 {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ + p5##_type const p5;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -1773,7 +1804,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { ::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \ p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ @@ -1782,17 +1812,20 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { }\ name##MatcherP6(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\ + p5##_type gmock_p5) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ + p5##_type const p5;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\ };\ template <typename p0##_type, typename p1##_type, typename p2##_type, \ typename p3##_type, typename p4##_type, typename p5##_type>\ @@ -1807,7 +1840,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 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, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1818,31 +1851,38 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP7 {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ + p5##_type const p5;\ + p6##_type const p6;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -1852,7 +1892,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \ p6)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ @@ -1861,19 +1900,23 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { }\ name##MatcherP7(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(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ - p6(gmock_p6) {\ + p5##_type gmock_p5, \ + p6##_type gmock_p6) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ + p5##_type const p5;\ + p6##_type const p6;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\ };\ template <typename p0##_type, typename p1##_type, typename p2##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \ @@ -1891,7 +1934,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 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, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1902,32 +1945,40 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP8 {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ + p5##_type const p5;\ + p6##_type const p6;\ + p7##_type const p7;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -1937,7 +1988,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \ p3, p4, p5, p6, p7)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ @@ -1947,20 +1997,24 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { name##MatcherP8(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7) {\ + p7##_type gmock_p7) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_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;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ + p5##_type const p5;\ + p6##_type const p6;\ + p7##_type const p7;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\ };\ template <typename p0##_type, typename p1##_type, typename p2##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \ @@ -1980,7 +2034,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 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, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1991,34 +2045,42 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP9 {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_p8)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - 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;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ + p5##_type const p5;\ + p6##_type const p6;\ + p7##_type const p7;\ + p8##_type const p8;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -2028,7 +2090,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { p4##_type, p5##_type, p6##_type, p7##_type, \ p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ @@ -2038,21 +2099,26 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { name##MatcherP9(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8) {\ + p8##_type gmock_p8) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_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;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ + p5##_type const p5;\ + p6##_type const p6;\ + p7##_type const p7;\ + p8##_type const p8;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\ };\ template <typename p0##_type, typename p1##_type, typename p2##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \ @@ -2073,7 +2139,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 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, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -2085,36 +2151,45 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP10 {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8), p9(gmock_p9) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_p8)), \ + p9(::testing::internal::move(gmock_p9)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - 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;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ + p5##_type const p5;\ + p6##_type const p6;\ + p7##_type const p7;\ + p8##_type const p8;\ + p9##_type const p9;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -2124,7 +2199,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ @@ -2134,22 +2208,29 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { name##MatcherP10(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(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\ + p8##_type gmock_p8, \ + p9##_type gmock_p9) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_p8)), \ + p9(::testing::internal::move(gmock_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;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ + p5##_type const p5;\ + p6##_type const p6;\ + p7##_type const p7;\ + p8##_type const p8;\ + p9##_type const p9;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\ };\ template <typename p0##_type, typename p1##_type, typename p2##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \ @@ -2172,7 +2253,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 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, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const diff --git a/googlemock/include/gmock/gmock-generated-matchers.h.pump b/googlemock/include/gmock/gmock-generated-matchers.h.pump index de30c2c9..9fe0fd7a 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h.pump +++ b/googlemock/include/gmock/gmock-generated-matchers.h.pump @@ -1,6 +1,6 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-actions.h. +$$ This is a Pump source file. Please use Pump to convert +$$ it to gmock-generated-matchers.h. $$ $var n = 10 $$ The maximum arity we support. $$ }} This line fixes auto-indentation of the following code in Emacs. @@ -37,6 +37,8 @@ $$ }} This line fixes auto-indentation of the following code in Emacs. // // This file implements some commonly used variadic matchers. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ @@ -303,6 +305,9 @@ $for j, [[ // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension // that matches n elements in any order. We support up to n=$n arguments. +// +// If you have >$n elements, consider UnorderedElementsAreArray() or +// UnorderedPointwise() instead. $range i 0..n $for i [[ @@ -479,7 +484,7 @@ $$ // show up in the generated code. // using testing::PrintToString; // // MATCHER_P2(InClosedRange, low, hi, -// string(negation ? "is not" : "is") + " in range [" + +// std::string(negation ? "is not" : "is") + " in range [" + // PrintToString(low) + ", " + PrintToString(hi) + "]") { // return low <= arg && arg <= hi; // } @@ -587,7 +592,7 @@ $$ // show up in the generated code. // ================ // // To learn more about using these macros, please search for 'MATCHER' -// on http://code.google.com/p/googlemock/wiki/CookBook. +// on https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md $range i 0..n $for i @@ -604,32 +609,34 @@ $var template = [[$if i==0 [[]] $else [[ ]]]] $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(gmock_p$j)]]]]]] -$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]] +$var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::move(gmock_p$j))]]]]]] +$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::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]]]] $var param_field_decls = [[$for j [[ - p$j##_type p$j;\ + p$j##_type const p$j;\ ]]]] $var param_field_decls2 = [[$for j [[ - p$j##_type p$j;\ + p$j##_type const p$j;\ ]]]] #define $macro_name(name$for j [[, p$j]], description)\$template class $class_name {\ public:\ template <typename arg_type>\ - class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ [[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\ $impl_inits {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ @@ -637,8 +644,8 @@ $var param_field_decls2 = [[$for j *gmock_os << FormatDescription(true);\ }\$param_field_decls private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ if (!gmock_description.empty())\ return gmock_description;\ return ::testing::internal::FormatMatcherDescription(\ @@ -646,7 +653,6 @@ $var param_field_decls2 = [[$for j ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template <typename arg_type>\ operator ::testing::Matcher<arg_type>() const {\ @@ -656,14 +662,13 @@ $var param_field_decls2 = [[$for j [[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {\ }\$param_field_decls2 private:\ - GTEST_DISALLOW_ASSIGN_($class_name);\ };\$template inline $class_name$param_types name($param_types_and_names) {\ return $class_name$param_types($params);\ }\$template template <typename arg_type>\ bool $class_name$param_types::gmock_Impl<arg_type>::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const ]] diff --git a/googlemock/include/gmock/gmock-generated-nice-strict.h b/googlemock/include/gmock/gmock-generated-nice-strict.h index 4095f4d5..96d6f392 100644 --- a/googlemock/include/gmock/gmock-generated-nice-strict.h +++ b/googlemock/include/gmock/gmock-generated-nice-strict.h @@ -51,10 +51,9 @@ // NiceMock<MockFoo>. // // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of -// their respective base class, with up-to 10 arguments. Therefore -// you can write NiceMock<MockFoo>(5, "a") to construct a nice mock -// where MockFoo has a constructor that accepts (int, const char*), -// for example. +// their respective base class. Therefore you can write +// NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo +// has a constructor that accepts (int, const char*), for example. // // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>, // and StrictMock<MockFoo> only works for mock methods defined using @@ -63,10 +62,8 @@ // or "strict" modifier may not affect it, depending on the compiler. // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT // supported. -// -// Another known limitation is that the constructors of the base mock -// cannot have arguments passed by non-const reference, which are -// banned by the Google C++ style guide anyway. + +// GOOGLETEST_CM0002 DO NOT DELETE #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ @@ -79,15 +76,35 @@ namespace testing { template <class MockClass> class NiceMock : public MockClass { public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - NiceMock() { + NiceMock() : MockClass() { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_<MockClass*>(this)); + } + +#if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + + // Single argument constructor is special-cased so that it can be + // made explicit. + template <typename A> + explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) { ::testing::Mock::AllowUninterestingCalls( internal::ImplicitCast_<MockClass*>(this)); } - // C++ doesn't (yet) allow inheritance of constructors, so we have - // to define it for each arity. + template <typename A1, typename A2, typename... An> + NiceMock(A1&& arg1, A2&& arg2, An&&... args) + : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2), + std::forward<An>(args)...) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_<MockClass*>(this)); + } +#else + // C++98 doesn't have variadic templates, so we have to define one + // for each arity. template <typename A1> explicit NiceMock(const A1& a1) : MockClass(a1) { ::testing::Mock::AllowUninterestingCalls( @@ -163,7 +180,9 @@ class NiceMock : public MockClass { internal::ImplicitCast_<MockClass*>(this)); } - virtual ~NiceMock() { +#endif // GTEST_LANG_CXX11 + + ~NiceMock() { ::testing::Mock::UnregisterCallReaction( internal::ImplicitCast_<MockClass*>(this)); } @@ -175,15 +194,35 @@ class NiceMock : public MockClass { template <class MockClass> class NaggyMock : public MockClass { public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - NaggyMock() { + NaggyMock() : MockClass() { ::testing::Mock::WarnUninterestingCalls( internal::ImplicitCast_<MockClass*>(this)); } - // C++ doesn't (yet) allow inheritance of constructors, so we have - // to define it for each arity. +#if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + + // Single argument constructor is special-cased so that it can be + // made explicit. + template <typename A> + explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_<MockClass*>(this)); + } + + template <typename A1, typename A2, typename... An> + NaggyMock(A1&& arg1, A2&& arg2, An&&... args) + : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2), + std::forward<An>(args)...) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_<MockClass*>(this)); + } +#else + // C++98 doesn't have variadic templates, so we have to define one + // for each arity. template <typename A1> explicit NaggyMock(const A1& a1) : MockClass(a1) { ::testing::Mock::WarnUninterestingCalls( @@ -259,7 +298,9 @@ class NaggyMock : public MockClass { internal::ImplicitCast_<MockClass*>(this)); } - virtual ~NaggyMock() { +#endif // GTEST_LANG_CXX11 + + ~NaggyMock() { ::testing::Mock::UnregisterCallReaction( internal::ImplicitCast_<MockClass*>(this)); } @@ -271,15 +312,35 @@ class NaggyMock : public MockClass { template <class MockClass> class StrictMock : public MockClass { public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - StrictMock() { + StrictMock() : MockClass() { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_<MockClass*>(this)); + } + +#if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + + // Single argument constructor is special-cased so that it can be + // made explicit. + template <typename A> + explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) { ::testing::Mock::FailUninterestingCalls( internal::ImplicitCast_<MockClass*>(this)); } - // C++ doesn't (yet) allow inheritance of constructors, so we have - // to define it for each arity. + template <typename A1, typename A2, typename... An> + StrictMock(A1&& arg1, A2&& arg2, An&&... args) + : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2), + std::forward<An>(args)...) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_<MockClass*>(this)); + } +#else + // C++98 doesn't have variadic templates, so we have to define one + // for each arity. template <typename A1> explicit StrictMock(const A1& a1) : MockClass(a1) { ::testing::Mock::FailUninterestingCalls( @@ -355,7 +416,9 @@ class StrictMock : public MockClass { internal::ImplicitCast_<MockClass*>(this)); } - virtual ~StrictMock() { +#endif // GTEST_LANG_CXX11 + + ~StrictMock() { ::testing::Mock::UnregisterCallReaction( internal::ImplicitCast_<MockClass*>(this)); } diff --git a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump index 3ee1ce7f..7c2bf36a 100644 --- a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump +++ b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump @@ -1,6 +1,6 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-nice-strict.h. +$$ This is a Pump source file. Please use Pump to convert +$$ it to gmock-generated-nice-strict.h. $$ $var n = 10 $$ The maximum arity we support. // Copyright 2008, Google Inc. @@ -52,10 +52,9 @@ $var n = 10 $$ The maximum arity we support. // NiceMock<MockFoo>. // // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of -// their respective base class, with up-to $n arguments. Therefore -// you can write NiceMock<MockFoo>(5, "a") to construct a nice mock -// where MockFoo has a constructor that accepts (int, const char*), -// for example. +// their respective base class. Therefore you can write +// NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo +// has a constructor that accepts (int, const char*), for example. // // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>, // and StrictMock<MockFoo> only works for mock methods defined using @@ -64,10 +63,8 @@ $var n = 10 $$ The maximum arity we support. // or "strict" modifier may not affect it, depending on the compiler. // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT // supported. -// -// Another known limitation is that the constructors of the base mock -// cannot have arguments passed by non-const reference, which are -// banned by the Google C++ style guide anyway. + +// GOOGLETEST_CM0002 DO NOT DELETE #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ @@ -91,15 +88,35 @@ $var method=[[$if kind==0 [[AllowUninterestingCalls]] template <class MockClass> class $clazz : public MockClass { public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - $clazz() { + $clazz() : MockClass() { ::testing::Mock::$method( internal::ImplicitCast_<MockClass*>(this)); } - // C++ doesn't (yet) allow inheritance of constructors, so we have - // to define it for each arity. +#if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + + // Single argument constructor is special-cased so that it can be + // made explicit. + template <typename A> + explicit $clazz(A&& arg) : MockClass(std::forward<A>(arg)) { + ::testing::Mock::$method( + internal::ImplicitCast_<MockClass*>(this)); + } + + template <typename A1, typename A2, typename... An> + $clazz(A1&& arg1, A2&& arg2, An&&... args) + : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2), + std::forward<An>(args)...) { + ::testing::Mock::$method( + internal::ImplicitCast_<MockClass*>(this)); + } +#else + // C++98 doesn't have variadic templates, so we have to define one + // for each arity. template <typename A1> explicit $clazz(const A1& a1) : MockClass(a1) { ::testing::Mock::$method( @@ -117,7 +134,9 @@ $range j 1..i ]] - virtual ~$clazz() { +#endif // GTEST_LANG_CXX11 + + ~$clazz() { ::testing::Mock::UnregisterCallReaction( internal::ImplicitCast_<MockClass*>(this)); } diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 33b37a7a..adf49993 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -35,6 +35,8 @@ // matchers can be defined by the user implementing the // MatcherInterface<T> interface if necessary. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ @@ -47,10 +49,9 @@ #include <string> #include <utility> #include <vector> - +#include "gtest/gtest.h" #include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" #if GTEST_HAS_STD_INITIALIZER_LIST_ # include <initializer_list> // NOLINT -- must be after gtest.h @@ -180,13 +181,42 @@ class MatcherInterface : public MatcherDescriberInterface { // virtual void DescribeNegationTo(::std::ostream* os) const; }; +namespace internal { + +// Converts a MatcherInterface<T> to a MatcherInterface<const T&>. +template <typename T> +class MatcherInterfaceAdapter : public MatcherInterface<const T&> { + public: + explicit MatcherInterfaceAdapter(const MatcherInterface<T>* impl) + : impl_(impl) {} + virtual ~MatcherInterfaceAdapter() { delete impl_; } + + virtual void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } + + virtual void DescribeNegationTo(::std::ostream* os) const { + impl_->DescribeNegationTo(os); + } + + virtual bool MatchAndExplain(const T& x, + MatchResultListener* listener) const { + return impl_->MatchAndExplain(x, listener); + } + + private: + const MatcherInterface<T>* const impl_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(MatcherInterfaceAdapter); +}; + +} // namespace internal + // A match result listener that stores the explanation in a string. class StringMatchResultListener : public MatchResultListener { public: StringMatchResultListener() : MatchResultListener(&ss_) {} // Returns the explanation accumulated so far. - internal::string str() const { return ss_.str(); } + std::string str() const { return ss_.str(); } // Clears the explanation accumulated so far. void Clear() { ss_.str(""); } @@ -253,12 +283,13 @@ class MatcherBase { public: // Returns true iff the matcher matches x; also explains the match // result to 'listener'. - bool MatchAndExplain(T x, MatchResultListener* listener) const { + bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, + MatchResultListener* listener) const { return impl_->MatchAndExplain(x, listener); } // Returns true iff this matcher matches x. - bool Matches(T x) const { + bool Matches(GTEST_REFERENCE_TO_CONST_(T) x) const { DummyMatchResultListener dummy; return MatchAndExplain(x, &dummy); } @@ -272,7 +303,8 @@ class MatcherBase { } // Explains why x matches, or doesn't match, the matcher. - void ExplainMatchResultTo(T x, ::std::ostream* os) const { + void ExplainMatchResultTo(GTEST_REFERENCE_TO_CONST_(T) x, + ::std::ostream* os) const { StreamMatchResultListener listener(os); MatchAndExplain(x, &listener); } @@ -288,9 +320,18 @@ class MatcherBase { MatcherBase() {} // Constructs a matcher from its implementation. - explicit MatcherBase(const MatcherInterface<T>* impl) + explicit MatcherBase( + const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl) : impl_(impl) {} + template <typename U> + explicit MatcherBase( + const MatcherInterface<U>* impl, + typename internal::EnableIf< + !internal::IsSame<U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* = + NULL) + : impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {} + virtual ~MatcherBase() {} private: @@ -305,7 +346,9 @@ class MatcherBase { // // If performance becomes a problem, we should see if using // shared_ptr helps. - ::testing::internal::linked_ptr<const MatcherInterface<T> > impl_; + ::testing::internal::linked_ptr< + const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> > + impl_; }; } // namespace internal @@ -324,7 +367,13 @@ class Matcher : public internal::MatcherBase<T> { explicit Matcher() {} // NOLINT // Constructs a matcher from its implementation. - explicit Matcher(const MatcherInterface<T>* impl) + explicit Matcher(const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl) + : internal::MatcherBase<T>(impl) {} + + template <typename U> + explicit Matcher(const MatcherInterface<U>* impl, + typename internal::EnableIf<!internal::IsSame< + U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* = NULL) : internal::MatcherBase<T>(impl) {} // Implicit constructor here allows people to write @@ -333,86 +382,170 @@ class Matcher : public internal::MatcherBase<T> { }; // The following two specializations allow the user to write str -// instead of Eq(str) and "foo" instead of Eq("foo") when a string +// instead of Eq(str) and "foo" instead of Eq("foo") when a std::string // matcher is expected. template <> -class GTEST_API_ Matcher<const internal::string&> - : public internal::MatcherBase<const internal::string&> { +class GTEST_API_ Matcher<const std::string&> + : public internal::MatcherBase<const std::string&> { public: Matcher() {} - explicit Matcher(const MatcherInterface<const internal::string&>* impl) - : internal::MatcherBase<const internal::string&>(impl) {} + explicit Matcher(const MatcherInterface<const std::string&>* impl) + : internal::MatcherBase<const std::string&>(impl) {} // Allows the user to write str instead of Eq(str) sometimes, where - // str is a string object. - Matcher(const internal::string& s); // NOLINT + // str is a std::string object. + Matcher(const std::string& s); // NOLINT + +#if GTEST_HAS_GLOBAL_STRING + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT +#endif // GTEST_HAS_GLOBAL_STRING // Allows the user to write "foo" instead of Eq("foo") sometimes. Matcher(const char* s); // NOLINT }; template <> -class GTEST_API_ Matcher<internal::string> - : public internal::MatcherBase<internal::string> { +class GTEST_API_ Matcher<std::string> + : public internal::MatcherBase<std::string> { public: Matcher() {} - explicit Matcher(const MatcherInterface<internal::string>* impl) - : internal::MatcherBase<internal::string>(impl) {} + explicit Matcher(const MatcherInterface<const std::string&>* impl) + : internal::MatcherBase<std::string>(impl) {} + explicit Matcher(const MatcherInterface<std::string>* impl) + : internal::MatcherBase<std::string>(impl) {} // Allows the user to write str instead of Eq(str) sometimes, where // str is a string object. - Matcher(const internal::string& s); // NOLINT + Matcher(const std::string& s); // NOLINT + +#if GTEST_HAS_GLOBAL_STRING + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT +#endif // GTEST_HAS_GLOBAL_STRING // Allows the user to write "foo" instead of Eq("foo") sometimes. Matcher(const char* s); // NOLINT }; -#if GTEST_HAS_STRING_PIECE_ +#if GTEST_HAS_GLOBAL_STRING // The following two specializations allow the user to write str -// instead of Eq(str) and "foo" instead of Eq("foo") when a StringPiece +// instead of Eq(str) and "foo" instead of Eq("foo") when a ::string // matcher is expected. template <> -class GTEST_API_ Matcher<const StringPiece&> - : public internal::MatcherBase<const StringPiece&> { +class GTEST_API_ Matcher<const ::string&> + : public internal::MatcherBase<const ::string&> { public: Matcher() {} - explicit Matcher(const MatcherInterface<const StringPiece&>* impl) - : internal::MatcherBase<const StringPiece&>(impl) {} + explicit Matcher(const MatcherInterface<const ::string&>* impl) + : internal::MatcherBase<const ::string&>(impl) {} // Allows the user to write str instead of Eq(str) sometimes, where - // str is a string object. - Matcher(const internal::string& s); // NOLINT + // str is a std::string object. + Matcher(const std::string& s); // NOLINT + + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT // Allows the user to write "foo" instead of Eq("foo") sometimes. Matcher(const char* s); // NOLINT +}; + +template <> +class GTEST_API_ Matcher< ::string> + : public internal::MatcherBase< ::string> { + public: + Matcher() {} + + explicit Matcher(const MatcherInterface<const ::string&>* impl) + : internal::MatcherBase< ::string>(impl) {} + explicit Matcher(const MatcherInterface< ::string>* impl) + : internal::MatcherBase< ::string>(impl) {} + + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a std::string object. + Matcher(const std::string& s); // NOLINT - // Allows the user to pass StringPieces directly. - Matcher(StringPiece s); // NOLINT + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT + + // Allows the user to write "foo" instead of Eq("foo") sometimes. + Matcher(const char* s); // NOLINT }; +#endif // GTEST_HAS_GLOBAL_STRING +#if GTEST_HAS_ABSL +// The following two specializations allow the user to write str +// instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view +// matcher is expected. template <> -class GTEST_API_ Matcher<StringPiece> - : public internal::MatcherBase<StringPiece> { +class GTEST_API_ Matcher<const absl::string_view&> + : public internal::MatcherBase<const absl::string_view&> { public: Matcher() {} - explicit Matcher(const MatcherInterface<StringPiece>* impl) - : internal::MatcherBase<StringPiece>(impl) {} + explicit Matcher(const MatcherInterface<const absl::string_view&>* impl) + : internal::MatcherBase<const absl::string_view&>(impl) {} // Allows the user to write str instead of Eq(str) sometimes, where - // str is a string object. - Matcher(const internal::string& s); // NOLINT + // str is a std::string object. + Matcher(const std::string& s); // NOLINT + +#if GTEST_HAS_GLOBAL_STRING + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT +#endif // GTEST_HAS_GLOBAL_STRING // Allows the user to write "foo" instead of Eq("foo") sometimes. Matcher(const char* s); // NOLINT - // Allows the user to pass StringPieces directly. - Matcher(StringPiece s); // NOLINT + // Allows the user to pass absl::string_views directly. + Matcher(absl::string_view s); // NOLINT }; -#endif // GTEST_HAS_STRING_PIECE_ + +template <> +class GTEST_API_ Matcher<absl::string_view> + : public internal::MatcherBase<absl::string_view> { + public: + Matcher() {} + + explicit Matcher(const MatcherInterface<const absl::string_view&>* impl) + : internal::MatcherBase<absl::string_view>(impl) {} + explicit Matcher(const MatcherInterface<absl::string_view>* impl) + : internal::MatcherBase<absl::string_view>(impl) {} + + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a std::string object. + Matcher(const std::string& s); // NOLINT + +#if GTEST_HAS_GLOBAL_STRING + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT +#endif // GTEST_HAS_GLOBAL_STRING + + // Allows the user to write "foo" instead of Eq("foo") sometimes. + Matcher(const char* s); // NOLINT + + // Allows the user to pass absl::string_views directly. + Matcher(absl::string_view s); // NOLINT +}; +#endif // GTEST_HAS_ABSL + +// Prints a matcher in a human-readable format. +template <typename T> +std::ostream& operator<<(std::ostream& os, const Matcher<T>& matcher) { + matcher.DescribeTo(&os); + return os; +} // The PolymorphicMatcher class template makes it easy to implement a // polymorphic matcher (i.e. a matcher that can match values of more @@ -441,7 +574,7 @@ class PolymorphicMatcher { template <typename T> operator Matcher<T>() const { - return Matcher<T>(new MonomorphicImpl<T>(impl_)); + return Matcher<T>(new MonomorphicImpl<GTEST_REFERENCE_TO_CONST_(T)>(impl_)); } private: @@ -515,7 +648,7 @@ template <typename T, typename M> class MatcherCastImpl { public: static Matcher<T> Cast(const M& polymorphic_matcher_or_value) { - // M can be a polymorhic matcher, in which case we want to use + // M can be a polymorphic 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. // @@ -531,21 +664,18 @@ class MatcherCastImpl { return CastImpl( polymorphic_matcher_or_value, BooleanConstant< - internal::ImplicitlyConvertible<M, Matcher<T> >::value>()); + internal::ImplicitlyConvertible<M, Matcher<T> >::value>(), + BooleanConstant< + internal::ImplicitlyConvertible<M, T>::value>()); } private: - static Matcher<T> CastImpl(const 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)); - } - + template <bool Ignore> static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value, - BooleanConstant<true>) { + BooleanConstant<true> /* convertible_to_matcher */, + BooleanConstant<Ignore>) { // M is implicitly convertible to Matcher<T>, which means that either - // M is a polymorhpic matcher or Matcher<T> has an implicit constructor + // M is a polymorphic matcher or Matcher<T> has an implicit constructor // from M. In both cases using the implicit conversion will produce a // matcher. // @@ -554,6 +684,29 @@ class MatcherCastImpl { // (first to create T from M and then to create Matcher<T> from T). return polymorphic_matcher_or_value; } + + // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic + // matcher. It's a value of a type implicitly convertible to T. Use direct + // initialization to create a matcher. + static Matcher<T> CastImpl( + const M& value, BooleanConstant<false> /* convertible_to_matcher */, + BooleanConstant<true> /* convertible_to_T */) { + return Matcher<T>(ImplicitCast_<T>(value)); + } + + // M can't be implicitly converted to either Matcher<T> or T. Attempt to use + // polymorphic matcher Eq(value) in this case. + // + // Note that we first attempt to perform an implicit cast on the value and + // only fall back to the polymorphic Eq() matcher afterwards because the + // latter calls bool operator==(const Lhs& lhs, const Rhs& rhs) in the end + // which might be undefined even when Rhs is implicitly convertible to Lhs + // (e.g. std::pair<const int, int> vs. std::pair<int, int>). + // + // We don't define this method inline as we need the declaration of Eq(). + static Matcher<T> CastImpl( + const M& value, BooleanConstant<false> /* convertible_to_matcher */, + BooleanConstant<false> /* convertible_to_T */); }; // This more specialized version is used when MatcherCast()'s argument @@ -574,6 +727,22 @@ class MatcherCastImpl<T, Matcher<U> > { // We delegate the matching logic to the source matcher. virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { +#if GTEST_LANG_CXX11 + using FromType = typename std::remove_cv<typename std::remove_pointer< + typename std::remove_reference<T>::type>::type>::type; + using ToType = typename std::remove_cv<typename std::remove_pointer< + typename std::remove_reference<U>::type>::type>::type; + // Do not allow implicitly converting base*/& to derived*/&. + static_assert( + // Do not trigger if only one of them is a pointer. That implies a + // regular conversion and not a down_cast. + (std::is_pointer<typename std::remove_reference<T>::type>::value != + std::is_pointer<typename std::remove_reference<U>::type>::value) || + std::is_same<FromType, ToType>::value || + !std::is_base_of<FromType, ToType>::value, + "Can't implicitly convert from <base> to <derived>"); +#endif // GTEST_LANG_CXX11 + return source_matcher_.MatchAndExplain(static_cast<U>(x), listener); } @@ -646,7 +815,7 @@ class SafeMatcherCastImpl { // type U. GTEST_COMPILE_ASSERT_( internal::is_reference<T>::value || !internal::is_reference<U>::value, - cannot_convert_non_referentce_arg_to_reference); + cannot_convert_non_reference_arg_to_reference); // In case both T and U are arithmetic types, enforce that the // conversion is not lossy. typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT; @@ -675,7 +844,7 @@ Matcher<T> A(); namespace internal { // If the explanation is not empty, prints it to the ostream. -inline void PrintIfNotEmpty(const internal::string& explanation, +inline void PrintIfNotEmpty(const std::string& explanation, ::std::ostream* os) { if (explanation != "" && os != NULL) { *os << ", " << explanation; @@ -685,11 +854,11 @@ inline void PrintIfNotEmpty(const internal::string& explanation, // Returns true if the given type name is easy to read by a human. // This is used to decide whether printing the type of a value might // be helpful. -inline bool IsReadableTypeName(const string& type_name) { +inline bool IsReadableTypeName(const std::string& type_name) { // We consider a type name readable if it's short or doesn't contain // a template or function type. return (type_name.length() <= 20 || - type_name.find_first_of("<(") == string::npos); + type_name.find_first_of("<(") == std::string::npos); } // Matches the value against the given matcher, prints the value and explains @@ -711,7 +880,7 @@ bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher, UniversalPrint(value, listener->stream()); #if GTEST_HAS_RTTI - const string& type_name = GetTypeName<Value>(); + const std::string& type_name = GetTypeName<Value>(); if (IsReadableTypeName(type_name)) *listener->stream() << " (of type " << type_name << ")"; #endif @@ -751,7 +920,7 @@ class TuplePrefix { typename tuple_element<N - 1, MatcherTuple>::type matcher = get<N - 1>(matchers); typedef typename tuple_element<N - 1, ValueTuple>::type Value; - Value value = get<N - 1>(values); + GTEST_REFERENCE_TO_CONST_(Value) value = get<N - 1>(values); StringMatchResultListener listener; if (!matcher.MatchAndExplain(value, &listener)) { // TODO(wan): include in the message the name of the parameter @@ -856,10 +1025,12 @@ OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) { // Implements A<T>(). template <typename T> -class AnyMatcherImpl : public MatcherInterface<T> { +class AnyMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { public: - virtual bool MatchAndExplain( - T /* x */, MatchResultListener* /* listener */) const { return true; } + virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) /* x */, + MatchResultListener* /* listener */) const { + return true; + } virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; } virtual void DescribeNegationTo(::std::ostream* os) const { // This is mostly for completeness' safe, as it's not very useful @@ -1129,6 +1300,19 @@ class StrEqualityMatcher { bool case_sensitive) : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {} +#if GTEST_HAS_ABSL + bool MatchAndExplain(const absl::string_view& s, + MatchResultListener* listener) const { + if (s.data() == NULL) { + return !expect_eq_; + } + // This should fail to compile if absl::string_view is used with wide + // strings. + const StringType& str = string(s); + return MatchAndExplain(str, listener); + } +#endif // GTEST_HAS_ABSL + // Accepts pointer types, particularly: // const char* // char* @@ -1145,7 +1329,7 @@ class StrEqualityMatcher { // Matches anything that can convert to StringType. // // This is a template, not just a plain function with const StringType&, - // because StringPiece has some interfering non-explicit constructors. + // because absl::string_view has some interfering non-explicit constructors. template <typename MatcheeStringType> bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { @@ -1189,6 +1373,19 @@ class HasSubstrMatcher { explicit HasSubstrMatcher(const StringType& substring) : substring_(substring) {} +#if GTEST_HAS_ABSL + bool MatchAndExplain(const absl::string_view& s, + MatchResultListener* listener) const { + if (s.data() == NULL) { + return false; + } + // This should fail to compile if absl::string_view is used with wide + // strings. + const StringType& str = string(s); + return MatchAndExplain(str, listener); + } +#endif // GTEST_HAS_ABSL + // Accepts pointer types, particularly: // const char* // char* @@ -1202,7 +1399,7 @@ class HasSubstrMatcher { // Matches anything that can convert to StringType. // // This is a template, not just a plain function with const StringType&, - // because StringPiece has some interfering non-explicit constructors. + // because absl::string_view has some interfering non-explicit constructors. template <typename MatcheeStringType> bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { @@ -1236,6 +1433,19 @@ class StartsWithMatcher { explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) { } +#if GTEST_HAS_ABSL + bool MatchAndExplain(const absl::string_view& s, + MatchResultListener* listener) const { + if (s.data() == NULL) { + return false; + } + // This should fail to compile if absl::string_view is used with wide + // strings. + const StringType& str = string(s); + return MatchAndExplain(str, listener); + } +#endif // GTEST_HAS_ABSL + // Accepts pointer types, particularly: // const char* // char* @@ -1249,7 +1459,7 @@ class StartsWithMatcher { // Matches anything that can convert to StringType. // // This is a template, not just a plain function with const StringType&, - // because StringPiece has some interfering non-explicit constructors. + // because absl::string_view has some interfering non-explicit constructors. template <typename MatcheeStringType> bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { @@ -1282,6 +1492,19 @@ class EndsWithMatcher { public: explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {} +#if GTEST_HAS_ABSL + bool MatchAndExplain(const absl::string_view& s, + MatchResultListener* listener) const { + if (s.data() == NULL) { + return false; + } + // This should fail to compile if absl::string_view is used with wide + // strings. + const StringType& str = string(s); + return MatchAndExplain(str, listener); + } +#endif // GTEST_HAS_ABSL + // Accepts pointer types, particularly: // const char* // char* @@ -1295,7 +1518,7 @@ class EndsWithMatcher { // Matches anything that can convert to StringType. // // This is a template, not just a plain function with const StringType&, - // because StringPiece has some interfering non-explicit constructors. + // because absl::string_view has some interfering non-explicit constructors. template <typename MatcheeStringType> bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { @@ -1328,6 +1551,13 @@ class MatchesRegexMatcher { MatchesRegexMatcher(const RE* regex, bool full_match) : regex_(regex), full_match_(full_match) {} +#if GTEST_HAS_ABSL + bool MatchAndExplain(const absl::string_view& s, + MatchResultListener* listener) const { + return s.data() && MatchAndExplain(string(s), listener); + } +#endif // GTEST_HAS_ABSL + // Accepts pointer types, particularly: // const char* // char* @@ -1335,17 +1565,17 @@ class MatchesRegexMatcher { // wchar_t* template <typename CharType> bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(internal::string(s), listener); + return s != NULL && MatchAndExplain(std::string(s), listener); } - // Matches anything that can convert to internal::string. + // Matches anything that can convert to std::string. // - // This is a template, not just a plain function with const internal::string&, - // because StringPiece has some interfering non-explicit constructors. + // This is a template, not just a plain function with const std::string&, + // because absl::string_view has some interfering non-explicit constructors. template <class MatcheeStringType> bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const internal::string& s2(s); + const std::string& s2(s); return full_match_ ? RE::FullMatch(s2, *regex_) : RE::PartialMatch(s2, *regex_); } @@ -1353,13 +1583,13 @@ class MatchesRegexMatcher { void DescribeTo(::std::ostream* os) const { *os << (full_match_ ? "matches" : "contains") << " regular expression "; - UniversalPrinter<internal::string>::Print(regex_->pattern(), os); + UniversalPrinter<std::string>::Print(regex_->pattern(), os); } void DescribeNegationTo(::std::ostream* os) const { *os << "doesn't " << (full_match_ ? "match" : "contain") << " regular expression "; - UniversalPrinter<internal::string>::Print(regex_->pattern(), os); + UniversalPrinter<std::string>::Print(regex_->pattern(), os); } private: @@ -1441,12 +1671,13 @@ class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> { // will prevent different instantiations of NotMatcher from sharing // the same NotMatcherImpl<T> class. template <typename T> -class NotMatcherImpl : public MatcherInterface<T> { +class NotMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { public: explicit NotMatcherImpl(const Matcher<T>& matcher) : matcher_(matcher) {} - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, + MatchResultListener* listener) const { return !matcher_.MatchAndExplain(x, listener); } @@ -1489,117 +1720,66 @@ class NotMatcher { // that will prevent different instantiations of BothOfMatcher from // sharing the same BothOfMatcherImpl<T> class. template <typename T> -class BothOfMatcherImpl : public MatcherInterface<T> { +class AllOfMatcherImpl + : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { public: - BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2) - : matcher1_(matcher1), matcher2_(matcher2) {} + explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers) + : matchers_(internal::move(matchers)) {} virtual void DescribeTo(::std::ostream* os) const { *os << "("; - matcher1_.DescribeTo(os); - *os << ") and ("; - matcher2_.DescribeTo(os); + for (size_t i = 0; i < matchers_.size(); ++i) { + if (i != 0) *os << ") and ("; + matchers_[i].DescribeTo(os); + } *os << ")"; } virtual void DescribeNegationTo(::std::ostream* os) const { *os << "("; - matcher1_.DescribeNegationTo(os); - *os << ") or ("; - matcher2_.DescribeNegationTo(os); + for (size_t i = 0; i < matchers_.size(); ++i) { + if (i != 0) *os << ") or ("; + matchers_[i].DescribeNegationTo(os); + } *os << ")"; } - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, + MatchResultListener* listener) const { // If either matcher1_ or matcher2_ doesn't match x, we only need // to explain why one of them fails. - StringMatchResultListener listener1; - if (!matcher1_.MatchAndExplain(x, &listener1)) { - *listener << listener1.str(); - return false; - } + std::string all_match_result; - StringMatchResultListener listener2; - if (!matcher2_.MatchAndExplain(x, &listener2)) { - *listener << listener2.str(); - return false; + for (size_t i = 0; i < matchers_.size(); ++i) { + StringMatchResultListener slistener; + if (matchers_[i].MatchAndExplain(x, &slistener)) { + if (all_match_result.empty()) { + all_match_result = slistener.str(); + } else { + std::string result = slistener.str(); + if (!result.empty()) { + all_match_result += ", and "; + all_match_result += result; + } + } + } else { + *listener << slistener.str(); + return false; + } } // Otherwise we need to explain why *both* of them match. - const internal::string s1 = listener1.str(); - const internal::string s2 = listener2.str(); - - if (s1 == "") { - *listener << s2; - } else { - *listener << s1; - if (s2 != "") { - *listener << ", and " << s2; - } - } + *listener << all_match_result; return true; } private: - const Matcher<T> matcher1_; - const Matcher<T> matcher2_; + const std::vector<Matcher<T> > matchers_; - GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl); + GTEST_DISALLOW_ASSIGN_(AllOfMatcherImpl); }; #if GTEST_LANG_CXX11 -// MatcherList provides mechanisms for storing a variable number of matchers in -// a list structure (ListType) and creating a combining matcher from such a -// list. -// The template is defined recursively using the following template paramters: -// * kSize is the length of the MatcherList. -// * Head is the type of the first matcher of the list. -// * Tail denotes the types of the remaining matchers of the list. -template <int kSize, typename Head, typename... Tail> -struct MatcherList { - typedef MatcherList<kSize - 1, Tail...> MatcherListTail; - typedef ::std::pair<Head, typename MatcherListTail::ListType> ListType; - - // BuildList stores variadic type values in a nested pair structure. - // Example: - // MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return - // the corresponding result of type pair<int, pair<string, float>>. - static ListType BuildList(const Head& matcher, const Tail&... tail) { - return ListType(matcher, MatcherListTail::BuildList(tail...)); - } - - // CreateMatcher<T> creates a Matcher<T> from a given list of matchers (built - // by BuildList()). CombiningMatcher<T> is used to combine the matchers of the - // list. CombiningMatcher<T> must implement MatcherInterface<T> and have a - // constructor taking two Matcher<T>s as input. - template <typename T, template <typename /* T */> class CombiningMatcher> - static Matcher<T> CreateMatcher(const ListType& matchers) { - return Matcher<T>(new CombiningMatcher<T>( - SafeMatcherCast<T>(matchers.first), - MatcherListTail::template CreateMatcher<T, CombiningMatcher>( - matchers.second))); - } -}; - -// The following defines the base case for the recursive definition of -// MatcherList. -template <typename Matcher1, typename Matcher2> -struct MatcherList<2, Matcher1, Matcher2> { - typedef ::std::pair<Matcher1, Matcher2> ListType; - - static ListType BuildList(const Matcher1& matcher1, - const Matcher2& matcher2) { - return ::std::pair<Matcher1, Matcher2>(matcher1, matcher2); - } - - template <typename T, template <typename /* T */> class CombiningMatcher> - static Matcher<T> CreateMatcher(const ListType& matchers) { - return Matcher<T>(new CombiningMatcher<T>( - SafeMatcherCast<T>(matchers.first), - SafeMatcherCast<T>(matchers.second))); - } -}; - // VariadicMatcher is used for the variadic implementation of // AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...). // CombiningMatcher<T> is used to recursively combine the provided matchers @@ -1608,27 +1788,40 @@ template <template <typename T> class CombiningMatcher, typename... Args> class VariadicMatcher { public: VariadicMatcher(const Args&... matchers) // NOLINT - : matchers_(MatcherListType::BuildList(matchers...)) {} + : matchers_(matchers...) { + static_assert(sizeof...(Args) > 0, "Must have at least one matcher."); + } // This template type conversion operator allows an // VariadicMatcher<Matcher1, Matcher2...> object to match any type that // all of the provided matchers (Matcher1, Matcher2, ...) can match. template <typename T> operator Matcher<T>() const { - return MatcherListType::template CreateMatcher<T, CombiningMatcher>( - matchers_); + std::vector<Matcher<T> > values; + CreateVariadicMatcher<T>(&values, std::integral_constant<size_t, 0>()); + return Matcher<T>(new CombiningMatcher<T>(internal::move(values))); } private: - typedef MatcherList<sizeof...(Args), Args...> MatcherListType; + template <typename T, size_t I> + void CreateVariadicMatcher(std::vector<Matcher<T> >* values, + std::integral_constant<size_t, I>) const { + values->push_back(SafeMatcherCast<T>(std::get<I>(matchers_))); + CreateVariadicMatcher<T>(values, std::integral_constant<size_t, I + 1>()); + } + + template <typename T> + void CreateVariadicMatcher( + std::vector<Matcher<T> >*, + std::integral_constant<size_t, sizeof...(Args)>) const {} - const typename MatcherListType::ListType matchers_; + tuple<Args...> matchers_; GTEST_DISALLOW_ASSIGN_(VariadicMatcher); }; template <typename... Args> -using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl, Args...>; +using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>; #endif // GTEST_LANG_CXX11 @@ -1645,8 +1838,10 @@ class BothOfMatcher { // both Matcher1 and Matcher2 can match. template <typename T> operator Matcher<T>() const { - return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_), - SafeMatcherCast<T>(matcher2_))); + std::vector<Matcher<T> > values; + values.push_back(SafeMatcherCast<T>(matcher1_)); + values.push_back(SafeMatcherCast<T>(matcher2_)); + return Matcher<T>(new AllOfMatcherImpl<T>(internal::move(values))); } private: @@ -1661,68 +1856,69 @@ class BothOfMatcher { // that will prevent different instantiations of AnyOfMatcher from // sharing the same EitherOfMatcherImpl<T> class. template <typename T> -class EitherOfMatcherImpl : public MatcherInterface<T> { +class AnyOfMatcherImpl + : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { public: - EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2) - : matcher1_(matcher1), matcher2_(matcher2) {} + explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers) + : matchers_(internal::move(matchers)) {} virtual void DescribeTo(::std::ostream* os) const { *os << "("; - matcher1_.DescribeTo(os); - *os << ") or ("; - matcher2_.DescribeTo(os); + for (size_t i = 0; i < matchers_.size(); ++i) { + if (i != 0) *os << ") or ("; + matchers_[i].DescribeTo(os); + } *os << ")"; } virtual void DescribeNegationTo(::std::ostream* os) const { *os << "("; - matcher1_.DescribeNegationTo(os); - *os << ") and ("; - matcher2_.DescribeNegationTo(os); + for (size_t i = 0; i < matchers_.size(); ++i) { + if (i != 0) *os << ") and ("; + matchers_[i].DescribeNegationTo(os); + } *os << ")"; } - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, + MatchResultListener* listener) const { + std::string no_match_result; + // If either matcher1_ or matcher2_ matches x, we just need to // explain why *one* of them matches. - StringMatchResultListener listener1; - if (matcher1_.MatchAndExplain(x, &listener1)) { - *listener << listener1.str(); - return true; - } - - StringMatchResultListener listener2; - if (matcher2_.MatchAndExplain(x, &listener2)) { - *listener << listener2.str(); - return true; + for (size_t i = 0; i < matchers_.size(); ++i) { + StringMatchResultListener slistener; + if (matchers_[i].MatchAndExplain(x, &slistener)) { + *listener << slistener.str(); + return true; + } else { + if (no_match_result.empty()) { + no_match_result = slistener.str(); + } else { + std::string result = slistener.str(); + if (!result.empty()) { + no_match_result += ", and "; + no_match_result += result; + } + } + } } // Otherwise we need to explain why *both* of them fail. - const internal::string s1 = listener1.str(); - const internal::string s2 = listener2.str(); - - if (s1 == "") { - *listener << s2; - } else { - *listener << s1; - if (s2 != "") { - *listener << ", and " << s2; - } - } + *listener << no_match_result; return false; } private: - const Matcher<T> matcher1_; - const Matcher<T> matcher2_; + const std::vector<Matcher<T> > matchers_; - GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl); + GTEST_DISALLOW_ASSIGN_(AnyOfMatcherImpl); }; #if GTEST_LANG_CXX11 // AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...). template <typename... Args> -using AnyOfMatcher = VariadicMatcher<EitherOfMatcherImpl, Args...>; +using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>; #endif // GTEST_LANG_CXX11 @@ -1740,8 +1936,10 @@ class EitherOfMatcher { // both Matcher1 and Matcher2 can match. template <typename T> operator Matcher<T>() const { - return Matcher<T>(new EitherOfMatcherImpl<T>( - SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_))); + std::vector<Matcher<T> > values; + values.push_back(SafeMatcherCast<T>(matcher1_)); + values.push_back(SafeMatcherCast<T>(matcher2_)); + return Matcher<T>(new AnyOfMatcherImpl<T>(internal::move(values))); } private: @@ -2037,6 +2235,82 @@ class FloatingEqMatcher { GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher); }; +// A 2-tuple ("binary") wrapper around FloatingEqMatcher: +// FloatingEq2Matcher() matches (x, y) by matching FloatingEqMatcher(x, false) +// against y, and FloatingEq2Matcher(e) matches FloatingEqMatcher(x, false, e) +// against y. The former implements "Eq", the latter "Near". At present, there +// is no version that compares NaNs as equal. +template <typename FloatType> +class FloatingEq2Matcher { + public: + FloatingEq2Matcher() { Init(-1, false); } + + explicit FloatingEq2Matcher(bool nan_eq_nan) { Init(-1, nan_eq_nan); } + + explicit FloatingEq2Matcher(FloatType max_abs_error) { + Init(max_abs_error, false); + } + + FloatingEq2Matcher(FloatType max_abs_error, bool nan_eq_nan) { + Init(max_abs_error, nan_eq_nan); + } + + template <typename T1, typename T2> + operator Matcher< ::testing::tuple<T1, T2> >() const { + return MakeMatcher( + new Impl< ::testing::tuple<T1, T2> >(max_abs_error_, nan_eq_nan_)); + } + template <typename T1, typename T2> + operator Matcher<const ::testing::tuple<T1, T2>&>() const { + return MakeMatcher( + new Impl<const ::testing::tuple<T1, T2>&>(max_abs_error_, nan_eq_nan_)); + } + + private: + static ::std::ostream& GetDesc(::std::ostream& os) { // NOLINT + return os << "an almost-equal pair"; + } + + template <typename Tuple> + class Impl : public MatcherInterface<Tuple> { + public: + Impl(FloatType max_abs_error, bool nan_eq_nan) : + max_abs_error_(max_abs_error), + nan_eq_nan_(nan_eq_nan) {} + + virtual bool MatchAndExplain(Tuple args, + MatchResultListener* listener) const { + if (max_abs_error_ == -1) { + FloatingEqMatcher<FloatType> fm(::testing::get<0>(args), nan_eq_nan_); + return static_cast<Matcher<FloatType> >(fm).MatchAndExplain( + ::testing::get<1>(args), listener); + } else { + FloatingEqMatcher<FloatType> fm(::testing::get<0>(args), nan_eq_nan_, + max_abs_error_); + return static_cast<Matcher<FloatType> >(fm).MatchAndExplain( + ::testing::get<1>(args), listener); + } + } + virtual void DescribeTo(::std::ostream* os) const { + *os << "are " << GetDesc; + } + virtual void DescribeNegationTo(::std::ostream* os) const { + *os << "aren't " << GetDesc; + } + + private: + FloatType max_abs_error_; + const bool nan_eq_nan_; + }; + + void Init(FloatType max_abs_error_val, bool nan_eq_nan_val) { + max_abs_error_ = max_abs_error_val; + nan_eq_nan_ = nan_eq_nan_val; + } + FloatType max_abs_error_; + bool nan_eq_nan_; +}; + // Implements the Pointee(m) matcher for matching a pointer whose // pointee matches matcher m. The pointer can be either raw or smart. template <typename InnerMatcher> @@ -2054,7 +2328,8 @@ class PointeeMatcher { // enough for implementing the DescribeTo() method of Pointee(). template <typename Pointer> operator Matcher<Pointer>() const { - return MakeMatcher(new Impl<Pointer>(matcher_)); + return Matcher<Pointer>( + new Impl<GTEST_REFERENCE_TO_CONST_(Pointer)>(matcher_)); } private: @@ -2098,6 +2373,7 @@ class PointeeMatcher { GTEST_DISALLOW_ASSIGN_(PointeeMatcher); }; +#if GTEST_HAS_RTTI // Implements the WhenDynamicCastTo<T>(m) matcher that matches a pointer or // reference that matches inner_matcher when dynamic_cast<T> is applied. // The result of dynamic_cast<To> is forwarded to the inner matcher. @@ -2123,12 +2399,8 @@ class WhenDynamicCastToMatcherBase { protected: const Matcher<To> matcher_; - static string GetToName() { -#if GTEST_HAS_RTTI + static std::string GetToName() { return GetTypeName<To>(); -#else // GTEST_HAS_RTTI - return "the target type"; -#endif // GTEST_HAS_RTTI } private: @@ -2174,6 +2446,7 @@ class WhenDynamicCastToMatcher<To&> : public WhenDynamicCastToMatcherBase<To&> { return MatchPrintAndExplain(*to, this->matcher_, listener); } }; +#endif // GTEST_HAS_RTTI // Implements the Field() matcher for matching a field (i.e. member // variable) of an object. @@ -2182,15 +2455,21 @@ class FieldMatcher { public: FieldMatcher(FieldType Class::*field, const Matcher<const FieldType&>& matcher) - : field_(field), matcher_(matcher) {} + : field_(field), matcher_(matcher), whose_field_("whose given field ") {} + + FieldMatcher(const std::string& field_name, FieldType Class::*field, + const Matcher<const FieldType&>& matcher) + : field_(field), + matcher_(matcher), + whose_field_("whose field `" + field_name + "` ") {} void DescribeTo(::std::ostream* os) const { - *os << "is an object whose given field "; + *os << "is an object " << whose_field_; matcher_.DescribeTo(os); } void DescribeNegationTo(::std::ostream* os) const { - *os << "is an object whose given field "; + *os << "is an object " << whose_field_; matcher_.DescribeNegationTo(os); } @@ -2208,7 +2487,7 @@ class FieldMatcher { // true_type iff the Field() matcher is used to match a pointer. bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, MatchResultListener* listener) const { - *listener << "whose given field is "; + *listener << whose_field_ << "is "; return MatchPrintAndExplain(obj.*field_, matcher_, listener); } @@ -2227,12 +2506,19 @@ class FieldMatcher { const FieldType Class::*field_; const Matcher<const FieldType&> matcher_; + // Contains either "whose given field " if the name of the field is unknown + // or "whose field `name_of_field` " if the name is known. + const std::string whose_field_; + GTEST_DISALLOW_ASSIGN_(FieldMatcher); }; // Implements the Property() matcher for matching a property // (i.e. return value of a getter method) of an object. -template <typename Class, typename PropertyType> +// +// Property is a const-qualified member function of Class returning +// PropertyType. +template <typename Class, typename PropertyType, typename Property> class PropertyMatcher { public: // The property may have a reference type, so 'const PropertyType&' @@ -2241,17 +2527,24 @@ class PropertyMatcher { // PropertyType being a reference or not. typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty; - PropertyMatcher(PropertyType (Class::*property)() const, + PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher) + : property_(property), + matcher_(matcher), + whose_property_("whose given property ") {} + + PropertyMatcher(const std::string& property_name, Property property, const Matcher<RefToConstProperty>& matcher) - : property_(property), matcher_(matcher) {} + : property_(property), + matcher_(matcher), + whose_property_("whose property `" + property_name + "` ") {} void DescribeTo(::std::ostream* os) const { - *os << "is an object whose given property "; + *os << "is an object " << whose_property_; matcher_.DescribeTo(os); } void DescribeNegationTo(::std::ostream* os) const { - *os << "is an object whose given property "; + *os << "is an object " << whose_property_; matcher_.DescribeNegationTo(os); } @@ -2269,7 +2562,7 @@ class PropertyMatcher { // true_type iff the Property() matcher is used to match a pointer. bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, MatchResultListener* listener) const { - *listener << "whose given property is "; + *listener << whose_property_ << "is "; // Cannot pass the return value (for example, int) to MatchPrintAndExplain, // which takes a non-const reference as argument. #if defined(_PREFAST_ ) && _MSC_VER == 1800 @@ -2295,9 +2588,13 @@ class PropertyMatcher { return MatchAndExplainImpl(false_type(), *p, listener); } - PropertyType (Class::*property_)() const; + Property property_; const Matcher<RefToConstProperty> matcher_; + // Contains either "whose given property " if the name of the property is + // unknown or "whose property `name_of_property` " if the name is known. + const std::string whose_property_; + GTEST_DISALLOW_ASSIGN_(PropertyMatcher); }; @@ -2378,7 +2675,7 @@ class ResultOfMatcher { private: // Functors often define operator() as non-const method even though - // they are actualy stateless. But we need to use them even when + // they are actually stateless. But we need to use them even when // 'this' is a const pointer. It's the user's responsibility not to // use stateful callables with ResultOf(), which does't guarantee // how many times the callable will be invoked. @@ -2691,6 +2988,10 @@ class WhenSortedByMatcher { // container and the RHS container respectively. template <typename TupleMatcher, typename RhsContainer> class PointwiseMatcher { + GTEST_COMPILE_ASSERT_( + !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>::value, + use_UnorderedPointwise_with_hash_tables); + public: typedef internal::StlContainerView<RhsContainer> RhsView; typedef typename RhsView::type RhsStlContainer; @@ -2708,6 +3009,10 @@ class PointwiseMatcher { template <typename LhsContainer> operator Matcher<LhsContainer>() const { + GTEST_COMPILE_ASSERT_( + !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)>::value, + use_UnorderedPointwise_with_hash_tables); + return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_)); } @@ -2758,12 +3063,15 @@ class PointwiseMatcher { typename LhsStlContainer::const_iterator left = lhs_stl_container.begin(); typename RhsStlContainer::const_iterator right = rhs_.begin(); for (size_t i = 0; i != actual_size; ++i, ++left, ++right) { - const InnerMatcherArg value_pair(*left, *right); - if (listener->IsInterested()) { StringMatchResultListener inner_listener; + // Create InnerMatcherArg as a temporarily object to avoid it outlives + // *left and *right. Dereference or the conversion to `const T&` may + // return temp objects, e.g for vector<bool>. if (!mono_tuple_matcher_.MatchAndExplain( - value_pair, &inner_listener)) { + InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left), + ImplicitCast_<const RhsValue&>(*right)), + &inner_listener)) { *listener << "where the value pair ("; UniversalPrint(*left, listener->stream()); *listener << ", "; @@ -2773,7 +3081,9 @@ class PointwiseMatcher { return false; } } else { - if (!mono_tuple_matcher_.Matches(value_pair)) + if (!mono_tuple_matcher_.Matches( + InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left), + ImplicitCast_<const RhsValue&>(*right)))) return false; } } @@ -2931,6 +3241,50 @@ class EachMatcher { GTEST_DISALLOW_ASSIGN_(EachMatcher); }; +struct Rank1 {}; +struct Rank0 : Rank1 {}; + +namespace pair_getters { +#if GTEST_LANG_CXX11 +using std::get; +template <typename T> +auto First(T& x, Rank1) -> decltype(get<0>(x)) { // NOLINT + return get<0>(x); +} +template <typename T> +auto First(T& x, Rank0) -> decltype((x.first)) { // NOLINT + return x.first; +} + +template <typename T> +auto Second(T& x, Rank1) -> decltype(get<1>(x)) { // NOLINT + return get<1>(x); +} +template <typename T> +auto Second(T& x, Rank0) -> decltype((x.second)) { // NOLINT + return x.second; +} +#else +template <typename T> +typename T::first_type& First(T& x, Rank0) { // NOLINT + return x.first; +} +template <typename T> +const typename T::first_type& First(const T& x, Rank0) { + return x.first; +} + +template <typename T> +typename T::second_type& Second(T& x, Rank0) { // NOLINT + return x.second; +} +template <typename T> +const typename T::second_type& Second(const T& x, Rank0) { + return x.second; +} +#endif // GTEST_LANG_CXX11 +} // namespace pair_getters + // Implements Key(inner_matcher) for the given argument pair type. // Key(inner_matcher) matches an std::pair whose 'first' field matches // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an @@ -2951,9 +3305,9 @@ class KeyMatcherImpl : public MatcherInterface<PairType> { virtual bool MatchAndExplain(PairType key_value, MatchResultListener* listener) const { StringMatchResultListener inner_listener; - const bool match = inner_matcher_.MatchAndExplain(key_value.first, - &inner_listener); - const internal::string explanation = inner_listener.str(); + const bool match = inner_matcher_.MatchAndExplain( + pair_getters::First(key_value, Rank0()), &inner_listener); + const std::string explanation = inner_listener.str(); if (explanation != "") { *listener << "whose first field is a value " << explanation; } @@ -3035,18 +3389,18 @@ class PairMatcherImpl : public MatcherInterface<PairType> { if (!listener->IsInterested()) { // If the listener is not interested, we don't need to construct the // explanation. - return first_matcher_.Matches(a_pair.first) && - second_matcher_.Matches(a_pair.second); + return first_matcher_.Matches(pair_getters::First(a_pair, Rank0())) && + second_matcher_.Matches(pair_getters::Second(a_pair, Rank0())); } StringMatchResultListener first_inner_listener; - if (!first_matcher_.MatchAndExplain(a_pair.first, + if (!first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank0()), &first_inner_listener)) { *listener << "whose first field does not match"; PrintIfNotEmpty(first_inner_listener.str(), listener->stream()); return false; } StringMatchResultListener second_inner_listener; - if (!second_matcher_.MatchAndExplain(a_pair.second, + if (!second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank0()), &second_inner_listener)) { *listener << "whose second field does not match"; PrintIfNotEmpty(second_inner_listener.str(), listener->stream()); @@ -3058,8 +3412,8 @@ class PairMatcherImpl : public MatcherInterface<PairType> { } private: - void ExplainSuccess(const internal::string& first_explanation, - const internal::string& second_explanation, + void ExplainSuccess(const std::string& first_explanation, + const std::string& second_explanation, MatchResultListener* listener) const { *listener << "whose both fields match"; if (first_explanation != "") { @@ -3166,7 +3520,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> { const bool listener_interested = listener->IsInterested(); // explanations[i] is the explanation of the element at index i. - ::std::vector<internal::string> explanations(count()); + ::std::vector<std::string> explanations(count()); StlContainerReference stl_container = View::ConstReference(container); typename StlContainer::const_iterator it = stl_container.begin(); size_t exam_pos = 0; @@ -3225,7 +3579,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> { if (listener_interested) { bool reason_printed = false; for (size_t i = 0; i != count(); ++i) { - const internal::string& s = explanations[i]; + const std::string& s = explanations[i]; if (!s.empty()) { if (reason_printed) { *listener << ",\nand "; @@ -3278,7 +3632,7 @@ class GTEST_API_ MatchMatrix { void Randomize(); - string DebugString() const; + std::string DebugString() const; private: size_t SpaceIndex(size_t ilhs, size_t irhs) const { @@ -3302,14 +3656,23 @@ typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs; GTEST_API_ ElementMatcherPairs FindMaxBipartiteMatching(const MatchMatrix& g); -GTEST_API_ bool FindPairing(const MatchMatrix& matrix, - MatchResultListener* listener); +struct UnorderedMatcherRequire { + enum Flags { + Superset = 1 << 0, + Subset = 1 << 1, + ExactMatch = Superset | Subset, + }; +}; // Untyped base class for implementing UnorderedElementsAre. By // putting logic that's not specific to the element type here, we // reduce binary bloat and increase compilation speed. class GTEST_API_ UnorderedElementsAreMatcherImplBase { protected: + explicit UnorderedElementsAreMatcherImplBase( + UnorderedMatcherRequire::Flags matcher_flags) + : match_flags_(matcher_flags) {} + // A vector of matcher describers, one for each element matcher. // Does not own the describers (and thus can be used only when the // element matchers are alive). @@ -3321,10 +3684,12 @@ class GTEST_API_ UnorderedElementsAreMatcherImplBase { // Describes the negation of this UnorderedElementsAre matcher. void DescribeNegationToImpl(::std::ostream* os) const; - bool VerifyAllElementsAndMatchersAreMatched( - const ::std::vector<string>& element_printouts, - const MatchMatrix& matrix, - MatchResultListener* listener) const; + bool VerifyMatchMatrix(const ::std::vector<std::string>& element_printouts, + const MatchMatrix& matrix, + MatchResultListener* listener) const; + + bool FindPairing(const MatchMatrix& matrix, + MatchResultListener* listener) const; MatcherDescriberVec& matcher_describers() { return matcher_describers_; @@ -3334,13 +3699,17 @@ class GTEST_API_ UnorderedElementsAreMatcherImplBase { return Message() << n << " element" << (n == 1 ? "" : "s"); } + UnorderedMatcherRequire::Flags match_flags() const { return match_flags_; } + private: + UnorderedMatcherRequire::Flags match_flags_; MatcherDescriberVec matcher_describers_; GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase); }; -// Implements unordered ElementsAre and unordered ElementsAreArray. +// Implements UnorderedElementsAre, UnorderedElementsAreArray, IsSubsetOf, and +// IsSupersetOf. template <typename Container> class UnorderedElementsAreMatcherImpl : public MatcherInterface<Container>, @@ -3353,10 +3722,10 @@ class UnorderedElementsAreMatcherImpl typedef typename StlContainer::const_iterator StlContainerConstIterator; typedef typename StlContainer::value_type Element; - // Constructs the matcher from a sequence of element values or - // element matchers. template <typename InputIter> - UnorderedElementsAreMatcherImpl(InputIter first, InputIter last) { + UnorderedElementsAreMatcherImpl(UnorderedMatcherRequire::Flags matcher_flags, + InputIter first, InputIter last) + : UnorderedElementsAreMatcherImplBase(matcher_flags) { for (; first != last; ++first) { matchers_.push_back(MatcherCast<const Element&>(*first)); matcher_describers().push_back(matchers_.back().GetDescriber()); @@ -3376,38 +3745,36 @@ class UnorderedElementsAreMatcherImpl virtual bool MatchAndExplain(Container container, MatchResultListener* listener) const { StlContainerReference stl_container = View::ConstReference(container); - ::std::vector<string> element_printouts; - MatchMatrix matrix = AnalyzeElements(stl_container.begin(), - stl_container.end(), - &element_printouts, - listener); - - const size_t actual_count = matrix.LhsSize(); - if (actual_count == 0 && matchers_.empty()) { + ::std::vector<std::string> element_printouts; + MatchMatrix matrix = + AnalyzeElements(stl_container.begin(), stl_container.end(), + &element_printouts, listener); + + if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) { return true; } - if (actual_count != matchers_.size()) { - // The element count doesn't match. If the container is empty, - // there's no need to explain anything as Google Mock already - // prints the empty container. Otherwise we just need to show - // how many elements there actually are. - if (actual_count != 0 && listener->IsInterested()) { - *listener << "which has " << Elements(actual_count); + + if (match_flags() == UnorderedMatcherRequire::ExactMatch) { + if (matrix.LhsSize() != matrix.RhsSize()) { + // The element count doesn't match. If the container is empty, + // there's no need to explain anything as Google Mock already + // prints the empty container. Otherwise we just need to show + // how many elements there actually are. + if (matrix.LhsSize() != 0 && listener->IsInterested()) { + *listener << "which has " << Elements(matrix.LhsSize()); + } + return false; } - return false; } - return VerifyAllElementsAndMatchersAreMatched(element_printouts, - matrix, listener) && + return VerifyMatchMatrix(element_printouts, matrix, listener) && FindPairing(matrix, listener); } private: - typedef ::std::vector<Matcher<const Element&> > MatcherVec; - template <typename ElementIter> MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last, - ::std::vector<string>* element_printouts, + ::std::vector<std::string>* element_printouts, MatchResultListener* listener) const { element_printouts->clear(); ::std::vector<char> did_match; @@ -3431,7 +3798,7 @@ class UnorderedElementsAreMatcherImpl return matrix; } - MatcherVec matchers_; + ::std::vector<Matcher<const Element&> > matchers_; GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl); }; @@ -3464,7 +3831,7 @@ class UnorderedElementsAreMatcher { TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_, ::std::back_inserter(matchers)); return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>( - matchers.begin(), matchers.end())); + UnorderedMatcherRequire::ExactMatch, matchers.begin(), matchers.end())); } private: @@ -3480,6 +3847,11 @@ class ElementsAreMatcher { template <typename Container> operator Matcher<Container>() const { + GTEST_COMPILE_ASSERT_( + !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value || + ::testing::tuple_size<MatcherTuple>::value < 2, + use_UnorderedElementsAre_with_hash_tables); + typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; typedef typename internal::StlContainerView<RawContainer>::type View; typedef typename View::value_type Element; @@ -3497,24 +3869,23 @@ class ElementsAreMatcher { GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher); }; -// Implements UnorderedElementsAreArray(). +// Implements UnorderedElementsAreArray(), IsSubsetOf(), and IsSupersetOf(). template <typename T> class UnorderedElementsAreArrayMatcher { public: - UnorderedElementsAreArrayMatcher() {} - template <typename Iter> - UnorderedElementsAreArrayMatcher(Iter first, Iter last) - : matchers_(first, last) {} + UnorderedElementsAreArrayMatcher(UnorderedMatcherRequire::Flags match_flags, + Iter first, Iter last) + : match_flags_(match_flags), matchers_(first, last) {} template <typename Container> operator Matcher<Container>() const { - return MakeMatcher( - new UnorderedElementsAreMatcherImpl<Container>(matchers_.begin(), - matchers_.end())); + return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>( + match_flags_, matchers_.begin(), matchers_.end())); } private: + UnorderedMatcherRequire::Flags match_flags_; ::std::vector<T> matchers_; GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher); @@ -3529,6 +3900,10 @@ class ElementsAreArrayMatcher { template <typename Container> operator Matcher<Container>() const { + GTEST_COMPILE_ASSERT_( + !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value, + use_UnorderedElementsAreArray_with_hash_tables); + return MakeMatcher(new ElementsAreMatcherImpl<Container>( matchers_.begin(), matchers_.end())); } @@ -3619,13 +3994,189 @@ BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond( // 'negation' is false; otherwise returns the description of the // negation of the matcher. 'param_values' contains a list of strings // that are the print-out of the matcher's parameters. -GTEST_API_ string FormatMatcherDescription(bool negation, - const char* matcher_name, - const Strings& param_values); +GTEST_API_ std::string FormatMatcherDescription(bool negation, + const char* matcher_name, + const Strings& param_values); + +// Implements a matcher that checks the value of a optional<> type variable. +template <typename ValueMatcher> +class OptionalMatcher { + public: + explicit OptionalMatcher(const ValueMatcher& value_matcher) + : value_matcher_(value_matcher) {} + + template <typename Optional> + operator Matcher<Optional>() const { + return MakeMatcher(new Impl<Optional>(value_matcher_)); + } + + template <typename Optional> + class Impl : public MatcherInterface<Optional> { + public: + typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Optional) OptionalView; + typedef typename OptionalView::value_type ValueType; + explicit Impl(const ValueMatcher& value_matcher) + : value_matcher_(MatcherCast<ValueType>(value_matcher)) {} + + virtual void DescribeTo(::std::ostream* os) const { + *os << "value "; + value_matcher_.DescribeTo(os); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + *os << "value "; + value_matcher_.DescribeNegationTo(os); + } + + virtual bool MatchAndExplain(Optional optional, + MatchResultListener* listener) const { + if (!optional) { + *listener << "which is not engaged"; + return false; + } + const ValueType& value = *optional; + StringMatchResultListener value_listener; + const bool match = value_matcher_.MatchAndExplain(value, &value_listener); + *listener << "whose value " << PrintToString(value) + << (match ? " matches" : " doesn't match"); + PrintIfNotEmpty(value_listener.str(), listener->stream()); + return match; + } + + private: + const Matcher<ValueType> value_matcher_; + GTEST_DISALLOW_ASSIGN_(Impl); + }; + + private: + const ValueMatcher value_matcher_; + GTEST_DISALLOW_ASSIGN_(OptionalMatcher); +}; + +namespace variant_matcher { +// Overloads to allow VariantMatcher to do proper ADL lookup. +template <typename T> +void holds_alternative() {} +template <typename T> +void get() {} + +// Implements a matcher that checks the value of a variant<> type variable. +template <typename T> +class VariantMatcher { + public: + explicit VariantMatcher(::testing::Matcher<const T&> matcher) + : matcher_(internal::move(matcher)) {} + + template <typename Variant> + bool MatchAndExplain(const Variant& value, + ::testing::MatchResultListener* listener) const { + if (!listener->IsInterested()) { + return holds_alternative<T>(value) && matcher_.Matches(get<T>(value)); + } + + if (!holds_alternative<T>(value)) { + *listener << "whose value is not of type '" << GetTypeName() << "'"; + return false; + } + const T& elem = get<T>(value); + StringMatchResultListener elem_listener; + const bool match = matcher_.MatchAndExplain(elem, &elem_listener); + *listener << "whose value " << PrintToString(elem) + << (match ? " matches" : " doesn't match"); + PrintIfNotEmpty(elem_listener.str(), listener->stream()); + return match; + } + + void DescribeTo(std::ostream* os) const { + *os << "is a variant<> with value of type '" << GetTypeName() + << "' and the value "; + matcher_.DescribeTo(os); + } + + void DescribeNegationTo(std::ostream* os) const { + *os << "is a variant<> with value of type other than '" << GetTypeName() + << "' or the value "; + matcher_.DescribeNegationTo(os); + } + + private: + static std::string GetTypeName() { +#if GTEST_HAS_RTTI + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_( + return internal::GetTypeName<T>()); +#endif + return "the element type"; + } + + const ::testing::Matcher<const T&> matcher_; +}; + +} // namespace variant_matcher + +namespace any_cast_matcher { + +// Overloads to allow AnyCastMatcher to do proper ADL lookup. +template <typename T> +void any_cast() {} + +// Implements a matcher that any_casts the value. +template <typename T> +class AnyCastMatcher { + public: + explicit AnyCastMatcher(const ::testing::Matcher<const T&>& matcher) + : matcher_(matcher) {} + + template <typename AnyType> + bool MatchAndExplain(const AnyType& value, + ::testing::MatchResultListener* listener) const { + if (!listener->IsInterested()) { + const T* ptr = any_cast<T>(&value); + return ptr != NULL && matcher_.Matches(*ptr); + } + + const T* elem = any_cast<T>(&value); + if (elem == NULL) { + *listener << "whose value is not of type '" << GetTypeName() << "'"; + return false; + } + + StringMatchResultListener elem_listener; + const bool match = matcher_.MatchAndExplain(*elem, &elem_listener); + *listener << "whose value " << PrintToString(*elem) + << (match ? " matches" : " doesn't match"); + PrintIfNotEmpty(elem_listener.str(), listener->stream()); + return match; + } + + void DescribeTo(std::ostream* os) const { + *os << "is an 'any' type with value of type '" << GetTypeName() + << "' and the value "; + matcher_.DescribeTo(os); + } + + void DescribeNegationTo(std::ostream* os) const { + *os << "is an 'any' type with value of type other than '" << GetTypeName() + << "' or the value "; + matcher_.DescribeNegationTo(os); + } + + private: + static std::string GetTypeName() { +#if GTEST_HAS_RTTI + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_( + return internal::GetTypeName<T>()); +#endif + return "the element type"; + } + + const ::testing::Matcher<const T&> matcher_; +}; + +} // namespace any_cast_matcher } // namespace internal -// ElementsAreArray(first, last) +// ElementsAreArray(iterator_first, iterator_last) // ElementsAreArray(pointer, count) // ElementsAreArray(array) // ElementsAreArray(container) @@ -3674,20 +4225,26 @@ ElementsAreArray(::std::initializer_list<T> xs) { } #endif -// UnorderedElementsAreArray(first, last) +// UnorderedElementsAreArray(iterator_first, iterator_last) // UnorderedElementsAreArray(pointer, count) // UnorderedElementsAreArray(array) // UnorderedElementsAreArray(container) // UnorderedElementsAreArray({ e1, e2, ..., en }) // -// The UnorderedElementsAreArray() functions are like -// ElementsAreArray(...), but allow matching the elements in any order. +// UnorderedElementsAreArray() verifies that a bijective mapping onto a +// collection of matchers exists. +// +// The matchers can be specified as an array, a pointer and count, a container, +// an initializer list, or an STL iterator range. In each of these cases, the +// underlying matchers can be either values or matchers. + template <typename Iter> inline internal::UnorderedElementsAreArrayMatcher< typename ::std::iterator_traits<Iter>::value_type> UnorderedElementsAreArray(Iter first, Iter last) { typedef typename ::std::iterator_traits<Iter>::value_type T; - return internal::UnorderedElementsAreArrayMatcher<T>(first, last); + return internal::UnorderedElementsAreArrayMatcher<T>( + internal::UnorderedMatcherRequire::ExactMatch, first, last); } template <typename T> @@ -3729,7 +4286,9 @@ UnorderedElementsAreArray(::std::initializer_list<T> xs) { const internal::AnythingMatcher _ = {}; // Creates a matcher that matches any value of the given type T. template <typename T> -inline Matcher<T> A() { return MakeMatcher(new internal::AnyMatcherImpl<T>()); } +inline Matcher<T> A() { + return Matcher<T>(new internal::AnyMatcherImpl<T>()); +} // Creates a matcher that matches any value of the given type T. template <typename T> @@ -3746,6 +4305,14 @@ inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); } template <typename T> Matcher<T>::Matcher(T value) { *this = Eq(value); } +template <typename T, typename M> +Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl( + const M& value, + internal::BooleanConstant<false> /* convertible_to_matcher */, + internal::BooleanConstant<false> /* convertible_to_T */) { + return Eq(value); +} + // Creates a monomorphic matcher that matches anything with type Lhs // and equal to rhs. A user may need to use this instead of Eq(...) // in order to resolve an overloading ambiguity. @@ -3874,6 +4441,7 @@ inline internal::PointeeMatcher<InnerMatcher> Pointee( return internal::PointeeMatcher<InnerMatcher>(inner_matcher); } +#if GTEST_HAS_RTTI // Creates a matcher that matches a pointer or reference that matches // inner_matcher when dynamic_cast<To> is applied. // The result of dynamic_cast<To> is forwarded to the inner matcher. @@ -3886,6 +4454,7 @@ WhenDynamicCastTo(const Matcher<To>& inner_matcher) { return MakePolymorphicMatcher( internal::WhenDynamicCastToMatcher<To>(inner_matcher)); } +#endif // GTEST_HAS_RTTI // Creates a matcher that matches an object whose given field matches // 'matcher'. For example, @@ -3904,16 +4473,28 @@ inline PolymorphicMatcher< // to compile where bar is an int32 and m is a matcher for int64. } +// Same as Field() but also takes the name of the field to provide better error +// messages. +template <typename Class, typename FieldType, typename FieldMatcher> +inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType> > Field( + const std::string& field_name, FieldType Class::*field, + const FieldMatcher& matcher) { + return MakePolymorphicMatcher(internal::FieldMatcher<Class, FieldType>( + field_name, field, MatcherCast<const FieldType&>(matcher))); +} + // Creates a matcher that matches an object whose given property // matches 'matcher'. For example, // Property(&Foo::str, StartsWith("hi")) // matches a Foo object x iff x.str() starts with "hi". template <typename Class, typename PropertyType, typename PropertyMatcher> -inline PolymorphicMatcher< - internal::PropertyMatcher<Class, PropertyType> > Property( - PropertyType (Class::*property)() const, const PropertyMatcher& matcher) { +inline PolymorphicMatcher<internal::PropertyMatcher< + Class, PropertyType, PropertyType (Class::*)() const> > +Property(PropertyType (Class::*property)() const, + const PropertyMatcher& matcher) { return MakePolymorphicMatcher( - internal::PropertyMatcher<Class, PropertyType>( + internal::PropertyMatcher<Class, PropertyType, + PropertyType (Class::*)() const>( property, MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); // The call to MatcherCast() is required for supporting inner @@ -3922,6 +4503,50 @@ inline PolymorphicMatcher< // to compile where bar() returns an int32 and m is a matcher for int64. } +// Same as Property() above, but also takes the name of the property to provide +// better error messages. +template <typename Class, typename PropertyType, typename PropertyMatcher> +inline PolymorphicMatcher<internal::PropertyMatcher< + Class, PropertyType, PropertyType (Class::*)() const> > +Property(const std::string& property_name, + PropertyType (Class::*property)() const, + const PropertyMatcher& matcher) { + return MakePolymorphicMatcher( + internal::PropertyMatcher<Class, PropertyType, + PropertyType (Class::*)() const>( + property_name, property, + MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); +} + +#if GTEST_LANG_CXX11 +// The same as above but for reference-qualified member functions. +template <typename Class, typename PropertyType, typename PropertyMatcher> +inline PolymorphicMatcher<internal::PropertyMatcher< + Class, PropertyType, PropertyType (Class::*)() const &> > +Property(PropertyType (Class::*property)() const &, + const PropertyMatcher& matcher) { + return MakePolymorphicMatcher( + internal::PropertyMatcher<Class, PropertyType, + PropertyType (Class::*)() const &>( + property, + MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); +} + +// Three-argument form for reference-qualified member functions. +template <typename Class, typename PropertyType, typename PropertyMatcher> +inline PolymorphicMatcher<internal::PropertyMatcher< + Class, PropertyType, PropertyType (Class::*)() const &> > +Property(const std::string& property_name, + PropertyType (Class::*property)() const &, + const PropertyMatcher& matcher) { + return MakePolymorphicMatcher( + internal::PropertyMatcher<Class, PropertyType, + PropertyType (Class::*)() const &>( + property_name, property, + MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); +} +#endif + // Creates a matcher that matches an object iff the result of applying // a callable to x matches 'matcher'. // For example, @@ -3935,6 +4560,7 @@ inline PolymorphicMatcher< // concurrent access. // * If it is a function object, it has to define type result_type. // We recommend deriving your functor classes from std::unary_function. +// template <typename Callable, typename ResultOfMatcher> internal::ResultOfMatcher<Callable> ResultOf( Callable callable, const ResultOfMatcher& matcher) { @@ -3951,53 +4577,52 @@ internal::ResultOfMatcher<Callable> ResultOf( // String matchers. // Matches a string equal to str. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > - StrEq(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( - str, true, true)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrEq( + const std::string& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::string>(str, true, true)); } // Matches a string not equal to str. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > - StrNe(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( - str, false, true)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrNe( + const std::string& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::string>(str, false, true)); } // Matches a string equal to str, ignoring case. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > - StrCaseEq(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( - str, true, false)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseEq( + const std::string& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::string>(str, true, false)); } // Matches a string not equal to str, ignoring case. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > - StrCaseNe(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( - str, false, false)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseNe( + const std::string& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::string>(str, false, false)); } // Creates a matcher that matches any string, std::string, or C string // that contains the given substring. -inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::string> > - HasSubstr(const internal::string& substring) { - return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::string>( - substring)); +inline PolymorphicMatcher<internal::HasSubstrMatcher<std::string> > HasSubstr( + const std::string& substring) { + return MakePolymorphicMatcher( + internal::HasSubstrMatcher<std::string>(substring)); } // Matches a string that starts with 'prefix' (case-sensitive). -inline PolymorphicMatcher<internal::StartsWithMatcher<internal::string> > - StartsWith(const internal::string& prefix) { - return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::string>( - prefix)); +inline PolymorphicMatcher<internal::StartsWithMatcher<std::string> > StartsWith( + const std::string& prefix) { + return MakePolymorphicMatcher( + internal::StartsWithMatcher<std::string>(prefix)); } // Matches a string that ends with 'suffix' (case-sensitive). -inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> > - EndsWith(const internal::string& suffix) { - return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string>( - suffix)); +inline PolymorphicMatcher<internal::EndsWithMatcher<std::string> > EndsWith( + const std::string& suffix) { + return MakePolymorphicMatcher(internal::EndsWithMatcher<std::string>(suffix)); } // Matches a string that fully matches regular expression 'regex'. @@ -4007,7 +4632,7 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true)); } inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( - const internal::string& regex) { + const std::string& regex) { return MatchesRegex(new internal::RE(regex)); } @@ -4018,7 +4643,7 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false)); } inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( - const internal::string& regex) { + const std::string& regex) { return ContainsRegex(new internal::RE(regex)); } @@ -4026,53 +4651,53 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( // Wide string matchers. // Matches a string equal to str. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > - StrEq(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( - str, true, true)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrEq( + const std::wstring& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::wstring>(str, true, true)); } // Matches a string not equal to str. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > - StrNe(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( - str, false, true)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrNe( + const std::wstring& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::wstring>(str, false, true)); } // Matches a string equal to str, ignoring case. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > - StrCaseEq(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( - str, true, false)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > +StrCaseEq(const std::wstring& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::wstring>(str, true, false)); } // Matches a string not equal to str, ignoring case. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > - StrCaseNe(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>( - str, false, false)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > +StrCaseNe(const std::wstring& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::wstring>(str, false, false)); } -// Creates a matcher that matches any wstring, std::wstring, or C wide string +// Creates a matcher that matches any ::wstring, std::wstring, or C wide string // that contains the given substring. -inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::wstring> > - HasSubstr(const internal::wstring& substring) { - return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::wstring>( - substring)); +inline PolymorphicMatcher<internal::HasSubstrMatcher<std::wstring> > HasSubstr( + const std::wstring& substring) { + return MakePolymorphicMatcher( + internal::HasSubstrMatcher<std::wstring>(substring)); } // Matches a string that starts with 'prefix' (case-sensitive). -inline PolymorphicMatcher<internal::StartsWithMatcher<internal::wstring> > - StartsWith(const internal::wstring& prefix) { - return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::wstring>( - prefix)); +inline PolymorphicMatcher<internal::StartsWithMatcher<std::wstring> > +StartsWith(const std::wstring& prefix) { + return MakePolymorphicMatcher( + internal::StartsWithMatcher<std::wstring>(prefix)); } // Matches a string that ends with 'suffix' (case-sensitive). -inline PolymorphicMatcher<internal::EndsWithMatcher<internal::wstring> > - EndsWith(const internal::wstring& suffix) { - return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::wstring>( - suffix)); +inline PolymorphicMatcher<internal::EndsWithMatcher<std::wstring> > EndsWith( + const std::wstring& suffix) { + return MakePolymorphicMatcher( + internal::EndsWithMatcher<std::wstring>(suffix)); } #endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING @@ -4101,6 +4726,58 @@ inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); } // first field != the second field. inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); } +// Creates a polymorphic matcher that matches a 2-tuple where +// FloatEq(first field) matches the second field. +inline internal::FloatingEq2Matcher<float> FloatEq() { + return internal::FloatingEq2Matcher<float>(); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// DoubleEq(first field) matches the second field. +inline internal::FloatingEq2Matcher<double> DoubleEq() { + return internal::FloatingEq2Matcher<double>(); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// FloatEq(first field) matches the second field with NaN equality. +inline internal::FloatingEq2Matcher<float> NanSensitiveFloatEq() { + return internal::FloatingEq2Matcher<float>(true); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// DoubleEq(first field) matches the second field with NaN equality. +inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleEq() { + return internal::FloatingEq2Matcher<double>(true); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// FloatNear(first field, max_abs_error) matches the second field. +inline internal::FloatingEq2Matcher<float> FloatNear(float max_abs_error) { + return internal::FloatingEq2Matcher<float>(max_abs_error); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// DoubleNear(first field, max_abs_error) matches the second field. +inline internal::FloatingEq2Matcher<double> DoubleNear(double max_abs_error) { + return internal::FloatingEq2Matcher<double>(max_abs_error); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// FloatNear(first field, max_abs_error) matches the second field with NaN +// equality. +inline internal::FloatingEq2Matcher<float> NanSensitiveFloatNear( + float max_abs_error) { + return internal::FloatingEq2Matcher<float>(max_abs_error, true); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// DoubleNear(first field, max_abs_error) matches the second field with NaN +// equality. +inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleNear( + double max_abs_error) { + return internal::FloatingEq2Matcher<double>(max_abs_error, true); +} + // Creates a matcher that matches any value of type T that m doesn't // match. template <typename InnerMatcher> @@ -4283,6 +4960,128 @@ inline internal::ContainsMatcher<M> Contains(M matcher) { return internal::ContainsMatcher<M>(matcher); } +// IsSupersetOf(iterator_first, iterator_last) +// IsSupersetOf(pointer, count) +// IsSupersetOf(array) +// IsSupersetOf(container) +// IsSupersetOf({e1, e2, ..., en}) +// +// IsSupersetOf() verifies that a surjective partial mapping onto a collection +// of matchers exists. In other words, a container matches +// IsSupersetOf({e1, ..., en}) if and only if there is a permutation +// {y1, ..., yn} of some of the container's elements where y1 matches e1, +// ..., and yn matches en. Obviously, the size of the container must be >= n +// in order to have a match. Examples: +// +// - {1, 2, 3} matches IsSupersetOf({Ge(3), Ne(0)}), as 3 matches Ge(3) and +// 1 matches Ne(0). +// - {1, 2} doesn't match IsSupersetOf({Eq(1), Lt(2)}), even though 1 matches +// both Eq(1) and Lt(2). The reason is that different matchers must be used +// for elements in different slots of the container. +// - {1, 1, 2} matches IsSupersetOf({Eq(1), Lt(2)}), as (the first) 1 matches +// Eq(1) and (the second) 1 matches Lt(2). +// - {1, 2, 3} matches IsSupersetOf(Gt(1), Gt(1)), as 2 matches (the first) +// Gt(1) and 3 matches (the second) Gt(1). +// +// The matchers can be specified as an array, a pointer and count, a container, +// an initializer list, or an STL iterator range. In each of these cases, the +// underlying matchers can be either values or matchers. + +template <typename Iter> +inline internal::UnorderedElementsAreArrayMatcher< + typename ::std::iterator_traits<Iter>::value_type> +IsSupersetOf(Iter first, Iter last) { + typedef typename ::std::iterator_traits<Iter>::value_type T; + return internal::UnorderedElementsAreArrayMatcher<T>( + internal::UnorderedMatcherRequire::Superset, first, last); +} + +template <typename T> +inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf( + const T* pointer, size_t count) { + return IsSupersetOf(pointer, pointer + count); +} + +template <typename T, size_t N> +inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf( + const T (&array)[N]) { + return IsSupersetOf(array, N); +} + +template <typename Container> +inline internal::UnorderedElementsAreArrayMatcher< + typename Container::value_type> +IsSupersetOf(const Container& container) { + return IsSupersetOf(container.begin(), container.end()); +} + +#if GTEST_HAS_STD_INITIALIZER_LIST_ +template <typename T> +inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf( + ::std::initializer_list<T> xs) { + return IsSupersetOf(xs.begin(), xs.end()); +} +#endif + +// IsSubsetOf(iterator_first, iterator_last) +// IsSubsetOf(pointer, count) +// IsSubsetOf(array) +// IsSubsetOf(container) +// IsSubsetOf({e1, e2, ..., en}) +// +// IsSubsetOf() verifies that an injective mapping onto a collection of matchers +// exists. In other words, a container matches IsSubsetOf({e1, ..., en}) if and +// only if there is a subset of matchers {m1, ..., mk} which would match the +// container using UnorderedElementsAre. Obviously, the size of the container +// must be <= n in order to have a match. Examples: +// +// - {1} matches IsSubsetOf({Gt(0), Lt(0)}), as 1 matches Gt(0). +// - {1, -1} matches IsSubsetOf({Lt(0), Gt(0)}), as 1 matches Gt(0) and -1 +// matches Lt(0). +// - {1, 2} doesn't matches IsSubsetOf({Gt(0), Lt(0)}), even though 1 and 2 both +// match Gt(0). The reason is that different matchers must be used for +// elements in different slots of the container. +// +// The matchers can be specified as an array, a pointer and count, a container, +// an initializer list, or an STL iterator range. In each of these cases, the +// underlying matchers can be either values or matchers. + +template <typename Iter> +inline internal::UnorderedElementsAreArrayMatcher< + typename ::std::iterator_traits<Iter>::value_type> +IsSubsetOf(Iter first, Iter last) { + typedef typename ::std::iterator_traits<Iter>::value_type T; + return internal::UnorderedElementsAreArrayMatcher<T>( + internal::UnorderedMatcherRequire::Subset, first, last); +} + +template <typename T> +inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf( + const T* pointer, size_t count) { + return IsSubsetOf(pointer, pointer + count); +} + +template <typename T, size_t N> +inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf( + const T (&array)[N]) { + return IsSubsetOf(array, N); +} + +template <typename Container> +inline internal::UnorderedElementsAreArrayMatcher< + typename Container::value_type> +IsSubsetOf(const Container& container) { + return IsSubsetOf(container.begin(), container.end()); +} + +#if GTEST_HAS_STD_INITIALIZER_LIST_ +template <typename T> +inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf( + ::std::initializer_list<T> xs) { + return IsSubsetOf(xs.begin(), xs.end()); +} +#endif + // Matches an STL-style container or a native array that contains only // elements matching the given value or matcher. // @@ -4356,17 +5155,60 @@ inline bool ExplainMatchResult( return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener); } +// Returns a string representation of the given matcher. Useful for description +// strings of matchers defined using MATCHER_P* macros that accept matchers as +// their arguments. For example: +// +// MATCHER_P(XAndYThat, matcher, +// "X that " + DescribeMatcher<int>(matcher, negation) + +// " and Y that " + DescribeMatcher<double>(matcher, negation)) { +// return ExplainMatchResult(matcher, arg.x(), result_listener) && +// ExplainMatchResult(matcher, arg.y(), result_listener); +// } +template <typename T, typename M> +std::string DescribeMatcher(const M& matcher, bool negation = false) { + ::std::stringstream ss; + Matcher<T> monomorphic_matcher = SafeMatcherCast<T>(matcher); + if (negation) { + monomorphic_matcher.DescribeNegationTo(&ss); + } else { + monomorphic_matcher.DescribeTo(&ss); + } + return ss.str(); +} + #if GTEST_LANG_CXX11 // Define variadic matcher versions. They are overloaded in // gmock-generated-matchers.h for the cases supported by pre C++11 compilers. template <typename... Args> -inline internal::AllOfMatcher<Args...> AllOf(const Args&... matchers) { - return internal::AllOfMatcher<Args...>(matchers...); +internal::AllOfMatcher<typename std::decay<const Args&>::type...> AllOf( + const Args&... matchers) { + return internal::AllOfMatcher<typename std::decay<const Args&>::type...>( + matchers...); +} + +template <typename... Args> +internal::AnyOfMatcher<typename std::decay<const Args&>::type...> AnyOf( + const Args&... matchers) { + return internal::AnyOfMatcher<typename std::decay<const Args&>::type...>( + matchers...); +} + +template <typename... Args> +internal::ElementsAreMatcher<tuple<typename std::decay<const Args&>::type...>> +ElementsAre(const Args&... matchers) { + return internal::ElementsAreMatcher< + tuple<typename std::decay<const Args&>::type...>>( + make_tuple(matchers...)); } template <typename... Args> -inline internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) { - return internal::AnyOfMatcher<Args...>(matchers...); +internal::UnorderedElementsAreMatcher< + tuple<typename std::decay<const Args&>::type...>> +UnorderedElementsAre(const Args&... matchers) { + return internal::UnorderedElementsAreMatcher< + tuple<typename std::decay<const Args&>::type...>>( + make_tuple(matchers...)); } #endif // GTEST_LANG_CXX11 @@ -4381,6 +5223,39 @@ inline internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) { template <typename InnerMatcher> inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; } +// Returns a matcher that matches the value of an optional<> type variable. +// The matcher implementation only uses '!arg' and requires that the optional<> +// type has a 'value_type' member type and that '*arg' is of type 'value_type' +// and is printable using 'PrintToString'. It is compatible with +// std::optional/std::experimental::optional. +// Note that to compare an optional type variable against nullopt you should +// use Eq(nullopt) and not Optional(Eq(nullopt)). The latter implies that the +// optional value contains an optional itself. +template <typename ValueMatcher> +inline internal::OptionalMatcher<ValueMatcher> Optional( + const ValueMatcher& value_matcher) { + return internal::OptionalMatcher<ValueMatcher>(value_matcher); +} + +// Returns a matcher that matches the value of a absl::any type variable. +template <typename T> +PolymorphicMatcher<internal::any_cast_matcher::AnyCastMatcher<T> > AnyWith( + const Matcher<const T&>& matcher) { + return MakePolymorphicMatcher( + internal::any_cast_matcher::AnyCastMatcher<T>(matcher)); +} + +// Returns a matcher that matches the value of a variant<> type variable. +// The matcher implementation uses ADL to find the holds_alternative and get +// functions. +// It is compatible with std::variant. +template <typename T> +PolymorphicMatcher<internal::variant_matcher::VariantMatcher<T> > VariantWith( + const Matcher<const T&>& matcher) { + return MakePolymorphicMatcher( + internal::variant_matcher::VariantMatcher<T>(matcher)); +} + // These macros allow using matchers to check values in Google Test // tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher) // succeed iff the value matches the matcher. If the assertion fails, @@ -4396,4 +5271,5 @@ inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; } // We must include this header at the end to make sure it can use the // declarations from this file. #include "gmock/internal/custom/gmock-matchers.h" + #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ diff --git a/googlemock/include/gmock/gmock-more-actions.h b/googlemock/include/gmock/gmock-more-actions.h index 3d387b6b..1106818d 100644 --- a/googlemock/include/gmock/gmock-more-actions.h +++ b/googlemock/include/gmock/gmock-more-actions.h @@ -33,6 +33,8 @@ // // This file implements some actions that depend on gmock-generated-actions.h. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index 3db899f4..6c6b3e3c 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -36,6 +36,8 @@ // Note that tests are implemented in gmock-matchers_test.cc rather than // gmock-more-matchers-test.cc. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_GMOCK_MORE_MATCHERS_H_ #define GMOCK_GMOCK_MORE_MATCHERS_H_ @@ -43,6 +45,18 @@ namespace testing { +// Silence C4100 (unreferenced formal +// parameter) for MSVC +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4100) +#if (_MSC_VER == 1900) +// and silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14 +# pragma warning(disable:4800) + #endif +#endif + // Defines a matcher that matches an empty container. The container must // support both size() and empty(), which all STL-like containers provide. MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { @@ -53,6 +67,27 @@ MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { return false; } +// Define a matcher that matches a value that evaluates in boolean +// context to true. Useful for types that define "explicit operator +// bool" operators and so can't be compared for equality with true +// and false. +MATCHER(IsTrue, negation ? "is false" : "is true") { + return static_cast<bool>(arg); +} + +// Define a matcher that matches a value that evaluates in boolean +// context to false. Useful for types that define "explicit operator +// bool" operators and so can't be compared for equality with true +// and false. +MATCHER(IsFalse, negation ? "is true" : "is false") { + return !static_cast<bool>(arg); +} + +#ifdef _MSC_VER +# pragma warning(pop) +#endif + + } // namespace testing #endif // GMOCK_GMOCK_MORE_MATCHERS_H_ diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index fed7de66..9670b59c 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -57,6 +57,8 @@ // where all clauses are optional, and .InSequence()/.After()/ // .WillOnce() can appear any number of times. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ @@ -65,11 +67,6 @@ #include <sstream> #include <string> #include <vector> - -#if GTEST_HAS_EXCEPTIONS -# include <stdexcept> // NOLINT -#endif - #include "gmock/gmock-actions.h" #include "gmock/gmock-cardinalities.h" #include "gmock/gmock-matchers.h" @@ -77,6 +74,10 @@ #include "gmock/internal/gmock-port.h" #include "gtest/gtest.h" +#if GTEST_HAS_EXCEPTIONS +# include <stdexcept> // NOLINT +#endif + namespace testing { // An abstract handle of an expectation. @@ -148,15 +149,13 @@ class GTEST_API_ UntypedFunctionMockerBase { // action fails. // L = * virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( - const void* untyped_args, - const string& call_description) const = 0; + void* untyped_args, const std::string& call_description) const = 0; // Performs the given action with the given arguments and returns // the action's result. // L = * virtual UntypedActionResultHolderBase* UntypedPerformAction( - const void* untyped_action, - const void* untyped_args) const = 0; + const void* untyped_action, void* untyped_args) const = 0; // Writes a message that the call is uninteresting (i.e. neither // explicitly expected nor explicitly unexpected) to the given @@ -211,9 +210,8 @@ class GTEST_API_ UntypedFunctionMockerBase { // arguments. This function can be safely called from multiple // threads concurrently. The caller is responsible for deleting the // result. - UntypedActionResultHolderBase* UntypedInvokeWith( - const void* untyped_args) - GTEST_LOCK_EXCLUDED_(g_gmock_mutex); + UntypedActionResultHolderBase* UntypedInvokeWith(void* untyped_args) + GTEST_LOCK_EXCLUDED_(g_gmock_mutex); protected: typedef std::vector<const void*> UntypedOnCallSpecs; @@ -238,6 +236,14 @@ class GTEST_API_ UntypedFunctionMockerBase { UntypedOnCallSpecs untyped_on_call_specs_; // All expectations for this function mocker. + // + // It's undefined behavior to interleave expectations (EXPECT_CALLs + // or ON_CALLs) and mock function calls. Also, the order of + // expectations is important. Therefore it's a logic race condition + // to read/write untyped_expectations_ concurrently. In order for + // tools like tsan to catch concurrent read/write accesses to + // untyped_expectations, we deliberately leave accesses to it + // unprotected. UntypedExpectations untyped_expectations_; }; // class UntypedFunctionMockerBase @@ -263,12 +269,14 @@ class UntypedOnCallSpecBase { }; // Asserts that the ON_CALL() statement has a certain property. - void AssertSpecProperty(bool property, const string& failure_message) const { + void AssertSpecProperty(bool property, + const std::string& failure_message) const { Assert(property, file_, line_, failure_message); } // Expects that the ON_CALL() statement has a certain property. - void ExpectSpecProperty(bool property, const string& failure_message) const { + void ExpectSpecProperty(bool property, + const std::string& failure_message) const { Expect(property, file_, line_, failure_message); } @@ -362,7 +370,6 @@ enum CallReaction { kAllow, kWarn, kFail, - kDefault = kWarn // By default, warn about uninteresting calls. }; } // namespace internal @@ -690,7 +697,7 @@ GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence; class GTEST_API_ ExpectationBase { public: // source_text is the EXPECT_CALL(...) source that created this Expectation. - ExpectationBase(const char* file, int line, const string& source_text); + ExpectationBase(const char* file, int line, const std::string& source_text); virtual ~ExpectationBase(); @@ -738,12 +745,14 @@ class GTEST_API_ ExpectationBase { virtual Expectation GetHandle() = 0; // Asserts that the EXPECT_CALL() statement has the given property. - void AssertSpecProperty(bool property, const string& failure_message) const { + void AssertSpecProperty(bool property, + const std::string& failure_message) const { Assert(property, file_, line_, failure_message); } // Expects that the EXPECT_CALL() statement has the given property. - void ExpectSpecProperty(bool property, const string& failure_message) const { + void ExpectSpecProperty(bool property, + const std::string& failure_message) const { Expect(property, file_, line_, failure_message); } @@ -845,7 +854,7 @@ class GTEST_API_ ExpectationBase { // an EXPECT_CALL() statement finishes. const char* file_; // The file that contains the expectation. int line_; // The line number of the expectation. - const string source_text_; // The EXPECT_CALL(...) source text. + const std::string source_text_; // The EXPECT_CALL(...) source text. // True iff the cardinality is specified explicitly. bool cardinality_specified_; Cardinality cardinality_; // The cardinality of the expectation. @@ -880,8 +889,8 @@ class TypedExpectation : public ExpectationBase { typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; typedef typename Function<F>::Result Result; - TypedExpectation(FunctionMockerBase<F>* owner, - const char* a_file, int a_line, const string& a_source_text, + TypedExpectation(FunctionMockerBase<F>* owner, const char* a_file, int a_line, + const std::string& a_source_text, const ArgumentMatcherTuple& m) : ExpectationBase(a_file, a_line, a_source_text), owner_(owner), @@ -1240,7 +1249,7 @@ class TypedExpectation : public ExpectationBase { // Logs a message including file and line number information. GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity, const char* file, int line, - const string& message); + const std::string& message); template <typename F> class MockSpec { @@ -1251,15 +1260,16 @@ class MockSpec { // Constructs a MockSpec object, given the function mocker object // that the spec is associated with. - explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker) - : function_mocker_(function_mocker) {} + MockSpec(internal::FunctionMockerBase<F>* function_mocker, + const ArgumentMatcherTuple& matchers) + : function_mocker_(function_mocker), matchers_(matchers) {} // Adds a new default action spec to the function mocker and returns // the newly created spec. internal::OnCallSpec<F>& InternalDefaultActionSetAt( const char* file, int line, const char* obj, const char* call) { LogWithLocation(internal::kInfo, file, line, - string("ON_CALL(") + obj + ", " + call + ") invoked"); + std::string("ON_CALL(") + obj + ", " + call + ") invoked"); return function_mocker_->AddNewOnCallSpec(file, line, matchers_); } @@ -1267,20 +1277,24 @@ class MockSpec { // the newly created spec. internal::TypedExpectation<F>& InternalExpectedAt( const char* file, int line, const char* obj, const char* call) { - const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")"); + const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " + + call + ")"); LogWithLocation(internal::kInfo, file, line, source_text + " invoked"); return function_mocker_->AddNewExpectation( file, line, source_text, matchers_); } + // This operator overload is used to swallow the superfluous parameter list + // introduced by the ON/EXPECT_CALL macros. See the macro comments for more + // explanation. + MockSpec<F>& operator()(const internal::WithoutMatchers&, void* const) { + return *this; + } + private: template <typename Function> friend class internal::FunctionMocker; - void SetMatchers(const ArgumentMatcherTuple& matchers) { - matchers_ = matchers; - } - // The function mocker that owns this spec. internal::FunctionMockerBase<F>* const function_mocker_; // The argument matchers specified in the spec. @@ -1388,19 +1402,20 @@ class ActionResultHolder : public UntypedActionResultHolderBase { template <typename F> static ActionResultHolder* PerformDefaultAction( const FunctionMockerBase<F>* func_mocker, - const typename Function<F>::ArgumentTuple& args, - const string& call_description) { - return new ActionResultHolder(Wrapper( - func_mocker->PerformDefaultAction(args, call_description))); + typename RvalueRef<typename Function<F>::ArgumentTuple>::type args, + const std::string& call_description) { + return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction( + internal::move(args), call_description))); } // Performs the given action and returns the result in a new-ed // ActionResultHolder. template <typename F> - static ActionResultHolder* - PerformAction(const Action<F>& action, - const typename Function<F>::ArgumentTuple& args) { - return new ActionResultHolder(Wrapper(action.Perform(args))); + static ActionResultHolder* PerformAction( + const Action<F>& action, + typename RvalueRef<typename Function<F>::ArgumentTuple>::type args) { + return new ActionResultHolder( + Wrapper(action.Perform(internal::move(args)))); } private: @@ -1428,9 +1443,9 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase { template <typename F> static ActionResultHolder* PerformDefaultAction( const FunctionMockerBase<F>* func_mocker, - const typename Function<F>::ArgumentTuple& args, - const string& call_description) { - func_mocker->PerformDefaultAction(args, call_description); + typename RvalueRef<typename Function<F>::ArgumentTuple>::type args, + const std::string& call_description) { + func_mocker->PerformDefaultAction(internal::move(args), call_description); return new ActionResultHolder; } @@ -1439,8 +1454,8 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase { template <typename F> static ActionResultHolder* PerformAction( const Action<F>& action, - const typename Function<F>::ArgumentTuple& args) { - action.Perform(args); + typename RvalueRef<typename Function<F>::ArgumentTuple>::type args) { + action.Perform(internal::move(args)); return new ActionResultHolder; } @@ -1459,7 +1474,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { typedef typename Function<F>::ArgumentTuple ArgumentTuple; typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; - FunctionMockerBase() : current_spec_(this) {} + FunctionMockerBase() {} // The destructor verifies that all expectations on this mock // function have been satisfied. If not, it will report Google Test @@ -1495,14 +1510,16 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // mutable state of this object, and thus can be called concurrently // without locking. // L = * - Result PerformDefaultAction(const ArgumentTuple& args, - const string& call_description) const { + Result PerformDefaultAction( + typename RvalueRef<typename Function<F>::ArgumentTuple>::type args, + const std::string& call_description) const { const OnCallSpec<F>* const spec = this->FindOnCallSpec(args); if (spec != NULL) { - return spec->GetAction().Perform(args); + return spec->GetAction().Perform(internal::move(args)); } - const string message = call_description + + const std::string message = + call_description + "\n The mock function has no default action " "set, and its return type has no default value set."; #if GTEST_HAS_EXCEPTIONS @@ -1521,11 +1538,11 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // action fails. The caller is responsible for deleting the result. // L = * virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( - const void* untyped_args, // must point to an ArgumentTuple - const string& call_description) const { - const ArgumentTuple& args = - *static_cast<const ArgumentTuple*>(untyped_args); - return ResultHolder::PerformDefaultAction(this, args, call_description); + void* untyped_args, // must point to an ArgumentTuple + const std::string& call_description) const { + ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args); + return ResultHolder::PerformDefaultAction(this, internal::move(*args), + call_description); } // Performs the given action with the given arguments and returns @@ -1533,13 +1550,12 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // result. // L = * virtual UntypedActionResultHolderBase* UntypedPerformAction( - const void* untyped_action, const void* untyped_args) const { + const void* untyped_action, void* untyped_args) const { // Make a copy of the action before performing it, in case the // action deletes the mock object (and thus deletes itself). const Action<F> action = *static_cast<const Action<F>*>(untyped_action); - const ArgumentTuple& args = - *static_cast<const ArgumentTuple*>(untyped_args); - return ResultHolder::PerformAction(action, args); + ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args); + return ResultHolder::PerformAction(action, internal::move(*args)); } // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked(): @@ -1579,10 +1595,14 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // Returns the result of invoking this mock function with the given // arguments. This function can be safely called from multiple // threads concurrently. - Result InvokeWith(const ArgumentTuple& args) - GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { + Result InvokeWith( + typename RvalueRef<typename Function<F>::ArgumentTuple>::type args) + GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { + // const_cast is required since in C++98 we still pass ArgumentTuple around + // by const& instead of rvalue reference. + void* untyped_args = const_cast<void*>(static_cast<const void*>(&args)); scoped_ptr<ResultHolder> holder( - DownCast_<ResultHolder*>(this->UntypedInvokeWith(&args))); + DownCast_<ResultHolder*>(this->UntypedInvokeWith(untyped_args))); return holder->Unwrap(); } @@ -1598,16 +1618,16 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { } // Adds and returns an expectation spec for this mock function. - TypedExpectation<F>& AddNewExpectation( - const char* file, - int line, - const string& source_text, - const ArgumentMatcherTuple& m) - GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { + TypedExpectation<F>& AddNewExpectation(const char* file, int line, + const std::string& source_text, + const ArgumentMatcherTuple& m) + GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); TypedExpectation<F>* const expectation = new TypedExpectation<F>(this, file, line, source_text, m); const linked_ptr<ExpectationBase> untyped_expectation(expectation); + // See the definition of untyped_expectations_ for why access to + // it is unprotected here. untyped_expectations_.push_back(untyped_expectation); // Adds this expectation into the implicit sequence if there is one. @@ -1619,10 +1639,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { return *expectation; } - // The current spec (either default action spec or expectation spec) - // being described on this function mocker. - MockSpec<F>& current_spec() { return current_spec_; } - private: template <typename Func> friend class TypedExpectation; @@ -1715,6 +1731,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { const ArgumentTuple& args) const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { g_gmock_mutex.AssertHeld(); + // See the definition of untyped_expectations_ for why access to + // it is unprotected here. for (typename UntypedExpectations::const_reverse_iterator it = untyped_expectations_.rbegin(); it != untyped_expectations_.rend(); ++it) { @@ -1765,14 +1783,10 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { } } - // The current spec (either default action spec or expectation spec) - // being described on this function mocker. - MockSpec<F> current_spec_; - // There is no generally useful and implementable semantics of // copying a mock object, so copying a mock is usually a user error. // Thus we disallow copying function mockers. If the user really - // wants to copy a mock object, he should implement his own copy + // wants to copy a mock object, they should implement their own copy // operation, for example: // // class MockFoo : public Foo { @@ -1796,7 +1810,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // Reports an uninteresting call (whose description is in msg) in the // manner specified by 'reaction'. -void ReportUninterestingCall(CallReaction reaction, const string& msg); +void ReportUninterestingCall(CallReaction reaction, const std::string& msg); } // namespace internal @@ -1831,17 +1845,76 @@ inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT } // namespace testing -// A separate macro is required to avoid compile errors when the name -// of the method used in call is a result of macro expansion. -// See CompilesWithMethodNameExpandedFromMacro tests in -// internal/gmock-spec-builders_test.cc for more details. -#define GMOCK_ON_CALL_IMPL_(obj, call) \ - ((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \ - #obj, #call) -#define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call) - -#define GMOCK_EXPECT_CALL_IMPL_(obj, call) \ - ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call) -#define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call) +// Implementation for ON_CALL and EXPECT_CALL macros. A separate macro is +// required to avoid compile errors when the name of the method used in call is +// a result of macro expansion. See CompilesWithMethodNameExpandedFromMacro +// tests in internal/gmock-spec-builders_test.cc for more details. +// +// This macro supports statements both with and without parameter matchers. If +// the parameter list is omitted, gMock will accept any parameters, which allows +// tests to be written that don't need to encode the number of method +// parameter. This technique may only be used for non-overloaded methods. +// +// // These are the same: +// ON_CALL(mock, NoArgsMethod()).WillByDefault(...); +// ON_CALL(mock, NoArgsMethod).WillByDefault(...); +// +// // As are these: +// ON_CALL(mock, TwoArgsMethod(_, _)).WillByDefault(...); +// ON_CALL(mock, TwoArgsMethod).WillByDefault(...); +// +// // Can also specify args if you want, of course: +// ON_CALL(mock, TwoArgsMethod(_, 45)).WillByDefault(...); +// +// // Overloads work as long as you specify parameters: +// ON_CALL(mock, OverloadedMethod(_)).WillByDefault(...); +// ON_CALL(mock, OverloadedMethod(_, _)).WillByDefault(...); +// +// // Oops! Which overload did you want? +// ON_CALL(mock, OverloadedMethod).WillByDefault(...); +// => ERROR: call to member function 'gmock_OverloadedMethod' is ambiguous +// +// How this works: The mock class uses two overloads of the gmock_Method +// expectation setter method plus an operator() overload on the MockSpec object. +// In the matcher list form, the macro expands to: +// +// // This statement: +// ON_CALL(mock, TwoArgsMethod(_, 45))... +// +// // ...expands to: +// mock.gmock_TwoArgsMethod(_, 45)(WithoutMatchers(), nullptr)... +// |-------------v---------------||------------v-------------| +// invokes first overload swallowed by operator() +// +// // ...which is essentially: +// mock.gmock_TwoArgsMethod(_, 45)... +// +// Whereas the form without a matcher list: +// +// // This statement: +// ON_CALL(mock, TwoArgsMethod)... +// +// // ...expands to: +// mock.gmock_TwoArgsMethod(WithoutMatchers(), nullptr)... +// |-----------------------v--------------------------| +// invokes second overload +// +// // ...which is essentially: +// mock.gmock_TwoArgsMethod(_, _)... +// +// The WithoutMatchers() argument is used to disambiguate overloads and to +// block the caller from accidentally invoking the second overload directly. The +// second argument is an internal type derived from the method signature. The +// failure to disambiguate two overloads of this method in the ON_CALL statement +// is how we block callers from setting expectations on overloaded methods. +#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \ + ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), NULL) \ + .Setter(__FILE__, __LINE__, #mock_expr, #call) + +#define ON_CALL(obj, call) \ + GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call) + +#define EXPECT_CALL(obj, call) \ + GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call) #endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ diff --git a/googlemock/include/gmock/gmock.h b/googlemock/include/gmock/gmock.h index 6735c71b..6330294d 100644 --- a/googlemock/include/gmock/gmock.h +++ b/googlemock/include/gmock/gmock.h @@ -33,6 +33,8 @@ // // This is the main header file a user should include. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_H_ @@ -59,8 +61,8 @@ #include "gmock/gmock-cardinalities.h" #include "gmock/gmock-generated-actions.h" #include "gmock/gmock-generated-function-mockers.h" -#include "gmock/gmock-generated-nice-strict.h" #include "gmock/gmock-generated-matchers.h" +#include "gmock/gmock-generated-nice-strict.h" #include "gmock/gmock-matchers.h" #include "gmock/gmock-more-actions.h" #include "gmock/gmock-more-matchers.h" @@ -71,6 +73,7 @@ namespace testing { // Declares Google Mock flags that we want a user to use programmatically. GMOCK_DECLARE_bool_(catch_leaked_mocks); GMOCK_DECLARE_string_(verbose); +GMOCK_DECLARE_int32_(default_mock_behavior); // Initializes Google Mock. This must be called before running the // tests. In particular, it parses the command line for the flags diff --git a/googlemock/include/gmock/internal/custom/gmock-generated-actions.h b/googlemock/include/gmock/internal/custom/gmock-generated-actions.h index 7dc3b1ad..92d910cf 100644 --- a/googlemock/include/gmock/internal/custom/gmock-generated-actions.h +++ b/googlemock/include/gmock/internal/custom/gmock-generated-actions.h @@ -2,6 +2,8 @@ // pump.py gmock-generated-actions.h.pump // DO NOT EDIT BY HAND!!! +// 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_ diff --git a/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump b/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump index d26c8a08..67c221f1 100644 --- a/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump @@ -1,9 +1,11 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file (http://go/pump). Please use Pump to convert +$$ 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_ diff --git a/googlemock/include/gmock/internal/custom/gmock-matchers.h b/googlemock/include/gmock/internal/custom/gmock-matchers.h index f2efef91..b9b7e3f8 100644 --- a/googlemock/include/gmock/internal/custom/gmock-matchers.h +++ b/googlemock/include/gmock/internal/custom/gmock-matchers.h @@ -32,8 +32,9 @@ // ============================================================ // // Adds google3 callback support to CallableTraits. -// -#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_ -#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_ -#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_ +// GOOGLETEST_CM0002 DO NOT DELETE + +#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ +#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ +#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ diff --git a/googlemock/include/gmock/internal/custom/gmock-port.h b/googlemock/include/gmock/internal/custom/gmock-port.h index 9ce8bfe0..ad9ae36f 100644 --- a/googlemock/include/gmock/internal/custom/gmock-port.h +++ b/googlemock/include/gmock/internal/custom/gmock-port.h @@ -40,6 +40,8 @@ // // ** Custom implementation starts here ** +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ diff --git a/googlemock/include/gmock/internal/gmock-generated-internal-utils.h b/googlemock/include/gmock/internal/gmock-generated-internal-utils.h index 7811e43f..c9bfbc8b 100644 --- a/googlemock/include/gmock/internal/gmock-generated-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-generated-internal-utils.h @@ -38,6 +38,8 @@ // This file contains template meta-programming utility classes needed // for implementing Google Mock. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ @@ -90,42 +92,48 @@ struct MatcherTuple< ::testing::tuple<A1, A2, A3> > { template <typename A1, typename A2, typename A3, typename A4> struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4> > { - typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, - Matcher<A4> > type; + typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4> > + type; }; template <typename A1, typename A2, typename A3, typename A4, typename A5> struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5> > { typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - Matcher<A5> > type; + Matcher<A5> > + type; }; template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6> > { typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - Matcher<A5>, Matcher<A6> > type; + Matcher<A5>, Matcher<A6> > + type; }; template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7> > { typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - Matcher<A5>, Matcher<A6>, Matcher<A7> > type; + Matcher<A5>, Matcher<A6>, Matcher<A7> > + type; }; template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > { typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8> > type; + Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8> > + type; }; template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > { typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9> > type; + Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, + Matcher<A9> > + type; }; template <typename A1, typename A2, typename A3, typename A4, typename A5, @@ -133,8 +141,9 @@ template <typename A1, typename A2, typename A3, typename A4, typename A5, struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10> > { typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9>, - Matcher<A10> > type; + Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, + Matcher<A9>, Matcher<A10> > + type; }; // Template struct Function<F>, where F must be a function type, contains diff --git a/googlemock/include/gmock/internal/gmock-generated-internal-utils.h.pump b/googlemock/include/gmock/internal/gmock-generated-internal-utils.h.pump index 800af17c..f13151bd 100644 --- a/googlemock/include/gmock/internal/gmock-generated-internal-utils.h.pump +++ b/googlemock/include/gmock/internal/gmock-generated-internal-utils.h.pump @@ -39,6 +39,8 @@ $var n = 10 $$ The maximum arity we support. // This file contains template meta-programming utility classes needed // for implementing Google Mock. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index e2ddb05c..e0846d9b 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -35,13 +35,14 @@ // Mock. They are subject to change without notice, so please DO NOT // USE THEM IN USER CODE. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ #include <stdio.h> #include <ostream> // NOLINT #include <string> - #include "gmock/internal/gmock-generated-internal-utils.h" #include "gmock/internal/gmock-port.h" #include "gtest/gtest.h" @@ -49,11 +50,23 @@ namespace testing { namespace internal { +// Silence MSVC C4100 (unreferenced formal parameter) and +// C4805('==': unsafe mix of type 'const int' and type 'const bool') +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4100) +# pragma warning(disable:4805) +#endif + +// Joins a vector of strings as if they are fields of a tuple; returns +// the joined string. +GTEST_API_ std::string JoinAsTuple(const Strings& fields); + // Converts an identifier name to a space-separated list of lower-case // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is // treated as one word. For example, both "FooBar123" and // "foo_bar_123" are converted to "foo bar 123". -GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name); +GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name); // PointeeOf<Pointer>::type is the type of a value pointed to by a // Pointer, which can be either a smart pointer or a raw pointer. The @@ -114,9 +127,11 @@ struct LinkedPtrLessThan { // To gcc, // wchar_t == signed wchar_t != unsigned wchar_t == unsigned int #ifdef __GNUC__ +#if !defined(__WCHAR_UNSIGNED__) // signed/unsigned wchar_t are valid types. # define GMOCK_HAS_SIGNED_WCHAR_T_ 1 #endif +#endif // In what follows, we use the term "kind" to indicate whether a type // is bool, an integer type (excluding bool), a floating-point type, @@ -267,7 +282,7 @@ class FailureReporterInterface { // Reports a failure that occurred at the given source file location. virtual void ReportFailure(FailureType type, const char* file, int line, - const string& message) = 0; + const std::string& message) = 0; }; // Returns the failure reporter used by Google Mock. @@ -279,7 +294,7 @@ GTEST_API_ FailureReporterInterface* GetFailureReporter(); // inline this function to prevent it from showing up in the stack // trace. inline void Assert(bool condition, const char* file, int line, - const string& msg) { + const std::string& msg) { if (!condition) { GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal, file, line, msg); @@ -292,7 +307,7 @@ inline void Assert(bool condition, const char* file, int line) { // Verifies that condition is true; generates a non-fatal failure if // condition is false. inline void Expect(bool condition, const char* file, int line, - const string& msg) { + const std::string& msg) { if (!condition) { GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal, file, line, msg); @@ -328,10 +343,24 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity); // stack_frames_to_skip is treated as 0, since we don't know which // function calls will be inlined by the compiler and need to be // conservative. -GTEST_API_ void Log(LogSeverity severity, - const string& message, +GTEST_API_ void Log(LogSeverity severity, const std::string& message, int stack_frames_to_skip); +// A marker class that is used to resolve parameterless expectations to the +// correct overload. This must not be instantiable, to prevent client code from +// accidentally resolving to the overload; for example: +// +// ON_CALL(mock, Method({}, nullptr))... +// +class WithoutMatchers { + private: + WithoutMatchers() {} + friend GTEST_API_ WithoutMatchers GetWithoutMatchers(); +}; + +// Internal use only: access the singleton instance of WithoutMatchers. +GTEST_API_ WithoutMatchers GetWithoutMatchers(); + // TODO(wan@google.com): group all type utilities together. // Type traits. @@ -504,8 +533,44 @@ struct RemoveConstFromKey<std::pair<const K, V> > { template <bool kValue> struct BooleanConstant {}; +// Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to +// reduce code size. +GTEST_API_ void IllegalDoDefault(const char* file, int line); + +#if GTEST_LANG_CXX11 +// Helper types for Apply() below. +template <size_t... Is> struct int_pack { typedef int_pack type; }; + +template <class Pack, size_t I> struct append; +template <size_t... Is, size_t I> +struct append<int_pack<Is...>, I> : int_pack<Is..., I> {}; + +template <size_t C> +struct make_int_pack : append<typename make_int_pack<C - 1>::type, C - 1> {}; +template <> struct make_int_pack<0> : int_pack<> {}; + +template <typename F, typename Tuple, size_t... Idx> +auto ApplyImpl(F&& f, Tuple&& args, int_pack<Idx...>) -> decltype( + std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...)) { + return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...); +} + +// Apply the function to a tuple of arguments. +template <typename F, typename Tuple> +auto Apply(F&& f, Tuple&& args) + -> decltype(ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), + make_int_pack<std::tuple_size<Tuple>::value>())) { + return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), + make_int_pack<std::tuple_size<Tuple>::value>()); +} +#endif + + +#ifdef _MSC_VER +# pragma warning(pop) +#endif + } // namespace internal } // namespace testing #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ - diff --git a/googlemock/include/gmock/internal/gmock-port.h b/googlemock/include/gmock/internal/gmock-port.h index 63f4a680..79f43663 100644 --- a/googlemock/include/gmock/internal/gmock-port.h +++ b/googlemock/include/gmock/internal/gmock-port.h @@ -36,6 +36,8 @@ // end with _ are part of Google Mock's public API and can be used by // code outside Google Mock. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ @@ -50,15 +52,11 @@ // portability utilities to Google Test's gtest-port.h instead of // here, as Google Mock depends on Google Test. Only add a utility // here if it's truly specific to Google Mock. + #include "gtest/internal/gtest-linked_ptr.h" #include "gtest/internal/gtest-port.h" #include "gmock/internal/custom/gmock-port.h" -// To avoid conditional compilation everywhere, we make it -// gmock-port.h's responsibility to #include the header implementing -// tr1/tuple. gmock-port.h does this via gtest-port.h, which is -// guaranteed to pull in the tuple header. - // For MS Visual C++, check the compiler version. At least VS 2003 is // required to compile Google Mock. #if defined(_MSC_VER) && _MSC_VER < 1310 @@ -72,18 +70,18 @@ #if !defined(GMOCK_DECLARE_bool_) // Macros for declaring flags. -#define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name) -#define GMOCK_DECLARE_int32_(name) \ +# define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name) +# define GMOCK_DECLARE_int32_(name) \ extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) -#define GMOCK_DECLARE_string_(name) \ +# define GMOCK_DECLARE_string_(name) \ extern GTEST_API_ ::std::string GMOCK_FLAG(name) // Macros for defining flags. -#define GMOCK_DEFINE_bool_(name, default_val, doc) \ +# define GMOCK_DEFINE_bool_(name, default_val, doc) \ GTEST_API_ bool GMOCK_FLAG(name) = (default_val) -#define GMOCK_DEFINE_int32_(name, default_val, doc) \ +# define GMOCK_DEFINE_int32_(name, default_val, doc) \ GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val) -#define GMOCK_DEFINE_string_(name, default_val, doc) \ +# define GMOCK_DEFINE_string_(name, default_val, doc) \ GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val) #endif // !defined(GMOCK_DECLARE_bool_) |