Browse Source

Z991240-735 #comment module: Assistantchannel实体增加测试用例

胡琛80272472 5 years ago
parent
commit
71d5a9bf14

+ 21 - 146
Module/mod_assistantchannel/mod_assistantchannel.cpp

@@ -1,19 +1,13 @@
 #include "stdafx.h"
-#include "SpBase.h"
-#include "Common/ListEntry.h"
+#include "mod_assistantchannel.h"
+
 #include "VideoDesc.h"
 #include "AssistantChannel_server_g.h"
-#include "bizchan.h"
 #include "rec_common.h"
 #include "chan_protocol.h"
-#include "EventCode.h"
-
-#include "mod_counterconnector/CallType.h"
 
 using namespace AssistantChannel;
 
-class CBizChannelEntity;
-
 static const char *__states[] = {
 	"Idle", "Connecting", "Connected", "Closing"
 };
@@ -70,55 +64,8 @@ static int MakeDesc(DWORD eScreen,DeviceTypeEnum eDevicetype)
 	return 0;
 }
 
-class ChannelServiceSession : public ChannelService_ServerSessionBase
-{
-public:
-	ChannelServiceSession(CBizChannelEntity *pEntity, int id) : m_pEntity(pEntity), m_id(id) {}
-
-	virtual void Handle_Connect(SpReqAnsContext<ChannelService_Connect_Req, ChannelService_Connect_Ans>::Pointer ctx);
-
-	virtual void Handle_Close(SpReqAnsContext<ChannelService_Close_Req, ChannelService_Close_Ans>::Pointer ctx);
-
-	virtual void Handle_GetState(SpReqAnsContext<ChannelService_GetState_Req, ChannelService_GetState_Ans>::Pointer ctx);
-
-	virtual void Handle_BeginState(SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx);
-
-	virtual void Handle_EndState(SpOnewayCallContext<ChannelService_EndState_Info>::Pointer ctx);
-
-	virtual void Handle_Send(SpOnewayCallContext<ChannelService_Send_Info>::Pointer ctx);
-
-	virtual void Handle_BeginRecv(SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx);
 
-	virtual void Handle_EndRecv(SpOnewayCallContext<ChannelService_EndRecv_Info>::Pointer ctx);
-
-	virtual void OnClose(ErrorCodeEnum eErrorCode);
-
-private:
-	int m_id;
-	CBizChannelEntity *m_pEntity;
-};
-
-
-class CBizChannelEntity : public CEntityBase
-{
-public:
-	CBizChannelEntity() : m_id_seq(0) {}
-	virtual ~CBizChannelEntity() {}
-	virtual const char *GetEntityName() const { return "AssistantChannel"; }
-	virtual bool IsService()const{return true;}
-
-	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext) 
-	{ 
-		ErrorCodeEnum Error = __OnStart(Error_Succeed);
-		pTransactionContext->SendAnswer(Error);
-	}
-	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext) 
-	{ 
-		ErrorCodeEnum Error = __OnClose(Error_Succeed);
-		pTransactionContext->SendAnswer(Error); 
-	}
-
-	ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
+	ErrorCodeEnum CBizChannelEntity::__OnStart(ErrorCodeEnum preOperationError)
 	{
 		//MessageBoxA(0,0,0,0);
 		bizchan_lib_init();
@@ -162,21 +109,21 @@ public:
 		return Error_Succeed;
 	}
 
-	ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
+	ErrorCodeEnum CBizChannelEntity::__OnClose(ErrorCodeEnum preOperationError)
 	{
 		//.....
 		bizchan_lib_term();
 		return Error_Succeed;
 	}
 
-	virtual CServerSessionBase *OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
+	CServerSessionBase * CBizChannelEntity::OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
 	{
 		LOG_FUNCTION();
 		LOG_TRACE("%s connected class = %s!", pszRemoteEntityName, pszClass);
 		return new ChannelServiceSession(this, m_id_seq++);
 	}
 
