Class documentation of Concepts

Loading...
Searching...
No Matches
testcase.hh
Go to the documentation of this file.
1
7#ifndef TEST_H
8#define TEST_H
9
10#include <iostream>
11#include <string>
12#include <iosfwd>
13#include <complex>
14
66namespace test {
67
68 using std::string;
69 using std::ostream;
70
71 // The following have underscores because they are macros
72 // (and it's impolite to usurp other users' functions!).
73 // For consistency, _succeed() also has an underscore.
74
76#define _test(cond) do_test(cond, #cond, __FILE__, __LINE__)
78#define _numtest(num, orig) do_numtest(num, orig, #num, #orig, __FILE__, __LINE__)
80#define _numtesttol(num, orig, tol) do_numtest(num, orig, #num, #orig, __FILE__, __LINE__, tol)
82#define _fail(str) do_fail(str, __FILE__, __LINE__)
83
92 class TestCase {
93 public:
97 TestCase(ostream* osptr = 0);
98 virtual ~TestCase() {}
100 virtual void run() = 0;
101
103 long getNumPassed() const { return m_nPass; }
105 long getNumFailed() const { return m_nFail; }
107 const ostream* getStream() const { return m_osptr; }
109 void setStream(ostream* osptr) { m_osptr = osptr; }
110
112 void _succeed() { ++m_nPass; }
117 long report() const;
119 virtual void reset() { m_nPass = m_nFail = 0; }
120 protected:
122 bool do_test(bool cond, const string& lbl,
123 const char* fname, long lineno);
125 bool do_numtest(double num, double orig, const string& lbl,
126 const string& lbl2, const char* fname, long lineno,
127 const double tol = 1e-10);
128 bool do_numtest(std::complex<double> num, std::complex<double> orig,
129 const string& lbl, const string& lbl2, const char* fname,
130 long lineno, const double tol = 1e-10);
134 void do_fail(const string& lbl,
135 const char* fname, long lineno);
136 private:
137 ostream* m_osptr;
138 long m_nPass;
139 long m_nFail;
140
142 TestCase(const TestCase&);
144 TestCase& operator=(const TestCase&);
145 };
146
147 inline TestCase::TestCase(ostream* osptr) :
148 m_osptr(osptr), m_nPass(0), m_nFail(0) {
149 if (m_osptr == 0)
150 m_osptr = &std::cout;
151 }
152
153} // namespace test
154
155#endif // TEST_H
const ostream * getStream() const
Returns output stream.
Definition testcase.hh:107
TestCase(ostream *osptr=0)
Definition testcase.hh:147
long report() const
void setStream(ostream *osptr)
Sets the output stream.
Definition testcase.hh:109
virtual void run()=0
Runs the tests. Must be overwritten by the specialization.
bool do_numtest(double num, double orig, const string &lbl, const string &lbl2, const char *fname, long lineno, const double tol=1e-10)
Internal function to do a numerical test.
long getNumFailed() const
Returns number of failed tests.
Definition testcase.hh:105
void do_fail(const string &lbl, const char *fname, long lineno)
virtual void reset()
Resets the counters for the failed and passed tests.
Definition testcase.hh:119
long getNumPassed() const
Returns number of passed tests.
Definition testcase.hh:103
void _succeed()
Explicitly succeds a test.
Definition testcase.hh:112
bool do_test(bool cond, const string &lbl, const char *fname, long lineno)
Internal function to do a test.