My Project
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes
CxxTest::X11Gui Class Reference

#include <X11Gui.h>

Public Member Functions

void enterGui (int &argc, char **argv)
 
void enterWorld (const WorldDescription &wd)
 
void guiEnterTest (const char *suiteName, const char *testName)
 
void yellowBar ()
 
void redBar ()
 
void leaveGui ()
 
- Public Member Functions inherited from CxxTest::GuiListener
 GuiListener ()
 
virtual ~GuiListener ()
 
virtual void runGui (int &argc, char **argv, TestListener &listener)
 
virtual void enterGui (int &, char **)
 
virtual void leaveGui ()
 
virtual void guiEnterWorld (unsigned)
 
virtual void guiEnterSuite (const char *)
 
virtual void guiEnterTest (const char *, const char *)
 
virtual void yellowBar ()
 
virtual void redBar ()
 
void enterWorld (const WorldDescription &d)
 
void enterSuite (const SuiteDescription &d)
 
void enterTest (const TestDescription &d)
 
void leaveTest (const TestDescription &)
 
void leaveSuite (const SuiteDescription &)
 
void leaveWorld (const WorldDescription &)
 
void warning (const char *, unsigned, const char *)
 
void failedTest (const char *, unsigned, const char *)
 
void failedAssert (const char *, unsigned, const char *)
 
void failedAssertEquals (const char *, unsigned, const char *, const char *, const char *, const char *)
 
void failedAssertSameData (const char *, unsigned, const char *, const char *, const char *, const void *, const void *, unsigned)
 
void failedAssertDelta (const char *, unsigned, const char *, const char *, const char *, const char *, const char *, const char *)
 
void failedAssertDiffers (const char *, unsigned, const char *, const char *, const char *)
 
void failedAssertLessThan (const char *, unsigned, const char *, const char *, const char *, const char *)
 
void failedAssertLessThanEquals (const char *, unsigned, const char *, const char *, const char *, const char *)
 
void failedAssertPredicate (const char *, unsigned, const char *, const char *, const char *)
 
void failedAssertRelation (const char *, unsigned, const char *, const char *, const char *, const char *, const char *)
 
void failedAssertThrows (const char *, unsigned, const char *, const char *, bool)
 
void failedAssertThrowsNot (const char *, unsigned, const char *)
 
- Public Member Functions inherited from CxxTest::TestListener
 TestListener ()
 
virtual ~TestListener ()
 
virtual void enterWorld (const WorldDescription &)
 
virtual void enterSuite (const SuiteDescription &)
 
virtual void enterTest (const TestDescription &)
 
virtual void trace (const char *, unsigned, const char *)
 
virtual void warning (const char *, unsigned, const char *)
 
virtual void failedTest (const char *, unsigned, const char *)
 
virtual void failedAssert (const char *, unsigned, const char *)
 
virtual void failedAssertEquals (const char *, unsigned, const char *, const char *, const char *, const char *)
 
virtual void failedAssertSameData (const char *, unsigned, const char *, const char *, const char *, const void *, const void *, unsigned)
 
virtual void failedAssertDelta (const char *, unsigned, const char *, const char *, const char *, const char *, const char *, const char *)
 
virtual void failedAssertDiffers (const char *, unsigned, const char *, const char *, const char *)
 
virtual void failedAssertLessThan (const char *, unsigned, const char *, const char *, const char *, const char *)
 
virtual void failedAssertLessThanEquals (const char *, unsigned, const char *, const char *, const char *, const char *)
 
virtual void failedAssertPredicate (const char *, unsigned, const char *, const char *, const char *)
 
virtual void failedAssertRelation (const char *, unsigned, const char *, const char *, const char *, const char *, const char *)
 
virtual void failedAssertThrows (const char *, unsigned, const char *, const char *, bool)
 
virtual void failedAssertThrowsNot (const char *, unsigned, const char *)
 
virtual void leaveTest (const TestDescription &)
 
virtual void leaveSuite (const SuiteDescription &)
 
