1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
43 #include <QtTest/QtTest>
44 #include "../../../auto/particles/shared/particlestestsshared.h"
45 #include <private/qquickparticlesystem_p.h>
47 class tst_affectors : public QObject
55 void test_basic_data();
57 void test_filtered_data();
60 tst_affectors::tst_affectors()
64 void tst_affectors::test_basic_data()
66 QTest::addColumn<int> ("dt");
67 QTest::newRow("16ms") << 16;
68 QTest::newRow("32ms") << 32;
69 QTest::newRow("100ms") << 100;
70 QTest::newRow("500ms") << 500;
73 void tst_affectors::test_filtered_data()
75 QTest::addColumn<int> ("dt");
76 QTest::newRow("16ms") << 16;
77 QTest::newRow("32ms") << 32;
78 QTest::newRow("100ms") << 100;
79 QTest::newRow("500ms") << 500;
82 void tst_affectors::test_basic()
85 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml");
86 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
87 //Pretend we're running, but we manually advance the simulation
88 system->m_running = true;
89 system->m_animation = 0;
93 system->updateCurrentTime(curTime);//Fixed point and get init out of the way - including emission
97 system->updateCurrentTime(curTime);
101 QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 1000, 10));//Small simulation variance is permissible.
102 foreach (QQuickParticleData *d, system->groupData[0]->data) {
104 continue; //Particle data unused
110 QCOMPARE(d->vx, 0.f);
111 QCOMPARE(d->vy, 0.f);
112 QCOMPARE(d->ax, 0.f);
113 QCOMPARE(d->ay, 0.f);
114 QCOMPARE(d->size, 32.f);
115 QCOMPARE(d->endSize, 32.f);
116 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
118 QVERIFY(extremelyFuzzyCompare(stillAlive, 1000, 10));//Small simulation variance is permissible.
122 void tst_affectors::test_filtered()
125 QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/filtered.qml");
126 QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
127 //Pretend we're running, but we manually advance the simulation
128 system->m_running = true;
129 system->m_animation = 0;
133 system->updateCurrentTime(curTime);//Fixed point and get init out of the way - including emission
137 system->updateCurrentTime(curTime);
141 QVERIFY(extremelyFuzzyCompare(system->groupData[1]->size(), 1000, 10));//Small simulation variance is permissible.
142 foreach (QQuickParticleData *d, system->groupData[1]->data) {
144 continue; //Particle data unused
148 QCOMPARE(d->x, 160.f);
149 QCOMPARE(d->y, 160.f);
150 QCOMPARE(d->vx, 0.f);
151 QCOMPARE(d->vy, 0.f);
152 QCOMPARE(d->ax, 0.f);
153 QCOMPARE(d->ay, 0.f);
154 QCOMPARE(d->size, 32.f);
155 QCOMPARE(d->endSize, 32.f);
156 QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0)));
158 QVERIFY(extremelyFuzzyCompare(stillAlive, 1000, 10));//Small simulation variance is permissible.
162 QTEST_MAIN(tst_affectors);
164 #include "tst_affectors.moc"