ctkDoubleRangeSliderEventTranslatorPlayerTest1.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <QTimer>
  18. // QtTesting includes
  19. #include <pqTestUtility.h>
  20. // CTK includes
  21. #include "ctkCallback.h"
  22. #include "ctkConfig.h"
  23. #include "ctkDoubleRangeSlider.h"
  24. #include "ctkDoubleRangeSliderEventPlayer.h"
  25. #include "ctkDoubleRangeSliderEventTranslator.h"
  26. #include "ctkEventTranslatorPlayerWidget.h"
  27. #include "ctkSetName.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. ctkDoubleRangeSlider* widget = reinterpret_cast<ctkDoubleRangeSlider*>(data);
  39. CTKCOMPARE(widget->maximumValue(), 76.00);
  40. CTKCOMPARE(widget->minimumValue(), 19.00);
  41. }
  42. void checkFinalWidgetState2(void* data)
  43. {
  44. ctkDoubleRangeSlider* widget = reinterpret_cast<ctkDoubleRangeSlider*>(data);
  45. CTKCOMPARE(widget->maximumValue(), 78.00);
  46. CTKCOMPARE(widget->minimumValue(), 17.00);
  47. }
  48. void checkFinalWidgetState3(void* data)
  49. {
  50. ctkDoubleRangeSlider* widget = reinterpret_cast<ctkDoubleRangeSlider*>(data);
  51. CTKCOMPARE(widget->maximumValue(), -10.47);
  52. CTKCOMPARE(widget->minimumValue(), -49.79);
  53. }
  54. }
  55. //-----------------------------------------------------------------------------
  56. int ctkDoubleRangeSliderEventTranslatorPlayerTest1(int argc, char * argv [])
  57. {
  58. QApplication app(argc, argv);
  59. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  60. // ------------------------
  61. ctkEventTranslatorPlayerWidget etpWidget;
  62. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  63. etpWidget.setTestUtility(testUtility);
  64. etpWidget.addWidgetEventTranslator(new ctkDoubleRangeSliderEventTranslator);
  65. etpWidget.addWidgetEventPlayer(new ctkDoubleRangeSliderEventPlayer);
  66. // Test case 1
  67. ctkDoubleRangeSlider* widget = new ctkDoubleRangeSlider() << ctkSetName("doubleRangeSlider1");
  68. etpWidget.addTestCase(widget,
  69. xmlDirectory + "ctkDoubleRangeSliderEventTranslatorPlayerTest1.xml",
  70. &checkFinalWidgetState);
  71. // Test case 2
  72. ctkDoubleRangeSlider* widget2 = new ctkDoubleRangeSlider() << ctkSetName("doubleRangeSlider2");
  73. widget2->setOrientation(Qt::Horizontal);
  74. etpWidget.addTestCase(widget2,
  75. xmlDirectory + "ctkDoubleRangeSliderEventTranslatorPlayerTest2.xml",
  76. &checkFinalWidgetState2);
  77. // Test case 3
  78. ctkDoubleRangeSlider* widget3 = new ctkDoubleRangeSlider();
  79. widget3->setOrientation(Qt::Horizontal);
  80. widget3->setRange(-52.89,10);
  81. widget3->setMinimumPosition(-40.00);
  82. widget3->setSingleStep(0.89);
  83. etpWidget.addTestCase(widget3,
  84. xmlDirectory + "ctkDoubleRangeSliderEventTranslatorPlayerTest3.xml",
  85. &checkFinalWidgetState3);
  86. // ------------------------
  87. if (!app.arguments().contains("-I"))
  88. {
  89. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  90. }
  91. etpWidget.show();
  92. return app.exec();
  93. }