ctkWorkflowWidgetTest1.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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. QPushButton* finishButton = workflowWidget->buttonBoxWidget()->goToButtons().first();
  170. Q_ASSERT(backButton);
  171. Q_ASSERT(nextButton);
  172. Q_ASSERT(finishButton);
  173. QList<derivedTestData*> tests;
  174. // we should be in the first step at the start of the workflow
  175. tests << new derivedTestData(0, step1, step2);
  176. // tests with good input (lineEdit value = 100, which passes the
  177. // condition that it be >= 10)
  178. // CurrentStep ButtonPress ExpectedStep Shouldn'tDoAnything
  179. // step1 next step2
  180. // step2 back step1
  181. // step1 next step2
  182. // step2 back step1
  183. tests << new derivedTestData(nextButton, step2, step1)
  184. << new derivedTestData(backButton, step1, step2)
  185. << new derivedTestData(nextButton, step2, step1)
  186. << new derivedTestData(backButton, step1, step2);
  187. // tests with both good and bad input (lineEdit value may be
  188. // invalid)
  189. // CurrentStep ButtonPress Invalid input ExpectedStep
  190. // step1 next * step1
  191. // step1 next step2
  192. // step2 back * step1
  193. // step1 next * (empty) step1
  194. // step1 next step2
  195. tests << new derivedTestData(nextButton, step1, step2, step1, "1")
  196. << new derivedTestData(nextButton, step2, step1, step1, "100")
  197. << new derivedTestData(backButton, step1, step2)
  198. << new derivedTestData(nextButton, step1, step2, step1, "")
  199. << new derivedTestData(nextButton, step2, step1, step1, "100");
  200. foreach (derivedTestData* test, tests)
  201. {
  202. if (!test->runTest(app, defaultTime, workflow, workflowWidget, backButton, nextButton))
  203. {
  204. return EXIT_FAILURE;
  205. }
  206. }
  207. // TODO
  208. // // after adding the steps, then the widget's client area should have
  209. // // them as a child
  210. // if (!workflowWidget->clientArea()->isAncestorOf(testStep1->stepArea()))
  211. // {
  212. // std::cerr << "testStep1 was incorrectly added to the workflowWidget" << std::endl;
  213. // return EXIT_FAILURE;
  214. // }
  215. // if (!workflowWidget->clientArea()->isAncestorOf(testStep2->stepArea()))
  216. // {
  217. // std::cerr << "testStep2 was incorrectly added to the workflowWidget" << std::endl;
  218. // return EXIT_FAILURE;
  219. // }
  220. return EXIT_SUCCESS;
  221. }
  222. //-----------------------------------------------------------------------------
  223. // simulates valid and invalid user interaction for a workflow with
  224. // three steps
  225. int userInteractionSimulator2(QApplication& app, ctkExampleDerivedWorkflowWidgetStep* step1, ctkExampleDerivedWorkflowWidgetStep* step2, ctkExampleDerivedWorkflowWidgetStep* step3, ctkWorkflow* workflow, ctkWorkflowWidget* workflowWidget, int defaultTime)
  226. {
  227. // ensure we can get the pages/layouts we may want
  228. if (ctkWorkflowAbstractPagedWidget* pagedWidget = qobject_cast<ctkWorkflowAbstractPagedWidget*>(workflowWidget))
  229. {
  230. if (!pagedWidget->workflowGroupBox(step1))
  231. {
  232. std::cerr << "could not access widget for page 1" << std::endl;
  233. return EXIT_FAILURE;
  234. }
  235. if (!pagedWidget->workflowGroupBox(step1)->clientAreaLayout())
  236. {
  237. std::cerr << "could not access client area layout for page 1" << std::endl;
  238. return EXIT_FAILURE;
  239. }
  240. }
  241. else
  242. {
  243. if (!workflowWidget->workflowGroupBox()->clientAreaLayout())
  244. {
  245. std::cerr << "could not access client area layout" << std::endl;
  246. return EXIT_FAILURE;
  247. }
  248. }
  249. QPushButton* backButton = workflowWidget->buttonBoxWidget()->backButton();
  250. QPushButton* nextButton = workflowWidget->buttonBoxWidget()->nextButton();
  251. QPushButton* finishButton = workflowWidget->buttonBoxWidget()->goToButtons().first();
  252. Q_ASSERT(backButton);
  253. Q_ASSERT(nextButton);
  254. Q_ASSERT(finishButton);
  255. QList<derivedTestData*> tests;
  256. // we should be in the first step at the start of the workflow
  257. tests << new derivedTestData(0, step1, step2);
  258. // tests with good input (lineEdit value = 100, which passes the
  259. // condition that it be >= 10)
  260. // CurrentStep ButtonPress ExpectedStep Shouldn'tDoAnything
  261. // step1 next step2
  262. // step2 next step3
  263. // step3 back step2
  264. // step2 back step1
  265. // step1 next step2
  266. // step2 next step3
  267. // step3 back step2
  268. tests << new derivedTestData(nextButton, step2, step1)
  269. << new derivedTestData(nextButton, step3, step2, step2, "100")
  270. << new derivedTestData(backButton, step2, step3)
  271. << new derivedTestData(backButton, step1, step2)
  272. << new derivedTestData(nextButton, step2, step1)
  273. << new derivedTestData(nextButton, step3, step2)
  274. << new derivedTestData(backButton, step2, step3);
  275. // tests with both good and bad input (lineEdit value may be
  276. // invalid)
  277. // CurrentStep ButtonPress Invalid input ExpectedStep
  278. // step2 next * step2
  279. // step2 next step3
  280. // step3 back * step2
  281. // step2 next * (empty) step2
  282. // step2 next step3
  283. tests << new derivedTestData(nextButton, step2, step3, step2, "1")
  284. << new derivedTestData(nextButton, step3, step2, step2, "100")
  285. << new derivedTestData(backButton, step2, step3)
  286. << new derivedTestData(nextButton, step2, step3, step2, "")
  287. << new derivedTestData(nextButton, step3, step2, step2, "100");
  288. // first go back to the beginning
  289. tests << new derivedTestData(backButton, step2, step3, step2, "100")
  290. << new derivedTestData(backButton, step1, step2);
  291. // tests going to the finish step
  292. // CurrentStep ButtonPress Invalid input ExpectedStep
  293. // step1 finish step1
  294. // step1 finish step1
  295. // step1 next step2
  296. // step2 finish step2
  297. // step2 next step3
  298. // step3 finish step3
  299. // step3 back step2
  300. // step2 finish step2
  301. // step2 back step1
  302. // step1 finish step1
  303. tests << new derivedTestData(finishButton, step1, step3)
  304. << new derivedTestData(finishButton, step1, step3)
  305. << new derivedTestData(nextButton, step2, step1)
  306. << new derivedTestData(finishButton, step2, step3)
  307. << new derivedTestData(nextButton, step3, step2)
  308. << new derivedTestData(finishButton, step3, step2)
  309. << new derivedTestData(backButton, step2, step3)
  310. << new derivedTestData(finishButton, step2, step3)
  311. << new derivedTestData(backButton, step1, step2)
  312. << new derivedTestData(finishButton, step1, step3);
  313. // tests going to the finish step with invalid input
  314. // CurrentStep ButtonPress Invalid input ExpectedStep
  315. // step1 finish * (step2) step2
  316. // step2 next step3
  317. // step3 back step2
  318. // step2 finish * (step2) step2
  319. // step2 back step1
  320. // step1 finish * (step3) step1
  321. tests << new derivedTestData(finishButton, step2, step1, step2, "0")
  322. << new derivedTestData(nextButton, step3, step2, step2, "100")
  323. << new derivedTestData(backButton, step2, step3)
  324. << new derivedTestData(finishButton, step2, step3, step2, "0")
  325. << new derivedTestData(backButton, step1, step2, step2, "100") // reset text for step2
  326. << new derivedTestData(finishButton, step1, step3, step3, "0");
  327. foreach (derivedTestData* test, tests)
  328. {
  329. if (!test->runTest(app, defaultTime, workflow, workflowWidget, backButton, nextButton, finishButton))
  330. {
  331. return EXIT_FAILURE;
  332. }
  333. }
  334. // TODO
  335. // // after adding the steps, then the widget's client area should have
  336. // // them as a child
  337. // if (!workflowWidget->workflowGroupBox()->isAncestorOf(step3->stepArea()))
  338. // {
  339. // std::cerr << "step3 was incorrectly added to the workflowWidget" << std::endl;
  340. // return EXIT_FAILURE;
  341. // }
  342. return EXIT_SUCCESS;
  343. }
  344. // //-----------------------------------------------------------------------------
  345. // // simulates valid and invalid user interaction for a workflow with
  346. // // three steps and two finish steps
  347. // int userInteractionSimulator3(QApplication& app, ctkExampleDerivedWorkflowWidgetStep* step1, ctkExampleDerivedWorkflowWidgetStep* step2, ctkExampleDerivedWorkflowWidgetStep* step3, ctkWorkflow* workflow, ctkWorkflowWidget* workflowWidget, int defaultTime)
  348. // {
  349. // QPushButton* backButton = workflowWidget->buttonBoxWidget()->backButton();
  350. // QPushButton* nextButton = workflowWidget->buttonBoxWidget()->nextButton();
  351. // QPushButton* finishButton1 = workflowWidget->buttonBoxWidget()->goToButtons().first();
  352. // QPushButton* finishButton2 = workflowWidget->buttonBoxWidget()->goToButtons().at(1);
  353. // Q_ASSERT(backButton);
  354. // Q_ASSERT(nextButton);
  355. // Q_ASSERT(finishButton1);
  356. // Q_ASSERT(finishButton2);
  357. // // if (!nextButton || !finishButton || !finishButton || nextButton->text() != "Next" || finishButton->text() != "finish" || finishButton->text() != "finish")
  358. // // {
  359. // // std::cerr << "incorrect button assignment for step1" << std::endl;
  360. // // return EXIT_FAILURE;
  361. // // }
  362. // // we should be in the first step
  363. // if (!buttonClickTest(app, defaultTime, step1, step2, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  364. // // tests with good input, so that we can get all of the buttons
  365. // // (lineEdit value = 100, which passes the condition that it be >= 10)
  366. // // CurrentStep ButtonPress ExpectedStep Shouldn'tDoAnything
  367. // // step1 next step2
  368. // // step2 next step3
  369. // // normal forwards/backwards transitions
  370. // nextButton->click();
  371. // QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  372. // app.exec();
  373. // // get the back/next buttons for the second step
  374. // // buttons = step2->stepArea()->findChildren<QPushButton*>();
  375. // // if (buttons.length() != 4)
  376. // // {
  377. // // std::cerr << "incorrect number of buttons for step2" << std::endl;
  378. // // std::cerr << "number of buttons = " << buttons.length() << ", expecting 4" << std::endl;
  379. // // return EXIT_FAILURE;
  380. // // }
  381. // // backButton = buttons.at(BACK_BUTTON_INDEX);
  382. // // nextButton = buttons.at(NEXT_BUTTON_INDEX);
  383. // // finishButton = buttons.at(FINISH_BUTTON_INDEX_1);
  384. // // finishButton = buttons.at(FINISH_BUTTON_INDEX_2);
  385. // // backButton = workflowWidget->buttonBoxWidget()->backButton();
  386. // // nextButton = workflowWidget->buttonBoxWidget()->nextButton();
  387. // // finishButton = workflowWidget->buttonBoxWidget()->goToButtons().first();
  388. // // finishButton = workflowWidget->buttonBoxWidget()->goToButtons().at(1);
  389. // // if (!backButton || !nextButton || !finishButton || !finishButton || backButton->text() != "Back" || nextButton->text() != "Next" || finishButton->text() != "finish" || finishButton->text() != "finish")
  390. // // {
  391. // // std::cerr << "incorrect button assignment for step2" << std::endl;
  392. // // return EXIT_FAILURE;
  393. // // }
  394. // if (!buttonClickTest(app, defaultTime, step2, step1, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  395. // nextButton->click();
  396. // QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  397. // app.exec();
  398. // // get the back/next buttons for the third step
  399. // // buttons = step3->stepArea()->findChildren<QPushButton*>();
  400. // // if (buttons.length() != 3)
  401. // // {
  402. // // std::cerr << "incorrect number of buttons for step3" << std::endl;
  403. // // std::cerr << "number of buttons = " << buttons.length() << ", expecting 3" << std::endl;
  404. // // return EXIT_FAILURE;
  405. // // }
  406. // // backButton = buttons.at(BACK_BUTTON_INDEX);
  407. // // finishButton1 = buttons.at(FINISH_BUTTON_INDEX_1);
  408. // // finishButton2 = buttons.at(FINISH_BUTTON_INDEX_2);
  409. // // backButton = workflowWidget->buttonBoxWidget()->backButton();
  410. // // finishButton1 = workflowWidget->buttonBoxWidget()->goToButtons().first();
  411. // // finishButton2 = workflowWidget->buttonBoxWidget()->goToButtons().at(1);
  412. // // if (!backButton || !finishButton1 || !finishButton2 || backButton->text() != "Back" || finishButton1->text() != "finish" || finishButton2->text() != "finish")
  413. // // {
  414. // // std::cerr << "incorrect button assignment for step3" << std::endl;
  415. // // return EXIT_FAILURE;
  416. // // }
  417. // if (!buttonClickTest(app, defaultTime, step3, step2, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  418. // // tests going to the finish step
  419. // // CurrentStep ButtonPress Invalid input ExpectedStep
  420. // // step3 back step2
  421. // // step2 back step1
  422. // // step1 finish1 step1
  423. // // step1 next step2
  424. // // step2 finish1 step2
  425. // // step2 finish2 step2
  426. // // step2 back step1
  427. // // step1 finish2 step1
  428. // // step1 next step2
  429. // backButton->click();
  430. // if (!buttonClickTest(app, defaultTime, step2, step3, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  431. // backButton->click();
  432. // if (!buttonClickTest(app, defaultTime, step1, step2, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  433. // finishButton1->click();
  434. // if (!buttonClickTest(app, defaultTime, step1, step3, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  435. // nextButton->click();
  436. // if (!buttonClickTest(app, defaultTime, step2, step1, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  437. // finishButton1->click();
  438. // if (!buttonClickTest(app, defaultTime, step2, step3, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  439. // finishButton2->click();
  440. // if (!buttonClickTest(app, defaultTime, step2, step3, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  441. // backButton->click();
  442. // if (!buttonClickTest(app, defaultTime, step1, step2, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  443. // finishButton2->click();
  444. // if (!buttonClickTest(app, defaultTime, step1, step2, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  445. // nextButton->click();
  446. // if (!buttonClickTest(app, defaultTime, step2, step1, workflow, workflowWidget, backButton, nextButton, finishButton1, finishButton2)) {return EXIT_FAILURE;}
  447. // return EXIT_SUCCESS;
  448. // }
  449. //-----------------------------------------------------------------------------
  450. int runWorkflowWidgetTest(ctkWorkflowWidget* workflowWidget, QApplication& app, bool hideWidgets, int defaultTime)
  451. {
  452. ctkWorkflow* workflow = new ctkWorkflow;
  453. workflowWidget->setWorkflow(workflow);
  454. ctkWorkflowGroupBox* groupBox = workflowWidget->workflowGroupBox();
  455. groupBox->setPreText("I am some pre-text");
  456. groupBox->setPostText("I am some post-text");
  457. groupBox->setHideWidgetsOfNonCurrentSteps(hideWidgets);
  458. // create and add the first workflow step (depends on workflowWidget
  459. // type)
  460. ctkExampleDerivedWorkflowWidgetStep* step1 = new ctkExampleDerivedWorkflowWidgetStep(workflow, "Step 1");
  461. step1->setName("Step 1");
  462. step1->setDescription("I am in step 1");
  463. if (ctkWorkflowTabWidget* tabWidget = qobject_cast<ctkWorkflowTabWidget*>(workflowWidget))
  464. {
  465. tabWidget->associateStepWithLabel(step1, "tab1");
  466. }
  467. // step1 is the initial step
  468. workflow->setInitialStep(step1);
  469. // create and add the second workflow step (depends on
  470. // workflowWidget type)
  471. ctkExampleDerivedWorkflowWidgetStep* step2 = new ctkExampleDerivedWorkflowWidgetStep(workflow, "Step 2");
  472. step2->setName("Step 2");
  473. step2->setDescription("I am in step 2");
  474. if (ctkWorkflowTabWidget* tabWidget = qobject_cast<ctkWorkflowTabWidget*>(workflowWidget))
  475. {
  476. tabWidget->associateStepWithLabel(step2, "tab2");
  477. }
  478. // add the steps to the workflow
  479. workflow->addTransition(step1, step2);
  480. // start the workflow
  481. workflow->start();
  482. workflowWidget->show();
  483. // first user interaction test
  484. if (userInteractionSimulator1(app, step1, step2, workflow, workflowWidget, defaultTime) == EXIT_FAILURE)
  485. {
  486. return EXIT_FAILURE;
  487. }
  488. // stop the workflow
  489. workflow->stop();
  490. QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  491. app.exec();
  492. // create and add a third workflow step (depends on workflowWidget
  493. // type)
  494. ctkExampleDerivedWorkflowWidgetStep* step3 = new ctkExampleDerivedWorkflowWidgetStep(workflow, "Step 3");
  495. step3->setName("Step 3");
  496. step3->setDescription("I am in step 3");
  497. if (ctkWorkflowStackedWidget* stackedWidget = qobject_cast<ctkWorkflowStackedWidget*>(workflowWidget))
  498. {
  499. stackedWidget->associateStepWithPage(step3, 1);
  500. }
  501. else if (ctkWorkflowTabWidget* tabWidget = qobject_cast<ctkWorkflowTabWidget*>(workflowWidget))
  502. {
  503. tabWidget->associateStepWithPage(step3, 1, "tab2");
  504. }
  505. // icon test - add an icon to step3, should show up as a icon on the finish button
  506. step3->setIcon(step3->stepArea()->style()->standardIcon(QStyle::SP_ArrowUp));
  507. workflow->addTransition(step2, step3);
  508. // restart the workflow
  509. workflow->start();
  510. // second user interaction test
  511. if (userInteractionSimulator2(app, step1, step2, step3, workflow, workflowWidget, defaultTime) == EXIT_FAILURE)
  512. {
  513. return EXIT_FAILURE;
  514. }
  515. // stop the workflow
  516. workflow->stop();
  517. QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  518. app.exec();
  519. // TODO put back once we can have more than one finish step
  520. // make the second workflow step a finish step as well
  521. // finishSteps.push_back(step2);
  522. // step1->setFinishStepsToHaveButtonsInStepArea(finishSteps);
  523. // step2->setFinishStepsToHaveButtonsInStepArea(finishSteps);
  524. // step3->setFinishStepsToHaveButtonsInStepArea(finishSteps);
  525. // // workflow->addFinishStep(step2);
  526. // // restart the workflow
  527. // workflow->start();
  528. // QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  529. // app.exec();
  530. // // third user interfaction test
  531. // if (userInteractionSimulator3(app, step1, step2, step3, workflow, workflowWidget, defaultTime) == EXIT_FAILURE)
  532. // {
  533. // return EXIT_FAILURE;
  534. // }
  535. // // stop the workflow
  536. // workflow->stop();
  537. // QTimer::singleShot(defaultTime, &app, SLOT(quit()));
  538. // app.exec();
  539. // handles deletion of the workflowWidget, workflow, steps, states
  540. // and transitions
  541. delete workflowWidget;
  542. return EXIT_SUCCESS;
  543. }
  544. //-----------------------------------------------------------------------------
  545. int ctkWorkflowWidgetTest1(int argc, char * argv [] )
  546. {
  547. QApplication app(argc, argv);
  548. int defaultTime = 100;
  549. bool hideWidgets = false;
  550. if (runWorkflowWidgetTest(new ctkWorkflowWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  551. {
  552. return EXIT_FAILURE;
  553. }
  554. if (runWorkflowWidgetTest(new ctkWorkflowStackedWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  555. {
  556. return EXIT_FAILURE;
  557. }
  558. if (runWorkflowWidgetTest(new ctkWorkflowTabWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  559. {
  560. return EXIT_FAILURE;
  561. }
  562. hideWidgets = true;
  563. if (runWorkflowWidgetTest(new ctkWorkflowWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  564. {
  565. return EXIT_FAILURE;
  566. }
  567. if (runWorkflowWidgetTest(new ctkWorkflowStackedWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  568. {
  569. return EXIT_FAILURE;
  570. }
  571. if (runWorkflowWidgetTest(new ctkWorkflowTabWidget, app, hideWidgets, defaultTime) == EXIT_FAILURE)
  572. {
  573. return EXIT_FAILURE;
  574. }
  575. return EXIT_SUCCESS;
  576. }