Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPropertyListTest.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 "mitkLookupTables.h"
18 #include "mitkProperties.h"
19 #include "mitkPropertyList.h"
20 #include "mitkStringProperty.h"
21 #include <iostream>
22 
23 int mitkPropertyListTest(int /*argc*/, char * /*argv*/ [])
24 {
26  std::cout << "Testing mitk::PropertyList::New(): ";
27  propList = mitk::PropertyList::New();
28  if (propList.IsNull())
29  {
30  std::cout << "[FAILED]" << std::endl;
31  return EXIT_FAILURE;
32  }
33  else
34  {
35  std::cout << "[PASSED]" << std::endl;
36  }
39  std::cout << "Testing BoolProperty ==: ";
40  if (!(*boolProp2 == *boolProp))
41  {
42  std::cout << "[FAILED]" << std::endl;
43  return EXIT_FAILURE;
44  }
45  std::cout << "[PASSED]" << std::endl;
46  unsigned long tBefore, tAfter;
47 
48  std::cout << "Testing SetProperty() with new key value: ";
49  tBefore = propList->GetMTime();
50  propList->SetProperty("test", boolProp);
51  tAfter = propList->GetMTime();
52  if (!(tAfter > tBefore))
53  {
54  std::cout << "[FAILED]" << std::endl;
55  return EXIT_FAILURE;
56  }
57  std::cout << "[PASSED]" << std::endl;
58 
59  std::cout << "Testing SetProperty() with changed property value: ";
60  tBefore = propList->GetMTime();
61  propList->SetProperty("test", mitk::BoolProperty::New(true));
62  tAfter = propList->GetMTime();
63  if (!(tAfter > tBefore))
64  {
65  std::cout << "[FAILED]" << std::endl;
66  return EXIT_FAILURE;
67  }
68  std::cout << "[PASSED]" << std::endl;
69 
70  std::cout << "Testing SetProperty() with unchanged property value: ";
71  tBefore = propList->GetMTime();
72  propList->SetProperty("test", mitk::BoolProperty::New(true));
73  tAfter = propList->GetMTime();
74  if (tBefore != tAfter)
75  {
76  std::cout << "[FAILED]" << std::endl;
77  return EXIT_FAILURE;
78  }
79  std::cout << "[PASSED]" << std::endl;
80 
81  std::cout << "Testing MTime correctness when changing property value: ";
82  boolProp = mitk::BoolProperty::New(true);
83  propList->ReplaceProperty("test", boolProp);
84  tBefore = propList->GetMTime();
85  boolProp->SetValue(true);
86  tAfter = propList->GetMTime();
87  boolProp->SetValue(false);
88  unsigned long tAfterAll = propList->GetMTime();
89 
90  if (tBefore != tAfter || tAfterAll <= tAfter)
91  {
92  std::cout << "[FAILED]" << std::endl;
93  return EXIT_FAILURE;
94  }
95  std::cout << "[PASSED]" << std::endl;
96 
97  std::cout << "Testing MTime correctness when calling SetProperty twice: ";
98  boolProp = mitk::BoolProperty::New(true);
99  propList->SetProperty("test", boolProp);
100  tBefore = propList->GetMTime();
101  propList->SetProperty("test", boolProp);
102  tAfter = propList->GetMTime();
103 
104  if (tBefore != tAfter)
105  {
106  std::cout << "[FAILED]" << std::endl;
107  return EXIT_FAILURE;
108  }
109  std::cout << "[PASSED]" << std::endl;
110 
111  std::cout << "Testing if existing properties survive SetProperty: ";
112  propList->SetProperty("test", boolProp);
113  mitk::BaseProperty *bpBefore = propList->GetProperty("test");
114  propList->SetProperty("test", boolProp2);
115  mitk::BaseProperty *bpAfter = propList->GetProperty("test");
116 
117  if (bpBefore != bpAfter || bpAfter == nullptr)
118  {
119  std::cout << std::endl;
120  std::cout << "[FAILED]" << std::endl;
121  return EXIT_FAILURE;
122  }
123  std::cout << "[PASSED]" << std::endl;
124 
125  std::cout << "Testing if existing properties survive ReplaceProperty: ";
126  propList->SetProperty("test", boolProp);
127  bpBefore = propList->GetProperty("test");
128  propList->ReplaceProperty("test", boolProp2);
129  bpAfter = propList->GetProperty("test");
130 
131  if (bpBefore == bpAfter || bpAfter == nullptr)
132  {
133  std::cout << std::endl;
134  std::cout << "[FAILED]" << std::endl;
135  return EXIT_FAILURE;
136  }
137  std::cout << "[PASSED]" << std::endl;
138 
139  // std::cout << "Testing output of PropertyList to file: ";
140  // if ( TestXMLWriter() )
141  // std::cout << "[PASSED]" << std::endl;
142  // else
143  // return EXIT_FAILURE;
144 
145  std::cout << "Testing GetPropertyValue(bool): ";
147  propList->SetProperty("gpvBool", gpvTest);
148  bool b = false;
149  bool getPropertyValueReturnValue = propList->GetPropertyValue<bool>("gpvBool", b);
150  if ((getPropertyValueReturnValue == true) && (b == gpvTest->GetValue()))
151  std::cout << "[PASSED]" << std::endl;
152  else
153  {
154  std::cout << "Oh, not goot:"
155  "\nWe called propList->GetPropertyValue<bool>('gpvBool', b) and it returned "
156  << getPropertyValueReturnValue << "\nThen we compared b [" << b << "] and gpvTest->GetValue() ["
157  << gpvTest->GetValue() << "]" << std::endl;
158  std::cout << "[FAILED]" << std::endl;
159  return EXIT_FAILURE;
160  }
161 
162  std::cout << "Testing GetPropertyValue(float): ";
164  propList->SetProperty("gpvfloat", gpvTest2);
165  float v = -1.23;
166  if ((propList->GetPropertyValue<float>("gpvfloat", v) == true) && (v == gpvTest2->GetValue()))
167  std::cout << "[PASSED]" << std::endl;
168  else
169  {
170  std::cout << "[FAILED]" << std::endl;
171  return EXIT_FAILURE;
172  }
173 
174  std::cout << "Testing GetPropertyValue(BoolLookupTable): ";
176  blt.SetTableValue(17, true);
177  propList->SetProperty("blutprop", mitk::BoolLookupTableProperty::New(blt));
178  try
179  {
181  if ((propList->GetPropertyValue<mitk::BoolLookupTable>("blutprop", blut) == true) &&
182  (blut.GetTableValue(17) == true))
183  std::cout << "[PASSED]" << std::endl;
184  else
185  {
186  std::cout << "[FAILED]" << std::endl;
187  return EXIT_FAILURE;
188  }
189  }
190  catch (...)
191  {
192  std::cout << "Exception thrown! [FAILED]" << std::endl;
193  return EXIT_FAILURE;
194  }
195 
196  {
197  std::cout << "Testing GetBoolProperty(): ";
199  propList->ReplaceProperty("test", prop);
200  bool v = false;
201  if ((propList->GetBoolProperty("test", v) == true) && (v == prop->GetValue()))
202  std::cout << "[PASSED]" << std::endl;
203  else
204  {
205  std::cout << "[FAILED]" << std::endl;
206  return EXIT_FAILURE;
207  }
208  }
209  {
210  std::cout << "Testing GetIntProperty(): ";
212  propList->ReplaceProperty("test", prop);
213  int v = 1;
214  if ((propList->GetIntProperty("test", v) == true) && (v == prop->GetValue()))
215  std::cout << "[PASSED]" << std::endl;
216  else
217  {
218  std::cout << "[FAILED]" << std::endl;
219  return EXIT_FAILURE;
220  }
221  }
222  {
223  std::cout << "Testing GetFloatProperty(): ";
225  propList->ReplaceProperty("test", prop);
226  float v = 1.2;
227  if ((propList->GetFloatProperty("test", v) == true) && (v == prop->GetValue()))
228  std::cout << "[PASSED]" << std::endl;
229  else
230  {
231  std::cout << "[FAILED]" << std::endl;
232  return EXIT_FAILURE;
233  }
234  }
235  {
236  std::cout << "Testing GetStringProperty(): ";
238  propList->ReplaceProperty("test", prop);
239  std::string v = "";
240  if ((propList->GetStringProperty("test", v) == true) && (v == prop->GetValue()))
241  std::cout << "[PASSED]" << std::endl;
242  else
243  {
244  std::cout << "[FAILED]" << std::endl;
245  return EXIT_FAILURE;
246  }
247  }
248 
249  std::cout << "[TEST DONE]" << std::endl;
250  return EXIT_SUCCESS;
251 }
static Pointer New()
void SetTableValue(IdentifierType id, ValueType value)
ValueType GetTableValue(IdentifierType id) const
static Pointer New()
Abstract base class for properties.
static Pointer New()
static Pointer New()
int mitkPropertyListTest(int, char *[])
specializations of GenericLookupTable
static Pointer New()