Go to the source code of this file.
Data Structures | |
struct | exception_state |
class | unittest |
Namespaces | |
bfn | |
Macros | |
#define | NO_HIPPOMOCKS_NAMESPACE |
#define | expect_true(c) expect_true_with_args(c, gsl::cstring_span<>(#c), gsl::cstring_span<>(__PRETTY_FUNCTION__), __LINE__) |
#define | expect_false(c) expect_false_with_args(c, gsl::cstring_span<>(#c), gsl::cstring_span<>(__PRETTY_FUNCTION__), __LINE__) |
#define | expect_exception(f, e) expect_exception_with_args(f, e, __PRETTY_FUNCTION__, __LINE__) |
#define | expect_no_exception(f) expect_no_exception_with_args(f, __PRETTY_FUNCTION__, __LINE__) |
#define | RUN_UNITTEST_WITH_MOCKS(a, b) this->run_unittest_with_mocks(a,b, static_cast<const char *>(__PRETTY_FUNCTION__), __LINE__); |
#define | RUN_ALL_TESTS(ut) [&]() -> decltype(auto) { (void) argc; (void) argv; ut _ut; return _ut.run(); }() |
Functions | |
auto | operator"" _ut_ree (const char *str, std::size_t len) |
auto | operator"" _ut_lee (const char *str, std::size_t len) |
auto | operator"" _ut_iae (const char *str, std::size_t len) |
auto | operator"" _ut_ore (const char *str, std::size_t len) |
auto | operator"" _ut_dme (const char *str, std::size_t len) |
auto | operator"" _ut_ffe (const char *str, std::size_t len) |
auto | operator"" _ut_bae (const char *str, std::size_t len) |
template<class T , class = typename std::enable_if<std::is_integral<T>::value>::type> | |
auto | make_ptr (const T ptr) |
template<class P , class T , class = typename std::enable_if<std::is_integral<T>::value>::type> | |
auto | make_ptr (const T ptr) |
template<class T , class = typename std::enable_if<std::is_pointer<T>::value>::type> | |
auto | make_uintptr (const T ptr) |
template<class T > | |
void | no_delete (T *) |
template<class T > | |
auto | bfn::mock_no_delete (MockRepository &mocks) |
template<class T > | |
auto | bfn::mock_shared (MockRepository &mocks) |
template<class T > | |
auto | bfn::mock_unique (MockRepository &mocks) |
#define NO_HIPPOMOCKS_NAMESPACE |
Definition at line 40 of file unittest.h.
#define expect_true | ( | c | ) | expect_true_with_args(c, gsl::cstring_span<>(#c), gsl::cstring_span<>(__PRETTY_FUNCTION__), __LINE__) |
Expect True
This macro passes the boolean condition c along with the caller's name and line information to expect_true_with_args. This macro must be invoked on the unittest object using this.
Definition at line 100 of file unittest.h.
#define expect_false | ( | c | ) | expect_false_with_args(c, gsl::cstring_span<>(#c), gsl::cstring_span<>(__PRETTY_FUNCTION__), __LINE__) |
Expect False
This macro passes the boolean condition c along with the caller's name and line information to expect_false_with_args. This macro must be invoked on the unittest object using this.
Definition at line 114 of file unittest.h.
#define expect_exception | ( | f, | |
e | |||
) | expect_exception_with_args(f, e, __PRETTY_FUNCTION__, __LINE__) |
Expect Exception
This macro is used to pass the function name and line number to expect_exception_with_args. The argument f is a function that takes no arguments and returns void. The argument e is a std::shared_ptr<std::exception> whose dynamic type is the same as the exception in the throw statement in function-under-test.
If the caller wishes to pass a function that takes arguments they must first std::bind the arguments or create a lambda with the desired call, and pass the result to expect_exception.
Definition at line 162 of file unittest.h.
#define expect_no_exception | ( | f | ) | expect_no_exception_with_args(f, __PRETTY_FUNCTION__, __LINE__) |
Expect No Exception
This macro is used to pass the function name and line number to expect_no_exception_with_args. The argument f is a callable object that returns void and takes no arguments
If the caller wishes to pass a function that takes arguments they must first std::bind the arguments or create a lambda with the desired call, and pass the result to expect_no_exception.
Definition at line 198 of file unittest.h.
#define RUN_UNITTEST_WITH_MOCKS | ( | a, | |
b | |||
) | this->run_unittest_with_mocks(a,b, static_cast<const char *>(__PRETTY_FUNCTION__), __LINE__); |
Run Unittests with Mocks
When using mocks, it's possible that hippomocks could throw an exception. For example, if you call a function on a mocked class that you have not setup an "OnCall" for. If this happens, a default function within hippomocks is called, that throws an exception.
To handle these types of issues, mocks should be used inside this function call using a lamda function. This way, if an exeption should occur, the unit test handles it properly. This call will also check to see if the mock's expectations are satisfied. If they are not, it will also fail the unit test.
Definition at line 229 of file unittest.h.
#define RUN_ALL_TESTS | ( | ut | ) | [&]() -> decltype(auto) { (void) argc; (void) argv; ut _ut; return _ut.run(); }() |
Run Unit Tests
This runs your unit test. Use the following to kick off your unit tests
Definition at line 246 of file unittest.h.
|
inline |
Definition at line 55 of file unittest.h.
|
inline |
Definition at line 58 of file unittest.h.
|
inline |
Definition at line 61 of file unittest.h.
|
inline |
Definition at line 64 of file unittest.h.
|
inline |
Definition at line 67 of file unittest.h.
|
inline |
Definition at line 70 of file unittest.h.
|
inline |
Definition at line 73 of file unittest.h.
auto make_ptr | ( | const T | ptr | ) |
Definition at line 77 of file unittest.h.
auto make_ptr | ( | const T | ptr | ) |
Definition at line 81 of file unittest.h.
auto make_uintptr | ( | const T | ptr | ) |
Definition at line 85 of file unittest.h.
void no_delete | ( | T * | ) |
No Delete
This is used by mock_shared to prevent a shared pointer from performing the deletion of the variable. In this case, mock is doing this for us. Note that this should not be used directly.
Definition at line 255 of file unittest.h.