mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Improve tests
- Check callability of function.expect.with(...) - Check serialization of MOCK_CONSTRAINT - Actually test some variations of MOCK_CONSTRAINT usages - Add more test for unique_ptr (move-only class) - Remove redundant stuff from test_log and change a few values to catch mistakes - Add test for *-matcher serialization
This commit is contained in:
parent
50ea9982ed
commit
1a81536f3c
5 changed files with 168 additions and 50 deletions
|
|
@ -10,6 +10,7 @@
|
|||
#include "../undefined.hpp"
|
||||
#include <turtle/constraints.hpp>
|
||||
#include <turtle/detail/function.hpp>
|
||||
#include <turtle/detail/void_t.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
|
@ -24,6 +25,42 @@ static_assert(std::is_same<void, decltype(mock::detail::function<void()>{}())>::
|
|||
static_assert(std::is_same<int, decltype(mock::detail::function<int()>{}())>::value, "!");
|
||||
static_assert(std::is_same<void, decltype(mock::detail::function<void(float)>{}(std::declval<float>()))>::value, "!");
|
||||
static_assert(std::is_same<int, decltype(mock::detail::function<int(float)>{}(std::declval<float>()))>::value, "!");
|
||||
|
||||
template<class TFunction, typename... TParams>
|
||||
using with_call_t = decltype(std::declval<TFunction>().expect().with(std::declval<TParams>()...));
|
||||
template<class AlwaysVoid, class TFunction, typename... TParams>
|
||||
struct with_is_callable : std::false_type
|
||||
{};
|
||||
template<class TFunction, class... TParams>
|
||||
struct with_is_callable<mock::detail::void_t<with_call_t<TFunction, TParams...>>, TFunction, TParams...> :
|
||||
std::true_type
|
||||
{};
|
||||
// Detect if we can call function.expect().with(params)
|
||||
template<class TFunction, class... TParams>
|
||||
using with_is_callable_t = with_is_callable<void, TFunction, TParams...>;
|
||||
|
||||
// For function with no parameters `with` can never be called
|
||||
using function_0_args = mock::detail::function<int()>;
|
||||
static_assert(!with_is_callable_t<function_0_args>::value, "Can't call with()");
|
||||
static_assert(!with_is_callable_t<function_0_args, int>::value, "Can't call with(int)");
|
||||
static_assert(!with_is_callable_t<function_0_args, bool()>::value, "Can't call with custom constraint");
|
||||
|
||||
// For functions with parameters `with` can be called with a custom constraint (taking all params)
|
||||
// or exactly as many parameters as the function has (here 1 and 4 respectively)
|
||||
using function_1_args = mock::detail::function<int(int)>;
|
||||
static_assert(!with_is_callable_t<function_1_args>::value, "Can't call with()");
|
||||
static_assert(with_is_callable_t<function_1_args, int>::value, "Can call with(int)");
|
||||
static_assert(with_is_callable_t<function_1_args, bool(int)>::value, "Can call with custom constraint");
|
||||
static_assert(!with_is_callable_t<function_1_args, int, int>::value, "Can't call with(int, int)");
|
||||
|
||||
using function_4_args = mock::detail::function<int(int, int, int, int)>;
|
||||
static_assert(!with_is_callable_t<function_4_args>::value, "Can't call with()");
|
||||
static_assert(with_is_callable_t<function_4_args, bool(int, int, int, int)>::value, "Can call with custom constraint");
|
||||
static_assert(!with_is_callable_t<function_4_args, int, int>::value, "Can't call with(int, int)");
|
||||
static_assert(!with_is_callable_t<function_4_args, int, int, int>::value, "Can't call with(int, int, int)");
|
||||
static_assert(with_is_callable_t<function_4_args, int, int, int, int>::value, "Can call with(int, int, int, int)");
|
||||
static_assert(!with_is_callable_t<function_4_args, int, int, int, int, int>::value,
|
||||
"Can't call with(int, int, int, int, int)");
|
||||
} // namespace
|
||||
|
||||
// functor
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue