#include "stdafx.h" #include "SpBase.h" #include "SpTest.h" #include "modVer.h" const char* CHILD_TEST_ENTITY_NAME = "TestPassiveEntity"; class CPrivilegeEntityTest : public CEntityBase { public: CPrivilegeEntityTest(){} virtual ~CPrivilegeEntityTest() {} virtual const char *GetEntityName() const { return "TestPrivilegeEntity"; } const char* GetEntityVersion() const { return MODULE_VERSION_FULL; } virtual void OnPreStart(CAutoArray strArgs, CSmartPointer pTransactionContext) { LOG_FUNCTION(); pTransactionContext->SendAnswer(_onTest()); } void OnStarted() { LOG_FUNCTION(); } void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer pTransactionContext) { LOG_FUNCTION(); pTransactionContext->SendAnswer(Error_Succeed); } private: ErrorCodeEnum _onTest(); }; ErrorCodeEnum CPrivilegeEntityTest::_onTest() { #if 1 REQUIRE(GetFunction()->HasPrivilege()); auto privilegeFunc = GetFunction()->GetPrivilegeFunction(); REQUIRE(privilegeFunc != NULL); CSmartPointer spWait; REQUIRE(Error_Null == privilegeFunc->PauseEntity(NULL, spWait)); REQUIRE(Error_Param == privilegeFunc->PauseEntity("", spWait)); REQUIRE(Error_NotExist == privilegeFunc->PauseEntity("NoExistedEntity", spWait)); Dbg("Try to start %s entity", CHILD_TEST_ENTITY_NAME); IFFAILRET(privilegeFunc->StartEntity(CHILD_TEST_ENTITY_NAME, "param1 2 \"I am a bank\" -mode test", spWait)); REQUIRE(spWait != NULL); IFFAILRET(spWait->WaitAnswer(10000)); //start other brother entity. Dbg("Try to start TestPassiveSecondEntity entity"); spWait = NULL; IFFAILRET(privilegeFunc->StartEntity("TestPassiveSecondEntity", NULL, spWait)); REQUIRE(spWait != NULL); IFFAILRET(spWait->WaitAnswer(10000)); Dbg("Try to start TestPassiveThirdEntity entity"); spWait = NULL; IFFAILRET(privilegeFunc->StartEntity("TestPassiveThirdEntity", NULL, spWait)); REQUIRE(spWait != NULL); IFFAILRET(spWait->WaitAnswer(10000)); //pause entity. spWait = NULL; IFFAILRET(privilegeFunc->PauseEntity(CHILD_TEST_ENTITY_NAME, spWait)); REQUIRE(spWait != NULL); IFFAILRET(spWait->WaitAnswer(10000)); //pause the same entity again. spWait = NULL; //still send succ IFFAILRET(privilegeFunc->PauseEntity(CHILD_TEST_ENTITY_NAME, spWait)); REQUIRE(spWait != NULL); REQUIRE(Error_InvalidState == spWait->WaitAnswer(10000)); //continue entity. spWait = NULL; IFFAILRET(privilegeFunc->ContinueEntity(CHILD_TEST_ENTITY_NAME, spWait)); REQUIRE(spWait != NULL); IFFAILRET(spWait->WaitAnswer(10000)); //continue the same entity again. spWait = NULL; REQUIRE(Error_Succeed == privilegeFunc->ContinueEntity(CHILD_TEST_ENTITY_NAME, spWait)); REQUIRE(spWait != NULL); REQUIRE(Error_InvalidState == spWait->WaitAnswer(10000)); //stop entity equals CloseEntity spWait = NULL; IFFAILRET(privilegeFunc->StopEntity(CHILD_TEST_ENTITY_NAME, spWait)); REQUIRE(spWait != NULL); IFFAILRET(spWait->WaitAnswer(10000)); //stop the same entity again. spWait = NULL; REQUIRE(Error_Succeed == privilegeFunc->StopEntity(CHILD_TEST_ENTITY_NAME, spWait)); REQUIRE(spWait != NULL); REQUIRE_FALSE(Error_Succeed == spWait->WaitAnswer(10000)); //start entity again. spWait = NULL; IFFAILRET(privilegeFunc->StartEntity(CHILD_TEST_ENTITY_NAME, "param1 2 \"I am a bank\" -mode test", spWait)); REQUIRE(spWait != NULL); IFFAILRET(spWait->WaitAnswer(10000)); //test entity in shakehand mode. spWait = NULL; IFFAILRET(privilegeFunc->TestEntity(CHILD_TEST_ENTITY_NAME, Test_ShakeHand, spWait)); REQUIRE(spWait != NULL); IFFAILRET(spWait->WaitAnswer(10000)); //test entity in examine mode. spWait = NULL; IFFAILRET(privilegeFunc->TestEntity(CHILD_TEST_ENTITY_NAME, Test_Examine, spWait)); REQUIRE(spWait != NULL); IFFAILRET(spWait->WaitAnswer(10000)); //test entity in reset mode. spWait = NULL; IFFAILRET(privilegeFunc->TestEntity(CHILD_TEST_ENTITY_NAME, Test_Reset, spWait)); REQUIRE(spWait != NULL); IFFAILRET(spWait->WaitAnswer(10000)); //terminate module. spWait = NULL; REQUIRE(Error_Succeed == privilegeFunc->TerminateEntity(CHILD_TEST_ENTITY_NAME, spWait)); REQUIRE(spWait != NULL); IFFAILRET(spWait->WaitAnswer(10000)); CSmartPointer privilegeFunc2 = GetFunction().ConvertCase(); REQUIRE(privilegeFunc2 != NULL); REQUIRE((uintptr_t)privilegeFunc2.GetRawPointer() == (uintptr_t)privilegeFunc.GetRawPointer()); #endif return Error_Succeed; } SP_BEGIN_ENTITY_MAP() SP_ENTITY(CPrivilegeEntityTest) SP_END_ENTITY_MAP()