⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mockfunctor.h

📁 这是国外的resip协议栈
💻 H
字号:
#ifndef MOCKFUNCTOR_H#define MOCKFUNCTOR_H#include <cppunit/TestAssert.h>#include <cppunit/Protector.h>#include "FailureException.h"#include "MockProtector.h"class MockFunctor : public CPPUNIT_NS::Functor{public:  MockFunctor()    : m_shouldThrow( false )    , m_shouldThrowFailureException( false )    , m_hasExpectation( false )    , m_actualCallCount( 0 )    , m_expectedCallCount( 0 )    , m_shouldSucceed( true )  {  }  bool operator()() const  {    ++CPPUNIT_CONST_CAST(MockFunctor *,this)->m_actualCallCount;    if ( m_shouldThrow )    {      if ( m_shouldThrowFailureException )        throw FailureException();      throw MockProtectorException();    }    return m_shouldSucceed;  }  void setThrowFailureException()  {    m_shouldThrow = true;    m_shouldThrowFailureException = true;    ++m_expectedCallCount;    m_hasExpectation = true;  }  void setThrowMockProtectorException()  {    m_shouldThrow = true;    m_shouldThrowFailureException = false;    ++m_expectedCallCount;    m_hasExpectation = true;  }  void setShouldFail()  {    m_shouldSucceed = false;  }  void setShouldSucceed()  {    m_shouldSucceed = true;  }  void setExpectedCallCount( int callCount =1 )  {    m_expectedCallCount = callCount;    m_hasExpectation = true;  }  void verify()  {    if ( m_hasExpectation )    {      CPPUNIT_ASSERT_EQUAL_MESSAGE( "MockFunctor: bad call count",                                    m_expectedCallCount,                                    m_actualCallCount );    }  }private:  bool m_shouldSucceed;  bool m_shouldThrow;  bool m_shouldThrowFailureException;  bool m_hasExpectation;  int m_actualCallCount;  int m_expectedCallCount;};#endif // MOCKFUNCTOR_H

⌨️ 快捷键说明

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