1 /****************************************************************************
3 ** Copyright (C) 2012 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 ****************************************************************************/
42 #include <QtTest/QtTest>
43 #include "../shared/particlestestsshared.h"
44 #include <private/qquickparticlesystem_p.h>
45 #include <private/qabstractanimation_p.h>
47 const double CONV_FACTOR = 0.017453292519943295;//Degrees to radians
49 class tst_qquickimageparticle : public QObject
53 tst_qquickimageparticle();
63 tst_qquickimageparticle::tst_qquickimageparticle()
65 QUnifiedTimer::instance()->setConsistentTiming(true);
68 void tst_qquickimageparticle::test_basic()
70 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600);
71 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
72 ensureAnimTime(600, system->m_animation);
74 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
75 foreach (QQuickParticleData *d, system->groupData[0]->data) {
77 continue; //Particle data unused
85 QCOMPARE(d->lifeSpan, 0.5f);
86 QCOMPARE(d->size, 32.f);
87 QCOMPARE(d->endSize, 32.f);
88 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
89 QCOMPARE(d->color.r, (uchar)255);
90 QCOMPARE(d->color.g, (uchar)255);
91 QCOMPARE(d->color.b, (uchar)255);
92 QCOMPARE(d->color.a, (uchar)255);
93 QCOMPARE(d->xx, 1.0f);
94 QCOMPARE(d->xy, 0.0f);
95 QCOMPARE(d->yy, 1.0f);
96 QCOMPARE(d->yx, 0.0f);
97 QCOMPARE(d->rotation, 0.0f);
98 QCOMPARE(d->rotationSpeed, 0.0f);
99 QCOMPARE(d->autoRotate, 0.0f);
100 QCOMPARE(d->animX, 0.0f);
101 QCOMPARE(d->animY, 0.0f);
102 QCOMPARE(d->animWidth, 1.0f);
103 QCOMPARE(d->animHeight, 1.0f);
104 QCOMPARE(d->frameDuration, 1.0f);
105 QCOMPARE(d->frameCount, 1.0f);
106 QCOMPARE(d->animT, -1.0f);
112 void tst_qquickimageparticle::test_colored()
114 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/colored.qml", 600);
115 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
116 ensureAnimTime(600, system->m_animation);
118 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
119 foreach (QQuickParticleData *d, system->groupData[0]->data) {
121 continue; //Particle data unused
125 QCOMPARE(d->vx, 0.f);
126 QCOMPARE(d->vy, 0.f);
127 QCOMPARE(d->ax, 0.f);
128 QCOMPARE(d->ay, 0.f);
129 QCOMPARE(d->lifeSpan, 0.5f);
130 QCOMPARE(d->size, 32.f);
131 QCOMPARE(d->endSize, 32.f);
132 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
133 QCOMPARE(d->color.r, (uchar)003);
134 QCOMPARE(d->color.g, (uchar)002);
135 QCOMPARE(d->color.b, (uchar)001);
136 QCOMPARE(d->color.a, (uchar)127);
137 QCOMPARE(d->xx, 1.0f);
138 QCOMPARE(d->xy, 0.0f);
139 QCOMPARE(d->yy, 1.0f);
140 QCOMPARE(d->yx, 0.0f);
141 QCOMPARE(d->rotation, 0.0f);
142 QCOMPARE(d->rotationSpeed, 0.0f);
143 QCOMPARE(d->autoRotate, 0.0f);
144 QCOMPARE(d->animX, 0.0f);
145 QCOMPARE(d->animY, 0.0f);
146 QCOMPARE(d->animWidth, 1.0f);
147 QCOMPARE(d->animHeight, 1.0f);
148 QCOMPARE(d->frameDuration, 1.0f);
149 QCOMPARE(d->frameCount, 1.0f);
150 QCOMPARE(d->animT, -1.0f);
156 void tst_qquickimageparticle::test_deformed()
158 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/deformed.qml", 600);
159 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
160 ensureAnimTime(600, system->m_animation);
162 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
163 foreach (QQuickParticleData *d, system->groupData[0]->data) {
165 continue; //Particle data unused
169 QCOMPARE(d->vx, 0.f);
170 QCOMPARE(d->vy, 0.f);
171 QCOMPARE(d->ax, 0.f);
172 QCOMPARE(d->ay, 0.f);
173 QCOMPARE(d->lifeSpan, 0.5f);
174 QCOMPARE(d->size, 32.f);
175 QCOMPARE(d->endSize, 32.f);
176 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
177 QCOMPARE(d->color.r, (uchar)255);
178 QCOMPARE(d->color.g, (uchar)255);
179 QCOMPARE(d->color.b, (uchar)255);
180 QCOMPARE(d->color.a, (uchar)255);
181 QCOMPARE(d->xx, 0.5f);
182 QCOMPARE(d->xy, 0.5f);
183 QCOMPARE(d->yy, 0.5f);
184 QCOMPARE(d->yx, 0.5f);
185 QCOMPARE(d->rotation, 90.0f * (float)CONV_FACTOR);
186 QCOMPARE(d->rotationSpeed, 90.0f * (float)CONV_FACTOR);
187 QCOMPARE(d->autoRotate, 1.0f);
188 QCOMPARE(d->animX, 0.0f);
189 QCOMPARE(d->animY, 0.0f);
190 QCOMPARE(d->animWidth, 1.0f);
191 QCOMPARE(d->animHeight, 1.0f);
192 QCOMPARE(d->frameDuration, 1.0f);
193 QCOMPARE(d->frameCount, 1.0f);
194 QCOMPARE(d->animT, -1.0f);
200 void tst_qquickimageparticle::test_tabled()
202 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/tabled.qml", 600);
203 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
204 ensureAnimTime(600, system->m_animation);
206 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
207 foreach (QQuickParticleData *d, system->groupData[0]->data) {
209 continue; //Particle data unused
213 QCOMPARE(d->vx, 0.f);
214 QCOMPARE(d->vy, 0.f);
215 QCOMPARE(d->ax, 0.f);
216 QCOMPARE(d->ay, 0.f);
217 QCOMPARE(d->lifeSpan, 0.5f);
218 QCOMPARE(d->size, 32.f);
219 QCOMPARE(d->endSize, 32.f);
220 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
221 QCOMPARE(d->color.r, (uchar)255);
222 QCOMPARE(d->color.g, (uchar)255);
223 QCOMPARE(d->color.b, (uchar)255);
224 QCOMPARE(d->color.a, (uchar)255);
225 QCOMPARE(d->xx, 1.0f);
226 QCOMPARE(d->xy, 0.0f);
227 QCOMPARE(d->yy, 1.0f);
228 QCOMPARE(d->yx, 0.0f);
229 QCOMPARE(d->rotation, 0.0f);
230 QCOMPARE(d->rotationSpeed, 0.0f);
231 QCOMPARE(d->autoRotate, 0.0f);
232 QCOMPARE(d->animX, 0.0f);
233 QCOMPARE(d->animY, 0.0f);
234 QCOMPARE(d->animWidth, 1.0f);
235 QCOMPARE(d->animHeight, 1.0f);
236 QCOMPARE(d->frameDuration, 1.0f);
237 QCOMPARE(d->frameCount, 1.0f);
238 QCOMPARE(d->animT, -1.0f);
239 //TODO: This performance level doesn't alter particleData, but goes straight to shaders. Find something to test
245 void tst_qquickimageparticle::test_sprite()
247 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/sprite.qml", 600);
248 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
249 ensureAnimTime(600, system->m_animation);
251 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
252 foreach (QQuickParticleData *d, system->groupData[0]->data) {
254 continue; //Particle data unused
258 QCOMPARE(d->vx, 0.f);
259 QCOMPARE(d->vy, 0.f);
260 QCOMPARE(d->ax, 0.f);
261 QCOMPARE(d->ay, 0.f);
262 QCOMPARE(d->lifeSpan, 0.5f);
263 QCOMPARE(d->size, 32.f);
264 QCOMPARE(d->endSize, 32.f);
265 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
266 QCOMPARE(d->color.r, (uchar)255);
267 QCOMPARE(d->color.g, (uchar)255);
268 QCOMPARE(d->color.b, (uchar)255);
269 QCOMPARE(d->color.a, (uchar)255);
270 QCOMPARE(d->xx, 1.0f);
271 QCOMPARE(d->xy, 0.0f);
272 QCOMPARE(d->yy, 1.0f);
273 QCOMPARE(d->yx, 0.0f);
274 QCOMPARE(d->rotation, 0.0f);
275 QCOMPARE(d->rotationSpeed, 0.0f);
276 QCOMPARE(d->autoRotate, 0.0f);
277 QVERIFY(myFuzzyCompare(d->frameDuration, 120.f));
278 QCOMPARE(d->frameCount, 6.0f);
279 QVERIFY(d->animT > 0.0f);
280 QCOMPARE(d->animX, 0.0f);
281 QCOMPARE(d->animY, 0.0f);
282 QCOMPARE(d->animWidth, 31.0f);
283 QCOMPARE(d->animHeight, 30.0f);
288 QTEST_MAIN(tst_qquickimageparticle);
290 #include "tst_qquickimageparticle.moc"