-	ErrorCodeEnum Connect(const char *ip, int port, const char *callno, CallingTypeEnum eType)
+	ErrorCodeEnum CBizChannelEntity::Connect(const char *ip, int port, const char *callno, CallingTypeEnum eType)
 	{
 		ErrorCodeEnum Error = Error_Succeed;
 		if (m_eState == eChannelState_Idle) 
@@ -222,7 +169,7 @@ public:
 		return Error;
 	}
 
-	ErrorCodeEnum Close()
+	ErrorCodeEnum CBizChannelEntity::Close()
 	{
 		ErrorCodeEnum Error = Error_Succeed;
 		if (m_eState == eChannelState_Connecting || m_eState == eChannelState_Connected) {
@@ -238,9 +185,7 @@ public:
 		return Error_Succeed;
 	}
 
-	int GetState() { return m_eState; }
-
-	ErrorCodeEnum RegisterState(int id, SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx)
+	ErrorCodeEnum CBizChannelEntity::RegisterState(int id, SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx)
 	{
 		state_entry *pos;
 		ListEntry_ForEach(pos, &m_stateList, state_entry, entry) 
@@ -257,7 +202,7 @@ public:
 		return Error_Succeed;
 	}
 
-	ErrorCodeEnum RegisterRxPkt(int id, SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx)
+	ErrorCodeEnum CBizChannelEntity::RegisterRxPkt(int id, SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx)
 	{
 		rxpkt_entry *pos;
 		ListEntry_ForEach(pos, &m_rxpktList, rxpkt_entry, entry) 
@@ -276,7 +221,7 @@ public:
 		return Error_Succeed;
 	}
 
-	void UnregisterState(int id)
+	void CBizChannelEntity::UnregisterState(int id)
 	{
 		state_entry *pos,*n;
 		ListEntry_ForEachSafe(pos,n, &m_stateList, state_entry, entry) {
@@ -287,7 +232,7 @@ public:
 		}
 	}
 
-	void UnregisterRxpkt(int id)
+	void CBizChannelEntity::UnregisterRxpkt(int id)
 	{
 		rxpkt_entry *pos,*n;
 		//ListEntry_ForEach(pos, &m_rxpktList, rxpkt_entry, entry) 
@@ -302,7 +247,7 @@ public:
 		}
 	}
 
-	ErrorCodeEnum Send(int type, bool compress, bool encrypt, int sub_type, int id, CBlob &data)
+	ErrorCodeEnum CBizChannelEntity::Send(int type, bool compress, bool encrypt, int sub_type, int id, CBlob &data)
 	{
 		if (m_eState == eChannelState_Connected) {
 			LOG_TRACE("tx pkt, %d bytes, type = %d, compress = %d, encrypt = %d, sub_type = %d, id = %d, hash=%d", data.m_iLength, type, !!compress, !!encrypt, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
@@ -316,40 +261,7 @@ public:
 		}
 	}
 
-private:
-	struct NotifyOnClose : public ITaskSp
-	{
-		CBizChannelEntity *m_pEntity;
-		virtual void Process()
-		{
-			m_pEntity->on_close();
-		}
-	};
-	struct NotifyOnRecvPkt : public ITaskSp
-	{
-		CBizChannelEntity *m_pEntity;
-		int type;
-		int sub_type;
-		int id;
-		CBlob data;
-		virtual void Process()
-		{
-			m_pEntity->on_recv_pkt(type, sub_type, id, data);
-		}
-	};
-	struct NotifyOnConnect : public ITaskSp
-	{
-		CBizChannelEntity *m_pEntity;
-		int error;
-		CSimpleStringA remote_rtp_ip;
-		int remote_video_port;
-		int remote_video_desc;
-		virtual void Process()
-		{
-			m_pEntity->on_connect(error, (LPCSTR)remote_rtp_ip, remote_video_port, remote_video_desc);
-		}
-	};
-	void ChangeState(int new_state, const char *param = NULL)
+	void CBizChannelEntity::ChangeState(int new_state, const char *param)
 	{
 		if (m_eState != new_state) {
 			LOG_TRACE("change state from %s to %s", state2str(m_eState), state2str(new_state));
@@ -368,7 +280,7 @@ private:
 	}
 
 	//void on_recv_pkt(int type, int sub_type, const char *pkt, int pkt_size)
-	void on_recv_pkt(int type, int sub_type, int id, CBlob &data)
+	void CBizChannelEntity::on_recv_pkt(int type, int sub_type, int id, CBlob &data)
 	{
 		LOG_TRACE("rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", data.m_iLength, type, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
 		Dbg("rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", data.m_iLength, type, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
@@ -389,7 +301,7 @@ private:
 			}
 		}
 	}
-	void on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc)
+	void CBizChannelEntity::on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc)
 	{
 		if (!error) {
 			if (m_eState == eChannelState_Connecting) {
@@ -460,7 +372,7 @@ private:
 			ChangeState(eChannelState_Idle);
 		}
 	}
-	void on_close()
+	void CBizChannelEntity::on_close()
 	{
 		if (m_pChan) {
 			bizchan_close(m_pChan);
@@ -469,7 +381,7 @@ private:
 		}
 		ChangeState(eChannelState_Idle);
 	}
-	void _on_recv_pkt(int type, int sub_type, int id, const char *pkt, int pkt_size)
+	void CBizChannelEntity::_on_recv_pkt(int type, int sub_type, int id, const char *pkt, int pkt_size)
 	{
 		LOG_TRACE("_on rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", pkt_size, type, sub_type, id, hash32_buf(pkt, pkt_size, 0));
 		NotifyOnRecvPkt *task = new NotifyOnRecvPkt();
@@ -488,7 +400,7 @@ private:
 		}
 		GetFunction()->PostEntityTaskFIFO(task);
 	}
