1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
41 #include <QtTest/QtTest>
42 #include <QtTest/QSignalSpy>
43 #include <QtQuick1/qdeclarativeview.h>
44 #include <QGraphicsObject>
47 // In Symbian OS test data is located in applications private dir
51 class tst_QDeclarativeParticles : public QObject
55 tst_QDeclarativeParticles();
63 QDeclarativeView *createView(const QString &filename);
67 tst_QDeclarativeParticles::tst_QDeclarativeParticles()
71 void tst_QDeclarativeParticles::properties()
73 QDeclarativeView *canvas = createView(SRCDIR "/data/particlestest.qml");
74 QVERIFY(canvas->rootObject());
76 QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
79 particles->setProperty("source", QUrl::fromLocalFile(SRCDIR "/data/particle.png"));
80 QCOMPARE(particles->property("source").toUrl(), QUrl::fromLocalFile(SRCDIR "/data/particle.png"));
82 particles->setProperty("lifeSpanDeviation", (1000));
83 QCOMPARE(particles->property("lifeSpanDeviation").toInt(), 1000);
85 particles->setProperty("fadeInDuration", 1000);
86 QCOMPARE(particles->property("fadeInDuration").toInt(), 1000);
88 particles->setProperty("fadeOutDuration", 1000);
89 QCOMPARE(particles->property("fadeOutDuration").toInt(), 1000);
91 particles->setProperty("angle", 100.0);
92 QCOMPARE(particles->property("angle").toDouble(), 100.0);
94 particles->setProperty("angleDeviation", 100.0);
95 QCOMPARE(particles->property("angleDeviation").toDouble(), 100.0);
97 particles->setProperty("velocity", 100.0);
98 QCOMPARE(particles->property("velocity").toDouble(), 100.0);
100 particles->setProperty("velocityDeviation", 100.0);
101 QCOMPARE(particles->property("velocityDeviation").toDouble(), 100.0);
103 particles->setProperty("emissionVariance", 0.5);
104 QCOMPARE(particles->property("emissionVariance").toDouble(),0.5);
106 particles->setProperty("emissionRate", 12);
107 QCOMPARE(particles->property("emissionRate").toInt(), 12);
112 void tst_QDeclarativeParticles::motionGravity()
114 QDeclarativeView *canvas = createView(SRCDIR "/data/particlemotiontest.qml");
115 QVERIFY(canvas->rootObject());
117 QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
120 QObject* motionGravity = canvas->rootObject()->findChild<QObject*>("motionGravity");
121 //QCOMPARE(qvariant_cast<QObject*>(particles->property("motion")), motionGravity);
123 QSignalSpy xattractorSpy(motionGravity, SIGNAL(xattractorChanged()));
124 QSignalSpy yattractorSpy(motionGravity, SIGNAL(yattractorChanged()));
125 QSignalSpy accelerationSpy(motionGravity, SIGNAL(accelerationChanged()));
127 QCOMPARE(motionGravity->property("xattractor").toDouble(), 0.0);
128 QCOMPARE(motionGravity->property("yattractor").toDouble(), 1000.0);
129 QCOMPARE(motionGravity->property("acceleration").toDouble(), 25.0);
131 motionGravity->setProperty("xattractor", 20.0);
132 motionGravity->setProperty("yattractor", 10.0);
133 motionGravity->setProperty("acceleration", 10.0);
135 QCOMPARE(motionGravity->property("xattractor").toDouble(), 20.0);
136 QCOMPARE(motionGravity->property("yattractor").toDouble(), 10.0);
137 QCOMPARE(motionGravity->property("acceleration").toDouble(), 10.0);
139 QCOMPARE(xattractorSpy.count(), 1);
140 QCOMPARE(yattractorSpy.count(), 1);
141 QCOMPARE(accelerationSpy.count(), 1);
143 motionGravity->setProperty("xattractor", 20.0);
144 motionGravity->setProperty("yattractor", 10.0);
145 motionGravity->setProperty("acceleration", 10.0);
147 QCOMPARE(xattractorSpy.count(), 1);
148 QCOMPARE(yattractorSpy.count(), 1);
149 QCOMPARE(accelerationSpy.count(), 1);
154 void tst_QDeclarativeParticles::motionWander()
156 QDeclarativeView *canvas = createView(SRCDIR "/data/particlemotiontest.qml");
157 QVERIFY(canvas->rootObject());
159 QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
162 QSignalSpy motionSpy(particles, SIGNAL(motionChanged()));
163 QObject* motionWander = canvas->rootObject()->findChild<QObject*>("motionWander");
165 QCOMPARE(motionSpy.count(), 0);
166 particles->setProperty("motion", QVariant::fromValue(motionWander));
167 //QCOMPARE(particles->property("motion"), QVariant::fromValue(motionWander));
168 //QCOMPARE(motionSpy.count(), 1);
170 particles->setProperty("motion", QVariant::fromValue(motionWander));
171 //QCOMPARE(motionSpy.count(), 1);
173 QSignalSpy xvarianceSpy(motionWander, SIGNAL(xvarianceChanged()));
174 QSignalSpy yvarianceSpy(motionWander, SIGNAL(yvarianceChanged()));
175 QSignalSpy paceSpy(motionWander, SIGNAL(paceChanged()));
177 QCOMPARE(motionWander->property("xvariance").toDouble(), 30.0);
178 QCOMPARE(motionWander->property("yvariance").toDouble(), 30.0);
179 QCOMPARE(motionWander->property("pace").toDouble(), 100.0);
181 motionWander->setProperty("xvariance", 20.0);
182 motionWander->setProperty("yvariance", 10.0);
183 motionWander->setProperty("pace", 10.0);
185 QCOMPARE(motionWander->property("xvariance").toDouble(), 20.0);
186 QCOMPARE(motionWander->property("yvariance").toDouble(), 10.0);
187 QCOMPARE(motionWander->property("pace").toDouble(), 10.0);
189 QCOMPARE(xvarianceSpy.count(), 1);
190 QCOMPARE(yvarianceSpy.count(), 1);
191 QCOMPARE(paceSpy.count(), 1);
193 QCOMPARE(motionWander->property("xvariance").toDouble(), 20.0);
194 QCOMPARE(motionWander->property("yvariance").toDouble(), 10.0);
195 QCOMPARE(motionWander->property("pace").toDouble(), 10.0);
197 QCOMPARE(xvarianceSpy.count(), 1);
198 QCOMPARE(yvarianceSpy.count(), 1);
199 QCOMPARE(paceSpy.count(), 1);
204 void tst_QDeclarativeParticles::runs()
206 QDeclarativeView *canvas = createView(SRCDIR "/data/particlestest.qml");
207 QVERIFY(canvas->rootObject());
209 QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
211 QTest::qWait(1000);//Run for one second. Test passes if it doesn't crash.
216 QDeclarativeView *tst_QDeclarativeParticles::createView(const QString &filename)
218 QDeclarativeView *canvas = new QDeclarativeView(0);
219 canvas->setFixedSize(240,320);
221 canvas->setSource(QUrl::fromLocalFile(filename));
225 QTEST_MAIN(tst_QDeclarativeParticles)
227 #include "tst_qdeclarativeparticles.moc"