| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #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<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- pTransactionContext->SendAnswer(_onTest());
- }
- void OnStarted()
- {
- LOG_FUNCTION();
- }
- void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> 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<IAsynWaitSp> 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<IEntityFunctionPrivilege> privilegeFunc2 = GetFunction().ConvertCase<IEntityFunctionPrivilege>();
- 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()
|