23 return "testSerialize";
29 return result.GetPointer();
34 CPPUNIT_TEST_SUITE(mitkPropertyPersistenceInfoTestSuite);
49 CPPUNIT_TEST_SUITE_END();
53 std::string refSerialization;
55 std::string refSerialization_testFunction;
59 std::string nameRegEx;
61 std::string nameTemplate;
62 std::string keyTemplate;
67 refSerialization =
"my_shiny_test_value";
70 refSerialization_testFunction =
"testSerialize";
73 nameRegEx =
"name(\\d*)";
74 nameTemplate =
"$1_name";
75 keyRegEx =
"key(\\d*)";
76 keyTemplate =
"newkey_[$1]";
79 regexInfo->UseRegEx(nameRegEx, nameTemplate, keyRegEx, keyTemplate);
82 void tearDown()
override {}
83 void CheckDefaultInfo()
85 CPPUNIT_ASSERT_MESSAGE(
86 "Testing PropertyPersistenceInfo::ANY_MIMETYPE_NAME()",
88 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::GetName()", info->GetName() ==
"");
89 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::GetKey()", info->GetKey() ==
"");
90 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::GetMimeTypeName()",
92 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::IsRegEx()", !info->IsRegEx());
94 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::IsRegEx()", regexInfo->IsRegEx());
97 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::GetDeserializationFunction() producing a StringProperty",
98 dynamic_cast<mitk::StringProperty *>(prop.GetPointer()));
99 CPPUNIT_ASSERT_MESSAGE(
100 "Testing PropertyPersistenceInfo::GetDeserializationFunction() producing a StringProperty with correct value",
101 prop->GetValueAsString() == refSerialization);
103 std::string value = info->GetSerializationFunction()(refProp);
104 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::GetSerializationFunction()", value == refSerialization);
109 info->SetName(
"MyName");
110 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::SetKey() changed name", info->GetName() ==
"MyName");
111 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::SetKey() changed key", info->GetKey() ==
"MyName");
114 regexInfo->SetName(
"MyName");
115 CPPUNIT_ASSERT_MESSAGE(
"Testing regex reset when using SetName()", !regexInfo->IsRegEx());
120 info->SetNameAndKey(
"MyName",
"MyKey");
121 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::SetNameAndKey() changed name",
122 info->GetName() ==
"MyName");
123 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::SetNameAndKey() changed key", info->GetKey() ==
"MyKey");
126 regexInfo->SetNameAndKey(
"MyName",
"MyKey");
127 CPPUNIT_ASSERT_MESSAGE(
"Testing regex reset when using SetNameAndKey()", !regexInfo->IsRegEx());
130 void SetMimeTypeName()
132 info->SetMimeTypeName(
"newMime");
133 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::SetMimeTypeName()", info->GetMimeTypeName() ==
"newMime");
138 info->UseRegEx(nameRegEx, nameTemplate);
139 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::IsRegEx()", info->IsRegEx());
140 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::UseRegEx() changed name", info->GetName() == nameRegEx);
141 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::UseRegEx() changed key", info->GetKey() == nameRegEx);
142 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::UseRegEx() changed name template",
143 info->GetNameTemplate() == nameTemplate);
144 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::UseRegEx() changed key template",
145 info->GetKeyTemplate() == nameTemplate);
150 info->UseRegEx(nameRegEx, nameTemplate, keyRegEx, keyTemplate);
151 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::IsRegEx()", info->IsRegEx());
152 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::UseRegEx() changed name", info->GetName() == nameRegEx);
153 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::UseRegEx() changed key", info->GetKey() == keyRegEx);
154 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::UseRegEx() changed name template",
155 info->GetNameTemplate() == nameTemplate);
156 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::UseRegEx() changed key template",
157 info->GetKeyTemplate() == keyTemplate);
163 CPPUNIT_ASSERT_MESSAGE(
"Testing IsRegEx() of \"unreg\"ed regexInfo", !newInfo->IsRegEx());
164 CPPUNIT_ASSERT_MESSAGE(
"Testing GetName() of \"unreg\"ed regexInfo", newInfo->GetName() ==
"name42");
165 CPPUNIT_ASSERT_MESSAGE(
"Testing GetKey() of \"unreg\"ed regexInfo", newInfo->GetKey() ==
"newkey_[42]");
167 newInfo = info->UnRegExByName(
"name42");
168 CPPUNIT_ASSERT_MESSAGE(
"Testing IsRegEx() of \"unreg\"ed info", !newInfo->IsRegEx());
169 CPPUNIT_ASSERT_MESSAGE(
"Testing GetName() of \"unreg\"ed info", newInfo->GetName() == info->GetName());
170 CPPUNIT_ASSERT_MESSAGE(
"Testing GetKey() of \"unreg\"ed info", newInfo->GetKey() == info->GetKey());
176 CPPUNIT_ASSERT_MESSAGE(
"Testing IsRegEx() of \"unreg\"ed regexInfo", !newInfo->IsRegEx());
177 CPPUNIT_ASSERT_MESSAGE(
"Testing GetName() of \"unreg\"ed regexInfo", newInfo->GetName() ==
"42_name");
178 CPPUNIT_ASSERT_MESSAGE(
"Testing GetKey() of \"unreg\"ed regexInfo", newInfo->GetKey() ==
"key42");
180 newInfo = info->UnRegExByKey(
"key42");
181 CPPUNIT_ASSERT_MESSAGE(
"Testing IsRegEx() of \"unreg\"ed info", !newInfo->IsRegEx());
182 CPPUNIT_ASSERT_MESSAGE(
"Testing GetName() of \"unreg\"ed info", newInfo->GetName() == info->GetName());
183 CPPUNIT_ASSERT_MESSAGE(
"Testing GetKey() of \"unreg\"ed info", newInfo->GetKey() == info->GetKey());
186 void SetDeserializationFunction()
190 CPPUNIT_ASSERT_MESSAGE(
191 "Testing PropertyPersistenceInfo::SetDeserializationFunction() producing a StringProperty with correct value",
192 prop->GetValueAsString() == refSerialization_testFunction);
195 void SetSerializationFunction()
198 std::string value = info->GetSerializationFunction()(refProp);
199 CPPUNIT_ASSERT_MESSAGE(
"Testing PropertyPersistenceInfo::SetSerializationFunction()",
200 value == refSerialization_testFunction);
206 CPPUNIT_ASSERT_MESSAGE(
"Testing serializeByGetValueAsString()", value == refSerialization);
213 CPPUNIT_ASSERT_MESSAGE(
"Testing deserializeToStringProperty() producing a StringProperty",
214 dynamic_cast<mitk::StringProperty *>(prop.GetPointer()));
215 CPPUNIT_ASSERT_MESSAGE(
"Testing deserializeToStringProperty() producing a StringProperty with correct value",
216 prop->GetValueAsString() == refSerialization);
static MimeTypeNameType ANY_MIMETYPE_NAME()
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
MITKCORE_EXPORT::std::string serializeByGetValueAsString(const mitk::BaseProperty *prop)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
MITKCORE_EXPORT mitk::BaseProperty::Pointer deserializeToStringProperty(const std::string &value)
static void info(const char *fmt,...)
Abstract base class for properties.
static std::string DEFAULT_BASE_NAME()
mitk::BaseProperty::Pointer testDeserializeFunction(const std::string &)
Test fixture for parameterized tests.
::std::string testSerializeFunction(const mitk::BaseProperty *)