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