summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-04-15 13:10:31 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2020-04-30 13:44:08 +0200
commitc78a960198d59fb9a9ddd83ad7098b1db396edfd (patch)
tree3e8eec0b57cd67796743ebb56fa883ca24ee2f69 /src/testlib/qtestcase.cpp
parent91d18c646443c812addf6d1cdada99d3c2d3a3ec (diff)
QCOMPARE: treat values as equal if qFuzzyIsNull(each)
We hope this shall avoid some flaky failures noticed in quick tests, e.g. tst_QQuickMenu::Material::subMenuPosition(cascading,flip) was recently seen failing with 3.88e-11 != 0. This required some revision to test data in the testlib selftest for floats; the resulting expected output differs in details but not in which tests pass or fail. QEMU, naturally, made life difficult, requiring special-case code in the test-driver. [ChangeLog][QtTestLib][QCOMPARE] QCOMPARE() now treats its values as equal when qFuzzyIsNull() is true for both of them. Change-Id: Icc6ad5164b609937eddbe39cc69120f0abf0f3b4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index f45999c7fa..74507c11e1 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
@@ -2525,16 +2525,21 @@ bool QTest::compare_helper(bool success, const char *failureMsg,
}
template <typename T>
-static bool floatingCompare(const T &t1, const T &t2)
+static bool floatingCompare(const T &actual, const T &expected)
{
- switch (qFpClassify(t1))
+ switch (qFpClassify(expected))
{
case FP_INFINITE:
- return (t1 < 0) == (t2 < 0) && qFpClassify(t2) == FP_INFINITE;
+ return (expected < 0) == (actual < 0) && qFpClassify(actual) == FP_INFINITE;
case FP_NAN:
- return qFpClassify(t2) == FP_NAN;
+ return qFpClassify(actual) == FP_NAN;
default:
- return qFuzzyCompare(t1, t2);
+ if (!qFuzzyIsNull(expected))
+ return qFuzzyCompare(actual, expected);
+ Q_FALLTHROUGH();
+ case FP_SUBNORMAL: // subnormal is always fuzzily null
+ case FP_ZERO:
+ return qFuzzyIsNull(actual);
}
}