ctkWorkflowWidgetTest1.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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.commontk.org/LICENSE
  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 <QTimer>
  17. #include <QPushButton>
  18. #include <QLabel>
  19. #include <QLineEdit>
  20. #include <QList>
  21. #include <QIcon>
  22. #include <QStyle>
  23. #include <QDebug>
  24. // CTK includes
  25. #include "ctkWorkflow.h"
  26. #include "ctkWorkflowWidget.h"
  27. #include "ctkWorkflowStackedWidget.h"
  28. #include "ctkWorkflowTabWidget.h"
  29. #include "ctkWorkflowGroupBox.h"
  30. #include "ctkWorkflowButtonBoxWidget.h"
  31. #include "ctkExampleDerivedWorkflowWidgetStep.h"
  32. // STD includes
  33. #include <cstdlib>
  34. #include <iostream>
  35. //-----------------------------------------------------------------------------
  36. bool buttonClickTest(QApplication& app, int defaultTime, ctkWorkflowAbstractWidgetStep* currentStep, QWidget* shownStepArea, QLineEdit* shownLineEdit, QLabel* shownLabel, QWidget* hiddenStepArea, QLineEdit* hiddenLineEdit, QLabel* hiddenLabel, ctkWorkflow* workflow, ctkWorkflowWidget* workflowWidget, QPushButton* backButton, QPushButton* nextButton, QPushButton* finishButton1=0, QPushButton* finishButton2=0)
  37. {
  38. QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  39. app.exec();
  40. // // ensure we are in the correct step
  41. if (workflow->currentStep() != currentStep)
  42. {
  43. std::cerr << "In incorrect step" << std::endl;
  44. return false;
  45. }
  46. // ensure that the widgets of the current step are visible
  47. if ((currentStep && (!shownStepArea || !shownStepArea->isVisible()))
  48. || (shownLabel && !shownLabel->isVisible())
  49. || (shownLineEdit && !shownLineEdit->isVisible())
  50. || !backButton->isVisible()
  51. || !nextButton->isVisible()
  52. || (finishButton1 && !finishButton1->isVisible())
  53. || (finishButton2 && !finishButton2->isVisible()))
  54. {
  55. std::cerr << "Incorrect widget visibility - the current step's widgets are invisible" << std::endl;
  56. return false;
  57. }
  58. // ensure that buttons are appropriately enabled
  59. // TODO finish buttons
  60. if ((workflow->canGoBackward() != backButton->isEnabled()) || (workflow->canGoForward() != nextButton->isEnabled()) || (shownLineEdit && !shownLineEdit->isEnabled()))
  61. {
  62. std::cerr << "Incorrect widget visibility - the buttons are incorrectly enabled" << std::endl;
  63. return false;
  64. }
  65. // ensure that the currentStep step's name and description are shown in
  66. // the widget
  67. ctkWorkflowGroupBox* groupBox;
  68. if (ctkWorkflowAbstractPagedWidget* pagedWidget = qobject_cast<ctkWorkflowAbstractPagedWidget*>(workflowWidget))
  69. {
  70. groupBox = pagedWidget->workflowGroupBox(currentStep);
  71. }
  72. else
  73. {
  74. groupBox = workflowWidget->workflowGroupBox();
  75. }
  76. Q_ASSERT(groupBox);
  77. if (currentStep->name() != groupBox->title() || currentStep->description() != groupBox->subTitle())
  78. {
  79. std::cerr << "Incorrect widget title/subtitle" << std::endl;
  80. return false;
  81. }
  82. // ensure that the finish button has an icon
  83. if ((finishButton1 && finishButton1->icon().isNull()) || (finishButton2 && finishButton2->icon().isNull()))
  84. {
  85. std::cerr << "Incorrect finish icon visibility" << std::endl;
  86. return false;
  87. }
  88. // ensure that widgets of the other step are either invisible, or
  89. // visible but disabled
  90. if (hiddenStepArea)
  91. {
  92. if (hiddenStepArea->isVisible() && groupBox->hideWidgetsOfNonCurrentSteps())
  93. {
  94. std::cerr << "Incorrect widget visibility - the other step's stepArea is showing" << std::endl;
  95. return false;
  96. }
  97. else if (hiddenStepArea->isVisible() && hiddenStepArea->isEnabled())
  98. {
  99. std::cerr << "Incorrect widget visibility - the other step's stepArea is enabled" << std::endl;
  100. return false;
  101. }
  102. }
  103. if (hiddenLabel)
  104. {
  105. if (hiddenLabel->isVisible() && groupBox->hideWidgetsOfNonCurrentSteps())
  106. {
  107. std::cerr << "Incorrect widget visibility - the other step's label is showing" << std::endl;
  108. return false;
  109. }
  110. }
  111. if (hiddenLineEdit)
  112. {
  113. if (hiddenLineEdit->isVisible() && groupBox->hideWidgetsOfNonCurrentSteps())
  114. {
  115. std::cerr << "Incorrect widget visibility - the other step's lineEdit is showing" << std::endl;
  116. return false;
  117. }
  118. else if (hiddenLineEdit->isVisible() && hiddenLineEdit->isEnabled())
  119. {
  120. std::cerr << "Incorrect widget visibility - the other step's lineEdit is enabled" << std::endl;
  121. return false;
  122. }
  123. }
  124. return true;
  125. }
  126. //-----------------------------------------------------------------------------
  127. struct derivedTestData
  128. {
  129. QPushButton* buttonToClick;
  130. ctkExampleDerivedWorkflowWidgetStep* currentStep;
  131. ctkExampleDerivedWorkflowWidgetStep* hiddenStep;
  132. ctkExampleDerivedWorkflowWidgetStep* stepToChangeLineEdit;
  133. QString lineEditText;
  134. derivedTestData(QPushButton* newButtonToClick, ctkExampleDerivedWorkflowWidgetStep* newCurrentStep, ctkExampleDerivedWorkflowWidgetStep* newHiddenStep, ctkExampleDerivedWorkflowWidgetStep* newStepToChangeLineEdit=0, QString newLineEditText="")
  135. {
  136. this->buttonToClick = newButtonToClick;
  137. this->currentStep = newCurrentStep;
  138. this->hiddenStep = newHiddenStep;
  139. this->stepToChangeLineEdit = newStepToChangeLineEdit;
  140. this->lineEditText = newLineEditText;
  141. }
  142. bool runTest(QApplication& app, int defaultTime, ctkWorkflow* workflow, ctkWorkflowWidget* workflowWidget, QPushButton* backButton, QPushButton* nextButton, QPushButton* finishButton1=0, QPushButton* finishButton2=0)
  143. {
  144. if (this->stepToChangeLineEdit)
  145. {
  146. this->stepToChangeLineEdit->lineEdit()->setText(lineEditText);
  147. }
  148. if (this->buttonToClick)
  149. {
  150. this->buttonToClick->click();
  151. }
  152. if (this->currentStep)
  153. {
  154. return buttonClickTest(app, defaultTime, this->currentStep, this->currentStep->stepArea(), this->currentStep->lineEdit(), this->currentStep->label(), this->hiddenStep->stepArea(), this->hiddenStep->lineEdit(), this->hiddenStep->label(), workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2);
  155. }
  156. else
  157. {
  158. return buttonClickTest(app, defaultTime, this->currentStep, 0, 0, 0, this->hiddenStep->stepArea(), this->hiddenStep->lineEdit(), this->hiddenStep->label(), workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2);
  159. }
  160. }
  161. };
  162. //-----------------------------------------------------------------------------
  163. // simulates valid and invalid user interaction for a workflow with
  164. // two steps
  165. int userInteractionSimulator1(QApplication& app, ctkExampleDerivedWorkflowWidgetStep* step1, ctkExampleDerivedWorkflowWidgetStep* step2, ctkWorkflow* workflow, ctkWorkflowWidget* workflowWidget, int defaultTime)
  166. {
  167. QPushButton* backButton = workflowWidget->buttonBoxWidget()->backButton();
  168. QPushButton* nextButton = workflowWidget->buttonBoxWidget()->nextButton();
  169. Q_ASSERT(backButton);
  170. Q_ASSERT(nextButton);
  171. #ifndef QT_NO_DEBUG
  172. QPushButton* finishButton = workflowWidget->buttonBoxWidget()->goToButtons().first();
  173. Q_ASSERT(finishButton);
  174. #endif
  175. QList<derivedTestData*> tests;
  176. // we should be in the first step at the start of the workflow
  177. tests << new derivedTestData(0, step1, step2);
  178. // tests with good input (lineEdit value = 100, which passes the
  179. // condition that it be >= 10)
  180. // CurrentStep ButtonPress ExpectedStep Shouldn'tDoAnything
  181. // step1 next step2
  182. // step2 back step1
  183. // step1 next step2
  184. // step2 back step1
  185. tests << new derivedTestData(nextButton, step2, step1)
  186. << new derivedTestData(backButton, step1, step2)
  187. << new derivedTestData(nextButton, step2, step1)
  188. << new derivedTestData(backButton, step1, step2);
  189. // tests with both good and bad input (lineEdit value may be
  190. // invalid)
  191. // CurrentStep ButtonPress Invalid input ExpectedStep
  192. // step1 next * step1
  193. // step1 next step2
  194. // step2 back * step1
  195. // step1 next * (empty) step1
  196. // step1 next step2
  197. tests << new derivedTestData(nextButton, step1, step2, step1, "1")
  198. << new derivedTestData(nextButton, step2, step1, step1, "100")
  199. << new derivedTestData(backButton, step1, step2)
  200. << new derivedTestData(nextButton, step1, step2, step1, "")
  201. << new derivedTestData(nextButton, step2, step1, step1, "100");
  202. foreach (derivedTestData* test, tests)
  203. {
  204. if (!test->runTest(app, defaultTime, workflow, workflowWidget, backButton, nextButton))
  205. {
  206. return EXIT_FAILURE;
  207. }
  208. }
  209. // TODO
  210. // // after adding the steps, then the widget's client area should have
  211. // // them as a child
  212. // if (!workflowWidget->clientArea()->isAncestorOf(testStep1->stepArea()))
  213. // {
  214. // std::cerr << "testStep1 was incorrectly added to the workflowWidget" << std::endl;
  215. // return EXIT_FAILURE;
  216. // }
  217. // if (!workflowWidget->clientArea()->isAncestorOf(testStep2->stepArea()))
  218. // {
  219. // std::cerr << "testStep2 was incorrectly added to the workflowWidget" << std::endl;
  220. // return EXIT_FAILURE;
  221. // }
  222. return EXIT_SUCCESS;
  223. }
  224. //-----------------------------------------------------------------------------
  225. // simulates valid and invalid user interaction for a workflow with
  226. // three steps
  227. int userInteractionSimulator2(QApplication& app, ctkExampleDerivedWorkflowWidgetStep* step1, ctkExampleDerivedWorkflowWidgetStep* step2, ctkExampleDerivedWorkflowWidgetStep* step3, ctkWorkflow* workflow, ctkWorkflowWidget* workflowWidget, int defaultTime)
  228. {
  229. // ensure we can get the pages/layouts we may want
  230. if (ctkWorkflowAbstractPagedWidget* pagedWidget = qobject_cast<ctkWorkflowAbstractPagedWidget*>(workflowWidget))
  231. {
  232. if (!pagedWidget->workflowGroupBox(step1))
  233. {
  234. std::cerr << "could not access widget for page 1" << std::endl;
  235. return EXIT_FAILURE;
  236. }
  237. if (!pagedWidget->workflowGroupBox(step1)->clientAreaLayout())
  238. {
  239. std::cerr << "could not access client area layout for page 1" << std::endl;
  240. return EXIT_FAILURE;
  241. }
  242. }
  243. else
  244. {
  245. if (!workflowWidget->workflowGroupBox()->clientAreaLayout())
  246. {
  247. std::cerr << "could not access client area layout" << std::endl;
  248. return EXIT_FAILURE;
  249. }
  250. }
  251. QPushButton* backButton = workflowWidget->buttonBoxWidget()->backButton();
  252. QPushButton* nextButton = workflowWidget->buttonBoxWidget()->nextButton();
  253. QPushButton* finishButton = workflowWidget->buttonBoxWidget()->goToButtons().first();
  254. Q_ASSERT(backButton);
  255. Q_ASSERT(nextButton);
  256. Q_ASSERT(finishButton);
  257. QList<derivedTestData*> tests;
  258. // we should be in the first step at the start of the workflow
  259. tests << new derivedTestData(0, step1, step2);
  260. // tests with good input (lineEdit value = 100, which passes the
  261. // condition that it be >= 10)
  262. // CurrentStep ButtonPress ExpectedStep Shouldn'tDoAnything
  263. // step1 next step2
  264. // step2 next step3
  265. // step3 back step2
  266. // step2 back step1
  267. // step1 next step2
  268. // step2 next step3
  269. // step3 back step2
  270. tests << new derivedTestData(nextButton, step2, step1)
  271. << new derivedTestData(nextButton, step3, step2, step2, "100")
  272. << new derivedTestData(backButton, step2, step3)
  273. << new derivedTestData(backButton, step1, step2)
  274. << new derivedTestData(nextButton, step2, step1)
  275. << new derivedTestData(nextButton, step3, step2)
  276. << new derivedTestData(backButton, step2, step3);
  277. // tests with both good and bad input (lineEdit value may be
  278. // invalid)
  279. // CurrentStep ButtonPress Invalid input ExpectedStep
  280. // step2 next * step2
  281. // step2 next step3
  282. // step3 back * step2
  283. // step2 next * (empty) step2
  284. // step2 next step3
  285. tests << new derivedTestData(nextButton, step2, step3, step2, "1")
  286. << new derivedTestData(nextButton, step3, step2, step2, "100")
  287. << new derivedTestData(backButton, step2, step3)
  288. << new derivedTestData(nextButton, step2, step3, step2, "")
  289. << new derivedTestData(nextButton, step3, step2, step2, "100");
  290. // first go back to the beginning
  291. tests << new derivedTestData(backButton, step2, step3, step2, "100")
  292. << new derivedTestData(backButton, step1, step2);
  293. // tests going to the finish step
  294. // CurrentStep ButtonPress Invalid input ExpectedStep
  295. // step1 finish step1
  296. // step1 finish step1
  297. // step1 next step2
  298. // step2 finish step2
  299. // step2 next step3
  300. // step3 finish step3
  301. // step3 back step2
  302. // step2 finish step2
  303. // step2 back step1
  304. // step1 finish step1
  305. tests << new derivedTestData(finishButton, step1, step3)
  306. << new derivedTestData(finishButton, step1, step3)
  307. << new derivedTestData(nextButton, step2, step1)
  308. << new derivedTestData(finishButton, step2, step3)
  309. << new derivedTestData(nextButton, step3, step2)
  310. << new derivedTestData(finishButton, step3, step2)
  311. << new derivedTestData(backButton, step2, step3)
  312. << new derivedTestData(finishButton, step2, step3)
  313. << new derivedTestData(backButton, step1, step2)
  314. << new derivedTestData(finishButton, step1, step3);
  315. // tests going to the finish step with invalid input
  316. // CurrentStep ButtonPress Invalid input ExpectedStep
  317. // step1 finish * (step2) step2
  318. // step2 next step3
  319. // step3 back step2
  320. // step2 finish * (step2) step2
  321. // step2 back step1
  322. // step1 finish * (step3) step1
  323. tests << new derivedTestData(finishButton, step2, step1, step2, "0")
  324. << new derivedTestData(nextButton, step3, step2, step2, "100")
  325. << new derivedTestData(backButton, step2, step3)
  326. << new derivedTestData(finishButton, step2, step3, step2, "0")
  327. << new derivedTestData(backButton, step1, step2, step2, "100") // reset text for step2
  328. << new derivedTestData(finishButton, step1, step3, step3, "0");
  329. foreach (derivedTestData* test, tests)
  330. {
  331. if (!test->runTest(app, defaultTime, workflow, workflowWidget, backButton, nextButton, finishButton))
  332. {
  333. return EXIT_FAILURE;
  334. }
  335. }
  336. // TODO
  337. // // after adding the steps, then the widget's client area should have
  338. // // them as a child
  339. // if (!workflowWidget->workflowGroupBox()->isAncestorOf(step3->stepArea()))
  340. // {
  341. // std::cerr << "step3 was incorrectly added to the workflowWidget" << std::endl;
  342. // return EXIT_FAILURE;
  343. // }
  344. return EXIT_SUCCESS;
  345. }
  346. // //-----------------------------------------------------------------------------
  347. // // simulates valid and invalid user interaction for a workflow with
  348. // // three steps and two finish steps
  349. // int userInteractionSimulator3(QApplication& app, ctkExampleDerivedWorkflowWidgetStep* step1, ctkExampleDerivedWorkflowWidgetStep* step2, ctkExampleDerivedWorkflowWidgetStep* step3, ctkWorkflow* workflow, ctkWorkflowWidget* workflowWidget, int defaultTime)
  350. // {
  351. // QPushButton* backButton = workflowWidget->buttonBoxWidget()->backButton();
  352. // QPushButton* nextButton = workflowWidget->buttonBoxWidget()->nextButton();
  353. // QPushButton* finishButton1 = workflowWidget->buttonBoxWidget()->goToButtons().first();
  354. // QPushButton* finishButton2 = workflowWidget->buttonBoxWidget()->goToButtons().at(1);
  355. // Q_ASSERT(backButton);
  356. // Q_ASSERT(nextButton);
  357. // Q_ASSERT(finishButton1);
  358. // Q_ASSERT(finishButton2);
  359. // // if (!nextButton || !finishButton || !finishButton || nextButton->text() != "Next" || finishButton->text() != "finish" || finishButton->text() != "finish")
  360. // // {
  361. // // std::cerr << "incorrect button assignment for step1" << std::endl;
  362. // // return EXIT_FAILURE;
  363. // // }
  364. // // we should be in the first step
  365. // if (!buttonClickTest(app, defaultTime, step1, step2, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  366. // // tests with good input, so that we can get all of the buttons
  367. // // (lineEdit value = 100, which passes the condition that it be >= 10)
  368. // // CurrentStep ButtonPress ExpectedStep Shouldn'tDoAnything
  369. // // step1 next step2
  370. // // step2 next step3
  371. // // normal forwards/backwards transitions
  372. // nextButton->click();
  373. // QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  374. // app.exec();
  375. // // get the back/next buttons for the second step
  376. // // buttons = step2->stepArea()->findChildren<QPushButton*>();
  377. // // if (buttons.length() != 4)
  378. // // {
  379. // // std::cerr << "incorrect number of buttons for step2" << std::endl;
  380. // // std::cerr << "number of buttons = " << buttons.length() << ", expecting 4" << std::endl;
  381. // // return EXIT_FAILURE;
  382. // // }
  383. // // backButton = buttons.at(BACK_BUTTON_INDEX);
  384. // // nextButton = buttons.at(NEXT_BUTTON_INDEX);
  385. // // finishButton = buttons.at(FINISH_BUTTON_INDEX_1);
  386. // // finishButton = buttons.at(FINISH_BUTTON_INDEX_2);
  387. // // backButton = workflowWidget->buttonBoxWidget()->backButton();
  388. // // nextButton = workflowWidget->buttonBoxWidget()->nextButton();
  389. // // finishButton = workflowWidget->buttonBoxWidget()->goToButtons().first();
  390. // // finishButton = workflowWidget->buttonBoxWidget()->goToButtons().at(1);
  391. // // if (!backButton || !nextButton || !finishButton || !finishButton || backButton->text() != "Back" || nextButton->text() != "Next" || finishButton->text() != "finish" || finishButton->text() != "finish")
  392. // // {
  393. // // std::cerr << "incorrect button assignment for step2" << std::endl;
  394. // // return EXIT_FAILURE;
  395. // // }
  396. // if (!buttonClickTest(app, defaultTime, step2, step1, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  397. // nextButton->click();
  398. // QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  399. // app.exec();
  400. // // get the back/next buttons for the third step
  401. // // buttons = step3->stepArea()->findChildren<QPushButton*>();
  402. // // if (buttons.length() != 3)
  403. // // {
  404. // // std::cerr << "incorrect number of buttons for step3" << std::endl;
  405. // // std::cerr << "number of buttons = " << buttons.length() << ", expecting 3" << std::endl;
  406. // // return EXIT_FAILURE;
  407. // // }
  408. // // backButton = buttons.at(BACK_BUTTON_INDEX);
  409. // // finishButton1 = buttons.at(FINISH_BUTTON_INDEX_1);
  410. // // finishButton2 = buttons.at(FINISH_BUTTON_INDEX_2);
  411. // // backButton = workflowWidget->buttonBoxWidget()->backButton();
  412. // // finishButton1 = workflowWidget->buttonBoxWidget()->goToButtons().first();
  413. // // finishButton2 = workflowWidget->buttonBoxWidget()->goToButtons().at(1);
  414. // // if (!backButton || !finishButton1 || !finishButton2 || backButton->text() != "Back" || finishButton1->text() != "finish" || finishButton2->text() != "finish")
  415. // // {
  416. // // std::cerr << "incorrect button assignment for step3" << std::endl;
  417. // // return EXIT_FAILURE;
  418. // // }
  419. // if (!buttonClickTest(app, defaultTime, step3, step2, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  420. // // tests going to the finish step
  421. // // CurrentStep ButtonPress Invalid input ExpectedStep
  422. // // step3 back step2
  423. // // step2 back step1
  424. // // step1 finish1 step1
  425. // // step1 next step2
  426. // // step2 finish1 step2
  427. // // step2 finish2 step2
  428. // // step2 back step1
  429. // // step1 finish2 step1
  430. // // step1 next step2
  431. // backButton->click();
  432. // if (!buttonClickTest(app, defaultTime, step2, step3, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  433. // backButton->click();
  434. // if (!buttonClickTest(app, defaultTime, step1, step2, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  435. // finishButton1->click();
  436. // if (!buttonClickTest(app, defaultTime, step1, step3, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  437. // nextButton->click();
  438. // if (!buttonClickTest(app, defaultTime, step2, step1, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  439. // finishButton1->click();
  440. // if (!buttonClickTest(app, defaultTime, step2, step3, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  441. // finishButton2->click();
  442. // if (!buttonClickTest(app, defaultTime, step2, step3, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  443. // backButton->click();
  444. // if (!buttonClickTest(app, defaultTime, step1, step2, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  445. // finishButton2->click();
  446. // if (!buttonClickTest(app, defaultTime, step1, step2, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  447. // nextButton->click();
  448. // if (!buttonClickTest(app, defaultTime, step2, step1, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  449. // return EXIT_SUCCESS;
  450. // }
  451. //-----------------------------------------------------------------------------
  452. int runWorkflowWidgetTest(ctkWorkflowWidget* workflowWidget, QApplication& app, bool hideWidgets, int defaultTime)
  453. {
  454. ctkWorkflow* workflow = new ctkWorkflow;
  455. workflowWidget->setWorkflow(workflow);
  456. ctkWorkflowGroupBox* groupBox = workflowWidget->workflowGroupBox();
  457. groupBox->setPreText("I am some pre-text");
  458. groupBox->setPostText("I am some post-text");
  459. groupBox->setHideWidgetsOfNonCurrentSteps(hideWidgets);
  460. // create and add the first workflow step (depends on workflowWidget
  461. // type)
  462. ctkExampleDerivedWorkflowWidgetStep* step1 = new ctkExampleDerivedWorkflowWidgetStep(workflow, "Step 1");
  463. step1->setName("Step 1");
  464. step1->setDescription("I am in step 1");
  465. if (ctkWorkflowTabWidget* tabWidget = qobject_cast<ctkWorkflowTabWidget*>(workflowWidget))
  466. {
  467. tabWidget->associateStepWithLabel(step1, "tab1");
  468. }
  469. // step1 is the initial step
  470. workflow->setInitialStep(step1);
  471. // create and add the second workflow step (depends on
  472. // workflowWidget type)
  473. ctkExampleDerivedWorkflowWidgetStep* step2 = new ctkExampleDerivedWorkflowWidgetStep(workflow, "Step 2");
  474. step2->setName("Step 2");
  475. step2->setDescription("I am in step 2");
  476. if (ctkWorkflowTabWidget* tabWidget = qobject_cast<ctkWorkflowTabWidget*>(workflowWidget))
  477. {
  478. tabWidget->associateStepWithLabel(step2, "tab2");
  479. }
  480. // add the steps to the workflow
  481. workflow->addTransition(step1, step2);
  482. // start the workflow
  483. workflow->start();
  484. workflowWidget->show();
  485. // first user interaction test
  486. if (userInteractionSimulator1(app, step1, step2, workflow, workflowWidget, defaultTime) == EXIT_FAILURE)
  487. {
  488. return EXIT_FAILURE;
  489. }
  490. // stop the workflow
  491. workflow->stop();
  492. QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  493. app.exec();
  494. // create and add a third workflow step (depends on workflowWidget
  495. // type)
  496. ctkExampleDerivedWorkflowWidgetStep* step3 = new ctkExampleDerivedWorkflowWidgetStep(workflow, "Step 3");
  497. step3->setName("Step 3");
  498. step3->setDescription("I am in step 3");
  499. if (ctkWorkflowStackedWidget* stackedWidget = qobject_cast<ctkWorkflowStackedWidget*>(workflowWidget))
  500. {
  501. stackedWidget->associateStepWithPage(step3, 1);
  502. }
  503. else if (ctkWorkflowTabWidget* tabWidget = qobject_cast<ctkWorkflowTabWidget*>(workflowWidget))
  504. {
  505. tabWidget->associateStepWithPage(step3, 1, "tab2");
  506. }
  507. // icon test - add an icon to step3, should show up as a icon on the finish button
  508. step3->setIcon(step3->stepArea()->style()->standardIcon(QStyle::SP_ArrowUp));
  509. workflow->addTransition(step2, step3);
  510. // restart the workflow
  511. workflow->start();
  512. // second user interaction test
  513. if (userInteractionSimulator2(app, step1, step2, step3, workflow, workflowWidget, defaultTime) == EXIT_FAILURE)
  514. {
  515. return EXIT_FAILURE;
  516. }
  517. // stop the workflow
  518. workflow->stop();
  519. QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  520. app.exec();
  521. // TODO put back once we can have more than one finish step
  522. // make the second workflow step a finish step as well
  523. // finishSteps.push_back(step2);
  524. // step1->setFinishStepsToHaveButtonsInStepArea(finishSteps);
  525. // step2->setFinishStepsToHaveButtonsInStepArea(finishSteps);
  526. // step3->setFinishStepsToHaveButtonsInStepArea(finishSteps);
  527. // // workflow->addFinishStep(step2);
  528. // // restart the workflow
  529. // workflow->start();
  530. // QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  531. // app.exec();
  532. // // third user interfaction test
  533. // if (userInteractionSimulator3(app, step1, step2, step3, workflow, workflowWidget, defaultTime) == EXIT_FAILURE)
  534. // {
  535. // return EXIT_FAILURE;
  536. // }
  537. // // stop the workflow
  538. // workflow->stop();
  539. // QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  540. // app.exec();
  541. // handles deletion of the workflowWidget, workflow, steps, states
  542. // and transitions
  543. delete workflowWidget;
  544. return EXIT_SUCCESS;
  545. }
  546. //-----------------------------------------------------------------------------
  547. int ctkWorkflowWidgetTest1(int argc, char * argv [] )
  548. {
  549. QApplication app(argc, argv);
  550. int defaultTime = 100;
  551. bool hideWidgets = false;
  552. if (runWorkflowWidgetTest(new ctkWorkflowWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  553. {
  554. return EXIT_FAILURE;
  555. }
  556. if (runWorkflowWidgetTest(new ctkWorkflowStackedWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  557. {
  558. return EXIT_FAILURE;
  559. }
  560. if (runWorkflowWidgetTest(new ctkWorkflowTabWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  561. {
  562. return EXIT_FAILURE;
  563. }
  564. hideWidgets = true;
  565. if (runWorkflowWidgetTest(new ctkWorkflowWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  566. {
  567. return EXIT_FAILURE;
  568. }
  569. if (runWorkflowWidgetTest(new ctkWorkflowStackedWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  570. {
  571. return EXIT_FAILURE;
  572. }
  573. if (runWorkflowWidgetTest(new ctkWorkflowTabWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  574. {
  575. return EXIT_FAILURE;
  576. }
  577. return EXIT_SUCCESS;
  578. }