From 9e5ff0f6a865524e5784450f26a1c74807dc0c80 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Tue, 2 Oct 2001 05:49:27 +0000 Subject: 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 ). --- examples/cppunittest/HelperMacrosTest.cpp | 91 ++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) (limited to 'examples/cppunittest/HelperMacrosTest.cpp') 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 #include +#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 ); @@ -58,6 +109,42 @@ HelperMacrosTest::testSubclassing() } +void +HelperMacrosTest::testFail() +{ + std::auto_ptr suite( FailTestCase::suite() ); + suite->run( m_result ); + checkTestResult( 0,0,1 ); +} + + +void +HelperMacrosTest::testFailToFail() +{ + std::auto_ptr suite( FailToFailTestCase::suite() ); + suite->run( m_result ); + checkTestResult( 1,0,1 ); +} + + +void +HelperMacrosTest::testException() +{ + std::auto_ptr suite( ExceptionTestCase::suite() ); + suite->run( m_result ); + checkTestResult( 0,0,1 ); +} + + +void +HelperMacrosTest::testExceptionNotCaught() +{ + std::auto_ptr suite( ExceptionNotCaughtTestCase::suite() ); + suite->run( m_result ); + checkTestResult( 1,0,1 ); +} + + void HelperMacrosTest::checkTestResult( int expectedFailures, int expectedErrors, -- cgit v1.2.1