TestLogger.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // This source file is a part of ParCompMark
00004 // Parallel Compositing Benchmark Framework
00005 //
00006 // for latest info see http://parcompmark.sourceforge.net
00007 
00008 //
00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team
00010 // 
00011 // This program is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2
00014 // of the License, or (at your option) any later version.
00015 // 
00016 // This program is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public License
00022 // along with this program; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 
00027 
00028 #include "../include/TestLogger.h"
00029 
00030 namespace ParCompMarkTest
00031 {
00032 
00033   void TestLogger::setUp()
00034   {
00035         // TestLogger does not need a logger :)
00036   }
00037 
00038  /*----------------------------------------------------------------------*/
00039 
00040   void TestLogger::tearDown()
00041   {
00042   }
00043 
00044  /*----------------------------------------------------------------------*/
00045 
00046   //
00047   // Constructor & destructor tests
00048   //
00049 
00050   void TestLogger::test_constructor_cstd__string()
00051   {
00052         /*
00053          * You have to verify the following:
00054          * 
00055          * Create logger.
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         // Tested above
00068   }
00069 
00070  /*----------------------------------------------------------------------*/
00071 
00072   //
00073   // Class method tests
00074   //
00075 
00076   void TestLogger::test_translateLogLevel_cLogLevel()
00077   {
00078 
00079         /*
00080          * You have to verify the following:
00081          * 
00082          * Translate log level to human readable.
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          * You have to verify the following:
00099          * 
00100          * Translate an exception to human readable.
00101          */
00102 
00103         CPPUNIT_FAIL("Implement this test!");
00104   }
00105 
00106  /*----------------------------------------------------------------------*/
00107 
00108   //
00109   // Method tests
00110   //
00111 
00112   void TestLogger::test_initialize()
00113   {
00114 
00115         /*
00116          * You have to verify the following:
00117          * 
00118          * Initializes the logger.
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          * You have to verify the following:
00135          * 
00136          * Logs a message. (Does not care about multiline messages, because of performance).
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          * You have to verify the following:
00160          * 
00161          * Logs a message. Handles multiline messages too. 
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          * You have to verify the following:
00185          * 
00186          * Logs an exception.
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   // To register the suite we add:
00207   CPPUNIT_TEST_SUITE_REGISTRATION(TestLogger);
00208 }