diff options
| author | Max Horn | 2006-03-29 10:25:48 +0000 |
|---|---|---|
| committer | Max Horn | 2006-03-29 10:25:48 +0000 |
| commit | 3820593bb8dfdca4e2e17c70b278065b7f7894d9 (patch) | |
| tree | df3e8bebda3abcd99d0882dc9e8c6410f86850fb /test/cxxtest/sample/ExceptionTest.h | |
| parent | 9c94670e22cb68e32fd38c0d2b009539e35d4a71 (diff) | |
| download | scummvm-rg350-3820593bb8dfdca4e2e17c70b278065b7f7894d9.tar.gz scummvm-rg350-3820593bb8dfdca4e2e17c70b278065b7f7894d9.tar.bz2 scummvm-rg350-3820593bb8dfdca4e2e17c70b278065b7f7894d9.zip | |
bringing cxxtest-3.10.1 to ScummVM's main branch
svn-id: r21488
Diffstat (limited to 'test/cxxtest/sample/ExceptionTest.h')
| -rw-r--r-- | test/cxxtest/sample/ExceptionTest.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/cxxtest/sample/ExceptionTest.h b/test/cxxtest/sample/ExceptionTest.h new file mode 100644 index 0000000000..68363c8740 --- /dev/null +++ b/test/cxxtest/sample/ExceptionTest.h @@ -0,0 +1,52 @@ +#ifndef __EXCEPTIONTEST_H +#define __EXCEPTIONTEST_H + +#include <cxxtest/TestSuite.h> + +// +// This test suite demonstrates the use of TS_ASSERT_THROWS +// + +class ExceptionTest : public CxxTest::TestSuite +{ +public: + void testAssertion( void ) + { + // This assert passes, since throwThis() throws (Number) + TS_ASSERT_THROWS( throwThis(3), const Number & ); + // This assert passes, since throwThis() throws something + TS_ASSERT_THROWS_ANYTHING( throwThis(-30) ); + // This assert fails, since throwThis() doesn't throw char * + TS_ASSERT_THROWS( throwThis(5), const char * ); + // This assert fails since goodFunction() throws nothing + TS_ASSERT_THROWS_ANYTHING( goodFunction(1) ); + // The regular TS_ASSERT macros will catch unhandled exceptions + TS_ASSERT_EQUALS( throwThis(3), 333 ); + // You can assert that a function throws nothing + TS_ASSERT_THROWS_NOTHING( throwThis(-1) ); + // If you want to catch the exceptions yourself, use the ETS_ marcos + try { + ETS_ASSERT_EQUALS( throwThis(3), 333 ); + } catch( const Number & ) { + TS_FAIL( "throwThis(3) failed" ); + } + } + +private: + void goodFunction( int ) + { + } + + class Number + { + public: + Number( int ) {} + }; + + int throwThis( int i ) + { + throw Number( i ); + } +}; + +#endif // __EXCEPTIONTEST_H |
