Medical Imaging Interaction Toolkit  2018.4.99-e1268d66
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkEventConfig.h"
14 #include "mitkInteractionEvent.h"
17 #include "mitkMouseMoveEvent.h"
18 #include "mitkMousePressEvent.h"
19 #include "mitkMouseReleaseEvent.h"
20 #include "mitkMouseWheelEvent.h"
21 #include "mitkPropertyList.h"
22 #include "mitkTestingMacros.h"
23 #include "usGetModuleContext.h"
24 #include "usModule.h"
25 #include <fstream>
26 #include <iostream>
27 #include <string>
28 
29 int mitkEventConfigTest(int argc, char *argv[])
30 {
31  MITK_TEST_BEGIN("EventConfig")
32 
33  if (argc != 2)
34  {
35  MITK_ERROR << "Test needs configuration test file as parameter.";
36  return -1;
37  }
38 
39  /*
40  * Loads a test a Config file and test if Config is build up correctly,
41  * and if mapping from mitkEvents to EventVariant names works properly.
42  * Indirectly this also tests the EventFactory Class, since we also test if the events have been constructed properly.
43  *
44  * The configuration object is constructed in three different ways,
45  * each one is tested here.
46  */
47 
48  // Construction using compiled-in resrouces:
50  mitk::EventConfig newConfig("StatemachineConfigTest.xml", module);
51 
52  MITK_TEST_CONDITION_REQUIRED(newConfig.IsValid() == true, "01 Check if file can be loaded and is valid");
53  /*
54  * Test the global properties:
55  * Test if stored values match the ones in the test config file.
56  */
57  mitk::PropertyList::Pointer properties = newConfig.GetAttributes();
58  std::string prop1, prop2;
59  MITK_TEST_CONDITION_REQUIRED(properties->GetStringProperty("property1", prop1) && prop1 == "yes" &&
60  properties->GetStringProperty("scrollModus", prop2) && prop2 == "leftright",
61  "02 Check Global Properties");
62 
63  /*
64  * Check if Events get mapped to the proper Variants
65  */
66  mitk::Point2D pos;
69  pos,
74  pos,
80  pos,
88 
89  MITK_TEST_CONDITION_REQUIRED(newConfig.GetMappedEvent(mpe1.GetPointer()) == "Variant1" &&
90  newConfig.GetMappedEvent(standard1.GetPointer()) == "Standard1" &&
91  newConfig.GetMappedEvent(mme1.GetPointer()) == "Move2" &&
92  newConfig.GetMappedEvent(ke.GetPointer()) == "Key1" &&
93  newConfig.GetMappedEvent(mme2.GetPointer()) == "" // does not exist in file
94  ,
95  "03 Check Mouse- and Key-Events ");
96 
97  // Construction providing a input stream
98  std::ifstream configStream(argv[1]);
99  mitk::EventConfig newConfig2(configStream);
100 
101  MITK_TEST_CONDITION_REQUIRED(newConfig2.IsValid() == true, "01 Check if file can be loaded and is valid");
102  /*
103  * Test the global properties:
104  * Test if stored values match the ones in the test config file.
105  */
106  properties = newConfig2.GetAttributes();
107  MITK_TEST_CONDITION_REQUIRED(properties->GetStringProperty("property1", prop1) && prop1 == "yes" &&
108  properties->GetStringProperty("scrollModus", prop2) && prop2 == "leftright",
109  "02 Check Global Properties");
110 
111  /*
112  * Check if Events get mapped to the proper Variants
113  */
114  MITK_TEST_CONDITION_REQUIRED(newConfig2.GetMappedEvent(mpe1.GetPointer()) == "Variant1" &&
115  newConfig2.GetMappedEvent(standard1.GetPointer()) == "Standard1" &&
116  newConfig2.GetMappedEvent(mme1.GetPointer()) == "Move2" &&
117  newConfig2.GetMappedEvent(ke.GetPointer()) == "Key1" &&
118  newConfig2.GetMappedEvent(mme2.GetPointer()) == "" // does not exist in file
119  ,
120  "03 Check Mouse- and Key-Events ");
121 
122  // always end with this!
123 
124  // Construction providing a property list
125  std::vector<mitk::PropertyList::Pointer> configDescription;
126 
128  propertyList1->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventClass().c_str(), "MousePressEvent");
129  propertyList1->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventVariant().c_str(),
130  "MousePressEventVariant");
131  propertyList1->SetStringProperty("Modifiers", "CTRL,ALT");
132  configDescription.push_back(propertyList1);
133 
135  propertyList2->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventClass().c_str(), "MOUSERELEASEEVENT");
136  propertyList2->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventVariant().c_str(),
137  "MouseReleaseEventVariant");
138  propertyList2->SetStringProperty("Modifiers", "SHIFT");
139  configDescription.push_back(propertyList2);
140 
142  propertyList3->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventClass().c_str(), "MOUSERELEASEEVENT");
143  propertyList3->SetStringProperty(mitk::InteractionEventConst::xmlParameterEventVariant().c_str(),
144  "MouseReleaseEventVariant");
145  propertyList3->SetStringProperty("Modifiers", "ALT");
146  configDescription.push_back(propertyList3);
147 
148  mitk::EventConfig newConfig3(configDescription);
149 
150  mitk::MousePressEvent::Pointer mousePress1 =
152  pos,
158 
159  // create a second event with the same name but different modifiers...
162 
163  MITK_TEST_CONDITION_REQUIRED(newConfig3.GetMappedEvent(mousePress1.GetPointer()) == "MousePressEventVariant" &&
164  newConfig3.GetMappedEvent(mouseRelease1.GetPointer()) == "MouseReleaseEventVariant" &&
165  newConfig3.GetMappedEvent(mouseRelease2.GetPointer()) == "MouseReleaseEventVariant",
166  "04 Check Mouseevents from PropertyLists");
167 
168  MITK_TEST_END()
169 }
static Pointer New()
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, MouseButtons _arge)
#define MITK_ERROR
Definition: mitkLogMacros.h:20
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
std::string GetMappedEvent(const EventType &interactionEvent) const
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
static const std::string xmlParameterEventClass()
static const std::string xmlParameterEventVariant()
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, int _arge)
static Pointer New(BaseRenderer *_arga, const std::string &_argb, ModifierKeys _argc)
bool IsValid() const
Checks wether this EventConfig object is valid.
Module * GetModule() const
int mitkEventConfigTest(int argc, char *argv[])
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.
PropertyList::Pointer GetAttributes() const