-	void _on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc)
+	void CBizChannelEntity::_on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc)
 	{
 		NotifyOnConnect *task = new NotifyOnConnect();
 		task->m_pEntity = this;
@@ -498,51 +410,14 @@ private:
 		task->remote_video_desc = remote_video_desc;
 		GetFunction()->PostEntityTaskFIFO(task);
 	}
-	void _on_close()
+
+	void CBizChannelEntity::_on_close()
 	{
-		NotifyOnClose *task = new NotifyOnClose();
+		NotifyOnClose * task = new NotifyOnClose();
 		task->m_pEntity = this;
 		GetFunction()->PostEntityTaskFIFO(task);
 	}
-	static void __on_recv_pkt(bizchan_t *chan, int type, int sub_type, int id, const char *pkt, int pkt_size, void *user_data)
-	{
-		CBizChannelEntity *pThis = static_cast<CBizChannelEntity *>(user_data);
-		pThis->_on_recv_pkt(type, sub_type, id, pkt, pkt_size);
-	}
-	static void __on_connect(bizchan_t *chan, int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc, const char *remote_client_id, void *user_data)
-	{
-		CBizChannelEntity *pThis = static_cast<CBizChannelEntity *>(user_data);
-		pThis->_on_connect(error, remote_ip, remote_video_rtp, remote_video_desc);
-	}
-	static void __on_close(bizchan_t *chan, void *user_data)
-	{
-		CBizChannelEntity *pThis = static_cast<CBizChannelEntity *>(user_data);
-		pThis->_on_close();
-	}
-	static void __on_destroy(bizchan_t *chan, void *user_data)
-	{
-	}
 
