test.h

来自「Password Safe Password Safe is a passwor」· C头文件 代码 · 共 94 行

H
94
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?