ctkDoubleSliderTest.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.commontk.org/LICENSE
  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 <QTest>
  17. // CTK includes
  18. #include "ctkDoubleSlider.h"
  19. #include "ctkTest.h"
  20. //-----------------------------------------------------------------------------
  21. class ctkDoubleSliderTester: public QObject
  22. {
  23. Q_OBJECT
  24. private slots:
  25. void testUI();
  26. void testRange();
  27. void testRange_data();
  28. void testSingleStep();
  29. void testSingleStep_data();
  30. };
  31. // ----------------------------------------------------------------------------
  32. void ctkDoubleSliderTester::testUI()
  33. {
  34. ctkDoubleSlider slider;
  35. slider.show();
  36. #if (QT_VERSION >= 0x50000)
  37. QTest::qWaitForWindowActive(&slider);
  38. #else
  39. QTest::qWaitForWindowShown(&slider);
  40. #endif
  41. // qApp->exec();
  42. }
  43. // ----------------------------------------------------------------------------
  44. void ctkDoubleSliderTester::testRange()
  45. {
  46. ctkDoubleSlider slider;
  47. QFETCH(double, minimum);
  48. QFETCH(double, maximum);
  49. slider.setRange(minimum, maximum);
  50. QFETCH(double, expectedMinimum);
  51. QFETCH(double, expectedMaximum);
  52. QFETCH(double, expectedValue);
  53. QCOMPARE(slider.minimum(), expectedMinimum);
  54. QCOMPARE(slider.maximum(), expectedMaximum);
  55. QCOMPARE(slider.value(), expectedValue);
  56. }
  57. // ----------------------------------------------------------------------------
  58. void ctkDoubleSliderTester::testRange_data()
  59. {
  60. QTest::addColumn<double>("minimum");
  61. QTest::addColumn<double>("maximum");
  62. QTest::addColumn<double>("expectedMinimum");
  63. QTest::addColumn<double>("expectedMaximum");
  64. QTest::addColumn<double>("expectedValue");
  65. QTest::newRow("[20.123,20.1234]") << 20.123 << 20.1234 << 20.123 << 20.1234 << 20.123;
  66. }
  67. // ----------------------------------------------------------------------------
  68. void ctkDoubleSliderTester::testSingleStep()
  69. {
  70. ctkDoubleSlider slider;
  71. slider.setValue(50.);
  72. QFETCH(double, minimum);
  73. QFETCH(double, maximum);
  74. slider.setRange(minimum, maximum);
  75. QFETCH(double, singleStep);
  76. slider.setSingleStep(singleStep);
  77. QFETCH(double, expectedValue);
  78. QCOMPARE(slider.value(), expectedValue);
  79. }
  80. // ----------------------------------------------------------------------------
  81. void ctkDoubleSliderTester::testSingleStep_data()
  82. {
  83. QTest::addColumn<double>("minimum");
  84. QTest::addColumn<double>("maximum");
  85. QTest::addColumn<double>("singleStep");
  86. QTest::addColumn<double>("expectedValue");
  87. QTest::newRow("1.") << 0. << 100. << 1. << 50.;
  88. QTest::newRow("100.") << 0. << 100. << 100. << 50.;
  89. QTest::newRow("0.1") << 0. << 100. << 0.1 << 50.;
  90. QTest::newRow("min") << 0. << 100. << std::numeric_limits<double>::min() << 50.;
  91. QTest::newRow("max") << 0. << 100. << std::numeric_limits<double>::max() << 50.;
  92. QTest::newRow("-max") << 0. << 100. << -std::numeric_limits<double>::max() << 50.;
  93. QTest::newRow("-inf") << 0. << 100. << -std::numeric_limits<double>::infinity() << 50.;
  94. QTest::newRow("inf") << 0. << 100. << std::numeric_limits<double>::infinity() << 50.;
  95. QTest::newRow("NaN") << 0. << 100. << std::numeric_limits<double>::quiet_NaN() << 50.;
  96. }
  97. // ----------------------------------------------------------------------------
  98. CTK_TEST_MAIN(ctkDoubleSliderTest)
  99. #include "moc_ctkDoubleSliderTest.cpp"