diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-13 16:23:34 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-14 10:37:21 +0000 |
commit | 38a9a29f4f9436cace7f0e7abf9c586057df8a4e (patch) | |
tree | c4e8c458dc595bc0ddb435708fa2229edfd00bd4 /chromium/third_party/googletest/src/googlemock/include | |
parent | e684a3455bcc29a6e3e66a004e352dea4e1141e7 (diff) | |
download | qtwebengine-chromium-38a9a29f4f9436cace7f0e7abf9c586057df8a4e.tar.gz |
BASELINE: Update Chromium to 73.0.3683.37
Change-Id: I08c9af2948b645f671e5d933aca1f7a90ea372f2
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/third_party/googletest/src/googlemock/include')
19 files changed, 1283 insertions, 4512 deletions
diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-actions.h b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-actions.h index e4af9d2df71..2f936a15b33 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-actions.h +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-actions.h @@ -42,17 +42,19 @@ #endif #include <algorithm> +#include <functional> #include <memory> #include <string> +#include <type_traits> #include <utility> #include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-port.h" -#if GTEST_LANG_CXX11 // Defined by gtest-port.h via gmock-port.h. -#include <functional> -#include <type_traits> -#endif // GTEST_LANG_CXX11 +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4100) +#endif namespace testing { @@ -67,9 +69,6 @@ namespace testing { namespace internal { -template <typename F1, typename F2> -class ActionAdaptor; - // BuiltInDefaultValueGetter<T, true>::Get() returns a // default-constructed T value. BuiltInDefaultValueGetter<T, // false>::Get() crashes with an error. @@ -100,7 +99,6 @@ struct BuiltInDefaultValueGetter<T, false> { template <typename T> class BuiltInDefaultValue { public: -#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; @@ -110,18 +108,6 @@ class BuiltInDefaultValue { return BuiltInDefaultValueGetter< T, ::std::is_default_constructible<T>::value>::Get(); } - -#else // GTEST_LANG_CXX11 - // This function returns true iff type T has a built-in default value. - static bool Exists() { - return false; - } - - static T Get() { - return BuiltInDefaultValueGetter<T, false>::Get(); - } - -#endif // GTEST_LANG_CXX11 }; // This partial specialization says that we use the same built-in @@ -252,7 +238,7 @@ class DefaultValue { class FixedValueProducer : public ValueProducer { public: explicit FixedValueProducer(T value) : value_(value) {} - virtual T Produce() { return value_; } + T Produce() override { return value_; } private: const T value_; @@ -263,7 +249,7 @@ class DefaultValue { public: explicit FactoryValueProducer(FactoryFunction factory) : factory_(factory) {} - virtual T Produce() { return factory_(); } + T Produce() override { return factory_(); } private: const FactoryFunction factory_; @@ -353,6 +339,19 @@ class ActionInterface { // object as a handle to it. template <typename F> class Action { + // Adapter class to allow constructing Action from a legacy ActionInterface. + // New code should create Actions from functors instead. + struct ActionAdapter { + // Adapter must be copyable to satisfy std::function requirements. + ::std::shared_ptr<ActionInterface<F>> impl_; + + template <typename... Args> + typename internal::Function<F>::Result operator()(Args&&... args) { + return impl_->Perform( + ::std::forward_as_tuple(::std::forward<Args>(args)...)); + } + }; + public: typedef typename internal::Function<F>::Result Result; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; @@ -361,7 +360,6 @@ class Action { // STL containers. Action() {} -#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). @@ -369,26 +367,19 @@ class Action { typename = typename ::std::enable_if< ::std::is_constructible<::std::function<F>, G>::value>::type> Action(G&& fun) : fun_(::std::forward<G>(fun)) {} // NOLINT -#endif // Constructs an Action from its implementation. - explicit Action(ActionInterface<F>* impl) : impl_(impl) {} + explicit Action(ActionInterface<F>* impl) + : fun_(ActionAdapter{::std::shared_ptr<ActionInterface<F>>(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 - // to Func's and Func's return type can be implicitly converted to - // F's. + // to Func's and Func's return type can be implicitly converted to F's. template <typename Func> - explicit Action(const Action<Func>& action); + explicit Action(const Action<Func>& action) : fun_(action.fun_) {} // Returns true iff this is the DoDefault() action. - bool IsDoDefault() const { -#if GTEST_LANG_CXX11 - return impl_ == nullptr && fun_ == nullptr; -#else - return impl_ == NULL; -#endif - } + bool IsDoDefault() const { return fun_ == nullptr; } // Performs the action. Note that this method is const even though // the corresponding method in ActionInterface is not. The reason @@ -400,31 +391,15 @@ class Action { 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); + return internal::Apply(fun_, ::std::move(args)); } private: - 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 + // fun_ is an empty function iff this is the DoDefault() action. ::std::function<F> fun_; -#endif - std::shared_ptr<ActionInterface<F>> impl_; }; // The PolymorphicAction class template makes it easy to implement a @@ -467,7 +442,7 @@ class PolymorphicAction { explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} - virtual Result Perform(const ArgumentTuple& args) { + Result Perform(const ArgumentTuple& args) override { return impl_.template Perform<Result>(args); } @@ -503,26 +478,6 @@ inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) { namespace internal { -// Allows an Action<F2> object to pose as an Action<F1>, as long as F2 -// and F1 are compatible. -template <typename F1, typename F2> -class ActionAdaptor : public ActionInterface<F1> { - public: - typedef typename internal::Function<F1>::Result Result; - typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple; - - explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {} - - virtual Result Perform(const ArgumentTuple& args) { - return impl_->Perform(args); - } - - private: - const std::shared_ptr<ActionInterface<F2>> impl_; - - GTEST_DISALLOW_ASSIGN_(ActionAdaptor); -}; - // Helper struct to specialize ReturnAction to execute a move instead of a copy // on return. Useful for move-only types, but could be used on any type. template <typename T> @@ -569,7 +524,7 @@ class ReturnAction { // This template type conversion operator allows Return(x) to be // used in ANY function that returns x's type. template <typename F> - operator Action<F>() const { + operator Action<F>() const { // NOLINT // Assert statement belongs here because this is the best place to verify // conditions on F. It produces the clearest error messages // in most compilers. @@ -582,6 +537,8 @@ class ReturnAction { GTEST_COMPILE_ASSERT_( !is_reference<Result>::value, use_ReturnRef_instead_of_Return_to_return_a_reference); + static_assert(!std::is_void<Result>::value, + "Can't use Return() on an action expected to return `void`."); return Action<F>(new Impl<R, F>(value_)); } @@ -604,7 +561,7 @@ class ReturnAction { : value_before_cast_(*value), value_(ImplicitCast_<Result>(value_before_cast_)) {} - virtual Result Perform(const ArgumentTuple&) { return value_; } + Result Perform(const ArgumentTuple&) override { return value_; } private: GTEST_COMPILE_ASSERT_(!is_reference<Result>::value, @@ -628,7 +585,7 @@ class ReturnAction { explicit Impl(const std::shared_ptr<R>& wrapper) : performed_(false), wrapper_(wrapper) {} - virtual Result Perform(const ArgumentTuple&) { + Result Perform(const ArgumentTuple&) override { GTEST_CHECK_(!performed_) << "A ByMove() action should only be performed once."; performed_ = true; @@ -655,13 +612,7 @@ class ReturnNullAction { // pointer type on compile time. template <typename Result, typename ArgumentTuple> static Result Perform(const ArgumentTuple&) { -#if GTEST_LANG_CXX11 return nullptr; -#else - GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value, - ReturnNull_can_be_used_to_return_a_pointer_only); - return NULL; -#endif // GTEST_LANG_CXX11 } }; @@ -707,9 +658,7 @@ class ReturnRefAction { explicit Impl(T& ref) : ref_(ref) {} // NOLINT - virtual Result Perform(const ArgumentTuple&) { - return ref_; - } + Result Perform(const ArgumentTuple&) override { return ref_; } private: T& ref_; @@ -756,9 +705,7 @@ class ReturnRefOfCopyAction { explicit Impl(const T& value) : value_(value) {} // NOLINT - virtual Result Perform(const ArgumentTuple&) { - return value_; - } + Result Perform(const ArgumentTuple&) override { return value_; } private: T value_; @@ -870,69 +817,47 @@ class SetArgumentPointeeAction<N, Proto, true> { GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction); }; +// Implements the Invoke(object_ptr, &Class::Method) action. +template <class Class, typename MethodPtr> +struct InvokeMethodAction { + Class* const obj_ptr; + const MethodPtr method_ptr; + + template <typename... Args> + auto operator()(Args&&... args) const + -> decltype((obj_ptr->*method_ptr)(std::forward<Args>(args)...)) { + return (obj_ptr->*method_ptr)(std::forward<Args>(args)...); + } +}; + // Implements the InvokeWithoutArgs(f) action. The template argument // FunctionImpl is the implementation type of f, which can be either a // function pointer or a functor. InvokeWithoutArgs(f) can be used as an -// Action<F> as long as f's type is compatible with F (i.e. f can be -// assigned to a tr1::function<F>). +// Action<F> as long as f's type is compatible with F. template <typename FunctionImpl> -class InvokeWithoutArgsAction { - public: - // The c'tor makes a copy of function_impl (either a function - // pointer or a functor). - explicit InvokeWithoutArgsAction(FunctionImpl function_impl) - : function_impl_(function_impl) {} +struct InvokeWithoutArgsAction { + FunctionImpl function_impl; // Allows InvokeWithoutArgs(f) to be used as any action whose type is // compatible with f. - template <typename Result, typename ArgumentTuple> - Result Perform(const ArgumentTuple&) { return function_impl_(); } - - private: - FunctionImpl function_impl_; - - GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction); + template <typename... Args> + auto operator()(const Args&...) -> decltype(function_impl()) { + return function_impl(); + } }; // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action. template <class Class, typename MethodPtr> -class InvokeMethodWithoutArgsAction { - public: - InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr) - : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} +struct InvokeMethodWithoutArgsAction { + Class* const obj_ptr; + const MethodPtr method_ptr; - template <typename Result, typename ArgumentTuple> - Result Perform(const ArgumentTuple&) const { - return (obj_ptr_->*method_ptr_)(); - } + using ReturnType = typename std::result_of<MethodPtr(Class*)>::type; - private: - Class* const obj_ptr_; - const MethodPtr method_ptr_; - - 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. + template <typename... Args> + ReturnType operator()(const Args&...) const { + return (obj_ptr->*method_ptr)(); } - - // 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 std::shared_ptr<CallbackType> callback_; - - GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction); }; // Implements the IgnoreResult(action) action. @@ -968,7 +893,7 @@ class IgnoreResultAction { explicit Impl(const A& action) : action_(action) {} - virtual void Perform(const ArgumentTuple& args) { + void Perform(const ArgumentTuple& args) override { // Performs the action and ignores its result. action_.Perform(args); } @@ -989,76 +914,51 @@ class IgnoreResultAction { GTEST_DISALLOW_ASSIGN_(IgnoreResultAction); }; -// A ReferenceWrapper<T> object represents a reference to type T, -// which can be either const or not. It can be explicitly converted -// from, and implicitly converted to, a T&. Unlike a reference, -// ReferenceWrapper<T> can be copied and can survive template type -// inference. This is used to support by-reference arguments in the -// InvokeArgument<N>(...) action. The idea was from "reference -// wrappers" in tr1, which we don't have in our source tree yet. -template <typename T> -class ReferenceWrapper { - public: - // Constructs a ReferenceWrapper<T> object from a T&. - explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT - - // Allows a ReferenceWrapper<T> object to be implicitly converted to - // a T&. - operator T&() const { return *pointer_; } - private: - T* pointer_; +template <typename InnerAction, size_t... I> +struct WithArgsAction { + InnerAction action; + + // The inner action could be anything convertible to Action<X>. + // We use the conversion operator to detect the signature of the inner Action. + template <typename R, typename... Args> + operator Action<R(Args...)>() const { // NOLINT + Action<R(typename std::tuple_element<I, std::tuple<Args...>>::type...)> + converted(action); + + return [converted](Args... args) -> R { + return converted.Perform(std::forward_as_tuple( + std::get<I>(std::forward_as_tuple(std::forward<Args>(args)...))...)); + }; + } }; -// Allows the expression ByRef(x) to be printed as a reference to x. -template <typename T> -void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) { - T& value = ref; - UniversalPrinter<T&>::Print(value, os); -} +template <typename... Actions> +struct DoAllAction { + private: + template <typename... Args, size_t... I> + std::vector<Action<void(Args...)>> Convert(IndexSequence<I...>) const { + return {std::get<I>(actions)...}; + } -// Does two actions sequentially. Used for implementing the DoAll(a1, -// a2, ...) action. -template <typename Action1, typename Action2> -class DoBothAction { public: - DoBothAction(Action1 action1, Action2 action2) - : action1_(action1), action2_(action2) {} - - // This template type conversion operator allows DoAll(a1, ..., a_n) - // to be used in ANY function of compatible type. - template <typename F> - operator Action<F>() const { - return Action<F>(new Impl<F>(action1_, action2_)); + std::tuple<Actions...> actions; + + template <typename R, typename... Args> + operator Action<R(Args...)>() const { // NOLINT + struct Op { + std::vector<Action<void(Args...)>> converted; + Action<R(Args...)> last; + R operator()(Args... args) const { + auto tuple_args = std::forward_as_tuple(std::forward<Args>(args)...); + for (auto& a : converted) { + a.Perform(tuple_args); + } + return last.Perform(tuple_args); + } + }; + return Op{Convert<Args...>(MakeIndexSequence<sizeof...(Actions) - 1>()), + std::get<sizeof...(Actions) - 1>(actions)}; } - - private: - // Implements the DoAll(...) action for a particular function type F. - template <typename F> - class Impl : public ActionInterface<F> { - public: - typedef typename Function<F>::Result Result; - typedef typename Function<F>::ArgumentTuple ArgumentTuple; - typedef typename Function<F>::MakeResultVoid VoidResult; - - Impl(const Action<VoidResult>& action1, const Action<F>& action2) - : action1_(action1), action2_(action2) {} - - virtual Result Perform(const ArgumentTuple& args) { - action1_.Perform(args); - return action2_.Perform(args); - } - - private: - const Action<VoidResult> action1_; - const Action<F> action2_; - - GTEST_DISALLOW_ASSIGN_(Impl); - }; - - Action1 action1_; - Action2 action2_; - - GTEST_DISALLOW_ASSIGN_(DoBothAction); }; } // namespace internal @@ -1095,20 +995,43 @@ class DoBothAction { // EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin)); typedef internal::IgnoredValue Unused; -// This constructor allows us to turn an Action<From> object into an -// Action<To>, as long as To's arguments can be implicitly converted -// to From's and From's return type cann be implicitly converted to -// To's. -template <typename To> -template <typename From> -Action<To>::Action(const Action<From>& from) - : -#if GTEST_LANG_CXX11 - fun_(from.fun_), -#endif - impl_(from.impl_ == nullptr - ? nullptr - : new internal::ActionAdaptor<To, From>(from)) { +// Creates an action that does actions a1, a2, ..., sequentially in +// each invocation. +template <typename... Action> +internal::DoAllAction<typename std::decay<Action>::type...> DoAll( + Action&&... action) { + return {std::forward_as_tuple(std::forward<Action>(action)...)}; +} + +// WithArg<k>(an_action) creates an action that passes the k-th +// (0-based) argument of the mock function to an_action and performs +// it. It adapts an action accepting one argument to one that accepts +// multiple arguments. For convenience, we also provide +// WithArgs<k>(an_action) (defined below) as a synonym. +template <size_t k, typename InnerAction> +internal::WithArgsAction<typename std::decay<InnerAction>::type, k> +WithArg(InnerAction&& action) { + return {std::forward<InnerAction>(action)}; +} + +// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes +// the selected arguments of the mock function to an_action and +// performs it. It serves as an adaptor between actions with +// different argument lists. +template <size_t k, size_t... ks, typename InnerAction> +internal::WithArgsAction<typename std::decay<InnerAction>::type, k, ks...> +WithArgs(InnerAction&& action) { + return {std::forward<InnerAction>(action)}; +} + +// WithoutArgs(inner_action) can be used in a mock function with a +// non-empty argument list to perform inner_action, which takes no +// argument. In other words, it adapts an action accepting no +// argument to one that accepts (and ignores) arguments. +template <typename InnerAction> +internal::WithArgsAction<typename std::decay<InnerAction>::type> +WithoutArgs(InnerAction&& action) { + return {std::forward<InnerAction>(action)}; } // Creates an action that returns 'value'. 'value' is passed by value @@ -1168,10 +1091,6 @@ SetArgPointee(const T& x) { N, T, internal::IsAProtocolMessage<T>::value>(x)); } -#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) -// This overload allows SetArgPointee() to accept a string literal. -// GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish -// this overload from the templated version and emit a compile error. template <size_t N> PolymorphicAction< internal::SetArgumentPointeeAction<N, const char*, false> > @@ -1187,7 +1106,6 @@ SetArgPointee(const wchar_t* p) { return MakePolymorphicAction(internal::SetArgumentPointeeAction< N, const wchar_t*, false>(p)); } -#endif // The following version is DEPRECATED. template <size_t N, typename T> @@ -1217,24 +1135,38 @@ SetErrnoAndReturn(int errval, T result) { #endif // !GTEST_OS_WINDOWS_MOBILE -// Various overloads for InvokeWithoutArgs(). +// Various overloads for Invoke(). + +// Legacy function. +// Actions can now be implicitly constructed from callables. No need to create +// wrapper objects. +// This function exists for backwards compatibility. +template <typename FunctionImpl> +typename std::decay<FunctionImpl>::type Invoke(FunctionImpl&& function_impl) { + return std::forward<FunctionImpl>(function_impl); +} + +// Creates an action that invokes the given method on the given object +// with the mock function's arguments. +template <class Class, typename MethodPtr> +internal::InvokeMethodAction<Class, MethodPtr> Invoke(Class* obj_ptr, + MethodPtr method_ptr) { + return {obj_ptr, method_ptr}; +} // Creates an action that invokes 'function_impl' with no argument. template <typename FunctionImpl> -PolymorphicAction<internal::InvokeWithoutArgsAction<FunctionImpl> > +internal::InvokeWithoutArgsAction<typename std::decay<FunctionImpl>::type> InvokeWithoutArgs(FunctionImpl function_impl) { - return MakePolymorphicAction( - internal::InvokeWithoutArgsAction<FunctionImpl>(function_impl)); + return {std::move(function_impl)}; } // Creates an action that invokes the given method on the given object // with no argument. template <class Class, typename MethodPtr> -PolymorphicAction<internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> > -InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) { - return MakePolymorphicAction( - internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>( - obj_ptr, method_ptr)); +internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> InvokeWithoutArgs( + Class* obj_ptr, MethodPtr method_ptr) { + return {obj_ptr, method_ptr}; } // Creates an action that performs an_action and throws away its @@ -1252,11 +1184,19 @@ inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) { // where Base is a base class of Derived, just write: // // ByRef<const Base>(derived) +// +// N.B. ByRef is redundant with std::ref, std::cref and std::reference_wrapper. +// However, it may still be used for consistency with ByMove(). template <typename T> -inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT - return internal::ReferenceWrapper<T>(l_value); +inline ::std::reference_wrapper<T> ByRef(T& l_value) { // NOLINT + return ::std::reference_wrapper<T>(l_value); } } // namespace testing +#ifdef _MSC_VER +# pragma warning(pop) +#endif + + #endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-function-mocker.h b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-function-mocker.h new file mode 100644 index 00000000000..3d142049f98 --- /dev/null +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-function-mocker.h @@ -0,0 +1,218 @@ +#ifndef THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT +#define THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT + +#include "gmock/gmock-generated-function-mockers.h" // NOLINT +#include "gmock/internal/gmock-pp.h" + +#define MOCK_METHOD(...) \ + GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__) + +#define GMOCK_INTERNAL_MOCK_METHOD_ARG_1(...) \ + GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) + +#define GMOCK_INTERNAL_MOCK_METHOD_ARG_2(...) \ + GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) + +#define GMOCK_INTERNAL_MOCK_METHOD_ARG_3(_Ret, _MethodName, _Args) \ + GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ()) + +#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \ + GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \ + GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \ + GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ + GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \ + GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec); \ + GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ + GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \ + GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \ + GMOCK_INTERNAL_HAS_NOEXCEPT(_Spec), GMOCK_INTERNAL_GET_CALLTYPE(_Spec), \ + (GMOCK_INTERNAL_SIGNATURE(_Ret, _Args))) + +#define GMOCK_INTERNAL_MOCK_METHOD_ARG_5(...) \ + GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) + +#define GMOCK_INTERNAL_MOCK_METHOD_ARG_6(...) \ + GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) + +#define GMOCK_INTERNAL_MOCK_METHOD_ARG_7(...) \ + GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) + +#define GMOCK_INTERNAL_WRONG_ARITY(...) \ + static_assert( \ + false, \ + "MOCK_METHOD must be called with 3 or 4 arguments. _Ret, " \ + "_MethodName, _Args and optionally _Spec. _Args and _Spec must be " \ + "enclosed in parentheses. If _Ret is a type with unprotected commas, " \ + "it must also be enclosed in parentheses.") + +#define GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Tuple) \ + static_assert( \ + GMOCK_PP_IS_ENCLOSED_PARENS(_Tuple), \ + GMOCK_PP_STRINGIZE(_Tuple) " should be enclosed in parentheses.") + +#define GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE(_N, ...) \ + static_assert( \ + std::is_function<__VA_ARGS__>::value, \ + "Signature must be a function type, maybe return type contains " \ + "unprotected comma."); \ + static_assert( \ + ::testing::tuple_size<typename ::testing::internal::Function< \ + __VA_ARGS__>::ArgumentTuple>::value == _N, \ + "This method does not take " GMOCK_PP_STRINGIZE( \ + _N) " arguments. Parenthesize all types with unproctected commas.") + +#define GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ + GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT, ~, _Spec) + +#define GMOCK_INTERNAL_MOCK_METHOD_IMPL(_N, _MethodName, _Constness, \ + _Override, _Final, _Noexcept, \ + _CallType, _Signature) \ + typename ::testing::internal::Function<GMOCK_PP_REMOVE_PARENS( \ + _Signature)>::Result \ + GMOCK_INTERNAL_EXPAND(_CallType) \ + _MethodName(GMOCK_PP_REPEAT(GMOCK_INTERNAL_PARAMETER, _Signature, _N)) \ + GMOCK_PP_IF(_Constness, const, ) GMOCK_PP_IF(_Noexcept, noexcept, ) \ + GMOCK_PP_IF(_Override, override, ) \ + GMOCK_PP_IF(_Final, final, ) { \ + GMOCK_MOCKER_(_N, _Constness, _MethodName) \ + .SetOwnerAndName(this, #_MethodName); \ + return GMOCK_MOCKER_(_N, _Constness, _MethodName) \ + .Invoke(GMOCK_PP_REPEAT(GMOCK_INTERNAL_FORWARD_ARG, _Signature, _N)); \ + } \ + ::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \ + GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_PARAMETER, _Signature, _N)) \ + GMOCK_PP_IF(_Constness, const, ) { \ + GMOCK_MOCKER_(_N, _Constness, _MethodName).RegisterOwner(this); \ + return GMOCK_MOCKER_(_N, _Constness, _MethodName) \ + .With(GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_ARGUMENT, , _N)); \ + } \ + ::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \ + const ::testing::internal::WithoutMatchers&, \ + GMOCK_PP_IF(_Constness, const, )::testing::internal::Function< \ + GMOCK_PP_REMOVE_PARENS(_Signature)>*) \ + const GMOCK_PP_IF(_Noexcept, noexcept, ) { \ + return GMOCK_PP_CAT(::testing::internal::AdjustConstness_, \ + GMOCK_PP_IF(_Constness, const, ))(this) \ + ->gmock_##_MethodName(GMOCK_PP_REPEAT( \ + GMOCK_INTERNAL_A_MATCHER_ARGUMENT, _Signature, _N)); \ + } \ + mutable ::testing::FunctionMocker<GMOCK_PP_REMOVE_PARENS(_Signature)> \ + GMOCK_MOCKER_(_N, _Constness, _MethodName) + +#define GMOCK_INTERNAL_EXPAND(...) __VA_ARGS__ + +// Five Valid modifiers. +#define GMOCK_INTERNAL_HAS_CONST(_Tuple) \ + GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple)) + +#define GMOCK_INTERNAL_HAS_OVERRIDE(_Tuple) \ + GMOCK_PP_HAS_COMMA( \ + GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_OVERRIDE, ~, _Tuple)) + +#define GMOCK_INTERNAL_HAS_FINAL(_Tuple) \ + GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_FINAL, ~, _Tuple)) + +#define GMOCK_INTERNAL_HAS_NOEXCEPT(_Tuple) \ + GMOCK_PP_HAS_COMMA( \ + GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_NOEXCEPT, ~, _Tuple)) + +#define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \ + GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple) + +#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \ + static_assert( \ + (GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \ + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \ + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \ + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \ + GMOCK_INTERNAL_IS_CALLTYPE(_elem)) == 1, \ + GMOCK_PP_STRINGIZE( \ + _elem) " cannot be recognized as a valid specification modifier."); + +// Modifiers implementation. +#define GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem) \ + GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CONST_I_, _elem) + +#define GMOCK_INTERNAL_DETECT_CONST_I_const , + +#define GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem) \ + GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_OVERRIDE_I_, _elem) + +#define GMOCK_INTERNAL_DETECT_OVERRIDE_I_override , + +#define GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem) \ + GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_FINAL_I_, _elem) + +#define GMOCK_INTERNAL_DETECT_FINAL_I_final , + +// TODO(iserna): Maybe noexcept should accept an argument here as well. +#define GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem) \ + GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_NOEXCEPT_I_, _elem) + +#define GMOCK_INTERNAL_DETECT_NOEXCEPT_I_noexcept , + +#define GMOCK_INTERNAL_GET_CALLTYPE_IMPL(_i, _, _elem) \ + GMOCK_PP_IF(GMOCK_INTERNAL_IS_CALLTYPE(_elem), \ + GMOCK_INTERNAL_GET_VALUE_CALLTYPE, GMOCK_PP_EMPTY) \ + (_elem) + +// TODO(iserna): GMOCK_INTERNAL_IS_CALLTYPE and +// GMOCK_INTERNAL_GET_VALUE_CALLTYPE needed more expansions to work on windows +// maybe they can be simplified somehow. +#define GMOCK_INTERNAL_IS_CALLTYPE(_arg) \ + GMOCK_INTERNAL_IS_CALLTYPE_I( \ + GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) +#define GMOCK_INTERNAL_IS_CALLTYPE_I(_arg) GMOCK_PP_IS_ENCLOSED_PARENS(_arg) + +#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE(_arg) \ + GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I( \ + GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) +#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I(_arg) \ + GMOCK_PP_CAT(GMOCK_PP_IDENTITY, _arg) + +#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype + +#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \ + GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), GMOCK_PP_REMOVE_PARENS, \ + GMOCK_PP_IDENTITY) \ + (_Ret)(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args)) + +#define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \ + GMOCK_PP_COMMA_IF(_i) \ + GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_elem), GMOCK_PP_REMOVE_PARENS, \ + GMOCK_PP_IDENTITY) \ + (_elem) + +#define GMOCK_INTERNAL_PARAMETER(_i, _Signature, _) \ + GMOCK_PP_COMMA_IF(_i) \ + GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \ + GMOCK_PP_REMOVE_PARENS(_Signature)) \ + gmock_a##_i + +#define GMOCK_INTERNAL_FORWARD_ARG(_i, _Signature, _) \ + GMOCK_PP_COMMA_IF(_i) \ + ::std::forward<GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \ + GMOCK_PP_REMOVE_PARENS(_Signature))>( \ + gmock_a##_i) + +#define GMOCK_INTERNAL_MATCHER_PARAMETER(_i, _Signature, _) \ + GMOCK_PP_COMMA_IF(_i) \ + GMOCK_INTERNAL_MATCHER_O(typename, GMOCK_PP_INC(_i), \ + GMOCK_PP_REMOVE_PARENS(_Signature)) \ + gmock_a##_i + +#define GMOCK_INTERNAL_MATCHER_ARGUMENT(_i, _1, _2) \ + GMOCK_PP_COMMA_IF(_i) \ + gmock_a##_i + +#define GMOCK_INTERNAL_A_MATCHER_ARGUMENT(_i, _Signature, _) \ + GMOCK_PP_COMMA_IF(_i) \ + ::testing::A<GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \ + GMOCK_PP_REMOVE_PARENS(_Signature))>() + +#define GMOCK_INTERNAL_ARG_O(_tn, _i, ...) GMOCK_ARG_(_tn, _i, __VA_ARGS__) + +#define GMOCK_INTERNAL_MATCHER_O(_tn, _i, ...) \ + GMOCK_MATCHER_(_tn, _i, __VA_ARGS__) + +#endif // THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-actions.h b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-actions.h index 8966f05cb2b..3264bca6a41 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-actions.h +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-actions.h @@ -50,537 +50,6 @@ namespace testing { namespace internal { -// InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary -// 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; - -template <typename R> -class InvokeHelper<R, ::std::tuple<> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<>&) { - return function(); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<>&) { - return (obj_ptr->*method_ptr)(); - } - - template <typename CallbackType> - static R InvokeCallback(CallbackType* callback, - const ::std::tuple<>&) { - return callback->Run(); - } -}; - -template <typename R, typename A1> -class InvokeHelper<R, ::std::tuple<A1> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<A1>& args) { - return function(std::get<0>(args)); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<A1>& args) { - return (obj_ptr->*method_ptr)(std::get<0>(args)); - } - - template <typename CallbackType> - static R InvokeCallback(CallbackType* callback, - const ::std::tuple<A1>& args) { - return callback->Run(std::get<0>(args)); - } -}; - -template <typename R, typename A1, typename A2> -class InvokeHelper<R, ::std::tuple<A1, A2> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<A1, A2>& args) { - return function(std::get<0>(args), std::get<1>(args)); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<A1, A2>& args) { - return (obj_ptr->*method_ptr)(std::get<0>(args), std::get<1>(args)); - } - - template <typename CallbackType> - static R InvokeCallback(CallbackType* callback, - const ::std::tuple<A1, A2>& args) { - return callback->Run(std::get<0>(args), std::get<1>(args)); - } -}; - -template <typename R, typename A1, typename A2, typename A3> -class InvokeHelper<R, ::std::tuple<A1, A2, A3> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<A1, A2, A3>& args) { - return function(std::get<0>(args), std::get<1>(args), - std::get<2>(args)); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<A1, A2, A3>& args) { - return (obj_ptr->*method_ptr)(std::get<0>(args), std::get<1>(args), - std::get<2>(args)); - } - - template <typename CallbackType> - static R InvokeCallback(CallbackType* callback, - const ::std::tuple<A1, A2, A3>& args) { - return callback->Run(std::get<0>(args), std::get<1>(args), - std::get<2>(args)); - } -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4> -class InvokeHelper<R, ::std::tuple<A1, A2, A3, A4> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<A1, A2, A3, A4>& args) { - return function(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args)); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<A1, A2, A3, A4>& args) { - return (obj_ptr->*method_ptr)(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args)); - } - - template <typename CallbackType> - static R InvokeCallback(CallbackType* callback, - const ::std::tuple<A1, A2, A3, A4>& args) { - return callback->Run(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args)); - } -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5> -class InvokeHelper<R, ::std::tuple<A1, A2, A3, A4, A5> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<A1, A2, A3, A4, - A5>& args) { - return function(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args)); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<A1, A2, A3, A4, A5>& args) { - return (obj_ptr->*method_ptr)(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args)); - } - - template <typename CallbackType> - static R InvokeCallback(CallbackType* callback, - const ::std::tuple<A1, A2, A3, A4, A5>& args) { - return callback->Run(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args)); - } -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6> -class InvokeHelper<R, ::std::tuple<A1, A2, A3, A4, A5, A6> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<A1, A2, A3, A4, A5, - A6>& args) { - return function(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args), - std::get<5>(args)); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<A1, A2, A3, A4, A5, A6>& args) { - return (obj_ptr->*method_ptr)(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args), - std::get<5>(args)); - } - - // There is no InvokeCallback() for 6-tuples -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7> -class InvokeHelper<R, ::std::tuple<A1, A2, A3, A4, A5, A6, A7> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<A1, A2, A3, A4, A5, A6, - A7>& args) { - return function(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args), - std::get<5>(args), std::get<6>(args)); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<A1, A2, A3, A4, A5, A6, A7>& args) { - return (obj_ptr->*method_ptr)(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args), - std::get<5>(args), std::get<6>(args)); - } - - // There is no InvokeCallback() for 7-tuples -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7, typename A8> -class InvokeHelper<R, ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<A1, A2, A3, A4, A5, A6, - A7, A8>& args) { - return function(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args), - std::get<5>(args), std::get<6>(args), std::get<7>(args)); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<A1, A2, A3, A4, A5, A6, A7, - A8>& args) { - return (obj_ptr->*method_ptr)(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args), - std::get<5>(args), std::get<6>(args), std::get<7>(args)); - } - - // There is no InvokeCallback() for 8-tuples -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7, typename A8, typename A9> -class InvokeHelper<R, ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<A1, A2, A3, A4, A5, A6, - A7, A8, A9>& args) { - return function(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args), - std::get<5>(args), std::get<6>(args), std::get<7>(args), - std::get<8>(args)); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, - A9>& args) { - return (obj_ptr->*method_ptr)(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args), - std::get<5>(args), std::get<6>(args), std::get<7>(args), - std::get<8>(args)); - } - - // There is no InvokeCallback() for 9-tuples -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7, typename A8, typename A9, - typename A10> -class InvokeHelper<R, ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<A1, A2, A3, A4, A5, A6, - A7, A8, A9, A10>& args) { - return function(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args), - std::get<5>(args), std::get<6>(args), std::get<7>(args), - std::get<8>(args), std::get<9>(args)); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10>& args) { - return (obj_ptr->*method_ptr)(std::get<0>(args), std::get<1>(args), - std::get<2>(args), std::get<3>(args), std::get<4>(args), - std::get<5>(args), std::get<6>(args), std::get<7>(args), - std::get<8>(args), std::get<9>(args)); - } - - // There is no InvokeCallback() for 10-tuples -}; - -// 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 std::shared_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) \ - typename ::std::tuple_element<N, Tuple>::type - -// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the -// type of an n-ary function whose i-th (1-based) argument type is the -// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple -// type, and whose return type is Result. For example, -// SelectArgs<int, ::std::tuple<bool, char, double, long>, 0, 3>::type -// is int(bool, long). -// -// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args) -// returns the selected fields (k1, k2, ..., k_n) of args as a tuple. -// For example, -// SelectArgs<int, std::tuple<bool, char, double>, 2, 0>::Select( -// ::std::make_tuple(true, 'a', 2.5)) -// returns tuple (2.5, true). -// -// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be -// in the range [0, 10]. Duplicates are allowed and they don't have -// to be in an ascending or descending order. - -template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, - int k4, int k5, int k6, int k7, int k8, int k9, int k10> -class SelectArgs { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), - GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), - GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9), - GMOCK_FIELD_(ArgumentTuple, k10)); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - return SelectedArgs(std::get<k1>(args), std::get<k2>(args), - std::get<k3>(args), std::get<k4>(args), std::get<k5>(args), - std::get<k6>(args), std::get<k7>(args), std::get<k8>(args), - std::get<k9>(args), std::get<k10>(args)); - } -}; - -template <typename Result, typename ArgumentTuple> -class SelectArgs<Result, ArgumentTuple, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { - public: - typedef Result type(); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& /* args */) { - return SelectedArgs(); - } -}; - -template <typename Result, typename ArgumentTuple, int k1> -class SelectArgs<Result, ArgumentTuple, - k1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1)); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - return SelectedArgs(std::get<k1>(args)); - } -}; - -template <typename Result, typename ArgumentTuple, int k1, int k2> -class SelectArgs<Result, ArgumentTuple, - k1, k2, -1, -1, -1, -1, -1, -1, -1, -1> { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2)); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - return SelectedArgs(std::get<k1>(args), std::get<k2>(args)); - } -}; - -template <typename Result, typename ArgumentTuple, int k1, int k2, int k3> -class SelectArgs<Result, ArgumentTuple, - k1, k2, k3, -1, -1, -1, -1, -1, -1, -1> { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3)); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - return SelectedArgs(std::get<k1>(args), std::get<k2>(args), - std::get<k3>(args)); - } -}; - -template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, - int k4> -class SelectArgs<Result, ArgumentTuple, - k1, k2, k3, k4, -1, -1, -1, -1, -1, -1> { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4)); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - return SelectedArgs(std::get<k1>(args), std::get<k2>(args), - std::get<k3>(args), std::get<k4>(args)); - } -}; - -template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, - int k4, int k5> -class SelectArgs<Result, ArgumentTuple, - k1, k2, k3, k4, k5, -1, -1, -1, -1, -1> { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5)); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - return SelectedArgs(std::get<k1>(args), std::get<k2>(args), - std::get<k3>(args), std::get<k4>(args), std::get<k5>(args)); - } -}; - -template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, - int k4, int k5, int k6> -class SelectArgs<Result, ArgumentTuple, - k1, k2, k3, k4, k5, k6, -1, -1, -1, -1> { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), - GMOCK_FIELD_(ArgumentTuple, k6)); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - return SelectedArgs(std::get<k1>(args), std::get<k2>(args), - std::get<k3>(args), std::get<k4>(args), std::get<k5>(args), - std::get<k6>(args)); - } -}; - -template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, - int k4, int k5, int k6, int k7> -class SelectArgs<Result, ArgumentTuple, - k1, k2, k3, k4, k5, k6, k7, -1, -1, -1> { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), - GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7)); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - return SelectedArgs(std::get<k1>(args), std::get<k2>(args), - std::get<k3>(args), std::get<k4>(args), std::get<k5>(args), - std::get<k6>(args), std::get<k7>(args)); - } -}; - -template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, - int k4, int k5, int k6, int k7, int k8> -class SelectArgs<Result, ArgumentTuple, - k1, k2, k3, k4, k5, k6, k7, k8, -1, -1> { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), - GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), - GMOCK_FIELD_(ArgumentTuple, k8)); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - return SelectedArgs(std::get<k1>(args), std::get<k2>(args), - std::get<k3>(args), std::get<k4>(args), std::get<k5>(args), - std::get<k6>(args), std::get<k7>(args), std::get<k8>(args)); - } -}; - -template <typename Result, typename ArgumentTuple, int k1, int k2, int k3, - int k4, int k5, int k6, int k7, int k8, int k9> -class SelectArgs<Result, ArgumentTuple, - k1, k2, k3, k4, k5, k6, k7, k8, k9, -1> { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), - GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), - GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9)); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - return SelectedArgs(std::get<k1>(args), std::get<k2>(args), - std::get<k3>(args), std::get<k4>(args), std::get<k5>(args), - std::get<k6>(args), std::get<k7>(args), std::get<k8>(args), - std::get<k9>(args)); - } -}; - -#undef GMOCK_FIELD_ - -// Implements the WithArgs action. -template <typename InnerAction, int k1 = -1, int k2 = -1, int k3 = -1, - int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1, - int k9 = -1, int k10 = -1> -class WithArgsAction { - public: - explicit WithArgsAction(const InnerAction& action) : action_(action) {} - - template <typename F> - operator Action<F>() const { return MakeAction(new Impl<F>(action_)); } - - private: - template <typename F> - class Impl : public ActionInterface<F> { - public: - typedef typename Function<F>::Result Result; - typedef typename Function<F>::ArgumentTuple ArgumentTuple; - - explicit Impl(const InnerAction& action) : action_(action) {} - - virtual Result Perform(const ArgumentTuple& args) { - return action_.Perform(SelectArgs<Result, ArgumentTuple, k1, k2, k3, k4, - k5, k6, k7, k8, k9, k10>::Select(args)); - } - - private: - typedef typename SelectArgs<Result, ArgumentTuple, - k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType; - - Action<InnerFunctionType> action_; - }; - - const InnerAction action_; - - GTEST_DISALLOW_ASSIGN_(WithArgsAction); -}; - // A macro from the ACTION* family (defined later in this file) // defines an action that can be used in a mock function. Typically, // these actions only care about a subset of the arguments of the mock @@ -703,173 +172,6 @@ class ActionHelper { }; } // namespace internal - -// Various overloads for Invoke(). - -// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes -// the selected arguments of the mock function to an_action and -// performs it. It serves as an adaptor between actions with -// different argument lists. C++ doesn't support default arguments for -// function templates, so we have to overload it. -template <int k1, typename InnerAction> -inline internal::WithArgsAction<InnerAction, k1> -WithArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction, k1>(action); -} - -template <int k1, int k2, typename InnerAction> -inline internal::WithArgsAction<InnerAction, k1, k2> -WithArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction, k1, k2>(action); -} - -template <int k1, int k2, int k3, typename InnerAction> -inline internal::WithArgsAction<InnerAction, k1, k2, k3> -WithArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction, k1, k2, k3>(action); -} - -template <int k1, int k2, int k3, int k4, typename InnerAction> -inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4> -WithArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction, k1, k2, k3, k4>(action); -} - -template <int k1, int k2, int k3, int k4, int k5, typename InnerAction> -inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5> -WithArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5>(action); -} - -template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerAction> -inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6> -WithArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6>(action); -} - -template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, - typename InnerAction> -inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7> -WithArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, - k7>(action); -} - -template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, - typename InnerAction> -inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8> -WithArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, - k8>(action); -} - -template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, - int k9, typename InnerAction> -inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, k9> -WithArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, - k9>(action); -} - -template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, - int k9, int k10, typename InnerAction> -inline internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, - k9, k10> -WithArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction, k1, k2, k3, k4, k5, k6, k7, k8, - k9, k10>(action); -} - -// Creates an action that does actions a1, a2, ..., sequentially in -// each invocation. -template <typename Action1, typename Action2> -inline internal::DoBothAction<Action1, Action2> -DoAll(Action1 a1, Action2 a2) { - return internal::DoBothAction<Action1, Action2>(a1, a2); -} - -template <typename Action1, typename Action2, typename Action3> -inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, - Action3> > -DoAll(Action1 a1, Action2 a2, Action3 a3) { - return DoAll(a1, DoAll(a2, a3)); -} - -template <typename Action1, typename Action2, typename Action3, - typename Action4> -inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, - internal::DoBothAction<Action3, Action4> > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) { - return DoAll(a1, DoAll(a2, a3, a4)); -} - -template <typename Action1, typename Action2, typename Action3, - typename Action4, typename Action5> -inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, - internal::DoBothAction<Action3, internal::DoBothAction<Action4, - Action5> > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) { - return DoAll(a1, DoAll(a2, a3, a4, a5)); -} - -template <typename Action1, typename Action2, typename Action3, - typename Action4, typename Action5, typename Action6> -inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, - internal::DoBothAction<Action3, internal::DoBothAction<Action4, - internal::DoBothAction<Action5, Action6> > > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) { - return DoAll(a1, DoAll(a2, a3, a4, a5, a6)); -} - -template <typename Action1, typename Action2, typename Action3, - typename Action4, typename Action5, typename Action6, typename Action7> -inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, - internal::DoBothAction<Action3, internal::DoBothAction<Action4, - internal::DoBothAction<Action5, internal::DoBothAction<Action6, - Action7> > > > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, - Action7 a7) { - return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7)); -} - -template <typename Action1, typename Action2, typename Action3, - typename Action4, typename Action5, typename Action6, typename Action7, - typename Action8> -inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, - internal::DoBothAction<Action3, internal::DoBothAction<Action4, - internal::DoBothAction<Action5, internal::DoBothAction<Action6, - internal::DoBothAction<Action7, Action8> > > > > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, - Action7 a7, Action8 a8) { - return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8)); -} - -template <typename Action1, typename Action2, typename Action3, - typename Action4, typename Action5, typename Action6, typename Action7, - typename Action8, typename Action9> -inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, - internal::DoBothAction<Action3, internal::DoBothAction<Action4, - internal::DoBothAction<Action5, internal::DoBothAction<Action6, - internal::DoBothAction<Action7, internal::DoBothAction<Action8, - Action9> > > > > > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, - Action7 a7, Action8 a8, Action9 a9) { - return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9)); -} - -template <typename Action1, typename Action2, typename Action3, - typename Action4, typename Action5, typename Action6, typename Action7, - typename Action8, typename Action9, typename Action10> -inline internal::DoBothAction<Action1, internal::DoBothAction<Action2, - internal::DoBothAction<Action3, internal::DoBothAction<Action4, - internal::DoBothAction<Action5, internal::DoBothAction<Action6, - internal::DoBothAction<Action7, internal::DoBothAction<Action8, - internal::DoBothAction<Action9, Action10> > > > > > > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, - Action7 a7, Action8 a8, Action9 a9, Action10 a10) { - return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10)); -} - } // namespace testing // The ACTION* family of macros can be used in a namespace scope to diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-actions.h.pump b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-actions.h.pump index 09a39ca8562..1e9549f332f 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-actions.h.pump +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-actions.h.pump @@ -52,167 +52,6 @@ $$}} This meta comment fixes auto-indentation in editors. namespace testing { namespace internal { -// InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary -// 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 -$var types = [[$for j [[, typename A$j]]]] -$var as = [[$for j, [[A$j]]]] -$var args = [[$if i==0 [[]] $else [[ args]]]] -$var gets = [[$for j, [[std::get<$(j - 1)>(args)]]]] -template <typename R$types> -class InvokeHelper<R, ::std::tuple<$as> > { - public: - template <typename Function> - static R Invoke(Function function, const ::std::tuple<$as>&$args) { - return function($gets); - } - - template <class Class, typename MethodPtr> - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tuple<$as>&$args) { - return (obj_ptr->*method_ptr)($gets); - } - - -$if i <= max_callback_arity [[ - template <typename CallbackType> - static R InvokeCallback(CallbackType* callback, - const ::std::tuple<$as>&$args) { - return callback->Run($gets); - } -]] $else [[ - // There is no InvokeCallback() for $i-tuples -]] - -}; - - -]] -// 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 std::shared_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) \ - typename ::std::tuple_element<N, Tuple>::type - -$range i 1..n - -// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the -// type of an n-ary function whose i-th (1-based) argument type is the -// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple -// type, and whose return type is Result. For example, -// SelectArgs<int, ::std::tuple<bool, char, double, long>, 0, 3>::type -// is int(bool, long). -// -// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args) -// returns the selected fields (k1, k2, ..., k_n) of args as a tuple. -// For example, -// SelectArgs<int, std::tuple<bool, char, double>, 2, 0>::Select( -// ::std::make_tuple(true, 'a', 2.5)) -// returns tuple (2.5, true). -// -// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be -// in the range [0, $n]. Duplicates are allowed and they don't have -// to be in an ascending or descending order. - -template <typename Result, typename ArgumentTuple, $for i, [[int k$i]]> -class SelectArgs { - public: - typedef Result type($for i, [[GMOCK_FIELD_(ArgumentTuple, k$i)]]); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - return SelectedArgs($for i, [[std::get<k$i>(args)]]); - } -}; - - -$for i [[ -$range j 1..n -$range j1 1..i-1 -template <typename Result, typename ArgumentTuple$for j1[[, int k$j1]]> -class SelectArgs<Result, ArgumentTuple, - $for j, [[$if j <= i-1 [[k$j]] $else [[-1]]]]> { - public: - typedef Result type($for j1, [[GMOCK_FIELD_(ArgumentTuple, k$j1)]]); - typedef typename Function<type>::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& [[]] -$if i == 1 [[/* args */]] $else [[args]]) { - return SelectedArgs($for j1, [[std::get<k$j1>(args)]]); - } -}; - - -]] -#undef GMOCK_FIELD_ - -$var ks = [[$for i, [[k$i]]]] - -// Implements the WithArgs action. -template <typename InnerAction, $for i, [[int k$i = -1]]> -class WithArgsAction { - public: - explicit WithArgsAction(const InnerAction& action) : action_(action) {} - - template <typename F> - operator Action<F>() const { return MakeAction(new Impl<F>(action_)); } - - private: - template <typename F> - class Impl : public ActionInterface<F> { - public: - typedef typename Function<F>::Result Result; - typedef typename Function<F>::ArgumentTuple ArgumentTuple; - - explicit Impl(const InnerAction& action) : action_(action) {} - - virtual Result Perform(const ArgumentTuple& args) { - return action_.Perform(SelectArgs<Result, ArgumentTuple, $ks>::Select(args)); - } - - private: - typedef typename SelectArgs<Result, ArgumentTuple, - $ks>::type InnerFunctionType; - - Action<InnerFunctionType> action_; - }; - - const InnerAction action_; - - GTEST_DISALLOW_ASSIGN_(WithArgsAction); -}; - // A macro from the ACTION* family (defined later in this file) // defines an action that can be used in a mock function. Typically, // these actions only care about a subset of the arguments of the mock @@ -256,53 +95,6 @@ $template }; } // namespace internal - -// Various overloads for Invoke(). - -// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes -// the selected arguments of the mock function to an_action and -// performs it. It serves as an adaptor between actions with -// different argument lists. C++ doesn't support default arguments for -// function templates, so we have to overload it. - -$range i 1..n -$for i [[ -$range j 1..i -template <$for j [[int k$j, ]]typename InnerAction> -inline internal::WithArgsAction<InnerAction$for j [[, k$j]]> -WithArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction$for j [[, k$j]]>(action); -} - - -]] -// Creates an action that does actions a1, a2, ..., sequentially in -// each invocation. -$range i 2..n -$for i [[ -$range j 2..i -$var types = [[$for j, [[typename Action$j]]]] -$var Aas = [[$for j [[, Action$j a$j]]]] - -template <typename Action1, $types> -$range k 1..i-1 - -inline $for k [[internal::DoBothAction<Action$k, ]]Action$i$for k [[>]] - -DoAll(Action1 a1$Aas) { -$if i==2 [[ - - return internal::DoBothAction<Action1, Action2>(a1, a2); -]] $else [[ -$range j2 2..i - - return DoAll(a1, DoAll($for j2, [[a$j2]])); -]] - -} - -]] - } // namespace testing // The ACTION* family of macros can be used in a namespace scope to diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-function-mockers.h b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-function-mockers.h index 38a7d15d30b..cd9578178c0 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-function-mockers.h +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-function-mockers.h @@ -41,292 +41,14 @@ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ +#include <functional> #include <utility> #include "gmock/gmock-spec-builders.h" #include "gmock/internal/gmock-internal-utils.h" -#if GTEST_HAS_STD_FUNCTION_ -# include <functional> -#endif - namespace testing { namespace internal { - -template <typename F> -class FunctionMockerBase; - -// Note: class FunctionMocker really belongs to the ::testing -// namespace. However if we define it in ::testing, MSVC will -// complain when classes in ::testing::internal declare it as a -// friend class template. To workaround this compiler bug, we define -// FunctionMocker in ::testing::internal and import it into ::testing. -template <typename F> -class FunctionMocker; - -template <typename R> -class FunctionMocker<R()> : public - internal::FunctionMockerBase<R()> { - public: - typedef R F(); - typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - - MockSpec<F> With() { - return MockSpec<F>(this, ::std::make_tuple()); - } - - R Invoke() { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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()); - } -}; - -template <typename R, typename A1> -class FunctionMocker<R(A1)> : public - internal::FunctionMockerBase<R(A1)> { - public: - typedef R F(A1); - typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - - MockSpec<F> With(const Matcher<A1>& m1) { - return MockSpec<F>(this, ::std::make_tuple(m1)); - } - - R Invoke(A1 a1) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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(std::forward<A1>(a1))); - } -}; - -template <typename R, typename A1, typename A2> -class FunctionMocker<R(A1, A2)> : public - internal::FunctionMockerBase<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) { - return MockSpec<F>(this, ::std::make_tuple(m1, m2)); - } - - R Invoke(A1 a1, A2 a2) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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(std::forward<A1>(a1), - std::forward<A2>(a2))); - } -}; - -template <typename R, typename A1, typename A2, typename A3> -class FunctionMocker<R(A1, A2, A3)> : public - internal::FunctionMockerBase<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, - const Matcher<A3>& m3) { - return MockSpec<F>(this, ::std::make_tuple(m1, m2, m3)); - } - - R Invoke(A1 a1, A2 a2, A3 a3) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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(std::forward<A1>(a1), - std::forward<A2>(a2), std::forward<A3>(a3))); - } -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4> -class FunctionMocker<R(A1, A2, A3, A4)> : public - internal::FunctionMockerBase<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, - const Matcher<A3>& m3, const Matcher<A4>& m4) { - return MockSpec<F>(this, ::std::make_tuple(m1, m2, m3, m4)); - } - - R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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(std::forward<A1>(a1), - std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4))); - } -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5> -class FunctionMocker<R(A1, A2, A3, A4, A5)> : public - internal::FunctionMockerBase<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, - const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) { - return MockSpec<F>(this, ::std::make_tuple(m1, m2, m3, m4, m5)); - } - - R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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(std::forward<A1>(a1), - std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), - std::forward<A5>(a5))); - } -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6> -class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public - internal::FunctionMockerBase<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, - const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, - const Matcher<A6>& m6) { - return MockSpec<F>(this, ::std::make_tuple(m1, m2, m3, m4, m5, m6)); - } - - R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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(std::forward<A1>(a1), - std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), - std::forward<A5>(a5), std::forward<A6>(a6))); - } -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7> -class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public - internal::FunctionMockerBase<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, - const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, - const Matcher<A6>& m6, const Matcher<A7>& m7) { - return MockSpec<F>(this, ::std::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) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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(std::forward<A1>(a1), - std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), - std::forward<A5>(a5), std::forward<A6>(a6), std::forward<A7>(a7))); - } -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7, typename A8> -class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public - internal::FunctionMockerBase<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, - const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, - const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) { - return MockSpec<F>(this, ::std::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) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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(std::forward<A1>(a1), - std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), - std::forward<A5>(a5), std::forward<A6>(a6), std::forward<A7>(a7), - std::forward<A8>(a8))); - } -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7, typename A8, typename A9> -class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public - internal::FunctionMockerBase<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, - 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) { - return MockSpec<F>(this, ::std::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) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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(std::forward<A1>(a1), - std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), - std::forward<A5>(a5), std::forward<A6>(a6), std::forward<A7>(a7), - std::forward<A8>(a8), std::forward<A9>(a9))); - } -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7, typename A8, typename A9, - typename A10> -class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public - internal::FunctionMockerBase<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, - 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) { - return MockSpec<F>(this, ::std::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, - A10 a10) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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(std::forward<A1>(a1), - std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), - std::forward<A5>(a5), std::forward<A6>(a6), std::forward<A7>(a7), - std::forward<A8>(a8), std::forward<A9>(a9), std::forward<A10>(a10))); - } -}; - // Removes the given pointer; this is a helper for the expectation setter method // for parameterless matchers. // @@ -399,7 +121,7 @@ using internal::FunctionMocker; // The type of argument N of the given function type. // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_ARG_(tn, N, ...) \ - tn ::testing::internal::Function<__VA_ARGS__>::Argument##N + tn ::testing::internal::Function<__VA_ARGS__>::template Arg<N-1>::type // The matcher type for argument N of the given function type. // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! @@ -413,12 +135,11 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \ + static_assert(0 == \ + ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \ + "MOCK_METHOD<N> must match argument count.");\ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ ) constness { \ - GTEST_COMPILE_ASSERT_((::std::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(); \ } \ @@ -438,12 +159,11 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \ + static_assert(1 == \ + ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \ + "MOCK_METHOD<N> must match argument count.");\ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ - GTEST_COMPILE_ASSERT_((::std::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(::std::forward<GMOCK_ARG_(tn, 1, \ @@ -465,13 +185,12 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \ + static_assert(2 == \ + ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \ + "MOCK_METHOD<N> must match argument count.");\ 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_((::std::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(::std::forward<GMOCK_ARG_(tn, 1, \ @@ -496,14 +215,13 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \ + static_assert(3 == \ + ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \ + "MOCK_METHOD<N> must match argument count.");\ 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_((::std::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(::std::forward<GMOCK_ARG_(tn, 1, \ @@ -532,14 +250,13 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \ + static_assert(4 == \ + ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \ + "MOCK_METHOD<N> must match argument count.");\ 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_((::std::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(::std::forward<GMOCK_ARG_(tn, 1, \ @@ -571,15 +288,14 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \ + static_assert(5 == \ + ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \ + "MOCK_METHOD<N> must match argument count.");\ 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_((::std::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(::std::forward<GMOCK_ARG_(tn, 1, \ @@ -614,16 +330,15 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \ + static_assert(6 == \ + ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \ + "MOCK_METHOD<N> must match argument count.");\ 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_((::std::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(::std::forward<GMOCK_ARG_(tn, 1, \ @@ -661,16 +376,15 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \ + static_assert(7 == \ + ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \ + "MOCK_METHOD<N> must match argument count.");\ 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_((::std::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(::std::forward<GMOCK_ARG_(tn, 1, \ @@ -711,6 +425,9 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \ + static_assert(8 == \ + ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \ + "MOCK_METHOD<N> must match argument count.");\ 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, \ @@ -718,10 +435,6 @@ using internal::FunctionMocker; __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_((::std::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(::std::forward<GMOCK_ARG_(tn, 1, \ @@ -765,6 +478,9 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \ + static_assert(9 == \ + ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \ + "MOCK_METHOD<N> must match argument count.");\ 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, \ @@ -773,10 +489,6 @@ using internal::FunctionMocker; 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_((::std::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(::std::forward<GMOCK_ARG_(tn, 1, \ @@ -824,6 +536,9 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \ + static_assert(10 == \ + ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, \ + "MOCK_METHOD<N> must match argument count.");\ 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, \ @@ -832,10 +547,6 @@ using internal::FunctionMocker; 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_((::std::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(::std::forward<GMOCK_ARG_(tn, 1, \ @@ -1036,293 +747,6 @@ using internal::FunctionMocker; #define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \ GMOCK_METHOD10_(typename, const, ct, m, __VA_ARGS__) -// A MockFunction<F> class has one mock method whose type is F. It is -// useful when you just want your test code to emit some messages and -// have Google Mock verify the right messages are sent (and perhaps at -// the right times). For example, if you are exercising code: -// -// Foo(1); -// Foo(2); -// Foo(3); -// -// and want to verify that Foo(1) and Foo(3) both invoke -// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: -// -// TEST(FooTest, InvokesBarCorrectly) { -// MyMock mock; -// MockFunction<void(string check_point_name)> check; -// { -// InSequence s; -// -// EXPECT_CALL(mock, Bar("a")); -// EXPECT_CALL(check, Call("1")); -// EXPECT_CALL(check, Call("2")); -// EXPECT_CALL(mock, Bar("a")); -// } -// Foo(1); -// check.Call("1"); -// Foo(2); -// check.Call("2"); -// Foo(3); -// } -// -// The expectation spec says that the first Bar("a") must happen -// before check point "1", the second Bar("a") must happen after check -// point "2", and nothing should happen between the two check -// points. The explicit check points make it easy to tell which -// Bar("a") is called by which call to Foo(). -// -// MockFunction<F> can also be used to exercise code that accepts -// std::function<F> callbacks. To do so, use AsStdFunction() method -// to create std::function proxy forwarding to original object's Call. -// Example: -// -// TEST(FooTest, RunsCallbackWithBarArgument) { -// MockFunction<int(string)> callback; -// EXPECT_CALL(callback, Call("bar")).WillOnce(Return(1)); -// Foo(callback.AsStdFunction()); -// } -template <typename F> -class MockFunction; - -template <typename R> -class MockFunction<R()> { - public: - MockFunction() {} - - MOCK_METHOD0_T(Call, R()); - -#if GTEST_HAS_STD_FUNCTION_ - ::std::function<R()> AsStdFunction() { - return [this]() -> R { - return this->Call(); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template <typename R, typename A0> -class MockFunction<R(A0)> { - public: - MockFunction() {} - - MOCK_METHOD1_T(Call, R(A0)); - -#if GTEST_HAS_STD_FUNCTION_ - ::std::function<R(A0)> AsStdFunction() { - return [this](A0 a0) -> R { - return this->Call(::std::forward<A0>(a0)); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template <typename R, typename A0, typename A1> -class MockFunction<R(A0, A1)> { - public: - MockFunction() {} - - MOCK_METHOD2_T(Call, R(A0, A1)); - -#if GTEST_HAS_STD_FUNCTION_ - ::std::function<R(A0, A1)> AsStdFunction() { - return [this](A0 a0, A1 a1) -> R { - return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1)); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template <typename R, typename A0, typename A1, typename A2> -class MockFunction<R(A0, A1, A2)> { - public: - MockFunction() {} - - MOCK_METHOD3_T(Call, R(A0, A1, A2)); - -#if GTEST_HAS_STD_FUNCTION_ - ::std::function<R(A0, A1, A2)> AsStdFunction() { - return [this](A0 a0, A1 a1, A2 a2) -> R { - return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1), - ::std::forward<A2>(a2)); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template <typename R, typename A0, typename A1, typename A2, typename A3> -class MockFunction<R(A0, A1, A2, A3)> { - public: - MockFunction() {} - - MOCK_METHOD4_T(Call, R(A0, A1, A2, A3)); - -#if GTEST_HAS_STD_FUNCTION_ - ::std::function<R(A0, A1, A2, A3)> AsStdFunction() { - return [this](A0 a0, A1 a1, A2 a2, A3 a3) -> R { - return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1), - ::std::forward<A2>(a2), ::std::forward<A3>(a3)); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template <typename R, typename A0, typename A1, typename A2, typename A3, - typename A4> -class MockFunction<R(A0, A1, A2, A3, A4)> { - public: - MockFunction() {} - - MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4)); - -#if GTEST_HAS_STD_FUNCTION_ - ::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(::std::forward<A0>(a0), ::std::forward<A1>(a1), - ::std::forward<A2>(a2), ::std::forward<A3>(a3), - ::std::forward<A4>(a4)); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template <typename R, typename A0, typename A1, typename A2, typename A3, - typename A4, typename A5> -class MockFunction<R(A0, A1, A2, A3, A4, A5)> { - public: - MockFunction() {} - - 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() { - return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) -> R { - return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1), - ::std::forward<A2>(a2), ::std::forward<A3>(a3), - ::std::forward<A4>(a4), ::std::forward<A5>(a5)); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template <typename R, typename A0, typename A1, typename A2, typename A3, - typename A4, typename A5, typename A6> -class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> { - public: - MockFunction() {} - - 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() { - return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) -> R { - return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1), - ::std::forward<A2>(a2), ::std::forward<A3>(a3), - ::std::forward<A4>(a4), ::std::forward<A5>(a5), - ::std::forward<A6>(a6)); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template <typename R, typename A0, typename A1, typename A2, typename A3, - typename A4, typename A5, typename A6, typename A7> -class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> { - public: - MockFunction() {} - - 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() { - return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) -> R { - return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1), - ::std::forward<A2>(a2), ::std::forward<A3>(a3), - ::std::forward<A4>(a4), ::std::forward<A5>(a5), - ::std::forward<A6>(a6), ::std::forward<A7>(a7)); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template <typename R, typename A0, typename A1, typename A2, typename A3, - typename A4, typename A5, typename A6, typename A7, typename A8> -class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> { - public: - MockFunction() {} - - 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() { - return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, - A8 a8) -> R { - return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1), - ::std::forward<A2>(a2), ::std::forward<A3>(a3), - ::std::forward<A4>(a4), ::std::forward<A5>(a5), - ::std::forward<A6>(a6), ::std::forward<A7>(a7), - ::std::forward<A8>(a8)); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template <typename R, typename A0, typename A1, typename A2, typename A3, - typename A4, typename A5, typename A6, typename A7, typename A8, - typename A9> -class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> { - public: - MockFunction() {} - - 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() { - 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(::std::forward<A0>(a0), ::std::forward<A1>(a1), - ::std::forward<A2>(a2), ::std::forward<A3>(a3), - ::std::forward<A4>(a4), ::std::forward<A5>(a5), - ::std::forward<A6>(a6), ::std::forward<A7>(a7), - ::std::forward<A8>(a8), ::std::forward<A9>(a9)); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - } // namespace testing #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-function-mockers.h.pump b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-function-mockers.h.pump index 183e652c9d4..a56e132f348 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-function-mockers.h.pump +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-function-mockers.h.pump @@ -42,61 +42,16 @@ $var n = 10 $$ The maximum arity we support. #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ +#include <functional> #include <utility> #include "gmock/gmock-spec-builders.h" #include "gmock/internal/gmock-internal-utils.h" -#if GTEST_HAS_STD_FUNCTION_ -# include <functional> -#endif - namespace testing { namespace internal { -template <typename F> -class FunctionMockerBase; - -// Note: class FunctionMocker really belongs to the ::testing -// namespace. However if we define it in ::testing, MSVC will -// complain when classes in ::testing::internal declare it as a -// friend class template. To workaround this compiler bug, we define -// FunctionMocker in ::testing::internal and import it into ::testing. -template <typename F> -class FunctionMocker; - - $range i 0..n -$for i [[ -$range j 1..i -$var typename_As = [[$for j [[, typename A$j]]]] -$var As = [[$for j, [[A$j]]]] -$var as = [[$for j, [[std::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]]]] -template <typename R$typename_As> -class FunctionMocker<R($As)> : public - internal::FunctionMockerBase<R($As)> { - public: - typedef R F($As); - typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - - MockSpec<F> With($matchers) { - return MockSpec<F>(this, ::std::make_tuple($ms)); - } - - R Invoke($Aas) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // 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($as)); - } -}; - - -]] // Removes the given pointer; this is a helper for the expectation setter method // for parameterless matchers. // @@ -169,7 +124,7 @@ using internal::FunctionMocker; // The type of argument N of the given function type. // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_ARG_(tn, N, ...) \ - tn ::testing::internal::Function<__VA_ARGS__>::Argument##N + tn ::testing::internal::Function<__VA_ARGS__>::template Arg<N-1>::type // The matcher type for argument N of the given function type. // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! @@ -194,11 +149,9 @@ $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, ...) \ + static_assert($i == ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, "MOCK_METHOD<N> must match argument count.");\ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ $arg_as) constness { \ - GTEST_COMPILE_ASSERT_((::std::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value == $i), \ - this_method_does_not_take_$i[[]]_argument[[$if i != 1 [[s]]]]); \ GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \ return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \ } \ @@ -269,82 +222,6 @@ $for i [[ ]] -// A MockFunction<F> class has one mock method whose type is F. It is -// useful when you just want your test code to emit some messages and -// have Google Mock verify the right messages are sent (and perhaps at -// the right times). For example, if you are exercising code: -// -// Foo(1); -// Foo(2); -// Foo(3); -// -// and want to verify that Foo(1) and Foo(3) both invoke -// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: -// -// TEST(FooTest, InvokesBarCorrectly) { -// MyMock mock; -// MockFunction<void(string check_point_name)> check; -// { -// InSequence s; -// -// EXPECT_CALL(mock, Bar("a")); -// EXPECT_CALL(check, Call("1")); -// EXPECT_CALL(check, Call("2")); -// EXPECT_CALL(mock, Bar("a")); -// } -// Foo(1); -// check.Call("1"); -// Foo(2); -// check.Call("2"); -// Foo(3); -// } -// -// The expectation spec says that the first Bar("a") must happen -// before check point "1", the second Bar("a") must happen after check -// point "2", and nothing should happen between the two check -// points. The explicit check points make it easy to tell which -// Bar("a") is called by which call to Foo(). -// -// MockFunction<F> can also be used to exercise code that accepts -// std::function<F> callbacks. To do so, use AsStdFunction() method -// to create std::function proxy forwarding to original object's Call. -// Example: -// -// TEST(FooTest, RunsCallbackWithBarArgument) { -// MockFunction<int(string)> callback; -// EXPECT_CALL(callback, Call("bar")).WillOnce(Return(1)); -// Foo(callback.AsStdFunction()); -// } -template <typename F> -class MockFunction; - - -$for i [[ -$range j 0..i-1 -$var ArgTypes = [[$for j, [[A$j]]]] -$var ArgValues = [[$for j, [[::std::forward<A$j>(a$j)]]]] -$var ArgDecls = [[$for j, [[A$j a$j]]]] -template <typename R$for j [[, typename A$j]]> -class MockFunction<R($ArgTypes)> { - public: - MockFunction() {} - - MOCK_METHOD$i[[]]_T(Call, R($ArgTypes)); - -#if GTEST_HAS_STD_FUNCTION_ - ::std::function<R($ArgTypes)> AsStdFunction() { - return [this]($ArgDecls) -> R { - return this->Call($ArgValues); - }; - } -#endif // GTEST_HAS_STD_FUNCTION_ - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - - -]] } // namespace testing #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-matchers.h b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-matchers.h index 1161e870cb9..f9c927c1dfa 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-matchers.h +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-matchers.h @@ -47,343 +47,6 @@ #include <vector> #include "gmock/gmock-matchers.h" -namespace testing { -namespace internal { - -// The type of the i-th (0-based) field of Tuple. -#define GMOCK_FIELD_TYPE_(Tuple, i) \ - typename ::std::tuple_element<i, Tuple>::type - -// TupleFields<Tuple, k0, ..., kn> is for selecting fields from a -// tuple of type Tuple. It has two members: -// -// type: a tuple type whose i-th field is the ki-th field of Tuple. -// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple. -// -// For example, in class TupleFields<std::tuple<bool, char, int>, 2, 0>, -// we have: -// -// type is std::tuple<int, bool>, and -// GetSelectedFields(std::make_tuple(true, 'a', 42)) is (42, true). - -template <class Tuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1, - int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1, - int k9 = -1> -class TupleFields; - -// This generic version is used when there are 10 selectors. -template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6, - int k7, int k8, int k9> -class TupleFields { - public: - typedef ::std::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), GMOCK_FIELD_TYPE_(Tuple, - k1), GMOCK_FIELD_TYPE_(Tuple, k2), GMOCK_FIELD_TYPE_(Tuple, k3), - GMOCK_FIELD_TYPE_(Tuple, k4), GMOCK_FIELD_TYPE_(Tuple, k5), - GMOCK_FIELD_TYPE_(Tuple, k6), GMOCK_FIELD_TYPE_(Tuple, k7), - GMOCK_FIELD_TYPE_(Tuple, k8), GMOCK_FIELD_TYPE_(Tuple, k9)> type; - static type GetSelectedFields(const Tuple& t) { - return type(std::get<k0>(t), std::get<k1>(t), std::get<k2>(t), - std::get<k3>(t), std::get<k4>(t), std::get<k5>(t), std::get<k6>(t), - std::get<k7>(t), std::get<k8>(t), std::get<k9>(t)); - } -}; - -// The following specialization is used for 0 ~ 9 selectors. - -template <class Tuple> -class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { - public: - typedef ::std::tuple<> type; - static type GetSelectedFields(const Tuple& /* t */) { - return type(); - } -}; - -template <class Tuple, int k0> -class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> { - public: - typedef ::std::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type; - static type GetSelectedFields(const Tuple& t) { - return type(std::get<k0>(t)); - } -}; - -template <class Tuple, int k0, int k1> -class TupleFields<Tuple, k0, k1, -1, -1, -1, -1, -1, -1, -1, -1> { - public: - typedef ::std::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), GMOCK_FIELD_TYPE_(Tuple, - k1)> type; - static type GetSelectedFields(const Tuple& t) { - return type(std::get<k0>(t), std::get<k1>(t)); - } -}; - -template <class Tuple, int k0, int k1, int k2> -class TupleFields<Tuple, k0, k1, k2, -1, -1, -1, -1, -1, -1, -1> { - public: - typedef ::std::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), GMOCK_FIELD_TYPE_(Tuple, - k1), GMOCK_FIELD_TYPE_(Tuple, k2)> type; - static type GetSelectedFields(const Tuple& t) { - return type(std::get<k0>(t), std::get<k1>(t), std::get<k2>(t)); - } -}; - -template <class Tuple, int k0, int k1, int k2, int k3> -class TupleFields<Tuple, k0, k1, k2, k3, -1, -1, -1, -1, -1, -1> { - public: - typedef ::std::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), GMOCK_FIELD_TYPE_(Tuple, - k1), GMOCK_FIELD_TYPE_(Tuple, k2), GMOCK_FIELD_TYPE_(Tuple, k3)> type; - static type GetSelectedFields(const Tuple& t) { - return type(std::get<k0>(t), std::get<k1>(t), std::get<k2>(t), - std::get<k3>(t)); - } -}; - -template <class Tuple, int k0, int k1, int k2, int k3, int k4> -class TupleFields<Tuple, k0, k1, k2, k3, k4, -1, -1, -1, -1, -1> { - public: - typedef ::std::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), GMOCK_FIELD_TYPE_(Tuple, - k1), GMOCK_FIELD_TYPE_(Tuple, k2), GMOCK_FIELD_TYPE_(Tuple, k3), - GMOCK_FIELD_TYPE_(Tuple, k4)> type; - static type GetSelectedFields(const Tuple& t) { - return type(std::get<k0>(t), std::get<k1>(t), std::get<k2>(t), - std::get<k3>(t), std::get<k4>(t)); - } -}; - -template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5> -class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, -1, -1, -1, -1> { - public: - typedef ::std::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), GMOCK_FIELD_TYPE_(Tuple, - k1), GMOCK_FIELD_TYPE_(Tuple, k2), GMOCK_FIELD_TYPE_(Tuple, k3), - GMOCK_FIELD_TYPE_(Tuple, k4), GMOCK_FIELD_TYPE_(Tuple, k5)> type; - static type GetSelectedFields(const Tuple& t) { - return type(std::get<k0>(t), std::get<k1>(t), std::get<k2>(t), - std::get<k3>(t), std::get<k4>(t), std::get<k5>(t)); - } -}; - -template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6> -class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, -1, -1, -1> { - public: - typedef ::std::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), GMOCK_FIELD_TYPE_(Tuple, - k1), GMOCK_FIELD_TYPE_(Tuple, k2), GMOCK_FIELD_TYPE_(Tuple, k3), - GMOCK_FIELD_TYPE_(Tuple, k4), GMOCK_FIELD_TYPE_(Tuple, k5), - GMOCK_FIELD_TYPE_(Tuple, k6)> type; - static type GetSelectedFields(const Tuple& t) { - return type(std::get<k0>(t), std::get<k1>(t), std::get<k2>(t), - std::get<k3>(t), std::get<k4>(t), std::get<k5>(t), std::get<k6>(t)); - } -}; - -template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6, - int k7> -class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, -1, -1> { - public: - typedef ::std::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), GMOCK_FIELD_TYPE_(Tuple, - k1), GMOCK_FIELD_TYPE_(Tuple, k2), GMOCK_FIELD_TYPE_(Tuple, k3), - GMOCK_FIELD_TYPE_(Tuple, k4), GMOCK_FIELD_TYPE_(Tuple, k5), - GMOCK_FIELD_TYPE_(Tuple, k6), GMOCK_FIELD_TYPE_(Tuple, k7)> type; - static type GetSelectedFields(const Tuple& t) { - return type(std::get<k0>(t), std::get<k1>(t), std::get<k2>(t), - std::get<k3>(t), std::get<k4>(t), std::get<k5>(t), std::get<k6>(t), - std::get<k7>(t)); - } -}; - -template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6, - int k7, int k8> -class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, -1> { - public: - typedef ::std::tuple<GMOCK_FIELD_TYPE_(Tuple, k0), GMOCK_FIELD_TYPE_(Tuple, - k1), GMOCK_FIELD_TYPE_(Tuple, k2), GMOCK_FIELD_TYPE_(Tuple, k3), - GMOCK_FIELD_TYPE_(Tuple, k4), GMOCK_FIELD_TYPE_(Tuple, k5), - GMOCK_FIELD_TYPE_(Tuple, k6), GMOCK_FIELD_TYPE_(Tuple, k7), - GMOCK_FIELD_TYPE_(Tuple, k8)> type; - static type GetSelectedFields(const Tuple& t) { - return type(std::get<k0>(t), std::get<k1>(t), std::get<k2>(t), - std::get<k3>(t), std::get<k4>(t), std::get<k5>(t), std::get<k6>(t), - std::get<k7>(t), std::get<k8>(t)); - } -}; - -#undef GMOCK_FIELD_TYPE_ - -// Implements the Args() matcher. -template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1, - int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1, - int k9 = -1> -class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> { - public: - // ArgsTuple may have top-level const or reference modifiers. - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple; - typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, - k6, k7, k8, k9>::type SelectedArgs; - typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher; - - template <typename InnerMatcher> - explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) - : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {} - - virtual bool MatchAndExplain(ArgsTuple args, - MatchResultListener* listener) const { - const SelectedArgs& selected_args = GetSelectedArgs(args); - if (!listener->IsInterested()) - return inner_matcher_.Matches(selected_args); - - PrintIndices(listener->stream()); - *listener << "are " << PrintToString(selected_args); - - StringMatchResultListener inner_listener; - const bool match = inner_matcher_.MatchAndExplain(selected_args, - &inner_listener); - PrintIfNotEmpty(inner_listener.str(), listener->stream()); - return match; - } - - virtual void DescribeTo(::std::ostream* os) const { - *os << "are a tuple "; - PrintIndices(os); - inner_matcher_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "are a tuple "; - PrintIndices(os); - inner_matcher_.DescribeNegationTo(os); - } - - private: - static SelectedArgs GetSelectedArgs(ArgsTuple args) { - return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, - k9>::GetSelectedFields(args); - } - - // Prints the indices of the selected fields. - static void PrintIndices(::std::ostream* os) { - *os << "whose fields ("; - const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 }; - for (int i = 0; i < 10; i++) { - if (indices[i] < 0) - break; - - if (i >= 1) - *os << ", "; - - *os << "#" << indices[i]; - } - *os << ") "; - } - - const MonomorphicInnerMatcher inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl); -}; - -template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1, - int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, - int k8 = -1, int k9 = -1> -class ArgsMatcher { - public: - explicit ArgsMatcher(const InnerMatcher& inner_matcher) - : inner_matcher_(inner_matcher) {} - - template <typename ArgsTuple> - operator Matcher<ArgsTuple>() const { - return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k5, - k6, k7, k8, k9>(inner_matcher_)); - } - - private: - const InnerMatcher inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(ArgsMatcher); -}; - -} // namespace internal - -// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected -// fields of it matches a_matcher. C++ doesn't support default -// arguments for function templates, so we have to overload it. -template <typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher>(matcher); -} - -template <int k1, typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher, k1> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher, k1>(matcher); -} - -template <int k1, int k2, typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher, k1, k2> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher, k1, k2>(matcher); -} - -template <int k1, int k2, int k3, typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher, k1, k2, k3>(matcher); -} - -template <int k1, int k2, int k3, int k4, typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>(matcher); -} - -template <int k1, int k2, int k3, int k4, int k5, typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>(matcher); -} - -template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>(matcher); -} - -template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, - typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, - k7>(matcher); -} - -template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, - typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, - k8>(matcher); -} - -template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, - int k9, typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, - k9>(matcher); -} - -template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8, - int k9, int k10, typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9, - k10> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, - k9, k10>(matcher); -} - - -} // namespace testing - - // The MATCHER* family of macros can be used in a namespace scope to // define custom matchers easily. // diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-matchers.h.pump b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-matchers.h.pump index dcb42435938..43a0c5fa416 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-matchers.h.pump +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-matchers.h.pump @@ -49,169 +49,6 @@ $$ }} This line fixes auto-indentation of the following code in Emacs. #include <vector> #include "gmock/gmock-matchers.h" -namespace testing { -namespace internal { - -$range i 0..n-1 - -// The type of the i-th (0-based) field of Tuple. -#define GMOCK_FIELD_TYPE_(Tuple, i) \ - typename ::std::tuple_element<i, Tuple>::type - -// TupleFields<Tuple, k0, ..., kn> is for selecting fields from a -// tuple of type Tuple. It has two members: -// -// type: a tuple type whose i-th field is the ki-th field of Tuple. -// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple. -// -// For example, in class TupleFields<std::tuple<bool, char, int>, 2, 0>, -// we have: -// -// type is std::tuple<int, bool>, and -// GetSelectedFields(std::make_tuple(true, 'a', 42)) is (42, true). - -template <class Tuple$for i [[, int k$i = -1]]> -class TupleFields; - -// This generic version is used when there are $n selectors. -template <class Tuple$for i [[, int k$i]]> -class TupleFields { - public: - typedef ::std::tuple<$for i, [[GMOCK_FIELD_TYPE_(Tuple, k$i)]]> type; - static type GetSelectedFields(const Tuple& t) { - return type($for i, [[std::get<k$i>(t)]]); - } -}; - -// The following specialization is used for 0 ~ $(n-1) selectors. - -$for i [[ -$$ }}} -$range j 0..i-1 -$range k 0..n-1 - -template <class Tuple$for j [[, int k$j]]> -class TupleFields<Tuple, $for k, [[$if k < i [[k$k]] $else [[-1]]]]> { - public: - typedef ::std::tuple<$for j, [[GMOCK_FIELD_TYPE_(Tuple, k$j)]]> type; - static type GetSelectedFields(const Tuple& $if i==0 [[/* t */]] $else [[t]]) { - return type($for j, [[std::get<k$j>(t)]]); - } -}; - -]] - -#undef GMOCK_FIELD_TYPE_ - -// Implements the Args() matcher. - -$var ks = [[$for i, [[k$i]]]] -template <class ArgsTuple$for i [[, int k$i = -1]]> -class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> { - public: - // ArgsTuple may have top-level const or reference modifiers. - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple; - typedef typename internal::TupleFields<RawArgsTuple, $ks>::type SelectedArgs; - typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher; - - template <typename InnerMatcher> - explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) - : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {} - - virtual bool MatchAndExplain(ArgsTuple args, - MatchResultListener* listener) const { - const SelectedArgs& selected_args = GetSelectedArgs(args); - if (!listener->IsInterested()) - return inner_matcher_.Matches(selected_args); - - PrintIndices(listener->stream()); - *listener << "are " << PrintToString(selected_args); - - StringMatchResultListener inner_listener; - const bool match = inner_matcher_.MatchAndExplain(selected_args, - &inner_listener); - PrintIfNotEmpty(inner_listener.str(), listener->stream()); - return match; - } - - virtual void DescribeTo(::std::ostream* os) const { - *os << "are a tuple "; - PrintIndices(os); - inner_matcher_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "are a tuple "; - PrintIndices(os); - inner_matcher_.DescribeNegationTo(os); - } - - private: - static SelectedArgs GetSelectedArgs(ArgsTuple args) { - return TupleFields<RawArgsTuple, $ks>::GetSelectedFields(args); - } - - // Prints the indices of the selected fields. - static void PrintIndices(::std::ostream* os) { - *os << "whose fields ("; - const int indices[$n] = { $ks }; - for (int i = 0; i < $n; i++) { - if (indices[i] < 0) - break; - - if (i >= 1) - *os << ", "; - - *os << "#" << indices[i]; - } - *os << ") "; - } - - const MonomorphicInnerMatcher inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl); -}; - -template <class InnerMatcher$for i [[, int k$i = -1]]> -class ArgsMatcher { - public: - explicit ArgsMatcher(const InnerMatcher& inner_matcher) - : inner_matcher_(inner_matcher) {} - - template <typename ArgsTuple> - operator Matcher<ArgsTuple>() const { - return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, $ks>(inner_matcher_)); - } - - private: - const InnerMatcher inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(ArgsMatcher); -}; - -} // namespace internal - -// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected -// fields of it matches a_matcher. C++ doesn't support default -// arguments for function templates, so we have to overload it. - -$range i 0..n -$for i [[ -$range j 1..i -template <$for j [[int k$j, ]]typename InnerMatcher> -inline internal::ArgsMatcher<InnerMatcher$for j [[, k$j]]> -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher<InnerMatcher$for j [[, k$j]]>(matcher); -} - - -]] - -} // namespace testing -$$ } // This Pump meta comment fixes auto-indentation in Emacs. It will not -$$ // show up in the generated code. - - // The MATCHER* family of macros can be used in a namespace scope to // define custom matchers easily. // diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-nice-strict.h b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-nice-strict.h deleted file mode 100644 index 91ba1d9b2c0..00000000000 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-nice-strict.h +++ /dev/null @@ -1,459 +0,0 @@ -// This file was GENERATED by command: -// pump.py gmock-generated-nice-strict.h.pump -// DO NOT EDIT BY HAND!!! - -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -// Implements class templates NiceMock, NaggyMock, and StrictMock. -// -// Given a mock class MockFoo that is created using Google Mock, -// NiceMock<MockFoo> is a subclass of MockFoo that allows -// uninteresting calls (i.e. calls to mock methods that have no -// EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo -// that prints a warning when an uninteresting call occurs, and -// StrictMock<MockFoo> is a subclass of MockFoo that treats all -// uninteresting calls as errors. -// -// Currently a mock is naggy by default, so MockFoo and -// NaggyMock<MockFoo> behave like the same. However, we will soon -// switch the default behavior of mocks to be nice, as that in general -// leads to more maintainable tests. When that happens, MockFoo will -// stop behaving like NaggyMock<MockFoo> and start behaving like -// NiceMock<MockFoo>. -// -// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of -// 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 -// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. -// If a mock method is defined in a base class of MockFoo, the "nice" -// or "strict" modifier may not affect it, depending on the compiler. -// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT -// supported. - -// GOOGLETEST_CM0002 DO NOT DELETE - -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ - -#include "gmock/gmock-spec-builders.h" -#include "gmock/internal/gmock-port.h" - -namespace testing { - -template <class MockClass> -class NiceMock : public MockClass { - public: - 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)); - } - - 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( - internal::ImplicitCast_<MockClass*>(this)); - } - template <typename A1, typename A2> - NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3> - NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4> - NiceMock(const A1& a1, const A2& a2, const A3& a3, - const A4& a4) : MockClass(a1, a2, a3, a4) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5> - NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5) : MockClass(a1, a2, a3, a4, a5) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6> - NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7> - NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, - a6, a7) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7, typename A8> - NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, - a2, a3, a4, a5, a6, a7, a8) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7, typename A8, typename A9> - NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7, const A8& a8, - const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7, typename A8, typename A9, typename A10> - NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, - const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - -#endif // GTEST_LANG_CXX11 - - ~NiceMock() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_<MockClass*>(this)); - } - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); -}; - -template <class MockClass> -class NaggyMock : public MockClass { - public: - NaggyMock() : MockClass() { - ::testing::Mock::WarnUninterestingCalls( - 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 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( - internal::ImplicitCast_<MockClass*>(this)); - } - template <typename A1, typename A2> - NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3> - NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4> - NaggyMock(const A1& a1, const A2& a2, const A3& a3, - const A4& a4) : MockClass(a1, a2, a3, a4) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5> - NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5) : MockClass(a1, a2, a3, a4, a5) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6> - NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7> - NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, - a6, a7) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7, typename A8> - NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, - a2, a3, a4, a5, a6, a7, a8) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7, typename A8, typename A9> - NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7, const A8& a8, - const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7, typename A8, typename A9, typename A10> - NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, - const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - -#endif // GTEST_LANG_CXX11 - - ~NaggyMock() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_<MockClass*>(this)); - } - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock); -}; - -template <class MockClass> -class StrictMock : public MockClass { - public: - 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)); - } - - 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( - internal::ImplicitCast_<MockClass*>(this)); - } - template <typename A1, typename A2> - StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3> - StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4> - StrictMock(const A1& a1, const A2& a2, const A3& a3, - const A4& a4) : MockClass(a1, a2, a3, a4) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5> - StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5) : MockClass(a1, a2, a3, a4, a5) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6> - StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7> - StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, - a6, a7) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7, typename A8> - StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, - a2, a3, a4, a5, a6, a7, a8) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7, typename A8, typename A9> - StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7, const A8& a8, - const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - - template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7, typename A8, typename A9, typename A10> - StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, - const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_<MockClass*>(this)); - } - -#endif // GTEST_LANG_CXX11 - - ~StrictMock() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_<MockClass*>(this)); - } - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); -}; - -// The following specializations catch some (relatively more common) -// user errors of nesting nice and strict mocks. They do NOT catch -// all possible errors. - -// These specializations are declared but not defined, as NiceMock, -// NaggyMock, and StrictMock cannot be nested. - -template <typename MockClass> -class NiceMock<NiceMock<MockClass> >; -template <typename MockClass> -class NiceMock<NaggyMock<MockClass> >; -template <typename MockClass> -class NiceMock<StrictMock<MockClass> >; - -template <typename MockClass> -class NaggyMock<NiceMock<MockClass> >; -template <typename MockClass> -class NaggyMock<NaggyMock<MockClass> >; -template <typename MockClass> -class NaggyMock<StrictMock<MockClass> >; - -template <typename MockClass> -class StrictMock<NiceMock<MockClass> >; -template <typename MockClass> -class StrictMock<NaggyMock<MockClass> >; -template <typename MockClass> -class StrictMock<StrictMock<MockClass> >; - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-matchers.h b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-matchers.h index 95bc22c5250..2cb70286ac1 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-matchers.h +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-matchers.h @@ -33,6 +33,9 @@ // This file implements some commonly used argument matchers. More // matchers can be defined by the user implementing the // MatcherInterface<T> interface if necessary. +// +// See googletest/include/gtest/gtest-matchers.h for the definition of class +// Matcher, class MatcherInterface, and others. // GOOGLETEST_CM0002 DO NOT DELETE @@ -41,22 +44,20 @@ #include <math.h> #include <algorithm> +#include <initializer_list> #include <iterator> #include <limits> #include <memory> #include <ostream> // NOLINT #include <sstream> #include <string> +#include <type_traits> #include <utility> #include <vector> #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 -#endif - GTEST_DISABLE_MSC_WARNINGS_PUSH_( 4251 5046 /* class A needs to have dll-interface to be used by clients of class B */ @@ -76,144 +77,6 @@ namespace testing { // ownership management as Matcher objects can now be copied like // plain values. -// MatchResultListener is an abstract class. Its << operator can be -// used by a matcher to explain why a value matches or doesn't match. -// -// FIXME: add method -// bool InterestedInWhy(bool result) const; -// to indicate whether the listener is interested in why the match -// result is 'result'. -class MatchResultListener { - public: - // Creates a listener object with the given underlying ostream. The - // listener does not own the ostream, and does not dereference it - // in the constructor or destructor. - explicit MatchResultListener(::std::ostream* os) : stream_(os) {} - virtual ~MatchResultListener() = 0; // Makes this class abstract. - - // Streams x to the underlying ostream; does nothing if the ostream - // is NULL. - template <typename T> - MatchResultListener& operator<<(const T& x) { - if (stream_ != nullptr) *stream_ << x; - return *this; - } - - // Returns the underlying ostream. - ::std::ostream* stream() { return stream_; } - - // Returns true iff the listener is interested in an explanation of - // the match result. A matcher's MatchAndExplain() method can use - // this information to avoid generating the explanation when no one - // intends to hear it. - bool IsInterested() const { return stream_ != nullptr; } - - private: - ::std::ostream* const stream_; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener); -}; - -inline MatchResultListener::~MatchResultListener() { -} - -// An instance of a subclass of this knows how to describe itself as a -// matcher. -class MatcherDescriberInterface { - public: - virtual ~MatcherDescriberInterface() {} - - // Describes this matcher to an ostream. The function should print - // a verb phrase that describes the property a value matching this - // matcher should have. The subject of the verb phrase is the value - // being matched. For example, the DescribeTo() method of the Gt(7) - // matcher prints "is greater than 7". - virtual void DescribeTo(::std::ostream* os) const = 0; - - // Describes the negation of this matcher to an ostream. For - // example, if the description of this matcher is "is greater than - // 7", the negated description could be "is not greater than 7". - // You are not required to override this when implementing - // MatcherInterface, but it is highly advised so that your matcher - // can produce good error messages. - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "not ("; - DescribeTo(os); - *os << ")"; - } -}; - -// The implementation of a matcher. -template <typename T> -class MatcherInterface : public MatcherDescriberInterface { - public: - // Returns true iff the matcher matches x; also explains the match - // result to 'listener' if necessary (see the next paragraph), in - // the form of a non-restrictive relative clause ("which ...", - // "whose ...", etc) that describes x. For example, the - // MatchAndExplain() method of the Pointee(...) matcher should - // generate an explanation like "which points to ...". - // - // Implementations of MatchAndExplain() should add an explanation of - // the match result *if and only if* they can provide additional - // information that's not already present (or not obvious) in the - // print-out of x and the matcher's description. Whether the match - // succeeds is not a factor in deciding whether an explanation is - // needed, as sometimes the caller needs to print a failure message - // when the match succeeds (e.g. when the matcher is used inside - // Not()). - // - // For example, a "has at least 10 elements" matcher should explain - // what the actual element count is, regardless of the match result, - // as it is useful information to the reader; on the other hand, an - // "is empty" matcher probably only needs to explain what the actual - // size is when the match fails, as it's redundant to say that the - // size is 0 when the value is already known to be empty. - // - // You should override this method when defining a new matcher. - // - // It's the responsibility of the caller (Google Mock) to guarantee - // that 'listener' is not NULL. This helps to simplify a matcher's - // implementation when it doesn't care about the performance, as it - // can talk to 'listener' without checking its validity first. - // However, in order to implement dummy listeners efficiently, - // listener->stream() may be NULL. - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0; - - // Inherits these methods from MatcherDescriberInterface: - // virtual void DescribeTo(::std::ostream* os) const = 0; - // 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: @@ -231,397 +94,6 @@ class StringMatchResultListener : public MatchResultListener { GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener); }; -namespace internal { - -struct AnyEq { - template <typename A, typename B> - bool operator()(const A& a, const B& b) const { return a == b; } -}; -struct AnyNe { - template <typename A, typename B> - bool operator()(const A& a, const B& b) const { return a != b; } -}; -struct AnyLt { - template <typename A, typename B> - bool operator()(const A& a, const B& b) const { return a < b; } -}; -struct AnyGt { - template <typename A, typename B> - bool operator()(const A& a, const B& b) const { return a > b; } -}; -struct AnyLe { - template <typename A, typename B> - bool operator()(const A& a, const B& b) const { return a <= b; } -}; -struct AnyGe { - template <typename A, typename B> - bool operator()(const A& a, const B& b) const { return a >= b; } -}; - -// A match result listener that ignores the explanation. -class DummyMatchResultListener : public MatchResultListener { - public: - DummyMatchResultListener() : MatchResultListener(nullptr) {} - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener); -}; - -// A match result listener that forwards the explanation to a given -// ostream. The difference between this and MatchResultListener is -// that the former is concrete. -class StreamMatchResultListener : public MatchResultListener { - public: - explicit StreamMatchResultListener(::std::ostream* os) - : MatchResultListener(os) {} - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener); -}; - -// An internal class for implementing Matcher<T>, which will derive -// from it. We put functionalities common to all Matcher<T> -// specializations here to avoid code duplication. -template <typename T> -class MatcherBase { - public: - // Returns true iff the matcher matches x; also explains the match - // result to 'listener'. - 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(GTEST_REFERENCE_TO_CONST_(T) x) const { - DummyMatchResultListener dummy; - return MatchAndExplain(x, &dummy); - } - - // Describes this matcher to an ostream. - void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } - - // Describes the negation of this matcher to an ostream. - void DescribeNegationTo(::std::ostream* os) const { - impl_->DescribeNegationTo(os); - } - - // Explains why x matches, or doesn't match, the matcher. - void ExplainMatchResultTo(GTEST_REFERENCE_TO_CONST_(T) x, - ::std::ostream* os) const { - StreamMatchResultListener listener(os); - MatchAndExplain(x, &listener); - } - - // Returns the describer for this matcher object; retains ownership - // of the describer, which is only guaranteed to be alive when - // this matcher object is alive. - const MatcherDescriberInterface* GetDescriber() const { - return impl_.get(); - } - - protected: - MatcherBase() {} - - // Constructs a matcher from its implementation. - 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* = - nullptr) - : impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {} - - virtual ~MatcherBase() {} - - private: - std::shared_ptr<const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>> impl_; -}; - -} // namespace internal - -// A Matcher<T> is a copyable and IMMUTABLE (except by assignment) -// object that can check whether a value of type T matches. The -// implementation of Matcher<T> is just a std::shared_ptr to const -// MatcherInterface<T>. Don't inherit from Matcher! -template <typename T> -class Matcher : public internal::MatcherBase<T> { - public: - // Constructs a null matcher. Needed for storing Matcher objects in STL - // containers. A default-constructed matcher is not yet initialized. You - // cannot use it until a valid value has been assigned to it. - explicit Matcher() {} // NOLINT - - // Constructs a matcher from its implementation. - 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* = - nullptr) - : internal::MatcherBase<T>(impl) {} - - // Implicit constructor here allows people to write - // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes - Matcher(T value); // NOLINT -}; - -// The following two specializations allow the user to write str -// instead of Eq(str) and "foo" instead of Eq("foo") when a std::string -// matcher is expected. -template <> -class GTEST_API_ Matcher<const std::string&> - : public internal::MatcherBase<const std::string&> { - public: - Matcher() {} - - 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 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<std::string> - : public internal::MatcherBase<std::string> { - public: - Matcher() {} - - 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 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_GLOBAL_STRING -// The following two specializations allow the user to write str -// instead of Eq(str) and "foo" instead of Eq("foo") when a ::string -// matcher is expected. -template <> -class GTEST_API_ Matcher<const ::string&> - : public internal::MatcherBase<const ::string&> { - public: - Matcher() {} - - 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 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 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<const absl::string_view&> - : public internal::MatcherBase<const absl::string_view&> { - public: - Matcher() {} - - 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 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 -}; - -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 -// than one type, e.g. Eq(n) and NotNull()). -// -// To define a polymorphic matcher, a user should provide an Impl -// class that has a DescribeTo() method and a DescribeNegationTo() -// method, and define a member function (or member function template) -// -// bool MatchAndExplain(const Value& value, -// MatchResultListener* listener) const; -// -// See the definition of NotNull() for a complete example. -template <class Impl> -class PolymorphicMatcher { - public: - explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {} - - // Returns a mutable reference to the underlying matcher - // implementation object. - Impl& mutable_impl() { return impl_; } - - // Returns an immutable reference to the underlying matcher - // implementation object. - const Impl& impl() const { return impl_; } - - template <typename T> - operator Matcher<T>() const { - return Matcher<T>(new MonomorphicImpl<GTEST_REFERENCE_TO_CONST_(T)>(impl_)); - } - - private: - template <typename T> - class MonomorphicImpl : public MatcherInterface<T> { - public: - explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} - - virtual void DescribeTo(::std::ostream* os) const { - impl_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - impl_.DescribeNegationTo(os); - } - - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { - return impl_.MatchAndExplain(x, listener); - } - - private: - const Impl impl_; - - GTEST_DISALLOW_ASSIGN_(MonomorphicImpl); - }; - - Impl impl_; - - GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher); -}; - -// Creates a matcher from its implementation. This is easier to use -// than the Matcher<T> constructor as it doesn't require you to -// explicitly write the template argument, e.g. -// -// MakeMatcher(foo); -// vs -// Matcher<const string&>(foo); -template <typename T> -inline Matcher<T> MakeMatcher(const MatcherInterface<T>* impl) { - return Matcher<T>(impl); -} - -// Creates a polymorphic matcher from its implementation. This is -// easier to use than the PolymorphicMatcher<Impl> constructor as it -// doesn't require you to explicitly write the template argument, e.g. -// -// MakePolymorphicMatcher(foo); -// vs -// PolymorphicMatcher<TypeOfFoo>(foo); -template <class Impl> -inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) { - return PolymorphicMatcher<Impl>(impl); -} - // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION // and MUST NOT BE USED IN USER CODE!!! namespace internal { @@ -656,9 +128,9 @@ class MatcherCastImpl { return CastImpl( polymorphic_matcher_or_value, BooleanConstant< - internal::ImplicitlyConvertible<M, Matcher<T> >::value>(), + std::is_convertible<M, Matcher<T> >::value>(), BooleanConstant< - internal::ImplicitlyConvertible<M, T>::value>()); + std::is_convertible<M, T>::value>()); } private: @@ -718,8 +190,7 @@ class MatcherCastImpl<T, Matcher<U> > { : source_matcher_(source_matcher) {} // We delegate the matching logic to the source matcher. - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { -#if GTEST_LANG_CXX11 + bool MatchAndExplain(T x, MatchResultListener* listener) const override { 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< @@ -733,16 +204,15 @@ class MatcherCastImpl<T, Matcher<U> > { 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); } - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { source_matcher_.DescribeTo(os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { source_matcher_.DescribeNegationTo(os); } @@ -774,11 +244,8 @@ inline Matcher<T> MatcherCast(const M& matcher) { // Implements SafeMatcherCast(). // -// We use an intermediate class to do the actual safe casting as Nokia's -// Symbian compiler cannot decide between -// template <T, M> ... (M) and -// template <T, U> ... (const Matcher<U>&) -// for function templates but can for member function templates. +// FIXME: The intermediate SafeMatcherCastImpl class was introduced as a +// workaround for a compiler bug, and can now be removed. template <typename T> class SafeMatcherCastImpl { public: @@ -801,8 +268,8 @@ class SafeMatcherCastImpl { template <typename U> static inline Matcher<T> Cast(const Matcher<U>& matcher) { // Enforce that T can be implicitly converted to U. - GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible<T, U>::value), - T_must_be_implicitly_convertible_to_U); + GTEST_COMPILE_ASSERT_((std::is_convertible<T, U>::value), + "T must be implicitly convertible to U"); // Enforce that we are not converting a non-reference type T to a reference // type U. GTEST_COMPILE_ASSERT_( @@ -912,11 +379,9 @@ class TuplePrefix { typename std::tuple_element<N - 1, MatcherTuple>::type matcher = std::get<N - 1>(matchers); typedef typename std::tuple_element<N - 1, ValueTuple>::type Value; - GTEST_REFERENCE_TO_CONST_(Value) value = std::get<N - 1>(values); + const Value& value = std::get<N - 1>(values); StringMatchResultListener listener; if (!matcher.MatchAndExplain(value, &listener)) { - // FIXME: include in the message the name of the parameter - // as used in MOCK_METHOD*() when possible. *os << " Expected arg #" << N - 1 << ": "; std::get<N - 1>(matchers).DescribeTo(os); *os << "\n Actual: "; @@ -1017,14 +482,14 @@ OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) { // Implements A<T>(). template <typename T> -class AnyMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { +class AnyMatcherImpl : public MatcherInterface<const T&> { public: - virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) /* x */, - MatchResultListener* /* listener */) const { + bool MatchAndExplain(const T& /* x */, + MatchResultListener* /* listener */) const override { return true; } - virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "is anything"; } + void DescribeNegationTo(::std::ostream* os) const override { // This is mostly for completeness' safe, as it's not very useful // to write Not(A<bool>()). However we cannot completely rule out // such a possibility, and it doesn't hurt to be prepared. @@ -1042,99 +507,6 @@ class AnythingMatcher { operator Matcher<T>() const { return A<T>(); } }; -// Implements a matcher that compares a given value with a -// pre-supplied value using one of the ==, <=, <, etc, operators. The -// two values being compared don't have to have the same type. -// -// The matcher defined here is polymorphic (for example, Eq(5) can be -// used to match an int, a short, a double, etc). Therefore we use -// a template type conversion operator in the implementation. -// -// The following template definition assumes that the Rhs parameter is -// a "bare" type (i.e. neither 'const T' nor 'T&'). -template <typename D, typename Rhs, typename Op> -class ComparisonBase { - public: - explicit ComparisonBase(const Rhs& rhs) : rhs_(rhs) {} - template <typename Lhs> - operator Matcher<Lhs>() const { - return MakeMatcher(new Impl<Lhs>(rhs_)); - } - - private: - template <typename Lhs> - class Impl : public MatcherInterface<Lhs> { - public: - explicit Impl(const Rhs& rhs) : rhs_(rhs) {} - virtual bool MatchAndExplain( - Lhs lhs, MatchResultListener* /* listener */) const { - return Op()(lhs, rhs_); - } - virtual void DescribeTo(::std::ostream* os) const { - *os << D::Desc() << " "; - UniversalPrint(rhs_, os); - } - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << D::NegatedDesc() << " "; - UniversalPrint(rhs_, os); - } - private: - Rhs rhs_; - GTEST_DISALLOW_ASSIGN_(Impl); - }; - Rhs rhs_; - GTEST_DISALLOW_ASSIGN_(ComparisonBase); -}; - -template <typename Rhs> -class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq> { - public: - explicit EqMatcher(const Rhs& rhs) - : ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq>(rhs) { } - static const char* Desc() { return "is equal to"; } - static const char* NegatedDesc() { return "isn't equal to"; } -}; -template <typename Rhs> -class NeMatcher : public ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe> { - public: - explicit NeMatcher(const Rhs& rhs) - : ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe>(rhs) { } - static const char* Desc() { return "isn't equal to"; } - static const char* NegatedDesc() { return "is equal to"; } -}; -template <typename Rhs> -class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt> { - public: - explicit LtMatcher(const Rhs& rhs) - : ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt>(rhs) { } - static const char* Desc() { return "is <"; } - static const char* NegatedDesc() { return "isn't <"; } -}; -template <typename Rhs> -class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt> { - public: - explicit GtMatcher(const Rhs& rhs) - : ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt>(rhs) { } - static const char* Desc() { return "is >"; } - static const char* NegatedDesc() { return "isn't >"; } -}; -template <typename Rhs> -class LeMatcher : public ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe> { - public: - explicit LeMatcher(const Rhs& rhs) - : ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe>(rhs) { } - static const char* Desc() { return "is <="; } - static const char* NegatedDesc() { return "isn't <="; } -}; -template <typename Rhs> -class GeMatcher : public ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe> { - public: - explicit GeMatcher(const Rhs& rhs) - : ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe>(rhs) { } - static const char* Desc() { return "is >="; } - static const char* NegatedDesc() { return "isn't >="; } -}; - // Implements the polymorphic IsNull() matcher, which matches any raw or smart // pointer that is NULL. class IsNullMatcher { @@ -1142,11 +514,7 @@ class IsNullMatcher { template <typename Pointer> bool MatchAndExplain(const Pointer& p, MatchResultListener* /* listener */) const { -#if GTEST_LANG_CXX11 return p == nullptr; -#else // GTEST_LANG_CXX11 - return GetRawPointer(p) == NULL; -#endif // GTEST_LANG_CXX11 } void DescribeTo(::std::ostream* os) const { *os << "is NULL"; } @@ -1162,11 +530,7 @@ class NotNullMatcher { template <typename Pointer> bool MatchAndExplain(const Pointer& p, MatchResultListener* /* listener */) const { -#if GTEST_LANG_CXX11 return p != nullptr; -#else // GTEST_LANG_CXX11 - return GetRawPointer(p) != NULL; -#endif // GTEST_LANG_CXX11 } void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; } @@ -1222,18 +586,18 @@ class RefMatcher<T&> { // MatchAndExplain() takes a Super& (as opposed to const Super&) // in order to match the interface MatcherInterface<Super&>. - virtual bool MatchAndExplain( - Super& x, MatchResultListener* listener) const { + bool MatchAndExplain(Super& x, + MatchResultListener* listener) const override { *listener << "which is located @" << static_cast<const void*>(&x); return &x == &object_; } - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "references the variable "; UniversalPrinter<Super&>::Print(object_, os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "does not reference the variable "; UniversalPrinter<Super&>::Print(object_, os); } @@ -1523,62 +887,6 @@ class EndsWithMatcher { GTEST_DISALLOW_ASSIGN_(EndsWithMatcher); }; -// Implements polymorphic matchers MatchesRegex(regex) and -// ContainsRegex(regex), which can be used as a Matcher<T> as long as -// T can be converted to a string. -class MatchesRegexMatcher { - public: - 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 MatchAndExplain(string(s), listener); - } -#endif // GTEST_HAS_ABSL - - // Accepts pointer types, particularly: - // const char* - // char* - // const wchar_t* - // wchar_t* - template <typename CharType> - bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - return s != nullptr && MatchAndExplain(std::string(s), listener); - } - - // Matches anything that can convert to std::string. - // - // 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 std::string& s2(s); - return full_match_ ? RE::FullMatch(s2, *regex_) : - RE::PartialMatch(s2, *regex_); - } - - void DescribeTo(::std::ostream* os) const { - *os << (full_match_ ? "matches" : "contains") - << " regular expression "; - UniversalPrinter<std::string>::Print(regex_->pattern(), os); - } - - void DescribeNegationTo(::std::ostream* os) const { - *os << "doesn't " << (full_match_ ? "match" : "contain") - << " regular expression "; - UniversalPrinter<std::string>::Print(regex_->pattern(), os); - } - - private: - const std::shared_ptr<const RE> regex_; - const bool full_match_; - - GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher); -}; - // Implements a matcher that compares the two fields of a 2-tuple // using one of the ==, <=, <, etc, operators. The two fields being // compared don't have to have the same type. @@ -1592,7 +900,7 @@ class PairMatchBase { public: template <typename T1, typename T2> operator Matcher<::std::tuple<T1, T2>>() const { - return MakeMatcher(new Impl<::std::tuple<T1, T2>>); + return Matcher<::std::tuple<T1, T2>>(new Impl<const ::std::tuple<T1, T2>&>); } template <typename T1, typename T2> operator Matcher<const ::std::tuple<T1, T2>&>() const { @@ -1607,15 +915,14 @@ class PairMatchBase { template <typename Tuple> class Impl : public MatcherInterface<Tuple> { public: - virtual bool MatchAndExplain( - Tuple args, - MatchResultListener* /* listener */) const { + bool MatchAndExplain(Tuple args, + MatchResultListener* /* listener */) const override { return Op()(::std::get<0>(args), ::std::get<1>(args)); } - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "are " << GetDesc; } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "aren't " << GetDesc; } }; @@ -1651,21 +958,21 @@ 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<GTEST_REFERENCE_TO_CONST_(T)> { +class NotMatcherImpl : public MatcherInterface<const T&> { public: explicit NotMatcherImpl(const Matcher<T>& matcher) : matcher_(matcher) {} - virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, - MatchResultListener* listener) const { + bool MatchAndExplain(const T& x, + MatchResultListener* listener) const override { return !matcher_.MatchAndExplain(x, listener); } - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { matcher_.DescribeNegationTo(os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { matcher_.DescribeTo(os); } @@ -1700,13 +1007,12 @@ class NotMatcher { // that will prevent different instantiations of BothOfMatcher from // sharing the same BothOfMatcherImpl<T> class. template <typename T> -class AllOfMatcherImpl - : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { +class AllOfMatcherImpl : public MatcherInterface<const T&> { public: explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers) : matchers_(std::move(matchers)) {} - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "("; for (size_t i = 0; i < matchers_.size(); ++i) { if (i != 0) *os << ") and ("; @@ -1715,7 +1021,7 @@ class AllOfMatcherImpl *os << ")"; } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "("; for (size_t i = 0; i < matchers_.size(); ++i) { if (i != 0) *os << ") or ("; @@ -1724,8 +1030,8 @@ class AllOfMatcherImpl *os << ")"; } - virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, - MatchResultListener* listener) const { + bool MatchAndExplain(const T& x, + MatchResultListener* listener) const override { // If either matcher1_ or matcher2_ doesn't match x, we only need // to explain why one of them fails. std::string all_match_result; @@ -1807,13 +1113,12 @@ using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>; // that will prevent different instantiations of AnyOfMatcher from // sharing the same EitherOfMatcherImpl<T> class. template <typename T> -class AnyOfMatcherImpl - : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { +class AnyOfMatcherImpl : public MatcherInterface<const T&> { public: explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers) : matchers_(std::move(matchers)) {} - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "("; for (size_t i = 0; i < matchers_.size(); ++i) { if (i != 0) *os << ") or ("; @@ -1822,7 +1127,7 @@ class AnyOfMatcherImpl *os << ")"; } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "("; for (size_t i = 0; i < matchers_.size(); ++i) { if (i != 0) *os << ") and ("; @@ -1831,8 +1136,8 @@ class AnyOfMatcherImpl *os << ")"; } - virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, - MatchResultListener* listener) const { + bool MatchAndExplain(const T& x, + MatchResultListener* listener) const override { std::string no_match_result; // If either matcher1_ or matcher2_ matches x, we just need to @@ -1971,14 +1276,24 @@ class PredicateFormatterFromMatcher { // We don't write MatcherCast<const T&> either, as that allows // potentially unsafe downcasting of the matcher argument. const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_); - StringMatchResultListener listener; - if (MatchPrintAndExplain(x, matcher, &listener)) + + // The expected path here is that the matcher should match (i.e. that most + // tests pass) so optimize for this case. + if (matcher.Matches(x)) { return AssertionSuccess(); + } ::std::stringstream ss; ss << "Value of: " << value_text << "\n" << "Expected: "; matcher.DescribeTo(&ss); + + // Rerun the matcher to "PrintAndExain" the failure. + StringMatchResultListener listener; + if (MatchPrintAndExplain(x, matcher, &listener)) { + ss << "\n The matcher failed on the initial attempt; but passed when " + "rerun to generate the explanation."; + } ss << "\n Actual: " << listener.str(); return AssertionFailure() << ss.str(); } @@ -2037,8 +1352,8 @@ class FloatingEqMatcher { nan_eq_nan_(nan_eq_nan), max_abs_error_(max_abs_error) {} - virtual bool MatchAndExplain(T value, - MatchResultListener* listener) const { + bool MatchAndExplain(T value, + MatchResultListener* listener) const override { const FloatingPoint<FloatType> actual(value), expected(expected_); // Compares NaNs first, if nan_eq_nan_ is true. @@ -2072,7 +1387,7 @@ class FloatingEqMatcher { } } - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { // os->precision() returns the previously set precision, which we // store to restore the ostream to its original configuration // after outputting. @@ -2093,7 +1408,7 @@ class FloatingEqMatcher { os->precision(old_precision); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { // As before, get original precision. const ::std::streamsize old_precision = os->precision( ::std::numeric_limits<FloatType>::digits10 + 2); @@ -2199,8 +1514,8 @@ class FloatingEq2Matcher { max_abs_error_(max_abs_error), nan_eq_nan_(nan_eq_nan) {} - virtual bool MatchAndExplain(Tuple args, - MatchResultListener* listener) const { + bool MatchAndExplain(Tuple args, + MatchResultListener* listener) const override { if (max_abs_error_ == -1) { FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_); return static_cast<Matcher<FloatType>>(fm).MatchAndExplain( @@ -2212,10 +1527,10 @@ class FloatingEq2Matcher { ::std::get<1>(args), listener); } } - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "are " << GetDesc; } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "aren't " << GetDesc; } @@ -2249,8 +1564,7 @@ class PointeeMatcher { // enough for implementing the DescribeTo() method of Pointee(). template <typename Pointer> operator Matcher<Pointer>() const { - return Matcher<Pointer>( - new Impl<GTEST_REFERENCE_TO_CONST_(Pointer)>(matcher_)); + return Matcher<Pointer>(new Impl<const Pointer&>(matcher_)); } private: @@ -2264,18 +1578,18 @@ class PointeeMatcher { explicit Impl(const InnerMatcher& matcher) : matcher_(MatcherCast<const Pointee&>(matcher)) {} - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "points to a value that "; matcher_.DescribeTo(os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "does not point to a value that "; matcher_.DescribeTo(os); } - virtual bool MatchAndExplain(Pointer pointer, - MatchResultListener* listener) const { + bool MatchAndExplain(Pointer pointer, + MatchResultListener* listener) const override { if (GetRawPointer(pointer) == nullptr) return false; *listener << "which points to "; @@ -2341,7 +1655,6 @@ class WhenDynamicCastToMatcher : public WhenDynamicCastToMatcherBase<To> { template <typename From> bool MatchAndExplain(From from, MatchResultListener* listener) const { - // FIXME: Add more detail on failures. ie did the dyn_cast fail? To to = dynamic_cast<To>(from); return MatchPrintAndExplain(to, this->matcher_, listener); } @@ -2395,23 +1708,22 @@ class FieldMatcher { template <typename T> bool MatchAndExplain(const T& value, MatchResultListener* listener) const { + // FIXME: The dispatch on std::is_pointer was introduced as a workaround for + // a compiler bug, and can now be removed. return MatchAndExplainImpl( - typename ::testing::internal:: - is_pointer<GTEST_REMOVE_CONST_(T)>::type(), - value, listener); + typename std::is_pointer<GTEST_REMOVE_CONST_(T)>::type(), value, + listener); } private: - // The first argument of MatchAndExplainImpl() is needed to help - // Symbian's C++ compiler choose which overload to use. Its type is - // true_type iff the Field() matcher is used to match a pointer. - bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, + bool MatchAndExplainImpl(std::false_type /* is_not_pointer */, + const Class& obj, MatchResultListener* listener) const { *listener << whose_field_ << "is "; return MatchPrintAndExplain(obj.*field_, matcher_, listener); } - bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, + bool MatchAndExplainImpl(std::true_type /* is_pointer */, const Class* p, MatchResultListener* listener) const { if (p == nullptr) return false; @@ -2419,7 +1731,7 @@ class FieldMatcher { // Since *p has a field, it must be a class/struct/union type and // thus cannot be a pointer. Therefore we pass false_type() as // the first argument. - return MatchAndExplainImpl(false_type(), *p, listener); + return MatchAndExplainImpl(std::false_type(), *p, listener); } const FieldType Class::*field_; @@ -2440,11 +1752,7 @@ class FieldMatcher { template <typename Class, typename PropertyType, typename Property> class PropertyMatcher { public: - // The property may have a reference type, so 'const PropertyType&' - // may cause double references and fail to compile. That's why we - // need GTEST_REFERENCE_TO_CONST, which works regardless of - // PropertyType being a reference or not. - typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty; + typedef const PropertyType& RefToConstProperty; PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher) : property_(property), @@ -2470,32 +1778,22 @@ class PropertyMatcher { template <typename T> bool MatchAndExplain(const T&value, MatchResultListener* listener) const { return MatchAndExplainImpl( - typename ::testing::internal:: - is_pointer<GTEST_REMOVE_CONST_(T)>::type(), - value, listener); + typename std::is_pointer<GTEST_REMOVE_CONST_(T)>::type(), value, + listener); } private: - // The first argument of MatchAndExplainImpl() is needed to help - // Symbian's C++ compiler choose which overload to use. Its type is - // true_type iff the Property() matcher is used to match a pointer. - bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, + bool MatchAndExplainImpl(std::false_type /* is_not_pointer */, + const Class& obj, MatchResultListener* listener) const { *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 - // Workaround bug in VC++ 2013's /analyze parser. - // https://connect.microsoft.com/VisualStudio/feedback/details/1106363/internal-compiler-error-with-analyze-due-to-failure-to-infer-move - posix::Abort(); // To make sure it is never run. - return false; -#else RefToConstProperty result = (obj.*property_)(); return MatchPrintAndExplain(result, matcher_, listener); -#endif } - bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, + bool MatchAndExplainImpl(std::true_type /* is_pointer */, const Class* p, MatchResultListener* listener) const { if (p == nullptr) return false; @@ -2503,7 +1801,7 @@ class PropertyMatcher { // Since *p has a property method, it must be a class/struct/union // type and thus cannot be a pointer. Therefore we pass // false_type() as the first argument. - return MatchAndExplainImpl(false_type(), *p, listener); + return MatchAndExplainImpl(std::false_type(), *p, listener); } Property property_; @@ -2524,14 +1822,8 @@ struct CallableTraits { static void CheckIsValid(Functor /* functor */) {} -#if GTEST_LANG_CXX11 template <typename T> static auto Invoke(Functor f, T arg) -> decltype(f(arg)) { return f(arg); } -#else - typedef typename Functor::result_type ResultType; - template <typename T> - static ResultType Invoke(Functor f, T arg) { return f(arg); } -#endif }; // Specialization for function pointers. @@ -2570,29 +1862,25 @@ class ResultOfMatcher { template <typename T> class Impl : public MatcherInterface<T> { -#if GTEST_LANG_CXX11 using ResultType = decltype(CallableTraits<Callable>::template Invoke<T>( std::declval<CallableStorageType>(), std::declval<T>())); -#else - typedef typename CallableTraits<Callable>::ResultType ResultType; -#endif public: template <typename M> Impl(const CallableStorageType& callable, const M& matcher) : callable_(callable), matcher_(MatcherCast<ResultType>(matcher)) {} - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "is mapped by the given callable to a value that "; matcher_.DescribeTo(os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "is mapped by the given callable to a value that "; matcher_.DescribeNegationTo(os); } - virtual bool MatchAndExplain(T obj, MatchResultListener* listener) const { + bool MatchAndExplain(T obj, MatchResultListener* listener) const override { *listener << "which is mapped by the given callable to "; // Cannot pass the return value directly to MatchPrintAndExplain, which // takes a non-const reference as argument. @@ -2631,29 +1919,27 @@ class SizeIsMatcher { template <typename Container> operator Matcher<Container>() const { - return MakeMatcher(new Impl<Container>(size_matcher_)); + return Matcher<Container>(new Impl<const Container&>(size_matcher_)); } template <typename Container> class Impl : public MatcherInterface<Container> { public: - typedef internal::StlContainerView< - GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView; - typedef typename ContainerView::type::size_type SizeType; + using SizeType = decltype(std::declval<Container>().size()); explicit Impl(const SizeMatcher& size_matcher) : size_matcher_(MatcherCast<SizeType>(size_matcher)) {} - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "size "; size_matcher_.DescribeTo(os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "size "; size_matcher_.DescribeNegationTo(os); } - virtual bool MatchAndExplain(Container container, - MatchResultListener* listener) const { + bool MatchAndExplain(Container container, + MatchResultListener* listener) const override { SizeType size = container.size(); StringMatchResultListener size_listener; const bool result = size_matcher_.MatchAndExplain(size, &size_listener); @@ -2683,7 +1969,7 @@ class BeginEndDistanceIsMatcher { template <typename Container> operator Matcher<Container>() const { - return MakeMatcher(new Impl<Container>(distance_matcher_)); + return Matcher<Container>(new Impl<const Container&>(distance_matcher_)); } template <typename Container> @@ -2697,24 +1983,20 @@ class BeginEndDistanceIsMatcher { explicit Impl(const DistanceMatcher& distance_matcher) : distance_matcher_(MatcherCast<DistanceType>(distance_matcher)) {} - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "distance between begin() and end() "; distance_matcher_.DescribeTo(os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "distance between begin() and end() "; distance_matcher_.DescribeNegationTo(os); } - virtual bool MatchAndExplain(Container container, - MatchResultListener* listener) const { -#if GTEST_HAS_STD_BEGIN_AND_END_ + bool MatchAndExplain(Container container, + MatchResultListener* listener) const override { using std::begin; using std::end; DistanceType distance = std::distance(begin(container), end(container)); -#else - DistanceType distance = std::distance(container.begin(), container.end()); -#endif StringMatchResultListener distance_listener; const bool result = distance_matcher_.MatchAndExplain(distance, &distance_listener); @@ -2863,18 +2145,18 @@ class WhenSortedByMatcher { Impl(const Comparator& comparator, const ContainerMatcher& matcher) : comparator_(comparator), matcher_(matcher) {} - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "(when sorted) "; matcher_.DescribeTo(os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "(when sorted) "; matcher_.DescribeNegationTo(os); } - virtual bool MatchAndExplain(LhsContainer lhs, - MatchResultListener* listener) const { + bool MatchAndExplain(LhsContainer lhs, + MatchResultListener* listener) const override { LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(), lhs_stl_container.end()); @@ -2943,7 +2225,8 @@ class PointwiseMatcher { !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)>::value, use_UnorderedPointwise_with_hash_tables); - return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_)); + return Matcher<LhsContainer>( + new Impl<const LhsContainer&>(tuple_matcher_, rhs_)); } template <typename LhsContainer> @@ -2965,14 +2248,14 @@ class PointwiseMatcher { : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)), rhs_(rhs) {} - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "contains " << rhs_.size() << " values, where each value and its corresponding value in "; UniversalPrinter<RhsStlContainer>::Print(rhs_, os); *os << " "; mono_tuple_matcher_.DescribeTo(os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "doesn't contain exactly " << rhs_.size() << " values, or contains a value x at some index i" << " where x and the i-th value of "; @@ -2981,8 +2264,8 @@ class PointwiseMatcher { mono_tuple_matcher_.DescribeNegationTo(os); } - virtual bool MatchAndExplain(LhsContainer lhs, - MatchResultListener* listener) const { + bool MatchAndExplain(LhsContainer lhs, + MatchResultListener* listener) const override { LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); const size_t actual_size = lhs_stl_container.size(); if (actual_size != rhs_.size()) { @@ -3089,18 +2372,18 @@ class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> { : QuantifierMatcherImpl<Container>(inner_matcher) {} // Describes what this matcher does. - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "contains at least one element that "; this->inner_matcher_.DescribeTo(os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "doesn't contain any element that "; this->inner_matcher_.DescribeTo(os); } - virtual bool MatchAndExplain(Container container, - MatchResultListener* listener) const { + bool MatchAndExplain(Container container, + MatchResultListener* listener) const override { return this->MatchAndExplainImpl(false, container, listener); } @@ -3118,18 +2401,18 @@ class EachMatcherImpl : public QuantifierMatcherImpl<Container> { : QuantifierMatcherImpl<Container>(inner_matcher) {} // Describes what this matcher does. - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "only contains elements that "; this->inner_matcher_.DescribeTo(os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "contains some element that "; this->inner_matcher_.DescribeNegationTo(os); } - virtual bool MatchAndExplain(Container container, - MatchResultListener* listener) const { + bool MatchAndExplain(Container container, + MatchResultListener* listener) const override { return this->MatchAndExplainImpl(true, container, listener); } @@ -3145,7 +2428,8 @@ class ContainsMatcher { template <typename Container> operator Matcher<Container>() const { - return MakeMatcher(new ContainsMatcherImpl<Container>(inner_matcher_)); + return Matcher<Container>( + new ContainsMatcherImpl<const Container&>(inner_matcher_)); } private: @@ -3162,7 +2446,8 @@ class EachMatcher { template <typename Container> operator Matcher<Container>() const { - return MakeMatcher(new EachMatcherImpl<Container>(inner_matcher_)); + return Matcher<Container>( + new EachMatcherImpl<const Container&>(inner_matcher_)); } private: @@ -3175,7 +2460,6 @@ 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 @@ -3194,25 +2478,6 @@ 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. @@ -3232,8 +2497,8 @@ class KeyMatcherImpl : public MatcherInterface<PairType> { } // Returns true iff 'key_value.first' (the key) matches the inner matcher. - virtual bool MatchAndExplain(PairType key_value, - MatchResultListener* listener) const { + bool MatchAndExplain(PairType key_value, + MatchResultListener* listener) const override { StringMatchResultListener inner_listener; const bool match = inner_matcher_.MatchAndExplain( pair_getters::First(key_value, Rank0()), &inner_listener); @@ -3245,13 +2510,13 @@ class KeyMatcherImpl : public MatcherInterface<PairType> { } // Describes what this matcher does. - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "has a key that "; inner_matcher_.DescribeTo(os); } // Describes what the negation of this matcher does. - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "doesn't have a key that "; inner_matcher_.DescribeTo(os); } @@ -3270,7 +2535,8 @@ class KeyMatcher { template <typename PairType> operator Matcher<PairType>() const { - return MakeMatcher(new KeyMatcherImpl<PairType>(matcher_for_key_)); + return Matcher<PairType>( + new KeyMatcherImpl<const PairType&>(matcher_for_key_)); } private: @@ -3297,7 +2563,7 @@ class PairMatcherImpl : public MatcherInterface<PairType> { } // Describes what this matcher does. - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "has a first field that "; first_matcher_.DescribeTo(os); *os << ", and has a second field that "; @@ -3305,7 +2571,7 @@ class PairMatcherImpl : public MatcherInterface<PairType> { } // Describes what the negation of this matcher does. - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "has a first field that "; first_matcher_.DescribeNegationTo(os); *os << ", or has a second field that "; @@ -3314,8 +2580,8 @@ class PairMatcherImpl : public MatcherInterface<PairType> { // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.second' // matches second_matcher. - virtual bool MatchAndExplain(PairType a_pair, - MatchResultListener* listener) const { + bool MatchAndExplain(PairType a_pair, + MatchResultListener* listener) const override { if (!listener->IsInterested()) { // If the listener is not interested, we don't need to construct the // explanation. @@ -3375,9 +2641,8 @@ class PairMatcher { template <typename PairType> operator Matcher<PairType> () const { - return MakeMatcher( - new PairMatcherImpl<PairType>( - first_matcher_, second_matcher_)); + return Matcher<PairType>( + new PairMatcherImpl<const PairType&>(first_matcher_, second_matcher_)); } private: @@ -3407,7 +2672,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> { } // Describes what this matcher does. - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { if (count() == 0) { *os << "is empty"; } else if (count() == 1) { @@ -3426,7 +2691,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> { } // Describes what the negation of this matcher does. - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { if (count() == 0) { *os << "isn't empty"; return; @@ -3442,8 +2707,8 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> { } } - virtual bool MatchAndExplain(Container container, - MatchResultListener* listener) const { + bool MatchAndExplain(Container container, + MatchResultListener* listener) const override { // To work with stream-like "containers", we must only walk // through the elements in one pass. @@ -3663,17 +2928,17 @@ class UnorderedElementsAreMatcherImpl } // Describes what this matcher does. - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os); } // Describes what the negation of this matcher does. - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os); } - virtual bool MatchAndExplain(Container container, - MatchResultListener* listener) const { + bool MatchAndExplain(Container container, + MatchResultListener* listener) const override { StlContainerReference stl_container = View::ConstReference(container); ::std::vector<std::string> element_printouts; MatchMatrix matrix = @@ -3760,8 +3025,10 @@ class UnorderedElementsAreMatcher { matchers.reserve(::std::tuple_size<MatcherTuple>::value); TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_, ::std::back_inserter(matchers)); - return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>( - UnorderedMatcherRequire::ExactMatch, matchers.begin(), matchers.end())); + return Matcher<Container>( + new UnorderedElementsAreMatcherImpl<const Container&>( + UnorderedMatcherRequire::ExactMatch, matchers.begin(), + matchers.end())); } private: @@ -3790,8 +3057,8 @@ class ElementsAreMatcher { matchers.reserve(::std::tuple_size<MatcherTuple>::value); TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_, ::std::back_inserter(matchers)); - return MakeMatcher(new ElementsAreMatcherImpl<Container>( - matchers.begin(), matchers.end())); + return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>( + matchers.begin(), matchers.end())); } private: @@ -3810,8 +3077,9 @@ class UnorderedElementsAreArrayMatcher { template <typename Container> operator Matcher<Container>() const { - return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>( - match_flags_, matchers_.begin(), matchers_.end())); + return Matcher<Container>( + new UnorderedElementsAreMatcherImpl<const Container&>( + match_flags_, matchers_.begin(), matchers_.end())); } private: @@ -3834,7 +3102,7 @@ class ElementsAreArrayMatcher { !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value, use_UnorderedElementsAreArray_with_hash_tables); - return MakeMatcher(new ElementsAreMatcherImpl<Container>( + return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>( matchers_.begin(), matchers_.end())); } @@ -3886,14 +3154,14 @@ class BoundSecondMatcher { : mono_tuple2_matcher_(SafeMatcherCast<const ArgTuple&>(tm)), second_value_(second) {} - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "and "; UniversalPrint(second_value_, os); *os << " "; mono_tuple2_matcher_.DescribeTo(os); } - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + bool MatchAndExplain(T x, MatchResultListener* listener) const override { return mono_tuple2_matcher_.MatchAndExplain(ArgTuple(x, second_value_), listener); } @@ -3937,7 +3205,7 @@ class OptionalMatcher { template <typename Optional> operator Matcher<Optional>() const { - return MakeMatcher(new Impl<Optional>(value_matcher_)); + return Matcher<Optional>(new Impl<const Optional&>(value_matcher_)); } template <typename Optional> @@ -3948,18 +3216,18 @@ class OptionalMatcher { explicit Impl(const ValueMatcher& value_matcher) : value_matcher_(MatcherCast<ValueType>(value_matcher)) {} - virtual void DescribeTo(::std::ostream* os) const { + void DescribeTo(::std::ostream* os) const override { *os << "value "; value_matcher_.DescribeTo(os); } - virtual void DescribeNegationTo(::std::ostream* os) const { + void DescribeNegationTo(::std::ostream* os) const override { *os << "value "; value_matcher_.DescribeNegationTo(os); } - virtual bool MatchAndExplain(Optional optional, - MatchResultListener* listener) const { + bool MatchAndExplain(Optional optional, + MatchResultListener* listener) const override { if (!optional) { *listener << "which is not engaged"; return false; @@ -4105,6 +3373,80 @@ class AnyCastMatcher { }; } // namespace any_cast_matcher + +// Implements the Args() matcher. +template <class ArgsTuple, size_t... k> +class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> { + public: + using RawArgsTuple = typename std::decay<ArgsTuple>::type; + using SelectedArgs = + std::tuple<typename std::tuple_element<k, RawArgsTuple>::type...>; + using MonomorphicInnerMatcher = Matcher<const SelectedArgs&>; + + template <typename InnerMatcher> + explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) + : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {} + + bool MatchAndExplain(ArgsTuple args, + MatchResultListener* listener) const override { + // Workaround spurious C4100 on MSVC<=15.7 when k is empty. + (void)args; + const SelectedArgs& selected_args = + std::forward_as_tuple(std::get<k>(args)...); + if (!listener->IsInterested()) return inner_matcher_.Matches(selected_args); + + PrintIndices(listener->stream()); + *listener << "are " << PrintToString(selected_args); + + StringMatchResultListener inner_listener; + const bool match = + inner_matcher_.MatchAndExplain(selected_args, &inner_listener); + PrintIfNotEmpty(inner_listener.str(), listener->stream()); + return match; + } + + void DescribeTo(::std::ostream* os) const override { + *os << "are a tuple "; + PrintIndices(os); + inner_matcher_.DescribeTo(os); + } + + void DescribeNegationTo(::std::ostream* os) const override { + *os << "are a tuple "; + PrintIndices(os); + inner_matcher_.DescribeNegationTo(os); + } + + private: + // Prints the indices of the selected fields. + static void PrintIndices(::std::ostream* os) { + *os << "whose fields ("; + const char* sep = ""; + // Workaround spurious C4189 on MSVC<=15.7 when k is empty. + (void)sep; + const char* dummy[] = {"", (*os << sep << "#" << k, sep = ", ")...}; + (void)dummy; + *os << ") "; + } + + MonomorphicInnerMatcher inner_matcher_; +}; + +template <class InnerMatcher, size_t... k> +class ArgsMatcher { + public: + explicit ArgsMatcher(InnerMatcher inner_matcher) + : inner_matcher_(std::move(inner_matcher)) {} + + template <typename ArgsTuple> + operator Matcher<ArgsTuple>() const { // NOLINT + return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k...>(inner_matcher_)); + } + + private: + InnerMatcher inner_matcher_; +}; + } // namespace internal // ElementsAreArray(iterator_first, iterator_last) @@ -4148,13 +3490,11 @@ ElementsAreArray(const Container& container) { return ElementsAreArray(container.begin(), container.end()); } -#if GTEST_HAS_STD_INITIALIZER_LIST_ template <typename T> inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(::std::initializer_list<T> xs) { return ElementsAreArray(xs.begin(), xs.end()); } -#endif // UnorderedElementsAreArray(iterator_first, iterator_last) // UnorderedElementsAreArray(pointer, count) @@ -4197,13 +3537,11 @@ UnorderedElementsAreArray(const Container& container) { return UnorderedElementsAreArray(container.begin(), container.end()); } -#if GTEST_HAS_STD_INITIALIZER_LIST_ template <typename T> inline internal::UnorderedElementsAreArrayMatcher<T> UnorderedElementsAreArray(::std::initializer_list<T> xs) { return UnorderedElementsAreArray(xs.begin(), xs.end()); } -#endif // _ is a matcher that matches anything of any type. // @@ -4225,17 +3563,6 @@ inline Matcher<T> A() { template <typename T> inline Matcher<T> An() { return A<T>(); } -// Creates a polymorphic matcher that matches anything equal to x. -// Note: if the parameter of Eq() were declared as const T&, Eq("foo") -// wouldn't compile. -template <typename T> -inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); } - -// Constructs a Matcher<T> from a 'value' of type T. The constructed -// matcher matches any value that's equal to 'value'. -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, @@ -4244,51 +3571,6 @@ Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl( 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. -// -// TypedEq<T>(x) is just a convenient short-hand for Matcher<T>(Eq(x)) -// or Matcher<T>(x), but more readable than the latter. -// -// We could define similar monomorphic matchers for other comparison -// operations (e.g. TypedLt, TypedGe, and etc), but decided not to do -// it yet as those are used much less than Eq() in practice. A user -// can always write Matcher<T>(Lt(5)) to be explicit about the type, -// for example. -template <typename Lhs, typename Rhs> -inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); } - -// Creates a polymorphic matcher that matches anything >= x. -template <typename Rhs> -inline internal::GeMatcher<Rhs> Ge(Rhs x) { - return internal::GeMatcher<Rhs>(x); -} - -// Creates a polymorphic matcher that matches anything > x. -template <typename Rhs> -inline internal::GtMatcher<Rhs> Gt(Rhs x) { - return internal::GtMatcher<Rhs>(x); -} - -// Creates a polymorphic matcher that matches anything <= x. -template <typename Rhs> -inline internal::LeMatcher<Rhs> Le(Rhs x) { - return internal::LeMatcher<Rhs>(x); -} - -// Creates a polymorphic matcher that matches anything < x. -template <typename Rhs> -inline internal::LtMatcher<Rhs> Lt(Rhs x) { - return internal::LtMatcher<Rhs>(x); -} - -// Creates a polymorphic matcher that matches anything != x. -template <typename Rhs> -inline internal::NeMatcher<Rhs> Ne(Rhs x) { - return internal::NeMatcher<Rhs>(x); -} - // Creates a polymorphic matcher that matches any NULL pointer. inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() { return MakePolymorphicMatcher(internal::IsNullMatcher()); @@ -4426,8 +3708,7 @@ Property(PropertyType (Class::*property)() const, return MakePolymorphicMatcher( internal::PropertyMatcher<Class, PropertyType, PropertyType (Class::*)() const>( - property, - MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); + property, MatcherCast<const PropertyType&>(matcher))); // The call to MatcherCast() is required for supporting inner // matchers of compatible types. For example, it allows // Property(&Foo::bar, m) @@ -4445,11 +3726,9 @@ Property(const std::string& property_name, return MakePolymorphicMatcher( internal::PropertyMatcher<Class, PropertyType, PropertyType (Class::*)() const>( - property_name, property, - MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); + property_name, property, MatcherCast<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< @@ -4458,9 +3737,8 @@ 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))); + PropertyType (Class::*)() const&>( + property, MatcherCast<const PropertyType&>(matcher))); } // Three-argument form for reference-qualified member functions. @@ -4472,11 +3750,9 @@ Property(const std::string& property_name, const PropertyMatcher& matcher) { return MakePolymorphicMatcher( internal::PropertyMatcher<Class, PropertyType, - PropertyType (Class::*)() const &>( - property_name, property, - MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher))); + PropertyType (Class::*)() const&>( + property_name, property, MatcherCast<const PropertyType&>(matcher))); } -#endif // Creates a matcher that matches an object iff the result of applying // a callable to x matches 'matcher'. @@ -4545,28 +3821,6 @@ inline PolymorphicMatcher<internal::EndsWithMatcher<std::string> > EndsWith( return MakePolymorphicMatcher(internal::EndsWithMatcher<std::string>(suffix)); } -// Matches a string that fully matches regular expression 'regex'. -// The matcher takes ownership of 'regex'. -inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( - const internal::RE* regex) { - return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true)); -} -inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( - const std::string& regex) { - return MatchesRegex(new internal::RE(regex)); -} - -// Matches a string that contains regular expression 'regex'. -// The matcher takes ownership of 'regex'. -inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( - const internal::RE* regex) { - return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false)); -} -inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( - const std::string& regex) { - return ContainsRegex(new internal::RE(regex)); -} - #if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING // Wide string matchers. @@ -4790,7 +4044,6 @@ Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) { tuple_matcher, rhs); } -#if GTEST_HAS_STD_INITIALIZER_LIST_ // Supports the Pointwise(m, {a, b, c}) syntax. template <typename TupleMatcher, typename T> @@ -4799,7 +4052,6 @@ inline internal::PointwiseMatcher<TupleMatcher, std::vector<T> > Pointwise( return Pointwise(tuple_matcher, std::vector<T>(rhs)); } -#endif // GTEST_HAS_STD_INITIALIZER_LIST_ // UnorderedPointwise(pair_matcher, rhs) matches an STL-style // container or a native array that contains the same number of @@ -4844,7 +4096,6 @@ UnorderedPointwise(const Tuple2Matcher& tuple2_matcher, return UnorderedElementsAreArray(matchers); } -#if GTEST_HAS_STD_INITIALIZER_LIST_ // Supports the UnorderedPointwise(m, {a, b, c}) syntax. template <typename Tuple2Matcher, typename T> @@ -4855,7 +4106,6 @@ UnorderedPointwise(const Tuple2Matcher& tuple2_matcher, return UnorderedPointwise(tuple2_matcher, std::vector<T>(rhs)); } -#endif // GTEST_HAS_STD_INITIALIZER_LIST_ // Matches an STL-style container or a native array that contains at // least one element matching the given value or matcher. @@ -4935,13 +4185,11 @@ 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) @@ -4994,13 +4242,11 @@ 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. @@ -5130,6 +4376,16 @@ internal::AnyOfMatcher<typename std::decay<const Args&>::type...> AnyOf( matchers...); } +// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected +// fields of it matches a_matcher. C++ doesn't support default +// arguments for function templates, so we have to overload it. +template <size_t... k, typename InnerMatcher> +internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...> Args( + InnerMatcher&& matcher) { + return internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...>( + std::forward<InnerMatcher>(matcher)); +} + // AllArgs(m) is a synonym of m. This is useful in // // EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq())); diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-more-actions.h b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-more-actions.h index 5c6dc8bb717..a052495d00f 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-more-actions.h +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-more-actions.h @@ -38,59 +38,13 @@ #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ #include <algorithm> +#include <type_traits> #include "gmock/gmock-generated-actions.h" namespace testing { namespace internal { -// Implements the Invoke(f) action. The template argument -// FunctionImpl is the implementation type of f, which can be either a -// function pointer or a functor. Invoke(f) can be used as an -// Action<F> as long as f's type is compatible with F (i.e. f can be -// assigned to a tr1::function<F>). -template <typename FunctionImpl> -class InvokeAction { - public: - // The c'tor makes a copy of function_impl (either a function - // pointer or a functor). - explicit InvokeAction(FunctionImpl function_impl) - : function_impl_(function_impl) {} - - template <typename Result, typename ArgumentTuple> - Result Perform(const ArgumentTuple& args) { - return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args); - } - - private: - FunctionImpl function_impl_; - - GTEST_DISALLOW_ASSIGN_(InvokeAction); -}; - -// Implements the Invoke(object_ptr, &Class::Method) action. -template <class Class, typename MethodPtr> -class InvokeMethodAction { - public: - InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr) - : method_ptr_(method_ptr), obj_ptr_(obj_ptr) {} - - template <typename Result, typename ArgumentTuple> - Result Perform(const ArgumentTuple& args) const { - return InvokeHelper<Result, ArgumentTuple>::InvokeMethod( - obj_ptr_, method_ptr_, args); - } - - private: - // The order of these members matters. Reversing the order can trigger - // warning C4121 in MSVC (see - // http://computer-programming-forum.com/7-vc.net/6fbc30265f860ad1.htm ). - const MethodPtr method_ptr_; - Class* const obj_ptr_; - - GTEST_DISALLOW_ASSIGN_(InvokeMethodAction); -}; - // An internal replacement for std::copy which mimics its behavior. This is // necessary because Visual Studio deprecates ::std::copy, issuing warning 4996. // However Visual Studio 2010 and later do not honor #pragmas which disable that @@ -109,45 +63,6 @@ inline OutputIterator CopyElements(InputIterator first, // Various overloads for Invoke(). -// Creates an action that invokes 'function_impl' with the mock -// function's arguments. -template <typename FunctionImpl> -PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke( - FunctionImpl function_impl) { - return MakePolymorphicAction( - internal::InvokeAction<FunctionImpl>(function_impl)); -} - -// Creates an action that invokes the given method on the given object -// with the mock function's arguments. -template <class Class, typename MethodPtr> -PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke( - Class* obj_ptr, MethodPtr method_ptr) { - return MakePolymorphicAction( - internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr)); -} - -// WithoutArgs(inner_action) can be used in a mock function with a -// non-empty argument list to perform inner_action, which takes no -// argument. In other words, it adapts an action accepting no -// argument to one that accepts (and ignores) arguments. -template <typename InnerAction> -inline internal::WithArgsAction<InnerAction> -WithoutArgs(const InnerAction& action) { - return internal::WithArgsAction<InnerAction>(action); -} - -// WithArg<k>(an_action) creates an action that passes the k-th -// (0-based) argument of the mock function to an_action and performs -// it. It adapts an action accepting one argument to one that accepts -// multiple arguments. For convenience, we also provide -// WithArgs<k>(an_action) (defined below) as a synonym. -template <int k, typename InnerAction> -inline internal::WithArgsAction<InnerAction, k> -WithArg(const InnerAction& action) { - return internal::WithArgsAction<InnerAction, k>(action); -} - // The ACTION*() macros trigger warning C4100 (unreferenced formal // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in // the macro definition, as the warnings are generated when the macro diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-nice-strict.h.pump b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-nice-strict.h index ed49f4ab0be..5495a9805b5 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-generated-nice-strict.h.pump +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-nice-strict.h @@ -1,8 +1,3 @@ -$$ -*- mode: c++; -*- -$$ 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. // All rights reserved. // @@ -65,34 +60,60 @@ $var n = 10 $$ The maximum arity we support. // GOOGLETEST_CM0002 DO NOT DELETE -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ #include "gmock/gmock-spec-builders.h" #include "gmock/internal/gmock-port.h" namespace testing { -$range kind 0..2 -$for kind [[ +template <class MockClass> +class NiceMock : public MockClass { + public: + NiceMock() : MockClass() { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_<MockClass*>(this)); + } -$var clazz=[[$if kind==0 [[NiceMock]] - $elif kind==1 [[NaggyMock]] - $else [[StrictMock]]]] + // 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. -$var method=[[$if kind==0 [[AllowUninterestingCalls]] - $elif kind==1 [[WarnUninterestingCalls]] - $else [[FailUninterestingCalls]]]] + // 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)); + } + + 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)); + } + + ~NiceMock() { // NOLINT + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_<MockClass*>(this)); + } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); +}; template <class MockClass> -class $clazz : public MockClass { +class NaggyMock : public MockClass { public: - $clazz() : MockClass() { - ::testing::Mock::$method( + NaggyMock() : MockClass() { + ::testing::Mock::WarnUninterestingCalls( 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 @@ -101,51 +122,66 @@ class $clazz : public MockClass { // 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( + explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) { + ::testing::Mock::WarnUninterestingCalls( internal::ImplicitCast_<MockClass*>(this)); } template <typename A1, typename A2, typename... An> - $clazz(A1&& arg1, A2&& arg2, An&&... args) + NaggyMock(A1&& arg1, A2&& arg2, An&&... args) : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2), std::forward<An>(args)...) { - ::testing::Mock::$method( + ::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 $clazz(const A1& a1) : MockClass(a1) { - ::testing::Mock::$method( + + ~NaggyMock() { // NOLINT + ::testing::Mock::UnregisterCallReaction( internal::ImplicitCast_<MockClass*>(this)); } -$range i 2..n -$for i [[ -$range j 1..i - template <$for j, [[typename A$j]]> - $clazz($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) { - ::testing::Mock::$method( + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock); +}; + +template <class MockClass> +class StrictMock : public MockClass { + public: + StrictMock() : MockClass() { + ::testing::Mock::FailUninterestingCalls( internal::ImplicitCast_<MockClass*>(this)); } + // 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)); + } -]] -#endif // GTEST_LANG_CXX11 + 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)); + } - ~$clazz() { + ~StrictMock() { // NOLINT ::testing::Mock::UnregisterCallReaction( internal::ImplicitCast_<MockClass*>(this)); } private: - GTEST_DISALLOW_COPY_AND_ASSIGN_($clazz); + GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); }; -]] - // The following specializations catch some (relatively more common) // user errors of nesting nice and strict mocks. They do NOT catch // all possible errors. @@ -176,4 +212,4 @@ class StrictMock<StrictMock<MockClass> >; } // namespace testing -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ +#endif // GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-spec-builders.h b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-spec-builders.h index e58adfcbef6..9a81cfbc4cd 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-spec-builders.h +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock-spec-builders.h @@ -106,9 +106,6 @@ template <typename F> class TypedExpectation; // Helper class for testing the Expectation class template. class ExpectationTester; -// Base class for function mockers. -template <typename F> class FunctionMockerBase; - // Protects the mock object registry (in class Mock), all function // mockers, and all expectations. // @@ -125,9 +122,9 @@ GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex); // Untyped base class for ActionResultHolder<R>. class UntypedActionResultHolderBase; -// Abstract base class of FunctionMockerBase. This is the +// Abstract base class of FunctionMocker. This is the // type-agnostic part of the function mocker interface. Its pure -// virtual methods are implemented by FunctionMockerBase. +// virtual methods are implemented by FunctionMocker. class GTEST_API_ UntypedFunctionMockerBase { public: UntypedFunctionMockerBase(); @@ -189,7 +186,6 @@ class GTEST_API_ UntypedFunctionMockerBase { // this information in the global mock registry. Will be called // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock // method. - // FIXME: rename to SetAndRegisterOwner(). void RegisterOwner(const void* mock_obj) GTEST_LOCK_EXCLUDED_(g_gmock_mutex); @@ -305,11 +301,9 @@ class OnCallSpec : public UntypedOnCallSpecBase { : UntypedOnCallSpecBase(a_file, a_line), matchers_(matchers), // By default, extra_matcher_ should match anything. However, - // we cannot initialize it with _ as that triggers a compiler - // bug in Symbian's C++ compiler (cannot decide between two - // overloaded constructors of Matcher<const ArgumentTuple&>). - extra_matcher_(A<const ArgumentTuple&>()) { - } + // we cannot initialize it with _ as that causes ambiguity between + // Matcher's copy and move constructor for some argument types. + extra_matcher_(A<const ArgumentTuple&>()) {} // Implements the .With() clause. OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) { @@ -415,7 +409,7 @@ class GTEST_API_ Mock { // Needed for a function mocker to register itself (so that we know // how to clear a mock object). template <typename F> - friend class internal::FunctionMockerBase; + friend class internal::FunctionMocker; template <typename M> friend class NiceMock; @@ -478,7 +472,7 @@ class GTEST_API_ Mock { // Unregisters a mock method; removes the owning mock object from // the registry when the last mock method associated with it has // been unregistered. This is called only in the destructor of - // FunctionMockerBase. + // FunctionMocker. static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker) GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex); }; // class Mock @@ -534,7 +528,7 @@ class GTEST_API_ Expectation { friend class ::testing::internal::UntypedFunctionMockerBase; template <typename F> - friend class ::testing::internal::FunctionMockerBase; + friend class ::testing::internal::FunctionMocker; template <typename F> friend class ::testing::internal::TypedExpectation; @@ -893,20 +887,19 @@ 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, + TypedExpectation(FunctionMocker<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), matchers_(m), // By default, extra_matcher_ should match anything. However, - // we cannot initialize it with _ as that triggers a compiler - // bug in Symbian's C++ compiler (cannot decide between two - // overloaded constructors of Matcher<const ArgumentTuple&>). + // we cannot initialize it with _ as that causes ambiguity between + // Matcher's copy and move constructor for some argument types. extra_matcher_(A<const ArgumentTuple&>()), repeated_action_(DoDefault()) {} - virtual ~TypedExpectation() { + ~TypedExpectation() override { // Check the validity of the action count if it hasn't been done // yet (for example, if the expectation was never used). CheckActionCountIfNotDone(); @@ -1072,7 +1065,7 @@ class TypedExpectation : public ExpectationBase { // If this mock method has an extra matcher (i.e. .With(matcher)), // describes it to the ostream. - virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) { + void MaybeDescribeExtraMatcherTo(::std::ostream* os) override { if (extra_matcher_specified_) { *os << " Expected args: "; extra_matcher_.DescribeTo(os); @@ -1082,13 +1075,11 @@ class TypedExpectation : public ExpectationBase { private: template <typename Function> - friend class FunctionMockerBase; + friend class FunctionMocker; // Returns an Expectation object that references and co-owns this // expectation. - virtual Expectation GetHandle() { - return owner_->GetHandleOf(this); - } + Expectation GetHandle() override { return owner_->GetHandleOf(this); } // The following methods will be called only after the EXPECT_CALL() // statement finishes and when the current thread holds @@ -1161,10 +1152,9 @@ class TypedExpectation : public ExpectationBase { } // Returns the action that should be taken for the current invocation. - const Action<F>& GetCurrentAction( - const FunctionMockerBase<F>* mocker, - const ArgumentTuple& args) const - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { + const Action<F>& GetCurrentAction(const FunctionMocker<F>* mocker, + const ArgumentTuple& args) const + GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { g_gmock_mutex.AssertHeld(); const int count = call_count(); Assert(count >= 1, __FILE__, __LINE__, @@ -1199,12 +1189,11 @@ class TypedExpectation : public ExpectationBase { // Mock does it to 'why'. This method is not const as it calls // IncrementCallCount(). A return value of NULL means the default // action. - const Action<F>* GetActionForArguments( - const FunctionMockerBase<F>* mocker, - const ArgumentTuple& args, - ::std::ostream* what, - ::std::ostream* why) - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { + const Action<F>* GetActionForArguments(const FunctionMocker<F>* mocker, + const ArgumentTuple& args, + ::std::ostream* what, + ::std::ostream* why) + GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { g_gmock_mutex.AssertHeld(); if (IsSaturated()) { // We have an excessive call. @@ -1213,9 +1202,6 @@ class TypedExpectation : public ExpectationBase { mocker->DescribeDefaultActionTo(args, what); DescribeCallCountTo(why); - // FIXME: allow the user to control whether - // unexpected calls should fail immediately or continue using a - // flag --gmock_unexpected_calls_are_fatal. return nullptr; } @@ -1233,7 +1219,7 @@ class TypedExpectation : public ExpectationBase { // All the fields below won't change once the EXPECT_CALL() // statement finishes. - FunctionMockerBase<F>* const owner_; + FunctionMocker<F>* const owner_; ArgumentMatcherTuple matchers_; Matcher<const ArgumentTuple&> extra_matcher_; Action<F> repeated_action_; @@ -1265,7 +1251,7 @@ class MockSpec { // Constructs a MockSpec object, given the function mocker object // that the spec is associated with. - MockSpec(internal::FunctionMockerBase<F>* function_mocker, + MockSpec(internal::FunctionMocker<F>* function_mocker, const ArgumentMatcherTuple& matchers) : function_mocker_(function_mocker), matchers_(matchers) {} @@ -1301,7 +1287,7 @@ class MockSpec { friend class internal::FunctionMocker; // The function mocker that owns this spec. - internal::FunctionMockerBase<F>* const function_mocker_; + internal::FunctionMocker<F>* const function_mocker_; // The argument matchers specified in the spec. ArgumentMatcherTuple matchers_; @@ -1392,7 +1378,7 @@ class ActionResultHolder : public UntypedActionResultHolderBase { } // Prints the held value as an action's result to os. - virtual void PrintAsActionResult(::std::ostream* os) const { + void PrintAsActionResult(::std::ostream* os) const override { *os << "\n Returns: "; // T may be a reference type, so we don't use UniversalPrint(). UniversalPrinter<T>::Print(result_.Peek(), os); @@ -1402,7 +1388,7 @@ class ActionResultHolder : public UntypedActionResultHolderBase { // result in a new-ed ActionResultHolder. template <typename F> static ActionResultHolder* PerformDefaultAction( - const FunctionMockerBase<F>* func_mocker, + const FunctionMocker<F>* func_mocker, typename Function<F>::ArgumentTuple&& args, const std::string& call_description) { return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction( @@ -1436,13 +1422,13 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase { public: void Unwrap() { } - virtual void PrintAsActionResult(::std::ostream* /* os */) const {} + void PrintAsActionResult(::std::ostream* /* os */) const override {} // Performs the given mock function's default action and returns ownership // of an empty ActionResultHolder*. template <typename F> static ActionResultHolder* PerformDefaultAction( - const FunctionMockerBase<F>* func_mocker, + const FunctionMocker<F>* func_mocker, typename Function<F>::ArgumentTuple&& args, const std::string& call_description) { func_mocker->PerformDefaultAction(std::move(args), call_description); @@ -1463,23 +1449,39 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase { GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder); }; -// The base of the function mocker class for the given function type. -// We put the methods in this class instead of its child to avoid code -// bloat. template <typename F> -class FunctionMockerBase : public UntypedFunctionMockerBase { +class FunctionMocker; + +template <typename R, typename... Args> +class FunctionMocker<R(Args...)> : public UntypedFunctionMockerBase { + using F = R(Args...); + public: - typedef typename Function<F>::Result Result; - typedef typename Function<F>::ArgumentTuple ArgumentTuple; - typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; + using Result = R; + using ArgumentTuple = std::tuple<Args...>; + using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>; - FunctionMockerBase() {} + FunctionMocker() {} + + // 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, they should implement their own copy + // operation, for example: + // + // class MockFoo : public Foo { + // public: + // // Defines a copy constructor explicitly. + // MockFoo(const MockFoo& src) {} + // ... + // }; + FunctionMocker(const FunctionMocker&) = delete; + FunctionMocker& operator=(const FunctionMocker&) = delete; // The destructor verifies that all expectations on this mock // function have been satisfied. If not, it will report Google Test // non-fatal failures for the violations. - virtual ~FunctionMockerBase() - GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { + ~FunctionMocker() override GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { MutexLock l(&g_gmock_mutex); VerifyAndClearExpectationsLocked(); Mock::UnregisterLocked(this); @@ -1509,7 +1511,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // mutable state of this object, and thus can be called concurrently // without locking. // L = * - Result PerformDefaultAction(typename Function<F>::ArgumentTuple&& args, + Result PerformDefaultAction(ArgumentTuple&& args, const std::string& call_description) const { const OnCallSpec<F>* const spec = this->FindOnCallSpec(args); @@ -1535,9 +1537,9 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // the error message to describe the call in the case the default // action fails. The caller is responsible for deleting the result. // L = * - virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( + UntypedActionResultHolderBase* UntypedPerformDefaultAction( void* untyped_args, // must point to an ArgumentTuple - const std::string& call_description) const { + const std::string& call_description) const override { ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args); return ResultHolder::PerformDefaultAction(this, std::move(*args), call_description); @@ -1547,8 +1549,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // the action's result. The caller is responsible for deleting the // result. // L = * - virtual UntypedActionResultHolderBase* UntypedPerformAction( - const void* untyped_action, void* untyped_args) const { + UntypedActionResultHolderBase* UntypedPerformAction( + const void* untyped_action, void* untyped_args) const override { // 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); @@ -1558,7 +1560,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked(): // clears the ON_CALL()s set on this mock function. - virtual void ClearDefaultActionsLocked() + void ClearDefaultActionsLocked() override GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { g_gmock_mutex.AssertHeld(); @@ -1584,25 +1586,26 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { g_gmock_mutex.Lock(); } - protected: - template <typename Function> - friend class MockSpec; - - typedef ActionResultHolder<Result> ResultHolder; - // Returns the result of invoking this mock function with the given // arguments. This function can be safely called from multiple // threads concurrently. - Result InvokeWith(typename Function<F>::ArgumentTuple&& 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)); - std::unique_ptr<ResultHolder> holder( - DownCast_<ResultHolder*>(this->UntypedInvokeWith(untyped_args))); + Result Invoke(Args... args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { + ArgumentTuple tuple(std::forward<Args>(args)...); + std::unique_ptr<ResultHolder> holder(DownCast_<ResultHolder*>( + this->UntypedInvokeWith(static_cast<void*>(&tuple)))); return holder->Unwrap(); } + MockSpec<F> With(Matcher<Args>... m) { + return MockSpec<F>(this, ::std::make_tuple(std::move(m)...)); + } + + protected: + template <typename Function> + friend class MockSpec; + + typedef ActionResultHolder<Result> ResultHolder; + // Adds and returns a default action spec for this mock function. OnCallSpec<F>& AddNewOnCallSpec( const char* file, int line, @@ -1661,10 +1664,9 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // Writes a message that the call is uninteresting (i.e. neither // explicitly expected nor explicitly unexpected) to the given // ostream. - virtual void UntypedDescribeUninterestingCall( - const void* untyped_args, - ::std::ostream* os) const - GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { + void UntypedDescribeUninterestingCall(const void* untyped_args, + ::std::ostream* os) const override + GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { const ArgumentTuple& args = *static_cast<const ArgumentTuple*>(untyped_args); *os << "Uninteresting mock function call - "; @@ -1689,11 +1691,10 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // section. The reason is that we have no control on what the // action does (it can invoke an arbitrary user function or even a // mock function) and excessive locking could cause a dead lock. - virtual const ExpectationBase* UntypedFindMatchingExpectation( - const void* untyped_args, - const void** untyped_action, bool* is_excessive, - ::std::ostream* what, ::std::ostream* why) - GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { + const ExpectationBase* UntypedFindMatchingExpectation( + const void* untyped_args, const void** untyped_action, bool* is_excessive, + ::std::ostream* what, ::std::ostream* why) override + GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { const ArgumentTuple& args = *static_cast<const ArgumentTuple*>(untyped_args); MutexLock l(&g_gmock_mutex); @@ -1715,8 +1716,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { } // Prints the given function arguments to the ostream. - virtual void UntypedPrintArgs(const void* untyped_args, - ::std::ostream* os) const { + void UntypedPrintArgs(const void* untyped_args, + ::std::ostream* os) const override { const ArgumentTuple& args = *static_cast<const ArgumentTuple*>(untyped_args); UniversalPrint(args, os); @@ -1779,36 +1780,98 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { expectation->DescribeCallCountTo(why); } } - - // 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, they should implement their own copy - // operation, for example: - // - // class MockFoo : public Foo { - // public: - // // Defines a copy constructor explicitly. - // MockFoo(const MockFoo& src) {} - // ... - // }; - GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase); -}; // class FunctionMockerBase +}; // class FunctionMocker GTEST_DISABLE_MSC_WARNINGS_POP_() // 4355 -// Implements methods of FunctionMockerBase. - -// Verifies that all expectations on this mock function have been -// satisfied. Reports one or more Google Test non-fatal failures and -// returns false if not. - // Reports an uninteresting call (whose description is in msg) in the // manner specified by 'reaction'. void ReportUninterestingCall(CallReaction reaction, const std::string& msg); } // namespace internal +// A MockFunction<F> class has one mock method whose type is F. It is +// useful when you just want your test code to emit some messages and +// have Google Mock verify the right messages are sent (and perhaps at +// the right times). For example, if you are exercising code: +// +// Foo(1); +// Foo(2); +// Foo(3); +// +// and want to verify that Foo(1) and Foo(3) both invoke +// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: +// +// TEST(FooTest, InvokesBarCorrectly) { +// MyMock mock; +// MockFunction<void(string check_point_name)> check; +// { +// InSequence s; +// +// EXPECT_CALL(mock, Bar("a")); +// EXPECT_CALL(check, Call("1")); +// EXPECT_CALL(check, Call("2")); +// EXPECT_CALL(mock, Bar("a")); +// } +// Foo(1); +// check.Call("1"); +// Foo(2); +// check.Call("2"); +// Foo(3); +// } +// +// The expectation spec says that the first Bar("a") must happen +// before check point "1", the second Bar("a") must happen after check +// point "2", and nothing should happen between the two check +// points. The explicit check points make it easy to tell which +// Bar("a") is called by which call to Foo(). +// +// MockFunction<F> can also be used to exercise code that accepts +// std::function<F> callbacks. To do so, use AsStdFunction() method +// to create std::function proxy forwarding to original object's Call. +// Example: +// +// TEST(FooTest, RunsCallbackWithBarArgument) { +// MockFunction<int(string)> callback; +// EXPECT_CALL(callback, Call("bar")).WillOnce(Return(1)); +// Foo(callback.AsStdFunction()); +// } +template <typename F> +class MockFunction; + +template <typename R, typename... Args> +class MockFunction<R(Args...)> { + public: + MockFunction() {} + MockFunction(const MockFunction&) = delete; + MockFunction& operator=(const MockFunction&) = delete; + + std::function<R(Args...)> AsStdFunction() { + return [this](Args... args) -> R { + return this->Call(std::forward<Args>(args)...); + }; + } + + // Implementation detail: the expansion of the MOCK_METHOD macro. + R Call(Args... args) { + mock_.SetOwnerAndName(this, "Call"); + return mock_.Invoke(std::forward<Args>(args)...); + } + + internal::MockSpec<R(Args...)> gmock_Call(Matcher<Args>... m) { + mock_.RegisterOwner(this); + return mock_.With(std::move(m)...); + } + + internal::MockSpec<R(Args...)> gmock_Call(const internal::WithoutMatchers&, + R (*)(Args...)) { + return this->gmock_Call(::testing::A<Args>()...); + } + + private: + mutable internal::FunctionMocker<R(Args...)> mock_; +}; + // The style guide prohibits "using" statements in a namespace scope // inside a header file. However, the MockSpec class template is // meant to be defined in the ::testing namespace. The following line diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock.h b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock.h index dd962260564..c68ae1c7a51 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/gmock.h +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/gmock.h @@ -58,13 +58,14 @@ #include "gmock/gmock-actions.h" #include "gmock/gmock-cardinalities.h" +#include "gmock/gmock-function-mocker.h" #include "gmock/gmock-generated-actions.h" #include "gmock/gmock-generated-function-mockers.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" +#include "gmock/gmock-nice-strict.h" #include "gmock/internal/gmock-internal-utils.h" namespace testing { diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-generated-internal-utils.h b/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-generated-internal-utils.h deleted file mode 100644 index efa0462998c..00000000000 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-generated-internal-utils.h +++ /dev/null @@ -1,278 +0,0 @@ -// This file was GENERATED by command: -// pump.py gmock-generated-internal-utils.h.pump -// DO NOT EDIT BY HAND!!! - -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -// Google Mock - a framework for writing C++ mock classes. -// -// 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_ - -#include "gmock/internal/gmock-port.h" - -namespace testing { - -template <typename T> -class Matcher; - -namespace internal { - -// An IgnoredValue object can be implicitly constructed from ANY value. -// This is used in implementing the IgnoreResult(a) action. -class IgnoredValue { - public: - // This constructor template allows any value to be implicitly - // converted to IgnoredValue. The object has no data member and - // doesn't try to remember anything about the argument. We - // deliberately omit the 'explicit' keyword in order to allow the - // conversion to be implicit. - template <typename T> - IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit) -}; - -// MatcherTuple<T>::type is a tuple type where each field is a Matcher -// for the corresponding field in tuple type T. -template <typename Tuple> -struct MatcherTuple; - -template <> -struct MatcherTuple< ::std::tuple<> > { - typedef ::std::tuple< > type; -}; - -template <typename A1> -struct MatcherTuple< ::std::tuple<A1> > { - typedef ::std::tuple<Matcher<A1> > type; -}; - -template <typename A1, typename A2> -struct MatcherTuple< ::std::tuple<A1, A2> > { - typedef ::std::tuple<Matcher<A1>, Matcher<A2> > type; -}; - -template <typename A1, typename A2, typename A3> -struct MatcherTuple< ::std::tuple<A1, A2, A3> > { - typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3> > type; -}; - -template <typename A1, typename A2, typename A3, typename A4> -struct MatcherTuple< ::std::tuple<A1, A2, A3, A4> > { - typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, - Matcher<A4> > type; -}; - -template <typename A1, typename A2, typename A3, typename A4, typename A5> -struct MatcherTuple< ::std::tuple<A1, A2, A3, A4, A5> > { - typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - Matcher<A5> > type; -}; - -template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6> -struct MatcherTuple< ::std::tuple<A1, A2, A3, A4, A5, A6> > { - typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - Matcher<A5>, Matcher<A6> > type; -}; - -template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7> -struct MatcherTuple< ::std::tuple<A1, A2, A3, A4, A5, A6, A7> > { - typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - 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< ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > { - typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - 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< ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > { - typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9> > type; -}; - -template <typename A1, typename A2, typename A3, typename A4, typename A5, - typename A6, typename A7, typename A8, typename A9, typename A10> -struct MatcherTuple< ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10> > { - typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>, - 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 -// the following typedefs: -// -// Result: the function's return type. -// ArgumentN: the type of the N-th argument, where N starts with 1. -// ArgumentTuple: the tuple type consisting of all parameters of F. -// ArgumentMatcherTuple: the tuple type consisting of Matchers for all -// parameters of F. -// MakeResultVoid: the function type obtained by substituting void -// for the return type of F. -// MakeResultIgnoredValue: -// the function type obtained by substituting Something -// for the return type of F. -template <typename F> -struct Function; - -template <typename R> -struct Function<R()> { - typedef R Result; - typedef ::std::tuple<> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(); - typedef IgnoredValue MakeResultIgnoredValue(); -}; - -template <typename R, typename A1> -struct Function<R(A1)> - : Function<R()> { - typedef A1 Argument1; - typedef ::std::tuple<A1> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1); - typedef IgnoredValue MakeResultIgnoredValue(A1); -}; - -template <typename R, typename A1, typename A2> -struct Function<R(A1, A2)> - : Function<R(A1)> { - typedef A2 Argument2; - typedef ::std::tuple<A1, A2> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2); -}; - -template <typename R, typename A1, typename A2, typename A3> -struct Function<R(A1, A2, A3)> - : Function<R(A1, A2)> { - typedef A3 Argument3; - typedef ::std::tuple<A1, A2, A3> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3); -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4> -struct Function<R(A1, A2, A3, A4)> - : Function<R(A1, A2, A3)> { - typedef A4 Argument4; - typedef ::std::tuple<A1, A2, A3, A4> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4); -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5> -struct Function<R(A1, A2, A3, A4, A5)> - : Function<R(A1, A2, A3, A4)> { - typedef A5 Argument5; - typedef ::std::tuple<A1, A2, A3, A4, A5> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5); -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6> -struct Function<R(A1, A2, A3, A4, A5, A6)> - : Function<R(A1, A2, A3, A4, A5)> { - typedef A6 Argument6; - typedef ::std::tuple<A1, A2, A3, A4, A5, A6> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6); -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7> -struct Function<R(A1, A2, A3, A4, A5, A6, A7)> - : Function<R(A1, A2, A3, A4, A5, A6)> { - typedef A7 Argument7; - typedef ::std::tuple<A1, A2, A3, A4, A5, A6, A7> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7); -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7, typename A8> -struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> - : Function<R(A1, A2, A3, A4, A5, A6, A7)> { - typedef A8 Argument8; - typedef ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8); -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7, typename A8, typename A9> -struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> - : Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> { - typedef A9 Argument9; - typedef ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8, - A9); -}; - -template <typename R, typename A1, typename A2, typename A3, typename A4, - typename A5, typename A6, typename A7, typename A8, typename A9, - typename A10> -struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> - : Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> { - typedef A10 Argument10; - typedef ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8, - A9, A10); -}; - -} // namespace internal - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-generated-internal-utils.h.pump b/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-generated-internal-utils.h.pump deleted file mode 100644 index 9962f6b383d..00000000000 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-generated-internal-utils.h.pump +++ /dev/null @@ -1,137 +0,0 @@ -$$ -*- mode: c++; -*- -$$ 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. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -// Google Mock - a framework for writing C++ mock classes. -// -// 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_ - -#include "gmock/internal/gmock-port.h" - -namespace testing { - -template <typename T> -class Matcher; - -namespace internal { - -// An IgnoredValue object can be implicitly constructed from ANY value. -// This is used in implementing the IgnoreResult(a) action. -class IgnoredValue { - public: - // This constructor template allows any value to be implicitly - // converted to IgnoredValue. The object has no data member and - // doesn't try to remember anything about the argument. We - // deliberately omit the 'explicit' keyword in order to allow the - // conversion to be implicit. - template <typename T> - IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit) -}; - -// MatcherTuple<T>::type is a tuple type where each field is a Matcher -// for the corresponding field in tuple type T. -template <typename Tuple> -struct MatcherTuple; - - -$range i 0..n -$for i [[ -$range j 1..i -$var typename_As = [[$for j, [[typename A$j]]]] -$var As = [[$for j, [[A$j]]]] -$var matcher_As = [[$for j, [[Matcher<A$j>]]]] -template <$typename_As> -struct MatcherTuple< ::std::tuple<$As> > { - typedef ::std::tuple<$matcher_As > type; -}; - - -]] -// Template struct Function<F>, where F must be a function type, contains -// the following typedefs: -// -// Result: the function's return type. -// ArgumentN: the type of the N-th argument, where N starts with 1. -// ArgumentTuple: the tuple type consisting of all parameters of F. -// ArgumentMatcherTuple: the tuple type consisting of Matchers for all -// parameters of F. -// MakeResultVoid: the function type obtained by substituting void -// for the return type of F. -// MakeResultIgnoredValue: -// the function type obtained by substituting Something -// for the return type of F. -template <typename F> -struct Function; - -template <typename R> -struct Function<R()> { - typedef R Result; - typedef ::std::tuple<> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid(); - typedef IgnoredValue MakeResultIgnoredValue(); -}; - - -$range i 1..n -$for i [[ -$range j 1..i -$var typename_As = [[$for j [[, typename A$j]]]] -$var As = [[$for j, [[A$j]]]] -$var matcher_As = [[$for j, [[Matcher<A$j>]]]] -$range k 1..i-1 -$var prev_As = [[$for k, [[A$k]]]] -template <typename R$typename_As> -struct Function<R($As)> - : Function<R($prev_As)> { - typedef A$i Argument$i; - typedef ::std::tuple<$As> ArgumentTuple; - typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple; - typedef void MakeResultVoid($As); - typedef IgnoredValue MakeResultIgnoredValue($As); -}; - - -]] -} // namespace internal - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-internal-utils.h b/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-internal-utils.h index 7514635eb8c..093b46537fa 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -42,11 +42,15 @@ #include <stdio.h> #include <ostream> // NOLINT #include <string> -#include "gmock/internal/gmock-generated-internal-utils.h" +#include <type_traits> #include "gmock/internal/gmock-port.h" #include "gtest/gtest.h" namespace testing { + +template <typename> +class Matcher; + namespace internal { // Silence MSVC C4100 (unreferenced formal parameter) and @@ -92,16 +96,11 @@ inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) { template <typename Element> inline Element* GetRawPointer(Element* p) { return p; } -// Symbian compilation can be done with wchar_t being either a native -// type or a typedef. Using Google Mock with OpenC without wchar_t -// should require the definition of _STLP_NO_WCHAR_T. -// // MSVC treats wchar_t as a native type usually, but treats it as the // same as unsigned short when the compiler option /Zc:wchar_t- is // specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t // is a native type. -#if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \ - (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)) +#if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED) // wchar_t is a typedef. #else # define GMOCK_WCHAR_T_IS_NATIVE_ 1 @@ -351,8 +350,6 @@ class WithoutMatchers { // Internal use only: access the singleton instance of WithoutMatchers. GTEST_API_ WithoutMatchers GetWithoutMatchers(); -// FIXME: group all type utilities together. - // Type traits. // is_reference<T>::value is non-zero iff T is a reference type. @@ -452,32 +449,10 @@ class StlContainerView<Element[N]> { static const_reference ConstReference(const Element (&array)[N]) { // Ensures that Element is not a const type. testing::StaticAssertTypeEq<Element, RawElement>(); -#if GTEST_OS_SYMBIAN - // The Nokia Symbian compiler confuses itself in template instantiation - // for this call without the cast to Element*: - // function call '[testing::internal::NativeArray<char *>].NativeArray( - // {lval} const char *[4], long, testing::internal::RelationToSource)' - // does not match - // 'testing::internal::NativeArray<char *>::NativeArray( - // char *const *, unsigned int, testing::internal::RelationToSource)' - // (instantiating: 'testing::internal::ContainsMatcherImpl - // <const char * (&)[4]>::Matches(const char * (&)[4]) const') - // (instantiating: 'testing::internal::StlContainerView<char *[4]>:: - // ConstReference(const char * (&)[4])') - // (and though the N parameter type is mismatched in the above explicit - // conversion of it doesn't help - only the conversion of the array). - return type(const_cast<Element*>(&array[0]), N, - RelationToSourceReference()); -#else return type(array, N, RelationToSourceReference()); -#endif // GTEST_OS_SYMBIAN } static type Copy(const Element (&array)[N]) { -#if GTEST_OS_SYMBIAN - return type(const_cast<Element*>(&array[0]), N, RelationToSourceCopy()); -#else return type(array, N, RelationToSourceCopy()); -#endif // GTEST_OS_SYMBIAN } }; @@ -528,7 +503,6 @@ struct BooleanConstant {}; // 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; }; @@ -554,8 +528,38 @@ auto Apply(F&& f, Tuple&& args) return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), make_int_pack<std::tuple_size<Tuple>::value>()); } -#endif +// Template struct Function<F>, where F must be a function type, contains +// the following typedefs: +// +// Result: the function's return type. +// Arg<N>: the type of the N-th argument, where N starts with 0. +// ArgumentTuple: the tuple type consisting of all parameters of F. +// ArgumentMatcherTuple: the tuple type consisting of Matchers for all +// parameters of F. +// MakeResultVoid: the function type obtained by substituting void +// for the return type of F. +// MakeResultIgnoredValue: +// the function type obtained by substituting Something +// for the return type of F. +template <typename T> +struct Function; + +template <typename R, typename... Args> +struct Function<R(Args...)> { + using Result = R; + static constexpr size_t ArgumentCount = sizeof...(Args); + template <size_t I> + using Arg = ElemFromList<I, typename MakeIndexSequence<sizeof...(Args)>::type, + Args...>; + using ArgumentTuple = std::tuple<Args...>; + using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>; + using MakeResultVoid = void(Args...); + using MakeResultIgnoredValue = IgnoredValue(Args...); +}; + +template <typename R, typename... Args> +constexpr size_t Function<R(Args...)>::ArgumentCount; #ifdef _MSC_VER # pragma warning(pop) diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-port.h b/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-port.h index c5932493e22..063e2929acd 100644 --- a/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-port.h +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-port.h @@ -55,10 +55,10 @@ #include "gtest/internal/gtest-port.h" #include "gmock/internal/custom/gmock-port.h" -// For MS Visual C++, check the compiler version. At least VS 2003 is +// For MS Visual C++, check the compiler version. At least VS 2015 is // required to compile Google Mock. -#if defined(_MSC_VER) && _MSC_VER < 1310 -# error "At least Visual C++ 2003 (7.1) is required to compile Google Mock." +#if defined(_MSC_VER) && _MSC_VER < 1900 +# error "At least Visual C++ 2015 (14.0) is required to compile Google Mock." #endif // Macro for referencing flags. This is public as we want the user to diff --git a/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-pp.h b/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-pp.h new file mode 100644 index 00000000000..1ab80e1cdbe --- /dev/null +++ b/chromium/third_party/googletest/src/googlemock/include/gmock/internal/gmock-pp.h @@ -0,0 +1,317 @@ +#ifndef THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_ +#define THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_ + +#undef GMOCK_PP_INTERNAL_USE_MSVC +#if defined(__clang__) +#define GMOCK_PP_INTERNAL_USE_MSVC 0 +#elif defined(_MSC_VER) +// TODO(iserna): Also verify tradional versus comformant preprocessor. +static_assert( + _MSC_VER >= 1900, + "MSVC version not supported. There is support for MSVC 14.0 and above."); +#define GMOCK_PP_INTERNAL_USE_MSVC 1 +#else +#define GMOCK_PP_INTERNAL_USE_MSVC 0 +#endif + +// Expands and concatenates the arguments. Constructed macros reevaluate. +#define GMOCK_PP_CAT(_1, _2) GMOCK_PP_INTERNAL_CAT(_1, _2) + +// Expands and stringifies the only argument. +#define GMOCK_PP_STRINGIZE(...) GMOCK_PP_INTERNAL_STRINGIZE(__VA_ARGS__) + +// Returns empty. Given a variadic number of arguments. +#define GMOCK_PP_EMPTY(...) + +// Returns a comma. Given a variadic number of arguments. +#define GMOCK_PP_COMMA(...) , + +// Returns the only argument. +#define GMOCK_PP_IDENTITY(_1) _1 + +// MSVC preprocessor collapses __VA_ARGS__ in a single argument, we use a +// CAT-like directive to force correct evaluation. Each macro has its own. +#if GMOCK_PP_INTERNAL_USE_MSVC + +// Evaluates to the number of arguments after expansion. +// +// #define PAIR x, y +// +// GMOCK_PP_NARG() => 1 +// GMOCK_PP_NARG(x) => 1 +// GMOCK_PP_NARG(x, y) => 2 +// GMOCK_PP_NARG(PAIR) => 2 +// +// Requires: the number of arguments after expansion is at most 15. +#define GMOCK_PP_NARG(...) \ + GMOCK_PP_INTERNAL_NARG_CAT( \ + GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, \ + 8, 7, 6, 5, 4, 3, 2, 1), ) + +// Returns 1 if the expansion of arguments has an unprotected comma. Otherwise +// returns 0. Requires no more than 15 unprotected commas. +#define GMOCK_PP_HAS_COMMA(...) \ + GMOCK_PP_INTERNAL_HAS_COMMA_CAT( \ + GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ + 1, 1, 1, 1, 1, 0), ) +// Returns the first argument. +#define GMOCK_PP_HEAD(...) \ + GMOCK_PP_INTERNAL_HEAD_CAT(GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__), ) + +// Returns the tail. A variadic list of all arguments minus the first. Requires +// at least one argument. +#define GMOCK_PP_TAIL(...) \ + GMOCK_PP_INTERNAL_TAIL_CAT(GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__), ) + +// Calls CAT(_Macro, NARG(__VA_ARGS__))(__VA_ARGS__) +#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \ + GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT( \ + GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__), ) + +#else // GMOCK_PP_INTERNAL_USE_MSVC + +#define GMOCK_PP_NARG(...) \ + GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, \ + 7, 6, 5, 4, 3, 2, 1) +#define GMOCK_PP_HAS_COMMA(...) \ + GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ + 1, 1, 1, 1, 0) +#define GMOCK_PP_HEAD(...) GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__) +#define GMOCK_PP_TAIL(...) GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__) +#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \ + GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__) + +#endif // GMOCK_PP_INTERNAL_USE_MSVC + +// If the arguments after expansion have no tokens, evaluates to `1`. Otherwise +// evaluates to `0`. +// +// Requires: * the number of arguments after expansion is at most 15. +// * If the argument is a macro, it must be able to be called with one +// argument. +// +// Implementation details: +// +// There is one case when it generates a compile error: if the argument is macro +// that cannot be called with one argument. +// +// #define M(a, b) // it doesn't matter what it expands to +// +// // Expected: expands to `0`. +// // Actual: compile error. +// GMOCK_PP_IS_EMPTY(M) +// +// There are 4 cases tested: +// +// * __VA_ARGS__ possible expansion has no unparen'd commas. Expected 0. +// * __VA_ARGS__ possible expansion is not enclosed in parenthesis. Expected 0. +// * __VA_ARGS__ possible expansion is not a macro that ()-evaluates to a comma. +// Expected 0 +// * __VA_ARGS__ is empty, or has unparen'd commas, or is enclosed in +// parenthesis, or is a macro that ()-evaluates to comma. Expected 1. +// +// We trigger detection on '0001', i.e. on empty. +#define GMOCK_PP_IS_EMPTY(...) \ + GMOCK_PP_INTERNAL_IS_EMPTY(GMOCK_PP_HAS_COMMA(__VA_ARGS__), \ + GMOCK_PP_HAS_COMMA(GMOCK_PP_COMMA __VA_ARGS__), \ + GMOCK_PP_HAS_COMMA(__VA_ARGS__()), \ + GMOCK_PP_HAS_COMMA(GMOCK_PP_COMMA __VA_ARGS__())) + +// Evaluates to _Then if _Cond is 1 and _Else if _Cond is 0. +#define GMOCK_PP_IF(_Cond, _Then, _Else) \ + GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IF_, _Cond)(_Then, _Else) + +// Evaluates to the number of arguments after expansion. Identifies 'empty' as +// 0. +// +// #define PAIR x, y +// +// GMOCK_PP_NARG0() => 0 +// GMOCK_PP_NARG0(x) => 1 +// GMOCK_PP_NARG0(x, y) => 2 +// GMOCK_PP_NARG0(PAIR) => 2 +// +// Requires: * the number of arguments after expansion is at most 15. +// * If the argument is a macro, it must be able to be called with one +// argument. +#define GMOCK_PP_NARG0(...) \ + GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(__VA_ARGS__), 0, GMOCK_PP_NARG(__VA_ARGS__)) + +// Expands to 1 if the first argument starts with something in parentheses, +// otherwise to 0. +#define GMOCK_PP_IS_BEGIN_PARENS(...) \ + GMOCK_PP_INTERNAL_ALTERNATE_HEAD( \ + GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_, \ + GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C __VA_ARGS__)) + +// Expands to 1 is there is only one argument and it is enclosed in parentheses. +#define GMOCK_PP_IS_ENCLOSED_PARENS(...) \ + GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(__VA_ARGS__), \ + GMOCK_PP_IS_EMPTY(GMOCK_PP_EMPTY __VA_ARGS__), 0) + +// Remove the parens, requires GMOCK_PP_IS_ENCLOSED_PARENS(args) => 1. +#define GMOCK_PP_REMOVE_PARENS(...) GMOCK_PP_INTERNAL_REMOVE_PARENS __VA_ARGS__ + +// Expands to _Macro(0, _Data, e1) _Macro(1, _Data, e2) ... _Macro(K -1, _Data, +// eK) as many of GMOCK_INTERNAL_NARG0 _Tuple. +// Requires: * |_Macro| can be called with 3 arguments. +// * |_Tuple| expansion has no more than 15 elements. +#define GMOCK_PP_FOR_EACH(_Macro, _Data, _Tuple) \ + GMOCK_PP_CAT(GMOCK_PP_INTERNAL_FOR_EACH_IMPL_, GMOCK_PP_NARG0 _Tuple) \ + (0, _Macro, _Data, _Tuple) + +// Expands to _Macro(0, _Data, ) _Macro(1, _Data, ) ... _Macro(K - 1, _Data, ) +// Empty if _K = 0. +// Requires: * |_Macro| can be called with 3 arguments. +// * |_K| literal between 0 and 15 +#define GMOCK_PP_REPEAT(_Macro, _Data, _N) \ + GMOCK_PP_CAT(GMOCK_PP_INTERNAL_FOR_EACH_IMPL_, _N) \ + (0, _Macro, _Data, GMOCK_PP_INTENRAL_EMPTY_TUPLE) + +// Increments the argument, requires the argument to be between 0 and 15. +#define GMOCK_PP_INC(_i) GMOCK_PP_CAT(GMOCK_PP_INTERNAL_INC_, _i) + +// Returns comma if _i != 0. Requires _i to be between 0 and 15. +#define GMOCK_PP_COMMA_IF(_i) GMOCK_PP_CAT(GMOCK_PP_INTERNAL_COMMA_IF_, _i) + +// Internal details follow. Do not use any of these symbols outside of this +// file or we will break your code. +#define GMOCK_PP_INTENRAL_EMPTY_TUPLE (, , , , , , , , , , , , , , , ) +#define GMOCK_PP_INTERNAL_CAT(_1, _2) _1##_2 +#define GMOCK_PP_INTERNAL_STRINGIZE(...) #__VA_ARGS__ +#define GMOCK_PP_INTERNAL_INTERNAL_16TH(_1, _2, _3, _4, _5, _6, _7, _8, _9, \ + _10, _11, _12, _13, _14, _15, _16, \ + ...) \ + _16 +#define GMOCK_PP_INTERNAL_CAT_5(_1, _2, _3, _4, _5) _1##_2##_3##_4##_5 +#define GMOCK_PP_INTERNAL_IS_EMPTY(_1, _2, _3, _4) \ + GMOCK_PP_HAS_COMMA(GMOCK_PP_INTERNAL_CAT_5(GMOCK_PP_INTERNAL_IS_EMPTY_CASE_, \ + _1, _2, _3, _4)) +#define GMOCK_PP_INTERNAL_IS_EMPTY_CASE_0001 , +#define GMOCK_PP_INTERNAL_IF_1(_Then, _Else) _Then +#define GMOCK_PP_INTERNAL_IF_0(_Then, _Else) _Else +#define GMOCK_PP_INTERNAL_HEAD(_1, ...) _1 +#define GMOCK_PP_INTERNAL_TAIL(_1, ...) __VA_ARGS__ + +#if GMOCK_PP_INTERNAL_USE_MSVC +#define GMOCK_PP_INTERNAL_NARG_CAT(_1, _2) GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2) +#define GMOCK_PP_INTERNAL_HEAD_CAT(_1, _2) GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2) +#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT(_1, _2) \ + GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2) +#define GMOCK_PP_INTERNAL_TAIL_CAT(_1, _2) GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2) +#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT(_1, _2) \ + GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2) +#define GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2) _1##_2 +#define GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2) _1##_2 +#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2) _1##_2 +#define GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2) _1##_2 +#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2) _1##_2 +#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) \ + GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(GMOCK_PP_HEAD(__VA_ARGS__), ) +#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(_1, _2) \ + GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2) +#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2) _1##_2 +#else // GMOCK_PP_INTERNAL_USE_MSVC +#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) GMOCK_PP_HEAD(__VA_ARGS__) +#endif // GMOCK_PP_INTERNAL_USE_MSVC + +#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C(...) 1 _ +#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_1 1, +#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C \ + 0, +#define GMOCK_PP_INTERNAL_REMOVE_PARENS(...) __VA_ARGS__ +#define GMOCK_PP_INTERNAL_INC_0 1 +#define GMOCK_PP_INTERNAL_INC_1 2 +#define GMOCK_PP_INTERNAL_INC_2 3 +#define GMOCK_PP_INTERNAL_INC_3 4 +#define GMOCK_PP_INTERNAL_INC_4 5 +#define GMOCK_PP_INTERNAL_INC_5 6 +#define GMOCK_PP_INTERNAL_INC_6 7 +#define GMOCK_PP_INTERNAL_INC_7 8 +#define GMOCK_PP_INTERNAL_INC_8 9 +#define GMOCK_PP_INTERNAL_INC_9 10 +#define GMOCK_PP_INTERNAL_INC_10 11 +#define GMOCK_PP_INTERNAL_INC_11 12 +#define GMOCK_PP_INTERNAL_INC_12 13 +#define GMOCK_PP_INTERNAL_INC_13 14 +#define GMOCK_PP_INTERNAL_INC_14 15 +#define GMOCK_PP_INTERNAL_INC_15 16 +#define GMOCK_PP_INTERNAL_COMMA_IF_0 +#define GMOCK_PP_INTERNAL_COMMA_IF_1 , +#define GMOCK_PP_INTERNAL_COMMA_IF_2 , +#define GMOCK_PP_INTERNAL_COMMA_IF_3 , +#define GMOCK_PP_INTERNAL_COMMA_IF_4 , +#define GMOCK_PP_INTERNAL_COMMA_IF_5 , +#define GMOCK_PP_INTERNAL_COMMA_IF_6 , +#define GMOCK_PP_INTERNAL_COMMA_IF_7 , +#define GMOCK_PP_INTERNAL_COMMA_IF_8 , +#define GMOCK_PP_INTERNAL_COMMA_IF_9 , +#define GMOCK_PP_INTERNAL_COMMA_IF_10 , +#define GMOCK_PP_INTERNAL_COMMA_IF_11 , +#define GMOCK_PP_INTERNAL_COMMA_IF_12 , +#define GMOCK_PP_INTERNAL_COMMA_IF_13 , +#define GMOCK_PP_INTERNAL_COMMA_IF_14 , +#define GMOCK_PP_INTERNAL_COMMA_IF_15 , +#define GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, _element) \ + _Macro(_i, _Data, _element) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_0(_i, _Macro, _Data, _Tuple) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_2(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_3(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_2(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_4(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_3(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_5(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_4(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_6(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_5(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_7(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_6(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_8(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_7(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_9(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_8(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_10(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_9(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_11(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_10(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_12(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_11(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_13(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_12(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_14(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_13(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) +#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_15(_i, _Macro, _Data, _Tuple) \ + GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \ + GMOCK_PP_INTERNAL_FOR_EACH_IMPL_14(GMOCK_PP_INC(_i), _Macro, _Data, \ + (GMOCK_PP_TAIL _Tuple)) + +#endif // THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PP_H_ |