params() method from fcf::NTest::Storage class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.4
Returns or sets all parameters associated with a specific test.
The
This method has two distinct behaviors depending on whether it is used for reading or writing:
- Read Mode: When called without the
a_params argument, a copy of the parameters of the current parameter collection of the specific test (astd::vector of thefcf::NTest::SharedPtrAny object) is returned. - Write Mode: When called with the
a_param argument, it replaces the current parameters collection of the specific test.
Arguments
- The name of the test part.
- The name of the test group.
- The name of the test.
- The value to set for a new parameter collection.
Result
- A vector containing all parameters for the specified test.
Example: Retrieving all parameters for a test
Demonstrating how to fetch and iterate through all parameters assigned to a test.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
// Set the test parameters in the global fiction
FCF_TEST_BEFORE_DEFINE ("*", "*", "*", fcf::NTest::FL_GLOBAL ) {
fcf::NTest::log () << "Updating test parameters" << std::endl;
std::vector <fcf::NTest::SharedPtrAny > params = {
fcf::NTest::SharedPtrAny::make <int>(100),
fcf::NTest::SharedPtrAny::make <int>(200),
fcf::NTest::SharedPtrAny::make <int>(300),
};
fcf::NTest::storage ().params ("Data", "Batch", "MultiParamTest", params);
}
FCF_TEST_DEFINE ("Data", "Batch", "MultiParamTest") {
// Get the current test parameter
fcf::NTest::log () << "Current test parameter:" << *fcf::NTest::state ().param ().cast <int>() << std::endl;
// Output all test parameters, but only the first time the test is run
if (fcf::NTest::state().paramIndex() == 0) {
// Get all test parameters
std::vector <fcf::NTest::SharedPtrAny > allParams = fcf::NTest::storage ().params ("Data", "Batch", "MultiParamTest");
fcf::NTest::log () << "Found " << allParams.size() << " parameters." << std::endl;
// Iterate and inspect each parameter
for (size_t i = 0; i < allParams.size(); ++i) {
int * val = allParams[i].cast <int >();
fcf::NTest::log () << " Param " << i + 1 << ": " << *val << 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:
> Updating test parameters
Performing the test: "Data" -> "Batch" -> "MultiParamTest" ...
== Parameter set: 1
> Current test parameter:100
> Found 3 parameters.
> Param 1: 100
> Param 2: 200
> Param 3: 300
== Parameter set: 2
> Current test parameter:200
== Parameter set: 3
> Current test parameter:300
[SUCCESS] Test completed successfully (0.000`023`446 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`023`446 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.