diff --git a/Core/Code/Testing/CMakeLists.txt b/Core/Code/Testing/CMakeLists.txt index e14f65b25c..fd619d3bce 100644 --- a/Core/Code/Testing/CMakeLists.txt +++ b/Core/Code/Testing/CMakeLists.txt @@ -1,20 +1,23 @@ MITK_CREATE_MODULE_TESTS(LABELS MITK-Core) # MITK_INSTALL_TARGETS(EXECUTABLES MitkTestDriver) ADD_TEST(mitkPicFileReaderTest_emptyFile ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkPicFileReaderTest ${CMAKE_CURRENT_SOURCE_DIR}/Data/emptyFile.pic) SET_PROPERTY(TEST mitkPicFileReaderTest_emptyFile PROPERTY LABELS MITK-Core) ADD_TEST(mitkPicFileReaderTest_emptyGzipFile ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkPicFileReaderTest ${CMAKE_CURRENT_SOURCE_DIR}/Data/emptyFile.pic.gz) SET_PROPERTY(TEST mitkPicFileReaderTest_emptyGzipFile PROPERTY LABELS MITK-Core) ADD_TEST(mitkDICOMLocaleTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkDICOMLocaleTest ${MITK_DATA_DIR}/spacing-ok.dcm) SET_PROPERTY(TEST mitkDICOMLocaleTest PROPERTY LABELS MITK-Core) ADD_TEST(mitkEventMapperTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkEventMapperTest ${MITK_DATA_DIR}/TestStateMachine1.xml ${MITK_DATA_DIR}/TestStateMachine2.xml) SET_PROPERTY(TEST mitkEventMapperTest PROPERTY LABELS MITK-Core) ADD_TEST(mitkNodeDependentPointSetInteractorTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkNodeDependentPointSetInteractorTest ${MITK_DATA_DIR}/Pic3D.pic.gz ${MITK_DATA_DIR}/BallBinary30x30x30.pic.gz) SET_PROPERTY(TEST mitkNodeDependentPointSetInteractorTest PROPERTY LABELS MITK-Core) ADD_TEST(mitkDataStorageTest_US4DCyl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkDataStorageTest ${MITK_DATA_DIR}/US4DCyl.pic.gz) SET_PROPERTY(TEST mitkDataStorageTest_US4DCyl PROPERTY LABELS MITK-Core) + +ADD_TEST(mitkStateMachineFactoryTest_TestStateMachine1_2 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkStateMachineFactoryTest ${MITK_DATA_DIR}/TestStateMachine1.xml ${MITK_DATA_DIR}/TestStateMachine2.xml) +SET_PROPERTY(TEST mitkStateMachineFactoryTest_TestStateMachine1_2 PROPERTY LABELS MITK-Core) diff --git a/Core/Code/Testing/mitkStateMachineFactoryTest.cpp b/Core/Code/Testing/mitkStateMachineFactoryTest.cpp index 0f1c900190..d41be2b61f 100644 --- a/Core/Code/Testing/mitkStateMachineFactoryTest.cpp +++ b/Core/Code/Testing/mitkStateMachineFactoryTest.cpp @@ -1,95 +1,94 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include #include "mitkTestingMacros.h" -#include #include -int mitkStateMachineFactoryTest(int /*argc*/, char* /*argv*/[]) +int mitkStateMachineFactoryTest(int argc, char* argv[]) { MITK_TEST_BEGIN("StateMachineFactory") //create statemachinefactory mitk::StateMachineFactory* statemachineFactory = mitk::StateMachineFactory::New(); //load standard behavior MITK_TEST_CONDITION_REQUIRED(statemachineFactory->LoadStandardBehavior(),"Testing LoadStandardBehavior(): ") //get the first state of the statemachine "global" (mitkGlobalInteraction) mitk::State::Pointer state = statemachineFactory->GetStartState("global"); MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing GetStartState() of GlobalInteraction state machine pattern: ") - std::string xmlFileName1( mitk::StandardFileLocations::GetInstance()->FindFile("TestStateMachine1.xml", "Core/Code/Testing/Data") ); + std::string xmlFileName1 = argv[1]; MITK_TEST_CONDITION_REQUIRED(!xmlFileName1.empty(),"Getting xml file 1: ") MITK_TEST_CONDITION_REQUIRED(statemachineFactory->LoadBehavior(xmlFileName1),"Parsing xml file 1: ") state = statemachineFactory->GetStartState("test1"); MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing GetStartState() of test1 state machine pattern: ") //global still accessible? state = statemachineFactory->GetStartState("global"); MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if previous loaded state machine patterns are still accessible: ") - std::string xmlFileName2( mitk::StandardFileLocations::GetInstance()->FindFile("TestStateMachine2.xml", "Core/Code/Testing/Data") ); + std::string xmlFileName2 = argv[2]; MITK_TEST_CONDITION_REQUIRED(!xmlFileName2.empty(),"Getting xml file 2: ") MITK_TEST_CONDITION_REQUIRED(statemachineFactory->LoadBehavior(xmlFileName2),"Parsing xml file 2. Schould throw a fatal error due to already existing pattern name: ") state = statemachineFactory->GetStartState("test4"); MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing GetStartState() of test4 state machine pattern: ") state = statemachineFactory->GetStartState("global"); MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if previous loaded state machine pattern (global) is still accessible: ") state = statemachineFactory->GetStartState("test1"); MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if previous loaded state machine pattern (test1) is still accessible: ") //manually create a state machine pattern and add it to factory std::string patternName("manuallyCreatedStateMachine"); mitk::StateMachineFactory::StateMachineMapType* allStatesMap = new mitk::StateMachineFactory::StateMachineMapType(); mitk::State::Pointer state1 = mitk::State::New("firstState", 1); mitk::Transition* transition1 = new mitk::Transition("goto2", 2, mitk::EIDNULLEVENT); mitk::Action::Pointer action1 = mitk::Action::New(mitk::AcDONOTHING); transition1->AddAction(action1); state1->AddTransition(transition1); allStatesMap->insert(mitk::StateMachineFactory::StateMachineMapType::value_type(state1->GetId(), state1)); mitk::State::Pointer state2 = mitk::State::New("secondState", 2); transition1->SetNextState(state2); mitk::Transition* transition2 = new mitk::Transition("goto1", 1, mitk::EIDNULLEVENT); mitk::Action::Pointer action2 = mitk::Action::New(mitk::AcDONOTHING); transition2->AddAction(action2); transition2->SetNextState(state1); state2->AddTransition(transition2); allStatesMap->insert(mitk::StateMachineFactory::StateMachineMapType::value_type(state2->GetId(), state2)); //now add to factory statemachineFactory->AddStateMachinePattern(patternName.c_str(), state1, allStatesMap); //check if it is accessable state = statemachineFactory->GetStartState("global"); MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if previous loaded state machine pattern (global) is still accessible: ") state = statemachineFactory->GetStartState("test1"); MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if previous loaded state machine pattern (test1) is still accessible: ") state = statemachineFactory->GetStartState(patternName.c_str()); MITK_TEST_CONDITION_REQUIRED(state.IsNotNull(),"Testing if manually created and added state machine pattern is accessible: ") statemachineFactory->Delete(); //states, transitions and actions are freed in StateMachineFactory // always end with this! MITK_TEST_END(); }