From af3b3cd20060f7a55d64bd7b7533854267d133f7 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 17 Oct 2011 12:02:22 +1000 Subject: Stabilize Particles Tests A couple of targeted fixes, plus enabling QUnifiedTimer::consistentTiming. Task-number: QTBUG-21867 Change-Id: I62acf524eb2c6491bc88fd687a0065866d7ce8aa Reviewed-by: Martin Jones --- tests/auto/particles/qsgage/tst_qsgage.cpp | 8 ++++++++ .../qsgangleddirection/tst_qsgangleddirection.cpp | 5 ++++- .../tst_qsgcumulativedirection.cpp | 5 ++++- .../qsgcustomaffector/tst_qsgcustomaffector.cpp | 5 ++++- .../qsgcustomparticle/tst_qsgcustomparticle.cpp | 5 ++++- .../qsgellipseextruder/tst_qsgellipseextruder.cpp | 7 +++++-- tests/auto/particles/qsgfriction/tst_qsgfriction.cpp | 7 +++++-- tests/auto/particles/qsggravity/tst_qsggravity.cpp | 5 ++++- .../particles/qsgimageparticle/tst_qsgimageparticle.cpp | 17 ++++++++++++----- .../particles/qsgitemparticle/tst_qsgitemparticle.cpp | 7 +++++-- .../particles/qsglineextruder/tst_qsglineextruder.cpp | 7 +++++-- .../particles/qsgmaskextruder/tst_qsgmaskextruder.cpp | 5 ++++- .../particles/qsgparticlegroup/tst_qsgparticlegroup.cpp | 5 ++++- .../qsgparticlesystem/tst_qsgparticlesystem.cpp | 5 ++++- .../qsgpointattractor/tst_qsgpointattractor.cpp | 5 ++++- .../qsgpointdirection/tst_qsgpointdirection.cpp | 5 ++++- .../qsgrectangleextruder/tst_qsgrectangleextruder.cpp | 7 +++++-- .../qsgtargetdirection/tst_qsgtargetdirection.cpp | 5 ++++- .../particles/qsgtrailemitter/tst_qsgtrailemitter.cpp | 7 +++++-- .../auto/particles/qsgturbulence/tst_qsgturbulence.cpp | 5 ++++- tests/auto/particles/qsgwander/tst_qsgwander.cpp | 5 ++++- tests/auto/particles/shared/particlestestsshared.h | 7 +++++++ 22 files changed, 109 insertions(+), 30 deletions(-) (limited to 'tests') diff --git a/tests/auto/particles/qsgage/tst_qsgage.cpp b/tests/auto/particles/qsgage/tst_qsgage.cpp index b58d4558a3..54591e7349 100644 --- a/tests/auto/particles/qsgage/tst_qsgage.cpp +++ b/tests/auto/particles/qsgage/tst_qsgage.cpp @@ -42,6 +42,8 @@ #include #include "../shared/particlestestsshared.h" #include +#include "../../../shared/util.h" +#include class tst_qsgage : public QObject { @@ -58,12 +60,14 @@ private slots: tst_qsgage::tst_qsgage() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgage::test_kill() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/kill.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -87,6 +91,7 @@ void tst_qsgage::test_jump() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/jump.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -111,6 +116,7 @@ void tst_qsgage::test_onceOff() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/onceoff.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -134,6 +140,8 @@ void tst_qsgage::test_sustained() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/sustained.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + //TODO: Ensure some particles have lived to 0.4s point despite unified timer QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { diff --git a/tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp b/tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp index ea1d4ee6cf..dbb23ff29e 100644 --- a/tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp +++ b/tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp @@ -43,6 +43,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgangleddirection : public QObject { @@ -56,12 +57,14 @@ private slots: tst_qsgangleddirection::tst_qsgangleddirection() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgangleddirection::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -80,7 +83,7 @@ void tst_qsgangleddirection::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp b/tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp index 678b7493b8..00efff54bf 100644 --- a/tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp +++ b/tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgcumulativedirection : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgcumulativedirection::tst_qsgcumulativedirection() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgcumulativedirection::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -76,7 +79,7 @@ void tst_qsgcumulativedirection::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp b/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp index d5ae596ce5..2b36d318c5 100644 --- a/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp +++ b/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgcustomaffector : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgcustomaffector::tst_qsgcustomaffector() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgcustomaffector::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -76,7 +79,7 @@ void tst_qsgcustomaffector::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 100.f); QCOMPARE(d->endSize, 100.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp b/tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp index 239a135ad3..92762ea8e2 100644 --- a/tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp +++ b/tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgcustomparticle : public QObject { @@ -55,6 +56,7 @@ private slots: tst_qsgcustomparticle::tst_qsgcustomparticle() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgcustomparticle::test_basic() @@ -62,6 +64,7 @@ void tst_qsgcustomparticle::test_basic() QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QVERIFY(view); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); bool oneNonZero = false; QCOMPARE(system->groupData[0]->size(), 500); @@ -78,7 +81,7 @@ void tst_qsgcustomparticle::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); QVERIFY(d->r >= 0.0 && d->r <= 1.0); if (d->r != 0.0 ) oneNonZero = true; diff --git a/tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp b/tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp index 02b217329b..040a5e98b5 100644 --- a/tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp +++ b/tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp @@ -43,6 +43,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgellipseextruder : public QObject { @@ -58,6 +59,7 @@ private: tst_qsgellipseextruder::tst_qsgellipseextruder() { + QUnifiedTimer::instance()->setConsistentTiming(true); } bool tst_qsgellipseextruder::inCircle(qreal x, qreal y, qreal r, bool borderOnly) @@ -77,6 +79,7 @@ void tst_qsgellipseextruder::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); //Filled QCOMPARE(system->groupData[0]->size(), 500); @@ -92,7 +95,7 @@ void tst_qsgellipseextruder::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } //Just border QCOMPARE(system->groupData[1]->size(), 500); @@ -108,7 +111,7 @@ void tst_qsgellipseextruder::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgfriction/tst_qsgfriction.cpp b/tests/auto/particles/qsgfriction/tst_qsgfriction.cpp index 2d835de45a..bc622e4648 100644 --- a/tests/auto/particles/qsgfriction/tst_qsgfriction.cpp +++ b/tests/auto/particles/qsgfriction/tst_qsgfriction.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgfriction : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgfriction::tst_qsgfriction() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgfriction::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); //Default is just slowed a little QCOMPARE(system->groupData[0]->size(), 500); @@ -76,7 +79,7 @@ void tst_qsgfriction::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } //Nondefault comes to a complete stop within the first half of its life @@ -95,7 +98,7 @@ void tst_qsgfriction::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsggravity/tst_qsggravity.cpp b/tests/auto/particles/qsggravity/tst_qsggravity.cpp index e30d261e18..475809446c 100644 --- a/tests/auto/particles/qsggravity/tst_qsggravity.cpp +++ b/tests/auto/particles/qsggravity/tst_qsggravity.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsggravity : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsggravity::tst_qsggravity() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsggravity::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -72,7 +75,7 @@ void tst_qsggravity::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp b/tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp index ee8a179ac0..a416271669 100644 --- a/tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp +++ b/tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include const double CONV_FACTOR = 0.017453292519943295;//Degrees to radians @@ -61,12 +62,14 @@ private slots: tst_qsgimageparticle::tst_qsgimageparticle() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgimageparticle::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -82,7 +85,7 @@ void tst_qsgimageparticle::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); QCOMPARE(d->color.r, (uchar)255); QCOMPARE(d->color.g, (uchar)255); QCOMPARE(d->color.b, (uchar)255); @@ -109,6 +112,7 @@ void tst_qsgimageparticle::test_colored() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/colored.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -124,7 +128,7 @@ void tst_qsgimageparticle::test_colored() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); QCOMPARE(d->color.r, (uchar)003); QCOMPARE(d->color.g, (uchar)002); QCOMPARE(d->color.b, (uchar)001); @@ -151,6 +155,7 @@ void tst_qsgimageparticle::test_deformed() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/deformed.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -166,7 +171,7 @@ void tst_qsgimageparticle::test_deformed() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); QCOMPARE(d->color.r, (uchar)255); QCOMPARE(d->color.g, (uchar)255); QCOMPARE(d->color.b, (uchar)255); @@ -193,6 +198,7 @@ void tst_qsgimageparticle::test_tabled() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/tabled.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -208,7 +214,7 @@ void tst_qsgimageparticle::test_tabled() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); QCOMPARE(d->color.r, (uchar)255); QCOMPARE(d->color.g, (uchar)255); QCOMPARE(d->color.b, (uchar)255); @@ -236,6 +242,7 @@ void tst_qsgimageparticle::test_sprite() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/sprite.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -251,7 +258,7 @@ void tst_qsgimageparticle::test_sprite() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); QCOMPARE(d->color.r, (uchar)255); QCOMPARE(d->color.g, (uchar)255); QCOMPARE(d->color.b, (uchar)255); diff --git a/tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp b/tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp index f2307ed153..e58ab834f9 100644 --- a/tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp +++ b/tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp @@ -43,6 +43,7 @@ #include "../shared/particlestestsshared.h" #include #include +#include class tst_qsgitemparticle : public QObject { @@ -56,12 +57,14 @@ private slots: tst_qsgitemparticle::tst_qsgitemparticle() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgitemparticle::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -77,10 +80,10 @@ void tst_qsgitemparticle::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); if (d->t > ((qreal)system->timeInt/1000.0) - 0.05)//Delegates appear between frames, may miss the first couple continue; - if (d->t < ((qreal)system->timeInt/1000.0) - 0.5)//Delegates cleared on death + if (d->t < ((qreal)system->timeInt/1000.0) - 0.45)//Delegates cleared on death continue; QVERIFY(d->delegate); QVERIFY(qobject_cast(d->delegate)); diff --git a/tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp b/tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp index 2d43f7b585..0f25f50089 100644 --- a/tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp +++ b/tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsglineextruder : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsglineextruder::tst_qsglineextruder() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsglineextruder::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -75,7 +78,7 @@ void tst_qsglineextruder::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } QCOMPARE(system->groupData[1]->size(), 500); @@ -91,7 +94,7 @@ void tst_qsglineextruder::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp b/tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp index cdd5808cc8..03070d8be0 100644 --- a/tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp +++ b/tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgmaskextruder : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgmaskextruder::tst_qsgmaskextruder() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgmaskextruder::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -76,7 +79,7 @@ void tst_qsgmaskextruder::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp b/tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp index fd1709ba4a..49dc197ebb 100644 --- a/tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp +++ b/tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgparticlegroup : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgparticlegroup::tst_qsgparticlegroup() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgparticlegroup::test_instantTransition() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); //A frame or two worth of particles will be missed, the transition doesn't take effect on the frame it's spawned (QTBUG-21781) QVERIFY(system->groupData[0]->size() <= 500 && system->groupData[0]->size() >= 450); @@ -77,7 +80,7 @@ void tst_qsgparticlegroup::test_instantTransition() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp b/tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp index ade9ca929e..9c6f299884 100644 --- a/tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp +++ b/tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgparticlesystem : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgparticlesystem::tst_qsgparticlesystem() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgparticlesystem::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); int stillAlive = 0; @@ -79,7 +82,7 @@ void tst_qsgparticlesystem::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } QVERIFY(extremelyFuzzyCompare(stillAlive, 500, 5));//Small simulation variance is permissible. } diff --git a/tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp b/tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp index ef3b06a738..9e4ff328a7 100644 --- a/tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp +++ b/tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgpointattractor : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgpointattractor::tst_qsgpointattractor() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgpointattractor::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -77,7 +80,7 @@ void tst_qsgpointattractor::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp b/tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp index 4752f1c98b..c6a3a2c9b8 100644 --- a/tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp +++ b/tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgpointdirection : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgpointdirection::tst_qsgpointdirection() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgpointdirection::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -78,7 +81,7 @@ void tst_qsgpointdirection::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp b/tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp index b8cda61842..e8c27aab34 100644 --- a/tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp +++ b/tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgrectangleextruder : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgrectangleextruder::tst_qsgrectangleextruder() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgrectangleextruder::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -78,7 +81,7 @@ void tst_qsgrectangleextruder::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } QCOMPARE(system->groupData[1]->size(), 500); @@ -101,7 +104,7 @@ void tst_qsgrectangleextruder::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp b/tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp index 0f37fc0f72..decc96117a 100644 --- a/tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp +++ b/tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgtargetdirection : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgtargetdirection::tst_qsgtargetdirection() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgtargetdirection::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -76,7 +79,7 @@ void tst_qsgtargetdirection::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp b/tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp index 29e9d90499..e24c63c9d5 100644 --- a/tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp +++ b/tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgtrailemitter : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgtrailemitter::tst_qsgtrailemitter() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgtrailemitter::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { @@ -76,7 +79,7 @@ void tst_qsgtrailemitter::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } QCOMPARE(system->groupData[1]->size(), 500); @@ -93,7 +96,7 @@ void tst_qsgtrailemitter::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp b/tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp index 155b109ff9..4230bc529f 100644 --- a/tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp +++ b/tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgturbulence : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgturbulence::tst_qsgturbulence() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgturbulence::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); //Note that the noise image built-in provides the 'randomness', so this test should be stable so long as it and the size //of the Turbulence item remain the same @@ -74,7 +77,7 @@ void tst_qsgturbulence::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); } } diff --git a/tests/auto/particles/qsgwander/tst_qsgwander.cpp b/tests/auto/particles/qsgwander/tst_qsgwander.cpp index 0a7324862e..b200b6fbf0 100644 --- a/tests/auto/particles/qsgwander/tst_qsgwander.cpp +++ b/tests/auto/particles/qsgwander/tst_qsgwander.cpp @@ -42,6 +42,7 @@ #include #include "../shared/particlestestsshared.h" #include +#include class tst_qsgwander : public QObject { @@ -55,12 +56,14 @@ private slots: tst_qsgwander::tst_qsgwander() { + QUnifiedTimer::instance()->setConsistentTiming(true); } void tst_qsgwander::test_basic() { QSGView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); QSGParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); QCOMPARE(system->groupData[0]->size(), 500); //Since Wander is random perturbations, the compromise between stability and actual testing is to hope that one of @@ -76,7 +79,7 @@ void tst_qsgwander::test_basic() QCOMPARE(d->lifeSpan, 0.5f); QCOMPARE(d->size, 32.f); QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); if (d->vx != 0.0f) vxChanged = true; if (d->vy != 0.0f) diff --git a/tests/auto/particles/shared/particlestestsshared.h b/tests/auto/particles/shared/particlestestsshared.h index 66e880fc5b..ed483bae01 100644 --- a/tests/auto/particles/shared/particlestestsshared.h +++ b/tests/auto/particles/shared/particlestestsshared.h @@ -43,6 +43,7 @@ #define PARTICLES_TESTS_SHARED #include #include +#include const qreal EPSILON = 0.0001; bool extremelyFuzzyCompare(qreal a, qreal b, qreal e)//For cases which can have larger variances @@ -80,4 +81,10 @@ QSGView* createView(const QString &filename, int additionalWait=0) return canvas; } +void ensureAnimTime(int requiredTime, QAbstractAnimation* anim)//With consistentTiming, who knows how long an animation really takes... +{ + while (anim->currentTime() < requiredTime) + QTest::qWait(100); +} + #endif -- cgit v1.2.3