|
|
@@ -0,0 +1,114 @@
|
|
|
+#include "SpSecureClient.h"
|
|
|
+#include "gmock/gmock.h"
|
|
|
+#include "gtest/gtest.h"
|
|
|
+
|
|
|
+using testing::_;
|
|
|
+using testing::A;
|
|
|
+using testing::An;
|
|
|
+using testing::AnyNumber;
|
|
|
+using testing::Const;
|
|
|
+using testing::DoDefault;
|
|
|
+using testing::Eq;
|
|
|
+using testing::Lt;
|
|
|
+using testing::MockFunction;
|
|
|
+using testing::Ref;
|
|
|
+using testing::Return;
|
|
|
+using testing::ReturnRef;
|
|
|
+using testing::TypedEq;
|
|
|
+
|
|
|
+class CMockServerSession : public CServerSessionBase
|
|
|
+{
|
|
|
+public:
|
|
|
+ CMockServerSession(CEntityBase* pEntity):m_pEntity(pEntity) {}
|
|
|
+ ~CMockServerSession() {}
|
|
|
+
|
|
|
+ bool IsExclusive() override { return false; }
|
|
|
+ bool IsSessionOverlap() override { return true; }
|
|
|
+private:
|
|
|
+ CEntityBase* m_pEntity;
|
|
|
+};
|
|
|
+
|
|
|
+class entity_function_mock : public IEntityFunction
|
|
|
+{
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+class CMockEntity : public CEntityBase
|
|
|
+{
|
|
|
+public:
|
|
|
+ MOCK_METHOD0(OnStarted, void());
|
|
|
+ MOCK_METHOD2(OnPreStart, void(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext));
|
|
|
+ MOCK_METHOD2(OnNewSession, CServerSessionBase* (const char* /*pszRemoteEntityName*/, const char* /*pszParam*/));
|
|
|
+ MOCK_CONST_METHOD0(GetEntityName, const char* ());
|
|
|
+ MOCK_METHOD0(IsService, bool());
|
|
|
+};
|
|
|
+
|
|
|
+class client_comm_func_mock : public IClientCommFunc
|
|
|
+{
|
|
|
+public:
|
|
|
+ client_comm_func_mock() {}
|
|
|
+ virtual ~client_comm_func_mock() {}
|
|
|
+
|
|
|
+ MOCK_METHOD0(IsConnectionOK, bool());
|
|
|
+ MOCK_METHOD0(IsSecureConnection, bool());
|
|
|
+
|
|
|
+ MOCK_METHOD3(Connect, bool(const char* pServerAddr, int nPort, int nOption));
|
|
|
+ MOCK_METHOD0(Close, void());
|
|
|
+
|
|
|
+ MOCK_METHOD1(SendPackage, string(const CSmartPointer<IPackage>& pSendPkg));
|
|
|
+ MOCK_METHOD1(ReceivePackage, CSmartPointer<IPackage>(int nWaitSecond));
|
|
|
+ MOCK_METHOD1(CreateNewPackage, CSmartPointer<IPackage>(const char* pServiceCode));
|
|
|
+ MOCK_METHOD1(CreateReplyPackage, CSmartPointer<IPackage>(const CSmartPointer<IPackage>& pRecvPkg));
|
|
|
+};
|
|
|
+
|
|
|
+/*
|
|
|
+ * SpSecureClient 是用于Entity内连接分行服务使用的,继承该类并实现相关功能
|
|
|
+ */
|
|
|
+class CMockSecureClient : public SpSecureClient
|
|
|
+{
|
|
|
+public:
|
|
|
+ CMockSecureClient(CEntityBase* pEntityBase):SpSecureClient(pEntityBase){}
|
|
|
+
|
|
|
+ //MOCK_METHOD3(Connect, bool(const char* pServerAddr, int nPort, int nOption));
|
|
|
+ MOCK_METHOD1(ConnectFromConfig, bool(int nOption));
|
|
|
+ MOCK_METHOD0(ConnectFromCentralSetting, bool());
|
|
|
+ MOCK_METHOD0(IsConnectionOK, bool());
|
|
|
+ MOCK_METHOD0(IsSecureConn, bool());
|
|
|
+ MOCK_METHOD0(Close, void());
|
|
|
+
|
|
|
+ MOCK_METHOD1(SendPackage, string(const CSmartPointer<IPackage>& pSendPkg));
|
|
|
+ MOCK_METHOD1(ReceivePackage, CSmartPointer<IPackage>(int nWaitSecond));
|
|
|
+ MOCK_METHOD1(CreateNewPackage, CSmartPointer<IPackage>(const char* pServiceCode));
|
|
|
+ MOCK_METHOD1(CreateReplyPackage, CSmartPointer<IPackage>(const CSmartPointer<IPackage>& pRecvPkg));
|
|
|
+
|
|
|
+ MOCK_METHOD3(OnErrorMsg, void(DWORD dwSysCode, DWORD dwUserCode, const CSimpleStringA& pErrMsg));
|
|
|
+ MOCK_METHOD1(OnPkgAnswer, void(const CSmartPointer<IPackage>& pRecvPkg));
|
|
|
+
|
|
|
+ MOCK_METHOD0(GetFunction, CSmartPointer<IClientCommFunc>());
|
|
|
+};
|
|
|
+
|
|
|
+TEST(SpSecureClientMockTest, SpSecureClientComm)
|
|
|
+{
|
|
|
+ testing::DefaultValue<bool>::Set(true);
|
|
|
+
|
|
|
+ CMockEntity* entity = new CMockEntity();
|
|
|
+ ON_CALL(*entity, GetEntityName()).WillByDefault(Return("MockEntity"));
|
|
|
+ EXPECT_CALL(*entity, OnStarted()).Times(1);
|
|
|
+
|
|
|
+ client_comm_func_mock* comm_func_mock = new client_comm_func_mock();
|
|
|
+
|
|
|
+
|
|
|
+ CMockSecureClient* mock = new CMockSecureClient(entity);
|
|
|
+
|
|
|
+ ON_CALL(*mock, GetFunction()).WillByDefault(testing::Return(comm_func_mock));
|
|
|
+ EXPECT_CALL(*mock, GetFunction());
|
|
|
+ EXPECT_TRUE(mock->GetFunction() == CSmartPointer<IClientCommFunc>(comm_func_mock));
|
|
|
+
|
|
|
+ mock->Connect("127.0.0.1", 8090, 1);
|
|
|
+
|
|
|
+ mock->DecRefCount();
|
|
|
+ delete comm_func_mock;
|
|
|
+ delete entity;
|
|
|
+
|
|
|
+ testing::DefaultValue<bool>::Clear();
|
|
|
+}
|