/* * logunittest.cpp */ using namespace std; #include #include #include #include "logunittest.hpp" #include "logger.hpp" #include "errorLogger.hpp" #include "log.hpp" #include "defs.hpp" #include "verbose.hpp" /********************************************** Test classes **************************************/ // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( LogTest ); void LogTest::setUp() { }; void LogTest::tearDown() { }; /** * UnitTest for log() */ void LogTest::logTest() { logger::getInstance()->setVerbosity(2); cout << "Verbosity level is set to 2." << endl; log() << Verbose(0) << "Test level 0" << endl; log() << Verbose(1) << "Test level 1" << endl; log() << Verbose(2) << "Test level 2" << endl; log() << Verbose(3) << "Test level 3" << endl; log() << Verbose(4) << "Test level 4" << endl; log() << Verbose(0) << "Output a log message." << endl; elog() << Verbose(0) << "Output an error message." << endl; setVerbosity(3); log() << Verbose(4) << "This should not be printed." << endl; elog() << Verbose(4) << "This should not be printed." << endl; }; /********************************************** Main routine **************************************/ int main(int argc, char **argv) { // Get the top level suite from the registry CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); // Adds the test to the list of test to run CppUnit::TextUi::TestRunner runner; runner.addTest( suite ); // Change the default outputter to a compiler error format outputter runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), std::cerr ) ); // Run the tests. bool wasSucessful = runner.run(); // Return error code 1 if the one of test failed. return wasSucessful ? 0 : 1; };