comparison Framework/Plugins/IndexUnitTests.h @ 307:8de3a1ecac11

MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Jul 2021 16:53:28 +0200
parents 2447c290fc73
children d192bfd0e752
comparison
equal deleted inserted replaced
306:544e0c943b40 307:8de3a1ecac11
66 66
67 static std::unique_ptr<OrthancPluginAttachment> expectedAttachment; 67 static std::unique_ptr<OrthancPluginAttachment> expectedAttachment;
68 static std::list<OrthancPluginDicomTag> expectedDicomTags; 68 static std::list<OrthancPluginDicomTag> expectedDicomTags;
69 static std::unique_ptr<OrthancPluginExportedResource> expectedExported; 69 static std::unique_ptr<OrthancPluginExportedResource> expectedExported;
70 70
71 static std::map<std::string, OrthancPluginResourceType> deletedResources;
72 static std::unique_ptr< std::pair<std::string, OrthancPluginResourceType> > remainingAncestor;
73 static std::set<std::string> deletedAttachments;
74
75
71 static void CheckAttachment(const OrthancPluginAttachment& attachment) 76 static void CheckAttachment(const OrthancPluginAttachment& attachment)
72 { 77 {
73 ASSERT_STREQ(expectedAttachment->uuid, attachment.uuid); 78 ASSERT_STREQ(expectedAttachment->uuid, attachment.uuid);
74 ASSERT_EQ(expectedAttachment->contentType, attachment.contentType); 79 ASSERT_EQ(expectedAttachment->contentType, attachment.contentType);
75 ASSERT_EQ(expectedAttachment->uncompressedSize, attachment.uncompressedSize); 80 ASSERT_EQ(expectedAttachment->uncompressedSize, attachment.uncompressedSize);
146 *reinterpret_cast<const OrthancPluginDicomTag*>(answer.valueGeneric); 151 *reinterpret_cast<const OrthancPluginDicomTag*>(answer.valueGeneric);
147 CheckDicomTag(tag); 152 CheckDicomTag(tag);
148 break; 153 break;
149 } 154 }
150 155
156 case _OrthancPluginDatabaseAnswerType_DeletedResource:
157 deletedResources[answer.valueString] = static_cast<OrthancPluginResourceType>(answer.valueInt32);
158 break;
159
160 case _OrthancPluginDatabaseAnswerType_RemainingAncestor:
161 remainingAncestor.reset(new std::pair<std::string, OrthancPluginResourceType>());
162 *remainingAncestor = std::make_pair(answer.valueString, static_cast<OrthancPluginResourceType>(answer.valueInt32));
163 break;
164
165 case _OrthancPluginDatabaseAnswerType_DeletedAttachment:
166 deletedAttachments.insert(reinterpret_cast<const OrthancPluginAttachment*>(answer.valueGeneric)->uuid);
167 break;
168
151 default: 169 default:
152 printf("Unhandled message: %d\n", answer.type); 170 printf("Unhandled message: %d\n", answer.type);
153 break; 171 break;
154 } 172 }
155 173
486 504
487 { 505 {
488 // A transaction is needed here for MySQL, as it was not possible 506 // A transaction is needed here for MySQL, as it was not possible
489 // to implement recursive deletion of resources using pure SQL 507 // to implement recursive deletion of resources using pure SQL
490 // statements 508 // statements
491 manager->StartTransaction(TransactionType_ReadWrite); 509 manager->StartTransaction(TransactionType_ReadWrite);
510
511 deletedAttachments.clear();
512 deletedResources.clear();
513 remainingAncestor.reset();
514
492 db.DeleteResource(*output, *manager, c); 515 db.DeleteResource(*output, *manager, c);
516
517 ASSERT_EQ(0u, deletedAttachments.size());
518 ASSERT_EQ(1u, deletedResources.size());
519 ASSERT_EQ(OrthancPluginResourceType_Series, deletedResources["series2"]);
520 ASSERT_TRUE(remainingAncestor.get() != NULL);
521 ASSERT_EQ("study", remainingAncestor->first);
522 ASSERT_EQ(OrthancPluginResourceType_Study, remainingAncestor->second);
523
493 manager->CommitTransaction(); 524 manager->CommitTransaction();
494 } 525 }
495 526
527 deletedAttachments.clear();
528 deletedResources.clear();
529 remainingAncestor.reset();
530
496 ASSERT_FALSE(db.IsExistingResource(*manager, c)); 531 ASSERT_FALSE(db.IsExistingResource(*manager, c));
497 ASSERT_TRUE(db.IsExistingResource(*manager, a)); 532 ASSERT_TRUE(db.IsExistingResource(*manager, a));
498 ASSERT_TRUE(db.IsExistingResource(*manager, b)); 533 ASSERT_TRUE(db.IsExistingResource(*manager, b));
499 ASSERT_EQ(2u, db.GetAllResourcesCount(*manager)); 534 ASSERT_EQ(2u, db.GetAllResourcesCount(*manager));
500 db.DeleteResource(*output, *manager, a); 535 db.DeleteResource(*output, *manager, a);
501 ASSERT_EQ(0u, db.GetAllResourcesCount(*manager)); 536 ASSERT_EQ(0u, db.GetAllResourcesCount(*manager));
502 ASSERT_FALSE(db.IsExistingResource(*manager, a)); 537 ASSERT_FALSE(db.IsExistingResource(*manager, a));
503 ASSERT_FALSE(db.IsExistingResource(*manager, b)); 538 ASSERT_FALSE(db.IsExistingResource(*manager, b));
504 ASSERT_FALSE(db.IsExistingResource(*manager, c)); 539 ASSERT_FALSE(db.IsExistingResource(*manager, c));
505 540
541 ASSERT_EQ(0u, deletedAttachments.size());
542 ASSERT_EQ(2u, deletedResources.size());
543 ASSERT_EQ(OrthancPluginResourceType_Series, deletedResources["series"]);
544 ASSERT_EQ(OrthancPluginResourceType_Study, deletedResources["study"]);
545 ASSERT_FALSE(remainingAncestor.get() != NULL);
546
506 ASSERT_EQ(0u, db.GetAllResourcesCount(*manager)); 547 ASSERT_EQ(0u, db.GetAllResourcesCount(*manager));
507 ASSERT_EQ(0u, db.GetUnprotectedPatientsCount(*manager)); 548 ASSERT_EQ(0u, db.GetUnprotectedPatientsCount(*manager));
508 int64_t p1 = db.CreateResource(*manager, "patient1", OrthancPluginResourceType_Patient); 549 int64_t p1 = db.CreateResource(*manager, "patient1", OrthancPluginResourceType_Patient);
509 int64_t p2 = db.CreateResource(*manager, "patient2", OrthancPluginResourceType_Patient); 550 int64_t p2 = db.CreateResource(*manager, "patient2", OrthancPluginResourceType_Patient);
510 int64_t p3 = db.CreateResource(*manager, "patient3", OrthancPluginResourceType_Patient); 551 int64_t p3 = db.CreateResource(*manager, "patient3", OrthancPluginResourceType_Patient);
551 tmp.clear(); 592 tmp.clear();
552 ASSERT_TRUE(db.LookupGlobalProperty(tmp, *manager, "some-server", Orthanc::GlobalProperty_DatabaseInternal8)); 593 ASSERT_TRUE(db.LookupGlobalProperty(tmp, *manager, "some-server", Orthanc::GlobalProperty_DatabaseInternal8));
553 ASSERT_EQ(longProperty, tmp); 594 ASSERT_EQ(longProperty, tmp);
554 } 595 }
555 596
597 db.DeleteResource(*output, *manager, p1);
598 db.DeleteResource(*output, *manager, p3);
599
600 for (size_t level = 0; level < 4; level++)
601 {
602 // Test cascade up to the "patient" level
603 ASSERT_EQ(0u, db.GetAllResourcesCount(*manager));
604
605 std::vector<int64_t> resources;
606 resources.push_back(db.CreateResource(*manager, "patient", OrthancPluginResourceType_Patient));
607 resources.push_back(db.CreateResource(*manager, "study", OrthancPluginResourceType_Study));
608 resources.push_back(db.CreateResource(*manager, "series", OrthancPluginResourceType_Series));
609 resources.push_back(db.CreateResource(*manager, "instance", OrthancPluginResourceType_Instance));
610
611 OrthancPluginAttachment a;
612 a.uuid = "attachment";
613 a.contentType = Orthanc::FileContentType_DicomAsJson;
614 a.uncompressedSize = 4242;
615 a.uncompressedHash = "md5";
616 a.compressionType = Orthanc::CompressionType_None;
617 a.compressedSize = 4242;
618 a.compressedHash = "md5";
619 db.AddAttachment(*manager, resources[2], a, 42);
620
621 db.AttachChild(*manager, resources[0], resources[1]);
622 db.AttachChild(*manager, resources[1], resources[2]);
623 db.AttachChild(*manager, resources[2], resources[3]);
624 ASSERT_EQ(4u, db.GetAllResourcesCount(*manager));
625
626 deletedAttachments.clear();
627 deletedResources.clear();
628 remainingAncestor.reset();
629
630 db.DeleteResource(*output, *manager, resources[level]);
631
632 ASSERT_EQ(1u, deletedAttachments.size());
633 ASSERT_EQ("attachment", *deletedAttachments.begin());
634 ASSERT_EQ(4u, deletedResources.size());
635 ASSERT_EQ(OrthancPluginResourceType_Patient, deletedResources["patient"]);
636 ASSERT_EQ(OrthancPluginResourceType_Study, deletedResources["study"]);
637 ASSERT_EQ(OrthancPluginResourceType_Series, deletedResources["series"]);
638 ASSERT_EQ(OrthancPluginResourceType_Instance, deletedResources["instance"]);
639 ASSERT_TRUE(remainingAncestor.get() == NULL);
640 }
641
642 for (size_t level = 1; level < 4; level++)
643 {
644 // Test remaining ancestor
645 ASSERT_EQ(0u, db.GetAllResourcesCount(*manager));
646
647 std::vector<int64_t> resources;
648 resources.push_back(db.CreateResource(*manager, "patient", OrthancPluginResourceType_Patient));
649 resources.push_back(db.CreateResource(*manager, "study", OrthancPluginResourceType_Study));
650 resources.push_back(db.CreateResource(*manager, "series", OrthancPluginResourceType_Series));
651 resources.push_back(db.CreateResource(*manager, "instance", OrthancPluginResourceType_Instance));
652
653 int64_t unrelated = db.CreateResource(*manager, "unrelated", OrthancPluginResourceType_Patient);
654 int64_t remaining = db.CreateResource(*manager, "remaining", static_cast<OrthancPluginResourceType>(level));
655
656 db.AttachChild(*manager, resources[0], resources[1]);
657 db.AttachChild(*manager, resources[1], resources[2]);
658 db.AttachChild(*manager, resources[2], resources[3]);
659 db.AttachChild(*manager, resources[level - 1], remaining);
660 ASSERT_EQ(6u, db.GetAllResourcesCount(*manager));
661
662 deletedAttachments.clear();
663 deletedResources.clear();
664 remainingAncestor.reset();
665
666 db.DeleteResource(*output, *manager, resources[3]); // delete instance
667
668 ASSERT_EQ(0u, deletedAttachments.size());
669 ASSERT_EQ(OrthancPluginResourceType_Instance, deletedResources["instance"]);
670
671 ASSERT_TRUE(remainingAncestor.get() != NULL);
672
673 switch (level)
674 {
675 case 1:
676 ASSERT_EQ(3u, deletedResources.size());
677 ASSERT_EQ(OrthancPluginResourceType_Study, deletedResources["study"]);
678 ASSERT_EQ(OrthancPluginResourceType_Series, deletedResources["series"]);
679 ASSERT_EQ("patient", remainingAncestor->first);
680 ASSERT_EQ(OrthancPluginResourceType_Patient, remainingAncestor->second);
681 break;
682
683 case 2:
684 ASSERT_EQ(2u, deletedResources.size());
685 ASSERT_EQ(OrthancPluginResourceType_Series, deletedResources["series"]);
686 ASSERT_EQ("study", remainingAncestor->first);
687 ASSERT_EQ(OrthancPluginResourceType_Study, remainingAncestor->second);
688 break;
689
690 case 3:
691 ASSERT_EQ(1u, deletedResources.size());
692 ASSERT_EQ("series", remainingAncestor->first);
693 ASSERT_EQ(OrthancPluginResourceType_Series, remainingAncestor->second);
694 break;
695
696 default:
697 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
698 }
699
700 db.DeleteResource(*output, *manager, resources[0]);
701 db.DeleteResource(*output, *manager, unrelated);
702 }
703
556 manager->Close(); 704 manager->Close();
557 } 705 }