diff options
Diffstat (limited to 'src/unitsuite.h')
-rw-r--r-- | src/unitsuite.h | 60 |
1 files changed, 60 insertions, 0 deletions
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 @@ | |||
1 | #ifndef UNIT_SUITE_H | ||
2 | #define UNIT_SUITE_H | ||
3 | |||
4 | #include <stdint.h> | ||
5 | #include <list> | ||
6 | #include "fstring.h" | ||
7 | |||
8 | namespace Bu | ||
9 | { | ||
10 | /** | ||
11 | * | ||
12 | */ | ||
13 | class UnitSuite | ||
14 | { | ||
15 | public: | ||
16 | UnitSuite(); | ||
17 | virtual ~UnitSuite(); | ||
18 | |||
19 | int run( int argc=0, char *argv[]=NULL ); | ||
20 | |||
21 | typedef void (UnitSuite::*Test)(); | ||
22 | |||
23 | class Failed | ||
24 | { | ||
25 | public: | ||
26 | Failed() : str(""), bFile( false ) { } | ||
27 | Failed( const FString &s ) : str( s ), bFile( false ) { } | ||
28 | Failed( const FString &s, const FString &sFile, int nLine ) : | ||
29 | str( s ), sFile( sFile ), nLine( nLine ), bFile( true ) { } | ||
30 | |||
31 | FString str; | ||
32 | FString sFile; | ||
33 | int nLine; | ||
34 | bool bFile; | ||
35 | }; | ||
36 | |||
37 | protected: | ||
38 | void add( Test fTest, Bu::FString sName ); | ||
39 | void setName( const FString &sName ); | ||
40 | |||
41 | private: | ||
42 | typedef struct TestInfo | ||
43 | { | ||
44 | FString sName; | ||
45 | Test fTest; | ||
46 | } TestInfo; | ||
47 | |||
48 | typedef std::list<TestInfo> TestList; | ||
49 | TestList lTests; | ||
50 | FString sSuiteName; | ||
51 | }; | ||
52 | } | ||
53 | |||
54 | #define addTest( fn ) add( static_cast<Bu::UnitSuite::Test>(&fn), #fn ) | ||
55 | #define unitTest( tst ) if( !(tst) ) \ | ||
56 | { \ | ||
57 | throw Bu::UnitSuite::Failed( #tst, __FILE__, __LINE__ ); \ | ||
58 | } | ||
59 | |||
60 | #endif | ||