OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WTerminalColor_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 WTERMINALCOLOR_TEST_H
26 #define WTERMINALCOLOR_TEST_H
27 
28 #include <string>
29 #include <sstream>
30 
31 #include <boost/shared_ptr.hpp>
32 #include <cxxtest/TestSuite.h>
33 
34 #include "../WTerminalColor.h"
35 
36 /**
37  * Test WTerminalColor. Just some simple test to verify the control strings.
38  */
39 class WTerminalColorTest : public CxxTest::TestSuite
40 {
41 public:
42  /**
43  * An instantiation should never throw an exception.
44  */
45  void testInstantiation( void )
46  {
47  TS_ASSERT_THROWS_NOTHING( WTerminalColor c() );
48  TS_ASSERT_THROWS_NOTHING( WTerminalColor( WTerminalColor::Bold, WTerminalColor::FGRed, WTerminalColor::BGNone ) );
49  }
50 
51  /**
52  * Test control string generated by class.
53  */
55  {
57  TS_ASSERT_THROWS_NOTHING( c = WTerminalColor( WTerminalColor::Bold, WTerminalColor::FGRed, WTerminalColor::BGGreen ) );
58 
59  // generate an own control string
60  std::ostringstream ss;
61 #ifdef __linux__
62  char cStart = 0x1B;
63  ss << cStart << "[" << 1 << ";" << 31 << ";" << 42 << "m";
64 #endif
65  // compare them
66  TS_ASSERT( ss.str() == c.m_colorString );
67  }
68 
69  /**
70  * Test control string (reset) generated by class.
71  */
73  {
75  TS_ASSERT_THROWS_NOTHING( c = WTerminalColor( WTerminalColor::Bold, WTerminalColor::FGRed, WTerminalColor::BGGreen ) );
76 
77  // generate an own control string
78  std::ostringstream ss;
79 #ifdef __linux__
80  char cStart = 0x1B;
81  ss << cStart << "[0m";
82 #endif
83  // compare them
84  TS_ASSERT( ss.str() == c.m_colorResetString );
85  }
86 
87  /**
88  * Test whether the class returns empty control strings when colors are disabled.
89  */
90  void testColorDisabled( void )
91  {
93  TS_ASSERT_THROWS_NOTHING( c = WTerminalColor( WTerminalColor::Bold, WTerminalColor::FGRed, WTerminalColor::BGGreen ) );
94 
95  c.setEnabled( false );
96  TS_ASSERT( c.m_colorResetString == "" );
97  TS_ASSERT( c.m_colorString == "" );
98  }
99 };
100 
101 #endif // WTERMINALCOLOR_TEST_H