blob: 3502a1bbe4730e154f5bdda1da9663a2908e96e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#ifndef UNIT_SUITE_H
#define UNIT_SUITE_H
#include <stdint.h>
#include <list>
#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<TestInfo> TestList;
TestList lTests;
FString sSuiteName;
};
}
#define addTest( fn ) add( static_cast<Bu::UnitSuite::Test>(&fn), #fn )
#define unitTest( tst ) if( !(tst) ) \
{ \
throw Bu::UnitSuite::Failed( #tst, __FILE__, __LINE__ ); \
}
#endif
|