diff --git a/doc/changelog.qbk b/doc/changelog.qbk index 326f21a..56a5f9c 100644 --- a/doc/changelog.qbk +++ b/doc/changelog.qbk @@ -15,7 +15,7 @@ Released - * Removed MOCK_*_TPL as they are no longer required, use the non _TPL variant even for templates * Added MOCK_PROTECT_SIGNATURE to pass function signatures with commas in the return type * Remove support for protecting function signatures via BOOST_IDENTITY_TYPE, use MOCK_PROTECT_SIGNATURE instead -* Add support for unlimitted number of arguments making MOCK_MAX_ARGS superflous +* Add support for unlimitted number of arguments and sequences making MOCK_MAX_ARGS and MOCK_MAX_SEQUENCES superflous [endsect] diff --git a/doc/reference.qbk b/doc/reference.qbk index 72dd7a9..8d1239e 100644 --- a/doc/reference.qbk +++ b/doc/reference.qbk @@ -449,10 +449,7 @@ Synopsis : Each sequence is an instance of mock::sequence. -The maximum number of sequences that can be set is MOCK_MAX_SEQUENCES which defaults to 10. If needed the value can be increased before including the library : - - #define MOCK_MAX_SEQUENCES 12 - #include +The maximum number of sequences that can be set is basically unlimited. Example : @@ -467,7 +464,7 @@ An action performs additional treatments after an expectation has been deemed va Synopsis : MOCK_EXPECT( identifier ).returns( value ); // stored internally by copy - MOCK_EXPECT( identifier ).moves( value ); // stored internally by copy + MOCK_EXPECT( identifier ).moves( value ); // stored internally by copy/move MOCK_EXPECT( identifier ).throws( exception ); // stored internally by copy MOCK_EXPECT( identifier ).calls( functor ); // stored internally by copy, throws std::invalid_argument if empty diff --git a/include/turtle/config.hpp b/include/turtle/config.hpp index d60fe72..111d09d 100644 --- a/include/turtle/config.hpp +++ b/include/turtle/config.hpp @@ -18,10 +18,6 @@ # define MOCK_USE_BOOST_TEST #endif -#ifndef MOCK_MAX_SEQUENCES -# define MOCK_MAX_SEQUENCES 10 -#endif - #if !defined(BOOST_NO_CXX11_HDR_MUTEX) && !defined(BOOST_NO_0X_HDR_MUTEX) # ifndef MOCK_NO_HDR_MUTEX # define MOCK_HDR_MUTEX diff --git a/include/turtle/detail/function_impl.hpp b/include/turtle/detail/function_impl.hpp index a396718..188a159 100644 --- a/include/turtle/detail/function_impl.hpp +++ b/include/turtle/detail/function_impl.hpp @@ -13,8 +13,6 @@ #include "expectation.hpp" #include "mutex.hpp" #include "verifiable.hpp" -#include -#include #include #include #include @@ -187,19 +185,14 @@ namespace mock { namespace detail { return *this; } -#define MOCK_FUNCTION_IN_ADD(z, n, d) this->e_->add(s##n); - -#define MOCK_FUNCTION_IN(z, n, d) \ - wrapper& in(BOOST_PP_ENUM_PARAMS(n, sequence& s)) \ - { \ - BOOST_PP_REPEAT(n, MOCK_FUNCTION_IN_ADD, _) \ - return *this; \ - } - - BOOST_PP_REPEAT(MOCK_MAX_SEQUENCES, MOCK_FUNCTION_IN, _) - -#undef MOCK_FUNCTION_IN -#undef MOCK_FUNCTION_IN_ADD + /// Ensure the expectation is met in the given sequence(s) + template + wrapper& in(sequence& s0, MockSequences&... s) + { + using expander = int[]; + (void)expander{ (e_->add(s0), 0), (e_->add(s), 0)... }; + return *this; + } template void calls(TT t) diff --git a/test/test_sequence.cpp b/test/test_sequence.cpp index 2415cf4..1f6ae98 100644 --- a/test/test_sequence.cpp +++ b/test/test_sequence.cpp @@ -10,6 +10,7 @@ #include #include #include +#include BOOST_FIXTURE_TEST_CASE(registering_to_a_sequence_and_calling_out_of_order_throws, mock_error_fixture) { @@ -97,9 +98,13 @@ BOOST_FIXTURE_TEST_CASE(resetting_an_expectation_removes_it_from_order_call_enfo BOOST_FIXTURE_TEST_CASE(an_expectation_can_be_used_in_several_sequences, mock_error_fixture) { - mock::sequence s1, s2; + std::array s; mock::detail::function e; - e.expect().once().in(s1, s2); + // One can use any amount of sequences if wanted + // clang-format off + e.expect().once().in(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], + s[10], s[11], s[12], s[13], s[14], s[15], s[16], s[17], s[18], s[19]); + // clang-format on BOOST_CHECK_NO_THROW(e()); BOOST_CHECK(e.verify()); CHECK_CALLS(1);