1 | /*
|
---|
2 | * logunittest.cpp
|
---|
3 | */
|
---|
4 |
|
---|
5 |
|
---|
6 | using namespace std;
|
---|
7 |
|
---|
8 | #include <cppunit/CompilerOutputter.h>
|
---|
9 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
10 | #include <cppunit/ui/text/TestRunner.h>
|
---|
11 |
|
---|
12 | #include "logunittest.hpp"
|
---|
13 | #include "logger.hpp"
|
---|
14 | #include "errorLogger.hpp"
|
---|
15 | #include "log.hpp"
|
---|
16 | #include "defs.hpp"
|
---|
17 | #include "verbose.hpp"
|
---|
18 |
|
---|
19 | /********************************************** Test classes **************************************/
|
---|
20 |
|
---|
21 | // Registers the fixture into the 'registry'
|
---|
22 | CPPUNIT_TEST_SUITE_REGISTRATION( LogTest );
|
---|
23 |
|
---|
24 |
|
---|
25 | void LogTest::setUp()
|
---|
26 | {
|
---|
27 | };
|
---|
28 |
|
---|
29 | void LogTest::tearDown()
|
---|
30 | {
|
---|
31 | };
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * UnitTest for log()
|
---|
35 | */
|
---|
36 | void LogTest::logTest()
|
---|
37 | {
|
---|
38 | logger::getInstance()->setVerbosity(2);
|
---|
39 | cout << "Verbosity level is set to 2." << endl;
|
---|
40 | log() << Verbose(0) << "Test level 0" << endl;
|
---|
41 | log() << Verbose(1) << "Test level 1" << endl;
|
---|
42 | log() << Verbose(2) << "Test level 2" << endl;
|
---|
43 | log() << Verbose(3) << "Test level 3" << endl;
|
---|
44 | log() << Verbose(4) << "Test level 4" << endl;
|
---|
45 |
|
---|
46 | log() << Verbose(0) << "Output a log message." << endl;
|
---|
47 | elog() << Verbose(0) << "Output an error message." << endl;
|
---|
48 | setVerbosity(3);
|
---|
49 | log() << Verbose(4) << "This should not be printed." << endl;
|
---|
50 | elog() << Verbose(4) << "This should not be printed." << endl;
|
---|
51 | };
|
---|
52 |
|
---|
53 |
|
---|
54 | /********************************************** Main routine **************************************/
|
---|
55 |
|
---|
56 | int main(int argc, char **argv)
|
---|
57 | {
|
---|
58 | // Get the top level suite from the registry
|
---|
59 | CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
|
---|
60 |
|
---|
61 | // Adds the test to the list of test to run
|
---|
62 | CppUnit::TextUi::TestRunner runner;
|
---|
63 | runner.addTest( suite );
|
---|
64 |
|
---|
65 | // Change the default outputter to a compiler error format outputter
|
---|
66 | runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
|
---|
67 | std::cerr ) );
|
---|
68 | // Run the tests.
|
---|
69 | bool wasSucessful = runner.run();
|
---|
70 |
|
---|
71 | // Return error code 1 if the one of test failed.
|
---|
72 | return wasSucessful ? 0 : 1;
|
---|
73 | };
|
---|