mockprotector.h

来自「这是国外的resip协议栈」· C头文件 代码 · 共 97 行

H
97
字号
#ifndef MOCKPROTECTOR_H#define MOCKPROTECTOR_H#include <stdexcept>#include <cppunit/Protector.h>class MockProtectorException : public std::runtime_error{public:  MockProtectorException()     : std::runtime_error( "MockProtectorException" )  {  }};class MockProtector : public CPPUNIT_NS::Protector{public:  MockProtector()    : m_expectException( false )    , m_hasExpectation( false )    , m_wasCalled( false )    , m_wasTrapped( false )    , m_shouldPropagateException( false )  {  }  bool protect( const CPPUNIT_NS::Functor &functor,                const CPPUNIT_NS::ProtectorContext &context )  {    try    {      m_wasCalled = true;      return functor();    }    catch ( MockProtectorException & )    {      m_wasTrapped = true;      if ( m_shouldPropagateException )        throw;      reportError( context, CPPUNIT_NS::Message("MockProtector trap") );    }    return false;  }  void setExpectException()  {    m_expectException = true;    m_hasExpectation = true;  }  void setExpectNoException()  {    m_expectException = false;    m_hasExpectation = true;  }  void setExpectCatchAndPropagateException()  {    setExpectException();    m_shouldPropagateException = true;  }  void verify()  {    if ( m_hasExpectation )    {      CPPUNIT_ASSERT_MESSAGE( "MockProtector::protect() was not called",                              m_wasCalled );      std::string message;      if ( m_expectException )        message = "did not catch the exception.";      else        message = "caught an unexpected exception.";      CPPUNIT_ASSERT_EQUAL_MESSAGE( "MockProtector::protect() " + message,                                    m_expectException,                                    m_wasTrapped );    }  }private:  bool m_wasCalled;  bool m_wasTrapped;  bool m_expectException;  bool m_hasExpectation;  bool m_shouldPropagateException;};#endif // MOCKPROTECTOR_H

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?