Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkBaseDataTest.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 // Testing
13 #include "mitkTestFixture.h"
14 #include "mitkTestingMacros.h"
15 
16 // std includes
17 #include <string>
18 
19 // MITK includes
21 #include "mitkStringProperty.h"
23 #include <mitkTimeGeometry.h>
24 
25 #include "itkImage.h"
26 
27 // VTK includes
28 #include <vtkDebugLeaks.h>
29 
30 class mitkBaseDataTestSuite : public mitk::TestFixture
31 {
32  CPPUNIT_TEST_SUITE(mitkBaseDataTestSuite);
33 
34  MITK_TEST(CreateBaseData_Success);
35  MITK_TEST(InitializationOfBaseData_Success);
36 
37  MITK_TEST(CreateCloneBaseData_Success);
38  MITK_TEST(InitializationOfCloneBaseData_Success);
39 
40  MITK_TEST(GetAndSetTimeGeometry_Success);
41  MITK_TEST(ResetTimeGeometry_Success);
42  MITK_TEST(ReinitOfTimeGeometry_Success);
43 
44  MITK_TEST(GetGeometryForSingleTimeGeometries_Failure);
45 
46  MITK_TEST(TestingExpand_Success);
47 
48  MITK_TEST(TestingGetUpdateGeometry_Success);
49 
50  MITK_TEST(GetOriginOfBaseData_Success);
51  MITK_TEST(GetOriginOfCloneBaseData);
52 
53  MITK_TEST(ClearATimeStep);
54 
55  MITK_TEST(BaseDataSetAndGetProperty_Success);
56  MITK_TEST(CloneBaseDataSetAndGetProperty_Success);
57 
58  MITK_TEST(BasePropertyListIsSet_Success);
59  MITK_TEST(BasePorpertyIsSetInPropertyList_Success);
60 
61  MITK_TEST(UpdateOutputInformationOfBaseData_Failure);
62  MITK_TEST(CopyingInformationOfBaseData_Failure);
63 
64  CPPUNIT_TEST_SUITE_END();
65 
66 private:
69 
70  mitk::TimeGeometry *m_Geo;
72 
73  mitk::Geometry3D::Pointer m_Geometry3D;
75 
76  mitk::ScalarType m_X[3];
77  mitk::PropertyList::Pointer m_PropertyList;
78 
79 public:
80  void setUp() override
81  {
82  m_BaseDataImpl = mitk::BaseDataTestImplementation::New();
83  m_CloneBaseData = m_BaseDataImpl->Clone();
84 
85  m_Geo = nullptr;
87 
88  m_Geometry3D = mitk::Geometry3D::New();
89  m_Geo3 = dynamic_cast<mitk::BaseGeometry *>(m_Geometry3D.GetPointer());
90 
91  m_X[0] = 2;
92  m_X[1] = 4;
93  m_X[2] = 6;
94 
95  m_PropertyList = mitk::PropertyList::New();
96  }
97 
98  void tearDown() override
99  {
100  m_BaseDataImpl = nullptr;
101  m_CloneBaseData = nullptr;
102 
103  m_Geo = nullptr;
104  m_Geo2 = nullptr;
105 
106  m_Geometry3D = nullptr;
107  m_Geo3 = nullptr;
108 
109  m_X[0] = 0;
110  m_X[1] = 0;
111  m_X[2] = 0;
112 
113  m_PropertyList = nullptr;
114  }
115 
116  void CreateBaseData_Success()
117  {
118  // Create a BaseData implementation
119  MITK_INFO << "Creating a base data instance...";
120  CPPUNIT_ASSERT_MESSAGE("Testing instantiation", m_BaseDataImpl.IsNotNull());
121  }
122 
123  void InitializationOfBaseData_Success()
124  {
125  CPPUNIT_ASSERT_MESSAGE("BaseDataTestImplementation is initialized", m_BaseDataImpl->IsInitialized());
126  CPPUNIT_ASSERT_MESSAGE("BaseDataTestImplementation is initialized and empty", m_BaseDataImpl->IsEmpty());
127  }
128 
129  void CreateCloneBaseData_Success()
130  {
131  // Create CloneBaseData implementation
132  MITK_INFO << "Creating a clone base data instance...";
133  CPPUNIT_ASSERT_MESSAGE("Testing instantiation of base data clone", m_CloneBaseData.IsNotNull());
134  }
135 
136  void InitializationOfCloneBaseData_Success()
137  {
138  CPPUNIT_ASSERT_MESSAGE("Clone of BaseDataTestImplementation is initialized", m_CloneBaseData->IsInitialized());
139  CPPUNIT_ASSERT_MESSAGE("Clone of BaseDataTestImplementation is initialized and empty", m_CloneBaseData->IsEmpty());
140  }
141 
142  void GetAndSetTimeGeometry_Success()
143  {
144  // test method GetTimeGeometry()
145  MITK_INFO << "Testing setter and getter for geometries...";
146  CPPUNIT_ASSERT_MESSAGE("Testing creation of TimeGeometry", m_BaseDataImpl->GetTimeGeometry());
147  }
148 
149  void ResetTimeGeometry_Success()
150  {
151  m_BaseDataImpl->SetTimeGeometry(m_Geo);
152  CPPUNIT_ASSERT_MESSAGE("Reset Geometry", m_BaseDataImpl->GetTimeGeometry() == nullptr);
153  }
154 
155  void ReinitOfTimeGeometry_Success()
156  {
157  m_BaseDataImpl->SetTimeGeometry(m_Geo2);
158  m_Geo2->Initialize(2);
159  CPPUNIT_ASSERT_MESSAGE("Correct Reinit of TimeGeometry", m_BaseDataImpl->GetTimeGeometry() == m_Geo2.GetPointer());
160  }
161 
162  void GetGeometryForSingleTimeGeometries_Failure()
163  {
164  // test method GetGeometry(int timeStep)
165  CPPUNIT_ASSERT_MESSAGE("Testing Creation of single TimeGeometries", m_BaseDataImpl->GetGeometry(1) == nullptr);
166  }
167 
168  void TestingExpand_Success()
169  {
170  // test method Expand(unsigned int timeSteps)
171  m_BaseDataImpl->Expand(5);
172  CPPUNIT_ASSERT_MESSAGE("Expand the geometry to further time slices!", m_BaseDataImpl->GetTimeSteps() == 5);
173  }
174 
175  void TestingGetUpdateGeometry_Success()
176  {
177  // test method GetUpdatedGeometry(int timeStep);
178  m_BaseDataImpl->Expand(5);
180  dynamic_cast<mitk::ProportionalTimeGeometry *>(m_BaseDataImpl->GetTimeGeometry());
181  if (timeGeometry.IsNotNull())
182  {
183  timeGeometry->SetTimeStepGeometry(m_Geo3, 1);
184  }
185 
186  CPPUNIT_ASSERT_MESSAGE("Set Geometry for time step 1", m_BaseDataImpl->GetUpdatedGeometry(1) == m_Geo3);
187  CPPUNIT_ASSERT_MESSAGE("Check if modified time is set", m_BaseDataImpl->GetMTime() != 0);
188  }
189 
190  void GetOriginOfBaseData_Success()
191  {
192  m_BaseDataImpl->Expand(5);
193  m_BaseDataImpl->SetClonedGeometry(m_Geo3, 1);
194 
195  mitk::Point3D p3d(m_X);
196  m_BaseDataImpl->SetOrigin(p3d);
197  m_Geo3->SetOrigin(p3d);
198  CPPUNIT_ASSERT_MESSAGE("Testing Origin set", m_BaseDataImpl->GetGeometry(1)->GetOrigin() == m_Geo3->GetOrigin());
199  }
200  void GetOriginOfCloneBaseData()
201  {
202  m_BaseDataImpl->Expand(5);
203  m_BaseDataImpl->SetClonedGeometry(m_Geo3, 1);
204 
205  mitk::Point3D p3d(m_X);
206  m_BaseDataImpl->SetOrigin(p3d);
207  m_Geo3->SetOrigin(p3d);
208 
209  m_CloneBaseData = m_BaseDataImpl->Clone();
210  CPPUNIT_ASSERT_MESSAGE("Testing origin set in clone!",
211  m_CloneBaseData->GetGeometry(1)->GetOrigin() == m_Geo3->GetOrigin());
212  }
213 
214  void ClearATimeStep()
215  {
216  CPPUNIT_ASSERT_MESSAGE("Is not empty before clear()!", !m_BaseDataImpl->IsEmptyTimeStep(1));
217  m_BaseDataImpl->Clear();
218  CPPUNIT_ASSERT_MESSAGE("...but afterwards!", m_BaseDataImpl->IsEmptyTimeStep(1));
219  }
220 
221  void BaseDataSetAndGetProperty_Success()
222  {
223  // test method Set-/GetProperty()
224  m_BaseDataImpl->SetProperty("property38", mitk::StringProperty::New("testproperty"));
225  CPPUNIT_ASSERT_MESSAGE("Check if base property is set correctly!",
226  m_BaseDataImpl->GetProperty("property38")->GetValueAsString() == "testproperty");
227  }
228 
229  void CloneBaseDataSetAndGetProperty_Success()
230  {
231  m_BaseDataImpl->SetProperty("property38", mitk::StringProperty::New("testproperty"));
232  m_CloneBaseData = m_BaseDataImpl->Clone();
233  CPPUNIT_ASSERT_MESSAGE("Testing origin set in clone!",
234  m_CloneBaseData->GetProperty("property38")->GetValueAsString() == "testproperty");
235  }
236 
237  void BasePropertyListIsSet_Success()
238  {
239  // test method Set-/GetPropertyList
240  m_PropertyList->SetFloatProperty("floatProperty1", 123.45);
241  m_PropertyList->SetBoolProperty("visibility", true);
242  m_PropertyList->SetStringProperty("nameXY", "propertyName");
243  m_BaseDataImpl->SetPropertyList(m_PropertyList);
244 
245  CPPUNIT_ASSERT_MESSAGE("Check if base property list is set correctly!",
246  m_BaseDataImpl->GetPropertyList() == m_PropertyList);
247  }
248 
249  void BasePorpertyIsSetInPropertyList_Success()
250  {
251  m_PropertyList->SetFloatProperty("floatProperty1", 123.45);
252  m_PropertyList->SetBoolProperty("visibility", true);
253  m_PropertyList->SetStringProperty("nameXY", "propertyName");
254  m_BaseDataImpl->SetPropertyList(m_PropertyList);
255  bool value = false;
256  CPPUNIT_ASSERT_MESSAGE("Check if base property is set correctly in the property list!",
257  m_BaseDataImpl->GetPropertyList()->GetBoolProperty("visibility", value) == true);
258  }
259 
260  void UpdateOutputInformationOfBaseData_Failure()
261  {
262  // test method UpdateOutputInformation()
263  m_BaseDataImpl->UpdateOutputInformation();
264  m_Geo2->Initialize(2);
265  m_Geo2.GetPointer();
266  CPPUNIT_ASSERT_MESSAGE("TimeGeometry update!", m_BaseDataImpl->GetUpdatedTimeGeometry() != m_Geo2);
267  }
268 
269  void CopyingInformationOfBaseData_Failure()
270  {
271  // Test method CopyInformation()
273  newBaseData->CopyInformation(m_BaseDataImpl);
274  CPPUNIT_ASSERT_MESSAGE("Check copying of Basedata Data Object!",
275  newBaseData->GetTimeGeometry()->CountTimeSteps() != 5);
276  }
277 };
278 MITK_TEST_SUITE_REGISTRATION(mitkBaseData)
static Pointer New()
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_INFO
Definition: mitkLogMacros.h:18
double ScalarType
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static Pointer New()
Test fixture for parameterized tests.
static Pointer New()
BaseGeometry Describes the geometry of a data object.