1 #ifndef __cxxtest__X11Gui_h__ 2 #define __cxxtest__X11Gui_h__ 18 #include <X11/Xutil.h> 105 _programName = argv[0];
108 _foregroundName =
"Black";
109 _backgroundName =
"Grey";
110 _greenName =
"Green";
111 _yellowName =
"Yellow";
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];
134 _display = XOpenDisplay(
NULL );
139 _colormap = DefaultColormap( _display, 0 );
140 _foreground =
getColor( _foregroundName );
141 _background =
getColor( _backgroundName );
147 XParseColor( _display, _colormap, colorName, &color );
148 XAllocColor( _display, _colormap, &color );
154 _window = XCreateSimpleWindow( _display, RootWindow( _display, 0 ), 0, 0, 1, 1, 0, 0, _background );
159 _gc = XCreateGC( _display, _window, 0, 0 );
167 _textHeight = _fontInfo->ascent + _fontInfo->descent;
168 _textDescent = _fontInfo->descent;
175 _fontId = XLoadFont( _display, _fontName );
176 return (XSetFont( _display, _gc, _fontId ) == Success);
181 _fontId = XGContextFromGC( _gc );
186 _fontInfo = XQueryFont( _display, _fontId );
191 XFreeFontInfo(
NULL, _fontInfo, 1 );
196 _eventMask = ExposureMask;
197 XSelectInput( _display, _window, _eventMask );
220 XMapWindow( _display, _window );
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;
228 _width = (screenWidth * 4) / 5;
229 _height = screenHeight / 14;
231 XMoveResizeWindow( _display, _window, xCenter - (_width / 2), yCenter - (_height / 2), _width, _height );
239 while( XCheckMaskEvent( _display, _eventMask, &event ) )
245 unsigned length = strlen( _programName ) + strlen( suiteName ) + strlen( testName ) +
sizeof(
" - ::()" );
247 sprintf( name,
"%s - %s::%s()", _programName, suiteName, testName );
248 XSetStandardProperties( _display, _window, name, 0, 0, 0, 0, 0 );
263 XWindowAttributes attributes;
264 XGetWindowAttributes( _display, _window, &attributes );
265 _width = attributes.width;
266 _height = attributes.height;
271 unsigned barWidth = (_width *
_testsDone) / _numTotalTests;
273 XSetForeground( _display, _gc, _barColor );
274 XFillRectangle( _display, _window, _gc, 0, 0, barWidth, _height );
276 XSetForeground( _display, _gc, _background );
277 XFillRectangle( _display, _window, _gc, barWidth, 0, _width + 1 - barWidth, _height );
282 if(_width / _numTotalTests < 5)
285 int x = (_width *
i) / _numTotalTests;
286 XDrawLine( _display, _window, _gc, x, 0, x, _height);
292 XSetForeground( _display, _gc, _foreground );
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 );
298 int textWidth = XTextWidth( _fontInfo, str, len );
300 XDrawString( _display, _window, _gc,
301 (_width - textWidth) / 2, ((_height + _textHeight) / 2) - _textDescent,
312 XFreeGC( _display, _gc );
317 XDestroyWindow( _display, _window );
322 XCloseDisplay( _display );
327 #endif //__cxxtest__X11Gui_h__
void setWindowName(const char *suiteName, const char *testName)
void initializeBar(const WorldDescription &wd)
const char * _foregroundName
void getTotalTests(const WorldDescription &wd)
void guiEnterTest(const char *suiteName, const char *testName)
unsigned long _background
void parseCommandLine(int &argc, char **argv)
char _strTotalTests[WorldDescription::MAX_STRLEN_TOTAL_TESTS]
void enterGui(int &argc, char **argv)
void * malloc(size_t size)
const char * _programName
char name(const Variable &v)
char * strTotalTests(char *) const
void enterWorld(const WorldDescription &wd)
virtual unsigned numTotalTests(void) const =0
unsigned long getColor(const char *colorName)
const char * _backgroundName
unsigned long _foreground