Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / tests / auto / particles / qquickimageparticle / tst_qquickimageparticle.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <QtTest/QtTest>
43 #include "../shared/particlestestsshared.h"
44 #include <private/qquickparticlesystem_p.h>
45 #include <private/qabstractanimation_p.h>
46
47 const double CONV_FACTOR = 0.017453292519943295;//Degrees to radians
48
49 class tst_qquickimageparticle : public QObject
50 {
51     Q_OBJECT
52 public:
53     tst_qquickimageparticle();
54     ~tst_qquickimageparticle();
55
56 private slots:
57     void test_basic();
58     void test_colored();
59     void test_colorVariance();
60     void test_deformed();
61     void test_tabled();
62     void test_sprite();
63 };
64
65 tst_qquickimageparticle::tst_qquickimageparticle()
66 {
67     QUnifiedTimer::instance()->setConsistentTiming(true);
68     setenv("QML_PARTICLES_DEBUG","please",0);//QQuickImageParticle has several debug statements, with possible pointer dereferences
69 }
70
71 tst_qquickimageparticle::~tst_qquickimageparticle()
72 {
73     unsetenv("QML_PARTICLES_DEBUG");
74 }
75
76 void tst_qquickimageparticle::test_basic()
77 {
78     QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600);
79     QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
80     ensureAnimTime(600, system->m_animation);
81
82     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
83     foreach (QQuickParticleData *d, system->groupData[0]->data) {
84         if (d->t == -1)
85             continue; //Particle data unused
86
87         QCOMPARE(d->x, 0.f);
88         QCOMPARE(d->y, 0.f);
89         QCOMPARE(d->vx, 0.f);
90         QCOMPARE(d->vy, 0.f);
91         QCOMPARE(d->ax, 0.f);
92         QCOMPARE(d->ay, 0.f);
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);
115     }
116     delete view;
117 }
118
119
120 void tst_qquickimageparticle::test_colored()
121 {
122     QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/colored.qml", 600);
123     QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
124     ensureAnimTime(600, system->m_animation);
125
126     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
127     foreach (QQuickParticleData *d, system->groupData[0]->data) {
128         if (d->t == -1)
129             continue; //Particle data unused
130
131         QCOMPARE(d->x, 0.f);
132         QCOMPARE(d->y, 0.f);
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);
159     }
160     delete view;
161 }
162
163
164 void tst_qquickimageparticle::test_colorVariance()
165 {
166     QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/colorVariance.qml", 600);
167     QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
168     ensureAnimTime(600, system->m_animation);
169
170     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
171     foreach (QQuickParticleData *d, system->groupData[0]->data) {
172         if (d->t == -1)
173             continue; //Particle data unused
174
175         QCOMPARE(d->x, 0.f);
176         QCOMPARE(d->y, 0.f);
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);
204     }
205     delete view;
206 }
207
208
209 void tst_qquickimageparticle::test_deformed()
210 {
211     QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/deformed.qml", 600);
212     QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
213     ensureAnimTime(600, system->m_animation);
214
215     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
216     foreach (QQuickParticleData *d, system->groupData[0]->data) {
217         if (d->t == -1)
218             continue; //Particle data unused
219
220         QCOMPARE(d->x, 0.f);
221         QCOMPARE(d->y, 0.f);
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);
248     }
249     delete view;
250 }
251
252
253 void tst_qquickimageparticle::test_tabled()
254 {
255     QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/tabled.qml", 600);
256     QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
257     ensureAnimTime(600, system->m_animation);
258
259     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
260     foreach (QQuickParticleData *d, system->groupData[0]->data) {
261         if (d->t == -1)
262             continue; //Particle data unused
263
264         QCOMPARE(d->x, 0.f);
265         QCOMPARE(d->y, 0.f);
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
293     }
294     delete view;
295 }
296
297
298 void tst_qquickimageparticle::test_sprite()
299 {
300     QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/sprite.qml", 600);
301     QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
302     ensureAnimTime(600, system->m_animation);
303
304     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
305     foreach (QQuickParticleData *d, system->groupData[0]->data) {
306         if (d->t == -1)
307             continue; //Particle data unused
308
309         QCOMPARE(d->x, 0.f);
310         QCOMPARE(d->y, 0.f);
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);
337     }
338     delete view;
339 }
340
341 QTEST_MAIN(tst_qquickimageparticle);
342
343 #include "tst_qquickimageparticle.moc"