Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkEventConfigTest.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3  The Medical Imaging Interaction Toolkit (MITK)
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics.
7  All rights reserved.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without
10  even the implied warranty of MERCHANTABILITY or FITNESS FOR
11  A PARTICULAR PURPOSE.
12 
13  See LICENSE.txt or http://www.mitk.org for details.
14 
15  ===================================================================*/
16 
17 #include "mitkEventConfig.h"
18 #include "mitkInteractionEvent.h"
21 #include "mitkMouseMoveEvent.h"
22 #include "mitkMousePressEvent.h"
23 #include "mitkMouseReleaseEvent.h"
24 #include "mitkMouseWheelEvent.h"
25 #include "mitkPropertyList.h"
26 #include "mitkTestingMacros.h"
27 #include "usGetModuleContext.h"
28 #include "usModule.h"
29 #include <fstream>
30 #include <iostream>
31 #include <string>
32 
33 int mitkEventConfigTest(int argc, char *argv[])
34 {
35  MITK_TEST_BEGIN("EventConfig")
36 
37  if (argc != 2)
38  {
39  MITK_ERROR << "Test needs configuration test file as parameter.";
40  return -1;
41  }
42 
43  /*
44  * Loads a test a Config file and test if Config is build up correctly,
45  * and if mapping from mitkEvents to EventVariant names works properly.
46  * Indirectly this also tests the EventFactory Class, since we also test if the events have been constructed properly.
47  *
48  * The configuration object is constructed in three different ways,
49  * each one is tested here.
50  */
51 
52  // Construction using compiled-in resrouces:
54  mitk::EventConfig newConfig("StatemachineConfigTest.xml", module);
55 
56  MITK_TEST_CONDITION_REQUIRED(newConfig.IsValid() == true, "01 Check if file can be loaded and is valid");
57  /*
58  * Test the global properties:
59  * Test if stored values match the ones in the test config file.
60  */
61  mitk::PropertyList::Pointer properties = newConfig.GetAttributes();
62  std::string prop1, prop2;
63  MITK_TEST_CONDITION_REQUIRED(properties->GetStringProperty("property1", prop1) && prop1 == "yes" &&
64  properties->GetStringProperty("scrollModus", prop2) && prop2 == "leftright",
65  "02 Check Global Properties");
66 
67  /*
68  * Check if Events get mapped to the proper Variants
69  */
70  mitk::Point2D pos;
73  pos,
78  pos,
84  pos,
92 
93  MITK_TEST_CONDITION_REQUIRED(newConfig.GetMappedEvent(mpe1.GetPointer()) == "Variant1" &&
94  newConfig.GetMappedEvent(standard1.GetPointer()) == "Standard1" &&
95  newConfig.GetMappedEvent(mme1.GetPointer()) == "Move2" &&
96  newConfig.GetMappedEvent(ke.GetPointer()) == "Key1" &&
97  newConfig.GetMappedEvent(mme2.GetPointer()) == "" // does not exist in file
98  ,
99  "03 Check Mouse- and Key-Events ");
100 
101  // Construction providing a input stream
102  std::ifstream configStream(argv[1]);
103  mitk::EventConfig newConfig2(configStream);
104 
105  MITK_TEST_CONDITION_REQUIRED(newConfig2.IsValid() == true, "01 Check if file can be loaded and is valid");
106  /*
107  * Test the global properties:
108  * Test if stored values match the ones in the test config file.
109  */
110  properties = newConfig2.GetAttributes();
111  MITK_TEST_CONDITION_REQUIRED(properties->GetStringProperty("property1", prop1) && prop1 == "yes" &&
112  properties->GetStringProperty("scrollModus", prop2) && prop2 == "leftright",
113  "02 Check Global Properties");
114 
115  /*
116  * Check if Events get mapped to the proper Variants
117  */
118  MITK_TEST_CONDITION_REQUIRED(newConfig2.GetMappedEvent(mpe1.GetPointer()) == "Variant1" &&
119  newConfig2.GetMappedEvent(standard1.GetPointer()) == "Standard1" &&
120  newConfig2.GetMappedEvent(mme1.GetPointer()) == "Move2" &&
121  newConfig2.GetMappedEvent(ke.GetPointer()) == "Key1" &&
122  newConfig2.GetMappedEvent(mme2.GetPointer()) == "" // does not exist in file
123  ,
124  "03 Check Mouse- and Key-Events ");
125 
126  // always end with this!
127 
128  // Construction providing a property list
129  std::vector<mitk::PropertyList::Pointer> configDescription;
130 
132  propertyList1->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventClass().c_str(), "MousePressEvent");
133  propertyList1->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventVariant().c_str(),
134  "MousePressEventVariant");
135  propertyList1->SetStringProperty("Modifiers", "CTRL,ALT");
136  configDescription.push_back(propertyList1);
137 
139  propertyList2->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventClass().c_str(), "MOUSERELEASEEVENT");
140  propertyList2->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventVariant().c_str(),
141  "MouseReleaseEventVariant");
142  propertyList2->SetStringProperty("Modifiers", "SHIFT");
143  configDescription.push_back(propertyList2);
144 
146  propertyList3->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventClass().c_str(), "MOUSERELEASEEVENT");
147  propertyList3->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventVariant().c_str(),
148  "MouseReleaseEventVariant");
149  propertyList3->SetStringProperty("Modifiers", "ALT");
150  configDescription.push_back(propertyList3);
151 
152  mitk::EventConfig newConfig3(configDescription);
153 
154  mitk::MousePressEvent::Pointer mousePress1 =
156  pos,
162 
163  // create a second event with the same name but different modifiers...
166 
167  MITK_TEST_CONDITION_REQUIRED(newConfig3.GetMappedEvent(mousePress1.GetPointer()) == "MousePressEventVariant" &&
168  newConfig3.GetMappedEvent(mouseRelease1.GetPointer()) == "MouseReleaseEventVariant" &&
169  newConfig3.GetMappedEvent(mouseRelease2.GetPointer()) == "MouseReleaseEventVariant",
170  "04 Check Mouseevents from PropertyLists");
171 
172  MITK_TEST_END()
173 }
static Pointer New()
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, MouseButtons _arge)
#define MITK_ERROR
Definition: mitkLogMacros.h:24
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
PropertyList::Pointer GetAttributes() const
static const std::string xmlParameterEventClass()
static const std::string xmlParameterEventVariant()
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, int _arge)
std::string GetMappedEvent(const EventType &interactionEvent) const
static Pointer New(BaseRenderer *_arga, const std::string &_argb, ModifierKeys _argc)
Module * GetModule() const
int mitkEventConfigTest(int argc, char *argv[])
bool IsValid() const
Checks wether this EventConfig object is valid.
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd)
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, MouseButtons _arge)
Configuration Object for Statemachines.
and MITK_TEST_END()
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.