diff options
Diffstat (limited to 'tests/auto/corelib/tools/qline/tst_qline.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qline/tst_qline.cpp | 89 |
1 files changed, 53 insertions, 36 deletions
diff --git a/tests/auto/corelib/tools/qline/tst_qline.cpp b/tests/auto/corelib/tools/qline/tst_qline.cpp index f4ac51fc24..51f1f8ac79 100644 --- a/tests/auto/corelib/tools/qline/tst_qline.cpp +++ b/tests/auto/corelib/tools/qline/tst_qline.cpp @@ -1,35 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> #include <qline.h> #include <qmath.h> +#include <array> + class tst_QLine : public QObject { Q_OBJECT @@ -58,6 +35,9 @@ private slots: void testAngleTo_data(); void testSet(); + + void toLineF_data(); + void toLineF(); }; const qreal epsilon = sizeof(qreal) == sizeof(double) ? 1e-8 : 1e-4; @@ -247,8 +227,8 @@ void tst_QLine::testLength_data() << -(tiny * .5) << -(tiny * .5) << (tiny * .5) << (tiny * .5) << (tiny * M_SQRT2) << (2 * M_SQRT2) << 2.0 << 2.0; QTest::newRow("[1+3e-13,1+4e-13]|1895| (1, 1)") - << 1.0 << 1.0 << (1 + 3e-13) << (1 + 4e-13) // isNull(), so ignores setLength() - << 5e-13 << 1895.0 << 3e-13 << 4e-13; + << 1.0 << 1.0 << (1 + 3e-13) << (1 + 4e-13) + << 5e-13 << 1895.0 << 1137.0 << 1516.0; QTest::newRow("[4e-323,5e-324]|1892|") // Unavoidable underflow: denormals << 0.0 << 0.0 << 4e-323 << 5e-324 << 4e-323 << 1892.0 << 4e-323 << 5e-324; // vx, vy values ignored @@ -266,14 +246,21 @@ void tst_QLine::testLength() QFETCH(double, vy); QLineF l(x1, y1, x2, y2); - const bool wasNull = l.isNull(); - if (!wasNull) - QCOMPARE(l.length(), qreal(length)); + QCOMPARE(l.length(), qreal(length)); l.setLength(lengthToSet); - QCOMPARE(l.length(), wasNull ? qreal(length) : qreal(lengthToSet)); + + if constexpr (std::numeric_limits<double>::has_denorm != std::denorm_present) { + if (qstrcmp(QTest::currentDataTag(), "[tiny,tiny]->|2| (-tiny/2,-tiny/2)") == 0 + || qstrcmp(QTest::currentDataTag(), "[4e-323,5e-324]|1892|") == 0) { + QSKIP("Skipping 'denorm' as this type lacks denormals on this system"); + } + } // Scaling tiny values up to big can be imprecise: don't try to test vx, vy - if (wasNull || !qFuzzyIsNull(length)) { + if (length > 0 && qFuzzyIsNull(length)) { + QVERIFY(l.length() > lengthToSet / 2 && l.length() < lengthToSet * 2); + } else { + QCOMPARE(l.length(), length > 0 ? qreal(lengthToSet) : qreal(length)); QCOMPARE(l.dx(), qreal(vx)); QCOMPARE(l.dy(), qreal(vy)); } @@ -495,5 +482,35 @@ void tst_QLine::testAngleTo_data() } } +void tst_QLine::toLineF_data() +{ + QTest::addColumn<QLine>("input"); + QTest::addColumn<QLineF>("result"); + + auto row = [](int x1, int y1, int x2, int y2) { + QTest::addRow("((%d, %d)->(%d, %d))", x1, y1, x2, y2) + << QLine(x1, y1, x2, y2) << QLineF(x1, y1, x2, y2); + }; + constexpr std::array samples = {-1, 0, 1}; + for (int x1 : samples) { + for (int y1 : samples) { + for (int x2 : samples) { + for (int y2 : samples) { + row(x1, y1, x2, y2); + } + } + } + } +} + +void tst_QLine::toLineF() +{ + QFETCH(const QLine, input); + QFETCH(const QLineF, result); + + QCOMPARE(input.toLineF(), result); +} + + QTEST_MAIN(tst_QLine) #include "tst_qline.moc" |