Package: fcfTest
File: test.hpp
Available from version: 1.2.2
Provides access to the global singleton instance of the central test storage.
The storage function is a global accessor for the singleton instance of the fcf::NTest::Storage class. This class acts as the central repository for all registered test metadata, including test functions, hierarchical organization (parts and groups), execution orders, and setup/teardown fixtures.
Since it is a singleton, all calls to storage throughout your application will return a reference to the same object, ensuring a unified state for test registration and management.
Result
fcf::NTest::Storage&
- A reference to the global singleton instance of the Storage class.
Example: Manual Test Registration via Storage
Demonstrating how to access the global storage to manually append a test case and a fixture.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
// A simple test function to be registered manually
void myManualTest() {
FCF_TEST(true);
}
// A simple fixture function
void myManualFixture() {
fcf::NTest::log() << "Fixture is running..." << std::endl;
}
FCF_TEST_DEFINE("Manual", "Demo", "DummyTest") {
// This test is just a placeholder to ensure the runner has something to do
FCF_TEST(true);
}
int main(int a_argc, char* a_argv[]) {
// 1. Access the global storage
fcf::NTest::Storage& storage = fcf::NTest::storage();
// 2. Manually register a new test case
// We create a Test object and append it to the storage
fcf::NTest::Test manualTest;
manualTest.part = "Manual";
manualTest.group = "Demo";
manualTest.test = "ManualFunctionTest";
manualTest.testFunction = myManualTest;
manualTest.partOrder = 1;
manualTest.groupOrder = 1;
manualTest.testOrder = 1;
storage.appendTest(manualTest);
// 3. Manually register a fixture
fcf::NTest::Fixture manualFixture;
manualFixture.parts = {"Manual"};
manualFixture.groups = {"Demo"};
manualFixture.tests = {"ManualFunctionTest"};
manualFixture.before = true;
manualFixture.level = fcf::NTest::FL_PART;
manualFixture.fixtureFunction = myManualFixture;
manualFixture.file = __FILE__;
manualFixture.line = __LINE__;
storage.appendFixture(manualFixture);
// 4. Run the tests using the standard CLI runner
bool error = false;
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
> Fixture is running...
Performing the test: "Manual" -> "Demo" -> "ManualFunctionTest" ...
[SUCCESS] Test completed successfully (0.000`000`523 sec)
Performing the test: "Manual" -> "Demo" -> "DummyTest" ...
[SUCCESS] Test completed successfully (0.000`000`276 sec)
[SUCCESS] All tests were completed.
Tests: 2 passed, 0 failed, 0 skipped, 2 total
Duration: 0.000`000`799 sec
The storage method is the backbone of the framework, allowing for programmatic control over the test registry.