コード例 #1
0
ファイル: TaskTest.cpp プロジェクト: JeffreyZksun/pcassist
TEST(TaskTest, ConditionalTaskExecute)
{
	ITaskSystemPtr pTaskSystem (new TaskSystem());
	Ts::ITaskManagerPtr pTaskMgr = pTaskSystem->GetTaskManager();

	EXPECT_EQ(true, pTaskMgr != NULL);

	{
		BehaviorManager* pBehaviorManager = pTaskSystem->GetBehaviorManager();

		WString actionName = _T("demoAction");
		ActionPtr pNewAction = Action::Create(_T("EmptyAction"), pBehaviorManager);
		pNewAction->GetParameterTable().AddParameter(Parameter(OBJECT_ID, actionName.data()));

		WString conditionName (_T("TrueCondition"));
		ConditionPtr pNewCondtion = Condition::Create(_T("TrueCondition"), pBehaviorManager);
		pNewCondtion->GetParameterTable().AddParameter(Parameter(OBJECT_ID, conditionName.data()));
		
		ImmediateTask::pointer pImmeTask (ImmediateTask::Create(_T("basicTask")));
		pImmeTask->AppendAction(actionName);
		pTaskMgr->RegisterTask(pImmeTask);

		ConditionalTask::pointer pTask (ConditionalTask::Create(_T("conditionTask"), conditionName, pImmeTask->GetObjectId()));

		const bool ok = pTask->Execute(pTaskSystem.get());
		EXPECT_EQ(true, ok);
	}
}
コード例 #2
0
TEST(SaveLoadTest, SaveLoadLatestVersion)
{
    // Use the temp application.
    TaskSystem *pTempApp1 = new TaskSystem();
    TaskSystem* pPreviousApp = SetWorkingBrain(pTempApp1);

    {
        Parameter para(_T("OS"), _T("Windows7"));
        para.SetComments(_T("global"));
        GetWorkingBrain()->GetVariableManager()->AddUserParameter(para);
    }

    CString conditionId = _T("DoesRegExist");
    {
        ConditionPtr pRegCondition = Condition::Create(_T("RegisterKeyExistsCondition"), GetWorkingBrain()->GetBehaviorManager());
        Parameter objectId(OBJECT_ID, conditionId);
        Parameter para1(_T("RootKey"), _T("HKEY_LOCAL_MACHINE"));
        Parameter para2(_T("SubKey"), _T("Software\\Microsoft"));

        pRegCondition->GetParameterTable().AddParameter(objectId);
        pRegCondition->GetParameterTable().AddParameter(para1);
        pRegCondition->GetParameterTable().AddParameter(para2);

        //GetWorkingBrain()->GetBehaviorManager()->RegisterCondition(pRegCondition);
    }

    CString actionId = _T("DemoToRunSysCmd");
    {
        ActionPtr pNewAction = Action::Create(_T("RunSystemCommandAction"), GetWorkingBrain()->GetBehaviorManager());
        Parameter objectId(OBJECT_ID, actionId);
        objectId.SetComments(_T("Object Id is used to reference this object everywhere."));
        Parameter objectType;
        pNewAction->GetParameterTable().GetParameter(OBJECT_TYPE, objectType);
        objectType.SetComments(_T("Object type indicates which behavior body will this action invokes."));
        Parameter cmd(APPLICATION_NAME, _T("regedit.exe"));
        cmd.SetComments(_T("Indicate which command will be run"));
        pNewAction->GetParameterTable().AddParameter(objectId);
        pNewAction->GetParameterTable().AddParameter(objectType);
        pNewAction->GetParameterTable().AddParameter(cmd);

        //GetWorkingBrain()->GetBehaviorManager()->RegisterAction(pNewAction);
        GetWorkingBrain()->GetBehaviorManager()->AddActionTask(pNewAction);
    }

    CString fileName(_T("C:\\braintest.xml"));

    // Save
    bool ret = GetWorkingBrain()->XmlOut(fileName);
    EXPECT_EQ(true, ret);

    // Load
    TaskSystem *pTempApp2 = new TaskSystem();

    SetWorkingBrain(pTempApp2);

    ret = GetWorkingBrain()->XmlIn(fileName);
    EXPECT_EQ(true, ret);

    {
        ActionPtr pAction = GetWorkingBrain()->GetBehaviorManager()->GetActionById(actionId);
        EXPECT_EQ(true, (pAction != NULL));
    }

    {
        ConditionPtr pCondition = GetWorkingBrain()->GetBehaviorManager()->GetConditionById(conditionId);
        EXPECT_EQ(true, (pCondition != NULL));
    }

    // Recover
    SetWorkingBrain(pPreviousApp);
}