628de2e77e6e656575a7bf8ea73ba4ac5fd8e1ec
[profile/ivi/qtdeclarative.git] / tests / benchmarks / particles / affectors / tst_affectors.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
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 <qtest.h>
43 #include <QtTest/QtTest>
44 #include "../../../auto/particles/shared/particlestestsshared.h"
45 #include <private/qquickparticlesystem_p.h>
46
47 class tst_affectors : public QObject
48 {
49     Q_OBJECT
50 public:
51     tst_affectors();
52
53 private slots:
54     void test_basic();
55     void test_basic_data();
56     void test_filtered();
57     void test_filtered_data();
58 };
59
60 tst_affectors::tst_affectors()
61 {
62 }
63
64 void tst_affectors::test_basic_data()
65 {
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;
71 }
72
73 void tst_affectors::test_filtered_data()
74 {
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;
80 }
81
82 void tst_affectors::test_basic()
83 {
84     QFETCH(int, dt);
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;
90     system->reset();
91
92     int curTime = 1;
93     system->updateCurrentTime(curTime);//Fixed point and get init out of the way - including emission
94
95     QBENCHMARK {
96         curTime += dt;
97         system->updateCurrentTime(curTime);
98     }
99
100     int stillAlive = 0;
101     QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 1000, 10));//Small simulation variance is permissible.
102     foreach (QQuickParticleData *d, system->groupData[0]->data) {
103         if (d->t == -1)
104             continue; //Particle data unused
105
106         if (d->stillAlive())
107             stillAlive++;
108         QCOMPARE(d->x, 0.f);
109         QCOMPARE(d->y, 0.f);
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)));
117     }
118     QVERIFY(extremelyFuzzyCompare(stillAlive, 1000, 10));//Small simulation variance is permissible.
119     delete view;
120 }
121
122 void tst_affectors::test_filtered()
123 {
124     QFETCH(int, dt);
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;
130     system->reset();
131
132     int curTime = 1;
133     system->updateCurrentTime(curTime);//Fixed point and get init out of the way - including emission
134
135     QBENCHMARK {
136         curTime += dt;
137         system->updateCurrentTime(curTime);
138     }
139
140     int stillAlive = 0;
141     QVERIFY(extremelyFuzzyCompare(system->groupData[1]->size(), 1000, 10));//Small simulation variance is permissible.
142     foreach (QQuickParticleData *d, system->groupData[1]->data) {
143         if (d->t == -1)
144             continue; //Particle data unused
145
146         if (d->stillAlive())
147             stillAlive++;
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)));
157     }
158     QVERIFY(extremelyFuzzyCompare(stillAlive, 1000, 10));//Small simulation variance is permissible.
159     delete view;
160 }
161
162 QTEST_MAIN(tst_affectors);
163
164 #include "tst_affectors.moc"