~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to lib/cppunit-1.10.0/src/cppunit/TestCase.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2006-11-11 10:32:06 UTC
  • Revision ID: james.westby@ubuntu.com-20061111103206-f3p0r9g0vq44rp3r
Tags: upstream-3.0.PRE5
ImportĀ upstreamĀ versionĀ 3.0.PRE5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cppunit/Portability.h>
 
2
#include <cppunit/Exception.h>
 
3
#include <cppunit/Protector.h>
 
4
#include <cppunit/TestCase.h>
 
5
#include <cppunit/TestResult.h>
 
6
#include <stdexcept>
 
7
 
 
8
#if CPPUNIT_USE_TYPEINFO_NAME
 
9
#  include <typeinfo>
 
10
#endif
 
11
 
 
12
CPPUNIT_NS_BEGIN
 
13
 
 
14
/*! \brief Functor to call test case method (Implementation).
 
15
 *
 
16
 * Implementation detail.
 
17
 */
 
18
class TestCaseMethodFunctor : public Functor
 
19
{
 
20
public:
 
21
  typedef void (TestCase::*Method)();
 
22
 
 
23
  TestCaseMethodFunctor( TestCase *target,
 
24
                         Method method )
 
25
     : m_target( target )
 
26
     , m_method( method )
 
27
  {
 
28
  }
 
29
 
 
30
  bool operator()() const
 
31
  {
 
32
    (m_target->*m_method)();
 
33
    return true;
 
34
  }
 
35
 
 
36
private:
 
37
  TestCase *m_target;
 
38
  Method m_method;
 
39
};
 
40
 
 
41
 
 
42
/** Constructs a test case.
 
43
 *  \param name the name of the TestCase.
 
44
 **/
 
45
TestCase::TestCase( const std::string &name )
 
46
    : m_name(name)
 
47
{
 
48
}
 
49
 
 
50
 
 
51
/// Run the test and catch any exceptions that are triggered by it 
 
52
void 
 
53
TestCase::run( TestResult *result )
 
54
{
 
55
  result->startTest(this);
 
56
/*
 
57
  try {
 
58
    setUp();
 
59
 
 
60
    try {
 
61
      runTest();
 
62
    }
 
63
    catch ( Exception &e ) {
 
64
      Exception *copy = e.clone();
 
65
      result->addFailure( this, copy );
 
66
    }
 
67
    catch ( std::exception &e ) {
 
68
      result->addError( this, new Exception( Message( "uncaught std::exception", 
 
69
                                                      e.what() ) ) );
 
70
    }
 
71
    catch (...) {
 
72
      Exception *e = new Exception( Message( "uncaught unknown exception" ) );
 
73
      result->addError( this, e );
 
74
    }
 
75
 
 
76
    try {
 
77
      tearDown();
 
78
    }
 
79
    catch (...) {
 
80
      result->addError( this, new Exception( Message( "tearDown() failed" ) ) );
 
81
    }
 
82
  }
 
83
  catch (...) {
 
84
    result->addError( this, new Exception( Message( "setUp() failed" ) ) );
 
85
  }
 
86
*/
 
87
  if ( result->protect( TestCaseMethodFunctor( this, &TestCase::setUp ),
 
88
                        this,
 
89
                       "setUp() failed" ) )
 
90
  {
 
91
    result->protect( TestCaseMethodFunctor( this, &TestCase::runTest ),
 
92
                     this );
 
93
  }
 
94
 
 
95
  result->protect( TestCaseMethodFunctor( this, &TestCase::tearDown ),
 
96
                   this,
 
97
                   "tearDown() failed" );
 
98
 
 
99
  result->endTest( this );
 
100
}
 
101
 
 
102
 
 
103
/// All the work for runTest is deferred to subclasses 
 
104
void 
 
105
TestCase::runTest()
 
106
{
 
107
}
 
108
 
 
109
 
 
110
/** Constructs a test case for a suite.
 
111
 * \deprecated This constructor was used by fixture when TestFixture did not exist.
 
112
 *             Have your fixture inherits TestFixture instead of TestCase.
 
113
 * \internal
 
114
 *  This TestCase was intended for use by the TestCaller and should not
 
115
 *  be used by a test case for which run() is called.
 
116
 **/
 
117
TestCase::TestCase()
 
118
    : m_name( "" )
 
119
{
 
120
}
 
121
 
 
122
 
 
123
/// Destructs a test case
 
124
TestCase::~TestCase()
 
125
{
 
126
}
 
127
 
 
128
 
 
129
/// Returns the name of the test case
 
130
std::string 
 
131
TestCase::getName() const
 
132
 
133
  return m_name; 
 
134
}
 
135
  
 
136
 
 
137
CPPUNIT_NS_END