📄 test.h
字号:
// test.h#ifndef TEST_H#define TEST_H#include <string>#include <iosfwd>using std::string;using std::ostream;// The following have underscores because they are macros// (and it's impolite to usurp other users' functions!).// For consistency, _succeed() also has an underscore.#define _test(cond) do_test(cond, #cond, __FILE__, __LINE__)#define _fail(str) do_fail(str, __FILE__, __LINE__)class Test{public: Test(ostream* osptr = 0); 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* m_osptr; long m_nPass; long m_nFail; // Disallowed: Test(const Test&); Test& operator=(const Test&);};inlineTest::Test(ostream* osptr){ m_osptr = osptr; m_nPass = m_nFail = 0;}inlinelong Test::getNumPassed() const{ return m_nPass;}inlinelong Test::getNumFailed() const{ return m_nFail;}inlineconst ostream* Test::getStream() const{ return m_osptr;}inlinevoid Test::setStream(ostream* osptr){ m_osptr = osptr;}inlinevoid Test::_succeed(){ ++m_nPass;}inlinevoid Test::reset(){ m_nPass = m_nFail = 0;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -