testsuite.hh

Go to the documentation of this file.
1 
7 #ifndef testSUITE_H
8 #define testSUITE_H
9 
10 #include "testcase.hh"
11 #include "exceptions.hh"
12 #include <vector>
13 using std::string;
14 using std::ostream;
15 using std::vector;
16 
17 namespace test {
18 
19  // ******************************************************** TestSuiteError **
20 
25  public:
26  TestSuiteError(const std::string& error) throw();
27  protected:
28  virtual std::ostream& info(std::ostream& os) const throw();
29  };
30 
31  // ************************************************************* TestSuite **
32 
41  class TestSuite {
42  public:
47  TestSuite(const string& name, ostream* osptr = 0);
48 
50  string getName() const { return m_name; }
52  long getNumPassed() const;
54  long getNumFailed() const;
56  const ostream* getStream() const { return m_osptr; }
58  void setStream(ostream* osptr) { m_osptr = osptr; }
59 
61  void addTest(TestCase* t) throw (TestSuiteError);
63  void addSuite(const TestSuite&) throw(TestSuiteError);
65  void run();
70  long report() const;
72  void free();
73  private:
74  string m_name;
75  ostream* m_osptr;
76  vector<TestCase*> m_tests;
77  void reset();
78 
83  };
84 
85  inline TestSuite::TestSuite(const string& name, ostream* osptr) :
86  m_name(name), m_osptr(osptr) {
87  if (m_osptr == 0)
88  m_osptr = &std::cout;
89  }
90 
91 } // namespace test
92 
93 #endif // testSUITE_H
Base class for tests.
Definition: testcase.hh:92
ostream * m_osptr
Definition: testsuite.hh:75
void run()
Runs all test cases in the suite.
TestSuite(const string &name, ostream *osptr=0)
Constructor.
Definition: testsuite.hh:85
TestSuite & operator=(const TestSuite &)
Disallowed.
void addTest(TestCase *t)
Adds a test case to the suite of tests.
const ostream * getStream() const
Returns output stream.
Definition: testsuite.hh:56
long report() const
Prints a report on the number of passed and failed tests in the whole suite to the output stream.
Unit tests.
Definition: testcase.hh:66
Suite of tests.
Definition: testsuite.hh:41
void free()
Deletes the tests.
string getName() const
Returns name of test suite.
Definition: testsuite.hh:50
vector< TestCase * > m_tests
Definition: testsuite.hh:76
Exception for TestSuite.
Definition: testsuite.hh:24
TestSuiteError(const std::string &error)
TestSuite(const TestSuite &)
Disallowed.
Exception class to express a missing feature.
Definition: exceptions.hh:206
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
long getNumFailed() const
Returns number of failed tests.
long getNumPassed() const
Returns number of passed tests.
void setStream(ostream *osptr)
Sets the output stream.
Definition: testsuite.hh:58
void addSuite(const TestSuite &)
Adds a test suite to this test suite.
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich