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