ctkButtonGroupEventTranslatorPlayerTest1.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 <QDebug>
  18. #include <QPushButton>
  19. #include <QSignalSpy>
  20. #include <QStandardItemModel>
  21. #include <QTimer>
  22. #include <QTreeView>
  23. #include <QVBoxLayout>
  24. // CTK includes
  25. #include "ctkCallback.h"
  26. #include "ctkConfig.h"
  27. #include "ctkButtonGroup.h"
  28. #include "ctkEventTranslatorPlayerWidget.h"
  29. // STD includes
  30. #include <cstdlib>
  31. #include <iostream>
  32. namespace
  33. {
  34. QSignalSpy* Spy1;
  35. QSignalSpy* Spy2;
  36. QSignalSpy* Spy3;
  37. //-----------------------------------------------------------------------------
  38. void checkFinalWidgetState(void* data)
  39. {
  40. QWidget* parentWidget = reinterpret_cast<QWidget*>(data);
  41. QList<ctkButtonGroup*> widget = parentWidget->findChildren<ctkButtonGroup*>();
  42. if(widget.count())
  43. {
  44. CTKCOMPARE(widget[0]->checkedButton()->text(), QString("button 1"));
  45. CTKCOMPARE(Spy1->count(), 3);
  46. CTKCOMPARE(Spy2->count(), 2);
  47. CTKCOMPARE(Spy3->count(), 4);
  48. }
  49. else
  50. {
  51. QApplication::exit(EXIT_FAILURE);
  52. }
  53. }
  54. }
  55. //-----------------------------------------------------------------------------
  56. int ctkButtonGroupEventTranslatorPlayerTest1(int argc, char * argv [] )
  57. {
  58. QApplication app(argc, argv);
  59. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  60. // ------------------------
  61. ctkEventTranslatorPlayerWidget etpWidget;
  62. // Test case 1
  63. QWidget widget(0);
  64. QVBoxLayout* layout = new QVBoxLayout(&widget);
  65. QPushButton* button1 = new QPushButton("button 1", &widget);
  66. QPushButton* button2 = new QPushButton("button 2", &widget);
  67. QPushButton* button3 = new QPushButton("button 3", &widget);
  68. layout->addWidget(button1);
  69. layout->addWidget(button2);
  70. layout->addWidget(button3);
  71. widget.setLayout(layout);
  72. button1->setCheckable(true);
  73. button2->setCheckable(true);
  74. button3->setCheckable(false);
  75. ctkButtonGroup* buttonGroup = new ctkButtonGroup(&widget);
  76. buttonGroup->addButton(button1);
  77. buttonGroup->addButton(button2);
  78. buttonGroup->addButton(button3);
  79. QSignalSpy spy1(button1, SIGNAL(clicked()));
  80. QSignalSpy spy2(button2, SIGNAL(clicked()));
  81. QSignalSpy spy3(button3, SIGNAL(clicked()));
  82. Spy1 = &spy1;
  83. Spy2 = &spy2;
  84. Spy3 = &spy3;
  85. etpWidget.addTestCase(&widget,
  86. xmlDirectory + "ctkButtonGroupEventTranslatorPlayerTest1.xml",
  87. &checkFinalWidgetState);
  88. // ------------------------
  89. if (!app.arguments().contains("-I"))
  90. {
  91. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  92. }
  93. etpWidget.show();
  94. return app.exec();
  95. }