Mercurial > hg > orthanc-databases
comparison Framework/Plugins/IndexUnitTests.h @ 225:94c9908e6aca
removed DatabaseManager member out of class IndexBackend
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 01 Apr 2021 19:18:19 +0200 |
parents | 73cc85f3d9c1 |
children | a4918d57435c |
comparison
equal
deleted
inserted
replaced
224:61c309e06797 | 225:94c9908e6aca |
---|---|
179 #else | 179 #else |
180 # error Unsupported database backend | 180 # error Unsupported database backend |
181 #endif | 181 #endif |
182 | 182 |
183 db.SetOutputFactory(new DatabaseBackendAdapterV2::Factory(&context, NULL)); | 183 db.SetOutputFactory(new DatabaseBackendAdapterV2::Factory(&context, NULL)); |
184 db.Open(); | 184 |
185 | 185 DatabaseManager manager(db.CreateDatabaseFactory()); |
186 manager.Open(); | |
187 | |
186 std::unique_ptr<IDatabaseBackendOutput> output(db.CreateOutput()); | 188 std::unique_ptr<IDatabaseBackendOutput> output(db.CreateOutput()); |
187 | |
188 | 189 |
189 std::string s; | 190 std::string s; |
190 ASSERT_TRUE(db.LookupGlobalProperty(s, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion)); | 191 ASSERT_TRUE(db.LookupGlobalProperty(s, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion)); |
191 ASSERT_EQ("6", s); | 192 ASSERT_EQ("6", s); |
192 | 193 |
193 ASSERT_FALSE(db.LookupGlobalProperty(s, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_AnonymizationSequence)); | 194 ASSERT_FALSE(db.LookupGlobalProperty(s, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_AnonymizationSequence)); |
194 db.SetGlobalProperty(MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_AnonymizationSequence, "Hello"); | 195 db.SetGlobalProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_AnonymizationSequence, "Hello"); |
195 ASSERT_TRUE(db.LookupGlobalProperty(s, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_AnonymizationSequence)); | 196 ASSERT_TRUE(db.LookupGlobalProperty(s, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_AnonymizationSequence)); |
196 ASSERT_EQ("Hello", s); | 197 ASSERT_EQ("Hello", s); |
197 db.SetGlobalProperty(MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_AnonymizationSequence, "HelloWorld"); | 198 db.SetGlobalProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_AnonymizationSequence, "HelloWorld"); |
198 ASSERT_TRUE(db.LookupGlobalProperty(s, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_AnonymizationSequence)); | 199 ASSERT_TRUE(db.LookupGlobalProperty(s, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_AnonymizationSequence)); |
199 ASSERT_EQ("HelloWorld", s); | 200 ASSERT_EQ("HelloWorld", s); |
200 | 201 |
201 int64_t a = db.CreateResource("study", OrthancPluginResourceType_Study); | 202 int64_t a = db.CreateResource(manager, "study", OrthancPluginResourceType_Study); |
202 ASSERT_TRUE(db.IsExistingResource(a)); | 203 ASSERT_TRUE(db.IsExistingResource(manager, a)); |
203 ASSERT_FALSE(db.IsExistingResource(a + 1)); | 204 ASSERT_FALSE(db.IsExistingResource(manager, a + 1)); |
204 | 205 |
205 int64_t b; | 206 int64_t b; |
206 OrthancPluginResourceType t; | 207 OrthancPluginResourceType t; |
207 ASSERT_FALSE(db.LookupResource(b, t, "world")); | 208 ASSERT_FALSE(db.LookupResource(b, t, manager, "world")); |
208 ASSERT_TRUE(db.LookupResource(b, t, "study")); | 209 ASSERT_TRUE(db.LookupResource(b, t, manager, "study")); |
209 ASSERT_EQ(a, b); | 210 ASSERT_EQ(a, b); |
210 ASSERT_EQ(OrthancPluginResourceType_Study, t); | 211 ASSERT_EQ(OrthancPluginResourceType_Study, t); |
211 | 212 |
212 b = db.CreateResource("series", OrthancPluginResourceType_Series); | 213 b = db.CreateResource(manager, "series", OrthancPluginResourceType_Series); |
213 ASSERT_NE(a, b); | 214 ASSERT_NE(a, b); |
214 | 215 |
215 ASSERT_EQ("study", db.GetPublicId(a)); | 216 ASSERT_EQ("study", db.GetPublicId(manager, a)); |
216 ASSERT_EQ("series", db.GetPublicId(b)); | 217 ASSERT_EQ("series", db.GetPublicId(manager, b)); |
217 ASSERT_EQ(OrthancPluginResourceType_Study, db.GetResourceType(a)); | 218 ASSERT_EQ(OrthancPluginResourceType_Study, db.GetResourceType(manager, a)); |
218 ASSERT_EQ(OrthancPluginResourceType_Series, db.GetResourceType(b)); | 219 ASSERT_EQ(OrthancPluginResourceType_Series, db.GetResourceType(manager, b)); |
219 | 220 |
220 db.AttachChild(a, b); | 221 db.AttachChild(manager, a, b); |
221 | 222 |
222 int64_t c; | 223 int64_t c; |
223 ASSERT_FALSE(db.LookupParent(c, a)); | 224 ASSERT_FALSE(db.LookupParent(c, manager, a)); |
224 ASSERT_TRUE(db.LookupParent(c, b)); | 225 ASSERT_TRUE(db.LookupParent(c, manager, b)); |
225 ASSERT_EQ(a, c); | 226 ASSERT_EQ(a, c); |
226 | 227 |
227 c = db.CreateResource("series2", OrthancPluginResourceType_Series); | 228 c = db.CreateResource(manager, "series2", OrthancPluginResourceType_Series); |
228 db.AttachChild(a, c); | 229 db.AttachChild(manager, a, c); |
229 | 230 |
230 ASSERT_EQ(3u, db.GetAllResourcesCount()); | 231 ASSERT_EQ(3u, db.GetAllResourcesCount(manager)); |
231 ASSERT_EQ(0u, db.GetResourcesCount(OrthancPluginResourceType_Patient)); | 232 ASSERT_EQ(0u, db.GetResourcesCount(manager, OrthancPluginResourceType_Patient)); |
232 ASSERT_EQ(1u, db.GetResourcesCount(OrthancPluginResourceType_Study)); | 233 ASSERT_EQ(1u, db.GetResourcesCount(manager, OrthancPluginResourceType_Study)); |
233 ASSERT_EQ(2u, db.GetResourcesCount(OrthancPluginResourceType_Series)); | 234 ASSERT_EQ(2u, db.GetResourcesCount(manager, OrthancPluginResourceType_Series)); |
234 | 235 |
235 ASSERT_FALSE(db.GetParentPublicId(s, a)); | 236 ASSERT_FALSE(db.GetParentPublicId(s, manager, a)); |
236 ASSERT_TRUE(db.GetParentPublicId(s, b)); ASSERT_EQ("study", s); | 237 ASSERT_TRUE(db.GetParentPublicId(s, manager, b)); ASSERT_EQ("study", s); |
237 ASSERT_TRUE(db.GetParentPublicId(s, c)); ASSERT_EQ("study", s); | 238 ASSERT_TRUE(db.GetParentPublicId(s, manager, c)); ASSERT_EQ("study", s); |
238 | 239 |
239 std::list<std::string> children; | 240 std::list<std::string> children; |
240 db.GetChildren(children, a); | 241 db.GetChildren(children, manager, a); |
241 ASSERT_EQ(2u, children.size()); | 242 ASSERT_EQ(2u, children.size()); |
242 db.GetChildren(children, b); | 243 db.GetChildren(children, manager, b); |
243 ASSERT_EQ(0u, children.size()); | 244 ASSERT_EQ(0u, children.size()); |
244 db.GetChildren(children, c); | 245 db.GetChildren(children, manager, c); |
245 ASSERT_EQ(0u, children.size()); | 246 ASSERT_EQ(0u, children.size()); |
246 | 247 |
247 std::list<std::string> cp; | 248 std::list<std::string> cp; |
248 db.GetChildrenPublicId(cp, a); | 249 db.GetChildrenPublicId(cp, manager, a); |
249 ASSERT_EQ(2u, cp.size()); | 250 ASSERT_EQ(2u, cp.size()); |
250 ASSERT_TRUE(cp.front() == "series" || cp.front() == "series2"); | 251 ASSERT_TRUE(cp.front() == "series" || cp.front() == "series2"); |
251 ASSERT_TRUE(cp.back() == "series" || cp.back() == "series2"); | 252 ASSERT_TRUE(cp.back() == "series" || cp.back() == "series2"); |
252 ASSERT_NE(cp.front(), cp.back()); | 253 ASSERT_NE(cp.front(), cp.back()); |
253 | 254 |
254 std::list<std::string> pub; | 255 std::list<std::string> pub; |
255 db.GetAllPublicIds(pub, OrthancPluginResourceType_Patient); | 256 db.GetAllPublicIds(pub, manager, OrthancPluginResourceType_Patient); |
256 ASSERT_EQ(0u, pub.size()); | 257 ASSERT_EQ(0u, pub.size()); |
257 db.GetAllPublicIds(pub, OrthancPluginResourceType_Study); | 258 db.GetAllPublicIds(pub, manager, OrthancPluginResourceType_Study); |
258 ASSERT_EQ(1u, pub.size()); | 259 ASSERT_EQ(1u, pub.size()); |
259 ASSERT_EQ("study", pub.front()); | 260 ASSERT_EQ("study", pub.front()); |
260 db.GetAllPublicIds(pub, OrthancPluginResourceType_Series); | 261 db.GetAllPublicIds(pub, manager, OrthancPluginResourceType_Series); |
261 ASSERT_EQ(2u, pub.size()); | 262 ASSERT_EQ(2u, pub.size()); |
262 ASSERT_TRUE(pub.front() == "series" || pub.front() == "series2"); | 263 ASSERT_TRUE(pub.front() == "series" || pub.front() == "series2"); |
263 ASSERT_TRUE(pub.back() == "series" || pub.back() == "series2"); | 264 ASSERT_TRUE(pub.back() == "series" || pub.back() == "series2"); |
264 ASSERT_NE(pub.front(), pub.back()); | 265 ASSERT_NE(pub.front(), pub.back()); |
265 | 266 |
266 std::list<int64_t> ci; | 267 std::list<int64_t> ci; |
267 db.GetChildrenInternalId(ci, a); | 268 db.GetChildrenInternalId(ci, manager, a); |
268 ASSERT_EQ(2u, ci.size()); | 269 ASSERT_EQ(2u, ci.size()); |
269 ASSERT_TRUE(ci.front() == b || ci.front() == c); | 270 ASSERT_TRUE(ci.front() == b || ci.front() == c); |
270 ASSERT_TRUE(ci.back() == b || ci.back() == c); | 271 ASSERT_TRUE(ci.back() == b || ci.back() == c); |
271 ASSERT_NE(ci.front(), ci.back()); | 272 ASSERT_NE(ci.front(), ci.back()); |
272 | 273 |
273 db.SetMetadata(a, Orthanc::MetadataType_ModifiedFrom, "modified"); | 274 db.SetMetadata(manager, a, Orthanc::MetadataType_ModifiedFrom, "modified"); |
274 db.SetMetadata(a, Orthanc::MetadataType_LastUpdate, "update2"); | 275 db.SetMetadata(manager, a, Orthanc::MetadataType_LastUpdate, "update2"); |
275 ASSERT_FALSE(db.LookupMetadata(s, b, Orthanc::MetadataType_LastUpdate)); | 276 ASSERT_FALSE(db.LookupMetadata(s, manager, b, Orthanc::MetadataType_LastUpdate)); |
276 ASSERT_TRUE(db.LookupMetadata(s, a, Orthanc::MetadataType_LastUpdate)); | 277 ASSERT_TRUE(db.LookupMetadata(s, manager, a, Orthanc::MetadataType_LastUpdate)); |
277 ASSERT_EQ("update2", s); | 278 ASSERT_EQ("update2", s); |
278 db.SetMetadata(a, Orthanc::MetadataType_LastUpdate, "update"); | 279 db.SetMetadata(manager, a, Orthanc::MetadataType_LastUpdate, "update"); |
279 ASSERT_TRUE(db.LookupMetadata(s, a, Orthanc::MetadataType_LastUpdate)); | 280 ASSERT_TRUE(db.LookupMetadata(s, manager, a, Orthanc::MetadataType_LastUpdate)); |
280 ASSERT_EQ("update", s); | 281 ASSERT_EQ("update", s); |
281 | 282 |
282 std::list<int32_t> md; | 283 std::list<int32_t> md; |
283 db.ListAvailableMetadata(md, a); | 284 db.ListAvailableMetadata(md, manager, a); |
284 ASSERT_EQ(2u, md.size()); | 285 ASSERT_EQ(2u, md.size()); |
285 ASSERT_TRUE(md.front() == Orthanc::MetadataType_ModifiedFrom || md.back() == Orthanc::MetadataType_ModifiedFrom); | 286 ASSERT_TRUE(md.front() == Orthanc::MetadataType_ModifiedFrom || md.back() == Orthanc::MetadataType_ModifiedFrom); |
286 ASSERT_TRUE(md.front() == Orthanc::MetadataType_LastUpdate || md.back() == Orthanc::MetadataType_LastUpdate); | 287 ASSERT_TRUE(md.front() == Orthanc::MetadataType_LastUpdate || md.back() == Orthanc::MetadataType_LastUpdate); |
287 std::string mdd; | 288 std::string mdd; |
288 ASSERT_TRUE(db.LookupMetadata(mdd, a, Orthanc::MetadataType_ModifiedFrom)); | 289 ASSERT_TRUE(db.LookupMetadata(mdd, manager, a, Orthanc::MetadataType_ModifiedFrom)); |
289 ASSERT_EQ("modified", mdd); | 290 ASSERT_EQ("modified", mdd); |
290 ASSERT_TRUE(db.LookupMetadata(mdd, a, Orthanc::MetadataType_LastUpdate)); | 291 ASSERT_TRUE(db.LookupMetadata(mdd, manager, a, Orthanc::MetadataType_LastUpdate)); |
291 ASSERT_EQ("update", mdd); | 292 ASSERT_EQ("update", mdd); |
292 | 293 |
293 db.ListAvailableMetadata(md, b); | 294 db.ListAvailableMetadata(md, manager, b); |
294 ASSERT_EQ(0u, md.size()); | 295 ASSERT_EQ(0u, md.size()); |
295 | 296 |
296 db.DeleteMetadata(a, Orthanc::MetadataType_LastUpdate); | 297 db.DeleteMetadata(manager, a, Orthanc::MetadataType_LastUpdate); |
297 db.DeleteMetadata(b, Orthanc::MetadataType_LastUpdate); | 298 db.DeleteMetadata(manager, b, Orthanc::MetadataType_LastUpdate); |
298 ASSERT_FALSE(db.LookupMetadata(s, a, Orthanc::MetadataType_LastUpdate)); | 299 ASSERT_FALSE(db.LookupMetadata(s, manager, a, Orthanc::MetadataType_LastUpdate)); |
299 | 300 |
300 db.ListAvailableMetadata(md, a); | 301 db.ListAvailableMetadata(md, manager, a); |
301 ASSERT_EQ(1u, md.size()); | 302 ASSERT_EQ(1u, md.size()); |
302 ASSERT_EQ(Orthanc::MetadataType_ModifiedFrom, md.front()); | 303 ASSERT_EQ(Orthanc::MetadataType_ModifiedFrom, md.front()); |
303 | 304 |
304 ASSERT_EQ(0u, db.GetTotalCompressedSize()); | 305 ASSERT_EQ(0u, db.GetTotalCompressedSize(manager)); |
305 ASSERT_EQ(0u, db.GetTotalUncompressedSize()); | 306 ASSERT_EQ(0u, db.GetTotalUncompressedSize(manager)); |
306 | 307 |
307 | 308 |
308 std::list<int32_t> fc; | 309 std::list<int32_t> fc; |
309 | 310 |
310 OrthancPluginAttachment a1; | 311 OrthancPluginAttachment a1; |
323 a2.uncompressedHash = "md5_2"; | 324 a2.uncompressedHash = "md5_2"; |
324 a2.compressionType = Orthanc::CompressionType_None; | 325 a2.compressionType = Orthanc::CompressionType_None; |
325 a2.compressedSize = 4242; | 326 a2.compressedSize = 4242; |
326 a2.compressedHash = "md5_2"; | 327 a2.compressedHash = "md5_2"; |
327 | 328 |
328 db.AddAttachment(a, a1); | 329 db.AddAttachment(manager, a, a1); |
329 db.ListAvailableAttachments(fc, a); | 330 db.ListAvailableAttachments(fc, manager, a); |
330 ASSERT_EQ(1u, fc.size()); | 331 ASSERT_EQ(1u, fc.size()); |
331 ASSERT_EQ(Orthanc::FileContentType_Dicom, fc.front()); | 332 ASSERT_EQ(Orthanc::FileContentType_Dicom, fc.front()); |
332 db.AddAttachment(a, a2); | 333 db.AddAttachment(manager, a, a2); |
333 db.ListAvailableAttachments(fc, a); | 334 db.ListAvailableAttachments(fc, manager, a); |
334 ASSERT_EQ(2u, fc.size()); | 335 ASSERT_EQ(2u, fc.size()); |
335 ASSERT_FALSE(db.LookupAttachment(*output, b, Orthanc::FileContentType_Dicom)); | 336 ASSERT_FALSE(db.LookupAttachment(*output, manager, b, Orthanc::FileContentType_Dicom)); |
336 | 337 |
337 ASSERT_EQ(4284u, db.GetTotalCompressedSize()); | 338 ASSERT_EQ(4284u, db.GetTotalCompressedSize(manager)); |
338 ASSERT_EQ(4284u, db.GetTotalUncompressedSize()); | 339 ASSERT_EQ(4284u, db.GetTotalUncompressedSize(manager)); |
339 | 340 |
340 expectedAttachment.reset(new OrthancPluginAttachment); | 341 expectedAttachment.reset(new OrthancPluginAttachment); |
341 expectedAttachment->uuid = "uuid1"; | 342 expectedAttachment->uuid = "uuid1"; |
342 expectedAttachment->contentType = Orthanc::FileContentType_Dicom; | 343 expectedAttachment->contentType = Orthanc::FileContentType_Dicom; |
343 expectedAttachment->uncompressedSize = 42; | 344 expectedAttachment->uncompressedSize = 42; |
344 expectedAttachment->uncompressedHash = "md5_1"; | 345 expectedAttachment->uncompressedHash = "md5_1"; |
345 expectedAttachment->compressionType = Orthanc::CompressionType_None; | 346 expectedAttachment->compressionType = Orthanc::CompressionType_None; |
346 expectedAttachment->compressedSize = 42; | 347 expectedAttachment->compressedSize = 42; |
347 expectedAttachment->compressedHash = "md5_1"; | 348 expectedAttachment->compressedHash = "md5_1"; |
348 ASSERT_TRUE(db.LookupAttachment(*output, a, Orthanc::FileContentType_Dicom)); | 349 ASSERT_TRUE(db.LookupAttachment(*output, manager, a, Orthanc::FileContentType_Dicom)); |
349 | 350 |
350 expectedAttachment.reset(new OrthancPluginAttachment); | 351 expectedAttachment.reset(new OrthancPluginAttachment); |
351 expectedAttachment->uuid = "uuid2"; | 352 expectedAttachment->uuid = "uuid2"; |
352 expectedAttachment->contentType = Orthanc::FileContentType_DicomAsJson; | 353 expectedAttachment->contentType = Orthanc::FileContentType_DicomAsJson; |
353 expectedAttachment->uncompressedSize = 4242; | 354 expectedAttachment->uncompressedSize = 4242; |
354 expectedAttachment->uncompressedHash = "md5_2"; | 355 expectedAttachment->uncompressedHash = "md5_2"; |
355 expectedAttachment->compressionType = Orthanc::CompressionType_None; | 356 expectedAttachment->compressionType = Orthanc::CompressionType_None; |
356 expectedAttachment->compressedSize = 4242; | 357 expectedAttachment->compressedSize = 4242; |
357 expectedAttachment->compressedHash = "md5_2"; | 358 expectedAttachment->compressedHash = "md5_2"; |
358 ASSERT_TRUE(db.LookupAttachment(*output, a, Orthanc::FileContentType_DicomAsJson)); | 359 ASSERT_TRUE(db.LookupAttachment(*output, manager, a, Orthanc::FileContentType_DicomAsJson)); |
359 | 360 |
360 db.ListAvailableAttachments(fc, b); | 361 db.ListAvailableAttachments(fc, manager, b); |
361 ASSERT_EQ(0u, fc.size()); | 362 ASSERT_EQ(0u, fc.size()); |
362 db.DeleteAttachment(*output, a, Orthanc::FileContentType_Dicom); | 363 db.DeleteAttachment(*output, manager, a, Orthanc::FileContentType_Dicom); |
363 db.ListAvailableAttachments(fc, a); | 364 db.ListAvailableAttachments(fc, manager, a); |
364 ASSERT_EQ(1u, fc.size()); | 365 ASSERT_EQ(1u, fc.size()); |
365 ASSERT_EQ(Orthanc::FileContentType_DicomAsJson, fc.front()); | 366 ASSERT_EQ(Orthanc::FileContentType_DicomAsJson, fc.front()); |
366 db.DeleteAttachment(*output, a, Orthanc::FileContentType_DicomAsJson); | 367 db.DeleteAttachment(*output, manager, a, Orthanc::FileContentType_DicomAsJson); |
367 db.ListAvailableAttachments(fc, a); | 368 db.ListAvailableAttachments(fc, manager, a); |
368 ASSERT_EQ(0u, fc.size()); | 369 ASSERT_EQ(0u, fc.size()); |
369 | 370 |
370 | 371 |
371 db.SetIdentifierTag(a, 0x0010, 0x0020, "patient"); | 372 db.SetIdentifierTag(manager, a, 0x0010, 0x0020, "patient"); |
372 db.SetIdentifierTag(a, 0x0020, 0x000d, "study"); | 373 db.SetIdentifierTag(manager, a, 0x0020, 0x000d, "study"); |
373 | 374 |
374 expectedDicomTags.clear(); | 375 expectedDicomTags.clear(); |
375 expectedDicomTags.push_back(OrthancPluginDicomTag()); | 376 expectedDicomTags.push_back(OrthancPluginDicomTag()); |
376 expectedDicomTags.push_back(OrthancPluginDicomTag()); | 377 expectedDicomTags.push_back(OrthancPluginDicomTag()); |
377 expectedDicomTags.front().group = 0x0010; | 378 expectedDicomTags.front().group = 0x0010; |
378 expectedDicomTags.front().element = 0x0020; | 379 expectedDicomTags.front().element = 0x0020; |
379 expectedDicomTags.front().value = "patient"; | 380 expectedDicomTags.front().value = "patient"; |
380 expectedDicomTags.back().group = 0x0020; | 381 expectedDicomTags.back().group = 0x0020; |
381 expectedDicomTags.back().element = 0x000d; | 382 expectedDicomTags.back().element = 0x000d; |
382 expectedDicomTags.back().value = "study"; | 383 expectedDicomTags.back().value = "study"; |
383 db.GetMainDicomTags(*output, a); | 384 db.GetMainDicomTags(*output, manager, a); |
384 | 385 |
385 | 386 |
386 db.LookupIdentifier(ci, OrthancPluginResourceType_Study, 0x0010, 0x0020, | 387 db.LookupIdentifier(ci, manager, OrthancPluginResourceType_Study, 0x0010, 0x0020, |
387 OrthancPluginIdentifierConstraint_Equal, "patient"); | 388 OrthancPluginIdentifierConstraint_Equal, "patient"); |
388 ASSERT_EQ(1u, ci.size()); | 389 ASSERT_EQ(1u, ci.size()); |
389 ASSERT_EQ(a, ci.front()); | 390 ASSERT_EQ(a, ci.front()); |
390 db.LookupIdentifier(ci, OrthancPluginResourceType_Study, 0x0010, 0x0020, | 391 db.LookupIdentifier(ci, manager, OrthancPluginResourceType_Study, 0x0010, 0x0020, |
391 OrthancPluginIdentifierConstraint_Equal, "study"); | 392 OrthancPluginIdentifierConstraint_Equal, "study"); |
392 ASSERT_EQ(0u, ci.size()); | 393 ASSERT_EQ(0u, ci.size()); |
393 | 394 |
394 | 395 |
395 OrthancPluginExportedResource exp; | 396 OrthancPluginExportedResource exp; |
400 exp.date = "date"; | 401 exp.date = "date"; |
401 exp.patientId = "patient"; | 402 exp.patientId = "patient"; |
402 exp.studyInstanceUid = "study"; | 403 exp.studyInstanceUid = "study"; |
403 exp.seriesInstanceUid = "series"; | 404 exp.seriesInstanceUid = "series"; |
404 exp.sopInstanceUid = "instance"; | 405 exp.sopInstanceUid = "instance"; |
405 db.LogExportedResource(exp); | 406 db.LogExportedResource(manager, exp); |
406 | 407 |
407 expectedExported.reset(new OrthancPluginExportedResource()); | 408 expectedExported.reset(new OrthancPluginExportedResource()); |
408 *expectedExported = exp; | 409 *expectedExported = exp; |
409 expectedExported->seq = 1; | 410 expectedExported->seq = 1; |
410 | 411 |
411 bool done; | 412 bool done; |
412 db.GetExportedResources(*output, done, 0, 10); | 413 db.GetExportedResources(*output, done, manager, 0, 10); |
413 | 414 |
414 | 415 |
415 db.GetAllPublicIds(pub, OrthancPluginResourceType_Patient); ASSERT_EQ(0u, pub.size()); | 416 db.GetAllPublicIds(pub, manager, OrthancPluginResourceType_Patient); ASSERT_EQ(0u, pub.size()); |
416 db.GetAllPublicIds(pub, OrthancPluginResourceType_Study); ASSERT_EQ(1u, pub.size()); | 417 db.GetAllPublicIds(pub, manager, OrthancPluginResourceType_Study); ASSERT_EQ(1u, pub.size()); |
417 db.GetAllPublicIds(pub, OrthancPluginResourceType_Series); ASSERT_EQ(2u, pub.size()); | 418 db.GetAllPublicIds(pub, manager, OrthancPluginResourceType_Series); ASSERT_EQ(2u, pub.size()); |
418 db.GetAllPublicIds(pub, OrthancPluginResourceType_Instance); ASSERT_EQ(0u, pub.size()); | 419 db.GetAllPublicIds(pub, manager, OrthancPluginResourceType_Instance); ASSERT_EQ(0u, pub.size()); |
419 ASSERT_EQ(3u, db.GetAllResourcesCount()); | 420 ASSERT_EQ(3u, db.GetAllResourcesCount(manager)); |
420 | 421 |
421 ASSERT_EQ(0u, db.GetUnprotectedPatientsCount()); // No patient was inserted | 422 ASSERT_EQ(0u, db.GetUnprotectedPatientsCount(manager)); // No patient was inserted |
422 ASSERT_TRUE(db.IsExistingResource(c)); | 423 ASSERT_TRUE(db.IsExistingResource(manager, c)); |
423 | 424 |
424 { | 425 { |
425 // A transaction is needed here for MySQL, as it was not possible | 426 // A transaction is needed here for MySQL, as it was not possible |
426 // to implement recursive deletion of resources using pure SQL | 427 // to implement recursive deletion of resources using pure SQL |
427 // statements | 428 // statements |
428 db.StartTransaction(TransactionType_ReadWrite); | 429 manager.StartTransaction(TransactionType_ReadWrite); |
429 db.DeleteResource(*output, c); | 430 db.DeleteResource(*output, manager, c); |
430 db.CommitTransaction(); | 431 manager.CommitTransaction(); |
431 } | 432 } |
432 | 433 |
433 ASSERT_FALSE(db.IsExistingResource(c)); | 434 ASSERT_FALSE(db.IsExistingResource(manager, c)); |
434 ASSERT_TRUE(db.IsExistingResource(a)); | 435 ASSERT_TRUE(db.IsExistingResource(manager, a)); |
435 ASSERT_TRUE(db.IsExistingResource(b)); | 436 ASSERT_TRUE(db.IsExistingResource(manager, b)); |
436 ASSERT_EQ(2u, db.GetAllResourcesCount()); | 437 ASSERT_EQ(2u, db.GetAllResourcesCount(manager)); |
437 db.DeleteResource(*output, a); | 438 db.DeleteResource(*output, manager, a); |
438 ASSERT_EQ(0u, db.GetAllResourcesCount()); | 439 ASSERT_EQ(0u, db.GetAllResourcesCount(manager)); |
439 ASSERT_FALSE(db.IsExistingResource(a)); | 440 ASSERT_FALSE(db.IsExistingResource(manager, a)); |
440 ASSERT_FALSE(db.IsExistingResource(b)); | 441 ASSERT_FALSE(db.IsExistingResource(manager, b)); |
441 ASSERT_FALSE(db.IsExistingResource(c)); | 442 ASSERT_FALSE(db.IsExistingResource(manager, c)); |
442 | 443 |
443 ASSERT_EQ(0u, db.GetAllResourcesCount()); | 444 ASSERT_EQ(0u, db.GetAllResourcesCount(manager)); |
444 ASSERT_EQ(0u, db.GetUnprotectedPatientsCount()); | 445 ASSERT_EQ(0u, db.GetUnprotectedPatientsCount(manager)); |
445 int64_t p1 = db.CreateResource("patient1", OrthancPluginResourceType_Patient); | 446 int64_t p1 = db.CreateResource(manager, "patient1", OrthancPluginResourceType_Patient); |
446 int64_t p2 = db.CreateResource("patient2", OrthancPluginResourceType_Patient); | 447 int64_t p2 = db.CreateResource(manager, "patient2", OrthancPluginResourceType_Patient); |
447 int64_t p3 = db.CreateResource("patient3", OrthancPluginResourceType_Patient); | 448 int64_t p3 = db.CreateResource(manager, "patient3", OrthancPluginResourceType_Patient); |
448 ASSERT_EQ(3u, db.GetUnprotectedPatientsCount()); | 449 ASSERT_EQ(3u, db.GetUnprotectedPatientsCount(manager)); |
449 int64_t r; | 450 int64_t r; |
450 ASSERT_TRUE(db.SelectPatientToRecycle(r)); | 451 ASSERT_TRUE(db.SelectPatientToRecycle(r, manager)); |
451 ASSERT_EQ(p1, r); | 452 ASSERT_EQ(p1, r); |
452 ASSERT_TRUE(db.SelectPatientToRecycle(r, p1)); | 453 ASSERT_TRUE(db.SelectPatientToRecycle(r, manager, p1)); |
453 ASSERT_EQ(p2, r); | 454 ASSERT_EQ(p2, r); |
454 ASSERT_FALSE(db.IsProtectedPatient(p1)); | 455 ASSERT_FALSE(db.IsProtectedPatient(manager, p1)); |
455 db.SetProtectedPatient(p1, true); | 456 db.SetProtectedPatient(manager, p1, true); |
456 ASSERT_TRUE(db.IsProtectedPatient(p1)); | 457 ASSERT_TRUE(db.IsProtectedPatient(manager, p1)); |
457 ASSERT_TRUE(db.SelectPatientToRecycle(r)); | 458 ASSERT_TRUE(db.SelectPatientToRecycle(r, manager)); |
458 ASSERT_EQ(p2, r); | 459 ASSERT_EQ(p2, r); |
459 db.SetProtectedPatient(p1, false); | 460 db.SetProtectedPatient(manager, p1, false); |
460 ASSERT_FALSE(db.IsProtectedPatient(p1)); | 461 ASSERT_FALSE(db.IsProtectedPatient(manager, p1)); |
461 ASSERT_TRUE(db.SelectPatientToRecycle(r)); | 462 ASSERT_TRUE(db.SelectPatientToRecycle(r, manager)); |
462 ASSERT_EQ(p2, r); | 463 ASSERT_EQ(p2, r); |
463 db.DeleteResource(*output, p2); | 464 db.DeleteResource(*output, manager, p2); |
464 ASSERT_TRUE(db.SelectPatientToRecycle(r, p3)); | 465 ASSERT_TRUE(db.SelectPatientToRecycle(r, manager, p3)); |
465 ASSERT_EQ(p1, r); | 466 ASSERT_EQ(p1, r); |
466 } | 467 |
468 manager.Close(); | |
469 } |