summaryrefslogtreecommitdiff
path: root/src/cppunit
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-08-03 14:50:09 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-08-03 14:50:09 +0000
commite82ccd481800f8f0d36af5310c535b83a6cec788 (patch)
tree2b312dbac05563f3ed7baf63ddbd1fcdcbefc686 /src/cppunit
parent2a31073734be6e44e477079699578820282b7345 (diff)
downloadcppunit-e82ccd481800f8f0d36af5310c535b83a6cec788.tar.gz
Include/cppunit/Exception.
include/cppunit/Exception.h: * src/cppunit/Exception.h: added setMessage(). * include/cppunit/Protector.h: * src/cppunit/Protector.cpp: added class ProtectorGuard. Change the reportXXX() method to support Exception passing and SourceLine. * include/cppunit/TestCaller.h: removed 'expect exception' features. It is now handled by ExceptionTestCaseDecorator and TestCaller no longer need default template argument support. * include/cppunit/TestCase.h: * include/cppunit/extensions/TestCaller.h: runTest() is now public instead of protected, so that it can be decorated. * include/cppunit/TestResult.h: * src/cppunit/TestResult.h: added pushProtector() and popProtector() methods. This allow user to specify their own exception trap when running test case. * include/cppunit/extensions/TestDecorator.h: * src/cppunit/TestDecorator.cpp: added. Extracted from TestDecorator.h. The test passed to the constructor is now owned by the decorator. * include/cppunit/extensions/TestCaseDecorator.h: * src/cppunit/TestCaseDecorator.cpp: added. Decorator for TestCase setUp(), tearDown() and runTest(). * include/cppunit/extensions/ExceptionTestCaseDecorator.h: added. TestCaseDecorator to expect that a specific exception is thrown. * include/cppunit/extensions/HelperMacros.h: updated against TestCaller change. * src/cppunit/DefaultFunctor.h: fixed bug (did not return underlying test return code). * src/cppunit/ProtectorChain.cpp: fixed bug in chaing return code. * src/cppunit/DefaultFunctor.h: fixed bug. * src/msvc6/testrunner/ActiveTest.h: * src/msvc6/testrunner/ActiveTest.cpp: updated against TestCaseDecorator ownership policy change. Moved inline functions to .cpp. * examples/cppunittest/TestSetUpTest.cpp: updated to use MockTestCase and against the new ownership policy. * examples/cppunittest/TestDecoratorTest.cpp: * examples/cppunittest/RepeatedTestTest.cpp: updated against TestDecorator ownership policy change. * examples/cppunittest/ExceptionTestCaseDecoratorTest.h: * examples/cppunittest/ExceptionTestCaseDecoratorTest.cpp: added. Unit tests for ExceptionTestCaseDecoratorTest.
Diffstat (limited to 'src/cppunit')
-rw-r--r--src/cppunit/DefaultProtector.cpp13
-rw-r--r--src/cppunit/Exception.cpp7
-rw-r--r--src/cppunit/Makefile.am4
-rw-r--r--src/cppunit/Protector.cpp69
-rw-r--r--src/cppunit/ProtectorChain.cpp5
-rw-r--r--src/cppunit/TestCaseDecorator.cpp47
-rw-r--r--src/cppunit/TestDecorator.cpp53
-rw-r--r--src/cppunit/TestResult.cpp14
-rw-r--r--src/cppunit/TextTestRunner.cpp2
-rw-r--r--src/cppunit/cppunit.dsp20
-rw-r--r--src/cppunit/cppunit_dll.dsp16
11 files changed, 224 insertions, 26 deletions
diff --git a/src/cppunit/DefaultProtector.cpp b/src/cppunit/DefaultProtector.cpp
index 4c8a3ab..d05765c 100644
--- a/src/cppunit/DefaultProtector.cpp
+++ b/src/cppunit/DefaultProtector.cpp
@@ -12,12 +12,16 @@ DefaultProtector::protect( const Functor &functor,
{
try
{
+ // BUG: => should return what is returned. Need to update
+ // UT to prove there is a bug. Consequence: runTest() is called
+ // even if setUp() failed in a 'sub-protector'.
functor();
return true;
+// return functor();
}
catch ( Exception &failure )
{
- reportTestFailure( failure.message(), context, false );
+ reportFailure( context, failure );
}
catch ( std::exception &e )
{
@@ -28,13 +32,12 @@ DefaultProtector::protect( const Functor &functor,
shortDescription += "std::exception (or derived)."
#endif
Message message( shortDescription, e.what() );
- reportTestFailure( message, context, true );
+ reportError( context, message );
}
catch ( ... )
{
- reportTestFailure( Message( "uncaught exception of unknown type"),
- context,
- true );
+ reportError( context,
+ Message( "uncaught exception of unknown type") );
}
return false;
diff --git a/src/cppunit/Exception.cpp b/src/cppunit/Exception.cpp
index e9e3e37..3bbe24b 100644
--- a/src/cppunit/Exception.cpp
+++ b/src/cppunit/Exception.cpp
@@ -91,6 +91,13 @@ Exception::message() const
}
+void
+Exception::setMessage( const Message &message )
+{
+ m_message = message;
+}
+
+
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
long
Exception::lineNumber() const
diff --git a/src/cppunit/Makefile.am b/src/cppunit/Makefile.am
index 33a29c2..8a9f8fc 100644
--- a/src/cppunit/Makefile.am
+++ b/src/cppunit/Makefile.am
@@ -1,5 +1,5 @@
#
-# $Id: Makefile.am,v 1.37 2002-07-16 22:59:22 blep Exp $
+# $Id: Makefile.am,v 1.38 2002-08-03 15:47:52 blep Exp $
#
EXTRA_DIST = cppunit.dsp cppunit_dll.dsp DllMain.cpp
@@ -21,6 +21,7 @@ libcppunit_la_SOURCES = \
Message.cpp \
RepeatedTest.cpp \
PlugInManager.cpp \
+ Protector.cpp \
ProtectorChain.h \
ProtectorContext.h \
ProtectorChain.cpp \
@@ -30,6 +31,7 @@ libcppunit_la_SOURCES = \
Test.cpp \
TestAssert.cpp \
TestCase.cpp \
+ TestCaseDecorator.cpp \
TestComposite.cpp \
TestFactoryRegistry.cpp \
TestFailure.cpp \
diff --git a/src/cppunit/Protector.cpp b/src/cppunit/Protector.cpp
index 626829c..5c171ec 100644
--- a/src/cppunit/Protector.cpp
+++ b/src/cppunit/Protector.cpp
@@ -3,6 +3,7 @@
#include <cppunit/Protector.h>
#include <cppunit/TestResult.h>
#include "ProtectorContext.h"
+#include <memory>
CPPUNIT_NS_BEGIN
@@ -17,24 +18,68 @@ Protector::~Protector()
void
-Protector::reportTestFailure( const Message &message,
- const ProtectorContext &context,
- bool isError )
+Protector::reportError( const ProtectorContext &context,
+ const Exception &error ) const
{
- Message actualMessage;
+ std::auto_ptr<Exception> actualError( error.clone() );
+ actualError->setMessage( actualMessage( actualError->message(), context ) );
+ context.m_result->addError( context.m_test,
+ actualError.release() );
+}
+
+
+
+void
+Protector::reportError( const ProtectorContext &context,
+ const Message &message,
+ const SourceLine &sourceLine ) const
+{
+ reportError( context, Exception( message, sourceLine ) );
+}
+
+
+void
+Protector::reportFailure( const ProtectorContext &context,
+ const Exception &failure ) const
+{
+ std::auto_ptr<Exception> actualFailure( failure.clone() );
+ actualFailure->setMessage( actualMessage( actualFailure->message(), context ) );
+ context.m_result->addFailure( context.m_test,
+ actualFailure.release() );
+}
+
+
+Message
+Protector::actualMessage( const Message &message,
+ const ProtectorContext &context ) const
+{
+ Message theActualMessage;
if ( context.m_shortDescription.empty() )
- actualMessage = message;
+ theActualMessage = message;
else
{
- actualMessage = Message( context.m_shortDescription,
- message.shortDescription() );
- actualMessage.addDetail( message );
+ theActualMessage = Message( context.m_shortDescription,
+ message.shortDescription() );
+ theActualMessage.addDetail( message );
}
- if ( isError )
- context.m_result->addError( context.m_test, new Exception( message ) );
- else
- context.m_result->addFailure( context.m_test, new Exception( message ) );
+ return theActualMessage;
+}
+
+
+
+
+ProtectorGuard::ProtectorGuard( TestResult *result,
+ Protector *protector )
+ : m_result( result )
+{
+ m_result->pushProtector( protector );
+}
+
+
+ProtectorGuard::~ProtectorGuard()
+{
+ m_result->popProtector();
}
diff --git a/src/cppunit/ProtectorChain.cpp b/src/cppunit/ProtectorChain.cpp
index 087b938..f4c8bed 100644
--- a/src/cppunit/ProtectorChain.cpp
+++ b/src/cppunit/ProtectorChain.cpp
@@ -60,10 +60,7 @@ ProtectorChain::protect( const Functor &functor,
const ProtectorContext &context )
{
if ( m_protectors.empty() )
- {
- functor();
- return true;
- }
+ return functor();
Functors functors;
for ( int index = 0; index < m_protectors.size(); ++index )
diff --git a/src/cppunit/TestCaseDecorator.cpp b/src/cppunit/TestCaseDecorator.cpp
new file mode 100644
index 0000000..4fb8f80
--- /dev/null
+++ b/src/cppunit/TestCaseDecorator.cpp
@@ -0,0 +1,47 @@
+#include <cppunit/extensions/TestCaseDecorator.h>
+
+CPPUNIT_NS_BEGIN
+
+
+TestCaseDecorator::TestCaseDecorator( TestCase *test )
+ : m_test( test )
+ , TestCase( test->getName() )
+{
+}
+
+
+TestCaseDecorator::~TestCaseDecorator()
+{
+ delete m_test;
+}
+
+
+std::string
+TestCaseDecorator::getName() const
+{
+ return m_test->getName();
+}
+
+
+void
+TestCaseDecorator::setUp()
+{
+ m_test->setUp();
+}
+
+
+void
+TestCaseDecorator::tearDown()
+{
+ m_test->tearDown();
+}
+
+
+void
+TestCaseDecorator::runTest()
+{
+ m_test->runTest();
+}
+
+
+CPPUNIT_NS_END
diff --git a/src/cppunit/TestDecorator.cpp b/src/cppunit/TestDecorator.cpp
new file mode 100644
index 0000000..918a26e
--- /dev/null
+++ b/src/cppunit/TestDecorator.cpp
@@ -0,0 +1,53 @@
+#include <cppunit/extensions/TestDecorator.h>
+
+CPPUNIT_NS_BEGIN
+
+
+TestDecorator::TestDecorator( Test *test )
+ : m_test( test)
+{
+}
+
+
+TestDecorator::~TestDecorator()
+{
+ delete m_test;
+}
+
+
+int
+TestDecorator::countTestCases() const
+{
+ return m_test->countTestCases();
+}
+
+
+void
+TestDecorator::run( TestResult *result )
+{
+ m_test->run(result);
+}
+
+
+std::string
+TestDecorator::getName() const
+{
+ return m_test->getName();
+}
+
+
+int
+TestDecorator::getChildTestCount() const
+{
+ return m_test->getChildTestCount();
+}
+
+
+Test *
+TestDecorator::doGetChildTestAt( int index ) const
+{
+ return m_test->getChildTestAt( index );
+}
+
+
+CPPUNIT_NS_END \ No newline at end of file
diff --git a/src/cppunit/TestResult.cpp b/src/cppunit/TestResult.cpp
index cf03dd4..66e8d9b 100644
--- a/src/cppunit/TestResult.cpp
+++ b/src/cppunit/TestResult.cpp
@@ -200,4 +200,18 @@ TestResult::protect( const Functor &functor,
}
+void
+TestResult::pushProtector( Protector *protector )
+{
+ m_protectorChain->push( protector );
+}
+
+
+void
+TestResult::popProtector()
+{
+ m_protectorChain->pop();
+}
+
+
CPPUNIT_NS_END
diff --git a/src/cppunit/TextTestRunner.cpp b/src/cppunit/TextTestRunner.cpp
index 2be2d06..5ca182b 100644
--- a/src/cppunit/TextTestRunner.cpp
+++ b/src/cppunit/TextTestRunner.cpp
@@ -117,6 +117,8 @@ TextTestRunner::eventManager() const
*
* Notes that the outputter will be use after the test run only if \a printResult was
* \c true.
+ * \param outputter New outputter to use. The previous outputter is destroyed.
+ * The TextTestRunner assumes ownership of the outputter.
* \see CompilerOutputter, XmlOutputter, TextOutputter.
*/
void
diff --git a/src/cppunit/cppunit.dsp b/src/cppunit/cppunit.dsp
index f44e1bf..ba25beb 100644
--- a/src/cppunit/cppunit.dsp
+++ b/src/cppunit/cppunit.dsp
@@ -492,6 +492,10 @@ SOURCE=..\..\include\cppunit\extensions\TypeInfoHelper.h
# PROP Default_Filter ""
# Begin Source File
+SOURCE=..\..\include\cppunit\extensions\ExceptionTestCaseDecorator.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\cppunit\extensions\Orthodox.h
# End Source File
# Begin Source File
@@ -504,6 +508,18 @@ SOURCE=..\..\include\cppunit\extensions\RepeatedTest.h
# End Source File
# Begin Source File
+SOURCE=.\TestCaseDecorator.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\cppunit\extensions\TestCaseDecorator.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TestDecorator.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\cppunit\extensions\TestDecorator.h
# End Source File
# Begin Source File
@@ -641,10 +657,6 @@ SOURCE=..\..\include\cppunit\Makefile.am
# End Source File
# Begin Source File
-SOURCE=..\..\include\cppunit\plugin\Makefile.am
-# End Source File
-# Begin Source File
-
SOURCE=.\Makefile.am
# End Source File
# End Target
diff --git a/src/cppunit/cppunit_dll.dsp b/src/cppunit/cppunit_dll.dsp
index 9da9ecd..f42f123 100644
--- a/src/cppunit/cppunit_dll.dsp
+++ b/src/cppunit/cppunit_dll.dsp
@@ -119,6 +119,10 @@ SOURCE=.\DllMain.cpp
# PROP Default_Filter ""
# Begin Source File
+SOURCE=..\..\include\cppunit\extensions\ExceptionTestCaseDecorator.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\cppunit\extensions\Orthodox.h
# End Source File
# Begin Source File
@@ -131,6 +135,18 @@ SOURCE=..\..\include\cppunit\extensions\RepeatedTest.h
# End Source File
# Begin Source File
+SOURCE=.\TestCaseDecorator.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\cppunit\extensions\TestCaseDecorator.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TestDecorator.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\cppunit\extensions\TestDecorator.h
# End Source File
# Begin Source File