1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
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>
46 class tst_QDeclarativeParticles : public QObject
50 tst_QDeclarativeParticles();
58 QDeclarativeView *createView(const QString &filename);
62 tst_QDeclarativeParticles::tst_QDeclarativeParticles()
66 void tst_QDeclarativeParticles::properties()
68 QDeclarativeView *canvas = createView(SRCDIR "/data/particlestest.qml");
69 QVERIFY(canvas->rootObject());
71 QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
74 particles->setProperty("source", QUrl::fromLocalFile(SRCDIR "/data/particle.png"));
75 QCOMPARE(particles->property("source").toUrl(), QUrl::fromLocalFile(SRCDIR "/data/particle.png"));
77 particles->setProperty("lifeSpanDeviation", (1000));
78 QCOMPARE(particles->property("lifeSpanDeviation").toInt(), 1000);
80 particles->setProperty("fadeInDuration", 1000);
81 QCOMPARE(particles->property("fadeInDuration").toInt(), 1000);
83 particles->setProperty("fadeOutDuration", 1000);
84 QCOMPARE(particles->property("fadeOutDuration").toInt(), 1000);
86 particles->setProperty("angle", 100.0);
87 QCOMPARE(particles->property("angle").toDouble(), 100.0);
89 particles->setProperty("angleDeviation", 100.0);
90 QCOMPARE(particles->property("angleDeviation").toDouble(), 100.0);
92 particles->setProperty("velocity", 100.0);
93 QCOMPARE(particles->property("velocity").toDouble(), 100.0);
95 particles->setProperty("velocityDeviation", 100.0);
96 QCOMPARE(particles->property("velocityDeviation").toDouble(), 100.0);
98 particles->setProperty("emissionVariance", 0.5);
99 QCOMPARE(particles->property("emissionVariance").toDouble(),0.5);
101 particles->setProperty("emissionRate", 12);
102 QCOMPARE(particles->property("emissionRate").toInt(), 12);
107 void tst_QDeclarativeParticles::motionGravity()
109 QDeclarativeView *canvas = createView(SRCDIR "/data/particlemotiontest.qml");
110 QVERIFY(canvas->rootObject());
112 QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
115 QObject* motionGravity = canvas->rootObject()->findChild<QObject*>("motionGravity");
116 //QCOMPARE(qvariant_cast<QObject*>(particles->property("motion")), motionGravity);
118 QSignalSpy xattractorSpy(motionGravity, SIGNAL(xattractorChanged()));
119 QSignalSpy yattractorSpy(motionGravity, SIGNAL(yattractorChanged()));
120 QSignalSpy accelerationSpy(motionGravity, SIGNAL(accelerationChanged()));
122 QCOMPARE(motionGravity->property("xattractor").toDouble(), 0.0);
123 QCOMPARE(motionGravity->property("yattractor").toDouble(), 1000.0);
124 QCOMPARE(motionGravity->property("acceleration").toDouble(), 25.0);
126 motionGravity->setProperty("xattractor", 20.0);
127 motionGravity->setProperty("yattractor", 10.0);
128 motionGravity->setProperty("acceleration", 10.0);
130 QCOMPARE(motionGravity->property("xattractor").toDouble(), 20.0);
131 QCOMPARE(motionGravity->property("yattractor").toDouble(), 10.0);
132 QCOMPARE(motionGravity->property("acceleration").toDouble(), 10.0);
134 QCOMPARE(xattractorSpy.count(), 1);
135 QCOMPARE(yattractorSpy.count(), 1);
136 QCOMPARE(accelerationSpy.count(), 1);
138 motionGravity->setProperty("xattractor", 20.0);
139 motionGravity->setProperty("yattractor", 10.0);
140 motionGravity->setProperty("acceleration", 10.0);
142 QCOMPARE(xattractorSpy.count(), 1);
143 QCOMPARE(yattractorSpy.count(), 1);
144 QCOMPARE(accelerationSpy.count(), 1);
149 void tst_QDeclarativeParticles::motionWander()
151 QDeclarativeView *canvas = createView(SRCDIR "/data/particlemotiontest.qml");
152 QVERIFY(canvas->rootObject());
154 QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
157 QSignalSpy motionSpy(particles, SIGNAL(motionChanged()));
158 QObject* motionWander = canvas->rootObject()->findChild<QObject*>("motionWander");
160 QCOMPARE(motionSpy.count(), 0);
161 particles->setProperty("motion", QVariant::fromValue(motionWander));
162 //QCOMPARE(particles->property("motion"), QVariant::fromValue(motionWander));
163 //QCOMPARE(motionSpy.count(), 1);
165 particles->setProperty("motion", QVariant::fromValue(motionWander));
166 //QCOMPARE(motionSpy.count(), 1);
168 QSignalSpy xvarianceSpy(motionWander, SIGNAL(xvarianceChanged()));
169 QSignalSpy yvarianceSpy(motionWander, SIGNAL(yvarianceChanged()));
170 QSignalSpy paceSpy(motionWander, SIGNAL(paceChanged()));
172 QCOMPARE(motionWander->property("xvariance").toDouble(), 30.0);
173 QCOMPARE(motionWander->property("yvariance").toDouble(), 30.0);
174 QCOMPARE(motionWander->property("pace").toDouble(), 100.0);
176 motionWander->setProperty("xvariance", 20.0);
177 motionWander->setProperty("yvariance", 10.0);
178 motionWander->setProperty("pace", 10.0);
180 QCOMPARE(motionWander->property("xvariance").toDouble(), 20.0);
181 QCOMPARE(motionWander->property("yvariance").toDouble(), 10.0);
182 QCOMPARE(motionWander->property("pace").toDouble(), 10.0);
184 QCOMPARE(xvarianceSpy.count(), 1);
185 QCOMPARE(yvarianceSpy.count(), 1);
186 QCOMPARE(paceSpy.count(), 1);
188 QCOMPARE(motionWander->property("xvariance").toDouble(), 20.0);
189 QCOMPARE(motionWander->property("yvariance").toDouble(), 10.0);
190 QCOMPARE(motionWander->property("pace").toDouble(), 10.0);
192 QCOMPARE(xvarianceSpy.count(), 1);
193 QCOMPARE(yvarianceSpy.count(), 1);
194 QCOMPARE(paceSpy.count(), 1);
199 void tst_QDeclarativeParticles::runs()
201 QDeclarativeView *canvas = createView(SRCDIR "/data/particlestest.qml");
202 QVERIFY(canvas->rootObject());
204 QObject* particles = canvas->rootObject()->findChild<QObject*>("particles");
206 QTest::qWait(1000);//Run for one second. Test passes if it doesn't crash.
211 QDeclarativeView *tst_QDeclarativeParticles::createView(const QString &filename)
213 QDeclarativeView *canvas = new QDeclarativeView(0);
214 canvas->setFixedSize(240,320);
216 canvas->setSource(QUrl::fromLocalFile(filename));
220 QTEST_MAIN(tst_QDeclarativeParticles)
222 #include "tst_qdeclarativeparticles.moc"