| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 | /*=========================================================================  Library:   CTK  Copyright (c) Kitware Inc.   All rights reserved.  Distributed under a BSD License. See LICENSE.txt file.  This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the above copyright notice for more information.=========================================================================*/// Qt includes#include <QApplication>#include <QString>// CTK includes#include "ctkDoubleSlider.h"// STD includes#include <cstdlib>#include <iostream>//-----------------------------------------------------------------------------int ctkDoubleSliderTest1(int argc, char * argv [] ){  QApplication app(argc, argv);  ctkDoubleSlider slider;  std::cout << "Test setValue(18.54)" << std::endl;  slider.setValue(18.54);  if (!qFuzzyCompare(slider.value(), 18.54))    {    std::cerr << "ctkDoubleSlider::setValue failed." << slider.value() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test setMinimum(5.21)" << std::endl;  slider.setMinimum(5.21);  if (!qFuzzyCompare(slider.minimum(), 5.21) ||      !qFuzzyCompare(slider.value(),18.54))    {    std::cerr << "ctkDoubleSlider::setMinimum failed." << slider.value() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test setMaximum(1340.2)" << std::endl;  slider.setMaximum(1340.2);  if (!qFuzzyCompare(slider.maximum(), 1340.2) ||      !qFuzzyCompare(slider.value(), 18.54))    {    std::cerr << "ctkDoubleSlider::setMinimum failed." << slider.value() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test setSingleStep(0.15)" << std::endl;  slider.setSingleStep(0.15);  if (!qFuzzyCompare(slider.singleStep(), 0.15) ||      !qFuzzyCompare(slider.value(), 18.54) ||      !qFuzzyCompare(slider.sliderPosition(), 18.54))    {    std::cerr << "ctkDoubleSlider::setSingleStep failed."              << "Step:" << slider.singleStep()               << " Val:" << slider.value()               << " Pos:" << slider.sliderPosition() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test setSingleStep(0.33)" << std::endl;  slider.setSingleStep(0.33);  if (!qFuzzyCompare(slider.singleStep(), 0.33) ||      !qFuzzyCompare(slider.value(), 18.54) ||      !qFuzzyCompare(slider.sliderPosition(), 18.54))    {    std::cerr << "ctkDoubleSlider::setSingleStep failed."              << slider.value() << " "               << slider.sliderPosition() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test Step Add" << std::endl;  slider.triggerAction (QAbstractSlider::SliderSingleStepAdd);  if (!qFuzzyCompare(slider.value(), 18.87))    {    std::cerr << "ctkDoubleSlider:: Step Add failed" << slider.value() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test Step Sub" << std::endl;  slider.triggerAction (QAbstractSlider::SliderSingleStepSub);  if (!qFuzzyCompare(slider.value(), 18.54))    {    std::cerr << "ctkDoubleSlider:: Step Sub failed" << slider.value() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test setMaximum" << std::endl;  slider.setMaximum(15.08);  if (!qFuzzyCompare(slider.maximum(), 15.08) ||      !qFuzzyCompare(slider.value(), 15.08))    {    std::cerr << "ctkDoubleSlider:: setMaximum failed" << slider.value() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test setMaximum" << std::endl;  slider.setMaximum(5100000.333333);  if (!qFuzzyCompare(slider.maximum(), 5100000.333333) ||      !qFuzzyCompare(slider.value(), 15.08))    {    std::cerr << "ctkDoubleSlider:: setMaximum failed" << slider.value() << std::endl;    return EXIT_FAILURE;    }      std::cout << "Test setValue close to previous value" << std::endl;  slider.setValue(15.081);  if (!qFuzzyCompare(slider.value(), 15.081))    {    std::cerr << "ctkDoubleSlider:: setValue failed" << slider.value() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test setSingleStep" << std::endl;  slider.setSingleStep(1.);  if (!qFuzzyCompare(slider.value(),15.081) ||       !qFuzzyCompare(slider.sliderPosition(), 15.081))    {    std::cerr << "ctkDoubleSlider:: setSingleStep failed: val" << slider.value() << " pos:" << slider.sliderPosition() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test setSingleStep " << std::endl;  slider.setSingleStep(0.01);  if (!qFuzzyCompare(slider.value(),15.081) ||       !qFuzzyCompare(slider.sliderPosition(), 15.081))    {    std::cerr << "ctkDoubleSlider:: setSingleStep failed: val" << slider.value() << " pos:" << slider.sliderPosition() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test reach max" << std::endl;  slider.setMaximum(510.333333);  slider.setValue(1000);  if (!qFuzzyCompare(slider.maximum(), 510.333333) ||      !qFuzzyCompare(slider.value(), 510.333333))    {    std::cerr << "ctkDoubleSlider::setValue(1000) failed"              << " val:" << slider.value()               << " pos: " << slider.sliderPosition() << std::endl;    return EXIT_FAILURE;    }  std::cout << "Test change range" << std::endl;  slider.setRange(-500.1, 10.21);  if (!qFuzzyCompare(slider.maximum(), 10.21) ||      !qFuzzyCompare(slider.value(), 10.21) ||      !qFuzzyCompare(slider.sliderPosition(), 10.21))    {    std::cerr << "ctkDoubleSlider::setRange(-400.2, 10.21) failed"              << " val:" << slider.value()               << " pos: " << slider.sliderPosition() << std::endl;    return EXIT_FAILURE;    }  slider.setSingleStep(0.15);  if (!qFuzzyCompare(slider.value(), 10.21) ||      !qFuzzyCompare(slider.sliderPosition(), 10.21))    {    std::cerr << "ctkDoubleSlider::setSingleStep(0.15) failed"              << " val:" << slider.value()               << " pos: " << slider.sliderPosition() << std::endl;    return EXIT_FAILURE;    }  // FIXME   // slider.setSliderPosition(10.3333);  // if (!qFuzzyCompare(slider.value(), 10.3333) ||  //     !qFuzzyCompare(slider.sliderPosition(), 10.3333))  //   {  //   std::cerr << "ctkDoubleSlider::setSliderPosition(10.3333) failed"  //             << " val:" << slider.value()   //             << " pos: " << slider.sliderPosition() << std::endl;  //   return EXIT_FAILURE;  //   }  // slider.setTracking(false);  // slider.setSliderPosition(10.123456789);  // if (!qFuzzyCompare(slider.value(), 10.3333) ||  //     !qFuzzyCompare(slider.sliderPosition(), 10.123456789))  //   {  //   std::cerr << "ctkDoubleSlider::setSliderPosition(10.123456789) failed"  //             << " val:" << slider.value()   //             << " pos: " << slider.sliderPosition() << std::endl;  //   return EXIT_FAILURE;  //   }  return EXIT_SUCCESS;}
 |