1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QtTest>
30#include "../shared/particlestestsshared.h"
31#include <private/qquickparticlesystem_p.h>
32#include <private/qabstractanimation_p.h>
33
34#include "../../shared/util.h"
35
36const double CONV_FACTOR = 0.017453292519943295;//Degrees to radians
37
38class tst_qquickimageparticle : public QQmlDataTest
39{
40 Q_OBJECT
41public:
42 tst_qquickimageparticle() {}
43 ~tst_qquickimageparticle();
44
45private slots:
46 void initTestCase();
47 void test_basic();
48 void test_colored();
49 void test_colorVariance();
50 void test_deformed();
51 void test_tabled();
52 void test_sprite();
53};
54
55void tst_qquickimageparticle::initTestCase()
56{
57 QQmlDataTest::initTestCase();
58 QUnifiedTimer::instance()->setConsistentTiming(true);
59 //QQuickImageParticle has several debug statements, with possible pointer dereferences
60 qputenv(varName: "QML_PARTICLES_DEBUG",value: "please");
61}
62
63tst_qquickimageparticle::~tst_qquickimageparticle()
64{
65 qputenv(varName: "QML_PARTICLES_DEBUG",value: "");
66}
67
68void tst_qquickimageparticle::test_basic()
69{
70 QQuickView* view = createView(filename: testFileUrl(fileName: "basic.qml"), additionalWait: 600);
71 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>(aName: "system");
72 ensureAnimTime(requiredTime: 600, anim: system->m_animation);
73
74 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
75 for (QQuickParticleData *d : qAsConst(t&: 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->rotationVelocity, 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
112void tst_qquickimageparticle::test_colored()
113{
114 QQuickView* view = createView(filename: testFileUrl(fileName: "colored.qml"), additionalWait: 600);
115 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>(aName: "system");
116 ensureAnimTime(requiredTime: 600, anim: system->m_animation);
117
118 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
119 for (QQuickParticleData *d : qAsConst(t&: 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->rotationVelocity, 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
156void tst_qquickimageparticle::test_colorVariance()
157{
158 QQuickView* view = createView(filename: testFileUrl(fileName: "colorVariance.qml"), additionalWait: 600);
159 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>(aName: "system");
160 ensureAnimTime(requiredTime: 600, anim: system->m_animation);
161
162 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
163 for (QQuickParticleData *d : qAsConst(t&: 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 QVERIFY(d->color.r < 128);
178 QVERIFY(d->color.g < 64);
179 QVERIFY(d->color.b < 32);
180 QVERIFY(d->color.a >= 64);
181 QVERIFY(d->color.a < 192);
182 QCOMPARE(d->xx, 1.0f);
183 QCOMPARE(d->xy, 0.0f);
184 QCOMPARE(d->yy, 1.0f);
185 QCOMPARE(d->yx, 0.0f);
186 QCOMPARE(d->rotation, 0.0f);
187 QCOMPARE(d->rotationVelocity, 0.0f);
188 QCOMPARE(d->autoRotate, 0.0f);
189 QCOMPARE(d->animX, 0.0f);
190 QCOMPARE(d->animY, 0.0f);
191 QCOMPARE(d->animWidth, 1.0f);
192 QCOMPARE(d->animHeight, 1.0f);
193 QCOMPARE(d->frameDuration, 1.0f);
194 QCOMPARE(d->frameCount, 1.0f);
195 QCOMPARE(d->animT, -1.0f);
196 }
197 delete view;
198}
199
200
201void tst_qquickimageparticle::test_deformed()
202{
203 QQuickView* view = createView(filename: testFileUrl(fileName: "deformed.qml"), additionalWait: 600);
204 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>(aName: "system");
205 ensureAnimTime(requiredTime: 600, anim: system->m_animation);
206
207 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
208 for (QQuickParticleData *d : qAsConst(t&: system->groupData[0]->data)) {
209 if (d->t == -1)
210 continue; //Particle data unused
211
212 QCOMPARE(d->x, 0.f);
213 QCOMPARE(d->y, 0.f);
214 QCOMPARE(d->vx, 0.f);
215 QCOMPARE(d->vy, 0.f);
216 QCOMPARE(d->ax, 0.f);
217 QCOMPARE(d->ay, 0.f);
218 QCOMPARE(d->lifeSpan, 0.5f);
219 QCOMPARE(d->size, 32.f);
220 QCOMPARE(d->endSize, 32.f);
221 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
222 QCOMPARE(d->color.r, (uchar)255);
223 QCOMPARE(d->color.g, (uchar)255);
224 QCOMPARE(d->color.b, (uchar)255);
225 QCOMPARE(d->color.a, (uchar)255);
226 QCOMPARE(d->xx, 0.5f);
227 QCOMPARE(d->xy, 0.5f);
228 QCOMPARE(d->yy, 0.5f);
229 QCOMPARE(d->yx, 0.5f);
230 QCOMPARE(d->rotation, 90.0f * (float)CONV_FACTOR);
231 QCOMPARE(d->rotationVelocity, 90.0f * (float)CONV_FACTOR);
232 QCOMPARE(d->autoRotate, 1.0f);
233 QCOMPARE(d->animX, 0.0f);
234 QCOMPARE(d->animY, 0.0f);
235 QCOMPARE(d->animWidth, 1.0f);
236 QCOMPARE(d->animHeight, 1.0f);
237 QCOMPARE(d->frameDuration, 1.0f);
238 QCOMPARE(d->frameCount, 1.0f);
239 QCOMPARE(d->animT, -1.0f);
240 }
241 delete view;
242}
243
244
245void tst_qquickimageparticle::test_tabled()
246{
247 QQuickView* view = createView(filename: testFileUrl(fileName: "tabled.qml"), additionalWait: 600);
248 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>(aName: "system");
249 ensureAnimTime(requiredTime: 600, anim: system->m_animation);
250
251 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
252 for (QQuickParticleData *d : qAsConst(t&: 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->rotationVelocity, 0.0f);
276 QCOMPARE(d->autoRotate, 0.0f);
277 QCOMPARE(d->animX, 0.0f);
278 QCOMPARE(d->animY, 0.0f);
279 QCOMPARE(d->animWidth, 1.0f);
280 QCOMPARE(d->animHeight, 1.0f);
281 QCOMPARE(d->frameDuration, 1.0f);
282 QCOMPARE(d->frameCount, 1.0f);
283 QCOMPARE(d->animT, -1.0f);
284 //TODO: This performance level doesn't alter particleData, but goes straight to shaders. Find something to test
285 }
286 delete view;
287}
288
289
290void tst_qquickimageparticle::test_sprite()
291{
292 QQuickView* view = createView(filename: testFileUrl(fileName: "sprite.qml"), additionalWait: 600);
293 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>(aName: "system");
294 ensureAnimTime(requiredTime: 600, anim: system->m_animation);
295
296 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
297 for (QQuickParticleData *d : qAsConst(t&: system->groupData[0]->data)) {
298 if (d->t == -1)
299 continue; //Particle data unused
300
301 QCOMPARE(d->x, 0.f);
302 QCOMPARE(d->y, 0.f);
303 QCOMPARE(d->vx, 0.f);
304 QCOMPARE(d->vy, 0.f);
305 QCOMPARE(d->ax, 0.f);
306 QCOMPARE(d->ay, 0.f);
307 QCOMPARE(d->lifeSpan, 0.5f);
308 QCOMPARE(d->size, 32.f);
309 QCOMPARE(d->endSize, 32.f);
310 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
311 QCOMPARE(d->color.r, (uchar)255);
312 QCOMPARE(d->color.g, (uchar)255);
313 QCOMPARE(d->color.b, (uchar)255);
314 QCOMPARE(d->color.a, (uchar)255);
315 QCOMPARE(d->xx, 1.0f);
316 QCOMPARE(d->xy, 0.0f);
317 QCOMPARE(d->yy, 1.0f);
318 QCOMPARE(d->yx, 0.0f);
319 QCOMPARE(d->rotation, 0.0f);
320 QCOMPARE(d->rotationVelocity, 0.0f);
321 QCOMPARE(d->autoRotate, 0.0f);
322 QVERIFY(myFuzzyCompare(d->frameDuration, 120.f));
323 QCOMPARE(d->frameCount, 6.0f);
324 QVERIFY(d->animT > 0.0f);
325 QCOMPARE(d->animX, 0.0f);
326 QCOMPARE(d->animY, 0.0f);
327 QCOMPARE(d->animWidth, 31.0f);
328 QCOMPARE(d->animHeight, 30.0f);
329 }
330 delete view;
331}
332
333QTEST_MAIN(tst_qquickimageparticle);
334
335#include "tst_qquickimageparticle.moc"
336

source code of qtdeclarative/tests/auto/particles/qquickimageparticle/tst_qquickimageparticle.cpp