Public Member Functions | |
template<typename F > | |
void | expect_exception_with_args (F &&f, std::shared_ptr< const std::exception > expected, gsl::cstring_span<> func, int line, int path_id=-1) |
template<typename F > | |
void | expect_no_exception_with_args (F &&f, 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_false_with_args (bool condition, gsl::cstring_span<> condition_text, gsl::cstring_span<> func, int line) |
unittest () | |
virtual | ~unittest () |
decltype(auto) | run () |
void | expect_failed (const char *condition, const char *func, int line) |
void | assert_failed (const char *condition, const char *func, int line) |
Protected Member Functions | |
virtual bool | list () |
virtual bool | init () |
virtual bool | fini () |
template<typename T > | |
void | run_unittest_with_mocks (MockRepository &mocks, T lamda, const char *func, int line) |
void | compare_exceptions (const struct exception_state &state, gsl::cstring_span<> func, int line, int path_id=-1) |
void | inc_pass () |
void | inc_fail () |
Unit Test
This class provides the scaffolding needed to perform a unit test. Note that this class also provides support for Hippomocks.
In general, if you want an example of how to use this class, start with one of the existing unit tests, as they are cookie-cutter in design. For example, take a look at the following:
The unit test macros should be used when creating a unit test. expect_true
expect_false
expect_exception
expect_no_exception
And when a shared_ptr/unique_ptr must be created that is being mocked by Hippomocks, be sure to use:
bfn::mock_shared
bfn::mock_unique
Definition at line 355 of file unittest.h.
|
inline |
Definition at line 764 of file unittest.h.
|
inlinevirtual |
Definition at line 769 of file unittest.h.
|
inlineprotectedvirtual |
List Tests
Override this function to call each of your tests.
Reimplemented in vmcs_ut, bfelf_loader_ut, bfunwind_ut, driver_entry_ut, bfm_ut, crt_ut, debug_ring_ut, entry_ut, exit_handler_intel_x64_ut, intrinsics_ut, memory_manager_ut, misc_ut, serial_ut, vcpu_ut, and vmxon_ut.
Definition at line 383 of file unittest.h.
|
inlineprotectedvirtual |
Init Tests
Override this function to initalize your tests. It's better to use this fucntion than to use your constructor because if the init fails the unit test will stop, and report failure.
Reimplemented in vmcs_ut, bfelf_loader_ut, bfunwind_ut, driver_entry_ut, bfm_ut, crt_ut, debug_ring_ut, entry_ut, exit_handler_intel_x64_ut, intrinsics_ut, memory_manager_ut, misc_ut, serial_ut, vcpu_ut, and vmxon_ut.
Definition at line 405 of file unittest.h.
|
inlineprotectedvirtual |
Fini Tests
Override this function to finalize your tests. It's better to use this fucntion than to use your destructor because if the fini fails the unit test will stop, and report failure.
Reimplemented in vmcs_ut, bfelf_loader_ut, bfunwind_ut, driver_entry_ut, bfm_ut, crt_ut, debug_ring_ut, entry_ut, exit_handler_intel_x64_ut, intrinsics_ut, memory_manager_ut, misc_ut, serial_ut, vcpu_ut, and vmxon_ut.
Definition at line 427 of file unittest.h.
|
inlineprotected |
Definition at line 430 of file unittest.h.
|
inlineprotected |
Definition at line 477 of file unittest.h.
|
inline |
Expect Exception With Args
This macro verifies a unit test does throw an exception. If the unit test does not throw an exception, the unit test reports a failue and continues testing.
The first argument is a function that takes no arguments and returns void. If the caller wishes to pass a function that takes arguments, they must first std::bind the arguments or create a lambda, and pass the result to expect_exception_with_args.
The second argument is a shared_ptr to an instance of a std::exception for which the dynamic type is the same as the type seen in the throw statement in the function-under-test. A shared_ptr is needed to for RTTI to work properly when the expected exception is compared to the caught exception.
The third and fourth arguments correspond to __PRETTY_FUNCTION__ and __LINE__ passed from the macro expect_exception.
Definition at line 570 of file unittest.h.
|
inline |
Expect No Exception With Args
This macro verifies a unit test does not throw an exception. If the unit test does throw an exception, it reports a failue and continues testing.
The first argument is a function that takes no arguments and returns void. If the caller wishes to pass a function that takes arguments, they must first std::bind the arguments or create a lambda, and pass the result expect_no_exception_with_args
The second and third arguments correspond to __PRETTY_FUNCTION__ and __LINE__ passed in from the expect_no_exception macro.
Definition at line 632 of file unittest.h.
|
inline |
Expect true with args
This function verifies a condition in a unit test is true. If the condition is not true, the unit test reports a failure and continues testing. The macro expect_true passes the name of the function-under-test and the line on which it is invoked to this function.
Definition at line 675 of file unittest.h.
|
inline |
Expect false with args
This function verifies a condition in a unit test to be false. If the condition is not false, the unit test reports a failue and continues testing. The macro expect_false passes the name of the function-under-test and the line on which it is invoked to
Definition at line 702 of file unittest.h.
|
inlineprotected |
Definition at line 716 of file unittest.h.
|
inlineprotected |
Definition at line 717 of file unittest.h.
|
inline |
Definition at line 772 of file unittest.h.
|
inline |
Definition at line 817 of file unittest.h.
|
inline |
Definition at line 825 of file unittest.h.