32 #include <itkCommand.h> 34 #include <vtkDebugLeaks.h> 36 struct PropertyModifiedListener
38 typedef itk::SimpleMemberCommand<PropertyModifiedListener> CmdType;
40 PropertyModifiedListener() : m_Modified(false), m_Cmd(CmdType::New())
42 m_Cmd->SetCallbackFunction(
this, &PropertyModifiedListener::Modified);
45 void Modified() { m_Modified =
true; }
54 CmdType::Pointer m_Cmd;
59 CPPUNIT_TEST_SUITE(mitkPropertyTestSuite);
72 MITK_TEST(TestAnnotationProperty_Success);
75 MITK_TEST(TestLevelWindowProperty_Success);
76 MITK_TEST(TestSmartPointerProperty_Success);
78 MITK_TEST(TestTransferFunctionProperty_Success);
79 MITK_TEST(TestWeakPointerProperty_Success);
80 MITK_TEST(TestLookupTablePropertyProperty_Success);
81 CPPUNIT_TEST_SUITE_END();
84 PropertyModifiedListener m_L;
94 void TestPropInequality(T prop, T prop2)
97 CPPUNIT_ASSERT_MESSAGE(
"Test inequality 1", !(*prop == *prop2));
98 CPPUNIT_ASSERT_MESSAGE(
"Test polymorphic inequality 1", !(*prop == *baseProp2));
99 CPPUNIT_ASSERT_MESSAGE(
"Test polymorphic inequality 2", !(*baseProp2 == *prop));
103 void TestPropAssignment(T prop, T prop2,
const std::string &strProp)
105 unsigned long tag = prop->AddObserver(itk::ModifiedEvent(), m_L.m_Cmd.GetPointer());
109 CPPUNIT_ASSERT_MESSAGE(
"Test modified event", m_L.Pop());
110 std::string msg = std::string(
"Test assignment [") + prop->GetValueAsString() +
" == " + strProp +
"]";
111 CPPUNIT_ASSERT_MESSAGE(msg, prop->GetValueAsString() == strProp);
112 CPPUNIT_ASSERT_MESSAGE(
"Test equality", *prop == *prop2);
113 CPPUNIT_ASSERT_MESSAGE(
"Test equality", *prop == *baseProp2);
114 CPPUNIT_ASSERT_MESSAGE(
"Test polymorphic equality", *baseProp2 == *prop);
116 prop->RemoveObserver(tag);
120 void TestPropPolymorphicAssignment(T prop, T prop2,
const std::string &strProp)
124 unsigned long tag = baseProp->AddObserver(itk::ModifiedEvent(), m_L.m_Cmd.GetPointer());
127 CPPUNIT_ASSERT_MESSAGE(
"Test modified event", m_L.Pop());
129 std::string(
"Test polymorphic assignment [") + baseProp->GetValueAsString() +
" == " + strProp +
"]";
130 CPPUNIT_ASSERT_MESSAGE(msg, baseProp->GetValueAsString() == strProp);
131 CPPUNIT_ASSERT_MESSAGE(
"Test equality", *prop == *prop2);
132 CPPUNIT_ASSERT_MESSAGE(
"Test equality", *prop2 == *baseProp);
133 CPPUNIT_ASSERT_MESSAGE(
"Test polymorphic equality", *baseProp == *prop2);
134 baseProp->RemoveObserver(tag);
138 void TestPropCloning(T prop)
140 T prop2 = prop->Clone();
141 CPPUNIT_ASSERT_MESSAGE(
"Test clone pointer", prop.GetPointer() != prop2.GetPointer());
142 CPPUNIT_ASSERT_MESSAGE(
"Test equality of the clone", *prop == *prop2);
148 const std::string &strV1,
149 const std::string &strV2)
151 typename T::Pointer prop = T::New(v1);
154 CPPUNIT_ASSERT_MESSAGE(
"Test constructor", prop->GetValue() == v1);
155 std::string msg = std::string(
"Test GetValueAsString() [") + prop->GetValueAsString() +
" == " + strV1 +
"]";
156 CPPUNIT_ASSERT_MESSAGE(msg, prop->GetValueAsString() == strV1);
158 TestPropCloning(prop);
160 typename T::Pointer prop2 = T::New();
161 prop2->AddObserver(itk::ModifiedEvent(), m_L.m_Cmd.GetPointer());
162 CPPUNIT_ASSERT_MESSAGE(
"Test modified", !m_L.m_Modified);
164 CPPUNIT_ASSERT_MESSAGE(
"Test modified", m_L.Pop());
165 CPPUNIT_ASSERT_MESSAGE(
"Test SetValue()", prop2->GetValue() == v2);
167 CPPUNIT_ASSERT_MESSAGE(
"Test for no modification", !m_L.Pop());
169 TestPropInequality(prop, prop2);
170 TestPropAssignment(prop, prop2, strV2);
173 TestPropPolymorphicAssignment(prop2, prop, strV1);
176 void TestBoolProperty_Success()
178 TestProperty<mitk::BoolProperty>(
false,
true,
"0",
"1");
181 void TestIntProperty_Success()
183 TestProperty<mitk::IntProperty>(3, 5,
"3",
"5");
186 void TestFloatProperty_Success()
188 TestProperty<mitk::FloatProperty>(0.3f, -23.5f,
"0.3",
"-23.5");
191 void TestDoubleProperty_Success()
193 TestProperty<mitk::DoubleProperty>(64.1f, 2.34f,
"64.1",
"2.34");
196 void TestVector3DProperty_Success()
206 TestProperty<mitk::Vector3DProperty>(p1, p2,
"[2, 3, 4]",
"[-1, 2, 3]");
209 void TestPoint3D_Success()
219 TestProperty<mitk::Point3dProperty>(p1, p2,
"[2, 3, 4]",
"[-1, 2, 3]");
222 void TestPoint4D_Success()
234 TestProperty<mitk::Point4dProperty>(p1, p2,
"[2, 3, 4, -2]",
"[-1, 2, 3, 5]");
237 void TestPoint3I_Success()
247 TestProperty<mitk::Point3iProperty>(p1, p2,
"[2, 3, 4]",
"[8, 7, 6]");
250 void TestFloatLookupTable_Success()
260 TestProperty<mitk::FloatLookupTableProperty>(lut1, lut2,
"[1 -> 0.3, 4 -> 323.7]",
"[2 -> 25.7, 6 -> -0.3]");
263 void TestBoolLookupTable_Success()
272 TestProperty<mitk::BoolLookupTableProperty>(lut1, lut2,
"[3 -> 0, 5 -> 1]",
"[1 -> 0, 2 -> 0]");
275 void TestIntLookupTable_Success()
285 TestProperty<mitk::IntLookupTableProperty>(lut1, lut2,
"[5 -> -12, 7 -> 3]",
"[4 -> -6, 8 -> -45]");
288 void TestStringLookupTable_Success()
298 TestProperty<mitk::StringLookupTableProperty>(lut1, lut2,
"[0 -> a, 2 -> b]",
"[0 -> a, 2 -> c]");
301 void TestAnnotationProperty_Success()
303 std::string label1(
"Label1");
308 std::string str1 =
"Label1[3, 5, -4]";
310 std::string label2(
"Label2");
315 std::string str2 =
"Label2[-2, 8, -4]";
320 CPPUNIT_ASSERT_MESSAGE(
"Test constructor", prop->GetLabel() == label1 && prop->GetPosition() == point1);
321 std::string msg = std::string(
"Test GetValueAsString() [") + prop->GetValueAsString() +
" == " + str1 +
"]";
322 CPPUNIT_ASSERT_MESSAGE(msg, prop->GetValueAsString() == str1);
325 prop2->AddObserver(itk::ModifiedEvent(), m_L.m_Cmd.GetPointer());
326 CPPUNIT_ASSERT_MESSAGE(
"Test not modified", !m_L.m_Modified);
327 prop2->SetLabel(label2);
328 CPPUNIT_ASSERT_MESSAGE(
"Test modified", m_L.Pop());
329 prop2->SetPosition(point2);
330 CPPUNIT_ASSERT_MESSAGE(
"Test modified", m_L.Pop());
331 CPPUNIT_ASSERT_MESSAGE(
"Test Setter", prop2->GetLabel() == label2 && prop2->GetPosition() == point2);
333 prop2->SetLabel(label2);
334 CPPUNIT_ASSERT_MESSAGE(
"Test for no modification", !m_L.Pop());
335 prop2->SetPosition(point2);
336 CPPUNIT_ASSERT_MESSAGE(
"Test for no modification", !m_L.Pop());
338 TestPropInequality(prop, prop2);
339 TestPropAssignment(prop, prop2, str2);
341 prop->SetLabel(label1);
342 prop->SetPosition(point1);
343 TestPropPolymorphicAssignment(prop2, prop, str1);
346 void TestClippingProperty_Success()
348 bool enabled1 =
true;
357 std::string str1 =
"1[3, 5, -4][0, 2, -1]";
359 bool enabled2 =
false;
368 std::string str2 =
"0[-2, 8, -4][0, 2, 4]";
373 CPPUNIT_ASSERT_MESSAGE(
"Test constructor",
374 prop->GetClippingEnabled() == enabled1 && prop->GetOrigin() == point1 && prop->GetNormal() == vec1);
375 std::string msg = std::string(
"Test GetValueAsString() [") + prop->GetValueAsString() +
" == " + str1 +
"]";
376 CPPUNIT_ASSERT_MESSAGE(msg, prop->GetValueAsString() == str1);
379 prop2->AddObserver(itk::ModifiedEvent(), m_L.m_Cmd.GetPointer());
380 CPPUNIT_ASSERT_MESSAGE(
"Test not modified", !m_L.m_Modified);
381 prop2->SetClippingEnabled(enabled2);
382 CPPUNIT_ASSERT_MESSAGE(
"Test not modified", !m_L.Pop());
383 prop2->SetOrigin(point2);
384 CPPUNIT_ASSERT_MESSAGE(
"Test modified", m_L.Pop());
385 prop2->SetNormal(vec2);
386 CPPUNIT_ASSERT_MESSAGE(
"Test modified", m_L.Pop());
388 CPPUNIT_ASSERT_MESSAGE(
"Test Setter",
389 prop2->GetClippingEnabled() == enabled2 && prop2->GetOrigin() == point2 && prop2->GetNormal() == vec2);
391 prop2->SetClippingEnabled(enabled2);
392 CPPUNIT_ASSERT_MESSAGE(
"Test for no modification", !m_L.Pop());
393 prop2->SetOrigin(point2);
394 CPPUNIT_ASSERT_MESSAGE(
"Test for no modification", !m_L.Pop());
395 prop2->SetNormal(vec2);
396 CPPUNIT_ASSERT_MESSAGE(
"Test for no modification", !m_L.Pop());
398 TestPropInequality(prop, prop2);
399 TestPropAssignment(prop, prop2, str2);
401 prop->SetClippingEnabled(enabled1);
402 prop->SetOrigin(point1);
403 prop->SetNormal(vec1);
404 TestPropPolymorphicAssignment(prop2, prop, str1);
407 void TestColorProperty_Success()
417 TestProperty<mitk::ColorProperty>(c1, c2,
"0.2 0.6 0.8",
"0.2 0.4 0.1");
420 void TestLevelWindowProperty_Success()
424 TestProperty<mitk::LevelWindowProperty>(lw1, lw2,
"L:50 W:100",
"L:120 W:30");
427 void TestSmartPointerProperty_Success()
429 itk::Object::Pointer sp1 = itk::Object::New();
430 itk::Object::Pointer sp2 = itk::Object::New();
435 TestProperty<mitk::SmartPointerProperty>(sp1, sp2, spp1->GetReferenceUIDFor(sp1), spp2->GetReferenceUIDFor(sp2));
438 void TestStringProperty_Success()
440 TestProperty<mitk::StringProperty>(
"1",
"2",
"1",
"2");
443 void TestTransferFunctionProperty_Success()
447 tf2->AddScalarOpacityPoint(0.4, 0.8);
448 std::stringstream ss;
450 std::string strTF1 = ss.str();
453 std::string strTF2 = ss.str();
454 TestProperty<mitk::TransferFunctionProperty>(tf1, tf2, strTF1, strTF2);
457 void TestWeakPointerProperty_Success()
459 itk::Object::Pointer sp1 = itk::Object::New();
460 itk::Object::Pointer sp2 = itk::Object::New();
463 std::stringstream ss;
464 ss << sp1.GetPointer();
465 std::string str1 = ss.str();
467 ss << sp2.GetPointer();
468 std::string str2 = ss.str();
470 TestProperty<mitk::WeakPointerProperty>(wp1, wp2, str1, str2);
473 void TestLookupTablePropertyProperty_Success()
476 lut1->GetVtkLookupTable()->SetTableValue(0, 0.2, 0.3, 0.4);
478 lut2->GetVtkLookupTable()->SetTableValue(0, 0.2, 0.4, 0.4);
479 std::stringstream ss;
481 std::string strLUT1 = ss.str();
484 std::string strLUT2 = ss.str();
485 TestProperty<mitk::LookupTableProperty>(lut1, lut2, strLUT1, strLUT2);
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
void SetTableValue(IdentifierType id, ValueType value)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
#define MITK_TEST_OUTPUT(x)
Output some text.
The LevelWindow class Class to store level/window values.
ValueType
Type of the value held by a Value object.
Test fixture for parameterized tests.
itk::WeakPointer< itk::Object > ValueType
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
specializations of GenericLookupTable