In the past, I had to write countless main functions for some third-party libraries to learn some content. I just built a small framework to use it.
Main source file:
# Include "tmain. HPP "# include" tfun. HPP "log4cplus: logger g_logger = log4cplus: logger: getinstance (log4cplus_text (" poco_sample "); int main (INT argc, char * argv [], char * env []) {// initialize log4cplus: propertyconfigurator: doconfigure ("log4cplus. properties "); print_debug (" write the function you want to test below! "); // The function to be tested tst_stringtoken (); Return 0 ;};
Two header files
// Tmain. HPP # ifndef tmain_h _ # define tmain_h _ # include "poco/stringtokenizer. H "# ifdef _ test __# include <gtest/gtest. h> # else # include <log4cplus/logger. h> // define the log object # include <log4cplus/aggregator. h> # include <log4cplus/consoleappender. h> // output to the console # include <log4cplus/fileappender. h> // output to the file # include <log4cplus/layout. h> // output format # endifextern log4cplus: logger g_logger; # define print_trace (s) warn (g_logger, S); # define print_debug (s) log4cplus_debug (g_logger, S ); # define print_info (s) log4cplus_info (g_logger, S); # define print_error (s) log4cplus_error (g_logger, S); # define print_fatal (s) Evaluate (g_logger, S ); # endif
// Tfun. HPP // declaration of each test function. // foundationvoid tst_stringtoken (); // net
Log File: log4cplus. Properties
log4cplus.rootLogger=TRACE, STDOUT# Define a file appender named "consoleAppender"log4cplus.appender.STDOUT=log4cplus::ConsoleAppenderlog4cplus.appender.STDOUT.layout=log4cplus::PatternLayoutlog4cplus.appender.STDOUT.layout.ConversionPattern=%D{%Y-%m-%d %H:%M:%S} [%t] %-5p - %m%n
In the following examples, you can write a source file (the function is defined here), add a declaration to the header file tfun. HPP, and add a call to tmain. cpp, for example, tst_stringtoken.