1 #ifndef __CXXTEST__GUI_H 2 #define __CXXTEST__GUI_H 3 4 // 5 // GuiListener is a simple base class for the differes GUIs 6 // GuiTuiRunner<GuiT, TuiT> combines a GUI with a text-mode error formatter 7 // 8 9 #include <cxxtest/TeeListener.h> 10 11 namespace CxxTest 12 { 13 class GuiListener : public TestListener 14 { 15 public: GuiListener()16 GuiListener() : _state( GREEN_BAR ) {} ~GuiListener()17 virtual ~GuiListener() {} 18 runGui(int & argc,char ** argv,TestListener & listener)19 virtual void runGui( int &argc, char **argv, TestListener &listener ) 20 { 21 enterGui( argc, argv ); 22 TestRunner::runAllTests( listener ); 23 leaveGui(); 24 } 25 enterGui(int &,char **)26 virtual void enterGui( int & /*argc*/, char ** /*argv*/ ) {} leaveGui()27 virtual void leaveGui() {} 28 29 // 30 // The easy way is to implement these functions: 31 // guiEnterWorld(unsigned)32 virtual void guiEnterWorld( unsigned /*numTotalTests*/ ) {} guiEnterSuite(const char *)33 virtual void guiEnterSuite( const char * /*suiteName*/ ) {} guiEnterTest(const char *,const char *)34 virtual void guiEnterTest( const char * /*suiteName*/, const char * /*testName*/ ) {} yellowBar()35 virtual void yellowBar() {} redBar()36 virtual void redBar() {} 37 38 // 39 // The hard way is this: 40 // enterWorld(const WorldDescription & d)41 void enterWorld( const WorldDescription &d ) { guiEnterWorld( d.numTotalTests() ); } enterSuite(const SuiteDescription & d)42 void enterSuite( const SuiteDescription &d ) { guiEnterSuite( d.suiteName() ); } enterTest(const TestDescription & d)43 void enterTest( const TestDescription &d ) { guiEnterTest( d.suiteName(), d.testName() ); } leaveTest(const TestDescription &)44 void leaveTest( const TestDescription & ) {} leaveSuite(const SuiteDescription &)45 void leaveSuite( const SuiteDescription & ) {} leaveWorld(const WorldDescription &)46 void leaveWorld( const WorldDescription & ) {} 47 warning(const char *,unsigned,const char *)48 void warning( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ ) 49 { 50 yellowBarSafe(); 51 } 52 failedTest(const char *,unsigned,const char *)53 void failedTest( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ ) 54 { 55 redBarSafe(); 56 } 57 failedAssert(const char *,unsigned,const char *)58 void failedAssert( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ ) 59 { 60 redBarSafe(); 61 } 62 failedAssertEquals(const char *,unsigned,const char *,const char *,const char *,const char *)63 void failedAssertEquals( const char * /*file*/, unsigned /*line*/, 64 const char * /*xStr*/, const char * /*yStr*/, 65 const char * /*x*/, const char * /*y*/ ) 66 { 67 redBarSafe(); 68 } 69 failedAssertSameData(const char *,unsigned,const char *,const char *,const char *,const void *,const void *,unsigned)70 void failedAssertSameData( const char * /*file*/, unsigned /*line*/, 71 const char * /*xStr*/, const char * /*yStr*/, 72 const char * /*sizeStr*/, const void * /*x*/, 73 const void * /*y*/, unsigned /*size*/ ) 74 { 75 redBarSafe(); 76 } 77 failedAssertDelta(const char *,unsigned,const char *,const char *,const char *,const char *,const char *,const char *)78 void failedAssertDelta( const char * /*file*/, unsigned /*line*/, 79 const char * /*xStr*/, const char * /*yStr*/, const char * /*dStr*/, 80 const char * /*x*/, const char * /*y*/, const char * /*d*/ ) 81 { 82 redBarSafe(); 83 } 84 failedAssertDiffers(const char *,unsigned,const char *,const char *,const char *)85 void failedAssertDiffers( const char * /*file*/, unsigned /*line*/, 86 const char * /*xStr*/, const char * /*yStr*/, 87 const char * /*value*/ ) 88 { 89 redBarSafe(); 90 } 91 failedAssertLessThan(const char *,unsigned,const char *,const char *,const char *,const char *)92 void failedAssertLessThan( const char * /*file*/, unsigned /*line*/, 93 const char * /*xStr*/, const char * /*yStr*/, 94 const char * /*x*/, const char * /*y*/ ) 95 { 96 redBarSafe(); 97 } 98 failedAssertLessThanEquals(const char *,unsigned,const char *,const char *,const char *,const char *)99 void failedAssertLessThanEquals( const char * /*file*/, unsigned /*line*/, 100 const char * /*xStr*/, const char * /*yStr*/, 101 const char * /*x*/, const char * /*y*/ ) 102 { 103 redBarSafe(); 104 } 105 failedAssertPredicate(const char *,unsigned,const char *,const char *,const char *)106 void failedAssertPredicate( const char * /*file*/, unsigned /*line*/, 107 const char * /*predicate*/, const char * /*xStr*/, const char * /*x*/ ) 108 { 109 redBarSafe(); 110 } 111 failedAssertRelation(const char *,unsigned,const char *,const char *,const char *,const char *,const char *)112 void failedAssertRelation( const char * /*file*/, unsigned /*line*/, 113 const char * /*relation*/, const char * /*xStr*/, const char * /*yStr*/, 114 const char * /*x*/, const char * /*y*/ ) 115 { 116 redBarSafe(); 117 } 118 failedAssertThrows(const char *,unsigned,const char *,const char *,bool)119 void failedAssertThrows( const char * /*file*/, unsigned /*line*/, 120 const char * /*expression*/, const char * /*type*/, 121 bool /*otherThrown*/ ) 122 { 123 redBarSafe(); 124 } 125 failedAssertThrowsNot(const char *,unsigned,const char *)126 void failedAssertThrowsNot( const char * /*file*/, unsigned /*line*/, 127 const char * /*expression*/ ) 128 { 129 redBarSafe(); 130 } 131 132 protected: yellowBarSafe()133 void yellowBarSafe() 134 { 135 if ( _state < YELLOW_BAR ) { 136 yellowBar(); 137 _state = YELLOW_BAR; 138 } 139 } 140 redBarSafe()141 void redBarSafe() 142 { 143 if ( _state < RED_BAR ) { 144 redBar(); 145 _state = RED_BAR; 146 } 147 } 148 149 private: 150 enum { GREEN_BAR, YELLOW_BAR, RED_BAR } _state; 151 }; 152 153 template<class GuiT, class TuiT> 154 class GuiTuiRunner : public TeeListener 155 { 156 int &_argc; 157 char **_argv; 158 GuiT _gui; 159 TuiT _tui; 160 161 public: GuiTuiRunner(int & argc,char ** argv)162 GuiTuiRunner( int &argc, char **argv ) : 163 _argc( argc ), 164 _argv( argv ) 165 { 166 setFirst( _gui ); 167 setSecond( _tui ); 168 } 169 run()170 int run() 171 { 172 _gui.runGui( _argc, _argv, *this ); 173 return tracker().failedTests(); 174 } 175 }; 176 }; 177 178 #endif //__CXXTEST__GUI_H 179