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();
54 ~tst_qquickimageparticle();
59 void test_colorVariance();
65 tst_qquickimageparticle::tst_qquickimageparticle()
67 QUnifiedTimer::instance()->setConsistentTiming(true);
68 setenv("QML_PARTICLES_DEBUG","please",0);//QQuickImageParticle has several debug statements, with possible pointer dereferences
71 tst_qquickimageparticle::~tst_qquickimageparticle()
73 unsetenv("QML_PARTICLES_DEBUG");
76 void tst_qquickimageparticle::test_basic()
78 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600);
79 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
80 ensureAnimTime(600, system->m_animation);
82 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
83 foreach (QQuickParticleData *d, system->groupData[0]->data) {
85 continue; //Particle data unused
93 QCOMPARE(d->lifeSpan, 0.5f);
94 QCOMPARE(d->size, 32.f);
95 QCOMPARE(d->endSize, 32.f);
96 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
97 QCOMPARE(d->color.r, (uchar)255);
98 QCOMPARE(d->color.g, (uchar)255);
99 QCOMPARE(d->color.b, (uchar)255);
100 QCOMPARE(d->color.a, (uchar)255);
101 QCOMPARE(d->xx, 1.0f);
102 QCOMPARE(d->xy, 0.0f);
103 QCOMPARE(d->yy, 1.0f);
104 QCOMPARE(d->yx, 0.0f);
105 QCOMPARE(d->rotation, 0.0f);
106 QCOMPARE(d->rotationSpeed, 0.0f);
107 QCOMPARE(d->autoRotate, 0.0f);
108 QCOMPARE(d->animX, 0.0f);
109 QCOMPARE(d->animY, 0.0f);
110 QCOMPARE(d->animWidth, 1.0f);
111 QCOMPARE(d->animHeight, 1.0f);
112 QCOMPARE(d->frameDuration, 1.0f);
113 QCOMPARE(d->frameCount, 1.0f);
114 QCOMPARE(d->animT, -1.0f);
120 void tst_qquickimageparticle::test_colored()
122 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/colored.qml", 600);
123 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
124 ensureAnimTime(600, system->m_animation);
126 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
127 foreach (QQuickParticleData *d, system->groupData[0]->data) {
129 continue; //Particle data unused
133 QCOMPARE(d->vx, 0.f);
134 QCOMPARE(d->vy, 0.f);
135 QCOMPARE(d->ax, 0.f);
136 QCOMPARE(d->ay, 0.f);
137 QCOMPARE(d->lifeSpan, 0.5f);
138 QCOMPARE(d->size, 32.f);
139 QCOMPARE(d->endSize, 32.f);
140 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
141 QCOMPARE(d->color.r, (uchar)003);
142 QCOMPARE(d->color.g, (uchar)002);
143 QCOMPARE(d->color.b, (uchar)001);
144 QCOMPARE(d->color.a, (uchar)127);
145 QCOMPARE(d->xx, 1.0f);
146 QCOMPARE(d->xy, 0.0f);
147 QCOMPARE(d->yy, 1.0f);
148 QCOMPARE(d->yx, 0.0f);
149 QCOMPARE(d->rotation, 0.0f);
150 QCOMPARE(d->rotationSpeed, 0.0f);
151 QCOMPARE(d->autoRotate, 0.0f);
152 QCOMPARE(d->animX, 0.0f);
153 QCOMPARE(d->animY, 0.0f);
154 QCOMPARE(d->animWidth, 1.0f);
155 QCOMPARE(d->animHeight, 1.0f);
156 QCOMPARE(d->frameDuration, 1.0f);
157 QCOMPARE(d->frameCount, 1.0f);
158 QCOMPARE(d->animT, -1.0f);
164 void tst_qquickimageparticle::test_colorVariance()
166 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/colorVariance.qml", 600);
167 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
168 ensureAnimTime(600, system->m_animation);
170 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
171 foreach (QQuickParticleData *d, system->groupData[0]->data) {
173 continue; //Particle data unused
177 QCOMPARE(d->vx, 0.f);
178 QCOMPARE(d->vy, 0.f);
179 QCOMPARE(d->ax, 0.f);
180 QCOMPARE(d->ay, 0.f);
181 QCOMPARE(d->lifeSpan, 0.5f);
182 QCOMPARE(d->size, 32.f);
183 QCOMPARE(d->endSize, 32.f);
184 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
185 QVERIFY(d->color.r < 128);
186 QVERIFY(d->color.g < 64);
187 QVERIFY(d->color.b < 32);
188 QVERIFY(d->color.a >= 64);
189 QVERIFY(d->color.a < 192);
190 QCOMPARE(d->xx, 1.0f);
191 QCOMPARE(d->xy, 0.0f);
192 QCOMPARE(d->yy, 1.0f);
193 QCOMPARE(d->yx, 0.0f);
194 QCOMPARE(d->rotation, 0.0f);
195 QCOMPARE(d->rotationSpeed, 0.0f);
196 QCOMPARE(d->autoRotate, 0.0f);
197 QCOMPARE(d->animX, 0.0f);
198 QCOMPARE(d->animY, 0.0f);
199 QCOMPARE(d->animWidth, 1.0f);
200 QCOMPARE(d->animHeight, 1.0f);
201 QCOMPARE(d->frameDuration, 1.0f);
202 QCOMPARE(d->frameCount, 1.0f);
203 QCOMPARE(d->animT, -1.0f);
209 void tst_qquickimageparticle::test_deformed()
211 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/deformed.qml", 600);
212 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
213 ensureAnimTime(600, system->m_animation);
215 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
216 foreach (QQuickParticleData *d, system->groupData[0]->data) {
218 continue; //Particle data unused
222 QCOMPARE(d->vx, 0.f);
223 QCOMPARE(d->vy, 0.f);
224 QCOMPARE(d->ax, 0.f);
225 QCOMPARE(d->ay, 0.f);
226 QCOMPARE(d->lifeSpan, 0.5f);
227 QCOMPARE(d->size, 32.f);
228 QCOMPARE(d->endSize, 32.f);
229 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
230 QCOMPARE(d->color.r, (uchar)255);
231 QCOMPARE(d->color.g, (uchar)255);
232 QCOMPARE(d->color.b, (uchar)255);
233 QCOMPARE(d->color.a, (uchar)255);
234 QCOMPARE(d->xx, 0.5f);
235 QCOMPARE(d->xy, 0.5f);
236 QCOMPARE(d->yy, 0.5f);
237 QCOMPARE(d->yx, 0.5f);
238 QCOMPARE(d->rotation, 90.0f * (float)CONV_FACTOR);
239 QCOMPARE(d->rotationSpeed, 90.0f * (float)CONV_FACTOR);
240 QCOMPARE(d->autoRotate, 1.0f);
241 QCOMPARE(d->animX, 0.0f);
242 QCOMPARE(d->animY, 0.0f);
243 QCOMPARE(d->animWidth, 1.0f);
244 QCOMPARE(d->animHeight, 1.0f);
245 QCOMPARE(d->frameDuration, 1.0f);
246 QCOMPARE(d->frameCount, 1.0f);
247 QCOMPARE(d->animT, -1.0f);
253 void tst_qquickimageparticle::test_tabled()
255 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/tabled.qml", 600);
256 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
257 ensureAnimTime(600, system->m_animation);
259 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
260 foreach (QQuickParticleData *d, system->groupData[0]->data) {
262 continue; //Particle data unused
266 QCOMPARE(d->vx, 0.f);
267 QCOMPARE(d->vy, 0.f);
268 QCOMPARE(d->ax, 0.f);
269 QCOMPARE(d->ay, 0.f);
270 QCOMPARE(d->lifeSpan, 0.5f);
271 QCOMPARE(d->size, 32.f);
272 QCOMPARE(d->endSize, 32.f);
273 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
274 QCOMPARE(d->color.r, (uchar)255);
275 QCOMPARE(d->color.g, (uchar)255);
276 QCOMPARE(d->color.b, (uchar)255);
277 QCOMPARE(d->color.a, (uchar)255);
278 QCOMPARE(d->xx, 1.0f);
279 QCOMPARE(d->xy, 0.0f);
280 QCOMPARE(d->yy, 1.0f);
281 QCOMPARE(d->yx, 0.0f);
282 QCOMPARE(d->rotation, 0.0f);
283 QCOMPARE(d->rotationSpeed, 0.0f);
284 QCOMPARE(d->autoRotate, 0.0f);
285 QCOMPARE(d->animX, 0.0f);
286 QCOMPARE(d->animY, 0.0f);
287 QCOMPARE(d->animWidth, 1.0f);
288 QCOMPARE(d->animHeight, 1.0f);
289 QCOMPARE(d->frameDuration, 1.0f);
290 QCOMPARE(d->frameCount, 1.0f);
291 QCOMPARE(d->animT, -1.0f);
292 //TODO: This performance level doesn't alter particleData, but goes straight to shaders. Find something to test
298 void tst_qquickimageparticle::test_sprite()
300 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/sprite.qml", 600);
301 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
302 ensureAnimTime(600, system->m_animation);
304 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
305 foreach (QQuickParticleData *d, system->groupData[0]->data) {
307 continue; //Particle data unused
311 QCOMPARE(d->vx, 0.f);
312 QCOMPARE(d->vy, 0.f);
313 QCOMPARE(d->ax, 0.f);
314 QCOMPARE(d->ay, 0.f);
315 QCOMPARE(d->lifeSpan, 0.5f);
316 QCOMPARE(d->size, 32.f);
317 QCOMPARE(d->endSize, 32.f);
318 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
319 QCOMPARE(d->color.r, (uchar)255);
320 QCOMPARE(d->color.g, (uchar)255);
321 QCOMPARE(d->color.b, (uchar)255);
322 QCOMPARE(d->color.a, (uchar)255);
323 QCOMPARE(d->xx, 1.0f);
324 QCOMPARE(d->xy, 0.0f);
325 QCOMPARE(d->yy, 1.0f);
326 QCOMPARE(d->yx, 0.0f);
327 QCOMPARE(d->rotation, 0.0f);
328 QCOMPARE(d->rotationSpeed, 0.0f);
329 QCOMPARE(d->autoRotate, 0.0f);
330 QVERIFY(myFuzzyCompare(d->frameDuration, 120.f));
331 QCOMPARE(d->frameCount, 6.0f);
332 QVERIFY(d->animT > 0.0f);
333 QCOMPARE(d->animX, 0.0f);
334 QCOMPARE(d->animY, 0.0f);
335 QCOMPARE(d->animWidth, 31.0f);
336 QCOMPARE(d->animHeight, 30.0f);
341 QTEST_MAIN(tst_qquickimageparticle);
343 #include "tst_qquickimageparticle.moc"