From b6e100b94b12f3f92ec025dc2363eaf7c0ee6662 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 10 Apr 2007 16:02:07 +0000 Subject: Well, we've got the basis of a workable unit test harness thing. There should be a few more add-ons to it, but it works just fine, and eventually it should cover command line options and creating logs, and possibly even provide output functionality so that output from tests can be logged and kept track of well. --- src/unitsuite.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/unitsuite.h (limited to 'src/unitsuite.h') diff --git a/src/unitsuite.h b/src/unitsuite.h new file mode 100644 index 0000000..3502a1b --- /dev/null +++ b/src/unitsuite.h @@ -0,0 +1,60 @@ +#ifndef UNIT_SUITE_H +#define UNIT_SUITE_H + +#include +#include +#include "fstring.h" + +namespace Bu +{ + /** + * + */ + class UnitSuite + { + public: + UnitSuite(); + virtual ~UnitSuite(); + + int run( int argc=0, char *argv[]=NULL ); + + typedef void (UnitSuite::*Test)(); + + class Failed + { + public: + Failed() : str(""), bFile( false ) { } + Failed( const FString &s ) : str( s ), bFile( false ) { } + Failed( const FString &s, const FString &sFile, int nLine ) : + str( s ), sFile( sFile ), nLine( nLine ), bFile( true ) { } + + FString str; + FString sFile; + int nLine; + bool bFile; + }; + + protected: + void add( Test fTest, Bu::FString sName ); + void setName( const FString &sName ); + + private: + typedef struct TestInfo + { + FString sName; + Test fTest; + } TestInfo; + + typedef std::list TestList; + TestList lTests; + FString sSuiteName; + }; +} + +#define addTest( fn ) add( static_cast(&fn), #fn ) +#define unitTest( tst ) if( !(tst) ) \ +{ \ + throw Bu::UnitSuite::Failed( #tst, __FILE__, __LINE__ ); \ +} + +#endif -- cgit v1.2.3