dataKeys() method from fcf::NTest::State class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.1
Returns a set of all keys currently present in the state storage.
The
It returns a
Result
- A set containing all the keys currently stored in the state.
Example: Listing all stored keys
Demonstrating how to iterate through all keys in the state to see what data is available.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
FCF_TEST_DEFINE ("KeysDemo", "Inspection", "ListAllKeys") {
fcf::NTest::State & currentState = fcf::NTest::state ();
// 1. Populate state with some data
currentState.data ("key_a", fcf::NTest::SharedPtrAny::make <int>(1));
currentState.data ("key_b", fcf::NTest::SharedPtrAny::make <int>(2));
currentState.data ("key_c", fcf::NTest::SharedPtrAny::make <int>(3));
// 2. Retrieve all keys
std::set<std::string> keys = currentState.dataKeys ();
// 3. Print the keys
fcf::NTest::log () << "Available keys: " << std::endl;
for (const auto& key : keys) {
fcf::NTest::log () << " - " << key << std::endl;
}
FCF_TEST (keys.size() == 3);
}
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: "KeysDemo" -> "Inspection" -> "ListAllKeys" ...
> Available keys:
> - key_a
> - key_b
> - key_c
[SUCCESS] Test completed successfully (0.000`012`466 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`012`466 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.