summaryrefslogtreecommitdiff
path: root/src/cppunit/TestCase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cppunit/TestCase.cpp')
-rw-r--r--src/cppunit/TestCase.cpp120
1 files changed, 68 insertions, 52 deletions
diff --git a/src/cppunit/TestCase.cpp b/src/cppunit/TestCase.cpp
index 9499416..8f5494a 100644
--- a/src/cppunit/TestCase.cpp
+++ b/src/cppunit/TestCase.cpp
@@ -10,124 +10,140 @@
namespace CppUnit {
/// Create a default TestResult
-CppUnit::TestResult* TestCase::defaultResult ()
-{ return new TestResult; }
+CppUnit::TestResult*
+TestCase::defaultResult()
+{
+ return new TestResult;
+}
/// Run the test and catch any exceptions that are triggered by it
void
-TestCase::run (TestResult *result)
+TestCase::run( TestResult *result )
{
- result->startTest (this);
+ result->startTest(this);
- try {
- setUp ();
-
- try {
- runTest ();
- }
- catch (Exception& e) {
+ try {
+ setUp();
+
+ try {
+ runTest();
+ }
+ catch ( Exception &e ) {
Exception *copy = e.clone();
- result->addFailure (this, copy);
- }
- catch (std::exception& e) {
- result->addError (this, new Exception (e.what ()));
- }
- catch (...) {
- Exception *e = new Exception ("caught unknown exception");
- result->addError (this, e);
- }
-
- try {
- tearDown ();
- }
- catch ( ... ) {
+ result->addFailure( this, copy );
+ }
+ catch ( std::exception &e ) {
+ result->addError( this, new Exception( e.what() ) );
+ }
+ catch (...) {
+ Exception *e = new Exception( "caught unknown exception" );
+ result->addError( this, e );
+ }
+
+ try {
+ tearDown();
+ }
+ catch (...) {
result->addError( this, new Exception( "tearDown() failed" ) );
- }
- }
- catch ( ... ) {
- result->addError( this, new Exception( "setUp() failed" ) );
- }
-
- result->endTest (this);
+ }
+ }
+ catch (...) {
+ result->addError( this, new Exception( "setUp() failed" ) );
+ }
+
+ result->endTest( this );
}
/// A default run method
-TestResult *TestCase::run ()
+TestResult *
+TestCase::run()
{
- TestResult *result = defaultResult ();
+ TestResult *result = defaultResult();
run (result);
return result;
-
}
+
/// All the work for runTest is deferred to subclasses
-void TestCase::runTest ()
+void
+TestCase::runTest()
{
}
+
/** Constructs a test case.
* \param name the name of the TestCase.
**/
-TestCase::TestCase (std::string name)
- : m_name (name)
+TestCase::TestCase( std::string name )
+ : m_name(name)
{
}
+
/** Constructs a test case for a suite.
* This TestCase is intended for use by the TestCaller and should not
* be used by a test case for which run() is called.
**/
-TestCase::TestCase ()
- : m_name ("")
+TestCase::TestCase()
+ : m_name( "" )
{
}
/// Destructs a test case
-TestCase::~TestCase ()
-{}
+TestCase::~TestCase()
+{
+}
/// Returns a count of all the tests executed
-int TestCase::countTestCases () const
-{ return 1; }
+int
+TestCase::countTestCases() const
+{
+ return 1;
+}
/// Returns the name of the test case
std::string
- TestCase::getName () const
+TestCase::getName() const
{
return m_name;
}
/// A hook for fixture set up
-void TestCase::setUp ()
-{}
+void
+TestCase::setUp()
+{
+}
/// A hook for fixture tear down
-void TestCase::tearDown ()
-{}
+void
+TestCase::tearDown()
+{
+}
/// Returns the name of the test case instance
std::string
- TestCase::toString () const
+TestCase::toString() const
{
std::string className;
#if CPPUNIT_USE_TYPEINFO_NAME
- const std::type_info& thisClass = typeid (*this);
+ const std::type_info& thisClass = typeid( *this );
className = thisClass.name();
#else
className = "TestCase";
#endif
- return className + "." + getName ();
+ return className + "." + getName();
}
+
} // namespace CppUnit