Update copyright year in 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 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
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
55 private slots:
56     void test_basic();
57     void test_colored();
58     void test_deformed();
59     void test_tabled();
60     void test_sprite();
61 };
62
63 tst_qquickimageparticle::tst_qquickimageparticle()
64 {
65     QUnifiedTimer::instance()->setConsistentTiming(true);
66 }
67
68 void tst_qquickimageparticle::test_basic()
69 {
70     QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600);
71     QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
72     ensureAnimTime(600, system->m_animation);
73
74     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
75     foreach (QQuickParticleData *d, system->groupData[0]->data) {
76         if (d->t == -1)
77             continue; //Particle data unused
78
79         QCOMPARE(d->x, 0.f);
80         QCOMPARE(d->y, 0.f);
81         QCOMPARE(d->vx, 0.f);
82         QCOMPARE(d->vy, 0.f);
83         QCOMPARE(d->ax, 0.f);
84         QCOMPARE(d->ay, 0.f);
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);
107     }
108     delete view;
109 }
110
111
112 void tst_qquickimageparticle::test_colored()
113 {
114     QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/colored.qml", 600);
115     QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
116     ensureAnimTime(600, system->m_animation);
117
118     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
119     foreach (QQuickParticleData *d, system->groupData[0]->data) {
120         if (d->t == -1)
121             continue; //Particle data unused
122
123         QCOMPARE(d->x, 0.f);
124         QCOMPARE(d->y, 0.f);
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);
151     }
152     delete view;
153 }
154
155
156 void tst_qquickimageparticle::test_deformed()
157 {
158     QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/deformed.qml", 600);
159     QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
160     ensureAnimTime(600, system->m_animation);
161
162     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
163     foreach (QQuickParticleData *d, system->groupData[0]->data) {
164         if (d->t == -1)
165             continue; //Particle data unused
166
167         QCOMPARE(d->x, 0.f);
168         QCOMPARE(d->y, 0.f);
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);
195     }
196     delete view;
197 }
198
199
200 void tst_qquickimageparticle::test_tabled()
201 {
202     QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/tabled.qml", 600);
203     QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
204     ensureAnimTime(600, system->m_animation);
205
206     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
207     foreach (QQuickParticleData *d, system->groupData[0]->data) {
208         if (d->t == -1)
209             continue; //Particle data unused
210
211         QCOMPARE(d->x, 0.f);
212         QCOMPARE(d->y, 0.f);
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
240     }
241     delete view;
242 }
243
244
245 void tst_qquickimageparticle::test_sprite()
246 {
247     QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/sprite.qml", 600);
248     QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
249     ensureAnimTime(600, system->m_animation);
250
251     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
252     foreach (QQuickParticleData *d, system->groupData[0]->data) {
253         if (d->t == -1)
254             continue; //Particle data unused
255
256         QCOMPARE(d->x, 0.f);
257         QCOMPARE(d->y, 0.f);
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);
284     }
285     delete view;
286 }
287
288 QTEST_MAIN(tst_qquickimageparticle);
289
290 #include "tst_qquickimageparticle.moc"