ctkAxesWidgetEventTranslatorPlayerTest1.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <QSignalSpy>
  17. #include <QTimer>
  18. // CTK includes
  19. #include "ctkAxesWidget.h"
  20. #include "ctkAxesWidgetEventPlayer.h"
  21. #include "ctkAxesWidgetEventTranslator.h"
  22. #include <ctkCallback.h>
  23. #include <ctkConfig.h>
  24. #include "ctkEventTranslatorPlayerWidget.h"
  25. // QtTesting includes
  26. #include "pqTestUtility.h"
  27. // STD includes
  28. #include <cstdlib>
  29. #include <iostream>
  30. namespace
  31. {
  32. //-----------------------------------------------------------------------------
  33. void checkFinalWidgetState(void* data)
  34. {
  35. ctkAxesWidget* widget = reinterpret_cast<ctkAxesWidget*>(data);
  36. CTKCOMPARE(widget->currentAxis(), ctkAxesWidget::Left);
  37. }
  38. //-----------------------------------------------------------------------------
  39. void checkFinalWidgetState2(void* data)
  40. {
  41. ctkAxesWidget* widget = reinterpret_cast<ctkAxesWidget*>(data);
  42. CTKCOMPARE(widget->currentAxis(), ctkAxesWidget::None);
  43. }
  44. }
  45. //-----------------------------------------------------------------------------
  46. int ctkAxesWidgetEventTranslatorPlayerTest1(int argc, char * argv [] )
  47. {
  48. QApplication app(argc, argv);
  49. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  50. // ------------------------
  51. ctkEventTranslatorPlayerWidget etpWidget;
  52. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  53. etpWidget.setTestUtility(testUtility);
  54. etpWidget.addWidgetEventPlayer(new ctkAxesWidgetEventPlayer);
  55. etpWidget.addWidgetEventTranslator(new ctkAxesWidgetEventTranslator);
  56. // Test case 1 --- autoReset = false
  57. ctkAxesWidget* widget = new ctkAxesWidget();
  58. etpWidget.addTestCase(widget,
  59. xmlDirectory + "ctkAxesWidgetEventTranslatorPlayerTest1.xml",
  60. &checkFinalWidgetState);
  61. // Test case 2 --- autoReset = true
  62. ctkAxesWidget* widget2 = new ctkAxesWidget();
  63. widget2->setAutoReset(true);
  64. etpWidget.addTestCase(widget2,
  65. xmlDirectory + "ctkAxesWidgetEventTranslatorPlayerTest1.xml",
  66. &checkFinalWidgetState2);
  67. // ------------------------
  68. if (argc < 2 || QString(argv[1]) != "-I")
  69. {
  70. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  71. }
  72. etpWidget.show();
  73. return app.exec();
  74. }