ctkCollapsibleButtonEventTranslatorPlayerTest1.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 <QPushButton>
  18. #include <QStyle>
  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 "ctkCollapsibleButton.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. ctkCollapsibleButton* widget = reinterpret_cast<ctkCollapsibleButton*>(data);
  39. CTKCOMPARE(widget->collapsed(), true);
  40. CTKCOMPARE(widget->collapsedHeight(), 10);
  41. QApplication::exit(EXIT_SUCCESS);
  42. }
  43. }
  44. //-----------------------------------------------------------------------------
  45. int ctkCollapsibleButtonEventTranslatorPlayerTest1(int argc, char * argv [])
  46. {
  47. QApplication app(argc, argv);
  48. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  49. // ------------------------
  50. ctkEventTranslatorPlayerWidget etpWidget;
  51. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  52. etpWidget.setTestUtility(testUtility);
  53. // Test case 1
  54. ctkCollapsibleButton* widget = new ctkCollapsibleButton();
  55. widget->setText("top button");
  56. QPushButton * button= new QPushButton(QObject::tr("Button"));
  57. ctkCollapsibleButton *collapsibleButton2 = new ctkCollapsibleButton(QObject::tr("Nested Collapsible Button"));
  58. ctkCollapsibleButton *collapsibleButton3 = new ctkCollapsibleButton(QObject::tr("CollapsibleButton"));
  59. collapsibleButton3->setIcon(collapsibleButton3->style()->standardIcon(QStyle::SP_FileDialogDetailedView));
  60. QPushButton * button2 = new QPushButton(QObject::tr("Nested PushButton"));
  61. QVBoxLayout *nestedBox = new QVBoxLayout;
  62. nestedBox->addWidget(button2);
  63. collapsibleButton3->setLayout(nestedBox);
  64. QVBoxLayout *vbox = new QVBoxLayout;
  65. vbox->addWidget(button);
  66. vbox->addWidget(collapsibleButton2);
  67. vbox->addWidget(collapsibleButton3);
  68. widget->setLayout(vbox);
  69. etpWidget.addTestCase(widget,
  70. xmlDirectory + "ctkCollapsibleButtonEventTranslatorPlayerTest1.xml",
  71. &checkFinalWidgetState);
  72. // ------------------------
  73. if (!app.arguments().contains("-I"))
  74. {
  75. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  76. }
  77. etpWidget.show();
  78. return app.exec();
  79. }