ctkCmdLineModuleSignalTester.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkCmdLineModuleSignalTester.h"
  16. #include <QDebug>
  17. //-----------------------------------------------------------------------------
  18. ctkCmdLineModuleSignalTester::ctkCmdLineModuleSignalTester()
  19. {
  20. connect(&Watcher, SIGNAL(started()), SLOT(moduleStarted()));
  21. connect(&Watcher, SIGNAL(canceled()), SLOT(moduleCanceled()));
  22. connect(&Watcher, SIGNAL(finished()), SLOT(moduleFinished()));
  23. connect(&Watcher, SIGNAL(paused()), SLOT(modulePaused()));
  24. connect(&Watcher, SIGNAL(resumed()), SLOT(moduleResumed()));
  25. connect(&Watcher, SIGNAL(resultReadyAt(int)), SLOT(resultReadyAt(int)));
  26. connect(&Watcher, SIGNAL(resultsReadyAt(int,int)), SLOT(resultReadyAt(int,int)));
  27. connect(&Watcher, SIGNAL(progressRangeChanged(int,int)), SLOT(progressRangeChanged(int,int)));
  28. connect(&Watcher, SIGNAL(progressTextChanged(QString)), SLOT(progressTextChanged(QString)));
  29. connect(&Watcher, SIGNAL(progressValueChanged(int)), SLOT(progressValueChanged(int)));
  30. connect(&Watcher, SIGNAL(outputDataReady()), SLOT(outputDataReady()));
  31. connect(&Watcher, SIGNAL(errorDataReady()), SLOT(errorDataReady()));
  32. }
  33. //-----------------------------------------------------------------------------
  34. void ctkCmdLineModuleSignalTester::setFuture(const ctkCmdLineModuleFuture &future)
  35. {
  36. this->Watcher.setFuture(future);
  37. }
  38. //-----------------------------------------------------------------------------
  39. ctkCmdLineModuleFutureWatcher *ctkCmdLineModuleSignalTester::watcher()
  40. {
  41. return &this->Watcher;
  42. }
  43. //-----------------------------------------------------------------------------
  44. void ctkCmdLineModuleSignalTester::moduleStarted()
  45. {
  46. Events.push_back("module.started");
  47. }
  48. //-----------------------------------------------------------------------------
  49. void ctkCmdLineModuleSignalTester::moduleFinished()
  50. {
  51. Events.push_back("module.finished");
  52. }
  53. //-----------------------------------------------------------------------------
  54. void ctkCmdLineModuleSignalTester::moduleProgressValueChanged(int progress)
  55. {
  56. Events.push_back(QString("module.progressValueChanged(%1)").arg(progress));
  57. }
  58. //-----------------------------------------------------------------------------
  59. void ctkCmdLineModuleSignalTester::moduleProgressTextChanged(const QString& text)
  60. {
  61. Events.push_back(QString("module.progressTextChanged(\"%1\")").arg(text));
  62. }
  63. //-----------------------------------------------------------------------------
  64. void ctkCmdLineModuleSignalTester::modulePaused()
  65. {
  66. Events.push_back("module.paused");
  67. }
  68. //-----------------------------------------------------------------------------
  69. void ctkCmdLineModuleSignalTester::moduleResumed()
  70. {
  71. Events.push_back("module.resumed");
  72. }
  73. //-----------------------------------------------------------------------------
  74. void ctkCmdLineModuleSignalTester::moduleCanceled()
  75. {
  76. Events.push_back("module.canceled");
  77. }
  78. //-----------------------------------------------------------------------------
  79. void ctkCmdLineModuleSignalTester::resultReadyAt(int resultIndex)
  80. {
  81. Events.push_back(QString("module.resultReadyAt(%1)").arg(resultIndex));
  82. Results.push_back(Watcher.resultAt(resultIndex));
  83. }
  84. //-----------------------------------------------------------------------------
  85. void ctkCmdLineModuleSignalTester::resultReadyAt(int beginIndex, int endIndex)
  86. {
  87. Events.push_back(QString("module.resultReadyAt(%1,%2)").arg(beginIndex).arg(endIndex));
  88. }
  89. //-----------------------------------------------------------------------------
  90. void ctkCmdLineModuleSignalTester::progressRangeChanged(int minimum, int maximum)
  91. {
  92. Events.push_back(QString("module.progressRangeChanged(%1,%2)").arg(minimum).arg(maximum));
  93. }
  94. //-----------------------------------------------------------------------------
  95. void ctkCmdLineModuleSignalTester::progressValueChanged(int progressValue)
  96. {
  97. Events.push_back(QString("module.progressValueChanged(%1)").arg(progressValue));
  98. }
  99. //-----------------------------------------------------------------------------
  100. void ctkCmdLineModuleSignalTester::progressTextChanged(const QString &progressText)
  101. {
  102. Events.push_back(QString("module.progressTextChanged(%1)").arg(progressText));
  103. }
  104. //-----------------------------------------------------------------------------
  105. void ctkCmdLineModuleSignalTester::outputDataReady()
  106. {
  107. Events.push_back("module.outputReady");
  108. }
  109. //-----------------------------------------------------------------------------
  110. void ctkCmdLineModuleSignalTester::errorDataReady()
  111. {
  112. Events.push_back("module.errorReady");
  113. }
  114. //-----------------------------------------------------------------------------
  115. bool ctkCmdLineModuleSignalTester::checkSignals(const QList<QString>& expectedSignals)
  116. {
  117. if (Events.size() != expectedSignals.size())
  118. {
  119. dumpSignals(expectedSignals);
  120. return false;
  121. }
  122. for (int i=0; i < expectedSignals.size(); ++i)
  123. {
  124. if (expectedSignals[i] != Events[i])
  125. {
  126. dumpSignals(expectedSignals);
  127. return false;
  128. }
  129. }
  130. return true;
  131. }
  132. //-----------------------------------------------------------------------------
  133. void ctkCmdLineModuleSignalTester::dumpSignals(const QList<QString>& expectedSignals)
  134. {
  135. int max = Events.size() > expectedSignals.size() ? Events.size() : expectedSignals.size();
  136. qDebug() << "Expected signal -- Actual signal";
  137. for (int i = 0; i < max; ++i)
  138. {
  139. QString sig = i < Events.size() ? Events[i] : QString();
  140. if (i < expectedSignals.size())
  141. {
  142. qDebug() << " " << expectedSignals[i] << "--" << sig;
  143. }
  144. else
  145. {
  146. qDebug() << " " << "- NONE - " << "--" << sig;
  147. }
  148. }
  149. }
  150. //-----------------------------------------------------------------------------
  151. QList<ctkCmdLineModuleResult> ctkCmdLineModuleSignalTester::results() const
  152. {
  153. return Results;
  154. }