Mercurial > hg > orthanc
comparison UnitTestsSources/ServerIndex.cpp @ 713:9d1973813d8b
test attachment recycling
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 Feb 2014 09:21:23 +0100 |
parents | 8f62e8d5a384 |
children |
comparison
equal
deleted
inserted
replaced
712:9e3f21441903 | 713:9d1973813d8b |
---|---|
502 }*/ | 502 }*/ |
503 } | 503 } |
504 | 504 |
505 | 505 |
506 | 506 |
507 TEST(DatabaseWrapper, AttachmentRecycling) | 507 TEST(ServerIndex, AttachmentRecycling) |
508 { | 508 { |
509 const std::string path = "OrthancStorageUnitTests"; | 509 const std::string path = "OrthancStorageUnitTests"; |
510 Toolbox::RemoveFile(path + "/index"); | 510 Toolbox::RemoveFile(path + "/index"); |
511 ServerContext context(path, ":memory:"); // The SQLite DB is in memory | 511 ServerContext context(path, ":memory:"); // The SQLite DB is in memory |
512 ServerIndex& index = context.GetIndex(); | 512 ServerIndex& index = context.GetIndex(); |
513 | 513 |
514 index.SetMaximumStorageSize(10); | 514 index.SetMaximumStorageSize(10); |
515 | 515 |
516 Json::Value tmp; | 516 Json::Value tmp; |
517 index.ComputeStatistics(tmp); | 517 index.ComputeStatistics(tmp); |
518 ASSERT_EQ(0, tmp["PatientCount"].asInt()); | 518 ASSERT_EQ(0, tmp["CountPatients"].asInt()); |
519 ASSERT_EQ(0, boost::lexical_cast<int>(tmp["TotalDiskSize"].asString())); | |
519 | 520 |
520 ServerIndex::Attachments attachments; | 521 ServerIndex::Attachments attachments; |
521 | 522 |
522 DicomMap instance; | 523 std::vector<std::string> ids; |
523 instance.SetValue(DICOM_TAG_PATIENT_ID, "patient1"); | 524 for (int i = 0; i < 10; i++) |
524 instance.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "study1"); | 525 { |
525 instance.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, "series1"); | 526 std::string id = boost::lexical_cast<std::string>(i); |
526 instance.SetValue(DICOM_TAG_SOP_INSTANCE_UID, "instance1"); | 527 DicomMap instance; |
527 ASSERT_EQ(StoreStatus_Success, index.Store(instance, attachments, "")); | 528 instance.SetValue(DICOM_TAG_PATIENT_ID, "patient-" + id); |
529 instance.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "study-" + id); | |
530 instance.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, "series-" + id); | |
531 instance.SetValue(DICOM_TAG_SOP_INSTANCE_UID, "instance-" + id); | |
532 ASSERT_EQ(StoreStatus_Success, index.Store(instance, attachments, "")); | |
533 | |
534 DicomInstanceHasher hasher(instance); | |
535 ids.push_back(hasher.HashPatient()); | |
536 ids.push_back(hasher.HashStudy()); | |
537 ids.push_back(hasher.HashSeries()); | |
538 ids.push_back(hasher.HashInstance()); | |
539 } | |
540 | |
541 index.ComputeStatistics(tmp); | |
542 ASSERT_EQ(10, tmp["CountPatients"].asInt()); | |
543 ASSERT_EQ(0, boost::lexical_cast<int>(tmp["TotalDiskSize"].asString())); | |
544 | |
545 for (size_t i = 0; i < ids.size(); i++) | |
546 { | |
547 FileInfo info(Toolbox::GenerateUuid(), FileContentType_Dicom, 1, "md5"); | |
548 index.AddAttachment(info, ids[i]); | |
549 | |
550 index.ComputeStatistics(tmp); | |
551 ASSERT_GE(10, boost::lexical_cast<int>(tmp["TotalDiskSize"].asString())); | |
552 } | |
528 | 553 |
529 // Because the DB is in memory, the SQLite index must not have been created | 554 // Because the DB is in memory, the SQLite index must not have been created |
530 ASSERT_THROW(Toolbox::GetFileSize(path + "/index"), OrthancException); | 555 ASSERT_THROW(Toolbox::GetFileSize(path + "/index"), OrthancException); |
531 } | 556 } |