ctkDICOMAppWidgetTest1.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <QApplication>
  16. #include <QDebug>
  17. #include <QDir>
  18. #include <QTimer>
  19. #include <QString>
  20. // ctk includes
  21. #include "ctkUtils.h"
  22. // ctkDICOMCore includes
  23. #include "ctkDICOMAppWidget.h"
  24. // STD includes
  25. #include <iostream>
  26. /* Test from build directory:
  27. ./CTK-build/bin/CTKDICOMWidgetsCppTests ctkDICOMAppWidgetTest1 <test directory>
  28. if the test directory does not have 100 instances in one patient/study/series, test will fail
  29. */
  30. int ctkDICOMAppWidgetTest1( int argc, char * argv [] )
  31. {
  32. QApplication app(argc, argv);
  33. ctkDICOMAppWidget appWidget;
  34. QFileInfo tempFileInfo(QDir::tempPath() + QString("/ctkDICOMAppWidgetTest1-db"));
  35. QString dbDir = tempFileInfo.absoluteFilePath();
  36. qDebug() << "\n\nUsing directory: " << dbDir;
  37. if (tempFileInfo.exists())
  38. {
  39. qDebug() << "\n\nRemoving directory: " << dbDir;
  40. ctk::removeDirRecursively(dbDir);
  41. }
  42. qDebug() << "\n\nMaking directory: " << dbDir;
  43. QDir dir(dbDir);
  44. dir.mkdir(dbDir);
  45. appWidget.setDatabaseDirectory(dbDir);
  46. QString testString = QString("Test String");
  47. appWidget.onFileIndexed(testString);
  48. appWidget.openImportDialog();
  49. appWidget.openExportDialog();
  50. appWidget.openQueryDialog();
  51. appWidget.openQueryDialog();
  52. appWidget.setDisplayImportSummary(false);
  53. appWidget.onImportDirectory(argv[argc -1]);
  54. if ( appWidget.patientsAddedDuringImport() != 1
  55. || appWidget.studiesAddedDuringImport() != 1
  56. || appWidget.seriesAddedDuringImport() != 1
  57. || appWidget.instancesAddedDuringImport() != 100)
  58. {
  59. qDebug() << "\n\nDirectory did not import as expected!\n\n";
  60. return EXIT_FAILURE;
  61. }
  62. if (argc <= 2 || QString(argv[1]) != "-I")
  63. {
  64. QTimer::singleShot(200, &app, SLOT(quit()));
  65. }
  66. qDebug() << "\n\nAdded to database directory: " << dbDir;
  67. return app.exec();
  68. }