OpenWalnut  1.5.0dev
WLogEntry_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WLOGENTRY_TEST_H
26 #define WLOGENTRY_TEST_H
27 
28 #include <string>
29 
30 #include <cxxtest/TestSuite.h>
31 
32 #include "../WLogEntry.h"
33 
34 /**
35  * Unit tests our log messages.
36  */
37 class WLogEntryTest : public CxxTest::TestSuite
38 {
39 public:
40  /**
41  * If given a format string of the form: "%t :: %l :: %m" then
42  * the log message will replace %t with time of logging and
43  * %l with level of logging and %m with the message itself.
44  */
46  {
47  std::string dummyTime = "2009-Oct-02 14:46:50";
48  WLogEntry entry( dummyTime, "Dummy message", LL_INFO, "WLogEntryTest" );
49  // build our customized format string
50  std::string format = "%m :: %t %t %l";
51  std::string expected = "Dummy message :: 2009-Oct-02 14:46:50 %t INFO ";
52  TS_ASSERT_EQUALS( entry.getLogString( format, false ), expected );
53  }
54 
55  /**
56  * If an empty format string is given, then an empty string should be
57  * returned.
58  */
60  {
61  WLogEntry entry( "now", "msg", LL_INFO, "WLogEntryTest" );
62  TS_ASSERT_EQUALS( entry.getLogString( "", false ), "" );
63  }
64 
65  /**
66  * If ever an unknown log level was used to construct the entry then no
67  * replacement should be done.
68  */
69  void testUnkownLogLevel( void )
70  {
71  WLogEntry entry( "now", "msg", static_cast< LogLevel >( 4711 ), "WLogEntryTest" );
72  std::string expected( "%l" );
73  std::string format( "%l" );
74  TS_ASSERT_EQUALS( entry.getLogString( format, false ), expected );
75  }
76 };
77 
78 #endif // WLOGENTRY_TEST_H
Unit tests our log messages.
void testEmptyStringAsFormatString(void)
If an empty format string is given, then an empty string should be returned.
void testUnkownLogLevel(void)
If ever an unknown log level was used to construct the entry then no replacement should be done.
void testFormatStringReplacement(void)
If given a format string of the form: "%t :: %l :: %m" then the log message will replace t with time ...
Represents a simple log message with some attributes.
Definition: WLogEntry.h:57
std::string getLogString(std::string format="[%t] *%l* %m \n", bool colors=true) const
Definition: WLogEntry.cpp:77