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 <qmath.h>
30#include <QtTest/QtTest>
31#include "../shared/particlestestsshared.h"
32#include <private/qquickparticlesystem_p.h>
33#include <private/qabstractanimation_p.h>
34
35#include "../../shared/util.h"
36
37class tst_qquickellipseextruder : public QQmlDataTest
38{
39 Q_OBJECT
40public:
41 tst_qquickellipseextruder() {}
42
43private slots:
44 void initTestCase();
45 void test_basic();
46private:
47 bool inCircle(qreal x, qreal y, qreal r, bool borderOnly=false);
48};
49
50void tst_qquickellipseextruder::initTestCase()
51{
52 QQmlDataTest::initTestCase();
53 QUnifiedTimer::instance()->setConsistentTiming(true);
54}
55
56bool tst_qquickellipseextruder::inCircle(qreal x, qreal y, qreal r, bool borderOnly)
57{
58 x -= r;
59 y -= r;
60 if (myFuzzyCompare(a: x,b: 0) && myFuzzyCompare(a: y,b: 0))
61 return !borderOnly;
62 qreal mag = qSqrt(v: x*x + y*y);
63 if (borderOnly)
64 return myFuzzyCompare(a: mag, b: r); //Need myFuzzyCompare for smaller Epsilon than qFuzzyCompare
65 else
66 return mag - EPSILON < r;
67}
68
69void tst_qquickellipseextruder::test_basic()
70{
71 QQuickView* view = createView(filename: testFileUrl(fileName: "basic.qml"), additionalWait: 600);
72 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>(aName: "system");
73 ensureAnimTime(requiredTime: 600, anim: system->m_animation);
74
75 //Filled
76 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10));
77 for (QQuickParticleData *d : qAsConst(t&: system->groupData[0]->data)) {
78 if (d->t == -1)
79 continue; //Particle data unused
80
81 QVERIFY(inCircle(d->x, d->y, 160, false));
82 QCOMPARE(d->vx, 0.f);
83 QCOMPARE(d->vy, 0.f);
84 QCOMPARE(d->ax, 0.f);
85 QCOMPARE(d->ay, 0.f);
86 QCOMPARE(d->lifeSpan, 0.5f);
87 QCOMPARE(d->size, 32.f);
88 QCOMPARE(d->endSize, 32.f);
89 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
90 }
91
92 //Just border
93 QCOMPARE(system->groupData[1]->size(), 500);
94 for (QQuickParticleData *d : qAsConst(t&: system->groupData[1]->data)) {
95 if (d->t == -1)
96 continue; //Particle data unused
97
98 QVERIFY(inCircle(d->x, d->y, 160, true));
99 QCOMPARE(d->vx, 0.f);
100 QCOMPARE(d->vy, 0.f);
101 QCOMPARE(d->ax, 0.f);
102 QCOMPARE(d->ay, 0.f);
103 QCOMPARE(d->lifeSpan, 0.5f);
104 QCOMPARE(d->size, 32.f);
105 QCOMPARE(d->endSize, 32.f);
106 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
107 }
108 delete view;
109}
110
111QTEST_MAIN(tst_qquickellipseextruder);
112
113#include "tst_qquickellipseextruder.moc"
114

source code of qtdeclarative/tests/auto/particles/qquickellipseextruder/tst_qquickellipseextruder.cpp