-private:
-	DeviceTypeEnum m_eDeviceType;
-	int m_eState;
-	bizchan_t *m_pChan;
-	int m_id_seq;
-	struct state_entry
-	{
-		LIST_ENTRY entry;
-		int id;
-		SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx;
-	};
-	LIST_ENTRY m_stateList;
-	struct rxpkt_entry
-	{
-		LIST_ENTRY entry;
-		int id;
-		SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx;
-	};
-	LIST_ENTRY m_rxpktList;
-};
 
 void ChannelServiceSession::Handle_Connect( SpReqAnsContext<ChannelService_Connect_Req, ChannelService_Connect_Ans>::Pointer ctx )
 {

+ 171 - 0
Module/mod_assistantchannel/mod_assistantchannel.h

@@ -0,0 +1,171 @@
+#ifndef RVC_MOD_ASSISTANTCHANNEL_H__
+#define RVC_MOD_ASSISTANTCHANNEL_H__
+
+#include "SpBase.h"
+#include "SpTest.h"
+#include "modVer.h"
+
+#include "Common/ListEntry.h"
+#include "mod_counterconnector/CallType.h"
+#include "bizchan.h"
+#include "EventCode.h"
+
+#include "AssistantChannel_server_g.h"
+using namespace AssistantChannel;
+
+class CBizChannelEntity : public CEntityBase
+{
+public:
+	CBizChannelEntity() : m_id_seq(0) {}
+	virtual ~CBizChannelEntity() {}
+	virtual const char* GetEntityName() const { return "AssistantChannel"; }
+	const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
+	virtual bool IsService()const { return true; }
+
+	ON_ENTITYT_TEST()
+
+	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
+	{
+		ErrorCodeEnum Error = __OnStart(Error_Succeed);
+		pTransactionContext->SendAnswer(Error);
+	}
+
+	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
+	{
+		ErrorCodeEnum Error = __OnClose(Error_Succeed);
+		pTransactionContext->SendAnswer(Error);
+	}
+
+	ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError);
+
+	ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
+
+	virtual CServerSessionBase* OnNewSession(const char* pszRemoteEntityName, const char* pszClass);
+
+	ErrorCodeEnum Connect(const char* ip, int port, const char* callno, CallingTypeEnum eType);
+	ErrorCodeEnum Close();
+
+	int GetState() { return m_eState; }
+
+	ErrorCodeEnum RegisterState(int id, SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx);
+
+	ErrorCodeEnum RegisterRxPkt(int id, SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx);
+
+	void UnregisterState(int id);
+
+	void UnregisterRxpkt(int id);
+
+	ErrorCodeEnum Send(int type, bool compress, bool encrypt, int sub_type, int id, CBlob& data);
+
+private:
+	struct NotifyOnClose : public ITaskSp
+	{
+		CBizChannelEntity* m_pEntity;
+		virtual void Process()
+		{
+			m_pEntity->on_close();
+		}
+	};
+	struct NotifyOnRecvPkt : public ITaskSp
+	{
+		CBizChannelEntity* m_pEntity;
+		int type;
+		int sub_type;
+		int id;
+		CBlob data;
+		virtual void Process()
+		{
+			m_pEntity->on_recv_pkt(type, sub_type, id, data);
+		}
+	};
+	struct NotifyOnConnect : public ITaskSp
+	{
+		CBizChannelEntity* m_pEntity;
+		int error;
+		CSimpleStringA remote_rtp_ip;
+		int remote_video_port;
+		int remote_video_desc;
+		virtual void Process()
+		{
+			m_pEntity->on_connect(error, (LPCSTR)remote_rtp_ip, remote_video_port, remote_video_desc);
+		}
+	};
+	void ChangeState(int new_state, const char* param = NULL);
+	void on_recv_pkt(int type, int sub_type, int id, CBlob& data);
+	void on_connect(int error, const char* remote_ip, int remote_video_rtp, int remote_video_desc);
+	void on_close();
+	void _on_recv_pkt(int type, int sub_type, int id, const char* pkt, int pkt_size);
+	void _on_connect(int error, const char* remote_ip, int remote_video_rtp, int remote_video_desc);
+	void _on_close();
+	static void __on_recv_pkt(bizchan_t* chan, int type, int sub_type, int id, const char* pkt, int pkt_size, void* user_data)
+	{
+		CBizChannelEntity* pThis = static_cast<CBizChannelEntity*>(user_data);
+		pThis->_on_recv_pkt(type, sub_type, id, pkt, pkt_size);
+	}
+	static void __on_connect(bizchan_t* chan, int error, const char* remote_ip, int remote_video_rtp, int remote_video_desc, const char* remote_client_id, void* user_data)
+	{
+		CBizChannelEntity* pThis = static_cast<CBizChannelEntity*>(user_data);
+		pThis->_on_connect(error, remote_ip, remote_video_rtp, remote_video_desc);
+	}
+	static void __on_close(bizchan_t* chan, void* user_data)
+	{
+		CBizChannelEntity* pThis = static_cast<CBizChannelEntity*>(user_data);
+		pThis->_on_close();
+	}
+	static void __on_destroy(bizchan_t* chan, void* user_data)
+	{
+	}
+
+private:
+	DeviceTypeEnum m_eDeviceType;
+	int m_eState;
+	bizchan_t* m_pChan;
+	int m_id_seq;
+	struct state_entry
+	{
+		LIST_ENTRY entry;
+		int id;
+		SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx;
+	};
+	LIST_ENTRY m_stateList;
+	struct rxpkt_entry
+	{
+		LIST_ENTRY entry;
+		int id;
+		SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx;
+	};
+	LIST_ENTRY m_rxpktList;
+};
+
+
+class ChannelServiceSession : public ChannelService_ServerSessionBase
+{
+public:
+	ChannelServiceSession(CBizChannelEntity* pEntity, int id) : m_pEntity(pEntity), m_id(id) {}
+
+	virtual void Handle_Connect(SpReqAnsContext<ChannelService_Connect_Req, ChannelService_Connect_Ans>::Pointer ctx);
+
+	virtual void Handle_Close(SpReqAnsContext<ChannelService_Close_Req, ChannelService_Close_Ans>::Pointer ctx);
+
+	virtual void Handle_GetState(SpReqAnsContext<ChannelService_GetState_Req, ChannelService_GetState_Ans>::Pointer ctx);
+
+	virtual void Handle_BeginState(SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx);
+
+	virtual void Handle_EndState(SpOnewayCallContext<ChannelService_EndState_Info>::Pointer ctx);
+
+	virtual void Handle_Send(SpOnewayCallContext<ChannelService_Send_Info>::Pointer ctx);
+
+	virtual void Handle_BeginRecv(SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx);
+
+	virtual void Handle_EndRecv(SpOnewayCallContext<ChannelService_EndRecv_Info>::Pointer ctx);
+
+	virtual void OnClose(ErrorCodeEnum eErrorCode);
+
+private:
+	int m_id;
+	CBizChannelEntity* m_pEntity;
+};
+
+
+
+#endif /*RVC_MOD_ASSISTANTCHANNEL_H__*/

