📄 test.h
字号:
//: TestSuite:Test.h
#ifndef TEST_H
#define TEST_H
#include <string>
#include <iostream>
#include <cassert>
using std::string;
using std::ostream;
using std::cout;
// The following have underscores because
// they are macros. For consistency,
// succeed_() also has an underscore.
#define test_(cond) \
do_test(cond, #cond, __FILE__, __LINE__)
#define fail_(str) \
do_fail(str, __FILE__, __LINE__)
namespace TestSuite {
class Test {
public:
Test(ostream* osptr = &cout);
virtual ~Test(){}
virtual void run() = 0;
long getNumPassed() const;
long getNumFailed() const;
const ostream* getStream() const;
void setStream(ostream* osptr);
void succeed_();
long report() const;
virtual void reset();
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);
private:
ostream* osptr;
long nPass;
long nFail;
// Disallowed:
Test(const Test&);
Test& operator=(const Test&);
};
inline Test::Test(ostream* osptr) {
this->osptr = osptr;
nPass = nFail = 0;
}
inline long Test::getNumPassed() const {
return nPass;
}
inline long Test::getNumFailed() const {
return nFail;
}
inline const ostream* Test::getStream() const {
return osptr;
}
inline void Test::setStream(ostream* osptr) {
this->osptr = osptr;
}
inline void Test::succeed_() {
++nPass;
}
inline void Test::reset() {
nPass = nFail = 0;
}
} // namespace TestSuite
#endif // TEST_H ///:~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -