summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-03-18 08:16:20 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-03-19 12:02:24 +0100
commit5dc570f8b16debfda916b10bb1235aeea9650699 (patch)
tree3bfbd47a4b67f108fef975436d80341880488ccc /tests/auto/corelib/tools
parent2fb0135efa97708025dab7654a8b2f1350dc30bf (diff)
QLine/QMargins: add toLineF/toMarginsF()
For symmetry with QLineF::toLine(). [ChangeLog][QtCore][QLine] Added toLineF(). [ChangeLog][QtCore][QMargins] Added toMarginsF(). Task-number: QTBUG-73160 Change-Id: I69051cdd2fe4a3c0a000ab86e363a2918a7aea7c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qline/tst_qline.cpp37
-rw-r--r--tests/auto/corelib/tools/qmargins/tst_qmargins.cpp36
2 files changed, 71 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qline/tst_qline.cpp b/tests/auto/corelib/tools/qline/tst_qline.cpp
index 67e71dfb26..288962b3b6 100644
--- a/tests/auto/corelib/tools/qline/tst_qline.cpp
+++ b/tests/auto/corelib/tools/qline/tst_qline.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -30,6 +30,8 @@
#include <qline.h>
#include <qmath.h>
+#include <array>
+
class tst_QLine : public QObject
{
Q_OBJECT
@@ -58,6 +60,9 @@ private slots:
void testAngleTo_data();
void testSet();
+
+ void toLineF_data();
+ void toLineF();
};
const qreal epsilon = sizeof(qreal) == sizeof(double) ? 1e-8 : 1e-4;
@@ -502,5 +507,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"
diff --git a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
index 8eaa4edd3b..8267e5d0e0 100644
--- a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
+++ b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -29,6 +29,8 @@
#include <QTest>
#include <qmargins.h>
+#include <array>
+
Q_DECLARE_METATYPE(QMargins)
class tst_QMargins : public QObject
@@ -54,6 +56,9 @@ private slots:
#endif
void structuredBinding();
+
+ void toMarginsF_data();
+ void toMarginsF();
};
// Testing get/set functions
@@ -339,5 +344,34 @@ void tst_QMargins::structuredBinding()
}
}
+void tst_QMargins::toMarginsF_data()
+{
+ QTest::addColumn<QMargins>("input");
+ QTest::addColumn<QMarginsF>("result");
+
+ auto row = [](int x1, int y1, int x2, int y2) {
+ QTest::addRow("(%d, %d, %d, %d)", x1, y1, x2, y2)
+ << QMargins(x1, y1, x2, y2) << QMarginsF(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_QMargins::toMarginsF()
+{
+ QFETCH(const QMargins, input);
+ QFETCH(const QMarginsF, result);
+
+ QCOMPARE(input.toMarginsF(), result);
+}
+
QTEST_APPLESS_MAIN(tst_QMargins)
#include "tst_qmargins.moc"