31 CPPUNIT_TEST_SUITE(mitkPropertyPersistenceTestSuite);
42 CPPUNIT_TEST_SUITE_END();
64 std::string propXTemplate;
65 std::string keyXTemplate;
75 auto finding = std::find_if(infos.begin(), infos.end(), predicate);
77 bool result = finding != infos.end();
107 propX =
"prop(\\d*)";
109 propXTemplate =
"prop$1";
110 keyXTemplate =
"key.$1";
112 propX2 =
"otherprop(\\d*)";
115 info1->SetNameAndKey(prop1,
"key1");
117 info2->SetNameAndKey(prop2,
"key2");
119 info3->SetNameAndKey(prop3,
"key3");
121 info4->SetNameAndKey(prop4,
"key2");
123 info5->SetNameAndKey(prop5,
"key5");
126 infoX->UseRegEx(propX, propXTemplate, keyX, keyXTemplate);
129 infoX2->UseRegEx(propX2, propXTemplate);
131 service->
AddInfo(info1,
false);
132 service->
AddInfo(info2,
false);
133 service->
AddInfo(info3,
false);
134 service->
AddInfo(info4,
false);
135 service->
AddInfo(info5,
false);
136 service->
AddInfo(infoX,
false);
137 service->
AddInfo(infoX2,
false);
140 void tearDown()
override {
delete service; }
144 info2_new->SetNameAndKey(prop2,
"newKey");
146 info2_otherKey->SetNameAndKey(prop2,
"otherKey");
148 info_newPropNKey->SetNameAndKey(
"newProp",
"newKey");
150 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of already existing info (no overwrite) -> no adding",
151 !service->
AddInfo(info2_otherKey,
false));
152 CPPUNIT_ASSERT_MESSAGE(
153 "Testing addinfo of already existing info (no overwrite) -> no adding -> key should not be changed.",
154 service->
GetInfo(prop2,
"mime2",
false).front()->GetKey() ==
"key2");
156 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of already existing info (overwrite) -> adding",
157 service->
AddInfo(info2_otherKey,
true));
158 CPPUNIT_ASSERT_MESSAGE(
159 "Testing addinfo of already existing info (no overwrite) -> adding -> key should be changed.",
160 service->
GetInfo(prop2,
"mime2",
false).front()->GetKey() ==
"otherKey");
162 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of info (other mime type; no overwrite) -> adding",
163 service->
AddInfo(info2_new,
false));
164 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of info (other mime type; no overwrite) -> adding -> info exists.",
165 !service->
GetInfo(prop2,
"otherMime",
false).empty());
167 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of info (new prop name; no overwrite) -> adding",
168 service->
AddInfo(info_newPropNKey,
false));
169 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of info (new prop name; no overwrite) -> adding ->info exists.",
170 !service->
GetInfo(
"newProp",
"otherMime",
false).empty());
176 CPPUNIT_ASSERT(infos.size() == 3);
177 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info1));
178 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info2));
179 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info3));
181 infos = service->
GetInfo(prop4,
false);
182 CPPUNIT_ASSERT(infos.size() == 1);
183 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info4));
185 infos = service->
GetInfo(
"unkown",
false);
186 CPPUNIT_ASSERT_MESSAGE(
"Check size of result for unkown prop.", infos.empty());
188 infos = service->
GetInfo(
"prop101",
false);
189 CPPUNIT_ASSERT(infos.empty());
191 infos = service->
GetInfo(
"prop101",
true);
192 CPPUNIT_ASSERT(infos.size() == 1);
193 CPPUNIT_ASSERT_MESSAGE(
"Check Name of expected element 1.", infos.front()->GetName() ==
"prop101");
194 CPPUNIT_ASSERT_MESSAGE(
"Check Key of expected element 1.", infos.front()->GetKey() ==
"key.101");
195 CPPUNIT_ASSERT_MESSAGE(
"Check MimeTypeName of expected element 1.", infos.front()->GetMimeTypeName() ==
"mimeX");
201 CPPUNIT_ASSERT(infos.size() == 2);
202 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info2));
203 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 2.", checkExistance(infos, info4));
206 CPPUNIT_ASSERT(infos.size() == 1);
207 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info5));
210 CPPUNIT_ASSERT_MESSAGE(
"Check size of result for unkown key.", infos.empty());
213 CPPUNIT_ASSERT_MESSAGE(
"Check size of result for key101.", infos.empty());
216 CPPUNIT_ASSERT(infos.size() == 1);
217 CPPUNIT_ASSERT_MESSAGE(
"Check Name of expected element 1.", infos.front()->GetName() ==
"prop101");
218 CPPUNIT_ASSERT_MESSAGE(
"Check Key of expected element 1.", infos.front()->GetKey() ==
"key101");
219 CPPUNIT_ASSERT_MESSAGE(
"Check MimeTypeName of expected element 1.", infos.front()->GetMimeTypeName() ==
"mimeX");
225 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (existing element, no wildcard allowed, wildcard exists).",
226 infosAreEqual(info2, infos.front()));
227 infos = service->
GetInfo(prop1,
"mime2",
true,
false);
228 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (existing element, wildcard allowed, wildcard exists).",
229 infosAreEqual(info2, infos.front()));
230 infos = service->
GetInfo(prop1,
"unknownmime",
false,
false);
231 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting element, no wildcard allowed, wildcard exists).", infos.empty());
232 infos = service->
GetInfo(prop1,
"unknownmime",
true,
false);
233 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting element, wildcard allowed, wildcard exists).",
234 infosAreEqual(info1, infos.front()));
236 infos = service->
GetInfo(prop4,
"unknownmime",
false,
false);
237 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting element, no wildcard allowed).", infos.empty());
238 infos = service->
GetInfo(prop4,
"unknownmime",
true,
false);
239 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting element, wildcard allowed).", infos.empty());
241 infos = service->
GetInfo(
"prop101",
"unknownmime",
false,
true);
242 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting mime, no wildcard allowed, regex allowed).", infos.empty());
244 infos = service->
GetInfo(
"prop101",
"mimeX",
false,
true);
245 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (existing mime, no wildcard allowed, regex allowed).", infos.size() == 1);
247 infos = service->
GetInfo(
"otherprop",
"unknownmime",
false,
false);
248 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting mime, no wildcard allowed, no regex allowed).", infos.empty());
250 infos = service->
GetInfo(
"otherprop",
"unknownmime",
true,
false);
251 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting mime, wildcard allowed, no regex allowed).", infos.empty());
253 infos = service->
GetInfo(
"otherprop",
"unknownmime",
false,
true);
254 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting mime, no wildcard allowed, regex allowed).", infos.empty());
256 infos = service->
GetInfo(
"otherprop",
"unknownmime",
true,
true);
257 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting mime, wildcard allowed, regex allowed).", infos.size() == 1);
262 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop1)", service->
HasInfo(prop1));
263 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop4)", service->
HasInfo(prop4));
264 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (unkown prop)", !service->
HasInfo(
"unkownProp"));
270 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop1)", !service->
HasInfo(prop1));
271 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop4)", !service->
HasInfo(prop4));
272 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop5)", !service->
HasInfo(prop5));
277 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(prop1));
278 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop1)", !service->
HasInfo(prop1,
false));
279 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop4)", service->
HasInfo(prop4,
false));
280 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop5)", service->
HasInfo(prop5,
false));
282 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(prop4));
283 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop4)", !service->
HasInfo(prop4,
false));
284 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop5)", service->
HasInfo(prop5,
false));
286 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(prop5));
287 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop5)", !service->
HasInfo(prop5,
false));
289 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(
"unknown_prop"));
292 void RemoveInfo_withMime()
294 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(prop1,
"mime2"));
295 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos if info was removed", service->
GetInfo(prop1,
"mime2",
false).empty());
296 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos, if other info of same property name still exists",
297 !service->
GetInfo(prop1,
"mime3",
false).empty());
298 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos, if other info of other property name but same mime still exists",
299 !service->
GetInfo(prop4,
"mime2",
false).empty());
301 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(prop5,
"wrongMime"));
302 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos on prop 5 with wrong mime", service->
HasInfo(prop5,
false));
304 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(prop5,
"mime5"));
305 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos on prop 5", !service->
HasInfo(prop5,
false));
307 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(
"unkown_prop",
"mime2"));
308 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos, if unkown property name but exting mime was used",
309 service->
HasInfo(prop4,
false));
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
std::string GetName() const
virtual void RemoveInfo(const std::string &propertyName)=0
Remove persistence info instances of a specific property name/regex.
virtual InfoResultType GetInfoByKey(const std::string &persistenceKey, bool allowKeyRegEx=true) const =0
Get the persistence info that will use the specified key.
virtual void RemoveAllInfo()=0
Remove all persistence info.
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
virtual bool HasInfo(const std::string &propertyName, bool allowNameRegEx=true) const =0
Check if a specific base data property has persistence info.
std::string GetKey() const
MITKCORE_EXPORT IPropertyPersistence * CreateTestInstancePropertyPersistence()
IPropertyPersistence::InfoResultType InfoResultType
static void info(const char *fmt,...)
Property persistence info. This class is used to specify the way the persistance of a property of Bas...
virtual InfoResultType GetInfo(const std::string &propertyName, bool allowNameRegEx=true) const =0
Get the persistence info for a specific base data property.
Test fixture for parameterized tests.
const MimeTypeNameType & GetMimeTypeName() const
Interface of property persistence service.
virtual bool AddInfo(const PropertyPersistenceInfo *info, bool overwrite=false)=0
Add persistence info for a specific base data property. If there is already a property info instance ...