ctkDICOMAppWidgetTest1.cpp 2.6 KB

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