tests/auto/declarative/qdeclarativeparticles/tst_qdeclarativeparticles.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 #include <QtTest/QtTest>
       
    42 #include <QtTest/QSignalSpy>
       
    43 #include <qdeclarativeview.h>
       
    44 #include <QGraphicsObject>
       
    45 
       
    46 class tst_QDeclarativeParticles : public QObject
       
    47 {
       
    48     Q_OBJECT
       
    49 public:
       
    50     tst_QDeclarativeParticles();
       
    51 
       
    52 private slots:
       
    53     void properties();
       
    54     void motionGravity();
       
    55     void motionWander();
       
    56     void runs();
       
    57 private:
       
    58     QDeclarativeView *createView(const QString &filename);
       
    59 
       
    60 };
       
    61 
       
    62 tst_QDeclarativeParticles::tst_QDeclarativeParticles()
       
    63 {
       
    64 }
       
    65 
       
    66 void tst_QDeclarativeParticles::properties()
       
    67 {
       
    68     QDeclarativeView *canvas = createView(SRCDIR "/data/particlestest.qml");
       
    69     QVERIFY(canvas->rootObject());
       
    70 
       
    71     QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
       
    72     QVERIFY(particles);
       
    73 
       
    74     particles->setProperty("source", QUrl::fromLocalFile(SRCDIR "/data/particle.png"));
       
    75     QCOMPARE(particles->property("source").toUrl(), QUrl::fromLocalFile(SRCDIR "/data/particle.png"));
       
    76 
       
    77     particles->setProperty("lifeSpanDeviation", (1000));
       
    78     QCOMPARE(particles->property("lifeSpanDeviation").toInt(), 1000);
       
    79 
       
    80     particles->setProperty("fadeInDuration", 1000);
       
    81     QCOMPARE(particles->property("fadeInDuration").toInt(), 1000);
       
    82 
       
    83     particles->setProperty("fadeOutDuration", 1000);
       
    84     QCOMPARE(particles->property("fadeOutDuration").toInt(), 1000);
       
    85 
       
    86     particles->setProperty("angle", 100.0);
       
    87     QCOMPARE(particles->property("angle").toDouble(), 100.0);
       
    88 
       
    89     particles->setProperty("angleDeviation", 100.0);
       
    90     QCOMPARE(particles->property("angleDeviation").toDouble(), 100.0);
       
    91 
       
    92     particles->setProperty("velocity", 100.0);
       
    93     QCOMPARE(particles->property("velocity").toDouble(), 100.0);
       
    94 
       
    95     particles->setProperty("velocityDeviation", 100.0);
       
    96     QCOMPARE(particles->property("velocityDeviation").toDouble(), 100.0);
       
    97 
       
    98     particles->setProperty("emissionVariance", 0.5);
       
    99     QCOMPARE(particles->property("emissionVariance").toDouble(),0.5);
       
   100 
       
   101     particles->setProperty("emissionRate", 12);
       
   102     QCOMPARE(particles->property("emissionRate").toInt(), 12);
       
   103 }
       
   104 
       
   105 void tst_QDeclarativeParticles::motionGravity()
       
   106 {
       
   107     QDeclarativeView *canvas = createView(SRCDIR "/data/particlemotiontest.qml");
       
   108     QVERIFY(canvas->rootObject());
       
   109 
       
   110     QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
       
   111     QVERIFY(particles);
       
   112 
       
   113     QObject* motionGravity = canvas->rootObject()->findChild<QObject*>("motionGravity");
       
   114     //QCOMPARE(qvariant_cast<QObject*>(particles->property("motion")), motionGravity);
       
   115 
       
   116     QSignalSpy xattractorSpy(motionGravity, SIGNAL(xattractorChanged()));
       
   117     QSignalSpy yattractorSpy(motionGravity, SIGNAL(yattractorChanged()));
       
   118     QSignalSpy accelerationSpy(motionGravity, SIGNAL(accelerationChanged()));
       
   119 
       
   120     QCOMPARE(motionGravity->property("xattractor").toDouble(), 0.0);
       
   121     QCOMPARE(motionGravity->property("yattractor").toDouble(), 1000.0);
       
   122     QCOMPARE(motionGravity->property("acceleration").toDouble(), 25.0);
       
   123 
       
   124     motionGravity->setProperty("xattractor", 20.0);
       
   125     motionGravity->setProperty("yattractor", 10.0);
       
   126     motionGravity->setProperty("acceleration", 10.0);
       
   127 
       
   128     QCOMPARE(motionGravity->property("xattractor").toDouble(), 20.0);
       
   129     QCOMPARE(motionGravity->property("yattractor").toDouble(), 10.0);
       
   130     QCOMPARE(motionGravity->property("acceleration").toDouble(), 10.0);
       
   131 
       
   132     QCOMPARE(xattractorSpy.count(), 1);
       
   133     QCOMPARE(yattractorSpy.count(), 1);
       
   134     QCOMPARE(accelerationSpy.count(), 1);
       
   135 
       
   136     motionGravity->setProperty("xattractor", 20.0);
       
   137     motionGravity->setProperty("yattractor", 10.0);
       
   138     motionGravity->setProperty("acceleration", 10.0);
       
   139 
       
   140     QCOMPARE(xattractorSpy.count(), 1);
       
   141     QCOMPARE(yattractorSpy.count(), 1);
       
   142     QCOMPARE(accelerationSpy.count(), 1);
       
   143 }
       
   144 
       
   145 void tst_QDeclarativeParticles::motionWander()
       
   146 {
       
   147     QDeclarativeView *canvas = createView(SRCDIR "/data/particlemotiontest.qml");
       
   148     QVERIFY(canvas->rootObject());
       
   149 
       
   150     QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
       
   151     QVERIFY(particles);
       
   152 
       
   153     QSignalSpy motionSpy(particles, SIGNAL(motionChanged()));
       
   154     QObject* motionWander = canvas->rootObject()->findChild<QObject*>("motionWander");
       
   155 
       
   156     QCOMPARE(motionSpy.count(), 0);
       
   157     particles->setProperty("motion", QVariant::fromValue(motionWander));
       
   158     //QCOMPARE(particles->property("motion"), QVariant::fromValue(motionWander));
       
   159     //QCOMPARE(motionSpy.count(), 1);
       
   160 
       
   161     particles->setProperty("motion", QVariant::fromValue(motionWander));
       
   162     //QCOMPARE(motionSpy.count(), 1);
       
   163 
       
   164     QSignalSpy xvarianceSpy(motionWander, SIGNAL(xvarianceChanged()));
       
   165     QSignalSpy yvarianceSpy(motionWander, SIGNAL(yvarianceChanged()));
       
   166     QSignalSpy paceSpy(motionWander, SIGNAL(paceChanged()));
       
   167 
       
   168     QCOMPARE(motionWander->property("xvariance").toDouble(), 30.0);
       
   169     QCOMPARE(motionWander->property("yvariance").toDouble(), 30.0);
       
   170     QCOMPARE(motionWander->property("pace").toDouble(), 100.0);
       
   171 
       
   172     motionWander->setProperty("xvariance", 20.0);
       
   173     motionWander->setProperty("yvariance", 10.0);
       
   174     motionWander->setProperty("pace", 10.0);
       
   175 
       
   176     QCOMPARE(motionWander->property("xvariance").toDouble(), 20.0);
       
   177     QCOMPARE(motionWander->property("yvariance").toDouble(), 10.0);
       
   178     QCOMPARE(motionWander->property("pace").toDouble(), 10.0);
       
   179 
       
   180     QCOMPARE(xvarianceSpy.count(), 1);
       
   181     QCOMPARE(yvarianceSpy.count(), 1);
       
   182     QCOMPARE(paceSpy.count(), 1);
       
   183 
       
   184     QCOMPARE(motionWander->property("xvariance").toDouble(), 20.0);
       
   185     QCOMPARE(motionWander->property("yvariance").toDouble(), 10.0);
       
   186     QCOMPARE(motionWander->property("pace").toDouble(), 10.0);
       
   187 
       
   188     QCOMPARE(xvarianceSpy.count(), 1);
       
   189     QCOMPARE(yvarianceSpy.count(), 1);
       
   190     QCOMPARE(paceSpy.count(), 1);
       
   191 }
       
   192 
       
   193 void tst_QDeclarativeParticles::runs()
       
   194 {
       
   195     QDeclarativeView *canvas = createView(SRCDIR "/data/particlestest.qml");
       
   196     QVERIFY(canvas->rootObject());
       
   197 
       
   198     QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
       
   199     QVERIFY(particles);
       
   200     QTest::qWait(1000);//Run for one second. Test passes if it doesn't crash.
       
   201 }
       
   202 
       
   203 QDeclarativeView *tst_QDeclarativeParticles::createView(const QString &filename)
       
   204 {
       
   205     QDeclarativeView *canvas = new QDeclarativeView(0);
       
   206     canvas->setFixedSize(240,320);
       
   207 
       
   208     canvas->setSource(QUrl::fromLocalFile(filename));
       
   209 
       
   210     return canvas;
       
   211 }
       
   212 QTEST_MAIN(tst_QDeclarativeParticles)
       
   213 
       
   214 #include "tst_qdeclarativeparticles.moc"