40 #define NO_HIPPOMOCKS_NAMESPACE 42 #pragma GCC system_header 43 #include <hippomocks.h> 55 inline auto operator"" _ut_ree(
const char *
str, std::size_t len)
56 { (void)len;
return std::make_shared<std::runtime_error>(
str); }
58 inline auto operator"" _ut_lee(
const char *
str, std::size_t len)
59 { (void)len;
return std::make_shared<std::logic_error>(
str); }
61 inline auto operator"" _ut_iae(
const char *
str, std::size_t len)
62 { (void)len;
return std::make_shared<std::invalid_argument>(
str); }
64 inline auto operator"" _ut_ore(
const char *
str, std::size_t len)
65 { (void)len;
return std::make_shared<std::out_of_range>(
str); }
67 inline auto operator"" _ut_dme(
const char *
str, std::size_t len)
68 { (void)len;
return std::make_shared<std::domain_error>(
str); }
70 inline auto operator"" _ut_ffe(
const char *
str, std::size_t len)
71 { (void)len;
return std::make_shared<gsl::fail_fast>(
str); }
73 inline auto operator"" _ut_bae(
const char *
str, std::size_t len)
74 { (void)str; (void)len;
return std::make_shared<std::bad_alloc>(); }
76 template<class T, class = typename std::enable_if<std::is_integral<T>::value>
::type>
78 {
return reinterpret_cast<void *
>(ptr); }
80 template<class P, class T, class = typename std::enable_if<std::is_integral<T>::value>
::type>
82 {
return reinterpret_cast<P *
>(ptr); }
84 template<class T, class = typename std::enable_if<std::is_pointer<T>::value>
::type>
86 {
return reinterpret_cast<uintptr_t
>(ptr); }
100 #define expect_true(c) expect_true_with_args(c, gsl::cstring_span<>(#c), gsl::cstring_span<>(__PRETTY_FUNCTION__), __LINE__) 114 #define expect_false(c) expect_false_with_args(c, gsl::cstring_span<>(#c), gsl::cstring_span<>(__PRETTY_FUNCTION__), __LINE__) 162 #define expect_exception(f, e) expect_exception_with_args(f, e, __PRETTY_FUNCTION__, __LINE__) 198 #define expect_no_exception(f) expect_no_exception_with_args(f, __PRETTY_FUNCTION__, __LINE__) 229 #define RUN_UNITTEST_WITH_MOCKS(a,b) \ 230 this->run_unittest_with_mocks(a,b, static_cast<const char *>(__PRETTY_FUNCTION__), __LINE__); 246 #define RUN_ALL_TESTS(ut) [&]() -> decltype(auto) { (void) argc; (void) argv; ut _ut; return _ut.run(); }() 254 template<
class T>
void 271 template<
class T>
auto 274 auto &&ptr = mocks.Mock<T>();
275 mocks.OnCallDestructor(ptr);
289 template<
class T>
auto 291 {
return std::shared_ptr<T>(mocks.Mock<T>(), no_delete<T>); }
302 template<
class T>
auto 304 {
return std::unique_ptr<T>(mock_no_delete<T>(mocks)); }
316 check_exception_type(
struct exception_state &state,
const std::exception &caught,
const std::exception &expected)
322 if (
typeid(caught) !=
typeid(expected))
446 std::cout << std::uppercase;
452 catch (std::exception &e)
459 m_pass += mocks.VerifyAll();
461 catch (std::exception &e)
473 MockRepoInstanceHolder<0>::instance = 0;
479 std::string not_caught =
"no exception was caught";
480 std::string wrong_caught =
"wrong exception caught";
491 std::cerr <<
" - expecting: " <<
'\n';
499 this->
expect_failed(wrong_caught.c_str(), func.data(), line);
500 std::cerr <<
" - caught: " <<
'\n';
501 std::cout <<
" - type: " << state.
caught_type <<
'\n';
502 std::cout <<
" - what: " << state.
caught_what <<
'\n';
503 std::cerr <<
" - expecting: " <<
'\n';
569 template <
typename F>
void 571 gsl::cstring_span<> func,
int line,
int path_id = -1)
581 catch (std::exception &e) { check_exception_type(state, e, *expected); }
587 std::cerr <<
"unknown exception caught" <<
'\n';
631 template <
typename F>
void 643 catch (std::exception &e)
740 std::cout <<
"totals: ";
741 std::cout << std::dec << m_pass <<
" passed, ";
742 std::cout <<
"\033[1;31m";
743 std::cout << std::dec << m_fail <<
" failed";
744 std::cout <<
"\033[0m";
751 std::cout <<
"totals: ";
752 std::cout <<
"\033[1;32m";
753 std::cout << std::dec << m_pass <<
" passed, ";
754 std::cout <<
"\033[0m";
755 std::cout << std::dec << m_fail <<
" failed";
774 if (this->internal_init() ==
false)
777 if (this->
init() ==
false)
779 std::cout <<
"\033[1;31mFAILED\033[0m: init" <<
'\n';
785 if (this->
list() ==
false)
787 std::cout <<
"\033[1;31mFAILED\033[0m: list" <<
'\n';
791 catch (std::exception &e)
793 std::cout <<
"unexpected exception was caught: " << e.what() <<
'\n';
794 std::cout <<
"\033[1;31mFAILED\033[0m: list" <<
'\n';
799 std::cout <<
"unexpected exception was caught: unknown" <<
'\n';
800 std::cout <<
"\033[1;31mFAILED\033[0m: list" <<
'\n';
804 if (this->
fini() ==
false)
806 std::cout <<
"\033[1;31mFAILED\033[0m: fini" <<
'\n';
810 if (this->internal_fini() ==
false)
819 std::cout <<
"\033[1;31mFAILED\033[0m: [" << std::dec << line <<
"]: " << func <<
'\n';
820 std::cout <<
" - reason: " << condition <<
'\n';
std::string expecting_type
auto mock_unique(MockRepository &mocks)
auto mock_no_delete(MockRepository &mocks)
void expect_exception_with_args(F &&f, std::shared_ptr< const std::exception > expected, gsl::cstring_span<> func, int line, int path_id=-1)
void expect_true_with_args(bool condition, gsl::cstring_span<> condition_text, gsl::cstring_span<> func, int line)
void expect_no_exception_with_args(F &&f, gsl::cstring_span<> func, int line, int path_id=-1)
void expect_false_with_args(bool condition, gsl::cstring_span<> condition_text, gsl::cstring_span<> func, int line)
auto make_ptr(const T ptr)
constexpr const auto string
auto make_uintptr(const T ptr)
void assert_failed(const char *condition, const char *func, int line)
std::string to_string(const T val, const int base)
void expect_failed(const char *condition, const char *func, int line)
void run_unittest_with_mocks(MockRepository &mocks, T lamda, const char *func, int line)
constexpr const auto name
std::string expecting_what
auto mock_shared(MockRepository &mocks)
void compare_exceptions(const struct exception_state &state, gsl::cstring_span<> func, int line, int path_id=-1)