ctkCheckableComboBoxEventTranslatorPlayerTest1.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 <QApplication>
  16. #include <QDebug>
  17. #include <QSignalSpy>
  18. #include <QTimer>
  19. #include <QVBoxLayout>
  20. // QtTesting includes
  21. #include <pqTestUtility.h>
  22. // CTK includes
  23. #include "ctkCallback.h"
  24. #include "ctkConfig.h"
  25. #include "ctkCheckableComboBox.h"
  26. #include "ctkCheckableComboBoxEventPlayer.h"
  27. #include "ctkCheckableComboBoxEventTranslator.h"
  28. #include "ctkEventTranslatorPlayerWidget.h"
  29. // QtTesting includes
  30. #include "pqTestUtility.h"
  31. // STD includes
  32. #include <cstdlib>
  33. #include <iostream>
  34. namespace
  35. {
  36. QSignalSpy *Spy1;
  37. //-----------------------------------------------------------------------------
  38. void checkFinalWidgetState(void* data)
  39. {
  40. ctkCheckableComboBox* widget = reinterpret_cast<ctkCheckableComboBox*>(data);
  41. CTKCOMPARE(Spy1->count(), 15);
  42. CTKCOMPARE(widget->checkedIndexes().count(), 3);
  43. CTKCOMPARE(widget->noneChecked(), false);
  44. // CTKCOMPARE(widget->currentText(), "toto, titi, tutu");
  45. }
  46. //-----------------------------------------------------------------------------
  47. void checkFinalWidgetState2(void* data)
  48. {
  49. QWidget* parentWidget = reinterpret_cast<QWidget*>(data);
  50. QList<ctkCheckableComboBox*> widget = parentWidget->findChildren<ctkCheckableComboBox*>();
  51. if(widget.count())
  52. {
  53. CTKCOMPARE(widget[0]->checkedIndexes().count(), 2);
  54. CTKCOMPARE(widget[0]->noneChecked(), false);
  55. // CTKCOMPARE(widget[0]->currentText(), "tata,titi");
  56. }
  57. else
  58. {
  59. QApplication::exit(EXIT_FAILURE);
  60. }
  61. }
  62. }
  63. //-----------------------------------------------------------------------------
  64. int ctkCheckableComboBoxEventTranslatorPlayerTest1(int argc, char * argv [])
  65. {
  66. QApplication app(argc, argv);
  67. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  68. // ------------------------
  69. ctkEventTranslatorPlayerWidget etpWidget;
  70. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  71. etpWidget.setTestUtility(testUtility);
  72. etpWidget.addWidgetEventTranslator(new ctkCheckableComboBoxEventTranslator);
  73. etpWidget.addWidgetEventPlayer(new ctkCheckableComboBoxEventPlayer);
  74. // Test case 1
  75. ctkCheckableComboBox* widget = new ctkCheckableComboBox();
  76. widget->addItem("toto");
  77. widget->addItem("tata");
  78. widget->addItem("titi");
  79. widget->addItem(widget->style()->standardIcon(QStyle::SP_FileIcon),"tutu");
  80. QSignalSpy spy1(widget, SIGNAL(checkedIndexesChanged()));
  81. Spy1 = &spy1;
  82. etpWidget.addTestCase(widget,
  83. xmlDirectory + "ctkCheckableComboBoxEventTranslatorPlayerTest1.xml",
  84. &checkFinalWidgetState);
  85. // Test case 2
  86. QWidget widget2(0);
  87. ctkCheckableComboBox* comboBox2 = new ctkCheckableComboBox(&widget2);
  88. comboBox2->addItem("toto");
  89. comboBox2->addItem("tata");
  90. comboBox2->addItem("titi");
  91. comboBox2->addItem(comboBox2->style()->standardIcon(QStyle::SP_FileIcon),"tutu");
  92. etpWidget.addTestCase(&widget2,
  93. xmlDirectory + "ctkCheckableComboBoxEventTranslatorPlayerTest2.xml",
  94. &checkFinalWidgetState2);
  95. // ------------------------
  96. if (!app.arguments().contains("-I"))
  97. {
  98. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  99. }
  100. etpWidget.show();
  101. return app.exec();
  102. }