ctkRangeWidgetEventTranslatorPlayerTest1.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 <QAction>
  16. #include <QApplication>
  17. #include <QDebug>
  18. #include <QStandardItemModel>
  19. #include <QTimer>
  20. #include <QTreeView>
  21. // CTK includes
  22. #include "ctkCallback.h"
  23. #include "ctkConfig.h"
  24. #include "ctkRangeWidget.h"
  25. #include <ctkDoubleRangeSliderEventPlayer.h>
  26. #include <ctkDoubleRangeSliderEventTranslator.h>
  27. #include "ctkEventTranslatorPlayerWidget.h"
  28. #include "ctkSetName.h"
  29. // QtTesting includes
  30. #include "pqTestUtility.h"
  31. // STD includes
  32. #include <cstdlib>
  33. #include <iostream>
  34. namespace
  35. {
  36. //-----------------------------------------------------------------------------
  37. void checkFinalWidgetState(void* data)
  38. {
  39. ctkRangeWidget* widget = reinterpret_cast<ctkRangeWidget*>(data);
  40. CTKCOMPARE(widget->maximumValue(), 72.00);
  41. CTKCOMPARE(widget->minimumValue(), 34.00);
  42. }
  43. //-----------------------------------------------------------------------------
  44. void checkFinalWidgetState2(void* data)
  45. {
  46. ctkRangeWidget* widget = reinterpret_cast<ctkRangeWidget*>(data);
  47. CTKCOMPARE(widget->maximumValue(), -9.6);
  48. CTKCOMPARE(widget->minimumValue(), -35.00);
  49. }
  50. }
  51. //-----------------------------------------------------------------------------
  52. int ctkRangeWidgetEventTranslatorPlayerTest1(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. etpWidget.addWidgetEventPlayer(new ctkDoubleRangeSliderEventPlayer);
  61. etpWidget.addWidgetEventTranslator(new ctkDoubleRangeSliderEventTranslator);
  62. // Test case 1
  63. ctkRangeWidget* widget = new ctkRangeWidget() << ctkSetName("RangeWidget1");
  64. etpWidget.addTestCase(widget,
  65. xmlDirectory + "ctkRangeWidgetEventTranslatorPlayerTest1.xml",
  66. &checkFinalWidgetState);
  67. // Test case 2
  68. ctkRangeWidget* widget2 = new ctkRangeWidget() << ctkSetName("RangeWidget2");
  69. widget2->setRange(-50.38,5.4);
  70. widget2->setSingleStep(5.00);
  71. etpWidget.addTestCase(widget2,
  72. xmlDirectory + "ctkRangeWidgetEventTranslatorPlayerTest2.xml",
  73. &checkFinalWidgetState2);
  74. // ------------------------
  75. if (!app.arguments().contains("-I"))
  76. {
  77. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  78. }
  79. etpWidget.show();
  80. return app.exec();
  81. }