ctkDICOMDatabaseTest5.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QCoreApplication>
  16. #include <QDir>
  17. // ctkDICOMCore includes
  18. #include "ctkDICOMDatabase.h"
  19. // STD includes
  20. #include <iostream>
  21. #include <cstdlib>
  22. int ctkDICOMDatabaseTest5( int argc, char * argv [] )
  23. {
  24. QCoreApplication app(argc, argv);
  25. if (argc < 2)
  26. {
  27. std::cerr << "ctkDICOMDatabaseTest2: missing dicom filePath argument";
  28. std::cerr << std::endl;
  29. return EXIT_FAILURE;
  30. }
  31. QString dicomFilePath(argv[1]);
  32. ctkDICOMDatabase database;
  33. QDir databaseDirectory = QDir::temp();
  34. databaseDirectory.remove("ctkDICOMDatabase.sql");
  35. databaseDirectory.remove("ctkDICOMTagCache.sql");
  36. QFileInfo databaseFile(databaseDirectory, QString("database.test"));
  37. database.openDatabase(databaseFile.absoluteFilePath());
  38. bool res = database.initializeDatabase();
  39. if (!res)
  40. {
  41. std::cerr << "ctkDICOMDatabase::initializeDatabase() failed." << std::endl;
  42. return EXIT_FAILURE;
  43. }
  44. std::cerr << "Database is in " << databaseDirectory.path().toStdString() << std::endl;
  45. //
  46. // First, copy the passed file to two temp directories
  47. //
  48. databaseDirectory.rmdir("firstInsert");
  49. databaseDirectory.rmdir("secondInsert");
  50. databaseDirectory.mkdir("firstInsert");
  51. databaseDirectory.mkdir("secondInsert");
  52. QString firstDestination = QDir::cleanPath(databaseDirectory.absolutePath() + QDir::separator() + "firstInsert" + QDir::separator() + "file.dcm");
  53. QString secondDestination = QDir::cleanPath(databaseDirectory.absolutePath() + QDir::separator() + "secondInsert" + QDir::separator() + "file.dcm");
  54. QFile::copy(dicomFilePath, firstDestination);
  55. std::cerr << "copied to: " << firstDestination.toStdString() << std::endl;
  56. QFile::copy(dicomFilePath, secondDestination);
  57. std::cerr << "copied to: " << secondDestination.toStdString() << std::endl;
  58. //
  59. // Insert the first instance
  60. //
  61. database.insert(firstDestination, false, false);
  62. //
  63. // Now delete the first instance and try inserting the second
  64. //
  65. QFile::remove(firstDestination);
  66. database.insert(secondDestination, false, false);
  67. //
  68. // At this point, the file associated with the instance UID should be
  69. // the secondDestination - it's an error if not.
  70. //
  71. QString instanceUID("1.2.840.113619.2.135.3596.6358736.4843.1115808177.83");
  72. QString filePathInDatabase = database.fileForInstance(instanceUID);
  73. if (filePathInDatabase != secondDestination)
  74. {
  75. std::cerr << "ctkDICOMDatabase thinks instance is in " << filePathInDatabase.toStdString() << std::endl;
  76. std::cerr << "But we just inserted it from " << secondDestination.toStdString() << std::endl;
  77. return EXIT_FAILURE;
  78. }
  79. //
  80. // Close and clean up
  81. //
  82. database.closeDatabase();
  83. return EXIT_SUCCESS;
  84. }