| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- #ifndef __MOD_SAMPLEENTITY_H__
- #define __MOD_SAMPLEENTITY_H__
- #pragma once
- // This code is generated by spgenex tool!
- #include "SampleEntity_server_g.h"
- #include "SampleFSM.h"
- #include "SpTest.h"
- using namespace SampleEntity;
- class CSampleEntity : public CEntityBase, public ITestCaseSuite<CSampleEntity>
- {
- public:
- CSampleEntity(){}
- virtual ~CSampleEntity(){}
- virtual const char *GetEntityName() const { return "SampleEntity"; }
- virtual bool IsService() const { return true; }
- virtual bool IsMultiThread() const { return true; }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum ec = Error_Succeed;
- if(m_sampleFsm.Init(this) != 0) {
- ec = Error_InvalidState;
- }
- AddTestCaseEntry(&CSampleEntity::TestTwoWayFuncNormal);
- pTransactionContext->SendAnswer(ec);
- }
- virtual void OnStarted() override
- {
- CSimpleStringA strValue;
- CHECK(Error_NotExist == GetFunction()->GetSysVar("NoExistSysValue", strValue));
- IFFAILBREAK(GetFunction()->GetSysVar("SampleState", strValue));
- CHECK_FALSE(strValue.IsNullOrEmpty());
- /*set sys val*/
- Dbg("Update sysVal...");
- strValue = strValue.Compare("1") == 0 ? "0" : "1";
- IFFAILBREAK(GetFunction()->SetSysVar("SampleState", strValue, true));
- CSimpleStringA strNewValue;
- IFFAILBREAK(GetFunction()->GetSysVar("SampleState", strNewValue));
- CHECK(strValue.Compare(strNewValue) == 0);
- Dbg("Update sysVal again...");
- strValue = strValue.Compare("1") == 0 ? "0" : "1";
- IFFAILBREAK(GetFunction()->SetSysVar("SampleState", strValue));
- IFFAILBREAK(GetFunction()->GetSysVar("SampleState", strNewValue));
- CHECK(strValue.Compare(strNewValue) == 0);
- //depecrate: assert would happen!
- //IFFAILBREAK(GetFunction()->SetSysVar("SampleState", NULL)); //would clear the sys val value.
- Dbg("test some illegal action.");
- CHECK(Error_NotExist == GetFunction()->SetSysVar("NoExistSysValue", "1", true));
- CHECK(Error_NotExist == GetFunction()->SetSysVar("NoExistSysValue", "1"));
- CHECK(Error_Null == GetFunction()->SetSysVar(NULL, "1", true));
- CHECK(Error_Null == GetFunction()->SetSysVar(NULL, "1"));
- CHECK(Error_NoPrivilege == GetFunction()->SetSysVar("PrivilegeState", "1", true));
- CHECK(Error_NoPrivilege == GetFunction()->SetSysVar("PrivilegeState", "1"));
- TestCaseDemo();
- }
- void TestCaseDemo()
- {
- /** simple test way, user declare and implement the test method*/
- AddTestCaseEntry(&CSampleEntity::TestTwoWayFuncWithID);
- /** this is meanless usage way beacause we cannot set req member*/
- AddTestMethodEntry(
- new MethodTestCaseT<SampleService_TwoWayFuncNotOverlap_Req, SampleService_TwoWayFuncNotOverlap_Ans>(
- this,
- &CSampleEntity::TwoWayFuncNotOverlap));
- /** but we can change it like this.*/
- auto methdTest1 = new MethodTestCaseT<SampleService_TwoWayFuncNotOverlap_Req, SampleService_TwoWayFuncNotOverlap_Ans>(
- this,
- &CSampleEntity::TwoWayFuncNotOverlap);
- methdTest1->Req.req_context = "I'am Test";
- AddTestMethodEntry(methdTest1);
- /** but still, we cannot check the Ans member's validity, only one thing what we can do is
- just checking the aim furncion returned 'ErrorCodeEnum' type value*/
- /** last but not lease, we can inherit MethodTestCaseT and override PreTest(to set Req) and PostTest(to check Ans)*/
- struct TwoWayFuncOverlapTestCase :
- public MethodTestCaseT<SampleService_TwoWayFuncOverlap_Req, SampleService_TwoWayFuncOverlap_Ans>
- {
- TwoWayFuncOverlapTestCase(CEntityBase* ent, ToTestFuncProto testFunc) :MethodTestCaseT(ent, testFunc) {}
- void PreTest()
- {
- LOG_FUNCTION();
- Req.req_context = "hello";
- }
- ErrorCodeEnum PostTest()
- {
- LOG_FUNCTION();
- if (Ans.ans_context.Compare("world", true) != 0) {
- LOG_TRACE("Check failed, return except Error_Succeed");
- return Error_Unexpect;
- }
- return Error_Succeed;
- }
- };
- AddTestMethodEntry(new TwoWayFuncOverlapTestCase(this, &CSampleEntity::TwoWayFuncOverlap));
- }
- TESTCASE_OVERRIDE_ON_EXAM_AND_IMPLEMENT()
- ErrorCodeEnum CustomTestCase() override
- {
- LOG_FUNCTION();
- /** User add any other test logical*/
- return Error_Succeed;
- }
- ErrorCodeEnum OnewayFuncOverlap(
- SpOnewayCallContext<SampleService_OnewayFuncOverlap_Info>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_Unexpect;
- // TODO: user should implement the function!
- return ec;
- }
- ErrorCodeEnum OnewayFuncNoOverlap(
- SpOnewayCallContext<SampleService_OnewayFuncNoOverlap_Info>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_Unexpect;
- // TODO: user should implement the function!
- return ec;
- }
- ErrorCodeEnum OnewayFuncNormal(
- SpOnewayCallContext<SampleService_OnewayFuncNormal_Info>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_Unexpect;
- // TODO: user should implement the function!
- return ec;
- }
- ErrorCodeEnum TwoWayFuncOverlap(
- SpReqAnsContext<SampleService_TwoWayFuncOverlap_Req, SampleService_TwoWayFuncOverlap_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ErrorCodeEnum ec = Error_Succeed;
- // TODO:
- ctx->Ans.ans_context = "World";
- ctx->Answer();
- return ec;
- }
- ErrorCodeEnum TwoWayFuncNotOverlap(
- SpReqAnsContext<SampleService_TwoWayFuncNotOverlap_Req, SampleService_TwoWayFuncNotOverlap_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ErrorCodeEnum ec = Error_Succeed;
- ctx->Answer(Error_Succeed);
- return ec;
- }
- ErrorCodeEnum TwoWayFuncWithID(
- SpReqAnsContext<SampleService_TwoWayFuncWithID_Req, SampleService_TwoWayFuncWithID_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ErrorCodeEnum ec = Error_Succeed;
- // TODO:
- //ctx->Answer(Error_Unexpect, Error_Unexpect);
- return ec;
- }
- ErrorCodeEnum TwoWayFuncNormal(
- SpReqAnsContext<SampleService_TwoWayFuncNormal_Req, SampleService_TwoWayFuncNormal_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ErrorCodeEnum ec = Error_Succeed;
- ctx->Answer(Error_Succeed);
- return ec;
- }
- ErrorCodeEnum SubscribeOverlap(
- SpSubscribeContext<SampleService_SubscribeOverlap_Sub, SampleService_SubscribeOverlap_Message_Info>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_NotImpl;
- // TODO:
- return ec;
- }
- ErrorCodeEnum SubscribeOverlap_Cancel(
- SpOnewayCallContext<SampleService_SubscribeOverlap_Cancel_Info>::Pointer ctx)
- {
- ErrorCodeEnum ec = Error_NotImpl;
- // TODO:
- return ec;
- }
- ///////////////////////////
- void TestTwoWayFuncNormal(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- SpReqAnsContext< SampleService_TwoWayFuncNormal_Req, SampleService_TwoWayFuncNormal_Ans>::Pointer ctx =
- new SpReqAnsContext< SampleService_TwoWayFuncNormal_Req, SampleService_TwoWayFuncNormal_Ans>(pTransactionContext);
- /** Set ctx->Req*/
- /*The aim function you would like test.*/
- if (Error_Succeed == TwoWayFuncNormal(ctx))
- {
- /** Check ctx->Ans*/
- /** Overwite the Result using pTransactionContext->SendAnswer()*/
- }
- }
- void TestTwoWayFuncWithID(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- SpReqAnsContext< SampleService_TwoWayFuncWithID_Req, SampleService_TwoWayFuncWithID_Ans>::Pointer ctx =
- new SpReqAnsContext< SampleService_TwoWayFuncWithID_Req, SampleService_TwoWayFuncWithID_Ans>(pTransactionContext);
- TwoWayFuncWithID(ctx);
- }
- //TESTCASE_DECLARE_BEGIN(SampleService, TwoWayFuncOverlap);
- //ctx->Req.req_context = "hello";
- //TESTCASE_DECLARE_INVOKE(TwoWayFuncOverlap);
- //TESTCASE_DECLARE_END(TwoWayFuncOverlap);
- private:
- CSampleFSM m_sampleFsm;
- };
- class CSampleServiceSession : public SampleService_ServerSessionBase
- {
- public:
- CSampleServiceSession(CSampleEntity *pEntity) : m_pEntity(pEntity) {}
- virtual ~CSampleServiceSession() {}
- virtual void Handle_OnewayFuncOverlap(
- SpOnewayCallContext<SampleService_OnewayFuncOverlap_Info>::Pointer ctx)
- {
- auto rc = m_pEntity->OnewayFuncOverlap(ctx);
- }
- virtual void Handle_OnewayFuncNoOverlap(
- SpOnewayCallContext<SampleService_OnewayFuncNoOverlap_Info>::Pointer ctx)
- {
- auto rc = m_pEntity->OnewayFuncNoOverlap(ctx);
- }
- virtual void Handle_OnewayFuncNormal(
- SpOnewayCallContext<SampleService_OnewayFuncNormal_Info>::Pointer ctx)
- {
- auto rc = m_pEntity->OnewayFuncNormal(ctx);
- }
- virtual void Handle_TwoWayFuncOverlap(
- SpReqAnsContext<SampleService_TwoWayFuncOverlap_Req, SampleService_TwoWayFuncOverlap_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->TwoWayFuncOverlap(ctx);
- ctx->Answer(rc);
- }
- virtual void Handle_TwoWayFuncNotOverlap(
- SpReqAnsContext<SampleService_TwoWayFuncNotOverlap_Req, SampleService_TwoWayFuncNotOverlap_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->TwoWayFuncNotOverlap(ctx);
- ctx->Answer(rc);
- }
- virtual void Handle_TwoWayFuncWithID(
- SpReqAnsContext<SampleService_TwoWayFuncWithID_Req, SampleService_TwoWayFuncWithID_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->TwoWayFuncWithID(ctx);
- ctx->Answer(rc);
- }
- virtual void Handle_TwoWayFuncNormal(
- SpReqAnsContext<SampleService_TwoWayFuncNormal_Req, SampleService_TwoWayFuncNormal_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->TwoWayFuncNormal(ctx);
- ctx->Answer(rc);
- }
- virtual void Handle_SubscribeOverlap(
- SpSubscribeContext<SampleService_SubscribeOverlap_Sub, SampleService_SubscribeOverlap_Message_Info>::Pointer ctx)
- {
- auto rc = m_pEntity->SubscribeOverlap(ctx);
- }
- virtual void Handle_SubscribeOverlap_Cancel(
- SpOnewayCallContext<SampleService_SubscribeOverlap_Cancel_Info>::Pointer ctx)
- {
- auto rc = m_pEntity->SubscribeOverlap_Cancel(ctx);
- }
- private:
- CSampleEntity *m_pEntity;
- };
- ///////////////////////////
- #endif // __MOD_SAMPLEENTITY_H__
|