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 <mitkState.h>
00020 #include <mitkTransition.h>
00021 #include "mitkTestingMacros.h"
00022 #include <fstream>
00023
00024
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 int mitkStateTest(int , char* [])
00039 {
00040 int stateId = 10;
00041
00042
00043 mitk::State::Pointer state = mitk::State::New("state", stateId);
00044
00045
00046 MITK_TEST_CONDITION_REQUIRED(state->GetReferenceCount() == 1,"Testing ReferenceCount of State");
00047
00048
00049 MITK_TEST_CONDITION_REQUIRED(state->GetId()==stateId,"Testing GetID ");
00050
00051 int count = 0;
00052
00053 std::string firstTName = "firstTransition";
00054 std::string secondTName = "secondTransition";
00055 mitk::Transition* firstTransition = new mitk::Transition(firstTName, count, count+1);
00056 MITK_TEST_CONDITION_REQUIRED(state->AddTransition( firstTransition ),"Adding first transition");
00057 MITK_TEST_CONDITION_REQUIRED(state->IsValidEvent(count+1),"Check if the first EventId is valid");
00058 MITK_TEST_CONDITION_REQUIRED(state->GetTransition(count+1) == firstTransition ,"Getting first transition");
00059 MITK_TEST_CONDITION_REQUIRED(state->GetReferenceCount() == 1,"Testing ReferenceCount still one");
00060 ++count;
00061
00062 mitk::Transition* secondTransition = new mitk::Transition(secondTName, count, count+1);
00063 MITK_TEST_CONDITION_REQUIRED(state->AddTransition( secondTransition ),"Adding second transition");
00064 MITK_TEST_CONDITION_REQUIRED(state->IsValidEvent(count+1),"Check if the second EventId is valid");
00065 MITK_TEST_CONDITION_REQUIRED(state->GetTransition(count+1) == secondTransition ,"Getting second transition");
00066 MITK_TEST_CONDITION_REQUIRED(state->GetReferenceCount() == 1,"Testing ReferenceCount still one");
00067
00068 ++count;
00069 MITK_TEST_CONDITION_REQUIRED( ! state->IsValidEvent(count+1),"Check if a non existent EventId is valid");
00070
00071
00072 state = NULL;
00073 MITK_TEST_CONDITION_REQUIRED(state.IsNull(),"Testing setting state to null and deleting it with it");
00074
00075
00076 std::cout << "Check state with cyclic definition: StateA->TransitionA->StateA: \n";
00077 stateId = 20;
00078 const char* name = "StateA";
00079 state = mitk::State::New(name, stateId);
00080 MITK_TEST_CONDITION_REQUIRED(state->GetId()==stateId,"Testing GetID ");
00081 MITK_TEST_CONDITION_REQUIRED(state->GetName()==name,"Testing GetID ");
00082 MITK_TEST_CONDITION_REQUIRED(state->GetReferenceCount() == 1,"Testing ReferenceCount of State");
00083 std::cout << "Add next state to transition: ";
00084 count = 0;
00085
00086 firstTransition = new mitk::Transition(firstTName, stateId, count+1);
00087 firstTransition->SetNextState(state);
00088 state->AddTransition(firstTransition);
00089 MITK_TEST_CONDITION_REQUIRED(state->GetReferenceCount() == 1,"Testing ReferenceCount still one");
00090
00091 secondTransition = new mitk::Transition(secondTName, stateId, count+2);
00092 secondTransition ->SetNextState(state);
00093 state->AddTransition(secondTransition);
00094 MITK_TEST_CONDITION_REQUIRED(state->GetReferenceCount() == 1,"Testing ReferenceCount still one");
00095
00096
00097 state = NULL;
00098 MITK_TEST_CONDITION_REQUIRED(state.IsNull(),"Testing setting state to null and deleting it with it");
00099
00100
00101
00102
00103
00104
00105
00106
00108
00109
00110
00111
00112 std::cout<<"[TEST DONE]"<<std::endl;
00113 return EXIT_SUCCESS;
00114 }