virtual void leaveWorld (const WorldDescription &)
 

Private Member Functions

void parseCommandLine (int &argc, char **argv)
 
void openDisplay ()
 
void createColors ()
 
unsigned long getColor (const char *colorName)
 
void createWindow ()
 
void createGc ()
 
void createFont ()
 
bool loadFont ()
 
void useDefaultFont ()
 
void getFontInfo ()
 
void freeFontInfo ()
 
void initializeEvents ()
 
void initializeBar (const WorldDescription &wd)
 
void getTotalTests ()
 
void getTotalTests (const WorldDescription &wd)
 
void centerWindow ()
 
void processEvents ()
 
void setWindowName (const char *suiteName, const char *testName)
 
void redraw ()
 
void getWindowSize ()
 
void drawSolidBar ()
 
void drawDividers ()
 
void drawPercentage ()
 
void flush ()
 
void destroyGc ()
 
void destroyWindow ()
 
void closeDisplay ()
 

Private Attributes

const char * _programName
 
Display * _display
 
Window _window
 
unsigned _numTotalTests
 
unsigned _testsDone
 
char _strTotalTests [WorldDescription::MAX_STRLEN_TOTAL_TESTS]
 
const char * _foregroundName
 
const char * _backgroundName
 
const char * _greenName
 
const char * _yellowName
 
const char * _redName
 
unsigned long _foreground
 
unsigned long _background
 
unsigned long _barColor
 
int _width
 
int _height
 
GC _gc
 
const char * _fontName
 
XID _fontId
 
XFontStruct * _fontInfo
 
int _textHeight
 
int _textDescent
 
long _eventMask
 
Colormap _colormap
 

Additional Inherited Members

- Protected Member Functions inherited from CxxTest::GuiListener
void yellowBarSafe ()
 
void redBarSafe ()
 

Detailed Description

Definition at line 25 of file X11Gui.h.

Member Function Documentation

◆ centerWindow()

void CxxTest::X11Gui::centerWindow ( )
inlineprivate

Definition at line 218 of file X11Gui.h.

219 {
220 XMapWindow( _display, _window );
221
222 Screen *screen = XDefaultScreenOfDisplay( _display );
223 int screenWidth = WidthOfScreen( screen );
224 int screenHeight = HeightOfScreen( screen );
225 int xCenter = screenWidth / 2;
226 int yCenter = screenHeight / 2;
227
228 _width = (screenWidth * 4) / 5;
229 _height = screenHeight / 14;
230
231 XMoveResizeWindow( _display, _window, xCenter - (_width / 2), yCenter - (_height / 2), _width, _height );
232 }
Display * _display
Definition: X11Gui.h:87
Window _window
Definition: X11Gui.h:88

◆ closeDisplay()

void CxxTest::X11Gui::closeDisplay ( )
inlineprivate

Definition at line 320 of file X11Gui.h.

321 {
322 XCloseDisplay( _display );
323 }

◆ createColors()

void CxxTest::X11Gui::createColors ( )
inlineprivate

Definition at line 137 of file X11Gui.h.

138 {
139 _colormap = DefaultColormap( _display, 0 );
142 }
unsigned long _foreground
Definition: X11Gui.h:93
Colormap _colormap
Definition: X11Gui.h:101
unsigned long _background
Definition: X11Gui.h:93
unsigned long getColor(const char *colorName)
Definition: X11Gui.h:144
const char * _backgroundName
Definition: X11Gui.h:91
const char * _foregroundName
Definition: X11Gui.h:91

◆ createFont()

void CxxTest::X11Gui::createFont ( )
inlineprivate

Definition at line 162 of file X11Gui.h.

163 {
164 if ( !loadFont() )
166 getFontInfo();
167 _textHeight = _fontInfo->ascent + _fontInfo->descent;
168 _textDescent = _fontInfo->descent;
169 }
void getFontInfo()
Definition: X11Gui.h:184
void useDefaultFont()
Definition: X11Gui.h:179
int _textHeight
Definition: X11Gui.h:99
XFontStruct * _fontInfo
Definition: X11Gui.h:98
bool loadFont()
Definition: X11Gui.h:171
int _textDescent
Definition: X11Gui.h:99

