summaryrefslogtreecommitdiff
path: root/include/cppunit/extensions
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 /include/cppunit/extensions
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 'include/cppunit/extensions')
-rw-r--r--include/cppunit/extensions/HelperMacros.h37
-rw-r--r--include/cppunit/extensions/TestSuiteBuilder.h15
2 files changed, 51 insertions, 1 deletions
diff --git a/include/cppunit/extensions/HelperMacros.h b/include/cppunit/extensions/HelperMacros.h
index ee3274b..9291fc7 100644
--- a/include/cppunit/extensions/HelperMacros.h
+++ b/include/cppunit/extensions/HelperMacros.h
@@ -164,6 +164,43 @@
(__ThisTestCaseType*)factory->makeTest() )
+/*! Add a test which fail if the specified exception is not caught.
+ *
+ * Example:
+ * \code
+ * #include <cppunit/extensions/HelperMacros.h>
+ * #include <vector>
+ * class MyTest : public CppUnit::TestCase {
+ * CPPUNIT_TEST_SUITE( MyTest );
+ * CPPUNIT_TEST_EXCEPTION( testVectorAtThrow, std::invalid_argument );
+ * CPPUNIT_TEST_SUITE_END();
+ * public:
+ * void testVectorAtThrow()
+ * {
+ * std::vector<int> v;
+ * v.at( 1 ); // must throw exception std::invalid_argument
+ * }
+ * };
+ * \endcode
+ *
+ * \param testMethod Name of the method of the test case to add to the suite.
+ * \param ExceptionType Type of the exception that must be thrown by the test
+ * method.
+ */
+#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
+ builder.addTestCallerForException( #testMethod, \
+ &__ThisTestCaseType::testMethod , \
+ (__ThisTestCaseType*)factory->makeTest(), \
+ (ExceptionType *)NULL );
+
+/*! Add a test which is excepted to fail.
+ *
+ * To use when writing test case for testing utility class.
+ *
+ */
+#define CPPUNIT_TEST_FAIL( testMethod ) \
+ CPPUNIT_TEST_EXCEPTION( testMethod, CppUnit::Exception )
+
/** End declaration of the test suite.
*
* After this macro, member access is set to "private".
diff --git a/include/cppunit/extensions/TestSuiteBuilder.h b/include/cppunit/extensions/TestSuiteBuilder.h
index 1db761f..bcddfee 100644
--- a/include/cppunit/extensions/TestSuiteBuilder.h
+++ b/include/cppunit/extensions/TestSuiteBuilder.h
@@ -69,7 +69,20 @@ namespace CppUnit {
addTest( test );
}
- protected:
+ template<typename ExceptionType>
+ void addTestCallerForException( std::string methodName,
+ TestMethod testMethod,
+ Fixture *fixture,
+ ExceptionType *dummyPointer )
+ {
+ Test *test = new TestCaller<Fixture,ExceptionType>(
+ makeTestName( methodName ),
+ testMethod,
+ fixture);
+ addTest( test );
+ }
+
+
std::string makeTestName( const std::string &methodName )
{
return m_suite->getName() + "." + methodName;