56 lines
1.5 KiB
C++
56 lines
1.5 KiB
C++
//: TestSuite:Test.h
|
|
// From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison.
|
|
// (c) 1995-2004 MindView, Inc. All Rights Reserved.
|
|
// See source code use permissions stated in the file 'License.txt',
|
|
// distributed with the code package available at www.MindView.net.
|
|
#ifndef TEST_H
|
|
#define TEST_H
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <cassert>
|
|
using std::string;
|
|
using std::ostream;
|
|
using std::cout;
|
|
|
|
// fail_() has an underscore to prevent collision with
|
|
// ios::fail(). For consistency, test_() and succeed_()
|
|
// also have underscores.
|
|
|
|
#define test_(cond) \
|
|
do_test(cond, #cond, __FILE__, __LINE__)
|
|
#define fail_(str) \
|
|
do_fail(str, __FILE__, __LINE__)
|
|
|
|
namespace TestSuite {
|
|
|
|
class Test {
|
|
ostream* osptr;
|
|
long nPass;
|
|
long nFail;
|
|
// Disallowed:
|
|
Test(const Test&);
|
|
Test& operator=(const Test&);
|
|
protected:
|
|
void do_test(bool cond, const string& lbl,
|
|
const char* fname, long lineno);
|
|
void do_fail(const string& lbl,
|
|
const char* fname, long lineno);
|
|
public:
|
|
Test(ostream* osptr = &cout) {
|
|
this->osptr = osptr;
|
|
nPass = nFail = 0;
|
|
}
|
|
virtual ~Test() {}
|
|
virtual void run() = 0;
|
|
long getNumPassed() const { return nPass; }
|
|
long getNumFailed() const { return nFail; }
|
|
const ostream* getStream() const { return osptr; }
|
|
void setStream(ostream* osptr) { this->osptr = osptr; }
|
|
void succeed_() { ++nPass; }
|
|
long report() const;
|
|
virtual void reset() { nPass = nFail = 0; }
|
|
};
|
|
|
|
} // namespace TestSuite
|
|
#endif // TEST_H ///:~
|