Loading...
Searching...
No Matches
Gui.h
Go to the documentation of this file.
#ifndef __CXXTEST__GUI_H
#define __CXXTEST__GUI_H
//
// GuiListener is a simple base class for the different GUIs
// GuiTuiRunner<GuiT, TuiT> combines a GUI with a text-mode error formatter
//
#include <cxxtest/TeeListener.h>
namespace CxxTest
{
class GuiListener : public TestListener
{
public:
GuiListener() : _state( GREEN_BAR ) {}
virtual ~GuiListener() {}
virtual void runGui( int &argc, char **argv, TestListener &listener )
{
enterGui( argc, argv );
TestRunner::runAllTests( listener );
leaveGui();
}
virtual void enterGui( int & /*argc*/, char ** /*argv*/ ) {}
virtual void leaveGui() {}
//
// The easy way is to implement these functions:
//
virtual void guiEnterWorld( unsigned /*numTotalTests*/ ) {}
virtual void guiEnterSuite( const char * /*suiteName*/ ) {}
virtual void guiEnterTest( const char * /*suiteName*/, const char * /*testName*/ ) {}
virtual void yellowBar() {}
virtual void redBar() {}
//
// The hard way is this:
//
void enterWorld( const WorldDescription &d ) { guiEnterWorld( d.numTotalTests() ); }
void enterSuite( const SuiteDescription &d ) { guiEnterSuite( d.suiteName() ); }
void enterTest( const TestDescription &d ) { guiEnterTest( d.suiteName(), d.testName() ); }
void leaveTest( const TestDescription & ) {}
void leaveSuite( const SuiteDescription & ) {}
void leaveWorld( const WorldDescription & ) {}
void warning( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ )
{
yellowBarSafe();
}
void failedTest( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ )
{
redBarSafe();
}
void failedAssert( const char * /*file*/, unsigned /*line*/, const char * /*expression*/ )
{
redBarSafe();
}
void failedAssertEquals( const char * /*file*/, unsigned /*line*/,
const char * /*xStr*/, const char * /*yStr*/,
const char * /*x*/, const char * /*y*/ )
{
redBarSafe();
}
void failedAssertSameData( const char * /*file*/, unsigned /*line*/,
const char * /*xStr*/, const char * /*yStr*/,
const char * /*sizeStr*/, const void * /*x*/,
const void * /*y*/, unsigned /*size*/ )
{
redBarSafe();
}
void failedAssertDelta( const char * /*file*/, unsigned /*line*/,
const char * /*xStr*/, const char * /*yStr*/, const char * /*dStr*/,
const char * /*x*/, const char * /*y*/, const char * /*d*/ )
{
redBarSafe();
}
void failedAssertDiffers( const char * /*file*/, unsigned /*line*/,
const char * /*xStr*/, const char * /*yStr*/,
const char * /*value*/ )
{
redBarSafe();
}
void failedAssertLessThan( const char * /*file*/, unsigned /*line*/,
const char * /*xStr*/, const char * /*yStr*/,
const char * /*x*/, const char * /*y*/ )
{
redBarSafe();
}
void failedAssertLessThanEquals( const char * /*file*/, unsigned /*line*/,
const char * /*xStr*/, const char * /*yStr*/,
const char * /*x*/, const char * /*y*/ )
{
redBarSafe();
}
void failedAssertPredicate( const char * /*file*/, unsigned /*line*/,
const char * /*predicate*/, const char * /*xStr*/, const char * /*x*/ )
{
redBarSafe();
}
void failedAssertRelation( const char * /*file*/, unsigned /*line*/,
const char * /*relation*/, const char * /*xStr*/, const char * /*yStr*/,
const char * /*x*/, const char * /*y*/ )
{
redBarSafe();
}
void failedAssertThrows( const char * /*file*/, unsigned /*line*/,
const char * /*expression*/, const char * /*type*/,
bool /*otherThrown*/ )
{
redBarSafe();
}
void failedAssertThrowsNot( const char * /*file*/, unsigned /*line*/,
const char * /*expression*/ )
{
redBarSafe();
}
protected:
void yellowBarSafe()
{
if ( _state < YELLOW_BAR ) {
yellowBar();
_state = YELLOW_BAR;
}
}
void redBarSafe()
{
if ( _state < RED_BAR ) {
redBar();
_state = RED_BAR;
}
}
private:
enum { GREEN_BAR, YELLOW_BAR, RED_BAR } _state;
};
template<class GuiT, class TuiT>
class GuiTuiRunner : public TeeListener
{
int &_argc;
char **_argv;
GuiT _gui;
TuiT _tui;
public:
GuiTuiRunner( int &argc, char **argv ) :
_argc( argc ),
_argv( argv )
{
setFirst( _gui );
setSecond( _tui );
}
int run()
{
_gui.runGui( _argc, _argv, *this );
return tracker().failedTests();
}
};
};
#endif //__CXXTEST__GUI_H
TeeListener.h
CxxTest::GuiListener::GuiListener
GuiListener()
Definition Gui.h:16
CxxTest::GuiListener::failedAssert
void failedAssert(const char *, unsigned, const char *)
Definition Gui.h:58
CxxTest::GuiListener::failedAssertEquals
void failedAssertEquals(const char *, unsigned, const char *, const char *, const char *, const char *)
Definition Gui.h:63
CxxTest::GuiListener::failedAssertLessThanEquals
void failedAssertLessThanEquals(const char *, unsigned, const char *, const char *, const char *, const char *)
Definition Gui.h:99
CxxTest::GuiListener::failedAssertPredicate
void failedAssertPredicate(const char *, unsigned, const char *, const char *, const char *)
Definition Gui.h:106
CxxTest::GuiListener::redBarSafe
void redBarSafe()
Definition Gui.h:141
CxxTest::GuiListener::leaveWorld
void leaveWorld(const WorldDescription &)
Definition Gui.h:46
CxxTest::GuiListener::GREEN_BAR
@ GREEN_BAR
Definition Gui.h:150
CxxTest::GuiListener::YELLOW_BAR
@ YELLOW_BAR
Definition Gui.h:150
CxxTest::GuiListener::RED_BAR
@ RED_BAR
Definition Gui.h:150
CxxTest::GuiListener::failedTest
void failedTest(const char *, unsigned, const char *)
Definition Gui.h:53
CxxTest::GuiListener::guiEnterTest
virtual void guiEnterTest(const char *, const char *)
Definition Gui.h:34
CxxTest::GuiListener::yellowBar
virtual void yellowBar()
Definition Gui.h:35
CxxTest::GuiListener::enterSuite
void enterSuite(const SuiteDescription &d)
Definition Gui.h:42
CxxTest::GuiListener::leaveTest
void leaveTest(const TestDescription &)
Definition Gui.h:44
CxxTest::GuiListener::failedAssertLessThan
void failedAssertLessThan(const char *, unsigned, const char *, const char *, const char *, const char *)
Definition Gui.h:92
CxxTest::GuiListener::enterTest
void enterTest(const TestDescription &d)
Definition Gui.h:43
CxxTest::GuiListener::runGui
virtual void runGui(int &argc, char **argv, TestListener &listener)
Definition Gui.h:19
CxxTest::GuiListener::~GuiListener
virtual ~GuiListener()
Definition Gui.h:17
CxxTest::GuiListener::yellowBarSafe
void yellowBarSafe()
Definition Gui.h:133
CxxTest::GuiListener::enterGui
virtual void enterGui(int &, char **)
Definition Gui.h:26
CxxTest::GuiListener::_state
enum CxxTest::GuiListener::@301211057212335126110310004170100216260215321263 _state
CxxTest::GuiListener::failedAssertThrowsNot
void failedAssertThrowsNot(const char *, unsigned, const char *)
Definition Gui.h:126
CxxTest::GuiListener::guiEnterSuite
virtual void guiEnterSuite(const char *)
Definition Gui.h:33
CxxTest::GuiListener::failedAssertDelta
void failedAssertDelta(const char *, unsigned, const char *, const char *, const char *, const char *, const char *, const char *)
Definition Gui.h:78
CxxTest::GuiListener::warning
void warning(const char *, unsigned, const char *)
Definition Gui.h:48
CxxTest::GuiListener::enterWorld
void enterWorld(const WorldDescription &d)
Definition Gui.h:41
CxxTest::GuiListener::redBar
virtual void redBar()
Definition Gui.h:36
CxxTest::GuiListener::leaveGui
virtual void leaveGui()
Definition Gui.h:27
CxxTest::GuiListener::failedAssertSameData
void failedAssertSameData(const char *, unsigned, const char *, const char *, const char *, const void *, const void *, unsigned)
Definition Gui.h:70
CxxTest::GuiListener::failedAssertThrows
void failedAssertThrows(const char *, unsigned, const char *, const char *, bool)
Definition Gui.h:119
CxxTest::GuiListener::failedAssertRelation
void failedAssertRelation(const char *, unsigned, const char *, const char *, const char *, const char *, const char *)
Definition Gui.h:112
CxxTest::GuiListener::leaveSuite
void leaveSuite(const SuiteDescription &)
Definition Gui.h:45
CxxTest::GuiListener::guiEnterWorld
virtual void guiEnterWorld(unsigned)
Definition Gui.h:32
CxxTest::GuiListener::failedAssertDiffers
void failedAssertDiffers(const char *, unsigned, const char *, const char *, const char *)
Definition Gui.h:85
CxxTest::GuiTuiRunner::run
int run()
Definition Gui.h:170
CxxTest::GuiTuiRunner::_tui
TuiT _tui
Definition Gui.h:159
CxxTest::GuiTuiRunner::_argc
int & _argc
Definition Gui.h:156
CxxTest::GuiTuiRunner::_gui
GuiT _gui
Definition Gui.h:158
CxxTest::GuiTuiRunner::GuiTuiRunner
GuiTuiRunner(int &argc, char **argv)
Definition Gui.h:162
CxxTest::GuiTuiRunner::_argv
char ** _argv
Definition Gui.h:157
CxxTest::SuiteDescription
Definition Descriptions.h:32
CxxTest::SuiteDescription::suiteName
virtual const char * suiteName() const =0
CxxTest::TeeListener::TeeListener
TeeListener()
Definition TeeListener.h:16
CxxTest::TeeListener::setFirst
void setFirst(TestListener &first)
Definition TeeListener.h:26
CxxTest::TeeListener::setSecond
void setSecond(TestListener &second)
Definition TeeListener.h:31
CxxTest::TestDescription
Definition Descriptions.h:16
CxxTest::TestDescription::suiteName
virtual const char * suiteName() const =0
CxxTest::TestDescription::testName
virtual const char * testName() const =0
CxxTest::TestListener::TestListener
TestListener()
Definition TestListener.h:20
CxxTest::TestRunner::runAllTests
static void runAllTests(TestListener &listener)
Definition TestRunner.h:20
CxxTest::TestTracker::failedTests
unsigned failedTests() const
Definition TestTracker.h:37
CxxTest::WorldDescription
Definition Descriptions.h:54
CxxTest::WorldDescription::numTotalTests
virtual unsigned numTotalTests(void) const =0
CxxTest
Definition Descriptions.cpp:7
CxxTest::tracker
TestTracker & tracker()
Definition TestTracker.h:111