ctkDoubleSliderEventTranslatorPlayerTest1.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // CTK includes
  19. #include "ctkDoubleSlider.h"
  20. #include <ctkCallback.h>
  21. #include <ctkConfig.h>
  22. #include "ctkEventTranslatorPlayerWidget.h"
  23. // QtTesting includes
  24. #include "pqTestUtility.h"
  25. // STD includes
  26. #include <cstdlib>
  27. #include <iostream>
  28. namespace
  29. {
  30. //-----------------------------------------------------------------------------
  31. void checkFinalWidgetState(void* data)
  32. {
  33. ctkDoubleSlider* widget = reinterpret_cast<ctkDoubleSlider*>(data);
  34. CTKCOMPARE(widget->value(), 60.00);
  35. }
  36. void checkFinalWidgetState3(void* data)
  37. {
  38. ctkDoubleSlider* widget = reinterpret_cast<ctkDoubleSlider*>(data);
  39. CTKCOMPARE(widget->value(), -27.82);
  40. }
  41. }
  42. //-----------------------------------------------------------------------------
  43. int ctkDoubleSliderEventTranslatorPlayerTest1(int argc, char * argv [] )
  44. {
  45. QApplication app(argc, argv);
  46. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  47. // ------------------------
  48. ctkEventTranslatorPlayerWidget etpWidget;
  49. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  50. etpWidget.setTestUtility(testUtility);
  51. // Test case 1
  52. ctkDoubleSlider* widget = new ctkDoubleSlider();
  53. etpWidget.addTestCase(widget,
  54. xmlDirectory + "ctkDoubleSliderEventTranslatorPlayerTest1.xml",
  55. &checkFinalWidgetState);
  56. // Test case 2
  57. ctkDoubleSlider* widget2 = new ctkDoubleSlider();
  58. widget2->setOrientation(Qt::Horizontal);
  59. etpWidget.addTestCase(widget2,
  60. xmlDirectory + "ctkDoubleSliderEventTranslatorPlayerTest1.xml",
  61. &checkFinalWidgetState);
  62. // Test case 3
  63. ctkDoubleSlider* widget3 = new ctkDoubleSlider();
  64. widget3->setOrientation(Qt::Horizontal);
  65. widget3->setRange(-52.89,10);
  66. widget3->setValue(-40.28);
  67. widget3->setSingleStep(0.89);
  68. etpWidget.addTestCase(widget3,
  69. xmlDirectory + "ctkDoubleSliderEventTranslatorPlayerTest2.xml",
  70. &checkFinalWidgetState3);
  71. // ------------------------
  72. if (!app.arguments().contains("-I"))
  73. {
  74. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  75. }
  76. etpWidget.show();
  77. return app.exec();
  78. }