Imported Upstream version 2.81
[platform/upstream/libbullet.git] / UnitTests / cppunit / src / cppunit / Protector.cpp
1 #include <cppunit/Exception.h>
2 #include <cppunit/Message.h>
3 #include <cppunit/Protector.h>
4 #include <cppunit/TestResult.h>
5 #include "ProtectorContext.h"
6 #include <memory>
7
8 CPPUNIT_NS_BEGIN
9
10 Functor::~Functor()
11 {
12 }
13
14
15 Protector::~Protector()
16 {
17 }
18
19
20 void 
21 Protector::reportError( const ProtectorContext &context,
22                         const Exception &error ) const
23 {
24   std::auto_ptr<Exception> actualError( error.clone() );
25   actualError->setMessage( actualMessage( actualError->message(), context ) );
26   context.m_result->addError( context.m_test, 
27                               actualError.release() );
28 }
29
30
31
32 void 
33 Protector::reportError( const ProtectorContext &context,
34                         const Message &message,
35                         const SourceLine &sourceLine ) const
36 {
37   reportError( context, Exception( message, sourceLine ) );
38 }
39
40
41 void 
42 Protector::reportFailure( const ProtectorContext &context,
43                           const Exception &failure ) const
44 {
45   std::auto_ptr<Exception> actualFailure( failure.clone() );
46   actualFailure->setMessage( actualMessage( actualFailure->message(), context ) );
47   context.m_result->addFailure( context.m_test, 
48                                 actualFailure.release() );
49 }
50
51
52 Message 
53 Protector::actualMessage( const Message &message,
54                           const ProtectorContext &context ) const
55 {
56   Message theActualMessage;
57   if ( context.m_shortDescription.empty() )
58     theActualMessage = message;
59   else
60   {
61     theActualMessage = Message( context.m_shortDescription, 
62                                 message.shortDescription() );
63     theActualMessage.addDetail( message );
64   }
65
66   return theActualMessage;
67 }
68
69
70
71
72 ProtectorGuard::ProtectorGuard( TestResult *result,
73                                               Protector *protector )
74     : m_result( result )
75 {
76   m_result->pushProtector( protector );
77 }
78
79
80 ProtectorGuard::~ProtectorGuard()
81 {
82   m_result->popProtector();
83 }
84
85
86 CPPUNIT_NS_END