mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Replace Boost PP_Iterate by C++11 variadic templates
This allows support for any number of arguments and makes setting MOCK_MAX_ARGS unnecessary. It also allows for easier debugging due to being able to step into actual code instead of preprocessor generated stuff
This commit is contained in:
parent
90d9ac8055
commit
fca30e7780
17 changed files with 368 additions and 472 deletions
|
|
@ -11,28 +11,30 @@
|
|||
#include <boost/preprocessor/repetition/enum.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#define IDENTITY(z, n, d) d
|
||||
#define IDENTITY(z, n, text) text
|
||||
// Number of arguments is (now) unlimited, so take any high value here
|
||||
#define NUM_TEST_ARGS 100
|
||||
|
||||
namespace {
|
||||
struct my_custom_mock
|
||||
{
|
||||
MOCK_METHOD(method, MOCK_MAX_ARGS, void(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int)), tag)
|
||||
MOCK_METHOD(method2, MOCK_MAX_ARGS, int(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int)), tag_2)
|
||||
MOCK_METHOD(method, NUM_TEST_ARGS, void(BOOST_PP_ENUM(NUM_TEST_ARGS, IDENTITY, int)), tag)
|
||||
MOCK_METHOD(method2, NUM_TEST_ARGS, int(BOOST_PP_ENUM(NUM_TEST_ARGS, IDENTITY, int)), tag_2)
|
||||
};
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(call_mock_method_with_max_number_of_args, mock_error_fixture)
|
||||
{
|
||||
my_custom_mock m;
|
||||
MOCK_EXPECT(m.tag).once().with(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0));
|
||||
m.method(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0));
|
||||
MOCK_EXPECT(m.tag).once().with(BOOST_PP_ENUM(NUM_TEST_ARGS, IDENTITY, 0));
|
||||
m.method(BOOST_PP_ENUM(NUM_TEST_ARGS, IDENTITY, 0));
|
||||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(call_mock_method_with_max_number_of_args_and_a_return_value, mock_error_fixture)
|
||||
{
|
||||
my_custom_mock m;
|
||||
MOCK_EXPECT(m.tag_2).once().with(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0)).returns(42);
|
||||
BOOST_CHECK_EQUAL(42, m.method2(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0)));
|
||||
MOCK_EXPECT(m.tag_2).once().with(BOOST_PP_ENUM(NUM_TEST_ARGS, IDENTITY, 0)).returns(42);
|
||||
BOOST_CHECK_EQUAL(42, m.method2(BOOST_PP_ENUM(NUM_TEST_ARGS, IDENTITY, 0)));
|
||||
CHECK_CALLS(1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue