Loading...
Searching...
No Matches
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 | guiEnterWorld (unsigned)
virtual void | guiEnterSuite (const char *)
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 | trace (const char *, unsigned, const char *)

## 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 | ( |  | ) |

inline private

Definition at line 218 of file X11Gui.h.

{
XMapWindow( _display, _window );
Screen *screen = XDefaultScreenOfDisplay( _display );
int screenWidth = WidthOfScreen( screen );
int screenHeight = HeightOfScreen( screen );
int xCenter = screenWidth / 2;
int yCenter = screenHeight / 2;
_width = (screenWidth * 4) / 5;
_height = screenHeight / 14;
XMoveResizeWindow( _display, _window, xCenter - (_width / 2), yCenter - (_height / 2), _width, _height );
}
CxxTest::X11Gui::_height
int _height
Definition X11Gui.h:94
CxxTest::X11Gui::_width
int _width
Definition X11Gui.h:94
CxxTest::X11Gui::_display
Display * _display
Definition X11Gui.h:87
CxxTest::X11Gui::_window
Window _window
Definition X11Gui.h:88

## closeDisplay()

void CxxTest::X11Gui::closeDisplay | ( |  | ) |

inline private

Definition at line 320 of file X11Gui.h.

{
XCloseDisplay( _display );
}

## createColors()

void CxxTest::X11Gui::createColors | ( |  | ) |

inline private

Definition at line 137 of file X11Gui.h.

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

## createFont()

void CxxTest::X11Gui::createFont | ( |  | ) |

inline private

Definition at line 162 of file X11Gui.h.

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

## createGc()

void CxxTest::X11Gui::createGc | ( |  | ) |

inline private

Definition at line 157 of file X11Gui.h.

{
_gc = XCreateGC( _display, _window, 0, 0 );
}
CxxTest::X11Gui::_gc
GC _gc
Definition X11Gui.h:95

## createWindow()

void CxxTest::X11Gui::createWindow | ( |  | ) |

inline private

Definition at line 152 of file X11Gui.h.

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

## destroyGc()

void CxxTest::X11Gui::destroyGc | ( |  | ) |

inline private

Definition at line 310 of file X11Gui.h.

{
XFreeGC( _display, _gc );
}

## destroyWindow()

void CxxTest::X11Gui::destroyWindow | ( |  | ) |

inline private

Definition at line 315 of file X11Gui.h.

{
XDestroyWindow( _display, _window );
}

## drawDividers()

void CxxTest::X11Gui::drawDividers | ( |  | ) |

inline private

Definition at line 280 of file X11Gui.h.

{
if(_width / _numTotalTests < 5)
return;
for ( unsigned i = 1; i < _testsDone; ++ i ) {
int x = (_width * i) / _numTotalTests;
XDrawLine( _display, _window, _gc, x, 0, x, _height);
}
}
i
int i
Definition cfEzgcd.cc:132
x
Variable x
Definition cfModGcd.cc:4090
CxxTest::X11Gui::_testsDone
unsigned _testsDone
Definition X11Gui.h:89
CxxTest::X11Gui::_numTotalTests
unsigned _numTotalTests
Definition X11Gui.h:89

## drawPercentage()

void CxxTest::X11Gui::drawPercentage | ( |  | ) |

inline private

Definition at line 290 of file X11Gui.h.

{
XSetForeground( _display, _gc, _foreground );
char str[sizeof("1000000000 of ") + sizeof(_strTotalTests) + sizeof(" (100%)")];
sprintf( str, "%u of %s (%u%%)", _testsDone, _strTotalTests, (_testsDone * 100) / _numTotalTests );
unsigned len = strlen( str );
int textWidth = XTextWidth( _fontInfo, str, len );
XDrawString( _display, _window, _gc,
(_width - textWidth) / 2, ((_height + _textHeight) / 2) - _textDescent,
str, len );
}
CxxTest::X11Gui::_strTotalTests
char _strTotalTests[WorldDescription::MAX_STRLEN_TOTAL_TESTS]
Definition X11Gui.h:90
LibThread::str
char * str(leftv arg)
Definition shared.cc:699

## drawSolidBar()

void CxxTest::X11Gui::drawSolidBar | ( |  | ) |

inline private

Definition at line 269 of file X11Gui.h.

{
unsigned barWidth = (_width * _testsDone) / _numTotalTests;
XSetForeground( _display, _gc, _barColor );
XFillRectangle( _display, _window, _gc, 0, 0, barWidth, _height );
XSetForeground( _display, _gc, _background );
XFillRectangle( _display, _window, _gc, barWidth, 0, _width + 1 - barWidth, _height );
}
CxxTest::X11Gui::_barColor
unsigned long _barColor
Definition X11Gui.h:93

## enterGui()

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

inline virtual

Reimplemented from CxxTest::GuiListener.

Definition at line 28 of file X11Gui.h.

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

## enterWorld()

void CxxTest::X11Gui::enterWorld | ( | const WorldDescription & | wd | ) |

inline virtual

Reimplemented from CxxTest::GuiListener.

Definition at line 33 of file X11Gui.h.

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

## flush()

void CxxTest::X11Gui::flush | ( |  | ) |

inline private

Definition at line 305 of file X11Gui.h.

{
XFlush( _display );
}

## freeFontInfo()

void CxxTest::X11Gui::freeFontInfo | ( |  | ) |

inline private

Definition at line 189 of file X11Gui.h.

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

## getColor()

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

inline private

Definition at line 144 of file X11Gui.h.

{
XColor color;
XParseColor( _display, _colormap, colorName, &color );
XAllocColor( _display, _colormap, &color );
return color.pixel;
}

## getFontInfo()

void CxxTest::X11Gui::getFontInfo | ( |  | ) |

inline private

Definition at line 184 of file X11Gui.h.

{
_fontInfo = XQueryFont( _display, _fontId );
}
CxxTest::X11Gui::_fontId
XID _fontId
Definition X11Gui.h:97

## getTotalTests() [1/2]

void CxxTest::X11Gui::getTotalTests | ( |  | ) |

inline private

Definition at line 207 of file X11Gui.h.

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

## getTotalTests() [2/2]

void CxxTest::X11Gui::getTotalTests | ( | const WorldDescription & | wd | ) |

inline private

Definition at line 212 of file X11Gui.h.

{
_numTotalTests = wd.numTotalTests();
wd.strTotalTests( _strTotalTests );
}

## getWindowSize()

void CxxTest::X11Gui::getWindowSize | ( |  | ) |

inline private

Definition at line 261 of file X11Gui.h.

{
XWindowAttributes attributes;
XGetWindowAttributes( _display, _window, &attributes );
_width = attributes.width;
_height = attributes.height;
}

## guiEnterTest()

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

inline virtual

Reimplemented from CxxTest::GuiListener.

Definition at line 48 of file X11Gui.h.

{
if ( _display ) {
++ _testsDone;
setWindowName( suiteName, testName );
redraw();
}
}
CxxTest::X11Gui::redraw
void redraw()
Definition X11Gui.h:252
CxxTest::X11Gui::setWindowName
void setWindowName(const char *suiteName, const char *testName)
Definition X11Gui.h:243

## initializeBar()

void CxxTest::X11Gui::initializeBar | ( | const WorldDescription & | wd | ) |

inline private

Definition at line 200 of file X11Gui.h.

{
getTotalTests( wd );
_testsDone = 0;
_barColor = getColor( _greenName );
}
CxxTest::X11Gui::_greenName
const char * _greenName
Definition X11Gui.h:92

## initializeEvents()

void CxxTest::X11Gui::initializeEvents | ( |  | ) |

inline private

Definition at line 194 of file X11Gui.h.

{
_eventMask = ExposureMask;
XSelectInput( _display, _window, _eventMask );
}
CxxTest::X11Gui::_eventMask
long _eventMask
Definition X11Gui.h:100

## leaveGui()

void CxxTest::X11Gui::leaveGui | ( |  | ) |

inline virtual

Reimplemented from CxxTest::GuiListener.

Definition at line 75 of file X11Gui.h.

{
if ( _display ) {
freeFontInfo();
destroyGc();
destroyWindow();
closeDisplay();
}
}
CxxTest::X11Gui::closeDisplay
void closeDisplay()
Definition X11Gui.h:320
CxxTest::X11Gui::destroyGc
void destroyGc()
Definition X11Gui.h:310
CxxTest::X11Gui::freeFontInfo
void freeFontInfo()
Definition X11Gui.h:189
CxxTest::X11Gui::destroyWindow
void destroyWindow()
Definition X11Gui.h:315

## loadFont()

bool CxxTest::X11Gui::loadFont | ( |  | ) |

inline private

Definition at line 171 of file X11Gui.h.

{
if ( !_fontName )
return false;
_fontId = XLoadFont( _display, _fontName );
return (XSetFont( _display, _gc, _fontId ) == Success);
}
CxxTest::X11Gui::_fontName
const char * _fontName
Definition X11Gui.h:96

## openDisplay()

void CxxTest::X11Gui::openDisplay | ( |  | ) |

inline private

Definition at line 132 of file X11Gui.h.

{
_display = XOpenDisplay( NULL );
}

## parseCommandLine()

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

inline private

Definition at line 103 of file X11Gui.h.

{
_programName = argv[0];
_fontName = 0;
_foregroundName = "Black";
_backgroundName = "Grey";
_greenName = "Green";
_yellowName = "Yellow";
_redName = "Red";
for ( int i = 1; i + 1 < argc; ++ i ) {
if ( !strcmp( argv[i], "-title" ) )
_programName = argv[++ i];
else if ( !strcmp( argv[i], "-fn" ) || !strcmp( argv[i], "-font" ) )
_fontName = argv[++ i];
else if ( !strcmp( argv[i], "-fg" ) || !strcmp( argv[i], "-foreground" ) )
_foregroundName = argv[++ i];
else if ( !strcmp( argv[i], "-bg" ) || !strcmp( argv[i], "-background" ) )
_backgroundName = argv[++ i];
else if ( !strcmp( argv[i], "-green" ) )
_greenName = argv[++ i];
else if ( !strcmp( argv[i], "-yellow" ) )
_yellowName = argv[++ i];
else if ( !strcmp( argv[i], "-red" ) )
_redName = argv[++ i];
}
}
CxxTest::X11Gui::_yellowName
const char * _yellowName
Definition X11Gui.h:92
CxxTest::X11Gui::_programName
const char * _programName
Definition X11Gui.h:86
CxxTest::X11Gui::_redName
const char * _redName
Definition X11Gui.h:92

## processEvents()

void CxxTest::X11Gui::processEvents | ( |  | ) |

inline private

Definition at line 234 of file X11Gui.h.

{
redraw();
XEvent event;
while( XCheckMaskEvent( _display, _eventMask, &event ) )
redraw();
}

## redBar()

void CxxTest::X11Gui::redBar | ( |  | ) |

inline virtual

Reimplemented from CxxTest::GuiListener.

Definition at line 66 of file X11Gui.h.

{
if ( _display ) {
_barColor = getColor( _redName );
getTotalTests();
processEvents();
}
}

## redraw()

void CxxTest::X11Gui::redraw | ( |  | ) |

inline private

Definition at line 252 of file X11Gui.h.

{
getWindowSize();
drawSolidBar();
drawDividers();
drawPercentage();
flush();
}
CxxTest::X11Gui::drawPercentage
void drawPercentage()
Definition X11Gui.h:290
CxxTest::X11Gui::drawSolidBar
void drawSolidBar()
Definition X11Gui.h:269
CxxTest::X11Gui::flush
void flush()
Definition X11Gui.h:305
CxxTest::X11Gui::drawDividers
void drawDividers()
Definition X11Gui.h:280
CxxTest::X11Gui::getWindowSize
void getWindowSize()
Definition X11Gui.h:261

## setWindowName()

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

inline private

Definition at line 243 of file X11Gui.h.

{
unsigned length = strlen( _programName ) + strlen( suiteName ) + strlen( testName ) + sizeof( " - ::()" );
char *name = (char *)malloc( length );
sprintf( name, "%s - %s::%s()", _programName, suiteName, testName );
XSetStandardProperties( _display, _window, name, 0, 0, 0, 0, 0 );
free( name );
}
name
char name(const Variable &v)
Definition factory.h:189
length
static BOOLEAN length(leftv result, leftv arg)
Definition interval.cc:257
free
#define free
Definition omAllocFunc.c:14
malloc
#define malloc
Definition omAllocFunc.c:12

## useDefaultFont()

void CxxTest::X11Gui::useDefaultFont | ( |  | ) |

inline private

Definition at line 179 of file X11Gui.h.

{
_fontId = XGContextFromGC( _gc );
}

## yellowBar()

void CxxTest::X11Gui::yellowBar | ( |  | ) |

inline virtual

Reimplemented from CxxTest::GuiListener.

Definition at line 57 of file X11Gui.h.

{
if ( _display ) {
_barColor = getColor( _yellowName );
getTotalTests();
processEvents();
}
}

## 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:

- libpolys/tests/cxxtest/X11Gui.h