27 CPPUNIT_TEST_SUITE(mitkPropertyPersistenceTestSuite);
38 CPPUNIT_TEST_SUITE_END();
60 std::string propXTemplate;
61 std::string keyXTemplate;
71 auto finding = std::find_if(infos.begin(), infos.end(), predicate);
73 bool result = finding != infos.end();
103 propX =
"prop(\\d*)";
105 propXTemplate =
"prop$1";
106 keyXTemplate =
"key.$1";
108 propX2 =
"otherprop(\\d*)";
111 info1->SetNameAndKey(prop1,
"key1");
113 info2->SetNameAndKey(prop2,
"key2");
115 info3->SetNameAndKey(prop3,
"key3");
117 info4->SetNameAndKey(prop4,
"key2");
119 info5->SetNameAndKey(prop5,
"key5");
122 infoX->UseRegEx(propX, propXTemplate, keyX, keyXTemplate);
125 infoX2->UseRegEx(propX2, propXTemplate);
127 service->
AddInfo(info1,
false);
128 service->
AddInfo(info2,
false);
129 service->
AddInfo(info3,
false);
130 service->
AddInfo(info4,
false);
131 service->
AddInfo(info5,
false);
132 service->
AddInfo(infoX,
false);
133 service->
AddInfo(infoX2,
false);
136 void tearDown()
override {
delete service; }
140 info2_new->SetNameAndKey(prop2,
"newKey");
142 info2_otherKey->SetNameAndKey(prop2,
"otherKey");
144 info_newPropNKey->SetNameAndKey(
"newProp",
"newKey");
146 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of already existing info (no overwrite) -> no adding",
147 !service->
AddInfo(info2_otherKey,
false));
148 CPPUNIT_ASSERT_MESSAGE(
149 "Testing addinfo of already existing info (no overwrite) -> no adding -> key should not be changed.",
150 service->
GetInfo(prop2,
"mime2",
false).front()->GetKey() ==
"key2");
152 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of already existing info (overwrite) -> adding",
153 service->
AddInfo(info2_otherKey,
true));
154 CPPUNIT_ASSERT_MESSAGE(
155 "Testing addinfo of already existing info (no overwrite) -> adding -> key should be changed.",
156 service->
GetInfo(prop2,
"mime2",
false).front()->GetKey() ==
"otherKey");
158 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of info (other mime type; no overwrite) -> adding",
159 service->
AddInfo(info2_new,
false));
160 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of info (other mime type; no overwrite) -> adding -> info exists.",
161 !service->
GetInfo(prop2,
"otherMime",
false).empty());
163 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of info (new prop name; no overwrite) -> adding",
164 service->
AddInfo(info_newPropNKey,
false));
165 CPPUNIT_ASSERT_MESSAGE(
"Testing addinfo of info (new prop name; no overwrite) -> adding ->info exists.",
166 !service->
GetInfo(
"newProp",
"otherMime",
false).empty());
172 CPPUNIT_ASSERT(infos.size() == 3);
173 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info1));
174 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info2));
175 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info3));
177 infos = service->
GetInfo(prop4,
false);
178 CPPUNIT_ASSERT(infos.size() == 1);
179 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info4));
181 infos = service->
GetInfo(
"unkown",
false);
182 CPPUNIT_ASSERT_MESSAGE(
"Check size of result for unkown prop.", infos.empty());
184 infos = service->
GetInfo(
"prop101",
false);
185 CPPUNIT_ASSERT(infos.empty());
187 infos = service->
GetInfo(
"prop101",
true);
188 CPPUNIT_ASSERT(infos.size() == 1);
189 CPPUNIT_ASSERT_MESSAGE(
"Check Name of expected element 1.", infos.front()->GetName() ==
"prop101");
190 CPPUNIT_ASSERT_MESSAGE(
"Check Key of expected element 1.", infos.front()->GetKey() ==
"key.101");
191 CPPUNIT_ASSERT_MESSAGE(
"Check MimeTypeName of expected element 1.", infos.front()->GetMimeTypeName() ==
"mimeX");
197 CPPUNIT_ASSERT(infos.size() == 2);
198 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info2));
199 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 2.", checkExistance(infos, info4));
202 CPPUNIT_ASSERT(infos.size() == 1);
203 CPPUNIT_ASSERT_MESSAGE(
"Check expected element 1.", checkExistance(infos, info5));
206 CPPUNIT_ASSERT_MESSAGE(
"Check size of result for unkown key.", infos.empty());
209 CPPUNIT_ASSERT_MESSAGE(
"Check size of result for key101.", infos.empty());
212 CPPUNIT_ASSERT(infos.size() == 1);
213 CPPUNIT_ASSERT_MESSAGE(
"Check Name of expected element 1.", infos.front()->GetName() ==
"prop101");
214 CPPUNIT_ASSERT_MESSAGE(
"Check Key of expected element 1.", infos.front()->GetKey() ==
"key101");
215 CPPUNIT_ASSERT_MESSAGE(
"Check MimeTypeName of expected element 1.", infos.front()->GetMimeTypeName() ==
"mimeX");
221 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (existing element, no wildcard allowed, wildcard exists).",
222 infosAreEqual(info2, infos.front()));
223 infos = service->
GetInfo(prop1,
"mime2",
true,
false);
224 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (existing element, wildcard allowed, wildcard exists).",
225 infosAreEqual(info2, infos.front()));
226 infos = service->
GetInfo(prop1,
"unknownmime",
false,
false);
227 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting element, no wildcard allowed, wildcard exists).", infos.empty());
228 infos = service->
GetInfo(prop1,
"unknownmime",
true,
false);
229 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting element, wildcard allowed, wildcard exists).",
230 infosAreEqual(info1, infos.front()));
232 infos = service->
GetInfo(prop4,
"unknownmime",
false,
false);
233 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting element, no wildcard allowed).", infos.empty());
234 infos = service->
GetInfo(prop4,
"unknownmime",
true,
false);
235 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting element, wildcard allowed).", infos.empty());
237 infos = service->
GetInfo(
"prop101",
"unknownmime",
false,
true);
238 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting mime, no wildcard allowed, regex allowed).", infos.empty());
240 infos = service->
GetInfo(
"prop101",
"mimeX",
false,
true);
241 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (existing mime, no wildcard allowed, regex allowed).", infos.size() == 1);
243 infos = service->
GetInfo(
"otherprop",
"unknownmime",
false,
false);
244 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting mime, no wildcard allowed, no regex allowed).", infos.empty());
246 infos = service->
GetInfo(
"otherprop",
"unknownmime",
true,
false);
247 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting mime, wildcard allowed, no regex allowed).", infos.empty());
249 infos = service->
GetInfo(
"otherprop",
"unknownmime",
false,
true);
250 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting mime, no wildcard allowed, regex allowed).", infos.empty());
252 infos = service->
GetInfo(
"otherprop",
"unknownmime",
true,
true);
253 CPPUNIT_ASSERT_MESSAGE(
"Check GetInfos (inexisting mime, wildcard allowed, regex allowed).", infos.size() == 1);
258 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop1)", service->
HasInfo(prop1));
259 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop4)", service->
HasInfo(prop4));
260 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (unkown prop)", !service->
HasInfo(
"unkownProp"));
266 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop1)", !service->
HasInfo(prop1));
267 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop4)", !service->
HasInfo(prop4));
268 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop5)", !service->
HasInfo(prop5));
273 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(prop1));
274 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop1)", !service->
HasInfo(prop1,
false));
275 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop4)", service->
HasInfo(prop4,
false));
276 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop5)", service->
HasInfo(prop5,
false));
278 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(prop4));
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(prop5));
283 CPPUNIT_ASSERT_MESSAGE(
"Check HasInfos (prop5)", !service->
HasInfo(prop5,
false));
285 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(
"unknown_prop"));
288 void RemoveInfo_withMime()
290 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(prop1,
"mime2"));
291 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos if info was removed", service->
GetInfo(prop1,
"mime2",
false).empty());
292 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos, if other info of same property name still exists",
293 !service->
GetInfo(prop1,
"mime3",
false).empty());
294 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos, if other info of other property name but same mime still exists",
295 !service->
GetInfo(prop4,
"mime2",
false).empty());
297 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(prop5,
"wrongMime"));
298 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos on prop 5 with wrong mime", service->
HasInfo(prop5,
false));
300 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(prop5,
"mime5"));
301 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos on prop 5", !service->
HasInfo(prop5,
false));
303 CPPUNIT_ASSERT_NO_THROW(service->
RemoveInfo(
"unkown_prop",
"mime2"));
304 CPPUNIT_ASSERT_MESSAGE(
"Check RemoveInfos, if unkown property name but exting mime was used",
305 service->
HasInfo(prop4,
false));
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
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.
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...
const MimeTypeNameType & GetMimeTypeName() const
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.
std::string GetKey() 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 ...
std::string GetName() const