ctkDICOMTesterTest1.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Qt includes
  2. #include <QCoreApplication>
  3. #include <QFileInfo>
  4. // ctkDICOMCore includes
  5. #include "ctkDICOMTester.h"
  6. // STD includes
  7. #include <iostream>
  8. #include <cstdlib>
  9. void printUsage()
  10. {
  11. std::cout << " ctkDICOMTesterTest1 [<dcmqrscp>] [<configfile>]" << std::endl;
  12. }
  13. int ctkDICOMTesterTest1(int argc, char * argv [])
  14. {
  15. QCoreApplication app(argc, argv);
  16. ctkDICOMTester tester;
  17. if (argc > 1)
  18. {
  19. tester.setDCMQRSCPExecutable(argv[1]);
  20. if (tester.dcmqrscpExecutable() != argv[1])
  21. {
  22. std::cerr << __LINE__
  23. << ": Failed to set dcmqrscp: " << argv[1]
  24. << " value:" << qPrintable(tester.dcmqrscpExecutable())
  25. << std::endl;
  26. return EXIT_FAILURE;
  27. }
  28. }
  29. if (argc > 2)
  30. {
  31. tester.setDCMQRSCPConfigFile(argv[2]);
  32. if (tester.dcmqrscpConfigFile() != argv[2])
  33. {
  34. std::cerr << __LINE__
  35. << ": Failed to set dcmqrscp config file: " << argv[2]
  36. << " value:" << qPrintable(tester.dcmqrscpConfigFile())
  37. << std::endl;
  38. return EXIT_FAILURE;
  39. }
  40. }
  41. QString dcmqrscp(tester.dcmqrscpExecutable());
  42. QString dcmqrscpConf(tester.dcmqrscpConfigFile());
  43. if (!QFileInfo(dcmqrscp).exists() ||
  44. !QFileInfo(dcmqrscp).isExecutable())
  45. {
  46. std::cerr << __LINE__
  47. << ": Wrong dcmqrscp executable: " << qPrintable(dcmqrscp)
  48. << std::endl;
  49. }
  50. if (!QFileInfo(dcmqrscpConf).exists() ||
  51. !QFileInfo(dcmqrscpConf).isReadable())
  52. {
  53. std::cerr << __LINE__
  54. << ": Wrong dcmqrscp executable: " << qPrintable(dcmqrscp)
  55. << std::endl;
  56. }
  57. QProcess* process = tester.startDCMQRSCP();
  58. if (!process)
  59. {
  60. std::cerr << __LINE__
  61. << ": Failed to start dcmqrscp: " << qPrintable(dcmqrscp)
  62. << " with config file:" << qPrintable(dcmqrscpConf) << std::endl;
  63. return EXIT_FAILURE;
  64. }
  65. bool res = tester.stopDCMQRSCP();
  66. if (!res)
  67. {
  68. std::cerr << __LINE__
  69. << ": Failed to stop dcmqrscp: " << qPrintable(dcmqrscp)
  70. << " with config file:" << qPrintable(dcmqrscpConf) << std::endl;
  71. return EXIT_FAILURE;
  72. }
  73. process = tester.startDCMQRSCP();
  74. if (!process)
  75. {
  76. std::cerr << __LINE__
  77. << ": Failed to start dcmqrscp: " << qPrintable(dcmqrscp)
  78. << " with config file:" << qPrintable(dcmqrscpConf)
  79. << std::endl;
  80. return EXIT_FAILURE;
  81. }
  82. process = tester.startDCMQRSCP();
  83. if (process)
  84. {
  85. std::cerr << __LINE__
  86. << ": Failed to start dcmqrscp: " << qPrintable(dcmqrscp)
  87. << " with config file:"<< qPrintable(dcmqrscpConf) << std::endl;
  88. return EXIT_FAILURE;
  89. }
  90. res = tester.stopDCMQRSCP();
  91. if (!res)
  92. {
  93. std::cerr << __LINE__
  94. << ": Failed to stop dcmqrscp: " << qPrintable(dcmqrscp)
  95. << " with config file:" << qPrintable(dcmqrscpConf) << std::endl;
  96. return EXIT_FAILURE;
  97. }
  98. // there should be no process to stop
  99. res = tester.stopDCMQRSCP();
  100. if (res)
  101. {
  102. std::cerr << __LINE__
  103. << ": Failed to stop dcmqrscp: " << qPrintable(dcmqrscp)
  104. << " with config file:" << qPrintable(dcmqrscpConf) << std::endl;
  105. return EXIT_FAILURE;
  106. }
  107. return EXIT_SUCCESS;
  108. }