summaryrefslogtreecommitdiff
path: root/examples/cppunittest/HelperMacrosTest.cpp
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2001-10-02 05:49:27 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2001-10-02 05:49:27 +0000
commit9e5ff0f6a865524e5784450f26a1c74807dc0c80 (patch)
tree06537ff76603a0915252e3678fd922b2f00ecde4 /examples/cppunittest/HelperMacrosTest.cpp
parent0fe7e4fb21a7f2b096965dab4ad2ee19cc20522f (diff)
downloadcppunit-9e5ff0f6a865524e5784450f26a1c74807dc0c80.tar.gz
NEWS : updated.
NEWS : updated. * doc/other_documentation.dox : added all the authors to the list of authors. * examples/cppunittest/HelperMacrosTest.*: added unit tests for CPPUNIT_TEST_FAIL & CPPUNIT_TEST_EXCEPTION. * examples/cppunittest/TestAssertTest.*: added unit tests for CPPUNIT_FAIL. Corrected spelling error. Relaxed constraint on message produced by CPPUNIT_ASSERT_MESSAGE. Refactored some tests. * include/cppunit/extensions/HelperMacros.h : added macro CPPUNIT_TEST_EXCEPTION to create a test case for the specified method that must throw an exception of the specified type. * include/cppunit/extensions/TestSuiteBuilder.h : made makeTestName() public. Added addTestCallerForException() to add a test case expecting an exception of the specified type to be caught. * include/cppunit/TestAssert.h : added macro CPPUNIT_FAIL as a shortcut for CPPUNIT_ASSERT_MESSAGE( message, false ).
Diffstat (limited to 'examples/cppunittest/HelperMacrosTest.cpp')
-rw-r--r--examples/cppunittest/HelperMacrosTest.cpp91
1 files changed, 89 insertions, 2 deletions
diff --git a/examples/cppunittest/HelperMacrosTest.cpp b/examples/cppunittest/HelperMacrosTest.cpp
index a7b0ddc..f6720f0 100644
--- a/examples/cppunittest/HelperMacrosTest.cpp
+++ b/examples/cppunittest/HelperMacrosTest.cpp
@@ -1,12 +1,63 @@
-#include "HelperMacrosTest.h"
-#include "SubclassedTestCase.h"
#include <cppunit/TestResult.h>
#include <memory>
+#include "FailureException.h"
+#include "HelperMacrosTest.h"
+#include "SubclassedTestCase.h"
/* Note:
- no unit test for CPPUNIT_TEST_SUITE_REGISTRATION...
*/
+class FailTestCase : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE( FailTestCase );
+ CPPUNIT_TEST_FAIL( testFail );
+ CPPUNIT_TEST_SUITE_END();
+public:
+ void testFail()
+ {
+ CPPUNIT_ASSERT_MESSAGE( "Failure", false );
+ }
+};
+
+
+class FailToFailTestCase : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE( FailToFailTestCase );
+ CPPUNIT_TEST_FAIL( testFailToFail );
+ CPPUNIT_TEST_SUITE_END();
+public:
+ void testFailToFail()
+ {
+ }
+};
+
+
+class ExceptionTestCase : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE( ExceptionTestCase );
+ CPPUNIT_TEST_EXCEPTION( testException, FailureException );
+ CPPUNIT_TEST_SUITE_END();
+public:
+ void testException()
+ {
+ throw FailureException();
+ }
+};
+
+
+class ExceptionNotCaughtTestCase : public CppUnit::TestCase
+{
+ CPPUNIT_TEST_SUITE( ExceptionNotCaughtTestCase );
+ CPPUNIT_TEST_EXCEPTION( testExceptionNotCaught, FailureException );
+ CPPUNIT_TEST_SUITE_END();
+public:
+ void testExceptionNotCaught()
+ {
+ }
+};
+
+
CPPUNIT_TEST_SUITE_REGISTRATION( HelperMacrosTest );
@@ -59,6 +110,42 @@ HelperMacrosTest::testSubclassing()
void
+HelperMacrosTest::testFail()
+{
+ std::auto_ptr<CppUnit::TestSuite> suite( FailTestCase::suite() );
+ suite->run( m_result );
+ checkTestResult( 0,0,1 );
+}
+
+
+void
+HelperMacrosTest::testFailToFail()
+{
+ std::auto_ptr<CppUnit::TestSuite> suite( FailToFailTestCase::suite() );
+ suite->run( m_result );
+ checkTestResult( 1,0,1 );
+}
+
+
+void
+HelperMacrosTest::testException()
+{
+ std::auto_ptr<CppUnit::TestSuite> suite( ExceptionTestCase::suite() );
+ suite->run( m_result );
+ checkTestResult( 0,0,1 );
+}
+
+
+void
+HelperMacrosTest::testExceptionNotCaught()
+{
+ std::auto_ptr<CppUnit::TestSuite> suite( ExceptionNotCaughtTestCase::suite() );
+ suite->run( m_result );
+ checkTestResult( 1,0,1 );
+}
+
+
+void
HelperMacrosTest::checkTestResult( int expectedFailures,
int expectedErrors,
int expectedTestsRun )