UT restructure
Splitting main.cpp
into several other files. Since tests require somewhat to be set up, because we need to build the objects
and search for the card, each batch of test has been split into a separate namespace which defines a test_data
class which,
well, holds the test data. This is to be constructed as shared_ptr
and registered at some test_registrar
singleton, which is able to provide a pointer (a weak_ref
) to the tests. This is necessary because it seems Unity wants a simple void (*)()
function pointer, and class methods or capturing lambdas cannot match that signature. So we need to store that somewhere; before it was on unique_ptr
s dangling in main.cpp
, now it's done via the registrar basically.
The registrar uses essentially a std::map
to store the weak_ref
to the test instance data; in order to prevent clashes, each test instance data class has to specialize template <std::uint32_t> test_instance
, where the integer stands for a generic test tag (we do not have RTTI).
Test data instances may hold a shared pointer to some "parent" level test instance, e.g. desfire_files::test_instance
holds a pointer to desfire_main::test_instance
which holds a pointer to pn532::test_instance
. This enforces that one subsystem has to be set up in order for the second to run.
Once the test main routine releases the test_instance
, the registrar will follow and mark the weak_ref
as consumed.