Class: fcf::NTest::State
Package: fcfTest
File:
test.hpp
(
link_to_the_declaration_in_the_file
,
link_to_the_implementation_in_the_file
)
Available from version: 1.2.1
Removes a data entry from the state storage.
The eraseData method allows you to manually remove a specific piece of data from the global state using its unique key.
This is useful for cleaning up resources or ensuring that subsequent tests do not accidentally access stale data left behind by previous execution steps.
Arguments
const char* a_key
- The unique string identifier of the data entry to be removed.
Example: Removing data from state
Demonstrating how to delete a stored data entry.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
FCF_TEST_DEFINE("EraseDemo", "Cleanup", "RemoveKey") {
// 1. Set some data
fcf::NTest::state().data("temp_key", fcf::NTest::SharedPtrAny::make<int>(100));
// 2. Verify it exists
FCF_TEST(fcf::NTest::state().data("temp_key").cast<int>() != nullptr);
// 3. Erase the data
fcf::NTest::state().eraseData("temp_key");
// 4. Verify it is gone
FCF_TEST(!fcf::NTest::state().data("temp_key"));
}
int main(int a_argc, char* a_argv[]) {
bool error = false;
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
Performing the test: "EraseDemo" -> "Cleanup" -> "RemoveKey" ...
[SUCCESS] Test completed successfully (0.000`002`250 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`002`250 sec