aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock/include/gmock
diff options
context:
space:
mode:
Diffstat (limited to 'googlemock/include/gmock')
-rw-r--r--googlemock/include/gmock/gmock-actions.h142
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h302
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h.pump70
-rw-r--r--googlemock/include/gmock/gmock-matchers.h125
-rw-r--r--googlemock/include/gmock/gmock-more-actions.h66
-rw-r--r--googlemock/include/gmock/gmock-spec-builders.h12
-rw-r--r--googlemock/include/gmock/gmock.h4
-rw-r--r--googlemock/include/gmock/internal/gmock-internal-utils.h1
8 files changed, 189 insertions, 533 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index 28141257..2f936a15 100644
--- a/googlemock/include/gmock/gmock-actions.h
+++ b/googlemock/include/gmock/gmock-actions.h
@@ -817,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_)();
- }
-
- private:
- Class* const obj_ptr_;
- const MethodPtr method_ptr_;
-
- GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
-};
+ using ReturnType = typename std::result_of<MethodPtr(Class*)>::type;
-// 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.
@@ -936,33 +914,6 @@ 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_;
-};
-
-// 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 InnerAction, size_t... I>
struct WithArgsAction {
InnerAction action;
@@ -1184,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
@@ -1219,9 +1184,12 @@ 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
diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h
index 910436e0..3264bca6 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h
+++ b/googlemock/include/gmock/gmock-generated-actions.h
@@ -50,308 +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_;
-};
-
// 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
diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump
index 27c96efc..1e9549f3 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h.pump
+++ b/googlemock/include/gmock/gmock-generated-actions.h.pump
@@ -52,76 +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_;
-};
-
// 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
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index 56804f39..fa24fd2f 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -900,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 {
@@ -1175,6 +1175,37 @@ class AnyOfMatcherImpl : public MatcherInterface<const T&> {
template <typename... Args>
using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>;
+// Wrapper for implementation of Any/AllOfArray().
+template <template <class> class MatcherImpl, typename T>
+class SomeOfArrayMatcher {
+ public:
+ // Constructs the matcher from a sequence of element values or
+ // element matchers.
+ template <typename Iter>
+ SomeOfArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
+
+ template <typename U>
+ operator Matcher<U>() const { // NOLINT
+ using RawU = typename std::decay<U>::type;
+ std::vector<Matcher<RawU>> matchers;
+ for (const auto& matcher : matchers_) {
+ matchers.push_back(MatcherCast<RawU>(matcher));
+ }
+ return Matcher<U>(new MatcherImpl<RawU>(std::move(matchers)));
+ }
+
+ private:
+ const ::std::vector<T> matchers_;
+
+ GTEST_DISALLOW_ASSIGN_(SomeOfArrayMatcher);
+};
+
+template <typename T>
+using AllOfArrayMatcher = SomeOfArrayMatcher<AllOfMatcherImpl, T>;
+
+template <typename T>
+using AnyOfArrayMatcher = SomeOfArrayMatcher<AnyOfMatcherImpl, T>;
+
// Used for implementing Truly(pred), which turns a predicate into a
// matcher.
template <typename Predicate>
@@ -2535,7 +2566,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:
@@ -2640,9 +2672,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:
@@ -3205,7 +3236,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>
@@ -4376,6 +4407,88 @@ internal::AnyOfMatcher<typename std::decay<const Args&>::type...> AnyOf(
matchers...);
}
+// AnyOfArray(array)
+// AnyOfArray(pointer, count)
+// AnyOfArray(container)
+// AnyOfArray({ e1, e2, ..., en })
+// AnyOfArray(iterator_first, iterator_last)
+//
+// AnyOfArray() verifies whether a given value matches any member of a
+// collection of matchers.
+//
+// AllOfArray(array)
+// AllOfArray(pointer, count)
+// AllOfArray(container)
+// AllOfArray({ e1, e2, ..., en })
+// AllOfArray(iterator_first, iterator_last)
+//
+// AllOfArray() verifies whether a given value matches all members of a
+// collection of matchers.
+//
+// The matchers can be specified as an array, a pointer and count, a container,
+// an initializer list, or an STL iterator range. In each of these cases, the
+// underlying matchers can be either values or matchers.
+
+template <typename Iter>
+inline internal::AnyOfArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>
+AnyOfArray(Iter first, Iter last) {
+ return internal::AnyOfArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>(first, last);
+}
+
+template <typename Iter>
+inline internal::AllOfArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>
+AllOfArray(Iter first, Iter last) {
+ return internal::AllOfArrayMatcher<
+ typename ::std::iterator_traits<Iter>::value_type>(first, last);
+}
+
+template <typename T>
+inline internal::AnyOfArrayMatcher<T> AnyOfArray(const T* ptr, size_t count) {
+ return AnyOfArray(ptr, ptr + count);
+}
+
+template <typename T>
+inline internal::AllOfArrayMatcher<T> AllOfArray(const T* ptr, size_t count) {
+ return AllOfArray(ptr, ptr + count);
+}
+
+template <typename T, size_t N>
+inline internal::AnyOfArrayMatcher<T> AnyOfArray(const T (&array)[N]) {
+ return AnyOfArray(array, N);
+}
+
+template <typename T, size_t N>
+inline internal::AllOfArrayMatcher<T> AllOfArray(const T (&array)[N]) {
+ return AllOfArray(array, N);
+}
+
+template <typename Container>
+inline internal::AnyOfArrayMatcher<typename Container::value_type> AnyOfArray(
+ const Container& container) {
+ return AnyOfArray(container.begin(), container.end());
+}
+
+template <typename Container>
+inline internal::AllOfArrayMatcher<typename Container::value_type> AllOfArray(
+ const Container& container) {
+ return AllOfArray(container.begin(), container.end());
+}
+
+template <typename T>
+inline internal::AnyOfArrayMatcher<T> AnyOfArray(
+ ::std::initializer_list<T> xs) {
+ return AnyOfArray(xs.begin(), xs.end());
+}
+
+template <typename T>
+inline internal::AllOfArrayMatcher<T> AllOfArray(
+ ::std::initializer_list<T> xs) {
+ return AllOfArray(xs.begin(), xs.end());
+}
+
// 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.
diff --git a/googlemock/include/gmock/gmock-more-actions.h b/googlemock/include/gmock/gmock-more-actions.h
index 10984081..a052495d 100644
--- a/googlemock/include/gmock/gmock-more-actions.h
+++ b/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,24 +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));
-}
-
// 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/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h
index 526fe7aa..1f261bd2 100644
--- a/googlemock/include/gmock/gmock-spec-builders.h
+++ b/googlemock/include/gmock/gmock-spec-builders.h
@@ -300,7 +300,10 @@ class OnCallSpec : public UntypedOnCallSpecBase {
const ArgumentMatcherTuple& matchers)
: UntypedOnCallSpecBase(a_file, a_line),
matchers_(matchers),
- extra_matcher_(_) {}
+ // By default, extra_matcher_ should match anything. However,
+ // 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) {
@@ -890,7 +893,10 @@ class TypedExpectation : public ExpectationBase {
: ExpectationBase(a_file, a_line, a_source_text),
owner_(owner),
matchers_(m),
- extra_matcher_(_),
+ // By default, extra_matcher_ should match anything. However,
+ // 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()) {}
~TypedExpectation() override {
@@ -1447,7 +1453,7 @@ template <typename F>
class FunctionMocker;
template <typename R, typename... Args>
-class FunctionMocker<R(Args...)> : public UntypedFunctionMockerBase {
+class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase {
using F = R(Args...);
public:
diff --git a/googlemock/include/gmock/gmock.h b/googlemock/include/gmock/gmock.h
index c68ae1c7..7096984b 100644
--- a/googlemock/include/gmock/gmock.h
+++ b/googlemock/include/gmock/gmock.h
@@ -92,6 +92,10 @@ GTEST_API_ void InitGoogleMock(int* argc, char** argv);
// UNICODE mode.
GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv);
+// This overloaded version can be used on Arduino/embedded platforms where
+// there is no argc/argv.
+GTEST_API_ void InitGoogleMock();
+
} // namespace testing
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_
diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h
index 661c8357..093b4653 100644
--- a/googlemock/include/gmock/internal/gmock-internal-utils.h
+++ b/googlemock/include/gmock/internal/gmock-internal-utils.h
@@ -42,6 +42,7 @@
#include <stdio.h>
#include <ostream> // NOLINT
#include <string>
+#include <type_traits>
#include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"