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: |
---|
16 | GuiListener() : _state( GREEN_BAR ) {} |
---|
17 | virtual ~GuiListener() {} |
---|
18 | |
---|
19 | virtual void runGui( int &argc, char **argv, TestListener &listener ) |
---|
20 | { |
---|
21 | enterGui( argc, argv ); |
---|
22 | TestRunner::runAllTests( listener ); |
---|
23 | leaveGui(); |
---|
24 | } |
---|
25 | |
---|
26 | virtual void enterGui( int & /*argc*/, char ** /*argv*/ ) {} |
---|
27 | virtual void leaveGui() {} |
---|
28 | |
---|
29 | // |
---|
30 | // The easy way is to implement these functions: |
---|
31 | // |
---|
32 | virtual void guiEnterWorld( unsigned /*numTotalTests*/ ) {} |
---|
33 | virtual void guiEnterSuite( const char * /*suiteName*/ ) {} |
---|
34 | virtual void guiEnterTest( const char * /*suiteName*/, const char * /*testName*/ ) {} |
---|
35 | virtual void yellowBar() {} |
---|
36 | virtual void redBar() {} |
---|
37 | |
---|
38 | // |
---|
39 | // The hard way is this: |
---|
40 | // |
---|
41 | void enterWorld( const WorldDescription &d ) { guiEnterWorld( d.numTotalTests() ); } |
---|
42 | void enterSuite( const SuiteDescription &d ) { guiEnterSuite( d.suiteName() ); } |
---|
43 | void enterTest( const TestDescription &d ) { guiEnterTest( d.suiteName(), d.testName() ); } |
---|
44 | void leaveTest( const TestDescription & ) {} |
---|
45 | void leaveSuite( const SuiteDescription & ) {} |
---|
46 | void leaveWorld( const WorldDescription & ) {} |
---|
47 | |
---|
48 | void warning( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ ) |
---|
49 | { |
---|
50 | yellowBarSafe(); |
---|
51 | } |
---|
52 | |
---|
53 | void failedTest( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ ) |
---|
54 | { |
---|
55 | redBarSafe(); |
---|
56 | } |
---|
57 | |
---|
58 | void failedAssert( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ ) |
---|
59 | { |
---|
60 | redBarSafe(); |
---|
61 | } |
---|
62 | |
---|
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 | |
---|
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 | |
---|
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 | |
---|
85 | void failedAssertDiffers( const char * /*file*/, unsigned /*line*/, |
---|
86 | const char * /*xStr*/, const char * /*yStr*/, |
---|
87 | const char * /*value*/ ) |
---|
88 | { |
---|
89 | redBarSafe(); |
---|
90 | } |
---|
91 | |
---|
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 | |
---|
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 | |
---|
106 | void failedAssertPredicate( const char * /*file*/, unsigned /*line*/, |
---|
107 | const char * /*predicate*/, const char * /*xStr*/, const char * /*x*/ ) |
---|
108 | { |
---|
109 | redBarSafe(); |
---|
110 | } |
---|
111 | |
---|
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 | |
---|
119 | void failedAssertThrows( const char * /*file*/, unsigned /*line*/, |
---|
120 | const char * /*expression*/, const char * /*type*/, |
---|
121 | bool /*otherThrown*/ ) |
---|
122 | { |
---|
123 | redBarSafe(); |
---|
124 | } |
---|
125 | |
---|
126 | void failedAssertThrowsNot( const char * /*file*/, unsigned /*line*/, |
---|
127 | const char * /*expression*/ ) |
---|
128 | { |
---|
129 | redBarSafe(); |
---|
130 | } |
---|
131 | |
---|
132 | protected: |
---|
133 | void yellowBarSafe() |
---|
134 | { |
---|
135 | if ( _state < YELLOW_BAR ) { |
---|
136 | yellowBar(); |
---|
137 | _state = YELLOW_BAR; |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
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: |
---|
162 | GuiTuiRunner( int &argc, char **argv ) : |
---|
163 | _argc( argc ), |
---|
164 | _argv( argv ) |
---|
165 | { |
---|
166 | setFirst( _gui ); |
---|
167 | setSecond( _tui ); |
---|
168 | } |
---|
169 | |
---|
170 | int run() |
---|
171 | { |
---|
172 | _gui.runGui( _argc, _argv, *this ); |
---|
173 | return tracker().failedTests(); |
---|
174 | } |
---|
175 | }; |
---|
176 | }; |
---|
177 | |
---|
178 | #endif //__CXXTEST__GUI_H |
---|