Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
710f9c11
Commit
710f9c11
authored
Nov 05, 2020
by
ofats
Committed by
Andy Getz
Nov 05, 2020
Browse files
Googletest export
Rewrite InvokeArgument action without using pump. PiperOrigin-RevId: 340861582
parent
fb98f744
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
103 deletions
+76
-103
googlemock/include/gmock/gmock-actions.h
googlemock/include/gmock/gmock-actions.h
+0
-9
googlemock/include/gmock/gmock-generated-actions.h
googlemock/include/gmock/gmock-generated-actions.h
+38
-76
googlemock/include/gmock/gmock-generated-actions.h.pump
googlemock/include/gmock/gmock-generated-actions.h.pump
+38
-18
No files found.
googlemock/include/gmock/gmock-actions.h
View file @
710f9c11
...
...
@@ -1539,15 +1539,6 @@ class ActionImpl<Derived<Ts...>> {
std
::
tuple
<
Ts
...
>
params_
;
};
// internal::InvokeArgument - a helper for InvokeArgument action.
// The basic overloads are provided here for generic functors.
// Overloads for other custom-callables are provided in the
// internal/custom/gmock-generated-actions.h header.
template
<
typename
F
,
typename
...
Args
>
auto
InvokeArgument
(
F
f
,
Args
...
args
)
->
decltype
(
f
(
args
...))
{
return
f
(
args
...);
}
#define GMOCK_INTERNAL_ARG_UNUSED(i, data, el) \
, const arg##i##_type& arg##i GTEST_ATTRIBUTE_UNUSED_
#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_ \
...
...
googlemock/include/gmock/gmock-generated-actions.h
View file @
710f9c11
...
...
@@ -491,10 +491,8 @@
gmock_PerformImpl(\
GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
namespace
testing
{
// 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
...
...
@@ -505,8 +503,36 @@ namespace testing {
# pragma warning(disable:4100)
#endif
// Various overloads for InvokeArgument<N>().
//
namespace
internal
{
// internal::InvokeArgument - a helper for InvokeArgument action.
// The basic overloads are provided here for generic functors.
// Overloads for other custom-callables are provided in the
// internal/custom/gmock-generated-actions.h header.
template
<
typename
F
,
typename
...
Args
>
auto
InvokeArgument
(
F
f
,
Args
...
args
)
->
decltype
(
f
(
args
...))
{
return
f
(
args
...);
}
template
<
std
::
size_t
index
,
typename
...
Params
>
struct
InvokeArgumentAction
{
template
<
typename
...
Args
>
auto
operator
()(
Args
&&
...
args
)
const
->
decltype
(
internal
::
InvokeArgument
(
std
::
get
<
index
>
(
std
::
forward_as_tuple
(
std
::
forward
<
Args
>
(
args
)...)),
std
::
declval
<
const
Params
&>
()...))
{
internal
::
FlatTuple
<
Args
&&
...
>
args_tuple
(
std
::
forward
<
Args
>
(
args
)...);
return
params
.
Apply
([
&
](
const
Params
&
...
unpacked_params
)
{
auto
&&
callable
=
args_tuple
.
template
Get
<
index
>();
return
internal
::
InvokeArgument
(
std
::
forward
<
decltype
(
callable
)
>
(
callable
),
unpacked_params
...);
});
}
internal
::
FlatTuple
<
Params
...
>
params
;
};
}
// namespace internal
// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
// (0-based) argument, which must be a k-ary callable, of the mock
// function, with arguments a1, a2, ..., a_k.
...
...
@@ -514,15 +540,15 @@ namespace testing {
// Notes:
//
// 1. The arguments are passed by value by default. If you need to
// pass an argument by reference, wrap it inside
ByR
ef(). For
// pass an argument by reference, wrap it inside
std::r
ef(). For
// example,
//
// InvokeArgument<1>(5, string("Hello"),
ByR
ef(foo))
// InvokeArgument<1>(5, string("Hello"),
std::r
ef(foo))
//
// passes 5 and string("Hello") by value, and passes foo by
// reference.
//
// 2. If the callable takes an argument by reference but
ByR
ef() is
// 2. If the callable takes an argument by reference but
std::r
ef() is
// not used, it will receive the reference to a copy of the value,
// instead of the original value. For example, when the 0-th
// argument of the mock function takes a const string&, the action
...
...
@@ -534,75 +560,11 @@ namespace testing {
// to the callable. This makes it easy for a user to define an
// InvokeArgument action from temporary values and have it performed
// later.
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_0_VALUE_PARAMS
())
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
));
}
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_1_VALUE_PARAMS
(
p0
))
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
),
p0
);
}
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_2_VALUE_PARAMS
(
p0
,
p1
))
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
),
p0
,
p1
);
}
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_3_VALUE_PARAMS
(
p0
,
p1
,
p2
))
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
),
p0
,
p1
,
p2
);
}
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_4_VALUE_PARAMS
(
p0
,
p1
,
p2
,
p3
))
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
),
p0
,
p1
,
p2
,
p3
);
}
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_5_VALUE_PARAMS
(
p0
,
p1
,
p2
,
p3
,
p4
))
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
),
p0
,
p1
,
p2
,
p3
,
p4
);
}
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_6_VALUE_PARAMS
(
p0
,
p1
,
p2
,
p3
,
p4
,
p5
))
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
),
p0
,
p1
,
p2
,
p3
,
p4
,
p5
);
}
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_7_VALUE_PARAMS
(
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
))
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
),
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
);
}
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_8_VALUE_PARAMS
(
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
))
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
),
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
);
}
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_9_VALUE_PARAMS
(
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
))
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
),
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
);
}
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_10_VALUE_PARAMS
(
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
,
p9
))
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
),
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
,
p9
);
template
<
std
::
size_t
index
,
typename
...
Params
>
internal
::
InvokeArgumentAction
<
index
,
typename
std
::
decay
<
Params
>::
type
...
>
InvokeArgument
(
Params
&&
...
params
)
{
return
{
internal
::
FlatTuple
<
typename
std
::
decay
<
Params
>::
type
...
>
(
std
::
forward
<
Params
>
(
params
)...)};
}
#ifdef _MSC_VER
...
...
googlemock/include/gmock/gmock-generated-actions.h.pump
View file @
710f9c11
...
...
@@ -305,10 +305,8 @@ $range k 0..n-1
gmock_PerformImpl(\
GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
namespace
testing
{
// 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
...
...
@@ -319,8 +317,36 @@ namespace testing {
# pragma warning(disable:4100)
#endif
// Various overloads for InvokeArgument<N>().
//
namespace
internal
{
// internal::InvokeArgument - a helper for InvokeArgument action.
// The basic overloads are provided here for generic functors.
// Overloads for other custom-callables are provided in the
// internal/custom/gmock-generated-actions.h header.
template
<
typename
F
,
typename
...
Args
>
auto
InvokeArgument
(
F
f
,
Args
...
args
)
->
decltype
(
f
(
args
...))
{
return
f
(
args
...);
}
template
<
std
::
size_t
index
,
typename
...
Params
>
struct
InvokeArgumentAction
{
template
<
typename
...
Args
>
auto
operator
()(
Args
&&
...
args
)
const
->
decltype
(
internal
::
InvokeArgument
(
std
::
get
<
index
>
(
std
::
forward_as_tuple
(
std
::
forward
<
Args
>
(
args
)...)),
std
::
declval
<
const
Params
&>
()...))
{
internal
::
FlatTuple
<
Args
&&
...
>
args_tuple
(
std
::
forward
<
Args
>
(
args
)...);
return
params
.
Apply
([
&
](
const
Params
&
...
unpacked_params
)
{
auto
&&
callable
=
args_tuple
.
template
Get
<
index
>();
return
internal
::
InvokeArgument
(
std
::
forward
<
decltype
(
callable
)
>
(
callable
),
unpacked_params
...);
});
}
internal
::
FlatTuple
<
Params
...
>
params
;
};
}
// namespace internal
// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
// (0-based) argument, which must be a k-ary callable, of the mock
// function, with arguments a1, a2, ..., a_k.
...
...
@@ -328,15 +354,15 @@ namespace testing {
// Notes:
//
// 1. The arguments are passed by value by default. If you need to
// pass an argument by reference, wrap it inside
ByR
ef(). For
// pass an argument by reference, wrap it inside
std::r
ef(). For
// example,
//
// InvokeArgument<1>(5, string("Hello"),
ByR
ef(foo))
// InvokeArgument<1>(5, string("Hello"),
std::r
ef(foo))
//
// passes 5 and string("Hello") by value, and passes foo by
// reference.
//
// 2. If the callable takes an argument by reference but
ByR
ef() is
// 2. If the callable takes an argument by reference but
std::r
ef() is
// not used, it will receive the reference to a copy of the value,
// instead of the original value. For example, when the 0-th
// argument of the mock function takes a const string&, the action
...
...
@@ -348,19 +374,13 @@ namespace testing {
// to the callable. This makes it easy for a user to define an
// InvokeArgument action from temporary values and have it performed
// later.
$
range
i
0.
.
n
$
for
i
[[
$
range
j
0.
.
i
-
1
ACTION_TEMPLATE
(
InvokeArgument
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_
$
i
[[]]
_VALUE_PARAMS
(
$
for
j
,
[[
p
$
j
]]))
{
return
internal
::
InvokeArgument
(
::
std
::
get
<
k
>
(
args
)
$
for
j
[[,
p
$
j
]]);
template
<
std
::
size_t
index
,
typename
...
Params
>
internal
::
InvokeArgumentAction
<
index
,
typename
std
::
decay
<
Params
>::
type
...
>
InvokeArgument
(
Params
&&
...
params
)
{
return
{
internal
::
FlatTuple
<
typename
std
::
decay
<
Params
>::
type
...
>
(
std
::
forward
<
Params
>
(
params
)...)};
}
]]
#ifdef _MSC_VER
# pragma warning(pop)
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment