~ubuntu-branches/ubuntu/oneiric/psi/oneiric

« back to all changes in this revision

Viewing changes to third-party/cppunit/cppunit/include/cppunit/Protector.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef CPPUNIT_PROTECTOR_H
2
 
#define CPPUNIT_PROTECTOR_H
3
 
 
4
 
#include <cppunit/SourceLine.h>
5
 
 
6
 
CPPUNIT_NS_BEGIN
7
 
 
8
 
class Exception;
9
 
class Message;
10
 
class ProtectorContext;
11
 
class TestResult;
12
 
 
13
 
 
14
 
class CPPUNIT_API Functor
15
 
{
16
 
public:
17
 
  virtual ~Functor();
18
 
 
19
 
  virtual bool operator()() const =0;
20
 
};
21
 
 
22
 
 
23
 
/*! \brief Protects one or more test case run.
24
 
 *
25
 
 * Protector are used to globably 'decorate' a test case. The most common
26
 
 * usage of Protector is to catch exception that do not subclass std::exception,
27
 
 * such as MFC CException class or Rogue Wave RWXMsg class, and capture the
28
 
 * message associated to the exception. In fact, CppUnit capture message from
29
 
 * Exception and std::exception using a Protector.
30
 
 *
31
 
 * Protector are chained. When you add a Protector using 
32
 
 * TestResult::pushProtector(), your protector is in fact passed as a Functor
33
 
 * to the first protector of the chain.
34
 
 *
35
 
 * TestCase protects call to setUp(), runTest() and tearDown() by calling
36
 
 * TestResult::protect().
37
 
 *
38
 
 * Because the protector chain is handled by TestResult, a protector can be
39
 
 * active for a single test, or a complete test run.
40
 
 *
41
 
 * Here are some possible usages:
42
 
 * - run all test case in a separate thread and assumes the test failed if it
43
 
 *   did not finish in a given time (infinite loop work around)
44
 
 * - performance tracing : time only the runTest() time.
45
 
 * \sa TestResult, TestCase, TestListener.
46
 
 */
47
 
class CPPUNIT_API Protector
48
 
{
49
 
public:
50
 
  virtual ~Protector();
51
 
  
52
 
  virtual bool protect( const Functor &functor,
53
 
                        const ProtectorContext &context ) =0;
54
 
 
55
 
protected:
56
 
  void reportError( const ProtectorContext &context,
57
 
                    const Exception &error ) const;
58
 
 
59
 
  void reportError( const ProtectorContext &context,
60
 
                    const Message &message,
61
 
                    const SourceLine &sourceLine = SourceLine() ) const;
62
 
 
63
 
  void reportFailure( const ProtectorContext &context,
64
 
                      const Exception &failure ) const;
65
 
 
66
 
  Message actualMessage( const Message &message,
67
 
                         const ProtectorContext &context ) const;
68
 
};
69
 
 
70
 
 
71
 
/*! \brief Scoped protector push to TestResult.
72
 
 *
73
 
 * Adds the specified Protector to the specified TestResult for the object
74
 
 * life-time.
75
 
 */
76
 
class CPPUNIT_API ProtectorGuard
77
 
{
78
 
public:
79
 
  /// Pushes the specified protector.
80
 
  ProtectorGuard( TestResult *result,
81
 
                  Protector *protector );
82
 
 
83
 
  /// Pops the protector.
84
 
  ~ProtectorGuard();
85
 
 
86
 
private:
87
 
  TestResult *m_result;
88
 
};
89
 
 
90
 
CPPUNIT_NS_END
91
 
 
92
 
 
93
 
#endif // CPPUNIT_PROTECTOR_H
94