[go: nahoru, domu]

Skip to content

Commit

Permalink
Googletest export
Browse files Browse the repository at this point in the history
Fix the ACTION* macros to allow for more than 10 arguments in the action.
Only the first 10 will be passed as individual arguments as `argN`, but the rest
can be accessed from the `args` tuple.

PiperOrigin-RevId: 311542098
  • Loading branch information
Abseil Team authored and derekmauro committed May 28, 2020
1 parent 011959a commit 63713e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions googlemock/include/gmock/gmock-actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1335,15 +1335,17 @@ class ActionHelper {
public:
template <typename... Ts>
static Result Perform(Impl* impl, const std::tuple<Ts...>& args) {
return Apply(impl, args, MakeIndexSequence<sizeof...(Ts)>{},
MakeIndexSequence<10 - sizeof...(Ts)>{});
static constexpr size_t kMaxArgs = sizeof...(Ts) <= 10 ? sizeof...(Ts) : 10;
return Apply(impl, args, MakeIndexSequence<kMaxArgs>{},
MakeIndexSequence<10 - kMaxArgs>{});
}

private:
template <typename... Ts, std::size_t... tuple_ids, std::size_t... rest_ids>
static Result Apply(Impl* impl, const std::tuple<Ts...>& args,
IndexSequence<tuple_ids...>, IndexSequence<rest_ids...>) {
return impl->template gmock_PerformImpl<Ts...>(
return impl->template gmock_PerformImpl<
typename std::tuple_element<tuple_ids, std::tuple<Ts...>>::type...>(
args, std::get<tuple_ids>(args)...,
((void)rest_ids, ExcessiveArg())...);
}
Expand Down
20 changes: 20 additions & 0 deletions googlemock/test/gmock-actions_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,26 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) {
EXPECT_EQ(x, 3);
}

ACTION(ReturnArity) {
return std::tuple_size<args_type>::value;
}

TEST(ActionMacro, LargeArity) {
EXPECT_EQ(
1, testing::Action<int(int)>(ReturnArity()).Perform(std::make_tuple(0)));
EXPECT_EQ(
10,
testing::Action<int(int, int, int, int, int, int, int, int, int, int)>(
ReturnArity())
.Perform(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)));
EXPECT_EQ(
20,
testing::Action<int(int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int)>(
ReturnArity())
.Perform(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19)));
}

} // Unnamed namespace

Expand Down

0 comments on commit 63713e1

Please sign in to comment.