param() method from fcf::NTest::State class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.4
Retrieves the current parameter associated with the active test iteration.
The
Result
- A fcf::NTest::SharedPtrAny object containing the current parameter, or an empty object if no parameter is set.
Example: Accessing parameters in a test
Demonstrating how to retrieve a parameter of a specific type during test execution.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
// Registering parameters for the test
FCF_TEST_BEFORE_DEFINE ("*", "*", "*", fcf::NTest::FL_GLOBAL ) {
fcf::NTest::TestPath path = {"ParamDemo", "Access", "GetParamTest"};
fcf::NTest::storage ().appendParamValue (path, std::string("Hello fcfTest!"));
fcf::NTest::storage ().appendParamValue (path, std::string("Bye fcfTest!"));
}
FCF_TEST_DEFINE ("ParamDemo", "Access", "GetParamTest") {
// 1. Retrieve the parameter from the global state
fcf::NTest::SharedPtrAny currentParam = fcf::NTest::state ().param ();
// 2. Check if the parameter is valid
FCF_TEST (currentParam, "Parameter should not be empty");
// 3. Cast the parameter to the expected type (e.g., std::string)
std::string * strPtr = currentParam.cast <std::string >();
fcf::NTest::log () << "Retrieved value: " << *strPtr << std::endl;
}
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: "ParamDemo" -> "Access" -> "GetParamTest" ...
== Parameter set: 1
> Retrieved value: Hello fcfTest!
== Parameter set: 2
> Retrieved value: Bye fcfTest!
[SUCCESS] Test completed successfully (0.000`011`864 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`011`864 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.