Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkIGTLMessageSourceTest.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 
18 #include "mitkNavigationData.h"
19 
20 #include "mitkTestingMacros.h"
21 
26 class MyNavigationDataSourceTest : public mitk::NavigationDataSource
27  {
28  public:
29  mitkClassMacro(MyNavigationDataSourceTest, mitk::NavigationDataSource);
30  itkFactorylessNewMacro(Self)
31  itkCloneMacro(Self)
32  void CreateOutput()
33  {
34  this->SetNumberOfIndexedOutputs(1);
35  this->SetNthOutput(0, this->MakeOutput(0));
36  };
37  };
38 
40 class mitkNavigationDataSourceTestClass
41  {
42  public:
43 
44  static void TestInstantiation()
45  {
46  // let's create an object of our class
48 
49  // first test: did this work?
50  // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
51  // it makes no sense to continue without an object.
52  MITK_TEST_CONDITION_REQUIRED(myFilter.IsNotNull(), "Testing instantiation");
53 
54  // testing create outputs
55  MITK_TEST_CONDITION(myFilter->GetNumberOfInputs() == 0, "testing initial number of inputs");
56  MITK_TEST_CONDITION(myFilter->GetNumberOfOutputs() == 0, "testing initial number of outputs");
57  myFilter->CreateOutput();
58  MITK_TEST_CONDITION(myFilter->GetNumberOfOutputs() == 1, "testing SetNumberOfOutputs() and MakeOutput()");
59  MITK_TEST_CONDITION(dynamic_cast<mitk::NavigationData*>(myFilter->GetOutput()) != NULL, "test GetOutput() returning valid output object");
60  }
61 
62  static void TestMethodsNormalCases()
63  {
64  //create and initialize test objects
66  myFilter->CreateOutput();
68  mitk::FillVector3D(initialPos, 1.0, 2.0, 3.0);
69  mitk::NavigationData::OrientationType initialOri(0.1, 0.2, 0.3, 0.4);
70  mitk::ScalarType initialError(22.22);
71  bool initialValid(true);
73  nd1->SetPosition(initialPos);
74  nd1->SetOrientation(initialOri);
75  nd1->SetPositionAccuracy(initialError);
76  nd1->SetDataValid(initialValid);
77 
78  //test method graft
79  MITK_TEST_OUTPUT(<< "testing Graftoutput()");
80  myFilter->GraftOutput(nd1);
81  mitk::NavigationData::Pointer out = myFilter->GetOutput();
82  MITK_TEST_CONDITION(out.GetPointer() != nd1.GetPointer(), "testing if output is same object as source of graft");
83  MITK_TEST_CONDITION(mitk::Equal(out->GetPosition(), nd1->GetPosition()),"testing position equality after graft")
84  MITK_TEST_CONDITION(mitk::Equal(out->GetOrientation(), nd1->GetOrientation()),"testing orientation equality after graft")
85  MITK_TEST_CONDITION((out->GetCovErrorMatrix() == nd1->GetCovErrorMatrix()),"testing error matrix equality after graft")
86  MITK_TEST_CONDITION((out->IsDataValid() == nd1->IsDataValid()),"testing data valid equality after graft")
87  MITK_TEST_CONDITION(mitk::Equal(out->GetIGTTimeStamp(), nd1->GetIGTTimeStamp()), "testing timestamp equality after graft");
88 
89  //test method GetParameters()
90  mitk::PropertyList::ConstPointer list = myFilter->GetParameters();
91  MITK_TEST_CONDITION(list.IsNotNull(), "testing GetParameters()");
92  }
93 
94  static void TestMethodsInvalidCases()
95  {
96  //test invalid call of methods
98 
99  mitk::NavigationData::Pointer testOutput = myFilter->GetOutput();
100  MITK_TEST_CONDITION(testOutput.IsNull(), "testing GetOutput(int) before initialization");
101 
102  testOutput = myFilter->GetOutput("test");
103  MITK_TEST_CONDITION(testOutput.IsNull(), "testing GetOutput(string) before initialization");
104 
105  //test GetOutputIndex() with invalid output name
106  myFilter->CreateOutput();
107  bool exceptionThrown=false;
108  try
109  {
110  myFilter->GetOutputIndex("nonsense name");
111  }
112  catch(std::invalid_argument e)
113  {
114  exceptionThrown=true;
115  }
116  MITK_TEST_CONDITION(exceptionThrown,"Testing method GetOutputIndex with invalid navigation data name");
117 
118  //test method GraftNthOutput with invalid index
119  exceptionThrown=false;
120  try
121  {
122  mitk::NavigationData::Pointer graftObject;
123  myFilter->GraftNthOutput(100,graftObject);
124  }
125  catch(itk::ExceptionObject e)
126  {
127  exceptionThrown=true;
128  }
129  MITK_TEST_CONDITION(exceptionThrown,"Testing method GraftNthOutput with invalid index");
130  }
131 
132  static void TestMicroserviceRegister()
133  {
135  myFilter->CreateOutput();
137  mitk::FillVector3D(initialPos, 1.0, 2.0, 3.0);
138  mitk::NavigationData::OrientationType initialOri(0.1, 0.2, 0.3, 0.4);
139  mitk::ScalarType initialError(22.22);
140  bool initialValid(true);
142  nd1->SetPosition(initialPos);
143  nd1->SetOrientation(initialOri);
144  nd1->SetPositionAccuracy(initialError);
145  nd1->SetDataValid(initialValid);
146  myFilter->RegisterAsMicroservice();
147  MITK_TEST_CONDITION(myFilter->GetMicroserviceID()!="","Testing if microservice was registered successfully.");
148  }
149  static void TestMicroserviceAvailabilityAndUnregister()
150  {
151  //TODO: test if Microservice is available
152 
153  //TODO: remove Microservice
154 
155  //TODO: test if Microservice is not available any more
156 
157  }
158  };
159 
163 int mitkNavigationDataSourceTest(int /* argc */, char* /*argv*/[])
164 {
165  MITK_TEST_BEGIN("NavigationDataSource");
166 
167  mitkNavigationDataSourceTestClass::TestInstantiation();
168  mitkNavigationDataSourceTestClass::TestMethodsNormalCases();
169  mitkNavigationDataSourceTestClass::TestMethodsInvalidCases();
170  mitkNavigationDataSourceTestClass::TestMicroserviceRegister();
171  mitkNavigationDataSourceTestClass::TestMicroserviceAvailabilityAndUnregister();
172 
173  // always end with this!
174  MITK_TEST_END();
175 }
static Pointer New()
itk::SmartPointer< Self > Pointer
double ScalarType
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
int mitkNavigationDataSourceTest(int, char *[])
DataCollection - Class to facilitate loading/accessing structured data.
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:110
itk::SmartPointer< const Self > ConstPointer
#define MITK_TEST_OUTPUT(x)
Output some text.
virtual itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
#define MITK_TEST_CONDITION(COND, MSG)
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
and MITK_TEST_END()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.