Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Boost PP_Iterate by C++11 variadic templates #110

Merged
merged 7 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +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 and sequences making MOCK_MAX_ARGS and MOCK_MAX_SEQUENCES superflous

[endsect]

Expand Down
18 changes: 0 additions & 18 deletions doc/customization.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,6 @@ For more information about the serialization operator and the use of mock::forma

[endsect]

[section Number of arguments]

The maximum number of arguments a mocked method can have is defined by MOCK_MAX_ARGS.
By default this value is set to 9, but if needed it can be changed before including the library :

[max_args]

This means methods with up to 20 arguments will then be accepted.

The mock object library uses several boost libraries and will adjust some of their constants if they haven't already been defined :

* Boost.Function with BOOST_FUNCTION_MAX_ARGS required at MOCK_MAX_ARGS or higher
* Boost.FunctionTypes with BOOST_FT_MAX_ARITY required at MOCK_MAX_ARGS + 1 or higher

A compilation error will happen if one of those constants is already defined too low.

[endsect]

[section Test framework integration]

By default the library expects to be used in conjunction with Boost.Test e.g. :
Expand Down
6 changes: 0 additions & 6 deletions doc/example/customization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ BOOST_AUTO_TEST_CASE(near_constraint_works_with_with_float_wrapper_and_cref)
}
} // namespace near_constraint_cref_test

#undef MOCK_MAX_ARGS
//[ max_args
#define MOCK_MAX_ARGS 20
#include <turtle/mock.hpp>
//]

#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-parameter"
Expand Down
7 changes: 2 additions & 5 deletions doc/reference.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -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 <turtle/mock.hpp>
The maximum number of sequences that can be set is basically unlimited.

Example :

Expand All @@ -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

Expand Down
8 changes: 0 additions & 8 deletions include/turtle/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@
# define MOCK_USE_BOOST_TEST
#endif

#ifndef MOCK_MAX_ARGS
# define MOCK_MAX_ARGS 9
#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
Expand Down
111 changes: 2 additions & 109 deletions include/turtle/constraint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/preprocessor/variadic/to_array.hpp>
#include <boost/preprocessor/variadic/size.hpp>
#include <functional>
#include <type_traits>

Expand Down Expand Up @@ -178,118 +178,11 @@ const constraint<detail::not_<Constraint>> operator!(const constraint<Constraint
#define MOCK_CONSTRAINT_EXT(Name, n, Args, Expr) \
BOOST_PP_IF(n, MOCK_NARY_CONSTRAINT, MOCK_UNARY_CONSTRAINT)(Name, n, Args, Expr)

#ifdef BOOST_MSVC
# define MOCK_VARIADIC_SIZE(...) \
BOOST_PP_CAT(MOCK_VARIADIC_SIZE_I(__VA_ARGS__, \
32, \
31, \
30, \
29, \
28, \
27, \
26, \
25, \
24, \
23, \
22, \
21, \
20, \
19, \
18, \
17, \
16, \
15, \
14, \
13, \
12, \
11, \
10, \
9, \
8, \
7, \
6, \
5, \
4, \
3, \
2, \
1, ), )
#else // BOOST_MSVC
# define MOCK_VARIADIC_SIZE(...) \
MOCK_VARIADIC_SIZE_I(__VA_ARGS__, \
32, \
31, \
30, \
29, \
28, \
27, \
26, \
25, \
24, \
23, \
22, \
21, \
20, \
19, \
18, \
17, \
16, \
15, \
14, \
13, \
12, \
11, \
10, \
9, \
8, \
7, \
6, \
5, \
4, \
3, \
2, \
1, )
#endif // BOOST_MSVC
#define MOCK_VARIADIC_SIZE_I(e0, \
e1, \
e2, \
e3, \
e4, \
e5, \
e6, \
e7, \
e8, \
e9, \
e10, \
e11, \
e12, \
e13, \
e14, \
e15, \
e16, \
e17, \
e18, \
e19, \
e20, \
e21, \
e22, \
e23, \
e24, \
e25, \
e26, \
e27, \
e28, \
e29, \
e30, \
e31, \
size, \
...) \
size

#define MOCK_CONSTRAINT_AUX_AUX(Name, n, Array) \
MOCK_CONSTRAINT_EXT(Name, n, BOOST_PP_ARRAY_TO_TUPLE(BOOST_PP_ARRAY_POP_BACK(Array)), BOOST_PP_ARRAY_ELEM(n, Array))

#define MOCK_CONSTRAINT_AUX(Name, Size, Tuple) MOCK_CONSTRAINT_AUX_AUX(Name, BOOST_PP_DEC(Size), (Size, Tuple))

#define MOCK_CONSTRAINT(Name, ...) MOCK_CONSTRAINT_AUX(Name, MOCK_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))
#define MOCK_CONSTRAINT(Name, ...) MOCK_CONSTRAINT_AUX(Name, BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))

#endif // MOCK_CONSTRAINT_HPP_INCLUDED
1 change: 0 additions & 1 deletion include/turtle/constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "config.hpp"
#include "constraint.hpp"
#include "detail/move_helper.hpp"
#include "detail/void_t.hpp"
#include "unwrap_reference.hpp"
#include <boost/version.hpp>
Expand Down
39 changes: 21 additions & 18 deletions include/turtle/detail/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ namespace mock { namespace detail {
action_type a_;
};

/// Type erased value storage
struct value
{
value() = default;
value(const value&) = delete;
value& operator=(const value&) = delete;
virtual ~value() = default;
};
/// Actual value storage,
/// holds an instance of T (stripped of reference qualifiers)
template<typename T>
struct value_imp : value
{
using type = std::remove_const_t<std::remove_reference_t<T>>;

template<typename U>
value_imp(U&& t) : t_(std::forward<U>(t))
{}
type t_;
};

template<typename Result, typename Signature>
class action : public action_base<Result, Signature>
{
Expand All @@ -85,24 +106,6 @@ namespace mock { namespace detail {
}

private:
struct value
{
value() = default;
value(const value&) = delete;
value& operator=(const value&) = delete;
virtual ~value() = default;
};
template<typename T>
struct value_imp : value
{
typedef std::remove_const_t<std::remove_reference_t<T>> type;

template<typename U>
value_imp(U&& t) : t_(std::forward<U>(t))
{}
type t_;
};

template<typename T>
typename value_imp<T>::type& store(T&& t)
{
Expand Down
Loading