My Project
Loading...
Searching...
No Matches
Gui.h
Go to the documentation of this file.
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
10
11namespace CxxTest
12{
14 {
15 public:
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 //
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 {
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:
134 {
135 if ( _state < YELLOW_BAR ) {
136 yellowBar();
138 }
139 }
140
142 {
143 if ( _state < RED_BAR ) {
144 redBar();
145 _state = RED_BAR;
146 }
147 }
148
149 private:
151 };
152
153 template<class GuiT, class TuiT>
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
void failedAssert(const char *, unsigned, const char *)
Definition: Gui.h:58
void failedAssertEquals(const char *, unsigned, const char *, const char *, const char *, const char *)
Definition: Gui.h:63
void failedAssertLessThanEquals(const char *, unsigned, const char *, const char *, const char *, const char *)
Definition: Gui.h:99
void failedAssertPredicate(const char *, unsigned, const char *, const char *, const char *)
Definition: Gui.h:106
void redBarSafe()
Definition: Gui.h:141
void leaveWorld(const WorldDescription &)
Definition: Gui.h:46
enum CxxTest::GuiListener::@8 _state
void failedTest(const char *, unsigned, const char *)
Definition: Gui.h:53
virtual void guiEnterTest(const char *, const char *)
Definition: Gui.h:34
virtual void yellowBar()
Definition: Gui.h:35
void enterSuite(const SuiteDescription &d)
Definition: Gui.h:42
void leaveTest(const TestDescription &)
Definition: Gui.h:44
void failedAssertLessThan(const char *, unsigned, const char *, const char *, const char *, const char *)
Definition: Gui.h:92
void enterTest(const TestDescription &d)
Definition: Gui.h:43
virtual void runGui(int &argc, char **argv, TestListener &listener)
Definition: Gui.h:19
virtual ~GuiListener()
Definition: Gui.h:17
void yellowBarSafe()
Definition: Gui.h:133
virtual void enterGui(int &, char **)
Definition: Gui.h:26
void failedAssertThrowsNot(const char *, unsigned, const char *)
Definition: Gui.h:126
virtual void guiEnterSuite(const char *)
Definition: Gui.h:33
void failedAssertDelta(const char *, unsigned, const char *, const char *, const char *, const char *, const char *, const char *)
Definition: Gui.h:78
void warning(const char *, unsigned, const char *)
Definition: Gui.h:48
void enterWorld(const WorldDescription &d)
Definition: Gui.h:41
virtual void redBar()
Definition: Gui.h:36
virtual void leaveGui()
Definition: Gui.h:27
void failedAssertSameData(const char *, unsigned, const char *, const char *, const char *, const void *, const void *, unsigned)
Definition: Gui.h:70
void failedAssertThrows(const char *, unsigned, const char *, const char *, bool)
Definition: Gui.h:119
void failedAssertRelation(const char *, unsigned, const char *, const char *, const char *, const char *, const char *)
Definition: Gui.h:112
void leaveSuite(const SuiteDescription &)
Definition: Gui.h:45
virtual void guiEnterWorld(unsigned)
Definition: Gui.h:32
void failedAssertDiffers(const char *, unsigned, const char *, const char *, const char *)
Definition: Gui.h:85
GuiTuiRunner(int &argc, char **argv)
Definition: Gui.h:162
char ** _argv
Definition: Gui.h:157
virtual const char * suiteName() const =0
void setFirst(TestListener &first)
Definition: TeeListener.h:26
void setSecond(TestListener &second)
Definition: TeeListener.h:31
virtual const char * suiteName() const =0
virtual const char * testName() const =0
static void runAllTests(TestListener &listener)
Definition: TestRunner.h:20
unsigned failedTests() const
Definition: TestTracker.h:37
virtual unsigned numTotalTests(void) const =0
TestTracker & tracker()
Definition: TestTracker.h:111