~ubuntu-branches/ubuntu/utopic/psi/utopic

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef CPPUNIT_TESTRUNNER_H
 
2
#define CPPUNIT_TESTRUNNER_H
 
3
 
 
4
#include <cppunit/TestSuite.h>
 
5
#include <string>
 
6
 
 
7
CPPUNIT_NS_BEGIN
 
8
 
 
9
 
 
10
class Test;
 
11
class TestResult;
 
12
 
 
13
 
 
14
/*! \brief Generic test runner.
 
15
 * \ingroup ExecutingTest
 
16
 *
 
17
 * The TestRunner assumes ownership of all added tests: you can not add test
 
18
 * or suite that are local variable since they can't be deleted.
 
19
 *
 
20
 * Example of usage:
 
21
 * \code
 
22
 * #include <cppunit/extensions/TestFactoryRegistry.h>
 
23
 * #include <cppunit/CompilerOutputter.h>
 
24
 * #include <cppunit/TestResult.h>
 
25
 * #include <cppunit/TestResultCollector.h>
 
26
 * #include <cppunit/TestRunner.h>
 
27
 * #include <cppunit/TextTestProgressListener.h>
 
28
 * 
 
29
 * 
 
30
 * int 
 
31
 * main( int argc, char* argv[] )
 
32
 * {
 
33
 *   std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
 
34
 * 
 
35
 *   // Create the event manager and test controller
 
36
 *   CppUnit::TestResult controller;
 
37
 * 
 
38
 *   // Add a listener that colllects test result
 
39
 *   CppUnit::TestResultCollector result;
 
40
 *   controller.addListener( &result );        
 
41
 * 
 
42
 *   // Add a listener that print dots as test run.
 
43
 *   CppUnit::TextTestProgressListener progress;
 
44
 *   controller.addListener( &progress );      
 
45
 * 
 
46
 *   // Add the top suite to the test runner
 
47
 *   CppUnit::TestRunner runner;
 
48
 *   runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() );   
 
49
 *   try
 
50
 *   {
 
51
 *     std::cout << "Running "  <<  testPath;
 
52
 *     runner.run( controller, testPath );
 
53
 * 
 
54
 *     std::cerr << std::endl;
 
55
 * 
 
56
 *     // Print test in a compiler compatible format.
 
57
 *     CppUnit::CompilerOutputter outputter( &result, std::cerr );
 
58
 *     outputter.write();                      
 
59
 *   }
 
60
 *   catch ( std::invalid_argument &e )  // Test path not resolved
 
61
 *   {
 
62
 *     std::cerr  <<  std::endl  
 
63
 *                <<  "ERROR: "  <<  e.what()
 
64
 *                << std::endl;
 
65
 *     return 0;
 
66
 *   }
 
67
 * 
 
68
 *   return result.wasSuccessful() ? 0 : 1;
 
69
 * }
 
70
 * \endcode
 
71
 */
 
72
class CPPUNIT_API TestRunner
 
73
{
 
74
public:
 
75
  /*! \brief Constructs a TestRunner object.
 
76
   */
 
77
  TestRunner(  );
 
78
 
 
79
  /// Destructor.
 
80
  virtual ~TestRunner();
 
81
 
 
82
  /*! \brief Adds the specified test.
 
83
   * \param test Test to add. The TestRunner takes ownership of the test.
 
84
   */
 
85
  virtual void addTest( Test *test );
 
86
 
 
87
  /*! \brief Runs a test using the specified controller.
 
88
   * \param controller Event manager and controller used for testing
 
89
   * \param testPath Test path string. See Test::resolveTestPath() for detail.
 
90
   * \exception std::invalid_argument if no test matching \a testPath is found.
 
91
   *                                  see TestPath::TestPath( Test*, const std::string &)
 
92
   *                                  for detail.
 
93
   */
 
94
  virtual void run( TestResult &controller,
 
95
                    const std::string &testPath = "" );
 
96
 
 
97
protected:
 
98
  /*! \brief (INTERNAL) Mutating test suite.
 
99
   */
 
100
  class CPPUNIT_API WrappingSuite : public TestSuite
 
101
  {
 
102
  public:
 
103
    WrappingSuite( const std::string &name = "All Tests" );
 
104
 
 
105
    int getChildTestCount() const;
 
106
 
 
107
    std::string getName() const;
 
108
 
 
109
    void run( TestResult *result );
 
110
 
 
111
  protected:
 
112
    Test *doGetChildTestAt( int index ) const;
 
113
 
 
114
    bool hasOnlyOneTest() const;
 
115
 
 
116
    Test *getUniqueChildTest() const;
 
117
  };
 
118
 
 
119
protected:
 
120
  WrappingSuite *m_suite;
 
121
 
 
122
private:
 
123
  /// Prevents the use of the copy constructor.
 
124
  TestRunner( const TestRunner &copy );
 
125
 
 
126
  /// Prevents the use of the copy operator.
 
127
  void operator =( const TestRunner &copy );
 
128
 
 
129
private:
 
130
};
 
131
 
 
132
 
 
133
CPPUNIT_NS_END
 
134
 
 
135
#endif  // CPPUNIT_TESTRUNNER_H