Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkGenericPropertyTest.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 "mitkGenericProperty.h"
18 #include "mitkNumericTypes.h"
19 #include "mitkProperties.h"
20 #include "mitkStringProperty.h"
21 #include "mitkTestingMacros.h"
22 
23 #include <iostream>
24 #include <string>
25 
26 // call with testValue1 != testValue2
27 template <typename T>
29  typename T::ValueType testValue2,
30  std::string testValue1AsString,
31  std::string testValue2AsString,
32  std::string type)
33 {
34  std::cout << "Testing mitk::GenericProperty<" << type << ">(" << testValue1AsString << ", " << testValue2AsString
35  << ") \n";
36 
37  typename T::Pointer prop(T::New());
38  typename T::Pointer prop2(T::New(testValue1));
39  typename T::Pointer prop3(T::New(testValue2));
40 
41  unsigned long tBefore = prop->GetMTime();
42  prop->SetValue(testValue1);
43  unsigned long tAfter = prop->GetMTime();
44  prop->SetValue(testValue1);
45  unsigned long tAfterAll = prop->GetMTime();
46 
47  MITK_TEST_CONDITION_REQUIRED(prop->GetValue() == testValue1 && prop->GetValueAsString() == testValue1AsString,
48  "Testing SetValue")
49 
50  MITK_TEST_CONDITION_REQUIRED((*prop == *prop2), "Testing equality operator (operator==)");
51 
52  prop->SetValue(testValue2);
53  unsigned long tAfterEverything = prop->GetMTime();
54 
55  std::cout << " Testing MTime correctness when changing property value: ";
56  if (tBefore >= tAfter || tAfterAll != tAfter || tAfterEverything <= tAfterAll)
57  {
58  std::cout << "[FAILED]" << std::endl;
59  return EXIT_FAILURE;
60  }
61  std::cout << "[PASSED]" << std::endl;
62 
63  prop->SetValue(testValue1);
64  std::cout << " Testing Assignment: ";
65  prop->AssignProperty(*prop3);
66  if ((!(*prop == *prop3)) || (*prop == *prop2))
67  {
68  std::cout << " [FAILED]" << std::endl;
69  return EXIT_FAILURE;
70  }
71  std::cout << "[PASSED]" << std::endl;
72  std::cout << std::endl;
73 
74  return EXIT_SUCCESS;
75 }
76 
77 int mitkGenericPropertyTest(int /*argc*/, char * /*argv*/ [])
78 {
79  MITK_TEST_BEGIN(GenericPropertyTest)
80 
81  // testing for some different data types
82  TestGenericPropertyForDataType<mitk::IntProperty>(1, 2, "1", "2", "int");
83  TestGenericPropertyForDataType<mitk::BoolProperty>(true, false, "1", "0", "bool");
84  TestGenericPropertyForDataType<mitk::FloatProperty>(1.0, -1.0, "1", "-1", "float");
85  TestGenericPropertyForDataType<mitk::DoubleProperty>(1.0, -1.0, "1", "-1", "double");
86  TestGenericPropertyForDataType<mitk::UIntProperty>(1, 100000, "1", "100000", "unsigned int");
87  TestGenericPropertyForDataType<mitk::UShortProperty>(1, 20000, "1", "20000", "unsigned short");
88 
89  TestGenericPropertyForDataType<mitk::StringProperty>(
90  std::string("eins"), std::string("zwei"), std::string("eins"), std::string("zwei"), "std::string");
91 
92  {
93  mitk::Point3D p1;
94  p1[0] = 2.0;
95  p1[1] = 3.0;
96  p1[2] = 4.0;
97  mitk::Point3D p2;
98  p2[0] = -1.0;
99  p2[1] = 2.0;
100  p2[2] = 3.0;
101  TestGenericPropertyForDataType<mitk::Point3dProperty>(p1, p2, "[2, 3, 4]", "[-1, 2, 3]", "mitk::Point3D");
102  }
103 
104  {
105  mitk::Point4D p1;
106  p1[0] = 2.0;
107  p1[1] = 3.0;
108  p1[2] = 4.0;
109  p1[3] = -2.0;
110  mitk::Point4D p2;
111  p2[0] = -1.0;
112  p2[1] = 2.0;
113  p2[2] = 3.0;
114  p2[3] = 5.0;
115  TestGenericPropertyForDataType<mitk::Point4dProperty>(p1, p2, "[2, 3, 4, -2]", "[-1, 2, 3, 5]", "mitk::Point4D");
116  }
117 
118  /* THIS won't compile because of the interface of XMLWriter... that should be reworked perhaps
119  {
120  mitk::Vector2D p1; p1[0] = 2.0; p1[1] = 3.0;
121  mitk::Vector2D p2; p2[0] =-1.0; p2[1] = 2.0;
122  TestGenericPropertyForDataType<mitk::Vector2D>( p1, p2, "[2, 3]", "[-1, 2]", "mitk::Vector2D");
123  }
124  */
125 
126  {
127  mitk::Vector3D p1;
128  p1[0] = 2.0;
129  p1[1] = 3.0;
130  p1[2] = 4.0;
131  mitk::Vector3D p2;
132  p2[0] = -1.0;
133  p2[1] = 2.0;
134  p2[2] = 3.0;
135  TestGenericPropertyForDataType<mitk::Vector3DProperty>(p1, p2, "[2, 3, 4]", "[-1, 2, 3]", "mitk::Vector3D");
136  }
137 
138  MITK_TEST_END();
139 }
itk::SmartPointer< Self > Pointer
int TestGenericPropertyForDataType(typename T::ValueType testValue1, typename T::ValueType testValue2, std::string testValue1AsString, std::string testValue2AsString, std::string type)
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
ValueType
Type of the value held by a Value object.
Definition: jsoncpp.h:345
and MITK_TEST_END()
int mitkGenericPropertyTest(int, char *[])
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.