26 CPPUNIT_TEST_SUITE(mitkPropertyRelationsTestSuite);
31 MITK_TEST(GetRulesForDestinationCandidate);
38 CPPUNIT_TEST_SUITE_END();
61 auto finding = std::find_if(rules.begin(), rules.end(), predicate);
63 bool result = finding != rules.end();
79 unRelated->SetName(
"unRelated");
82 destination->SetName(
"destination");
85 source_1->SetName(
"source_1");
86 rule1->Connect(source_1, destination);
89 source_1n2->SetName(
"source_1n2");
90 rule1->Connect(source_1n2, destination);
91 rule2->Connect(source_1n2, destination);
94 source_2->SetName(
"source_2");
95 rule2->Connect(source_2, destination);
98 source_4->SetName(
"source_4");
99 rule4->Connect(source_4, destination);
101 service->
AddRule(rule1,
false);
102 service->
AddRule(rule2,
false);
103 service->
AddRule(rule3,
false);
104 service->
AddRule(rule4,
false);
107 void tearDown()
override {
delete service; }
113 CPPUNIT_ASSERT_MESSAGE(
"Testing addrule of already existing rule (no overwrite) -> failed",
114 !service->
AddRule(rule2_new,
false));
115 CPPUNIT_ASSERT(service->
GetRule(rule2->GetRuleID()).GetPointer() == rule2.GetPointer());
117 CPPUNIT_ASSERT_MESSAGE(
"Testing addrule of already existing rule (overwrite) -> failed, was not added.",
118 service->
AddRule(rule2_new,
true));
119 CPPUNIT_ASSERT(service->
GetRule(rule2->GetRuleID()).GetPointer() == rule2_new.GetPointer());
122 CPPUNIT_ASSERT(service->
GetRule(unkownRule->GetRuleID()).IsNull());
123 CPPUNIT_ASSERT(service->
AddRule(unkownRule));
124 CPPUNIT_ASSERT(service->
GetRule(unkownRule->GetRuleID()).IsNotNull());
126 CPPUNIT_ASSERT(!service->
AddRule(
nullptr));
129 void GetRulesForSource()
132 CPPUNIT_ASSERT(rules.size() == 1);
133 CPPUNIT_ASSERT(checkExistence(rules, rule1));
136 CPPUNIT_ASSERT(rules.size() == 2);
137 CPPUNIT_ASSERT(checkExistence(rules, rule1));
138 CPPUNIT_ASSERT(checkExistence(rules, rule2));
141 CPPUNIT_ASSERT(rules.size() == 0);
144 CPPUNIT_ASSERT(rules.size() == 0);
147 void GetRulesForSourceCandidate()
150 CPPUNIT_ASSERT(rules.size() == 4);
151 CPPUNIT_ASSERT(checkExistence(rules, rule1));
152 CPPUNIT_ASSERT(checkExistence(rules, rule2));
153 CPPUNIT_ASSERT(checkExistence(rules, rule3));
154 CPPUNIT_ASSERT(checkExistence(rules, rule4));
157 CPPUNIT_ASSERT(rules.size() == 0);
160 void GetRulesForDestinationCandidate()
163 CPPUNIT_ASSERT(rules.size() == 4);
164 CPPUNIT_ASSERT(checkExistence(rules, rule1));
165 CPPUNIT_ASSERT(checkExistence(rules, rule2));
166 CPPUNIT_ASSERT(checkExistence(rules, rule3));
167 CPPUNIT_ASSERT(checkExistence(rules, rule4));
170 CPPUNIT_ASSERT(rules.size() == 0);
175 auto rule = service->
GetRule(rule3->GetRuleID());
176 CPPUNIT_ASSERT(rule.IsNotNull());
177 rule = service->
GetRule(rule1->GetRuleID());
178 CPPUNIT_ASSERT(rule.IsNotNull());
179 rule = service->
GetRule(rule2->GetRuleID());
180 CPPUNIT_ASSERT(rule.IsNotNull());
181 rule = service->
GetRule(rule4->GetRuleID());
182 CPPUNIT_ASSERT(rule.IsNotNull());
184 rule = service->
GetRule(unkownRule->GetRuleID());
185 CPPUNIT_ASSERT(rule.IsNull());
192 CPPUNIT_ASSERT(ruleIDs.size()==4);
193 CPPUNIT_ASSERT(std::find(ruleIDs.begin(), ruleIDs.end(), rule1->GetRuleID()) != ruleIDs.end());
194 CPPUNIT_ASSERT(std::find(ruleIDs.begin(), ruleIDs.end(), rule2->GetRuleID()) != ruleIDs.end());
195 CPPUNIT_ASSERT(std::find(ruleIDs.begin(), ruleIDs.end(), rule3->GetRuleID()) != ruleIDs.end());
196 CPPUNIT_ASSERT(std::find(ruleIDs.begin(), ruleIDs.end(), rule4->GetRuleID()) != ruleIDs.end());
199 void HasRuleForSource()
209 CPPUNIT_ASSERT_NO_THROW(service->
RemoveRule(rule1->GetRuleID()));
210 CPPUNIT_ASSERT(!service->
GetRule(rule1->GetRuleID()));
211 CPPUNIT_ASSERT(service->
GetRule(rule2->GetRuleID()));
212 CPPUNIT_ASSERT(service->
GetRule(rule3->GetRuleID()));
213 CPPUNIT_ASSERT(service->
GetRule(rule4->GetRuleID()));
215 CPPUNIT_ASSERT_NO_THROW(service->
RemoveRule(rule3->GetRuleID()));
216 CPPUNIT_ASSERT(!service->
GetRule(rule1->GetRuleID()));
217 CPPUNIT_ASSERT(service->
GetRule(rule2->GetRuleID()));
218 CPPUNIT_ASSERT(!service->
GetRule(rule3->GetRuleID()));
219 CPPUNIT_ASSERT(service->
GetRule(rule4->GetRuleID()));
221 CPPUNIT_ASSERT_NO_THROW(service->
RemoveRule(
"unknown_rule"));
222 CPPUNIT_ASSERT(!service->
GetRule(rule1->GetRuleID()));
223 CPPUNIT_ASSERT(service->
GetRule(rule2->GetRuleID()));
224 CPPUNIT_ASSERT(!service->
GetRule(rule3->GetRuleID()));
225 CPPUNIT_ASSERT(service->
GetRule(rule4->GetRuleID()));
228 void RemoveAllRules()
231 CPPUNIT_ASSERT(service->
GetRuleIDs().empty());
virtual RuleIDType GetRuleID() const =0
Interface of property relations service.
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
virtual void RemoveRule(const RuleIDType &ruleID)=0
Remove relation rule instance with the passed ID. If rule does not exist nothing happens.
virtual RuleResultVectorType GetRulesForSource(const IPropertyProvider *source) const =0
Get all relation rules the passed source is really a source of. (PropertyRelationRuleBase::IsSource()...
virtual RuleResultVectorType GetRulesForDestinationCandidate(const IPropertyProvider *destCandidate) const =0
Get all relation rules that would accept the passed IPropertOwner as destination. ...
static Pointer New(const RuleIDType &_arg)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
MITKCORE_EXPORT IPropertyRelations * CreateTestInstancePropertyRelations()
virtual void RemoveAllRules()=0
Remove all relation rules.
Test fixture for parameterized tests.
IPropertyRelations::RuleResultVectorType RuleResultVectorType
virtual PropertyRelationRuleBase::ConstPointer GetRule(const RuleIDType &ruleID) const =0
Get the relation rule that has the specfied ruleID.
virtual RuleResultVectorType GetRulesForSourceCandidate(const IPropertyProvider *sourceCandidate) const =0
Get all relation rules that would accept the passed IPropertOwner as source.
virtual RuleIDVectorType GetRuleIDs() const =0
Get all IDs of registered rules.
virtual bool HasRuleForSource(const IPropertyProvider *source) const =0
Check if a passed instance has defined relation covered by the registered rules.
virtual bool AddRule(const PropertyRelationRuleBase *rule, bool overwrite=false)=0
Add rule for a specific relation. If there is already a property rule instance it won't be added...