FCF 2.0 development in progress...
> > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

fcf::NTest::trc() function

fcf::NTest::LogWriter fcf::NTest::trc()

Package: fcfTest

File: test.hpp

Available from version: 1.0.1

Returns an fcf::NTest::LogWriter object for trace log messages. This logging level is used to extract tracing data.

The message will only be written to the output if the current logger threshold is set to fcf::NTest::LL_TRC or upper (fcf::NTest::LL_ALL).

This logging level is useful for displaying tracing information.

Result
fcf::NTest::LogWriter
- An RAII-based stream wrapper used to buffer log messages before sending them to the logger.

Example: Basic Trace Logging

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> int main(int a_arg, char* a_argv[]) { // We set the logging level, // since this level is upper than the default level (LL_TRC). fcf::NTest::logger().level(fcf::NTest::LL_TRC); fcf::NTest::trc() << "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 "Trace", we will see our message.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> // Tested structure struct User { int frontPos; void go() { ++frontPos; } void back() { --frontPos; } }; // Our main test FCF_TEST_DECLARE("Engine", "User", "Motion"){ User user = {0}; // By default, the log output will not be executed // It is necessary to set the level of logging, trace or higher. fcf::NTest::trc() << " frontPos before calling the go method: " << user.frontPos << std::endl; user.go(); fcf::NTest::trc() << " frontPos after calling the go method: " << user.frontPos << std::endl; user.back(); fcf::NTest::trc() << " frontPos after calling the back method: " << user.frontPos << std::endl; FCF_TEST(user.frontPos == 0, user.frontPos); } 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`005`657 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`005`657 sec


Running (We start with the logging mode debug):

LAUNCH $: ./example --test-log-level trc

Output:

Performing the test: "Engine" -> "User" -> "Motion" ... > frontPos before calling the go method: 0 > frontPos after calling the go method: 1 > frontPos after calling the back method: 0 [SUCCESS] Test completed successfully (0.000`013`273 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`013`273 sec