From 63713e1ce49019da205daa1ca91b73fcfc9b333f Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 14 May 2020 12:00:56 -0400 Subject: [PATCH] Googletest export 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 --- googlemock/include/gmock/gmock-actions.h | 8 +++++--- googlemock/test/gmock-actions_test.cc | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 0f30abde..ecf47c40 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -1335,15 +1335,17 @@ class ActionHelper { public: template static Result Perform(Impl* impl, const std::tuple& args) { - return Apply(impl, args, MakeIndexSequence{}, - MakeIndexSequence<10 - sizeof...(Ts)>{}); + static constexpr size_t kMaxArgs = sizeof...(Ts) <= 10 ? sizeof...(Ts) : 10; + return Apply(impl, args, MakeIndexSequence{}, + MakeIndexSequence<10 - kMaxArgs>{}); } private: template static Result Apply(Impl* impl, const std::tuple& args, IndexSequence, IndexSequence) { - return impl->template gmock_PerformImpl( + return impl->template gmock_PerformImpl< + typename std::tuple_element>::type...>( args, std::get(args)..., ((void)rest_ids, ExcessiveArg())...); } diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index cac8f94f..547f48f4 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1550,6 +1550,26 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) { EXPECT_EQ(x, 3); } +ACTION(ReturnArity) { + return std::tuple_size::value; +} + +TEST(ActionMacro, LargeArity) { + EXPECT_EQ( + 1, testing::Action(ReturnArity()).Perform(std::make_tuple(0))); + EXPECT_EQ( + 10, + testing::Action( + ReturnArity()) + .Perform(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))); + EXPECT_EQ( + 20, + testing::Action( + 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