ctkDICOMTesterTest1.cpp 4.0 KB

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