From ef85e164c6f5039744d74cfcd54e589461ea012e Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 10 Oct 2011 18:02:17 +1000 Subject: [PATCH] Stabilize Particles tests One potential problem is that in certain circumstances the recycling data list is so efficient that it doesn't need to use all particle data in the list. In those cases, the uninitialized members were causing test failures but these slight differences are acceptable for the simulation. The ParticleSystem test is extended to check that it's only small edge cases. Change-Id: I5e2f133dc4b96dd05d49e7e983ae630e379fa66a Reviewed-on: http://codereview.qt-project.org/6312 Sanity-Review: Qt Sanity Bot Reviewed-by: Martin Jones --- tests/auto/particles/qsgage/tst_qsgage.cpp | 14 ++++++++++---- .../qsgangleddirection/tst_qsgangleddirection.cpp | 3 +++ .../qsgcumulativedirection/tst_qsgcumulativedirection.cpp | 3 +++ .../particles/qsgcustomaffector/tst_qsgcustomaffector.cpp | 5 +++-- .../particles/qsgcustomparticle/tst_qsgcustomparticle.cpp | 3 +++ .../qsgellipseextruder/tst_qsgellipseextruder.cpp | 6 ++++++ tests/auto/particles/qsgfriction/tst_qsgfriction.cpp | 6 ++++++ tests/auto/particles/qsggravity/tst_qsggravity.cpp | 3 +++ .../particles/qsgimageparticle/tst_qsgimageparticle.cpp | 3 +++ .../auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp | 3 +++ .../auto/particles/qsglineextruder/tst_qsglineextruder.cpp | 6 ++++++ .../auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp | 3 +++ .../particles/qsgparticlegroup/tst_qsgparticlegroup.cpp | 3 +++ .../particles/qsgparticlesystem/tst_qsgparticlesystem.cpp | 7 +++++++ .../particles/qsgpointattractor/tst_qsgpointattractor.cpp | 3 +++ .../particles/qsgpointdirection/tst_qsgpointdirection.cpp | 3 +++ .../qsgrectangleextruder/tst_qsgrectangleextruder.cpp | 6 ++++++ .../qsgtargetdirection/tst_qsgtargetdirection.cpp | 3 +++ .../auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp | 6 ++++++ tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp | 3 +++ tests/auto/particles/qsgwander/tst_qsgwander.cpp | 3 +++ 21 files changed, 89 insertions(+), 6 deletions(-) diff --git a/tests/auto/particles/qsgage/tst_qsgage.cpp b/tests/auto/particles/qsgage/tst_qsgage.cpp index 45267e5..b58d455 100644 --- a/tests/auto/particles/qsgage/tst_qsgage.cpp +++ b/tests/auto/particles/qsgage/tst_qsgage.cpp @@ -67,8 +67,9 @@ void tst_qsgage::test_kill() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) //Recycler out-smarted me and never needed to init this datum - continue; + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, 0.f); QCOMPARE(d->y, 0.f); QCOMPARE(d->vx, 1000.f); @@ -89,6 +90,9 @@ void tst_qsgage::test_jump() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + //Allow for a small variance because jump is trying to simulate off wall time extremelyFuzzyCompare(d->x, -100.f, 5.0f); extremelyFuzzyCompare(d->y, -100.f, 5.0f); @@ -111,7 +115,8 @@ void tst_qsgage::test_onceOff() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { if (d->t == -1) - continue; //Recycling process means not all initialized/used + continue; //Particle data unused + QCOMPARE(d->x, 0.f); QCOMPARE(d->y, 0.f); QCOMPARE(d->vx, 500.f); @@ -133,7 +138,8 @@ void tst_qsgage::test_sustained() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { if (d->t == -1) - continue; //Recycling process means not all initialized/used + continue; //Particle data unused + QCOMPARE(d->x, 0.f); QCOMPARE(d->y, 0.f); QCOMPARE(d->vx, 500.f); diff --git a/tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp b/tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp index 4e65fa4..ea1d4ee 100644 --- a/tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp +++ b/tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp @@ -65,6 +65,9 @@ void tst_qsgangleddirection::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, 0.f); QCOMPARE(d->y, 0.f); QVERIFY(qFuzzyCompare(d->vx, 353.55339f)); diff --git a/tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp b/tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp index 1c4e98c..678b749 100644 --- a/tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp +++ b/tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp @@ -64,6 +64,9 @@ void tst_qsgcumulativedirection::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QVERIFY(myFuzzyCompare(d->x, 0.0f)); QVERIFY(myFuzzyCompare(d->y, 0.0f)); QVERIFY(myFuzzyCompare(d->vx, 0.0f)); diff --git a/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp b/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp index 2a7e978..d5ae596 100644 --- a/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp +++ b/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp @@ -64,8 +64,9 @@ void tst_qsgcustomaffector::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) //Recycler out-smarted me and never needed to init this datum - continue; + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, 100.f); QCOMPARE(d->y, 100.f); QCOMPARE(d->vx, 100.f); diff --git a/tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp b/tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp index 01d557d..239a135 100644 --- a/tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp +++ b/tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp @@ -66,6 +66,9 @@ void tst_qsgcustomparticle::test_basic() bool oneNonZero = false; QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, 0.f); QCOMPARE(d->y, 0.f); QCOMPARE(d->vx, 0.f); diff --git a/tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp b/tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp index a5aa91b..02b2173 100644 --- a/tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp +++ b/tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp @@ -81,6 +81,9 @@ void tst_qsgellipseextruder::test_basic() //Filled QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QVERIFY(inCircle(d->x, d->y, 160, false)); QCOMPARE(d->vx, 0.f); QCOMPARE(d->vy, 0.f); @@ -94,6 +97,9 @@ void tst_qsgellipseextruder::test_basic() //Just border QCOMPARE(system->groupData[1]->size(), 500); foreach (QSGParticleData *d, system->groupData[1]->data) { + if (d->t == -1) + continue; //Particle data unused + QVERIFY(inCircle(d->x, d->y, 160, true)); QCOMPARE(d->vx, 0.f); QCOMPARE(d->vy, 0.f); diff --git a/tests/auto/particles/qsgfriction/tst_qsgfriction.cpp b/tests/auto/particles/qsgfriction/tst_qsgfriction.cpp index c56e004..2d835de 100644 --- a/tests/auto/particles/qsgfriction/tst_qsgfriction.cpp +++ b/tests/auto/particles/qsgfriction/tst_qsgfriction.cpp @@ -65,6 +65,9 @@ void tst_qsgfriction::test_basic() //Default is just slowed a little QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QVERIFY(d->vx < 100.f); QCOMPARE(d->y, 0.f); QCOMPARE(d->vy, 0.f); @@ -79,6 +82,9 @@ void tst_qsgfriction::test_basic() //Nondefault comes to a complete stop within the first half of its life QCOMPARE(system->groupData[1]->size(), 500); foreach (QSGParticleData *d, system->groupData[1]->data) { + if (d->t == -1) + continue; //Particle data unused + if (d->t > ((qreal)system->timeInt/1000.0) - 0.25) continue; QVERIFY(myFuzzyCompare(d->vx, 0.f)); diff --git a/tests/auto/particles/qsggravity/tst_qsggravity.cpp b/tests/auto/particles/qsggravity/tst_qsggravity.cpp index e99aa1e..e30d261 100644 --- a/tests/auto/particles/qsggravity/tst_qsggravity.cpp +++ b/tests/auto/particles/qsggravity/tst_qsggravity.cpp @@ -64,6 +64,9 @@ void tst_qsggravity::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->ax, 707.10678f); QCOMPARE(d->ay, 707.10678f); QCOMPARE(d->lifeSpan, 0.5f); diff --git a/tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp b/tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp index 423e842..e46dc4a 100644 --- a/tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp +++ b/tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp @@ -64,6 +64,9 @@ void tst_qsgimageparticle::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, 0.f); QCOMPARE(d->y, 0.f); QCOMPARE(d->vx, 0.f); diff --git a/tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp b/tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp index 2d18764..f2307ed 100644 --- a/tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp +++ b/tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp @@ -65,6 +65,9 @@ void tst_qsgitemparticle::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, 0.f); QCOMPARE(d->y, 0.f); QCOMPARE(d->vx, 0.f); diff --git a/tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp b/tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp index 602985b..2d43f7b 100644 --- a/tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp +++ b/tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp @@ -64,6 +64,9 @@ void tst_qsglineextruder::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, d->y); QCOMPARE(d->vx, 0.f); QCOMPARE(d->vy, 0.f); @@ -77,6 +80,9 @@ void tst_qsglineextruder::test_basic() QCOMPARE(system->groupData[1]->size(), 500); foreach (QSGParticleData *d, system->groupData[1]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x + d->y, 320.0f); QCOMPARE(d->vx, 0.f); QCOMPARE(d->vy, 0.f); diff --git a/tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp b/tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp index 483ad93..cdd5808 100644 --- a/tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp +++ b/tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp @@ -64,6 +64,9 @@ void tst_qsgmaskextruder::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QVERIFY(d->x >= 100.0f && d->x <= 200.0f); QVERIFY(d->y >= 100.0f && d->y <= 200.0f); QCOMPARE(d->vx, 0.f); diff --git a/tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp b/tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp index 5cf170c..fd1709b 100644 --- a/tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp +++ b/tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp @@ -65,6 +65,9 @@ void tst_qsgparticlegroup::test_instantTransition() //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); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, 0.f); QCOMPARE(d->y, 0.f); QCOMPARE(d->vx, 0.f); diff --git a/tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp b/tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp index cf00a00..ade9ca9 100644 --- a/tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp +++ b/tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp @@ -63,7 +63,13 @@ void tst_qsgparticlesystem::test_basic() QSGParticleSystem* system = view->rootObject()->findChild("system"); QCOMPARE(system->groupData[0]->size(), 500); + int stillAlive = 0; foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + if (d->stillAlive()) + stillAlive++; QCOMPARE(d->x, 0.f); QCOMPARE(d->y, 0.f); QCOMPARE(d->vx, 0.f); @@ -75,6 +81,7 @@ void tst_qsgparticlesystem::test_basic() QCOMPARE(d->endSize, 32.f); QVERIFY(d->t <= ((qreal)system->timeInt/1000.0)); } + QVERIFY(extremelyFuzzyCompare(stillAlive, 500, 5));//Small simulation variance is permissible. } QTEST_MAIN(tst_qsgparticlesystem); diff --git a/tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp b/tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp index 40877c4..ef3b06a 100644 --- a/tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp +++ b/tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp @@ -64,6 +64,9 @@ void tst_qsgpointattractor::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QVERIFY(d->x != 0.f); QVERIFY(d->y != 0.f); QVERIFY(d->x == d->y); diff --git a/tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp b/tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp index 56ef9cb..4752f1c 100644 --- a/tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp +++ b/tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp @@ -64,6 +64,9 @@ void tst_qsgpointdirection::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, 0.f); QCOMPARE(d->y, 0.f); QCOMPARE(d->vx, 100.f); diff --git a/tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp b/tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp index 80def8b..b8cda61 100644 --- a/tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp +++ b/tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp @@ -64,6 +64,9 @@ void tst_qsgrectangleextruder::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QVERIFY(d->x >= 0.f); QVERIFY(d->x <= 100.f); QVERIFY(d->y >= 0.f); @@ -80,6 +83,9 @@ void tst_qsgrectangleextruder::test_basic() QCOMPARE(system->groupData[1]->size(), 500); foreach (QSGParticleData *d, system->groupData[1]->data) { + if (d->t == -1) + continue; //Particle data unused + if (!myFuzzyCompare(d->x, 0.f) && !myFuzzyCompare(d->x, 100.f)){ QVERIFY(d->x >= 0.f); QVERIFY(d->x <= 100.f); diff --git a/tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp b/tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp index 642ef28..0f37fc0 100644 --- a/tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp +++ b/tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp @@ -64,6 +64,9 @@ void tst_qsgtargetdirection::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, 0.f); QCOMPARE(d->y, 0.f); QCOMPARE(d->vx, 160.f); diff --git a/tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp b/tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp index e6073ef..29e9d90 100644 --- a/tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp +++ b/tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp @@ -64,6 +64,9 @@ void tst_qsgtrailemitter::test_basic() QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, 4.f); QCOMPARE(d->y, 4.f); QCOMPARE(d->vx, 0.f); @@ -78,6 +81,9 @@ void tst_qsgtrailemitter::test_basic() QCOMPARE(system->groupData[1]->size(), 500); foreach (QSGParticleData *d, system->groupData[1]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->x, 4.f); QCOMPARE(d->y, 4.f); QCOMPARE(d->vx, 500.f); diff --git a/tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp b/tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp index 202de29..155b109 100644 --- a/tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp +++ b/tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp @@ -66,6 +66,9 @@ void tst_qsgturbulence::test_basic() //of the Turbulence item remain the same QCOMPARE(system->groupData[0]->size(), 500); foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QVERIFY(d->vx != 0.f); QVERIFY(d->vy != 0.f); QCOMPARE(d->lifeSpan, 0.5f); diff --git a/tests/auto/particles/qsgwander/tst_qsgwander.cpp b/tests/auto/particles/qsgwander/tst_qsgwander.cpp index 6e7bc17..0a73248 100644 --- a/tests/auto/particles/qsgwander/tst_qsgwander.cpp +++ b/tests/auto/particles/qsgwander/tst_qsgwander.cpp @@ -68,6 +68,9 @@ void tst_qsgwander::test_basic() bool vxChanged = false; bool vyChanged = false; foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + QCOMPARE(d->ax, 0.f); QCOMPARE(d->ay, 0.f); QCOMPARE(d->lifeSpan, 0.5f); -- 2.7.4