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