Package: fcfTest
File: test.hpp
Available from version: 1.0.1
Returns an fcf::NTest::LogWriter object for info level log messages. This level is used for message with a secondary importance
The message will only be written to the output if the current logger threshold is set to fcf::NTest::LL_INF or upper (e.g., fcf::NTest::LL_ALL, fcf::NTest::LL_DBG, fcf::NTest::LL_TRC).
This logging level is useful for displaying extended information when a large volume of output data makes it difficult to understand and monitor the test status.
Result
fcf::NTest::LogWriter
- An RAII-based stream wrapper used to buffer log messages before sending them to the logger.
Example: Basic Info Logging
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
int main() {
// We set the logging level,
// since this level is upper than the default level (LL_LOG).
fcf::NTest::logger().level(fcf::NTest::LL_INF);
fcf::NTest::inf() << "The application is running." << std::endl;
return 0;
}
Output:
> The application is running.
Example: Output to terminal with switching to logging mode
If we just run this test, then we will not see any message. However, if we run the test by transferring the login mode to "Info", we will see our message.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
// Tested structure
struct User {
volatile int frontPos;
void go(){
++frontPos;
}
};
// Our main test
FCF_TEST_DECLARE("Engine", "User", "Motion"){
User user = {0};
// Launch our benchmark
fcf::NTest::Duration bench(10001);
bench([&](){
user.go();
});
// We write a message about the total duration of the test
fcf::NTest::inf() << "The total time of execution: " << bench.totalDuration().count() << std::endl;
}
int main(int a_argc, char* a_argv[]) {
bool error;
// We run all tests declared in the application
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Running (Start by default. Level logging is log):
LAUNCH $: ./example
Output:
Performing the test: "Engine" -> "User" -> "Motion" ...
[SUCCESS] Test completed successfully (0.000`026`483 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`026`483 sec
Running (We start with the logging mode info):
LAUNCH $: ./example --test-log-level inf
Output:
Performing the test: "Engine" -> "User" -> "Motion" ...
> The total time of execution: 23166
[SUCCESS] Test completed successfully (0.000`044`008 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`044`008 sec