◆ createGc()

void CxxTest::X11Gui::createGc ( )
inlineprivate

Definition at line 157 of file X11Gui.h.

158 {
159 _gc = XCreateGC( _display, _window, 0, 0 );
160 }

◆ createWindow()

void CxxTest::X11Gui::createWindow ( )
inlineprivate

Definition at line 152 of file X11Gui.h.

153 {
154 _window = XCreateSimpleWindow( _display, RootWindow( _display, 0 ), 0, 0, 1, 1, 0, 0, _background );
155 }

◆ destroyGc()

void CxxTest::X11Gui::destroyGc ( )
inlineprivate

Definition at line 310 of file X11Gui.h.

311 {
312 XFreeGC( _display, _gc );
313 }

◆ destroyWindow()

void CxxTest::X11Gui::destroyWindow ( )
inlineprivate

Definition at line 315 of file X11Gui.h.

316 {
317 XDestroyWindow( _display, _window );
318 }

◆ drawDividers()

void CxxTest::X11Gui::drawDividers ( )
inlineprivate

Definition at line 280 of file X11Gui.h.

281 {
282 if(_width / _numTotalTests < 5)
283 return;
284 for ( unsigned i = 1; i < _testsDone; ++ i ) {
285 int x = (_width * i) / _numTotalTests;
286 XDrawLine( _display, _window, _gc, x, 0, x, _height);
287 }
288 }
int i
Definition: cfEzgcd.cc:132
Variable x
Definition: cfModGcd.cc:4082
unsigned _testsDone
Definition: X11Gui.h:89
unsigned _numTotalTests
Definition: X11Gui.h:89

◆ drawPercentage()

void CxxTest::X11Gui::drawPercentage ( )
inlineprivate

Definition at line 290 of file X11Gui.h.

291 {
292 XSetForeground( _display, _gc, _foreground );
293
294 char str[sizeof("1000000000 of ") + sizeof(_strTotalTests) + sizeof(" (100%)")];
295 sprintf( str, "%u of %s (%u%%)", _testsDone, _strTotalTests, (_testsDone * 100) / _numTotalTests );
296 unsigned len = strlen( str );
297
298 int textWidth = XTextWidth( _fontInfo, str, len );
299
300 XDrawString( _display, _window, _gc,
301 (_width - textWidth) / 2, ((_height + _textHeight) / 2) - _textDescent,
302 str, len );
303 }
char _strTotalTests[WorldDescription::MAX_STRLEN_TOTAL_TESTS]
Definition: X11Gui.h:90
char * str(leftv arg)
Definition: shared.cc:704

◆ drawSolidBar()

void CxxTest::X11Gui::drawSolidBar ( )
inlineprivate

Definition at line 269 of file X11Gui.h.

270 {
271 unsigned barWidth = (_width * _testsDone) / _numTotalTests;
272
273 XSetForeground( _display, _gc, _barColor );
274 XFillRectangle( _display, _window, _gc, 0, 0, barWidth, _height );
275
276 XSetForeground( _display, _gc, _background );
277 XFillRectangle( _display, _window, _gc, barWidth, 0, _width + 1 - barWidth, _height );
278 }
unsigned long _barColor
Definition: X11Gui.h:93

◆ enterGui()

void CxxTest::X11Gui::enterGui ( int &  argc,
char **  argv 
)
inlinevirtual

Reimplemented from CxxTest::GuiListener.

Definition at line 28 of file X11Gui.h.

29 {
30 parseCommandLine( argc, argv );
31 }
void parseCommandLine(int &argc, char **argv)
Definition: X11Gui.h:103

◆ enterWorld()

void CxxTest::X11Gui::enterWorld ( const WorldDescription wd)
inlinevirtual

Reimplemented from CxxTest::GuiListener.

