ctkDoubleSliderTest1.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. // Qt includes
  11. #include <QApplication>
  12. #include <QString>
  13. // CTK includes
  14. #include "ctkDoubleSlider.h"
  15. // STD includes
  16. #include <cstdlib>
  17. #include <iostream>
  18. //-----------------------------------------------------------------------------
  19. int ctkDoubleSliderTest1(int argc, char * argv [] )
  20. {
  21. QApplication app(argc, argv);
  22. ctkDoubleSlider slider;
  23. std::cout << "Test setValue(18.54)" << std::endl;
  24. slider.setValue(18.54);
  25. if (!qFuzzyCompare(slider.value(), 18.54))
  26. {
  27. std::cerr << "ctkDoubleSlider::setValue failed." << slider.value() << std::endl;
  28. return EXIT_FAILURE;
  29. }
  30. std::cout << "Test setMinimum(5.21)" << std::endl;
  31. slider.setMinimum(5.21);
  32. if (!qFuzzyCompare(slider.minimum(), 5.21) ||
  33. !qFuzzyCompare(slider.value(),18.54))
  34. {
  35. std::cerr << "ctkDoubleSlider::setMinimum failed." << slider.value() << std::endl;
  36. return EXIT_FAILURE;
  37. }
  38. std::cout << "Test setMaximum(1340.2)" << std::endl;
  39. slider.setMaximum(1340.2);
  40. if (!qFuzzyCompare(slider.maximum(), 1340.2) ||
  41. !qFuzzyCompare(slider.value(), 18.54))
  42. {
  43. std::cerr << "ctkDoubleSlider::setMinimum failed." << slider.value() << std::endl;
  44. return EXIT_FAILURE;
  45. }
  46. std::cout << "Test setSingleStep(0.15)" << std::endl;
  47. slider.setSingleStep(0.15);
  48. if (!qFuzzyCompare(slider.singleStep(), 0.15) ||
  49. !qFuzzyCompare(slider.value(), 18.54) ||
  50. !qFuzzyCompare(slider.sliderPosition(), 18.54))
  51. {
  52. std::cerr << "ctkDoubleSlider::setSingleStep failed."
  53. << "Step:" << slider.singleStep()
  54. << " Val:" << slider.value()
  55. << " Pos:" << slider.sliderPosition() << std::endl;
  56. return EXIT_FAILURE;
  57. }
  58. std::cout << "Test setSingleStep(0.33)" << std::endl;
  59. slider.setSingleStep(0.33);
  60. if (!qFuzzyCompare(slider.singleStep(), 0.33) ||
  61. !qFuzzyCompare(slider.value(), 18.54) ||
  62. !qFuzzyCompare(slider.sliderPosition(), 18.54))
  63. {
  64. std::cerr << "ctkDoubleSlider::setSingleStep failed."
  65. << slider.value() << " "
  66. << slider.sliderPosition() << std::endl;
  67. return EXIT_FAILURE;
  68. }
  69. std::cout << "Test Step Add" << std::endl;
  70. slider.triggerAction (QAbstractSlider::SliderSingleStepAdd);
  71. if (!qFuzzyCompare(slider.value(), 18.87))
  72. {
  73. std::cerr << "ctkDoubleSlider:: Step Add failed" << slider.value() << std::endl;
  74. return EXIT_FAILURE;
  75. }
  76. std::cout << "Test Step Sub" << std::endl;
  77. slider.triggerAction (QAbstractSlider::SliderSingleStepSub);
  78. if (!qFuzzyCompare(slider.value(), 18.54))
  79. {
  80. std::cerr << "ctkDoubleSlider:: Step Sub failed" << slider.value() << std::endl;
  81. return EXIT_FAILURE;
  82. }
  83. std::cout << "Test setMaximum" << std::endl;
  84. slider.setMaximum(15.08);
  85. if (!qFuzzyCompare(slider.maximum(), 15.08) ||
  86. !qFuzzyCompare(slider.value(), 15.08))
  87. {
  88. std::cerr << "ctkDoubleSlider:: setMaximum failed" << slider.value() << std::endl;
  89. return EXIT_FAILURE;
  90. }
  91. std::cout << "Test setMaximum" << std::endl;
  92. slider.setMaximum(5100000.333333);
  93. if (!qFuzzyCompare(slider.maximum(), 5100000.333333) ||
  94. !qFuzzyCompare(slider.value(), 15.08))
  95. {
  96. std::cerr << "ctkDoubleSlider:: setMaximum failed" << slider.value() << std::endl;
  97. return EXIT_FAILURE;
  98. }
  99. std::cout << "Test setValue close to previous value" << std::endl;
  100. slider.setValue(15.081);
  101. if (!qFuzzyCompare(slider.value(), 15.081))
  102. {
  103. std::cerr << "ctkDoubleSlider:: setValue failed" << slider.value() << std::endl;
  104. return EXIT_FAILURE;
  105. }
  106. std::cout << "Test setSingleStep" << std::endl;
  107. slider.setSingleStep(1.);
  108. if (!qFuzzyCompare(slider.value(),15.081) ||
  109. !qFuzzyCompare(slider.sliderPosition(), 15.081))
  110. {
  111. std::cerr << "ctkDoubleSlider:: setSingleStep failed: val" << slider.value() << " pos:" << slider.sliderPosition() << std::endl;
  112. return EXIT_FAILURE;
  113. }
  114. std::cout << "Test setSingleStep " << std::endl;
  115. slider.setSingleStep(0.01);
  116. if (!qFuzzyCompare(slider.value(),15.081) ||
  117. !qFuzzyCompare(slider.sliderPosition(), 15.081))
  118. {
  119. std::cerr << "ctkDoubleSlider:: setSingleStep failed: val" << slider.value() << " pos:" << slider.sliderPosition() << std::endl;
  120. return EXIT_FAILURE;
  121. }
  122. std::cout << "Test reach max" << std::endl;
  123. slider.setMaximum(510.333333);
  124. slider.setValue(1000);
  125. if (!qFuzzyCompare(slider.maximum(), 510.333333) ||
  126. !qFuzzyCompare(slider.value(), 510.333333))
  127. {
  128. std::cerr << "ctkDoubleSlider::setValue(1000) failed"
  129. << " val:" << slider.value()
  130. << " pos: " << slider.sliderPosition() << std::endl;
  131. return EXIT_FAILURE;
  132. }
  133. std::cout << "Test change range" << std::endl;
  134. slider.setRange(-500.1, 10.21);
  135. if (!qFuzzyCompare(slider.maximum(), 10.21) ||
  136. !qFuzzyCompare(slider.value(), 10.21) ||
  137. !qFuzzyCompare(slider.sliderPosition(), 10.21))
  138. {
  139. std::cerr << "ctkDoubleSlider::setRange(-400.2, 10.21) failed"
  140. << " val:" << slider.value()
  141. << " pos: " << slider.sliderPosition() << std::endl;
  142. return EXIT_FAILURE;
  143. }
  144. slider.setSingleStep(0.15);
  145. if (!qFuzzyCompare(slider.value(), 10.21) ||
  146. !qFuzzyCompare(slider.sliderPosition(), 10.21))
  147. {
  148. std::cerr << "ctkDoubleSlider::setSingleStep(0.15) failed"
  149. << " val:" << slider.value()
  150. << " pos: " << slider.sliderPosition() << std::endl;
  151. return EXIT_FAILURE;
  152. }
  153. // FIXME
  154. // slider.setSliderPosition(10.3333);
  155. // if (!qFuzzyCompare(slider.value(), 10.3333) ||
  156. // !qFuzzyCompare(slider.sliderPosition(), 10.3333))
  157. // {
  158. // std::cerr << "ctkDoubleSlider::setSliderPosition(10.3333) failed"
  159. // << " val:" << slider.value()
  160. // << " pos: " << slider.sliderPosition() << std::endl;
  161. // return EXIT_FAILURE;
  162. // }
  163. // slider.setTracking(false);
  164. // slider.setSliderPosition(10.123456789);
  165. // if (!qFuzzyCompare(slider.value(), 10.3333) ||
  166. // !qFuzzyCompare(slider.sliderPosition(), 10.123456789))
  167. // {
  168. // std::cerr << "ctkDoubleSlider::setSliderPosition(10.123456789) failed"
  169. // << " val:" << slider.value()
  170. // << " pos: " << slider.sliderPosition() << std::endl;
  171. // return EXIT_FAILURE;
  172. // }
  173. return EXIT_SUCCESS;
  174. }