+ 53 - 0
Module/mod_assistantchannel/test/testAssistantChannelEntity.cpp

@@ -0,0 +1,53 @@
+
+#include "mod_assistantchannel.h"
+
+
+
+TEST_CASE_ENTITY_CLASS(CBizChannelEntity, "__OnStart")
+{
+	LOG_FUNCTION();
+	ErrorCodeEnum Error = __OnStart(Error_Succeed);
+	if (Error == Error_Succeed) {
+		Dbg("__OnStart is success");
+	}
+	return Error;
+}
+
+TEST_CASE_ENTITY_CLASS(CBizChannelEntity, "__OnClose")
+{
+	LOG_FUNCTION();
+	ErrorCodeEnum Error = __OnClose(Error_Succeed);
+	if (Error == Error_Succeed) {
+		Dbg("__OnClose is success");
+	}
+	return Error;
+}
+
+
+TEST_CASE_ENTITY_CLASS(CBizChannelEntity, "Connect")
+{
+	LOG_FUNCTION();
+
+	ErrorCodeEnum Error = Connect("99.1.100.227", 2334, "07550001",NORMAL_CALLTYPE);
+	if (Error == Error_Succeed) {
+		Dbg("Connect is success");
+	}
+	Error = Close();
+	if (Error == Error_Succeed) {
+		Dbg("Close is success");
+	}
+	return Error;
+}
+
+/*
+TEST_CASE_ENTITY_CLASS(CBizChannelEntity, "Send")
+{
+	LOG_FUNCTION();
+
+	ErrorCodeEnum Error = Send();
+	if (Error == Error_Succeed) {
+		Dbg("Send is success");
+	}
+	return Error;
+}
+*/