Definition at line 33 of file X11Gui.h.

34 {
36 if ( _display ) {
39 createGc();
40 createFont();
43 initializeBar( wd );
45 }
46 }
void createColors()
Definition: X11Gui.h:137
void initializeEvents()
Definition: X11Gui.h:194
void processEvents()
Definition: X11Gui.h:234
void createGc()
Definition: X11Gui.h:157
void centerWindow()
Definition: X11Gui.h:218
void initializeBar(const WorldDescription &wd)
Definition: X11Gui.h:200
void createWindow()
Definition: X11Gui.h:152
void openDisplay()
Definition: X11Gui.h:132
void createFont()
Definition: X11Gui.h:162

◆ flush()

void CxxTest::X11Gui::flush ( )
inlineprivate

Definition at line 305 of file X11Gui.h.

306 {
307 XFlush( _display );
308 }

◆ freeFontInfo()

void CxxTest::X11Gui::freeFontInfo ( )
inlineprivate

Definition at line 189 of file X11Gui.h.

190 {
191 XFreeFontInfo( NULL, _fontInfo, 1 );
192 }
#define NULL
Definition: omList.c:12

◆ getColor()

unsigned long CxxTest::X11Gui::getColor ( const char *  colorName)
inlineprivate

Definition at line 144 of file X11Gui.h.

145 {
146 XColor color;
147 XParseColor( _display, _colormap, colorName, &color );
148 XAllocColor( _display, _colormap, &color );
149 return color.pixel;
150 }

◆ getFontInfo()

void CxxTest::X11Gui::getFontInfo ( )
inlineprivate

Definition at line 184 of file X11Gui.h.

185 {
186 _fontInfo = XQueryFont( _display, _fontId );
187 }

◆ getTotalTests() [1/2]

void CxxTest::X11Gui::getTotalTests ( )
inlineprivate

Definition at line 207 of file X11Gui.h.

208 {
209 getTotalTests( tracker().world() );
210 }
void getTotalTests()
Definition: X11Gui.h:207
TestTracker & tracker()
Definition: TestTracker.h:111

◆ getTotalTests() [2/2]

void CxxTest::X11Gui::getTotalTests ( const WorldDescription wd)
inlineprivate

Definition at line 212 of file X11Gui.h.

213 {
214 _numTotalTests = wd.numTotalTests();
215 wd.strTotalTests( _strTotalTests );
216 }

◆ getWindowSize()

void CxxTest::X11Gui::getWindowSize ( )
inlineprivate

Definition at line 261 of file X11Gui.h.

262 {
263 XWindowAttributes attributes;
264 XGetWindowAttributes( _display, _window, &attributes );
265 _width = attributes.width;
266 _height = attributes.height;
267 }

◆ guiEnterTest()

void CxxTest::X11Gui::guiEnterTest ( const char *  suiteName,
const char *  testName 
)
inlinevirtual

Reimplemented from CxxTest::GuiListener.

Definition at line 48 of file X11Gui.h.

49 {
50 if ( _display ) {
51 ++ _testsDone;
52 setWindowName( suiteName, testName );
53 redraw();
54 }
55 }
void redraw()
Definition: X11Gui.h:252
void setWindowName(const char *suiteName, const char *testName)
Definition: X11Gui.h:243

◆ initializeBar()

void CxxTest::X11Gui::initializeBar ( const WorldDescription wd)
inlineprivate

Definition at line 200 of file X11Gui.h.

201 {
202 getTotalTests( wd );
203 _testsDone = 0;
205 }
const char * _greenName
Definition: X11Gui.h:92

◆ initializeEvents()

void CxxTest::X11Gui::initializeEvents ( )
inlineprivate

Definition at line 194 of file X11Gui.h.

195 {
196 _eventMask = ExposureMask;
197 XSelectInput( _display, _window, _eventMask );
198 }
long _eventMask
Definition: X11Gui.h:100

◆ leaveGui()

void CxxTest::X11Gui::leaveGui ( )
inlinevirtual

