ctkCheckablePushButtonEventTranslatorPlayerTest1.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 <QStandardItem>
  18. #include <QTableView>
  19. #include <QTimer>
  20. #include <QVBoxLayout>
  21. // QtTesting includes
  22. #include <pqTestUtility.h>
  23. // CTK includes
  24. #include "ctkCallback.h"
  25. #include "ctkConfig.h"
  26. #include "ctkCheckablePushButton.h"
  27. #include "ctkEventTranslatorPlayerWidget.h"
  28. // QtTesting includes
  29. #include "pqTestUtility.h"
  30. // STD includes
  31. #include <cstdlib>
  32. #include <iostream>
  33. namespace
  34. {
  35. //-----------------------------------------------------------------------------
  36. void checkFinalWidgetState(void* data)
  37. {
  38. ctkCheckablePushButton* widget = reinterpret_cast<ctkCheckablePushButton*>(data);
  39. CTKCOMPARE(widget->isChecked(), true);
  40. }
  41. //-----------------------------------------------------------------------------
  42. void checkFinalWidgetState2(void* data)
  43. {
  44. QWidget* parentWidget = reinterpret_cast<QWidget*>(data);
  45. QList<ctkCheckablePushButton*> widget = parentWidget->findChildren<ctkCheckablePushButton*>();
  46. if(widget.count())
  47. {
  48. CTKCOMPARE(widget[0]->isChecked(), true);
  49. }
  50. else
  51. {
  52. QApplication::exit(EXIT_FAILURE);
  53. }
  54. }
  55. //-----------------------------------------------------------------------------
  56. void checkFinalWidgetState3(void* data)
  57. {
  58. QWidget* parentWidget = reinterpret_cast<QWidget*>(data);
  59. QList<ctkCheckablePushButton*> widget = parentWidget->findChildren<ctkCheckablePushButton*>();
  60. if(widget.count())
  61. {
  62. CTKCOMPARE(widget[0]->isChecked(), true);
  63. CTKCOMPARE(widget[1]->isChecked(), false);
  64. }
  65. else
  66. {
  67. QApplication::exit(EXIT_FAILURE);
  68. }
  69. }
  70. }
  71. //-----------------------------------------------------------------------------
  72. int ctkCheckablePushButtonEventTranslatorPlayerTest1(int argc, char * argv [])
  73. {
  74. QApplication app(argc, argv);
  75. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  76. // ------------------------
  77. ctkEventTranslatorPlayerWidget etpWidget;
  78. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  79. etpWidget.setTestUtility(testUtility);
  80. // Test case 1
  81. ctkCheckablePushButton* widget = new ctkCheckablePushButton();
  82. widget->setText("Foo");
  83. widget->setCheckable(true);
  84. etpWidget.addTestCase(widget,
  85. xmlDirectory + "ctkCheckablePushButtonEventTranslatorPlayerTest1.xml",
  86. &checkFinalWidgetState);
  87. // Test case 2
  88. QWidget widget2(0);
  89. ctkCheckablePushButton button1(QObject::tr("Button1"));
  90. button1.setCheckable(true);
  91. QVBoxLayout *layout= new QVBoxLayout;
  92. layout->addWidget(&button1);
  93. widget2.setLayout(layout);
  94. etpWidget.addTestCase(&widget2,
  95. xmlDirectory + "ctkCheckablePushButtonEventTranslatorPlayerTest2.xml",
  96. &checkFinalWidgetState2);
  97. // Test case 3
  98. QWidget widget3(0);
  99. ctkCheckablePushButton button2(QObject::tr("Button1"));
  100. ctkCheckablePushButton button3(QObject::tr("Button2"));
  101. button2.setCheckable(true);
  102. button3.setCheckable(true);
  103. QVBoxLayout *layout2= new QVBoxLayout;
  104. layout2->addWidget(&button2);
  105. layout2->addWidget(&button3);
  106. widget3.setLayout(layout2);
  107. etpWidget.addTestCase(&widget3,
  108. xmlDirectory + "ctkCheckablePushButtonEventTranslatorPlayerTest3.xml",
  109. &checkFinalWidgetState3);
  110. // ------------------------
  111. if (argc < 2 || QString(argv[1]) != "-I")
  112. {
  113. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  114. }
  115. etpWidget.show();
  116. return app.exec();
  117. }