ctkMenuButtonEventTranslatorPlayerTest1.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <QMenu>
  19. #include <QSignalSpy>
  20. #include <QStandardItemModel>
  21. #include <QTimer>
  22. #include <QTreeView>
  23. // CTK includes
  24. #include "ctkCallback.h"
  25. #include "ctkConfig.h"
  26. #include "ctkMenuButton.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. QSignalSpy* Spy1;
  36. QSignalSpy* Spy2;
  37. QSignalSpy* Spy3;
  38. //-----------------------------------------------------------------------------
  39. void checkFinalWidgetState(void* data)
  40. {
  41. ctkMenuButton* widget = reinterpret_cast<ctkMenuButton*>(data);
  42. if(!widget)
  43. {
  44. QApplication::exit(EXIT_FAILURE);
  45. }
  46. CTKCOMPARE(Spy1->count(), 1);
  47. CTKCOMPARE(Spy2->count(), 1);
  48. CTKCOMPARE(Spy3->count(), 1);
  49. }
  50. }
  51. //-----------------------------------------------------------------------------
  52. int ctkMenuButtonEventTranslatorPlayerTest1(int argc, char * argv [] )
  53. {
  54. QApplication app(argc, argv);
  55. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  56. // ------------------------
  57. ctkEventTranslatorPlayerWidget etpWidget;
  58. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  59. etpWidget.setTestUtility(testUtility);
  60. // Test case 1
  61. QWidget* widget = new QWidget(0);
  62. ctkMenuButton* menuButton = new ctkMenuButton("ctkMenuButton", widget);
  63. QMenu* menu = new QMenu("menu", menuButton);
  64. QAction* action1 = new QAction("extra choice 1", menu);
  65. QAction* action2 = new QAction("extra choice 2", menu);
  66. QAction* action3 = new QAction("extra choice 3", menu);
  67. menu->addAction(action1);
  68. menu->addAction(action2);
  69. menu->addAction(action3);
  70. QSignalSpy spy1(action1, SIGNAL(triggered()));
  71. QSignalSpy spy2(action2, SIGNAL(triggered()));
  72. QSignalSpy spy3(action3, SIGNAL(triggered()));
  73. Spy1 = &spy1;
  74. Spy2 = &spy2;
  75. Spy3 = &spy3;
  76. menuButton->setMenu(menu);
  77. etpWidget.addTestCase(widget,
  78. xmlDirectory + "ctkMenuButtonEventTranslatorPlayerTest1.xml",
  79. &checkFinalWidgetState);
  80. // ------------------------
  81. if (!app.arguments().contains("-I"))
  82. {
  83. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  84. }
  85. etpWidget.show();
  86. return app.exec();
  87. }