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 <mitkGlobalInteraction.h>
00020 #include <mitkPointSetInteractor.h>
00021
00022 #include "mitkTestingMacros.h"
00023
00024 #include <fstream>
00025 int mitkGlobalInteractionTest(int , char* [])
00026 {
00027 MITK_TEST_BEGIN("GlobalInteraction")
00028
00029
00030 mitk::GlobalInteraction::Pointer globalInteraction = mitk::GlobalInteraction::GetInstance();
00031 MITK_TEST_CONDITION_REQUIRED(globalInteraction.IsNotNull(),"testing singleton initialization: ")
00032 MITK_TEST_CONDITION_REQUIRED(globalInteraction->IsInitialized() == false ,"testing initial initialization: not initialized")
00033
00034
00035 MITK_TEST_CONDITION_REQUIRED(globalInteraction->Initialize("global"),"testing to initialize: ")
00036
00037
00038 MITK_TEST_CONDITION_REQUIRED(globalInteraction->IsInitialized(),"testing initial initialization: initialized")
00039
00040 MITK_TEST_CONDITION_REQUIRED(globalInteraction->Initialize("global") == false ,"testing double initialization")
00041
00042 MITK_TEST_CONDITION_REQUIRED(globalInteraction->IsInitialized(),"still initialized: ")
00043
00044 MITK_TEST_CONDITION_REQUIRED(globalInteraction.IsNotNull() ,"Testing 'instantiation' of 'global' static GlobalInteraction")
00045
00046
00047 mitk::GlobalInteraction::Pointer myGlobalInteraction = mitk::GlobalInteraction::New();
00048 MITK_TEST_CONDITION_REQUIRED(myGlobalInteraction.IsNotNull(),"testing non singleton initialization: ")
00049 MITK_TEST_CONDITION_REQUIRED(myGlobalInteraction->IsInitialized() == false ,"testing initial initialization of non singleton: not initialized")
00050 MITK_TEST_CONDITION_REQUIRED(myGlobalInteraction->Initialize("global"),"testing to initialize non singleton: ")
00051 MITK_TEST_CONDITION_REQUIRED(myGlobalInteraction->IsInitialized() ,"testing initialization of non singleton: initialized")
00052
00053
00054 MITK_TEST_CONDITION_REQUIRED(myGlobalInteraction != globalInteraction ,"Testing whether new instance equals the global satic one (must not be!)")
00055
00056
00057 MITK_TEST_CONDITION_REQUIRED(myGlobalInteraction->GetInstance() == globalInteraction ,"Testing singleton from non singleton instance")
00058
00059
00060 myGlobalInteraction = NULL;
00061
00062
00063
00064 mitk::PointSetInteractor::Pointer firstInteractor = mitk::PointSetInteractor::New("pointsetinteractor", NULL, 1);
00065 mitk::PointSetInteractor::Pointer secondInteractor = mitk::PointSetInteractor::New("pointsetinteractor", NULL, 10);
00066
00067 globalInteraction->AddInteractor(firstInteractor);
00068 MITK_TEST_CONDITION_REQUIRED(globalInteraction->InteractorRegistered(firstInteractor),"Add first interactor to globalInteraction and check if is is registered: ")
00069 globalInteraction->AddInteractor(secondInteractor);
00070 MITK_TEST_CONDITION_REQUIRED(globalInteraction->InteractorRegistered(secondInteractor),"Add second interactor to globalInteraction and check if is is registered: ")
00071
00072
00073 MITK_TEST_CONDITION_REQUIRED(globalInteraction->RemoveInteractor(firstInteractor),"Remove the first Interactor: ")
00074 MITK_TEST_CONDITION_REQUIRED(!globalInteraction->RemoveInteractor(firstInteractor),"Remove the first Interactor a second time: ")
00075
00076
00077 MITK_TEST_CONDITION_REQUIRED(!globalInteraction->InteractorRegistered(firstInteractor),"Check if the first is not registered: ")
00078
00079 MITK_TEST_CONDITION_REQUIRED(globalInteraction->InteractorRegistered(secondInteractor),"Check if the second is still registered: ")
00080
00081
00082 MITK_TEST_CONDITION_REQUIRED(globalInteraction->RemoveInteractor(secondInteractor),"Remove the second Interactor: ")
00083 MITK_TEST_CONDITION_REQUIRED(!globalInteraction->RemoveInteractor(secondInteractor),"Remove the second Interactor a second time: ")
00084 MITK_TEST_CONDITION_REQUIRED(!globalInteraction->InteractorRegistered(secondInteractor),"Check if the second is not registered: ")
00085
00086
00087
00088
00089 std::cout << "Check the addition of a Listener the same way: ";
00090 std::cout << "Add two interactors as listeners (usually you add statemachines, not interactors). Are they both registered?: ";
00091 std::cout << "Add listener1 (ITK popup with warning should come up: ";
00092 globalInteraction->AddListener(firstInteractor);
00093 MITK_TEST_CONDITION_REQUIRED(globalInteraction->ListenerRegistered(firstInteractor),"registered listener1: ")
00094 MITK_TEST_CONDITION_REQUIRED(!globalInteraction->ListenerRegistered(secondInteractor),"not yet registered listener2: ")
00095 std::cout << "Add listener2: ";
00096 globalInteraction->AddListener(secondInteractor);
00097 MITK_TEST_CONDITION_REQUIRED(globalInteraction->ListenerRegistered(secondInteractor),"registered listener2: ")
00098 MITK_TEST_CONDITION_REQUIRED(globalInteraction->ListenerRegistered(firstInteractor),"listener1 still registered: ")
00099
00100
00101 MITK_TEST_CONDITION_REQUIRED(globalInteraction->RemoveListener(secondInteractor),"Remove listener2: ")
00102 MITK_TEST_CONDITION_REQUIRED(!globalInteraction->ListenerRegistered(secondInteractor),"listener2 not registered anymore: ")
00103 MITK_TEST_CONDITION_REQUIRED(globalInteraction->ListenerRegistered(firstInteractor),"but listener1: ")
00104
00105 MITK_TEST_CONDITION_REQUIRED(globalInteraction->RemoveListener(firstInteractor),"Remove listener1: ")
00106 MITK_TEST_CONDITION_REQUIRED(!globalInteraction->ListenerRegistered(firstInteractor),"listener1 not registered anymore: ")
00107 MITK_TEST_CONDITION_REQUIRED(!globalInteraction->ListenerRegistered(secondInteractor),"listener2 also not registered: ")
00108
00109
00110
00111 std::cout << "Now add the two interactors as interactors again: ";
00112 globalInteraction->AddInteractor(firstInteractor);
00113 globalInteraction->AddInteractor(secondInteractor);
00114
00115 std::cout << "and free the instances!";
00116
00117 firstInteractor = NULL;
00118 secondInteractor = NULL;
00119 globalInteraction = NULL;
00120
00121
00122 MITK_TEST_END();
00123 }