summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2020-05-04 11:33:10 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-05-04 17:38:40 +0200
commit0f7987f0c934b311bd39a5a496ffb0c6128eb8df (patch)
treedea392deb3c43e377a224271c4f450dcff3fc76f /src/testlib
parentea7d85457d30e915ad470919d2e74867cba9cad8 (diff)
parentf0ea852d4dd6b3139869a952ee92e74cd367866d (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: src/corelib/text/qlocale.cpp src/network/access/qnetworkaccessmanager.cpp Regenerated tests/auto/testlib/selftests/float/CMakeLists.txt Change-Id: I5a8ae42511380ca49a38b13c6fa8a3c5df8bed01
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp2
-rw-r--r--src/testlib/qtestcase.cpp17
-rw-r--r--src/testlib/qtestcase.qdoc21
3 files changed, 22 insertions, 18 deletions
diff --git a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp
index eda0f430a1..cfa999a6f4 100644
--- a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp
+++ b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp
@@ -84,7 +84,7 @@ class TestQString : public QObject
void wrapInFunction()
{
//! [1]
-QVERIFY2(qIsNaN(0.0 / 0.0), "Ill-defined division produced unambiguous result.");
+QVERIFY2(QFileInfo("file.txt").exists(), "file.txt does not exist.");
//! [1]
//! [2]
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 8b5df06d82..e1da9e617c 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/
**
@@ -2541,16 +2541,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);
}
}
diff --git a/src/testlib/qtestcase.qdoc b/src/testlib/qtestcase.qdoc
index e4e1825bb5..72f8cdaf8c 100644
--- a/src/testlib/qtestcase.qdoc
+++ b/src/testlib/qtestcase.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@@ -109,19 +109,18 @@
continues. If not, a failure is recorded in the test log and the test
function returns without attempting any later checks.
- Always respect QCOMPARE() parameter semantics. The first parameter passed to it
- should always be the actual value produced by the code-under-test, while the
- second parameter should always be the expected value. When the values don't
- match, QCOMPARE() prints them with the labels \e Actual and \e Expected.
- If the parameter order is swapped, debugging a failing test can be confusing.
+ Always respect QCOMPARE() parameter semantics. The first parameter passed to
+ it should always be the actual value produced by the code-under-test, while
+ the second parameter should always be the expected value. When the values
+ don't match, QCOMPARE() prints them with the labels \e Actual and \e
+ Expected. If the parameter order is swapped, debugging a failing test can be
+ confusing and tests expecting zero may fail due to rounding errors.
When comparing floating-point types (\c float, \c double, and \c qfloat16),
- \l qFuzzyCompare() is used for finite values. Infinities match if they have
+ \l qFuzzyCompare() is used for finite values. If qFuzzyIsNull() is true for
+ both values, they are also considered equal. Infinities match if they have
the same sign, and any NaN as actual value matches with any NaN as expected
- value (even though NaN != NaN, even when they're identical). This means that
- expecting 0 can fail when the actual value may be affected by rounding errors.
- One solution to this is to offset both actual and expected values by adding
- some suitable constant (such as 1).
+ value (even though NaN != NaN, even when they're identical).
QCOMPARE() tries to output the contents of the values if the comparison fails,
so it is visible from the test log why the comparison failed.