22 #include <boost/lexical_cast.hpp>
45 CPPUNIT_TEST_SUITE(mitkVectorPropertySerializerTestSuite);
50 CPPUNIT_TEST_SUITE_END();
53 void setUp()
override {}
54 void tearDown()
override {}
55 template <
typename DATATYPE>
59 std::vector<DATATYPE> data;
60 data.push_back(-918273674.6172838);
62 data.push_back(+6172838.918273674);
63 data.push_back(sqrt(2));
64 if (std::numeric_limits<DATATYPE>::has_infinity)
66 data.push_back(std::numeric_limits<DATATYPE>::infinity());
67 data.push_back(-std::numeric_limits<DATATYPE>::infinity());
72 vectorProperty->SetValue(data);
74 return vectorProperty;
79 std::string serializername = std::string(property->GetNameOfClass()) +
"Serializer";
81 std::list<itk::LightObject::Pointer> allSerializers =
82 itk::ObjectFactoryBase::CreateAllInstance(serializername.c_str());
83 CPPUNIT_ASSERT_EQUAL(
size_t(1), allSerializers.size());
87 CPPUNIT_ASSERT(serializer !=
nullptr);
91 serializer->SetProperty(property);
92 TiXmlElement *serialization(
nullptr);
95 serialization = serializer->Serialize();
100 CPPUNIT_ASSERT(serialization !=
nullptr);
105 CPPUNIT_ASSERT(restoredProperty.IsNotNull());
106 return restoredProperty;
109 template <
typename DATATYPE>
112 auto property = MakeExampleProperty<DATATYPE>();
117 CPPUNIT_ASSERT(restored_vector_property.IsNotNull());
119 auto orig_vector =
property->
GetValue();
120 auto restored_vector = restored_vector_property->GetValue();
122 CPPUNIT_ASSERT_EQUAL(orig_vector.size(), restored_vector.size());
123 for (
unsigned int i = 0; i < orig_vector.size(); ++i)
126 CPPUNIT_ASSERT_MESSAGE(std::string(
"Verifying element ") + boost::lexical_cast<std::string>(i),
131 void TestSerializeIntTypedef()
134 TestSerialize(intVectorProperty.GetPointer());
137 void TestSerializeDoubleTypedef()
140 TestSerialize(doubleVectorProperty.GetPointer());
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Abstract base class for properties.
virtual const VectorType & GetValue() const
returns a const reference to the contained vector
Test fixture for parameterized tests.
Base class for objects that serialize BaseProperty types.
Providing a std::vector as property.
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.