1 #include "cppunit/Exception.h" 2 #include "cppunit/Test.h" 3 #include "cppunit/TestFailure.h" 4 5 namespace CppUnit { 6 7 /// Constructs a TestFailure with the given test and exception. 8 TestFailure::TestFailure( Test *failedTest, 9 Exception *thrownException, 10 bool isError ) : 11 m_failedTest( failedTest ), 12 m_thrownException( thrownException ), 13 m_isError( isError ) 14 { 15 } 16 17 /// Deletes the owned exception. 18 TestFailure::~TestFailure() 19 { 20 delete m_thrownException; 21 } 22 23 /// Gets the failed test. 24 Test * 25 TestFailure::failedTest() const 26 { 27 return m_failedTest; 28 } 29 30 31 /// Gets the thrown exception. Never \c NULL. 32 Exception * 33 TestFailure::thrownException() const 34 { 35 return m_thrownException; 36 } 37 38 39 /// Gets the failure location. 40 SourceLine 41 TestFailure::sourceLine() const 42 { 43 return m_thrownException->sourceLine(); 44 } 45 46 47 /// Indicates if the failure is a failed assertion or an error. 48 bool 49 TestFailure::isError() const 50 { 51 return m_isError; 52 } 53 54 55 /// Gets the name of the failed test. 56 string 57 TestFailure::failedTestName() const 58 { 59 return m_failedTest->getName(); 60 } 61 62 63 /// Returns a short description of the failure. 64 string 65 TestFailure::toString() const 66 { 67 return m_failedTest->toString() + ": " + m_thrownException->what(); 68 } 69 70 71 TestFailure * 72 TestFailure::clone() const 73 { 74 return new TestFailure( m_failedTest, m_thrownException->clone(), m_isError ); 75 } 76 77 } // namespace CppUnit 78