ctkActionsWidgetEventTranslatorPlayerTest1.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 <QStandardItemModel>
  19. #include <QTimer>
  20. #include <QTreeView>
  21. // CTK includes
  22. #include "ctkActionsWidget.h"
  23. #include <ctkCallback.h>
  24. #include <ctkConfig.h>
  25. #include "ctkEventTranslatorPlayerWidget.h"
  26. #include "ctkSetName.h"
  27. // QtTesting includes
  28. #include "pqTestUtility.h"
  29. // STD includes
  30. #include <cstdlib>
  31. #include <iostream>
  32. namespace
  33. {
  34. //-----------------------------------------------------------------------------
  35. void checkFinalWidgetState(void* data)
  36. {
  37. ctkActionsWidget* widget = reinterpret_cast<ctkActionsWidget*>(data);
  38. CTKCOMPARE(widget->view()->currentIndex().row(), 2);
  39. }
  40. }
  41. //-----------------------------------------------------------------------------
  42. int ctkActionsWidgetEventTranslatorPlayerTest1(int argc, char * argv [] )
  43. {
  44. QApplication app(argc, argv);
  45. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  46. // ------------------------
  47. ctkEventTranslatorPlayerWidget etpWidget;
  48. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  49. etpWidget.setTestUtility(testUtility);
  50. // Test case 1
  51. ctkActionsWidget* widget = new ctkActionsWidget() << ctkSetName("actionsWidget");
  52. QIcon informationIcon = widget->style()->standardIcon(QStyle::SP_MessageBoxInformation);
  53. widget->addAction(new QAction(0), "category 1");
  54. widget->addAction(new QAction(qApp), "category 1");
  55. widget->addAction(new QAction("Action Text3", &etpWidget), "category 1");
  56. widget->addAction(new QAction(informationIcon, "Action Text4", qApp), "category 1");
  57. widget->addAction(new QAction(informationIcon, "Action Text5", qApp), "category 1");
  58. etpWidget.addTestCase(widget,
  59. xmlDirectory + "ctkActionsWidgetEventTranslatorPlayerTest1.xml",
  60. &checkFinalWidgetState);
  61. // ------------------------
  62. if (argc < 2 || QString(argv[1]) != "-I")
  63. {
  64. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  65. }
  66. etpWidget.show();
  67. return app.exec();
  68. }