comparison PostgreSQL/UnitTests/PostgreSQLTests.cpp @ 242:b97a537f4613

MySQL: Support of range reads for the storage area
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 13 Apr 2021 17:00:02 +0200
parents 35598014f140
children 483af3f35a4b
comparison
equal deleted inserted replaced
241:a063bbf10a3e 242:b97a537f4613
361 std::unique_ptr<PostgreSQLDatabase> database(PostgreSQLDatabase::OpenDatabaseConnection(globalParameters_)); 361 std::unique_ptr<PostgreSQLDatabase> database(PostgreSQLDatabase::OpenDatabaseConnection(globalParameters_));
362 362
363 PostgreSQLStorageArea storageArea(globalParameters_, true /* clear database */); 363 PostgreSQLStorageArea storageArea(globalParameters_, true /* clear database */);
364 364
365 { 365 {
366 PostgreSQLStorageArea::Accessor accessor(storageArea); 366 std::unique_ptr<OrthancDatabases::StorageBackend::IAccessor> accessor(storageArea.CreateAccessor());
367 367
368 ASSERT_EQ(0, CountLargeObjects(*database)); 368 ASSERT_EQ(0, CountLargeObjects(*database));
369 369
370 for (int i = 0; i < 10; i++) 370 for (int i = 0; i < 10; i++)
371 { 371 {
372 std::string uuid = boost::lexical_cast<std::string>(i); 372 std::string uuid = boost::lexical_cast<std::string>(i);
373 std::string value = "Value " + boost::lexical_cast<std::string>(i * 2); 373 std::string value = "Value " + boost::lexical_cast<std::string>(i * 2);
374 accessor.Create(uuid, value.c_str(), value.size(), OrthancPluginContentType_Unknown); 374 accessor->Create(uuid, value.c_str(), value.size(), OrthancPluginContentType_Unknown);
375 } 375 }
376 376
377 std::string buffer; 377 std::string buffer;
378 ASSERT_THROW(accessor.ReadToString(buffer, "nope", OrthancPluginContentType_Unknown), 378 ASSERT_THROW(OrthancDatabases::StorageBackend::ReadWholeToString(buffer, *accessor, "nope", OrthancPluginContentType_Unknown),
379 Orthanc::OrthancException); 379 Orthanc::OrthancException);
380 380
381 ASSERT_EQ(10, CountLargeObjects(*database)); 381 ASSERT_EQ(10, CountLargeObjects(*database));
382 accessor.Remove("5", OrthancPluginContentType_Unknown); 382 accessor->Remove("5", OrthancPluginContentType_Unknown);
383 383
384 ASSERT_EQ(9, CountLargeObjects(*database)); 384 ASSERT_EQ(9, CountLargeObjects(*database));
385 385
386 for (int i = 0; i < 10; i++) 386 for (int i = 0; i < 10; i++)
387 { 387 {
388 std::string uuid = boost::lexical_cast<std::string>(i); 388 std::string uuid = boost::lexical_cast<std::string>(i);
389 std::string expected = "Value " + boost::lexical_cast<std::string>(i * 2); 389 std::string expected = "Value " + boost::lexical_cast<std::string>(i * 2);
390 390
391 if (i == 5) 391 if (i == 5)
392 { 392 {
393 ASSERT_THROW(accessor.ReadToString(buffer, uuid, OrthancPluginContentType_Unknown), 393 ASSERT_THROW(OrthancDatabases::StorageBackend::ReadWholeToString(buffer, *accessor, uuid, OrthancPluginContentType_Unknown),
394 Orthanc::OrthancException); 394 Orthanc::OrthancException);
395 } 395 }
396 else 396 else
397 { 397 {
398 accessor.ReadToString(buffer, uuid, OrthancPluginContentType_Unknown); 398 OrthancDatabases::StorageBackend::ReadWholeToString(buffer, *accessor, uuid, OrthancPluginContentType_Unknown);
399 ASSERT_EQ(expected, buffer); 399 ASSERT_EQ(expected, buffer);
400 } 400 }
401 } 401 }
402 402
403 for (int i = 0; i < 10; i++) 403 for (int i = 0; i < 10; i++)
404 { 404 {
405 accessor.Remove(boost::lexical_cast<std::string>(i), OrthancPluginContentType_Unknown); 405 accessor->Remove(boost::lexical_cast<std::string>(i), OrthancPluginContentType_Unknown);
406 } 406 }
407 407
408 ASSERT_EQ(0, CountLargeObjects(*database)); 408 ASSERT_EQ(0, CountLargeObjects(*database));
409 } 409 }
410 } 410 }