Reimplemented from CxxTest::GuiListener.

Definition at line 75 of file X11Gui.h.

76 {
77 if ( _display ) {
79 destroyGc();
82 }
83 }
void closeDisplay()
Definition: X11Gui.h:320
void destroyGc()
Definition: X11Gui.h:310
void freeFontInfo()
Definition: X11Gui.h:189
void destroyWindow()
Definition: X11Gui.h:315

◆ loadFont()

bool CxxTest::X11Gui::loadFont ( )
inlineprivate

Definition at line 171 of file X11Gui.h.

172 {
173 if ( !_fontName )
174 return false;
175 _fontId = XLoadFont( _display, _fontName );
176 return (XSetFont( _display, _gc, _fontId ) == Success);
177 }
const char * _fontName
Definition: X11Gui.h:96

◆ openDisplay()

void CxxTest::X11Gui::openDisplay ( )
inlineprivate

Definition at line 132 of file X11Gui.h.

133 {
134 _display = XOpenDisplay( NULL );
135 }

◆ parseCommandLine()

void CxxTest::X11Gui::parseCommandLine ( int &  argc,
char **  argv 
)
inlineprivate

Definition at line 103 of file X11Gui.h.

104 {
105 _programName = argv[0];
106
107 _fontName = 0;
108 _foregroundName = "Black";
109 _backgroundName = "Grey";
110 _greenName = "Green";
111 _yellowName = "Yellow";
112 _redName = "Red";
113
114 for ( int i = 1; i + 1 < argc; ++ i ) {
115 if ( !strcmp( argv[i], "-title" ) )
116 _programName = argv[++ i];
117 else if ( !strcmp( argv[i], "-fn" ) || !strcmp( argv[i], "-font" ) )
118 _fontName = argv[++ i];
119 else if ( !strcmp( argv[i], "-fg" ) || !strcmp( argv[i], "-foreground" ) )
120 _foregroundName = argv[++ i];
121 else if ( !strcmp( argv[i], "-bg" ) || !strcmp( argv[i], "-background" ) )
122 _backgroundName = argv[++ i];
123 else if ( !strcmp( argv[i], "-green" ) )
124 _greenName = argv[++ i];
125 else if ( !strcmp( argv[i], "-yellow" ) )
126 _yellowName = argv[++ i];
127 else if ( !strcmp( argv[i], "-red" ) )
128 _redName = argv[++ i];
129 }
130 }
const char * _yellowName
Definition: X11Gui.h:92
const char * _programName
Definition: X11Gui.h:86
const char * _redName
Definition: X11Gui.h:92

◆ processEvents()

void CxxTest::X11Gui::processEvents ( )
inlineprivate

Definition at line 234 of file X11Gui.h.

235 {
236 redraw();
237
238 XEvent event;
239 while( XCheckMaskEvent( _display, _eventMask, &event ) )
240 redraw();
241 }

◆ redBar()

void CxxTest::X11Gui::redBar ( )
inlinevirtual

Reimplemented from CxxTest::GuiListener.

Definition at line 66 of file X11Gui.h.

67 {
68 if ( _display ) {
72 }
73 }

◆ redraw()

void CxxTest::X11Gui::redraw ( )
inlineprivate

Definition at line 252 of file X11Gui.h.

253 {
255 drawSolidBar();
256 drawDividers();
258 flush();
259 }
void drawPercentage()
Definition: X11Gui.h:290
void drawSolidBar()
Definition: X11Gui.h:269
void flush()
Definition: X11Gui.h:305
void drawDividers()
Definition: X11Gui.h:280
void getWindowSize()
Definition: X11Gui.h:261

◆ setWindowName()

void CxxTest::X11Gui::setWindowName ( const char *  suiteName,
const char *  testName 
)
inlineprivate

Definition at line 243 of file X11Gui.h.

