29 CPPUNIT_TEST_SUITE(mitkSourceImageRelationRuleTestSuite);
38 MITK_TEST(GetDestinationCandidateIndicator);
48 CPPUNIT_TEST_SUITE_END();
80 if (!instance.empty())
82 keyPath.AddElement(instance);
88 for (
const auto &key : keys)
90 if (key.find(prefix) == 0)
102 std::vector<std::string> result;
106 if (destInstanceUIDProp.IsNull())
115 auto regEx = std::regex(sourceRegExStr);
117 std::vector<std::string> keys;
122 for (
const auto &key : keys)
124 if (std::regex_match(key, regEx))
127 if (*refUIDProp == *destInstanceUIDProp)
138 void SetDICOMReferenceInfo(
mitk::IPropertyOwner* owner,
const std::string& instanceUID,
const std::string& classUID,
const std::string& purpose,
unsigned int sequElement)
153 bool IsCorrectDICOMReference(
const mitk::IPropertyOwner* owner,
const std::string& instanceUID,
const std::string& classUID,
const std::string& purpose,
unsigned int sequElement)
const 158 if (prop->GetValueAsString() != instanceUID)
166 if (prop->GetValueAsString() != classUID)
174 if (prop->GetValueAsString() != purpose)
184 void setUp()
override 197 unRelated_Node->SetData(unRelated);
200 dest_1_Node->SetName(
"dest_1");
204 dest_1_Node->SetData(dest_1);
209 dest_2_Node->SetName(
"dest_2");
213 dest_2_Node->SetData(dest_2);
216 SetDICOMReferenceInfo(source_implicit_1,
"dest_1",
"image",
"Test", 0);
218 source_implicit_1_Node->SetData(source_implicit_1);
221 std::string name =
"MITK.Relations.1.relationUID";
223 name =
"MITK.Relations.1.destinationUID";
225 name =
"MITK.Relations.1.ruleID";
228 source_idOnly_1_Node->SetData(source_idOnly_1);
231 SetDICOMReferenceInfo(source_data_1,
"dest_1",
"image",
"Test", 0);
232 SetDICOMReferenceInfo(source_data_1,
"dest_2",
"image",
"otherpurpose", 1);
233 name =
"MITK.Relations.1.relationUID";
235 name =
"MITK.Relations.1.ruleID";
237 name =
"MITK.Relations.1.SourceImageSequenceItem";
239 name =
"MITK.Relations.2.relationUID";
241 name =
"MITK.Relations.2.SourceImageSequenceItem";
243 name =
"MITK.Relations.2.ruleID";
246 source_data_1_Node->SetData(source_data_1);
249 SetDICOMReferenceInfo(source_1,
"dest_1",
"image",
"Test", 0);
250 SetDICOMReferenceInfo(source_1,
"dest_2",
"image",
"otherpurpose", 1);
251 name =
"MITK.Relations.1.relationUID";
253 name =
"MITK.Relations.1.destinationUID";
255 name =
"MITK.Relations.1.ruleID";
257 name =
"MITK.Relations.1.SourceImageSequenceItem";
259 name =
"MITK.Relations.2.relationUID";
261 name =
"MITK.Relations.2.destinationUID";
263 name =
"MITK.Relations.2.ruleID";
265 name =
"MITK.Relations.2.SourceImageSequenceItem";
268 source_1_Node->SetData(source_1);
271 name =
"MITK.Relations.1.relationUID";
273 name =
"MITK.Relations.1.destinationUID";
275 name =
"MITK.Relations.1.ruleID";
278 source_otherRule_Node->SetData(source_otherRule);
281 name =
"MITK.Relations.1.relationUID";
283 name =
"MITK.Relations.1.destinationUID";
285 name =
"MITK.Relations.1.ruleID";
288 source_otherPurpose_Node->SetData(source_otherPurpose);
291 void tearDown()
override {}
293 void IsSourceCandidate()
296 CPPUNIT_ASSERT(!rule->IsSourceCandidate(
nullptr));
299 void IsDestinationCandidate()
301 CPPUNIT_ASSERT(rule->IsDestinationCandidate(this->dest_1_Node));
302 CPPUNIT_ASSERT(rule->IsDestinationCandidate(this->dest_1));
304 CPPUNIT_ASSERT(!rule->IsDestinationCandidate(
nullptr));
309 CPPUNIT_ASSERT_THROW_MESSAGE(
310 "Violated precondition (nullptr) does not throw.", rule->IsSource(
nullptr), itk::ExceptionObject);
312 CPPUNIT_ASSERT(!rule->IsSource(unRelated));
313 CPPUNIT_ASSERT(!rule->IsSource(source_implicit_1));
314 CPPUNIT_ASSERT(rule->IsSource(source_data_1));
315 CPPUNIT_ASSERT(rule->IsSource(source_idOnly_1));
316 CPPUNIT_ASSERT(rule->IsSource(source_1));
318 CPPUNIT_ASSERT(!rule->IsSource(source_otherRule));
319 CPPUNIT_ASSERT(!rule->IsSource(source_otherPurpose));
321 CPPUNIT_ASSERT(!rule->IsSource(source_implicit_1_Node));
322 CPPUNIT_ASSERT(rule->IsSource(source_data_1_Node));
323 CPPUNIT_ASSERT(rule->IsSource(source_idOnly_1_Node));
324 CPPUNIT_ASSERT(rule->IsSource(source_1_Node));
326 CPPUNIT_ASSERT(!rule->IsSource(source_otherRule_Node));
327 CPPUNIT_ASSERT(!rule->IsSource(source_otherPurpose_Node));
330 CPPUNIT_ASSERT(!abstractRule->IsSource(unRelated));
331 CPPUNIT_ASSERT(!abstractRule->IsSource(source_implicit_1));
332 CPPUNIT_ASSERT(abstractRule->IsSource(source_data_1));
333 CPPUNIT_ASSERT(abstractRule->IsSource(source_idOnly_1));
334 CPPUNIT_ASSERT(abstractRule->IsSource(source_1));
336 CPPUNIT_ASSERT(!abstractRule->IsSource(source_otherRule));
337 CPPUNIT_ASSERT(abstractRule->IsSource(source_otherPurpose));
339 CPPUNIT_ASSERT(!abstractRule->IsSource(unRelated_Node));
340 CPPUNIT_ASSERT(!abstractRule->IsSource(source_implicit_1_Node));
341 CPPUNIT_ASSERT(abstractRule->IsSource(source_data_1_Node));
342 CPPUNIT_ASSERT(abstractRule->IsSource(source_idOnly_1_Node));
343 CPPUNIT_ASSERT(abstractRule->IsSource(source_1_Node));
345 CPPUNIT_ASSERT(!abstractRule->IsSource(source_otherRule_Node));
346 CPPUNIT_ASSERT(abstractRule->IsSource(source_otherPurpose_Node));
351 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
352 rule->HasRelation(
nullptr, dest_1),
353 itk::ExceptionObject);
355 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
356 rule->HasRelation(source_1,
nullptr),
357 itk::ExceptionObject);
364 CPPUNIT_ASSERT(rule->HasRelation(source_implicit_1, dest_1) ==
366 CPPUNIT_ASSERT(rule->HasRelation(source_data_1, dest_1) ==
368 CPPUNIT_ASSERT(rule->HasRelation(source_idOnly_1, dest_1) ==
378 CPPUNIT_ASSERT(abstractRule->HasRelation(source_otherPurpose, dest_1) ==
381 CPPUNIT_ASSERT(abstractRule->HasRelation(source_implicit_1, dest_1) ==
383 CPPUNIT_ASSERT(abstractRule->HasRelation(source_data_1, dest_1) ==
385 CPPUNIT_ASSERT(abstractRule->HasRelation(source_idOnly_1, dest_1) ==
392 void GetExistingRelations()
394 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
395 rule->GetExistingRelations(
nullptr),
396 itk::ExceptionObject);
398 CPPUNIT_ASSERT(rule->GetExistingRelations(unRelated).empty());
399 CPPUNIT_ASSERT(rule->GetExistingRelations(source_otherRule).empty());
400 CPPUNIT_ASSERT(rule->GetExistingRelations(source_otherPurpose).empty());
401 CPPUNIT_ASSERT(rule->GetExistingRelations(source_implicit_1).empty());
403 auto uids = rule->GetExistingRelations(source_idOnly_1);
404 CPPUNIT_ASSERT(uids.size() == 1);
405 CPPUNIT_ASSERT(uids.front() ==
"uid1");
407 uids = rule->GetExistingRelations(source_data_1);
408 CPPUNIT_ASSERT(uids.size() == 1);
409 CPPUNIT_ASSERT(uids.front() ==
"uid2");
411 uids = rule->GetExistingRelations(source_1);
412 CPPUNIT_ASSERT(uids.size() == 1);
413 CPPUNIT_ASSERT(uids.front() ==
"uid3");
416 CPPUNIT_ASSERT(abstractRule->GetExistingRelations(unRelated).empty());
417 CPPUNIT_ASSERT(abstractRule->GetExistingRelations(source_otherRule).empty());
418 CPPUNIT_ASSERT(abstractRule->GetExistingRelations(source_implicit_1).empty());
420 uids = abstractRule->GetExistingRelations(source_idOnly_1);
421 CPPUNIT_ASSERT(uids.size() == 1);
422 CPPUNIT_ASSERT(uids.front() ==
"uid1");
424 uids = abstractRule->GetExistingRelations(source_data_1);
425 CPPUNIT_ASSERT(uids.size() == 2);
426 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid2") != uids.end());
427 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid10") != uids.end());
429 uids = abstractRule->GetExistingRelations(source_1);
430 CPPUNIT_ASSERT(uids.size() == 2);
431 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid3") != uids.end());
432 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid8") != uids.end());
434 uids = abstractRule->GetExistingRelations(source_otherPurpose);
435 CPPUNIT_ASSERT(uids.size() == 1);
436 CPPUNIT_ASSERT(uids.front() ==
"uid9");
439 void GetRelationUIDs()
441 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
442 rule->GetRelationUIDs(
nullptr, dest_1),
443 itk::ExceptionObject);
445 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
446 rule->GetRelationUIDs(source_1,
nullptr),
447 itk::ExceptionObject);
449 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_1, unRelated).empty());
450 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_1, dest_2).empty());
451 CPPUNIT_ASSERT(rule->GetRelationUIDs(unRelated, dest_1).empty());
452 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_otherRule, dest_1).empty());
453 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_otherPurpose, dest_1).empty());
455 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_idOnly_1, dest_1).front() ==
"uid1");
456 CPPUNIT_ASSERT(rule->GetRelationUIDs(source_data_1, dest_1).front() ==
"uid2");
457 auto uids = rule->GetRelationUIDs(source_1, dest_1);
458 CPPUNIT_ASSERT(uids.size() == 1);
459 CPPUNIT_ASSERT(uids.front() ==
"uid3");
461 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_1, unRelated).empty());
462 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(unRelated, dest_1).empty());
463 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_otherRule, dest_1).empty());
464 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_otherPurpose, dest_1).front() ==
"uid9");
466 CPPUNIT_ASSERT(abstractRule->GetRelationUIDs(source_idOnly_1, dest_1).front() ==
"uid1");
467 uids = abstractRule->GetRelationUIDs(source_data_1, dest_1);
468 CPPUNIT_ASSERT(uids.size() == 1);
469 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid2") != uids.end());
470 uids = abstractRule->GetRelationUIDs(source_1, dest_1);
471 CPPUNIT_ASSERT(uids.size() == 1);
472 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid3") != uids.end());
473 uids = abstractRule->GetRelationUIDs(source_1, dest_2);
474 CPPUNIT_ASSERT(uids.size() == 1);
475 CPPUNIT_ASSERT(std::find(uids.begin(), uids.end(),
"uid8") != uids.end());
478 void GetSourceCandidateIndicator()
480 auto predicate = rule->GetSourceCandidateIndicator();
483 CPPUNIT_ASSERT(!predicate->CheckNode(
nullptr));
486 void GetDestinationCandidateIndicator()
488 auto predicate = rule->GetDestinationCandidateIndicator();
490 CPPUNIT_ASSERT(predicate->CheckNode(this->dest_1_Node));
492 CPPUNIT_ASSERT(!predicate->CheckNode(
nullptr));
495 void GetConnectedSourcesDetector()
497 auto predicate = rule->GetConnectedSourcesDetector();
499 CPPUNIT_ASSERT(!predicate->CheckNode(
nullptr));
500 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
501 CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1_Node));
502 CPPUNIT_ASSERT(predicate->CheckNode(source_data_1_Node));
503 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
504 CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
506 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
507 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherPurpose_Node));
510 auto predicate2 = abstractRule->GetConnectedSourcesDetector();
512 CPPUNIT_ASSERT(!predicate2->CheckNode(
nullptr));
513 CPPUNIT_ASSERT(!predicate2->CheckNode(unRelated_Node));
514 CPPUNIT_ASSERT(!predicate2->CheckNode(source_implicit_1_Node));
515 CPPUNIT_ASSERT(predicate2->CheckNode(source_data_1_Node));
516 CPPUNIT_ASSERT(predicate2->CheckNode(source_idOnly_1_Node));
517 CPPUNIT_ASSERT(predicate2->CheckNode(source_1_Node));
519 CPPUNIT_ASSERT(!predicate2->CheckNode(source_otherRule_Node));
520 CPPUNIT_ASSERT(predicate2->CheckNode(source_otherPurpose_Node));
523 void GetSourcesDetector()
525 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
526 rule->GetSourcesDetector(
nullptr),
527 itk::ExceptionObject);
529 auto predicate = rule->GetSourcesDetector(dest_1);
531 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
532 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
533 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherPurpose_Node));
535 CPPUNIT_ASSERT(predicate->CheckNode(source_implicit_1_Node));
536 CPPUNIT_ASSERT(predicate->CheckNode(source_data_1_Node));
537 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
538 CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
542 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
543 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
544 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherPurpose_Node));
546 CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1_Node));
547 CPPUNIT_ASSERT(predicate->CheckNode(source_data_1_Node));
548 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
549 CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
553 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
554 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
555 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherPurpose_Node));
557 CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1_Node));
558 CPPUNIT_ASSERT(!predicate->CheckNode(source_data_1_Node));
559 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
560 CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
564 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
565 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
566 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherPurpose_Node));
568 CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1_Node));
569 CPPUNIT_ASSERT(!predicate->CheckNode(source_data_1_Node));
570 CPPUNIT_ASSERT(!predicate->CheckNode(source_idOnly_1_Node));
571 CPPUNIT_ASSERT(!predicate->CheckNode(source_1_Node));
575 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
576 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
577 CPPUNIT_ASSERT(predicate->CheckNode(source_otherPurpose_Node));
579 CPPUNIT_ASSERT(!predicate->CheckNode(source_implicit_1_Node));
580 CPPUNIT_ASSERT(!predicate->CheckNode(source_data_1_Node));
581 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
582 CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
584 predicate = abstractRule->GetSourcesDetector(dest_1);
586 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
587 CPPUNIT_ASSERT(!predicate->CheckNode(source_otherRule_Node));
588 CPPUNIT_ASSERT(predicate->CheckNode(source_otherPurpose_Node));
590 CPPUNIT_ASSERT(predicate->CheckNode(source_implicit_1_Node));
591 CPPUNIT_ASSERT(predicate->CheckNode(source_data_1_Node));
592 CPPUNIT_ASSERT(predicate->CheckNode(source_idOnly_1_Node));
593 CPPUNIT_ASSERT(predicate->CheckNode(source_1_Node));
596 void GetDestinationsDetector()
598 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
599 rule->GetDestinationsDetector(
nullptr),
600 itk::ExceptionObject);
602 auto predicate = rule->GetDestinationsDetector(source_otherRule);
603 CPPUNIT_ASSERT(!predicate->CheckNode(dest_1_Node));
605 predicate = rule->GetDestinationsDetector(source_otherPurpose);
606 CPPUNIT_ASSERT(!predicate->CheckNode(dest_1_Node));
608 predicate = rule->GetDestinationsDetector(source_implicit_1);
609 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
612 CPPUNIT_ASSERT(!predicate->CheckNode(dest_1_Node));
614 predicate = rule->GetDestinationsDetector(source_data_1);
615 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
618 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
621 CPPUNIT_ASSERT(!predicate->CheckNode(dest_1_Node));
623 predicate = rule->GetDestinationsDetector(source_idOnly_1);
624 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
627 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
630 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
632 predicate = rule->GetDestinationsDetector(source_1);
633 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
634 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
635 CPPUNIT_ASSERT(!predicate->CheckNode(dest_2_Node));
638 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
639 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
640 CPPUNIT_ASSERT(!predicate->CheckNode(dest_2_Node));
643 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
644 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
645 CPPUNIT_ASSERT(!predicate->CheckNode(dest_2_Node));
647 predicate = abstractRule->GetDestinationsDetector(source_otherPurpose);
648 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
649 predicate = abstractRule->GetDestinationsDetector(source_otherPurpose);
650 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
653 void GetDestinationDetector()
655 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
656 rule->GetDestinationDetector(
nullptr,
"uid1"),
657 itk::ExceptionObject);
659 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (relation uid is invalid) does not throw.",
660 rule->GetDestinationDetector(source_1,
"invalid uid"),
661 itk::ExceptionObject);
663 auto predicate = rule->GetDestinationDetector(source_1,
"uid3");
664 CPPUNIT_ASSERT(!predicate->CheckNode(unRelated_Node));
665 CPPUNIT_ASSERT(predicate->CheckNode(dest_1_Node));
666 CPPUNIT_ASSERT(!predicate->CheckNode(dest_2_Node));
671 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
672 rule->Connect(
nullptr, dest_1),
673 itk::ExceptionObject);
675 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
676 rule->Connect(source_1,
nullptr),
677 itk::ExceptionObject);
680 CPPUNIT_ASSERT(rule->HasRelation(source_implicit_1, dest_1) ==
682 rule->Connect(source_implicit_1, dest_1);
683 CPPUNIT_ASSERT(rule->HasRelation(source_implicit_1, dest_1) ==
685 auto dcmRefs = GetReferenceSequenceIndices(source_implicit_1, dest_1);
686 CPPUNIT_ASSERT_MESSAGE(
"Additional dicom reference was defined instead of using the existing one.", dcmRefs.size() == 1);
687 CPPUNIT_ASSERT_MESSAGE(
"Dicom reference is not correct.", IsCorrectDICOMReference(source_implicit_1,
"dest_1",
"image",
"Test", 0));
690 CPPUNIT_ASSERT(rule->HasRelation(source_data_1, dest_1) ==
692 rule->Connect(source_data_1, dest_1);
693 CPPUNIT_ASSERT(rule->HasRelation(source_data_1, dest_1) ==
696 auto relUID = rule->GetRelationUIDs(source_data_1, dest_1);
697 CPPUNIT_ASSERT(relUID.size() == 1);
699 std::string name =
"MITK.Relations.1.destinationUID";
700 auto prop = source_data_1->GetProperty(name.c_str());
701 CPPUNIT_ASSERT_MESSAGE(
702 "Destination uid was not stored with the correct key. Already existing session should be used.", prop);
703 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() == dest_1->GetUID());
705 name =
"MITK.Relations.1.ruleID";
706 prop = source_data_1->GetProperty(name.c_str());
707 CPPUNIT_ASSERT_MESSAGE(
"Incorrect ruleID was stored.", prop->GetValueAsString() == rule->GetRuleID());
709 name =
"MITK.Relations.1.SourceImageSequenceItem";
710 prop = source_data_1->GetProperty(name.c_str());
711 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() ==
"0");
713 dcmRefs = GetReferenceSequenceIndices(source_data_1, dest_1);
714 CPPUNIT_ASSERT_MESSAGE(
"Additional dicom reference was defined instead of using the existing one.", dcmRefs.size() == 1);
715 CPPUNIT_ASSERT_MESSAGE(
"Dicom reference is not correct.", IsCorrectDICOMReference(source_data_1,
"dest_1",
"image",
"Test", 0));
718 rule->Connect(source_idOnly_1, dest_1);
719 CPPUNIT_ASSERT(rule->HasRelation(source_idOnly_1, dest_1) ==
721 CPPUNIT_ASSERT_MESSAGE(
"Additional relation was defined instead of updating exting one.",
722 rule->GetExistingRelations(source_1).size() == 1);
725 rule->Connect(source_1, dest_1);
727 CPPUNIT_ASSERT_MESSAGE(
"Additional relation was defined instead of updating exting one.",
728 rule->GetExistingRelations(source_1).size() == 1);
729 name =
"MITK.Relations.1.destinationUID";
730 prop = source_1->GetProperty(name.c_str());
731 CPPUNIT_ASSERT_MESSAGE(
732 "Destination uid was not stored with the correct key. Already existing session should be used.", prop);
733 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() == dest_1->GetUID());
735 name =
"MITK.Relations.1.ruleID";
736 prop = source_1->GetProperty(name.c_str());
737 CPPUNIT_ASSERT_MESSAGE(
"Incorrect ruleID was stored.", prop->GetValueAsString() == rule->GetRuleID());
739 name =
"MITK.Relations.1.SourceImageSequenceItem";
740 prop = source_1->GetProperty(name.c_str());
741 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() ==
"0");
743 dcmRefs = GetReferenceSequenceIndices(source_1, dest_1);
744 CPPUNIT_ASSERT_MESSAGE(
"Additional dicom reference was defined instead of using the existing one.", dcmRefs.size() == 1);
745 CPPUNIT_ASSERT_MESSAGE(
"Dicom reference is not correct.", IsCorrectDICOMReference(source_1,
"dest_1",
"image",
"Test", 0));
748 rule->Connect(unRelated, dest_1);
750 CPPUNIT_ASSERT_MESSAGE(
"Relation was not defined instead of updating exting one.",
751 rule->GetExistingRelations(unRelated).size() == 1);
752 name =
"MITK.Relations.1.destinationUID";
753 prop = unRelated->GetProperty(name.c_str());
754 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() == dest_1->GetUID());
756 name =
"MITK.Relations.1.ruleID";
757 prop = unRelated->GetProperty(name.c_str());
758 CPPUNIT_ASSERT_MESSAGE(
"Incorrect ruleID was stored.", prop->GetValueAsString() == rule->GetRuleID());
760 name =
"MITK.Relations.1.SourceImageSequenceItem";
761 prop = unRelated->GetProperty(name.c_str());
762 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() ==
"0");
764 dcmRefs = GetReferenceSequenceIndices(unRelated, dest_1);
765 CPPUNIT_ASSERT_MESSAGE(
"Additional dicom reference was defined instead of using the existing one.", dcmRefs.size() == 1);
766 CPPUNIT_ASSERT_MESSAGE(
"Dicom reference squence is corrupted. Should be just an index 0.", dcmRefs[0] ==
"0");
767 CPPUNIT_ASSERT_MESSAGE(
"Dicom reference is not correct.", IsCorrectDICOMReference(unRelated,
"dest_1",
"image",
"Test", 0));
770 rule->Connect(unRelated, dest_2);
772 CPPUNIT_ASSERT_MESSAGE(
"Additional relation was not defined.",
773 rule->GetExistingRelations(unRelated).size() == 2);
774 name =
"MITK.Relations.1.destinationUID";
775 prop = unRelated->GetProperty(name.c_str());
776 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() == dest_1->GetUID());
778 name =
"MITK.Relations.1.ruleID";
779 prop = unRelated->GetProperty(name.c_str());
780 CPPUNIT_ASSERT_MESSAGE(
"Incorrect ruleID was stored.", prop->GetValueAsString() == rule->GetRuleID());
782 name =
"MITK.Relations.1.SourceImageSequenceItem";
783 prop = unRelated->GetProperty(name.c_str());
784 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() ==
"0");
786 name =
"MITK.Relations.2.destinationUID";
787 prop = unRelated->GetProperty(name.c_str());
788 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() == dest_2->GetUID());
790 name =
"MITK.Relations.2.ruleID";
791 prop = unRelated->GetProperty(name.c_str());
792 CPPUNIT_ASSERT_MESSAGE(
"Incorrect ruleID was stored.", prop->GetValueAsString() == rule->GetRuleID());
794 name =
"MITK.Relations.2.SourceImageSequenceItem";
795 prop = unRelated->GetProperty(name.c_str());
796 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() ==
"1");
799 dcmRefs = GetReferenceSequenceIndices(unRelated, dest_2);
800 CPPUNIT_ASSERT_MESSAGE(
"Additional dicom reference was not defined.", dcmRefs.size() == 1);
801 CPPUNIT_ASSERT_MESSAGE(
"Dicom reference is not correct.", IsCorrectDICOMReference(unRelated,
"dest_1",
"image",
"Test", 0));
802 CPPUNIT_ASSERT_MESSAGE(
"Dicom reference is not correct.", IsCorrectDICOMReference(unRelated,
"dest_2",
"image",
"Test", 1));
807 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (source is nullptr) does not throw.",
808 rule->Disconnect(
nullptr, dest_1),
809 itk::ExceptionObject);
811 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
812 rule->Disconnect(source_1,
nullptr),
813 itk::ExceptionObject);
815 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (destination is nullptr) does not throw.",
816 rule->Disconnect(
nullptr,
"uid"),
817 itk::ExceptionObject);
820 rule->Disconnect(source_1, unRelated);
822 CPPUNIT_ASSERT_MESSAGE(
"Other relationdata property was removed.", IsCorrectDICOMReference(source_1,
"dest_1",
"image",
"Test", 0));
825 rule->Connect(source_1, dest_2);
826 rule->Connect(source_1, unRelated);
827 rule->Disconnect(source_1, dest_2);
829 CPPUNIT_ASSERT(this->hasRelationProperties(source_1,
"1"));
830 CPPUNIT_ASSERT(this->hasRelationProperties(source_1,
"2"));
831 CPPUNIT_ASSERT(!this->hasRelationProperties(source_1,
"3"));
832 CPPUNIT_ASSERT(this->hasRelationProperties(source_1,
"4"));
833 CPPUNIT_ASSERT_MESSAGE(
"Dicom reference to dest_1 has been removed.", IsCorrectDICOMReference(source_1,
"dest_1",
"image",
"Test", 0));
834 CPPUNIT_ASSERT_MESSAGE(
"Dicom reference to dest_2 (other purpose) has been removed or has not a corrected sequence index (1 instead of 2).", IsCorrectDICOMReference(source_1,
"dest_2",
"image",
"otherpurpose", 1));
835 CPPUNIT_ASSERT_MESSAGE(
"Dicom reference to unRelated has been removed or has not a corrected sequence index (1 instead of 2).", IsCorrectDICOMReference(source_1,
"unRelated",
"image",
"Test", 2));
837 std::string name =
"MITK.Relations.4.destinationUID";
838 auto prop = source_1->GetProperty(name.c_str());
839 CPPUNIT_ASSERT_MESSAGE(
840 "Destination uid was not stored with the correct key. Already existing session should be used.", prop);
841 CPPUNIT_ASSERT_MESSAGE(
"Incorrect destination uid was stored.", prop->GetValueAsString() == unRelated->GetUID());
842 name =
"MITK.Relations.4.SourceImageSequenceItem";
843 prop = source_1->GetProperty(name.c_str());
844 CPPUNIT_ASSERT_MESSAGE(
"SourceImageSequenceItem was not actualized correctly.", prop->GetValueAsString() ==
"2");
846 rule->Disconnect(source_otherPurpose, dest_1);
847 CPPUNIT_ASSERT_MESSAGE(
"Data of other rule purpose was removed.", this->hasRelationProperties(source_otherPurpose,
"1"));
850 void Connect_abstract()
852 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (abstract does not connect) does not throw.",
853 abstractRule->Connect(
nullptr, dest_1),
854 itk::ExceptionObject);
856 CPPUNIT_ASSERT_THROW_MESSAGE(
"Violated precondition (abstract does not connect) does not throw.",
857 abstractRule->Connect(source_1,
nullptr),
858 itk::ExceptionObject);
861 void Disconnect_abstract()
865 abstractRule->Disconnect(source_1, dest_2);
867 CPPUNIT_ASSERT(!this->hasRelationProperties(source_1,
"2"));
870 abstractRule->Disconnect(source_1, dest_1);
872 CPPUNIT_ASSERT(!this->hasRelationProperties(source_1,
"1"));
874 abstractRule->Disconnect(source_otherPurpose, dest_1);
875 CPPUNIT_ASSERT_MESSAGE(
"Data of other rule type was removed.", !this->hasRelationProperties(source_otherPurpose,
"1"));
MITKCORE_EXPORT std::string PropertyKeyPathToPropertyName(const PropertyKeyPath &tagPath)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
ItemSelectionIndex selection
std::string MITKCORE_EXPORT GeneratePropertyNameForDICOMTag(unsigned int group, unsigned int element)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
PropertyKeyPath & AddElement(const ElementNameType &name)
virtual BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) const =0
Get property by its key.
const NodeInfo & GetNode(const PathIndexType &index) const
PropertyKeyPath & AddSelection(const ElementNameType &name, ItemSelectionIndex index)
static PropertyKeyPath GetRootKeyPath()
virtual std::vector< std::string > GetPropertyKeys(const std::string &contextName="", bool includeDefaultContext=false) const =0
Query keys of existing properties.
Test fixture for parameterized tests.
MITKCORE_EXPORT PropertyKeyPath PropertyNameToPropertyKeyPath(const std::string &propertyName)
Class that can be used to specify nested or wild carded property keys. E.g. for the use in context of...
MITKCORE_EXPORT std::string PropertyKeyPathToPropertyRegEx(const PropertyKeyPath &tagPath)
virtual void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false)=0
Add new or change existent property.
PropertyKeyPath & AddAnySelection(const ElementNameType &name)