ctkDICOMDatabaseTest1.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include <QTimer>
  18. // ctkDICOMCore includes
  19. #include "ctkDICOMDatabase.h"
  20. // STD includes
  21. #include <iostream>
  22. #include <cstdlib>
  23. int ctkDICOMDatabaseTest1( int argc, char * argv [] )
  24. {
  25. QCoreApplication app(argc, argv);
  26. ctkDICOMDatabase database;
  27. QDir databaseDirectory = QDir::temp();
  28. QFileInfo databaseFile(databaseDirectory, QString("database.test"));
  29. database.openDatabase(databaseFile.absoluteFilePath());
  30. if (!database.lastError().isEmpty())
  31. {
  32. std::cerr << "ctkDICOMDatabase::openDatabase() failed: "
  33. << qPrintable(database.lastError()) << std::endl;
  34. return EXIT_FAILURE;
  35. }
  36. if (!database.database().isValid())
  37. {
  38. std::cerr << "ctkDICOMDatabase::openDatabase() failed: "
  39. << "invalid sql database" << std::endl;
  40. return EXIT_FAILURE;
  41. }
  42. if (database.isInMemory())
  43. {
  44. std::cerr << "ctkDICOMDatabase::openDatabase() failed: "
  45. << "database should not be in memory" << std::endl;
  46. return EXIT_FAILURE;
  47. }
  48. if (database.databaseFilename() != databaseFile.absoluteFilePath())
  49. {
  50. std::cerr << "ctkDICOMDatabase::databaseFilename() failed: "
  51. << qPrintable( database.databaseFilename()) << std::endl;
  52. return EXIT_FAILURE;
  53. }
  54. if (QDir(database.databaseDirectory()) != databaseDirectory)
  55. {
  56. std::cerr << "ctkDICOMDatabase::databaseDirectory() failed"
  57. << qPrintable(database.databaseDirectory()) << std::endl;
  58. return EXIT_FAILURE;
  59. }
  60. bool res = database.initializeDatabase();
  61. if (!res)
  62. {
  63. std::cerr << "ctkDICOMDatabase::initializeDatabase() failed." << std::endl;
  64. return EXIT_FAILURE;
  65. }
  66. // check if it doesn't crash
  67. database.pathForDataset(0);
  68. database.insert(0, true, true);
  69. database.insert(0, true, false);
  70. database.insert(0, false, true);
  71. database.insert(0, false, false);
  72. database.closeDatabase();
  73. database.initializeDatabase();
  74. return EXIT_SUCCESS;
  75. }