244 {
245 unsigned length = strlen( _programName ) + strlen( suiteName ) + strlen( testName ) + sizeof( " - ::()" );
246 char *name = (char *)malloc( length );
247 sprintf( name, "%s - %s::%s()", _programName, suiteName, testName );
248 XSetStandardProperties( _display, _window, name, 0, 0, 0, 0, 0 );
249 free( name );
250 }
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:257
#define free
Definition: omAllocFunc.c:14
#define malloc
Definition: omAllocFunc.c:12
int name
New type name for int.
Definition: templateForC.h:21

◆ useDefaultFont()

void CxxTest::X11Gui::useDefaultFont ( )
inlineprivate

Definition at line 179 of file X11Gui.h.

180 {
181 _fontId = XGContextFromGC( _gc );
182 }

◆ yellowBar()

void CxxTest::X11Gui::yellowBar ( )
inlinevirtual

Reimplemented from CxxTest::GuiListener.

Definition at line 57 of file X11Gui.h.

58 {
59 if ( _display ) {
63 }
64 }

Field Documentation

◆ _background

unsigned long CxxTest::X11Gui::_background
private

Definition at line 93 of file X11Gui.h.

◆ _backgroundName

const char * CxxTest::X11Gui::_backgroundName
private

Definition at line 91 of file X11Gui.h.

◆ _barColor

unsigned long CxxTest::X11Gui::_barColor
private

Definition at line 93 of file X11Gui.h.

◆ _colormap

Colormap CxxTest::X11Gui::_colormap
private

Definition at line 101 of file X11Gui.h.

◆ _display

Display* CxxTest::X11Gui::_display
private

Definition at line 87 of file X11Gui.h.

◆ _eventMask

long CxxTest::X11Gui::_eventMask
private

Definition at line 100 of file X11Gui.h.

◆ _fontId

XID CxxTest::X11Gui::_fontId
private

Definition at line 97 of file X11Gui.h.

◆ _fontInfo

XFontStruct* CxxTest::X11Gui::_fontInfo
private

Definition at line 98 of file X11Gui.h.

◆ _fontName

const char* CxxTest::X11Gui::_fontName
private

Definition at line 96 of file X11Gui.h.

◆ _foreground

unsigned long CxxTest::X11Gui::_foreground
private

Definition at line 93 of file X11Gui.h.

◆ _foregroundName

const char* CxxTest::X11Gui::_foregroundName
private

Definition at line 91 of file X11Gui.h.

◆ _gc

GC CxxTest::X11Gui::_gc
private

Definition at line 95 of file X11Gui.h.

◆ _greenName

const char* CxxTest::X11Gui::_greenName
private

Definition at line 92 of file X11Gui.h.

◆ _height

int CxxTest::X11Gui::_height
private

Definition at line 94 of file X11Gui.h.

◆ _numTotalTests

unsigned CxxTest::X11Gui::_numTotalTests
private

Definition at line 89 of file X11Gui.h.

◆ _programName

const char* CxxTest::X11Gui::_programName
private

Definition at line 86 of file X11Gui.h.

◆ _redName

const char * CxxTest::X11Gui::_redName
private

Definition at line 92 of file X11Gui.h.

◆ _strTotalTests

char CxxTest::X11Gui::_strTotalTests[WorldDescription::MAX_STRLEN_TOTAL_TESTS]
private

Definition at line 90 of file X11Gui.h.

◆ _testsDone

unsigned CxxTest::X11Gui::_testsDone
private

Definition at line 89 of file X11Gui.h.

◆ _textDescent

int CxxTest::X11Gui::_textDescent
private

Definition at line 99 of file X11Gui.h.

◆ _textHeight

int CxxTest::X11Gui::_textHeight
private

Definition at line 99 of file X11Gui.h.

◆ _width

int CxxTest::X11Gui::_width
private

Definition at line 94 of file X11Gui.h.

◆ _window

Window CxxTest::X11Gui::_window
private

Definition at line 88 of file X11Gui.h.

◆ _yellowName

const char * CxxTest::X11Gui::_yellowName
private

Definition at line 92 of file X11Gui.h.


The documentation for this class was generated from the following file: