Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <mitkStateMachineFactory.h>
00020 #include <mitkState.h>
00021 #include "mitkTestingMacros.h"
00022 #include <mitkStandardFileLocations.h>
00023 #include <mitkInteractionConst.h>
00024 int mitkStateMachineFactoryTest(int , char* [])
00025 {
00026 MITK_TEST_BEGIN("StateMachineFactory")
00027
00028 mitk::StateMachineFactory* statemachineFactory = mitk::StateMachineFactory::New();
00029
00030
00031 MITK_TEST_CONDITION_REQUIRED(statemachineFactory->LoadStandardBehavior(),"Testing LoadStandardBehavior(): ")
00032
00033
00034 mitk::State::Pointer state = statemachineFactory->GetStartState("global");
00035 MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing GetStartState() of GlobalInteraction state machine pattern: ")
00036
00037 std::string xmlFileName1( mitk::StandardFileLocations::GetInstance()->FindFile("TestStateMachine1.xml", "Core/Code/Testing/Data") );
00038 MITK_TEST_CONDITION_REQUIRED(!xmlFileName1.empty(),"Getting xml file 1: ")
00039 MITK_TEST_CONDITION_REQUIRED(statemachineFactory->LoadBehavior(xmlFileName1),"Parsing xml file 1: ")
00040 state = statemachineFactory->GetStartState("test1");
00041 MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing GetStartState() of test1 state machine pattern: ")
00042
00043
00044 state = statemachineFactory->GetStartState("global");
00045 MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if previous loaded state machine patterns are still accessible: ")
00046
00047 std::string xmlFileName2( mitk::StandardFileLocations::GetInstance()->FindFile("TestStateMachine2.xml", "Core/Code/Testing/Data") );
00048 MITK_TEST_CONDITION_REQUIRED(!xmlFileName2.empty(),"Getting xml file 2: ")
00049 MITK_TEST_CONDITION_REQUIRED(statemachineFactory->LoadBehavior(xmlFileName2),"Parsing xml file 2. Schould throw a fatal error due to already existing pattern name: ")
00050 state = statemachineFactory->GetStartState("test4");
00051 MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing GetStartState() of test4 state machine pattern: ")
00052
00053 state = statemachineFactory->GetStartState("global");
00054 MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if previous loaded state machine pattern (global) is still accessible: ")
00055 state = statemachineFactory->GetStartState("test1");
00056 MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if previous loaded state machine pattern (test1) is still accessible: ")
00057
00058
00059
00060 std::string patternName("manuallyCreatedStateMachine");
00061 mitk::StateMachineFactory::StateMachineMapType* allStatesMap = new mitk::StateMachineFactory::StateMachineMapType();
00062
00063 mitk::State::Pointer state1 = mitk::State::New("firstState", 1);
00064 mitk::Transition* transition1 = new mitk::Transition("goto2", 2, mitk::EIDNULLEVENT);
00065 mitk::Action::Pointer action1 = mitk::Action::New(mitk::AcDONOTHING);
00066 transition1->AddAction(action1);
00067 state1->AddTransition(transition1);
00068 allStatesMap->insert(mitk::StateMachineFactory::StateMachineMapType::value_type(state1->GetId(), state1));
00069
00070 mitk::State::Pointer state2 = mitk::State::New("secondState", 2);
00071 transition1->SetNextState(state2);
00072 mitk::Transition* transition2 = new mitk::Transition("goto1", 1, mitk::EIDNULLEVENT);
00073 mitk::Action::Pointer action2 = mitk::Action::New(mitk::AcDONOTHING);
00074 transition2->AddAction(action2);
00075 transition2->SetNextState(state1);
00076 state2->AddTransition(transition2);
00077 allStatesMap->insert(mitk::StateMachineFactory::StateMachineMapType::value_type(state2->GetId(), state2));
00078
00079
00080 statemachineFactory->AddStateMachinePattern(patternName.c_str(), state1, allStatesMap);
00081
00082
00083 state = statemachineFactory->GetStartState("global");
00084 MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if previous loaded state machine pattern (global) is still accessible: ")
00085 state = statemachineFactory->GetStartState("test1");
00086 MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if previous loaded state machine pattern (test1) is still accessible: ")
00087 state = statemachineFactory->GetStartState(patternName.c_str());
00088 MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if manually created and added state machine pattern is accessible: ")
00089
00090 statemachineFactory->Delete();
00091
00092
00093
00094 MITK_TEST_END();
00095 }