diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/stable/unitsuite.h | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to '')
-rw-r--r-- | src/stable/unitsuite.h | 230 |
1 files changed, 115 insertions, 115 deletions
diff --git a/src/stable/unitsuite.h b/src/stable/unitsuite.h index 3442753..46a0773 100644 --- a/src/stable/unitsuite.h +++ b/src/stable/unitsuite.h | |||
@@ -17,126 +17,126 @@ | |||
17 | 17 | ||
18 | namespace Bu | 18 | namespace Bu |
19 | { | 19 | { |
20 | /** | 20 | /** |
21 | * Provides a unit testing framework. This is pretty easy to use, probably | 21 | * Provides a unit testing framework. This is pretty easy to use, probably |
22 | * the best way to get started is to use ch to generate a template, or use | 22 | * the best way to get started is to use ch to generate a template, or use |
23 | * the code below with appropriate tweaks: | 23 | * the code below with appropriate tweaks: |
24 | *@code | 24 | *@code |
25 | * #include "unitsuite.h" | 25 | * #include "unitsuite.h" |
26 | * | 26 | * |
27 | * class Unit : public Bu::UnitSuite | 27 | * class Unit : public Bu::UnitSuite |
28 | * { | 28 | * { |
29 | * public: | 29 | * public: |
30 | * Unit() | 30 | * Unit() |
31 | * { | 31 | * { |
32 | * setName("Example"); | 32 | * setName("Example"); |
33 | * addTest( Unit::test ); | 33 | * addTest( Unit::test ); |
34 | * } | 34 | * } |
35 | * | 35 | * |
36 | * virtual ~Unit() { } | 36 | * virtual ~Unit() { } |
37 | * | 37 | * |
38 | * // | 38 | * // |
39 | * // Tests go here | 39 | * // Tests go here |
40 | * // | 40 | * // |
41 | * void test() | 41 | * void test() |
42 | * { | 42 | * { |
43 | * unitTest( 1 == 1 ); | 43 | * unitTest( 1 == 1 ); |
44 | * } | 44 | * } |
45 | * }; | 45 | * }; |
46 | * | 46 | * |
47 | * int main( int argc, char *argv[] ) | 47 | * int main( int argc, char *argv[] ) |
48 | * { | 48 | * { |
49 | * return Unit().run( argc, argv ); | 49 | * return Unit().run( argc, argv ); |
50 | * } | 50 | * } |
51 | * | 51 | * |
52 | @endcode | 52 | @endcode |
53 | * The main function can contain other things, but using this one exactly | 53 | * The main function can contain other things, but using this one exactly |
54 | * makes all of the test suites work exactly the same. Using the optional | 54 | * makes all of the test suites work exactly the same. Using the optional |
55 | * setName at the top of the constructor replaces the class name with the | 55 | * setName at the top of the constructor replaces the class name with the |
56 | * chosen name when printing out stats and info. | 56 | * chosen name when printing out stats and info. |
57 | */ | 57 | */ |
58 | class UnitSuite | 58 | class UnitSuite |
59 | { | 59 | { |
60 | public: | 60 | public: |
61 | UnitSuite(); | 61 | UnitSuite(); |
62 | UnitSuite( int iOptions ); | 62 | UnitSuite( int iOptions ); |
63 | virtual ~UnitSuite(); | 63 | virtual ~UnitSuite(); |
64 | 64 | ||
65 | int run( int argc=0, char *argv[]=NULL ); | 65 | int run( int argc=0, char *argv[]=NULL ); |
66 | 66 | ||
67 | Bu::File tempFile( Bu::String &sFileName ); | 67 | Bu::File tempFile( Bu::String &sFileName ); |
68 | 68 | ||
69 | typedef void (UnitSuite::*Test)(); | 69 | typedef void (UnitSuite::*Test)(); |
70 | 70 | ||
71 | class Failed | 71 | class Failed |
72 | { | 72 | { |
73 | public: | 73 | public: |
74 | Failed() : str(""), bFile( false ) { } | 74 | Failed() : str(""), bFile( false ) { } |
75 | Failed( const String &s ) : str( s ), bFile( false ) { } | 75 | Failed( const String &s ) : str( s ), bFile( false ) { } |
76 | Failed( const String &s, const String &sFile, int nLine ) : | 76 | Failed( const String &s, const String &sFile, int nLine ) : |
77 | str( s ), sFile( sFile ), nLine( nLine ), bFile( true ) { } | 77 | str( s ), sFile( sFile ), nLine( nLine ), bFile( true ) { } |
78 | 78 | ||
79 | String str; | 79 | String str; |
80 | String sFile; | 80 | String sFile; |
81 | int nLine; | 81 | int nLine; |
82 | bool bFile; | 82 | bool bFile; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | enum | 85 | enum |
86 | { | 86 | { |
87 | optStopOnError = 0x000001 | 87 | optStopOnError = 0x000001 |
88 | }; | 88 | }; |
89 | 89 | ||
90 | enum Expect | 90 | enum Expect |
91 | { | 91 | { |
92 | expectPass, | 92 | expectPass, |
93 | expectFail | 93 | expectFail |
94 | }; | 94 | }; |
95 | 95 | ||
96 | protected: | 96 | protected: |
97 | void add( Test fTest, const Bu::String &sName, Expect e=expectPass ); | 97 | void add( Test fTest, const Bu::String &sName, Expect e=expectPass ); |
98 | void setName( const String &sName ); | 98 | void setName( const String &sName ); |
99 | 99 | ||
100 | void dispProgress(); | 100 | void dispProgress(); |
101 | void setStepCount( int iSteps ); | 101 | void setStepCount( int iSteps ); |
102 | void incProgress( int iAmnt = 1 ); | 102 | void incProgress( int iAmnt = 1 ); |
103 | void setProgress( int iAmnt ); | 103 | void setProgress( int iAmnt ); |
104 | 104 | ||
105 | private: | 105 | private: |
106 | int onListCases( Bu::Array<Bu::String> aParam ); | 106 | int onListCases( Bu::Array<Bu::String> aParam ); |
107 | int onAddTest( Bu::Array<Bu::String> aParam ); | 107 | int onAddTest( Bu::Array<Bu::String> aParam ); |
108 | 108 | ||
109 | private: | 109 | private: |
110 | typedef struct TestInfo | 110 | typedef struct TestInfo |
111 | { | 111 | { |
112 | String sName; | 112 | String sName; |
113 | Test fTest; | 113 | Test fTest; |
114 | Expect eExpect; | 114 | Expect eExpect; |
115 | } TestInfo; | 115 | } TestInfo; |
116 | 116 | ||
117 | typedef Bu::List<TestInfo> TestList; | 117 | typedef Bu::List<TestInfo> TestList; |
118 | TestList lTests; | 118 | TestList lTests; |
119 | String sSuiteName; | 119 | String sSuiteName; |
120 | 120 | ||
121 | int iOptions; | 121 | int iOptions; |
122 | 122 | ||
123 | typedef Bu::List<Bu::String> StrList; | 123 | typedef Bu::List<Bu::String> StrList; |
124 | StrList lFileCleanup; | 124 | StrList lFileCleanup; |
125 | int iNameWidth; | 125 | int iNameWidth; |
126 | int iStepCount; | 126 | int iStepCount; |
127 | int iProgress; | 127 | int iProgress; |
128 | time_t tLastUpdate; | 128 | time_t tLastUpdate; |
129 | 129 | ||
130 | Bu::Hash<Bu::String, bool> hSelTests; | 130 | Bu::Hash<Bu::String, bool> hSelTests; |
131 | }; | 131 | }; |
132 | 132 | ||
133 | Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::UnitSuite::Expect &e ); | 133 | Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::UnitSuite::Expect &e ); |
134 | } | 134 | } |
135 | 135 | ||
136 | #define addTest( fn ) add( static_cast<Bu::UnitSuite::Test>(&fn), #fn ) | 136 | #define addTest( fn ) add( static_cast<Bu::UnitSuite::Test>(&fn), #fn ) |
137 | #define unitTest( tst ) if( !(tst) ) \ | 137 | #define unitTest( tst ) if( !(tst) ) \ |
138 | { \ | 138 | { \ |
139 | throw Bu::UnitSuite::Failed( #tst, __FILE__, __LINE__ ); \ | 139 | throw Bu::UnitSuite::Failed( #tst, __FILE__, __LINE__ ); \ |
140 | } else (void)0 | 140 | } else (void)0 |
141 | #define unitFailed( msg ) throw Bu::UnitSuite::Failed(msg, __FILE__, __LINE__) | 141 | #define unitFailed( msg ) throw Bu::UnitSuite::Failed(msg, __FILE__, __LINE__) |
142 | 142 | ||