comparison Framework/Plugins/IndexUnitTests.h @ 201:42990b2dd51b

create IDatabaseBackendOutput only if needed
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Mar 2021 16:51:51 +0100
parents 30b210616f4f
children 2089d4071408
comparison
equal deleted inserted replaced
200:30b210616f4f 201:42990b2dd51b
166 context.InvokeService = InvokeService; 166 context.InvokeService = InvokeService;
167 167
168 ImplicitTransaction::SetErrorOnDoubleExecution(true); 168 ImplicitTransaction::SetErrorOnDoubleExecution(true);
169 169
170 #if ORTHANC_ENABLE_POSTGRESQL == 1 170 #if ORTHANC_ENABLE_POSTGRESQL == 1
171 PostgreSQLIndex db(globalParameters_); 171 PostgreSQLIndex db(&context, globalParameters_);
172 db.SetClearAll(true); 172 db.SetClearAll(true);
173 #elif ORTHANC_ENABLE_MYSQL == 1 173 #elif ORTHANC_ENABLE_MYSQL == 1
174 MySQLIndex db(globalParameters_); 174 MySQLIndex db(&context, globalParameters_);
175 db.SetClearAll(true); 175 db.SetClearAll(true);
176 #elif ORTHANC_ENABLE_SQLITE == 1 176 #elif ORTHANC_ENABLE_SQLITE == 1
177 SQLiteIndex db; // Open in memory 177 SQLiteIndex db(&context); // Open in memory
178 #else 178 #else
179 # error Unsupported database backend 179 # error Unsupported database backend
180 #endif 180 #endif
181 181
182 db.RegisterOutput(&context, new OrthancPlugins::DatabaseBackendOutputV2(&context, NULL)); 182 db.SetOutputFactory(new OrthancPlugins::DatabaseBackendOutputV2::Factory(&context, NULL));
183 db.Open(); 183 db.Open();
184
185 std::unique_ptr<OrthancPlugins::IDatabaseBackendOutput> output(db.CreateOutput());
184 186
185 187
186 std::string s; 188 std::string s;
187 ASSERT_TRUE(db.LookupGlobalProperty(s, Orthanc::GlobalProperty_DatabaseSchemaVersion)); 189 ASSERT_TRUE(db.LookupGlobalProperty(s, Orthanc::GlobalProperty_DatabaseSchemaVersion));
188 ASSERT_EQ("6", s); 190 ASSERT_EQ("6", s);
327 ASSERT_EQ(1u, fc.size()); 329 ASSERT_EQ(1u, fc.size());
328 ASSERT_EQ(Orthanc::FileContentType_Dicom, fc.front()); 330 ASSERT_EQ(Orthanc::FileContentType_Dicom, fc.front());
329 db.AddAttachment(a, a2); 331 db.AddAttachment(a, a2);
330 db.ListAvailableAttachments(fc, a); 332 db.ListAvailableAttachments(fc, a);
331 ASSERT_EQ(2u, fc.size()); 333 ASSERT_EQ(2u, fc.size());
332 ASSERT_FALSE(db.LookupAttachment(b, Orthanc::FileContentType_Dicom)); 334 ASSERT_FALSE(db.LookupAttachment(*output, b, Orthanc::FileContentType_Dicom));
333 335
334 ASSERT_EQ(4284u, db.GetTotalCompressedSize()); 336 ASSERT_EQ(4284u, db.GetTotalCompressedSize());
335 ASSERT_EQ(4284u, db.GetTotalUncompressedSize()); 337 ASSERT_EQ(4284u, db.GetTotalUncompressedSize());
336 338
337 expectedAttachment.reset(new OrthancPluginAttachment); 339 expectedAttachment.reset(new OrthancPluginAttachment);
340 expectedAttachment->uncompressedSize = 42; 342 expectedAttachment->uncompressedSize = 42;
341 expectedAttachment->uncompressedHash = "md5_1"; 343 expectedAttachment->uncompressedHash = "md5_1";
342 expectedAttachment->compressionType = Orthanc::CompressionType_None; 344 expectedAttachment->compressionType = Orthanc::CompressionType_None;
343 expectedAttachment->compressedSize = 42; 345 expectedAttachment->compressedSize = 42;
344 expectedAttachment->compressedHash = "md5_1"; 346 expectedAttachment->compressedHash = "md5_1";
345 ASSERT_TRUE(db.LookupAttachment(a, Orthanc::FileContentType_Dicom)); 347 ASSERT_TRUE(db.LookupAttachment(*output, a, Orthanc::FileContentType_Dicom));
346 348
347 expectedAttachment.reset(new OrthancPluginAttachment); 349 expectedAttachment.reset(new OrthancPluginAttachment);
348 expectedAttachment->uuid = "uuid2"; 350 expectedAttachment->uuid = "uuid2";
349 expectedAttachment->contentType = Orthanc::FileContentType_DicomAsJson; 351 expectedAttachment->contentType = Orthanc::FileContentType_DicomAsJson;
350 expectedAttachment->uncompressedSize = 4242; 352 expectedAttachment->uncompressedSize = 4242;
351 expectedAttachment->uncompressedHash = "md5_2"; 353 expectedAttachment->uncompressedHash = "md5_2";
352 expectedAttachment->compressionType = Orthanc::CompressionType_None; 354 expectedAttachment->compressionType = Orthanc::CompressionType_None;
353 expectedAttachment->compressedSize = 4242; 355 expectedAttachment->compressedSize = 4242;
354 expectedAttachment->compressedHash = "md5_2"; 356 expectedAttachment->compressedHash = "md5_2";
355 ASSERT_TRUE(db.LookupAttachment(a, Orthanc::FileContentType_DicomAsJson)); 357 ASSERT_TRUE(db.LookupAttachment(*output, a, Orthanc::FileContentType_DicomAsJson));
356 358
357 db.ListAvailableAttachments(fc, b); 359 db.ListAvailableAttachments(fc, b);
358 ASSERT_EQ(0u, fc.size()); 360 ASSERT_EQ(0u, fc.size());
359 db.DeleteAttachment(a, Orthanc::FileContentType_Dicom); 361 db.DeleteAttachment(*output, a, Orthanc::FileContentType_Dicom);
360 db.ListAvailableAttachments(fc, a); 362 db.ListAvailableAttachments(fc, a);
361 ASSERT_EQ(1u, fc.size()); 363 ASSERT_EQ(1u, fc.size());
362 ASSERT_EQ(Orthanc::FileContentType_DicomAsJson, fc.front()); 364 ASSERT_EQ(Orthanc::FileContentType_DicomAsJson, fc.front());
363 db.DeleteAttachment(a, Orthanc::FileContentType_DicomAsJson); 365 db.DeleteAttachment(*output, a, Orthanc::FileContentType_DicomAsJson);
364 db.ListAvailableAttachments(fc, a); 366 db.ListAvailableAttachments(fc, a);
365 ASSERT_EQ(0u, fc.size()); 367 ASSERT_EQ(0u, fc.size());
366 368
367 369
368 db.SetIdentifierTag(a, 0x0010, 0x0020, "patient"); 370 db.SetIdentifierTag(a, 0x0010, 0x0020, "patient");
375 expectedDicomTags.front().element = 0x0020; 377 expectedDicomTags.front().element = 0x0020;
376 expectedDicomTags.front().value = "patient"; 378 expectedDicomTags.front().value = "patient";
377 expectedDicomTags.back().group = 0x0020; 379 expectedDicomTags.back().group = 0x0020;
378 expectedDicomTags.back().element = 0x000d; 380 expectedDicomTags.back().element = 0x000d;
379 expectedDicomTags.back().value = "study"; 381 expectedDicomTags.back().value = "study";
380 db.GetMainDicomTags(a); 382 db.GetMainDicomTags(*output, a);
381 383
382 384
383 db.LookupIdentifier(ci, OrthancPluginResourceType_Study, 0x0010, 0x0020, 385 db.LookupIdentifier(ci, OrthancPluginResourceType_Study, 0x0010, 0x0020,
384 OrthancPluginIdentifierConstraint_Equal, "patient"); 386 OrthancPluginIdentifierConstraint_Equal, "patient");
385 ASSERT_EQ(1u, ci.size()); 387 ASSERT_EQ(1u, ci.size());
404 expectedExported.reset(new OrthancPluginExportedResource()); 406 expectedExported.reset(new OrthancPluginExportedResource());
405 *expectedExported = exp; 407 *expectedExported = exp;
406 expectedExported->seq = 1; 408 expectedExported->seq = 1;
407 409
408 bool done; 410 bool done;
409 db.GetExportedResources(done, 0, 10); 411 db.GetExportedResources(*output, done, 0, 10);
410 412
411 413
412 db.GetAllPublicIds(pub, OrthancPluginResourceType_Patient); ASSERT_EQ(0u, pub.size()); 414 db.GetAllPublicIds(pub, OrthancPluginResourceType_Patient); ASSERT_EQ(0u, pub.size());
413 db.GetAllPublicIds(pub, OrthancPluginResourceType_Study); ASSERT_EQ(1u, pub.size()); 415 db.GetAllPublicIds(pub, OrthancPluginResourceType_Study); ASSERT_EQ(1u, pub.size());
414 db.GetAllPublicIds(pub, OrthancPluginResourceType_Series); ASSERT_EQ(2u, pub.size()); 416 db.GetAllPublicIds(pub, OrthancPluginResourceType_Series); ASSERT_EQ(2u, pub.size());
421 { 423 {
422 // A transaction is needed here for MySQL, as it was not possible 424 // A transaction is needed here for MySQL, as it was not possible
423 // to implement recursive deletion of resources using pure SQL 425 // to implement recursive deletion of resources using pure SQL
424 // statements 426 // statements
425 db.StartTransaction(); 427 db.StartTransaction();
426 db.DeleteResource(c); 428 db.DeleteResource(*output, c);
427 db.CommitTransaction(); 429 db.CommitTransaction();
428 } 430 }
429 431
430 ASSERT_FALSE(db.IsExistingResource(c)); 432 ASSERT_FALSE(db.IsExistingResource(c));
431 ASSERT_TRUE(db.IsExistingResource(a)); 433 ASSERT_TRUE(db.IsExistingResource(a));
432 ASSERT_TRUE(db.IsExistingResource(b)); 434 ASSERT_TRUE(db.IsExistingResource(b));
433 ASSERT_EQ(2u, db.GetResourcesCount()); 435 ASSERT_EQ(2u, db.GetResourcesCount());
434 db.DeleteResource(a); 436 db.DeleteResource(*output, a);
435 ASSERT_EQ(0u, db.GetResourcesCount()); 437 ASSERT_EQ(0u, db.GetResourcesCount());
436 ASSERT_FALSE(db.IsExistingResource(a)); 438 ASSERT_FALSE(db.IsExistingResource(a));
437 ASSERT_FALSE(db.IsExistingResource(b)); 439 ASSERT_FALSE(db.IsExistingResource(b));
438 ASSERT_FALSE(db.IsExistingResource(c)); 440 ASSERT_FALSE(db.IsExistingResource(c));
439 441
455 ASSERT_EQ(p2, r); 457 ASSERT_EQ(p2, r);
456 db.SetProtectedPatient(p1, false); 458 db.SetProtectedPatient(p1, false);
457 ASSERT_FALSE(db.IsProtectedPatient(p1)); 459 ASSERT_FALSE(db.IsProtectedPatient(p1));
458 ASSERT_TRUE(db.SelectPatientToRecycle(r)); 460 ASSERT_TRUE(db.SelectPatientToRecycle(r));
459 ASSERT_EQ(p2, r); 461 ASSERT_EQ(p2, r);
460 db.DeleteResource(p2); 462 db.DeleteResource(*output, p2);
461 ASSERT_TRUE(db.SelectPatientToRecycle(r, p3)); 463 ASSERT_TRUE(db.SelectPatientToRecycle(r, p3));
462 ASSERT_EQ(p1, r); 464 ASSERT_EQ(p1, r);
463 } 465 }