aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock/include/gmock/gmock-generated-actions.h.pump
diff options
context:
space:
mode:
Diffstat (limited to 'googlemock/include/gmock/gmock-generated-actions.h.pump')
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h.pump85
1 files changed, 62 insertions, 23 deletions
diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump
index 66d9f9d5..2794ebb7 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h.pump
+++ b/googlemock/include/gmock/gmock-generated-actions.h.pump
@@ -1,5 +1,5 @@
$$ -*- mode: c++; -*-
-$$ This is a Pump source file. Please use Pump to convert it to
+$$ This is a Pump source file. Please use Pump to convert it to
$$ gmock-generated-actions.h.
$$
$var n = 10 $$ The maximum arity we support.
@@ -32,13 +32,14 @@ $$}} This meta comment fixes auto-indentation in editors.
// 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.
-//
-// Author: wan@google.com (Zhanyong Wan)
+
// Google Mock - a framework for writing C++ mock classes.
//
// This file implements some commonly used variadic actions.
+// GOOGLETEST_CM0002 DO NOT DELETE
+
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
@@ -49,41 +50,79 @@ namespace testing {
namespace internal {
// InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
-// function or method with the unpacked values, where F is a function
-// type that takes N arguments.
+// function, method, or callback with the unpacked values, where F is
+// a function type that takes N arguments.
template <typename Result, typename ArgumentTuple>
class InvokeHelper;
+$var max_callback_arity = 5
$range i 0..n
$for i [[
$range j 1..i
$var types = [[$for j [[, typename A$j]]]]
$var as = [[$for j, [[A$j]]]]
$var args = [[$if i==0 [[]] $else [[ args]]]]
-$var gets = [[$for j, [[get<$(j - 1)>(args)]]]]
+$var gets = [[$for j, [[std::get<$(j - 1)>(args)]]]]
template <typename R$types>
-class InvokeHelper<R, ::testing::tuple<$as> > {
+class InvokeHelper<R, ::std::tuple<$as> > {
public:
template <typename Function>
- static R Invoke(Function function, const ::testing::tuple<$as>&$args) {
+ 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 ::testing::tuple<$as>&$args) {
+ 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 linked_ptr<CallbackType> callback_;
+};
+
// An INTERNAL macro for extracting the type of a tuple field. It's
// subject to change without notice - DO NOT USE IN USER CODE!
#define GMOCK_FIELD_(Tuple, N) \
- typename ::testing::tuple_element<N, Tuple>::type
+ typename ::std::tuple_element<N, Tuple>::type
$range i 1..n
@@ -91,14 +130,14 @@ $range i 1..n
// 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, ::testing::tuple<bool, char, double, long>, 0, 3>::type
+// 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, tuple<bool, char, double>, 2, 0>::Select(
-// ::testing::make_tuple(true, 'a', 2.5))
+// 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
@@ -111,7 +150,7 @@ class SelectArgs {
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, [[get<k$i>(args)]]);
+ return SelectedArgs($for i, [[std::get<k$i>(args)]]);
}
};
@@ -127,7 +166,7 @@ class SelectArgs<Result, ArgumentTuple,
typedef typename Function<type>::ArgumentTuple SelectedArgs;
static SelectedArgs Select(const ArgumentTuple& [[]]
$if i == 1 [[/* args */]] $else [[args]]) {
- return SelectedArgs($for j1, [[get<k$j1>(args)]]);
+ return SelectedArgs($for j1, [[std::get<k$j1>(args)]]);
}
};
@@ -201,12 +240,12 @@ $range j 0..i-1
]]]]
$range j 0..i-1
$var As = [[$for j, [[A$j]]]]
-$var as = [[$for j, [[get<$j>(args)]]]]
+$var as = [[$for j, [[std::get<$j>(args)]]]]
$range k 1..n-i
$var eas = [[$for k, [[ExcessiveArg()]]]]
$var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]]
$template
- static Result Perform(Impl* impl, const ::testing::tuple<$As>& args) {
+ static Result Perform(Impl* impl, const ::std::tuple<$As>& args) {
return impl->template gmock_PerformImpl<$As>(args, $arg_list);
}
@@ -356,8 +395,8 @@ $range j2 2..i
//
// MORE INFORMATION:
//
-// To learn more about using these macros, please search for 'ACTION'
-// on http://code.google.com/p/googlemock/wiki/CookBook.
+// To learn more about using these macros, please search for 'ACTION' on
+// https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
$range i 0..n
$range k 0..n-1
@@ -393,7 +432,7 @@ $for k [[, \
// ACTION_TEMPLATE(DuplicateArg,
// HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
// AND_1_VALUE_PARAMS(output)) {
-// *output = T(::testing::get<k>(args));
+// *output = T(::std::get<k>(args));
// }
// ...
// int n;
@@ -486,7 +525,7 @@ _VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]]
$for i [[
$range j 0..i-1
#define GMOCK_INTERNAL_INIT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])\
- ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(gmock_p$j)]]
+ ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(::testing::internal::move(gmock_p$j))]]
]]
@@ -619,7 +658,7 @@ $var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]]
$range j 0..i-1
$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
-$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]]
+$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::forward<p$j##_type>(gmock_p$j))]]]]]]
$var param_field_decls = [[$for j
[[
@@ -757,7 +796,7 @@ ACTION_TEMPLATE(InvokeArgument,
using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(),
- ::testing::get<k>(args)$for j [[, p$j]]);
+ ::std::get<k>(args)$for j [[, p$j]]);
}
]]