ctkCollapsibleGroupBoxEventTranslatorPlayerTest1.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 <QAction>
  16. #include <QApplication>
  17. #include <QCheckBox>
  18. #include <QDebug>
  19. #include <QRadioButton>
  20. #include <QSignalSpy>
  21. #include <QStandardItemModel>
  22. #include <QTimer>
  23. #include <QTreeView>
  24. #include <QVBoxLayout>
  25. // CTK includes
  26. #include "ctkCallback.h"
  27. #include "ctkConfig.h"
  28. #include "ctkCollapsibleGroupBox.h"
  29. #include "ctkEventTranslatorPlayerWidget.h"
  30. // QtTesting includes
  31. #include "pqTestUtility.h"
  32. // STD includes
  33. #include <cstdlib>
  34. #include <iostream>
  35. namespace
  36. {
  37. QSignalSpy *Spy1;
  38. QSignalSpy *Spy2;
  39. //-----------------------------------------------------------------------------
  40. void checkFinalWidgetState(void* data)
  41. {
  42. QWidget* parentWidget = reinterpret_cast<QWidget*>(data);
  43. QList<ctkCollapsibleGroupBox*> widget = parentWidget->findChildren<ctkCollapsibleGroupBox*>();
  44. if(widget.count())
  45. {
  46. CTKCOMPARE(Spy1->count(), 2);
  47. CTKCOMPARE(Spy2->count(), 4);
  48. CTKCOMPARE(widget[0]->collapsed(), false);
  49. CTKCOMPARE(widget[1]->collapsed(), true);
  50. }
  51. else
  52. {
  53. QApplication::exit(EXIT_FAILURE);
  54. }
  55. }
  56. }
  57. //-----------------------------------------------------------------------------
  58. int ctkCollapsibleGroupBoxEventTranslatorPlayerTest1(int argc, char * argv [] )
  59. {
  60. QApplication app(argc, argv);
  61. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  62. // ------------------------
  63. ctkEventTranslatorPlayerWidget etpWidget;
  64. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  65. etpWidget.setTestUtility(testUtility);
  66. // Test case 1
  67. QWidget widget(0);
  68. ctkCollapsibleGroupBox* groupBox = new ctkCollapsibleGroupBox(QObject::tr("GroupBox"));
  69. QRadioButton *radio1 = new QRadioButton(QObject::tr("&Radio button 1"));
  70. QRadioButton *radio2 = new QRadioButton(QObject::tr("R&adio button 2"));
  71. QRadioButton *radio3 = new QRadioButton(QObject::tr("Ra&dio button 3"));
  72. ctkCollapsibleGroupBox* hiddenGroupBox = new ctkCollapsibleGroupBox;
  73. hiddenGroupBox->setTitle("Advanced...");
  74. radio1->setChecked(true);
  75. QVBoxLayout *vbox = new QVBoxLayout;
  76. vbox->addWidget(radio1);
  77. vbox->addWidget(radio2);
  78. vbox->addWidget(radio3);
  79. vbox->addWidget(hiddenGroupBox);
  80. vbox->addStretch(1);
  81. groupBox->setLayout(vbox);
  82. QCheckBox* checkBox = new QCheckBox("Check box");
  83. QVBoxLayout *vbox2 = new QVBoxLayout;
  84. vbox2->addWidget(checkBox);
  85. hiddenGroupBox->setLayout(vbox2);
  86. hiddenGroupBox->setCollapsed(true);
  87. QVBoxLayout* topLevelVBox = new QVBoxLayout;
  88. topLevelVBox->addWidget(groupBox);
  89. widget.setLayout(topLevelVBox);
  90. QSignalSpy spy1(groupBox, SIGNAL(clicked()));
  91. QSignalSpy spy2(hiddenGroupBox, SIGNAL(clicked()));
  92. Spy1 = &spy1;
  93. Spy2 = &spy2;
  94. etpWidget.addTestCase(&widget,
  95. xmlDirectory + "ctkCollapsibleGroupBoxEventTranslatorPlayerTest1.xml",
  96. &checkFinalWidgetState);
  97. // ------------------------
  98. if (!app.arguments().contains("-I"))
  99. {
  100. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  101. }
  102. etpWidget.show();
  103. return app.exec();
  104. }