tests/auto/qeasingcurve/tst_qeasingcurve.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 
       
    43 #include <QtTest/QtTest>
       
    44 
       
    45 #if QT_VERSION < 0x040200
       
    46 QTEST_NOOP_MAIN
       
    47 #else
       
    48 
       
    49 #include <qeasingcurve.h>
       
    50 
       
    51 //TESTED_CLASS=
       
    52 //TESTED_FILES=
       
    53 
       
    54 class tst_QEasingCurve : public QObject {
       
    55   Q_OBJECT
       
    56 
       
    57 public:
       
    58     tst_QEasingCurve();
       
    59     virtual ~tst_QEasingCurve();
       
    60 
       
    61 public Q_SLOTS:
       
    62     void init();
       
    63     void cleanup();
       
    64 
       
    65 private slots:
       
    66     void type();
       
    67     void propertyDefaults();
       
    68     void valueForProgress_data();
       
    69     void valueForProgress();
       
    70     void setCustomType();
       
    71     void operators();
       
    72 
       
    73 protected:
       
    74 };
       
    75 
       
    76 tst_QEasingCurve::tst_QEasingCurve()
       
    77 {
       
    78 }
       
    79 
       
    80 tst_QEasingCurve::~tst_QEasingCurve()
       
    81 {
       
    82 }
       
    83 
       
    84 void tst_QEasingCurve::init()
       
    85 {
       
    86 }
       
    87 
       
    88 void tst_QEasingCurve::cleanup()
       
    89 {
       
    90 }
       
    91 #include <qdebug.h>
       
    92 
       
    93 void tst_QEasingCurve::type()
       
    94 {
       
    95     {
       
    96     QEasingCurve curve(QEasingCurve::Linear);
       
    97     QCOMPARE(curve.period(), 0.3);
       
    98     QCOMPARE(curve.amplitude(), 1.0);
       
    99 
       
   100     curve.setPeriod(5);
       
   101     curve.setAmplitude(3);
       
   102     QCOMPARE(curve.period(), 5.0);
       
   103     QCOMPARE(curve.amplitude(), 3.0);
       
   104 
       
   105     curve.setType(QEasingCurve::InElastic);
       
   106     QCOMPARE(curve.period(), 5.0);
       
   107     QCOMPARE(curve.amplitude(), 3.0);
       
   108     }
       
   109 
       
   110     {
       
   111     QEasingCurve curve(QEasingCurve::InElastic);
       
   112     QCOMPARE(curve.period(), 0.3);
       
   113     QCOMPARE(curve.amplitude(), 1.0);
       
   114     curve.setAmplitude(2);
       
   115     QCOMPARE(curve.type(), QEasingCurve::InElastic);
       
   116     curve.setType(QEasingCurve::Linear);
       
   117     }
       
   118 
       
   119     {
       
   120     // check bounaries
       
   121     QEasingCurve curve(QEasingCurve::InCubic);
       
   122     QTest::ignoreMessage(QtWarningMsg, "QEasingCurve: Invalid curve type 9999");
       
   123     curve.setType((QEasingCurve::Type)9999);
       
   124     QCOMPARE(curve.type(), QEasingCurve::InCubic);
       
   125     QTest::ignoreMessage(QtWarningMsg, "QEasingCurve: Invalid curve type -9999");
       
   126     curve.setType((QEasingCurve::Type)-9999);
       
   127     QCOMPARE(curve.type(), QEasingCurve::InCubic);
       
   128     QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
       
   129                         .arg(QEasingCurve::NCurveTypes).toLatin1().constData());
       
   130     curve.setType(QEasingCurve::NCurveTypes);
       
   131     QCOMPARE(curve.type(), QEasingCurve::InCubic);
       
   132     QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
       
   133                         .arg(QEasingCurve::Custom).toLatin1().constData());
       
   134     curve.setType(QEasingCurve::Custom);
       
   135     QCOMPARE(curve.type(), QEasingCurve::InCubic);
       
   136     QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
       
   137                         .arg(-1).toLatin1().constData());
       
   138     curve.setType((QEasingCurve::Type)-1);
       
   139     QCOMPARE(curve.type(), QEasingCurve::InCubic);
       
   140     curve.setType(QEasingCurve::Linear);
       
   141     QCOMPARE(curve.type(), QEasingCurve::Linear);
       
   142     curve.setType(QEasingCurve::CosineCurve);
       
   143     QCOMPARE(curve.type(), QEasingCurve::CosineCurve);
       
   144     }
       
   145 }
       
   146 
       
   147 void tst_QEasingCurve::propertyDefaults()
       
   148 {
       
   149     {
       
   150     // checks if the defaults are correct, but also demonstrates a weakness with the API.
       
   151     QEasingCurve curve(QEasingCurve::InElastic);
       
   152     QCOMPARE(curve.period(), 0.3);
       
   153     QCOMPARE(curve.amplitude(), 1.0);
       
   154     QCOMPARE(curve.overshoot(), qreal(1.70158f));
       
   155     curve.setType(QEasingCurve::InBounce);
       
   156     QCOMPARE(curve.period(), 0.3);
       
   157     QCOMPARE(curve.amplitude(), 1.0);
       
   158     QCOMPARE(curve.overshoot(), qreal(1.70158f));
       
   159     curve.setType(QEasingCurve::Linear);
       
   160     QCOMPARE(curve.period(), 0.3);
       
   161     QCOMPARE(curve.amplitude(), 1.0);
       
   162     QCOMPARE(curve.overshoot(), qreal(1.70158f));
       
   163     curve.setType(QEasingCurve::InElastic);
       
   164     QCOMPARE(curve.period(), 0.3);
       
   165     QCOMPARE(curve.amplitude(), 1.0);
       
   166     QCOMPARE(curve.overshoot(), qreal(1.70158f));
       
   167     curve.setPeriod(0.4);
       
   168     curve.setAmplitude(0.6);
       
   169     curve.setOvershoot(1.0);
       
   170     curve.setType(QEasingCurve::Linear);
       
   171     QCOMPARE(curve.period(), 0.4);
       
   172     QCOMPARE(curve.amplitude(), 0.6);
       
   173     QCOMPARE(curve.overshoot(), 1.0);
       
   174     curve.setType(QEasingCurve::InElastic);
       
   175     QCOMPARE(curve.period(), 0.4);
       
   176     QCOMPARE(curve.amplitude(), 0.6);
       
   177     QCOMPARE(curve.overshoot(), 1.0);
       
   178     }
       
   179 }
       
   180 
       
   181 typedef QList<int> IntList;
       
   182 typedef QList<qreal> RealList;
       
   183 Q_DECLARE_METATYPE(IntList)
       
   184 Q_DECLARE_METATYPE(RealList)
       
   185 
       
   186 void tst_QEasingCurve::valueForProgress_data()
       
   187 {
       
   188     QTest::addColumn<int>("type");
       
   189     QTest::addColumn<IntList>("at");
       
   190     QTest::addColumn<RealList>("expected");
       
   191     // automatically generated.
       
   192     // note that values are scaled from range [0,1] to range [0, 100] in order to store them as
       
   193     // integer values and avoid fp inaccuracies
       
   194     QTest::newRow("Linear") << int(QEasingCurve::Linear)
       
   195          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   196          << (RealList() << 0 << 0.1 << 0.2 << 0.3 << 0.4 << 0.5 << 0.6 << 0.7 << 0.8 << 0.9 << 1);
       
   197 
       
   198     QTest::newRow("InQuad") << int(QEasingCurve::InQuad)
       
   199          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   200          << (RealList() << 0 << 0.01 << 0.04 << 0.09 << 0.16 << 0.25 << 0.36 << 0.49 << 0.64 << 0.81 << 1);
       
   201 
       
   202     QTest::newRow("OutQuad") << int(QEasingCurve::OutQuad)
       
   203          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   204          << (RealList() << 0 << 0.19 << 0.36 << 0.51 << 0.64 << 0.75 << 0.84 << 0.91 << 0.96 << 0.99 << 1);
       
   205 
       
   206     QTest::newRow("InOutQuad") << int(QEasingCurve::InOutQuad)
       
   207          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   208          << (RealList() << 0 << 0.02 << 0.08 << 0.18 << 0.32 << 0.5 << 0.68 << 0.82 << 0.92 << 0.98 << 1);
       
   209 
       
   210     QTest::newRow("OutInQuad") << int(QEasingCurve::OutInQuad)
       
   211          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   212          << (RealList() << 0 << 0.18 << 0.32 << 0.42 << 0.48 << 0.5 << 0.52 << 0.58 << 0.68 << 0.82 << 1);
       
   213 
       
   214     QTest::newRow("InCubic") << int(QEasingCurve::InCubic)
       
   215          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   216          << (RealList() << 0 << 0.001 << 0.008 << 0.027 << 0.064 << 0.125 << 0.216 << 0.343 << 0.512 << 0.729 << 1);
       
   217 
       
   218     QTest::newRow("OutCubic") << int(QEasingCurve::OutCubic)
       
   219          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   220          << (RealList() << 0 << 0.271 << 0.488 << 0.657 << 0.784 << 0.875 << 0.936 << 0.973 << 0.992 << 0.999 << 1);
       
   221 
       
   222     QTest::newRow("InOutCubic") << int(QEasingCurve::InOutCubic)
       
   223          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   224          << (RealList() << 0 << 0.004 << 0.032 << 0.108 << 0.256 << 0.5 << 0.744 << 0.892 << 0.968 << 0.996 << 1);
       
   225 
       
   226     QTest::newRow("OutInCubic") << int(QEasingCurve::OutInCubic)
       
   227          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   228          << (RealList() << 0 << 0.244 << 0.392 << 0.468 << 0.496 << 0.5 << 0.504 << 0.532 << 0.608 << 0.756 << 1);
       
   229 
       
   230     QTest::newRow("InQuart") << int(QEasingCurve::InQuart)
       
   231          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   232          << (RealList() << 0 << 0.0001 << 0.0016 << 0.0081 << 0.0256 << 0.0625 << 0.1296 << 0.2401 << 0.4096 << 0.6561 << 1);
       
   233 
       
   234     QTest::newRow("OutQuart") << int(QEasingCurve::OutQuart)
       
   235          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   236          << (RealList() << 0 << 0.3439 << 0.5904 << 0.7599 << 0.8704 << 0.9375 << 0.9744 << 0.9919 << 0.9984 << 0.9999 << 1);
       
   237 
       
   238     QTest::newRow("InOutQuart") << int(QEasingCurve::InOutQuart)
       
   239          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   240          << (RealList() << 0 << 0.0008 << 0.0128 << 0.0648 << 0.2048 << 0.5 << 0.7952 << 0.9352 << 0.9872 << 0.9992 << 1);
       
   241 
       
   242     QTest::newRow("OutInQuart") << int(QEasingCurve::OutInQuart)
       
   243          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   244          << (RealList() << 0 << 0.2952 << 0.4352 << 0.4872 << 0.4992 << 0.5 << 0.5008 << 0.5128 << 0.5648 << 0.7048 << 1);
       
   245 
       
   246     QTest::newRow("InQuint") << int(QEasingCurve::InQuint)
       
   247          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   248          << (RealList() << 0 << 1e-05 << 0.00032 << 0.00243 << 0.01024 << 0.03125 << 0.07776 << 0.1681 << 0.3277 << 0.5905 << 1);
       
   249 
       
   250     QTest::newRow("OutQuint") << int(QEasingCurve::OutQuint)
       
   251          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   252          << (RealList() << 0 << 0.4095 << 0.6723 << 0.8319 << 0.9222 << 0.9688 << 0.9898 << 0.9976 << 0.9997 << 1 << 1);
       
   253 
       
   254     QTest::newRow("InOutQuint") << int(QEasingCurve::InOutQuint)
       
   255          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   256          << (RealList() << 0 << 0.00016 << 0.00512 << 0.03888 << 0.1638 << 0.5 << 0.8362 << 0.9611 << 0.9949 << 0.9998 << 1);
       
   257 
       
   258     QTest::newRow("OutInQuint") << int(QEasingCurve::OutInQuint)
       
   259          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   260          << (RealList() << 0 << 0.3362 << 0.4611 << 0.4949 << 0.4998 << 0.5 << 0.5002 << 0.5051 << 0.5389 << 0.6638 << 1);
       
   261 
       
   262     QTest::newRow("InSine") << int(QEasingCurve::InSine)
       
   263          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   264          << (RealList() << 0 << 0.01231 << 0.04894 << 0.109 << 0.191 << 0.2929 << 0.4122 << 0.546 << 0.691 << 0.8436 << 1);
       
   265 
       
   266     QTest::newRow("OutSine") << int(QEasingCurve::OutSine)
       
   267          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   268          << (RealList() << 0 << 0.1564 << 0.309 << 0.454 << 0.5878 << 0.7071 << 0.809 << 0.891 << 0.9511 << 0.9877 << 1);
       
   269 
       
   270     QTest::newRow("InOutSine") << int(QEasingCurve::InOutSine)
       
   271          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   272          << (RealList() << 0 << 0.02447 << 0.09549 << 0.2061 << 0.3455 << 0.5 << 0.6545 << 0.7939 << 0.9045 << 0.9755 << 1);
       
   273 
       
   274     QTest::newRow("OutInSine") << int(QEasingCurve::OutInSine)
       
   275          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   276          << (RealList() << 0 << 0.1545 << 0.2939 << 0.4045 << 0.4755 << 0.5 << 0.5245 << 0.5955 << 0.7061 << 0.8455 << 1);
       
   277 
       
   278     QTest::newRow("InExpo") << int(QEasingCurve::InExpo)
       
   279          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   280          << (RealList() << 0 << 0.0009531 << 0.002906 << 0.006812 << 0.01462 << 0.03025 << 0.0615 << 0.124 << 0.249 << 0.499 << 1);
       
   281 
       
   282     QTest::newRow("OutExpo") << int(QEasingCurve::OutExpo)
       
   283          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   284          << (RealList() << 0 << 0.5005 << 0.7507 << 0.8759 << 0.9384 << 0.9697 << 0.9854 << 0.9932 << 0.9971 << 0.999 << 1);
       
   285 
       
   286     QTest::newRow("InOutExpo") << int(QEasingCurve::InOutExpo)
       
   287          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   288          << (RealList() << 0 << 0.001453 << 0.007312 << 0.03075 << 0.1245 << 0.5002 << 0.8754 << 0.9692 << 0.9927 << 0.9985 << 1);
       
   289 
       
   290     QTest::newRow("OutInExpo") << int(QEasingCurve::OutInExpo)
       
   291          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   292          << (RealList() << 0 << 0.3754 << 0.4692 << 0.4927 << 0.4985 << 0.5 << 0.5015 << 0.5073 << 0.5308 << 0.6245 << 1);
       
   293 
       
   294     QTest::newRow("InCirc") << int(QEasingCurve::InCirc)
       
   295          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   296          << (RealList() << 0 << 0.005013 << 0.0202 << 0.04606 << 0.08348 << 0.134 << 0.2 << 0.2859 << 0.4 << 0.5641 << 1);
       
   297 
       
   298     QTest::newRow("OutCirc") << int(QEasingCurve::OutCirc)
       
   299          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   300          << (RealList() << 0 << 0.4359 << 0.6 << 0.7141 << 0.8 << 0.866 << 0.9165 << 0.9539 << 0.9798 << 0.995 << 1);
       
   301 
       
   302     QTest::newRow("InOutCirc") << int(QEasingCurve::InOutCirc)
       
   303          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   304          << (RealList() << 0 << 0.0101 << 0.04174 << 0.1 << 0.2 << 0.5 << 0.8 << 0.9 << 0.9583 << 0.9899 << 1);
       
   305 
       
   306     QTest::newRow("OutInCirc") << int(QEasingCurve::OutInCirc)
       
   307          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   308          << (RealList() << 0 << 0.3 << 0.4 << 0.4583 << 0.4899 << 0.5 << 0.5101 << 0.5417 << 0.6 << 0.7 << 1);
       
   309 
       
   310     QTest::newRow("InElastic") << int(QEasingCurve::InElastic)
       
   311          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   312          << (RealList() << 0 << 0.001953 << -0.001953 << -0.003906 << 0.01562 << -0.01562 << -0.03125 << 0.125 << -0.125 << -0.25 << 1);
       
   313 
       
   314     QTest::newRow("OutElastic") << int(QEasingCurve::OutElastic)
       
   315          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   316          << (RealList() << 0 << 1.25 << 1.125 << 0.875 << 1.031 << 1.016 << 0.9844 << 1.004 << 1.002 << 0.998 << 1);
       
   317 
       
   318     QTest::newRow("InOutElastic") << int(QEasingCurve::InOutElastic)
       
   319          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   320          << (RealList() << 0 << -0.0009766 << 0.007812 << -0.01563 << -0.0625 << 0.5 << 1.062 << 1.016 << 0.9922 << 1.001 << 1);
       
   321 
       
   322     QTest::newRow("OutInElastic") << int(QEasingCurve::OutInElastic)
       
   323          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   324          << (RealList() << 0 << 0.375 << 0.5625 << 0.4922 << 0.498 << 0.5 << 0.4961 << 0.5078 << 0.5313 << 0.25 << 1);
       
   325 
       
   326     QTest::newRow("InBack") << int(QEasingCurve::InBack)
       
   327          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   328          << (RealList() << 0 << -0.01431 << -0.04645 << -0.0802 << -0.09935 << -0.0877 << -0.02903 << 0.09287 << 0.2942 << 0.5912 << 1);
       
   329 
       
   330     QTest::newRow("OutBack") << int(QEasingCurve::OutBack)
       
   331          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   332          << (RealList() << 0 << 0.4088 << 0.7058 << 0.9071 << 1.029 << 1.088 << 1.099 << 1.08 << 1.046 << 1.014 << 1);
       
   333 
       
   334     QTest::newRow("InOutBack") << int(QEasingCurve::InOutBack)
       
   335          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   336          << (RealList() << 0 << -0.03752 << -0.09256 << -0.07883 << 0.08993 << 0.5 << 0.9101 << 1.079 << 1.093 << 1.038 << 1);
       
   337 
       
   338     QTest::newRow("OutInBack") << int(QEasingCurve::OutInBack)
       
   339          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   340          << (RealList() << 0 << 0.3529 << 0.5145 << 0.5497 << 0.5232 << 0.5 << 0.4768 << 0.4503 << 0.4855 << 0.6471 << 1);
       
   341 
       
   342     QTest::newRow("InBounce") << int(QEasingCurve::InBounce)
       
   343          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   344          << (RealList() << 0 << 0.01188 << 0.06 << 0.06937 << 0.2275 << 0.2344 << 0.09 << 0.3194 << 0.6975 << 0.9244 << 1);
       
   345 
       
   346     QTest::newRow("OutBounce") << int(QEasingCurve::OutBounce)
       
   347          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   348          << (RealList() << 0 << 0.07563 << 0.3025 << 0.6806 << 0.91 << 0.7656 << 0.7725 << 0.9306 << 0.94 << 0.9881 << 1);
       
   349 
       
   350     QTest::newRow("InOutBounce") << int(QEasingCurve::InOutBounce)
       
   351          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   352          << (RealList() << 0 << 0.03 << 0.1138 << 0.045 << 0.3488 << 0.5 << 0.6512 << 0.955 << 0.8862 << 0.97 << 1);
       
   353 
       
   354     QTest::newRow("OutInBounce") << int(QEasingCurve::OutInBounce)
       
   355          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   356          << (RealList() << 0 << 0.1513 << 0.41 << 0.2725 << 0.44 << 0.5 << 0.56 << 0.7275 << 0.59 << 0.8488 << 1);
       
   357 
       
   358     QTest::newRow("InCurve") << int(QEasingCurve::InCurve)
       
   359          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   360          << (RealList() << 0 << 0.02447 << 0.1059 << 0.2343 << 0.3727 << 0.5 << 0.6055 << 0.7 << 0.8 << 0.9 << 1);
       
   361 
       
   362     QTest::newRow("OutCurve") << int(QEasingCurve::OutCurve)
       
   363          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   364          << (RealList() << 0 << 0.1 << 0.2 << 0.3 << 0.3945 << 0.5 << 0.6273 << 0.7657 << 0.8941 << 0.9755 << 1);
       
   365 
       
   366     QTest::newRow("SineCurve") << int(QEasingCurve::SineCurve)
       
   367          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   368          << (RealList() << 0 << 0.09549 << 0.3455 << 0.6545 << 0.9045 << 1 << 0.9045 << 0.6545 << 0.3455 << 0.09549 << 0);
       
   369 
       
   370     QTest::newRow("CosineCurve") << int(QEasingCurve::CosineCurve)
       
   371          << (IntList()  << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
       
   372          << (RealList() << 0.5 << 0.7939 << 0.9755 << 0.9755 << 0.7939 << 0.5 << 0.2061 << 0.02447 << 0.02447 << 0.2061 << 0.5);
       
   373 
       
   374 }
       
   375 
       
   376 
       
   377 void tst_QEasingCurve::valueForProgress()
       
   378 {
       
   379 #if 0
       
   380     // used to generate data tables...
       
   381     QFile out;
       
   382     out.open(stdout, QIODevice::WriteOnly);
       
   383     for (int c = QEasingCurve::Linear; c < QEasingCurve::NCurveTypes - 1; ++c) {
       
   384         QEasingCurve curve((QEasingCurve::Type)c);
       
   385         QMetaObject mo = QEasingCurve::staticMetaObject;
       
   386         QString strCurve = QLatin1String(mo.enumerator(mo.indexOfEnumerator("Type")).key(c));
       
   387         QString strInputs;
       
   388         QString strOutputs;
       
   389 
       
   390         for (int t = 0; t <= 100; t+= 10) {
       
   391             qreal ease = curve.valueForProgress(t/qreal(100));
       
   392             strInputs += QString::fromAscii(" << %1").arg(t);
       
   393             strOutputs += " << " + QString().setNum(ease, 'g', 4);
       
   394         }
       
   395         QString str = QString::fromAscii("    QTest::newRow(\"%1\") << int(QEasingCurve::%2)\n"
       
   396                                                 "         << (IntList() %3)\n"
       
   397                                                 "         << (RealList()%4);\n\n")
       
   398                                       .arg(strCurve)
       
   399                                       .arg(strCurve)
       
   400                                       .arg(strInputs)
       
   401                                       .arg(strOutputs);
       
   402         out.write(str.toLatin1().constData());
       
   403     }
       
   404     out.close();
       
   405     exit(1);
       
   406 #else
       
   407     QFETCH(int, type);
       
   408     QFETCH(IntList, at);
       
   409     QFETCH(RealList, expected);
       
   410 
       
   411     QEasingCurve curve((QEasingCurve::Type)type);
       
   412     for (int i = 0; i < at.count(); ++i) {
       
   413         qreal ease = curve.valueForProgress(at.at(i)/qreal(100));
       
   414         // converting ease to 4 precision qreal to match the generated samples
       
   415         qreal easeConv = qreal(QString().setNum(ease, 'g', 4).toDouble());
       
   416         qreal ex = expected.at(i);
       
   417 
       
   418         // the least significant digit it is still subject to rounding errors
       
   419         qreal error = easeConv - ex;
       
   420         qreal errorbound = 0.00001;                
       
   421 #if defined( Q_OS_WINCE ) || defined( Q_OS_SYMBIAN )
       
   422         // exception values for WINCE(this test should be rewritten, as it only freezes the status quo of QEasingCurve
       
   423         // The failing (2) values are explicitly excepted here:
       
   424         // The source values for the comparison table should remain untruncated double and the
       
   425         // error bound checking function dynamic. Also the source values should come from a "trusted" source and not
       
   426         // from QEasingCurve itself.        
       
   427         if ((type == int(QEasingCurve::InOutBounce) && (i == 8 || i == 6) ) || (type == int(QEasingCurve::OutExpo) && i == 2))
       
   428             errorbound = 0.0002;         
       
   429 #endif 
       
   430         // accept the potential rounding error in the least significant digit
       
   431         QVERIFY(error <= errorbound );          
       
   432     }
       
   433 #endif
       
   434 }
       
   435 
       
   436 static qreal discreteEase(qreal progress)
       
   437 {
       
   438     return qFloor(progress * 10) / qreal(10.0);
       
   439 }
       
   440 
       
   441 void tst_QEasingCurve::setCustomType()
       
   442 {
       
   443     QEasingCurve curve;
       
   444     curve.setCustomType(&discreteEase);
       
   445     QCOMPARE(curve.type(), QEasingCurve::Custom);
       
   446     QCOMPARE(curve.valueForProgress(0.0), 0.0);
       
   447     QCOMPARE(curve.valueForProgress(0.05), 0.0);
       
   448     QCOMPARE(curve.valueForProgress(0.10), 0.1);
       
   449     QCOMPARE(curve.valueForProgress(0.15), 0.1);
       
   450     QCOMPARE(curve.valueForProgress(0.20), 0.2);
       
   451     QCOMPARE(curve.valueForProgress(0.25), 0.2);
       
   452     QCOMPARE(curve.valueForProgress(0.30), 0.3);
       
   453     QCOMPARE(curve.valueForProgress(0.35), 0.3);
       
   454     QCOMPARE(curve.valueForProgress(0.999999), 0.9);
       
   455 
       
   456     curve.setType(QEasingCurve::Linear);
       
   457     QCOMPARE(curve.type(), QEasingCurve::Linear);
       
   458     QCOMPARE(curve.valueForProgress(0.0), 0.0);
       
   459     QCOMPARE(curve.valueForProgress(0.1), 0.1);
       
   460     QCOMPARE(curve.valueForProgress(0.5), 0.5);
       
   461     QCOMPARE(curve.valueForProgress(0.99), 0.99);
       
   462 }
       
   463 
       
   464 void tst_QEasingCurve::operators()
       
   465 {
       
   466     // operator=
       
   467     QEasingCurve curve;
       
   468     QEasingCurve curve2;
       
   469     curve.setCustomType(&discreteEase);
       
   470     curve2 = curve;
       
   471     QCOMPARE(curve2.type(), QEasingCurve::Custom);
       
   472     QCOMPARE(curve2.valueForProgress(0.0), 0.0);
       
   473     QCOMPARE(curve2.valueForProgress(0.05), 0.0);
       
   474     QCOMPARE(curve2.valueForProgress(0.15), 0.1);
       
   475     QCOMPARE(curve2.valueForProgress(0.25), 0.2);
       
   476     QCOMPARE(curve2.valueForProgress(0.35), 0.3);
       
   477     QCOMPARE(curve2.valueForProgress(0.999999), 0.9);
       
   478 
       
   479     // operator==
       
   480     curve.setType(QEasingCurve::InBack);
       
   481     curve2 = curve;
       
   482     curve2.setOvershoot(qreal(1.70158f));
       
   483     QCOMPARE(curve.overshoot(), curve2.overshoot());
       
   484     QVERIFY(curve2 == curve);
       
   485 
       
   486     curve.setOvershoot(3.0);
       
   487     QVERIFY(curve2 != curve);
       
   488     curve2.setOvershoot(3.0);
       
   489     QVERIFY(curve2 == curve);
       
   490 
       
   491     curve2.setType(QEasingCurve::Linear);
       
   492     QCOMPARE(curve.overshoot(), curve2.overshoot());
       
   493     QVERIFY(curve2 != curve);
       
   494     curve2.setType(QEasingCurve::InBack);
       
   495     QCOMPARE(curve.overshoot(), curve2.overshoot());
       
   496     QVERIFY(curve2 == curve);
       
   497 }
       
   498 
       
   499 
       
   500 QTEST_MAIN(tst_QEasingCurve)
       
   501 #include "tst_qeasingcurve.moc"
       
   502 
       
   503 #endif //QT_VERSION