TestLogger.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027
00028 #include "../include/TestLogger.h"
00029
00030 namespace ParCompMarkTest
00031 {
00032
00033 void TestLogger::setUp()
00034 {
00035
00036 }
00037
00038
00039
00040 void TestLogger::tearDown()
00041 {
00042 }
00043
00044
00045
00046
00047
00048
00049
00050 void TestLogger::test_constructor_cstd__string()
00051 {
00052
00053
00054
00055
00056
00057 Logger *logger = 0;
00058
00059 CPPUNIT_ASSERT_NO_THROW(logger = new Logger("logs/TestLogger1.log"));
00060 CPPUNIT_ASSERT_NO_THROW(delete logger);
00061 }
00062
00063
00064
00065 void TestLogger::test_destructor()
00066 {
00067
00068 }
00069
00070
00071
00072
00073
00074
00075
00076 void TestLogger::test_translateLogLevel_cLogLevel()
00077 {
00078
00079
00080
00081
00082
00083
00084
00085 CPPUNIT_ASSERT_NO_THROW(Logger::translateLogLevel(Logger::FATAL));
00086 CPPUNIT_ASSERT_NO_THROW(Logger::translateLogLevel(Logger::ERROR));
00087 CPPUNIT_ASSERT_NO_THROW(Logger::translateLogLevel(Logger::WARNING));
00088 CPPUNIT_ASSERT_NO_THROW(Logger::translateLogLevel(Logger::NOTICE));
00089 CPPUNIT_ASSERT_NO_THROW(Logger::translateLogLevel(Logger::DEBUG));
00090 }
00091
00092
00093
00094 void TestLogger::test_translateException_cException()
00095 {
00096
00097
00098
00099
00100
00101
00102
00103 CPPUNIT_FAIL("Implement this test!");
00104 }
00105
00106
00107
00108
00109
00110
00111
00112 void TestLogger::test_initialize()
00113 {
00114
00115
00116
00117
00118
00119
00120
00121 Logger *logger = 0;
00122
00123 CPPUNIT_ASSERT_NO_THROW(logger = new Logger("logs/TestLogger2.log"));
00124 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->initialize());
00125 CPPUNIT_ASSERT_NO_THROW(delete logger);
00126 }
00127
00128
00129
00130 void TestLogger::test_log_cLogLevel_cstd__string()
00131 {
00132
00133
00134
00135
00136
00137
00138
00139 Logger *logger = 0;
00140
00141 CPPUNIT_ASSERT_NO_THROW(logger = new Logger("logs/TestLogger3.log"));
00142 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->setConsoleLogLevel(Logger::DEBUG));
00143 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->setFileLogLevel(Logger::DEBUG));
00144 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->initialize());
00145 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->log(Logger::DEBUG, "This is a debug message"));
00146 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->log(Logger::NOTICE, "This is a notice message"));
00147 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->log(Logger::WARNING, "This is a warning message"));
00148 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->log(Logger::ERROR, "This is a error message"));
00149 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->log(Logger::FATAL, "This is a fatal message"));
00150 CPPUNIT_ASSERT_NO_THROW(delete logger);
00151 }
00152
00153
00154
00155 void TestLogger::test_logMultiLine_cLogLevel_cstd__string()
00156 {
00157
00158
00159
00160
00161
00162
00163
00164 Logger *logger = 0;
00165
00166 CPPUNIT_ASSERT_NO_THROW(logger = new Logger("logs/TestLogger4.log"));
00167 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->setConsoleLogLevel(Logger::DEBUG));
00168 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->setFileLogLevel(Logger::DEBUG));
00169 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->initialize());
00170 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->
00171 logMultiLine(Logger::DEBUG,
00172 "[1] This is the first line\n[2] This is the second line\n[3] This is the third line. That's all."));
00173 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->logMultiLine(Logger::DEBUG, "\n\nThere are empty lines.\n\n\n"));
00174 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->logMultiLine(Logger::DEBUG, "Line without backspash-n char."));
00175 CPPUNIT_ASSERT_NO_THROW(delete logger);
00176 }
00177
00178
00179
00180 void TestLogger::test_log_cException()
00181 {
00182
00183
00184
00185
00186
00187
00188
00189 Logger *logger = 0;
00190
00191 CPPUNIT_ASSERT_NO_THROW(logger = new Logger("logs/TestLogger5.log"));
00192 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->setConsoleLogLevel(Logger::DEBUG));
00193 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->setFileLogLevel(Logger::DEBUG));
00194 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->initialize());
00195 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->log(Exception()));
00196 CPPUNIT_ASSERT_NO_THROW(Logger::getInstance()->
00197 log(Exception
00198 (Exception::INVALID_OPERATION_ERROR, "It\'s a pity, is an exception", "sample.cpp",
00199 "sample()", 1234)));
00200 CPPUNIT_ASSERT_NO_THROW(delete logger);
00201 }
00202
00203
00204
00205
00207 CPPUNIT_TEST_SUITE_REGISTRATION(TestLogger);
00208 }