OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WLOGENTRY_TEST_H 00026 #define WLOGENTRY_TEST_H 00027 00028 #include <string> 00029 00030 #include <cxxtest/TestSuite.h> 00031 00032 #include "../WLogEntry.h" 00033 00034 /** 00035 * Unit tests our log messages. 00036 */ 00037 class WLogEntryTest : public CxxTest::TestSuite 00038 { 00039 public: 00040 /** 00041 * If given a format string of the form: "%t :: %l :: %m" then 00042 * the log message will replace %t with time of logging and 00043 * %l with level of logging and %m with the message itself. 00044 */ 00045 void testFormatStringReplacement( void ) 00046 { 00047 std::string dummyTime = "2009-Oct-02 14:46:50"; 00048 WLogEntry entry( dummyTime, "Dummy message", LL_INFO, "WLogEntryTest" ); 00049 // build our customized format string 00050 std::string format = "%m :: %t %t %l"; 00051 std::string expected = "Dummy message :: 2009-Oct-02 14:46:50 %t INFO "; 00052 TS_ASSERT_EQUALS( entry.getLogString( format, false ), expected ); 00053 } 00054 00055 /** 00056 * If an empty format string is given, then an empty string should be 00057 * returned. 00058 */ 00059 void testEmptyStringAsFormatString( void ) 00060 { 00061 WLogEntry entry( "now", "msg", LL_INFO, "WLogEntryTest" ); 00062 TS_ASSERT_EQUALS( entry.getLogString( "", false ), "" ); 00063 } 00064 00065 /** 00066 * If ever an unknown log level was used to construct the entry then no 00067 * replacement should be done. 00068 */ 00069 void testUnkownLogLevel( void ) 00070 { 00071 WLogEntry entry( "now", "msg", static_cast< LogLevel >( 4711 ), "WLogEntryTest" ); 00072 std::string expected( "%l" ); 00073 std::string format( "%l" ); 00074 TS_ASSERT_EQUALS( entry.getLogString( format, false ), expected ); 00075 } 00076 }; 00077 00078 #endif // WLOGENTRY_TEST_H