1
#ifndef __EXCEPTIONTEST_H
2
#define __EXCEPTIONTEST_H
4
#include <cxxtest/TestSuite.h>
7
// This test suite demonstrates the use of TS_ASSERT_THROWS
10
class ExceptionTest : public CxxTest::TestSuite
13
void testAssertion( void )
15
// This assert passes, since throwThis() throws (Number)
16
TS_ASSERT_THROWS( throwThis(3), const Number & );
17
// This assert passes, since throwThis() throws something
18
TS_ASSERT_THROWS_ANYTHING( throwThis(-30) );
19
// This assert fails, since throwThis() doesn't throw char *
20
TS_ASSERT_THROWS( throwThis(5), const char * );
21
// This assert fails since goodFunction() throws nothing
22
TS_ASSERT_THROWS_ANYTHING( goodFunction(1) );
23
// The regular TS_ASSERT macros will catch unhandled exceptions
24
TS_ASSERT_EQUALS( throwThis(3), 333 );
25
// You can assert that a function throws nothing
26
TS_ASSERT_THROWS_NOTHING( throwThis(-1) );
27
// If you want to catch the exceptions yourself, use the ETS_ marcos
29
ETS_ASSERT_EQUALS( throwThis(3), 333 );
30
} catch( const Number & ) {
31
TS_FAIL( "throwThis(3) failed" );
36
void goodFunction( int )
46
int throwThis( int i )
52
#endif // __EXCEPTIONTEST_H