paramIndex() method from fcf::NTest::State class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.4
Returns the index of the current parameter being processed.
The
This is useful for tracking progress or identifying which specific iteration of a parameterized test is currently being executed.
Result
- The current parameter index.
Example: Tracking parameter index
Demonstrating how to use paramIndex to identify the current iteration.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
FCF_TEST_DEFINE ("ParamDemo", "Index", "IndexTest") {
// 1. On the first call, you can add parameters for the test
// The value of fcf::NTest::State::param() will also be updated!
if (fcf::NTest::state ().paramIndex () == 0) {
fcf::NTest::storage ().appendParamValue (fcf::NTest::state ().test (), 10);
fcf::NTest::storage ().appendParamValue (fcf::NTest::state ().test (), 20);
}
// 2. Get the current index
size_t currentIndex = fcf::NTest::state ().paramIndex ();
fcf::NTest::log () << "Currently processing parameter index: " << currentIndex << std::endl;
// 3. Get the current parameter
fcf::NTest::SharedPtrAny currentParam = fcf::NTest::state ().param ();
fcf::NTest::log () << "Currently processing parameter value: " << *currentParam.cast <int>() << 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" -> "Index" -> "IndexTest" ...
== Parameter set: 1
> Currently processing parameter index: 0
> Currently processing parameter value: 10
== Parameter set: 2
> Currently processing parameter index: 1
> Currently processing parameter value: 20
[SUCCESS] Test completed successfully (0.000`029`661 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`029`661 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.