From a1d2c2708697cd8e2b3ade2b204c3f618b0c135d Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Wed, 11 Jul 2012 11:50:47 +1000 Subject: [PATCH] Fix test for value type interceptors. In release mode, floating point inaccuracies can cause this test to fail. Use a fuzzy compare since it doesn't affect what the test is actually trying to check for. Change-Id: I5e3d073614090450216c33fcc561a7454cf44ac3 Reviewed-by: Chris Adams --- .../auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index f038b9d..af5e914 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -1365,6 +1365,12 @@ void tst_qqmlvaluetypes::groupedInterceptors_data() QTest::newRow("ignore-interceptor") << QString::fromLatin1("grouped_interceptors_ignore.qml") << QColor(128, 0, 255) << QColor(50, 100, 200) << QColor(128, 100, 200); } +static bool fuzzyCompare(qreal a, qreal b) +{ + const qreal EPSILON = 0.0001; + return (a + EPSILON > b) && (a - EPSILON < b); +} + void tst_qqmlvaluetypes::groupedInterceptors() { QFETCH(QString, qmlfile); @@ -1377,12 +1383,18 @@ void tst_qqmlvaluetypes::groupedInterceptors() QVERIFY(object != 0); QColor initialColor = object->property("color").value(); - QCOMPARE(initialColor, expectedInitialColor); + QVERIFY(fuzzyCompare(initialColor.redF(), expectedInitialColor.redF())); + QVERIFY(fuzzyCompare(initialColor.greenF(), expectedInitialColor.greenF())); + QVERIFY(fuzzyCompare(initialColor.blueF(), expectedInitialColor.blueF())); + QVERIFY(fuzzyCompare(initialColor.alphaF(), expectedInitialColor.alphaF())); object->setProperty("color", setColor); QColor finalColor = object->property("color").value(); - QCOMPARE(finalColor, expectedFinalColor); + QVERIFY(fuzzyCompare(finalColor.redF(), expectedFinalColor.redF())); + QVERIFY(fuzzyCompare(finalColor.greenF(), expectedFinalColor.greenF())); + QVERIFY(fuzzyCompare(finalColor.blueF(), expectedFinalColor.blueF())); + QVERIFY(fuzzyCompare(finalColor.alphaF(), expectedFinalColor.alphaF())); delete object; } -- 1.7.2.5