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
commit2fb0135efa97708025dab7654a8b2f1350dc30bf (patch)
tree304e6abe32e206a656757a2a46eb7e4121ce57d6 /tests/auto/corelib/tools
parent98cbdae527b360e0e6d630848a375c6a025f572d (diff)
QSize/QPoint: add toSizeF/toPointF()
For symmetry with QSizeF::toSize(). [ChangeLog][QtCore][QSize] Added toSizeF(). [ChangeLog][QtCore][QPoint] Added toPointF(). Task-number: QTBUG-73160 Change-Id: I65b088b4f7365ab671ef2f0c75821b707f5ac26d 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/qpoint/tst_qpoint.cpp31
-rw-r--r--tests/auto/corelib/tools/qsize/tst_qsize.cpp31
2 files changed, 60 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
index 3ce8c3942d..30c4181d5f 100644
--- a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
+++ b/tests/auto/corelib/tools/qpoint/tst_qpoint.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.
@@ -31,6 +31,8 @@
#include <qpoint.h>
+#include <array>
+
class tst_QPoint : public QObject
{
Q_OBJECT
@@ -45,6 +47,9 @@ private slots:
void transposed();
+ void toPointF_data();
+ void toPointF();
+
void rx();
void ry();
@@ -131,6 +136,30 @@ void tst_QPoint::getSet()
QCOMPARE(point.y(), i);
}
+void tst_QPoint::toPointF_data()
+{
+ QTest::addColumn<QPoint>("input");
+ QTest::addColumn<QPointF>("result");
+
+ auto row = [](int x, int y) {
+ QTest::addRow("(%d, %d)", x, y) << QPoint(x, y) << QPointF(x, y);
+ };
+ constexpr std::array samples = {-1, 0, 1};
+ for (int x : samples) {
+ for (int y : samples) {
+ row(x, y);
+ }
+ }
+}
+
+void tst_QPoint::toPointF()
+{
+ QFETCH(const QPoint, input);
+ QFETCH(const QPointF, result);
+
+ QCOMPARE(input.toPointF(), result);
+}
+
void tst_QPoint::transposed()
{
QCOMPARE(QPoint(1, 2).transposed(), QPoint(2, 1));
diff --git a/tests/auto/corelib/tools/qsize/tst_qsize.cpp b/tests/auto/corelib/tools/qsize/tst_qsize.cpp
index 83b4f1bd34..80dc4ebaee 100644
--- a/tests/auto/corelib/tools/qsize/tst_qsize.cpp
+++ b/tests/auto/corelib/tools/qsize/tst_qsize.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 <qsize.h>
+#include <array>
+
Q_DECLARE_METATYPE(QMargins)
class tst_QSize : public QObject
@@ -47,6 +49,9 @@ private slots:
void grownOrShrunkBy_data();
void grownOrShrunkBy();
+ void toSizeF_data();
+ void toSizeF();
+
void transpose_data();
void transpose();
@@ -232,6 +237,30 @@ void tst_QSize::grownOrShrunkBy()
QCOMPARE(shrunk.grownBy(margins), input);
}
+void tst_QSize::toSizeF_data()
+{
+ QTest::addColumn<QSize>("input");
+ QTest::addColumn<QSizeF>("result");
+
+ auto row = [](int w, int h) {
+ QTest::addRow("(%d, %d)", w, h) << QSize(w, h) << QSizeF(w, h);
+ };
+ constexpr std::array samples = {-1, 0, 1};
+ for (int w : samples) {
+ for (int h : samples) {
+ row(w, h);
+ }
+ }
+}
+
+void tst_QSize::toSizeF()
+{
+ QFETCH(const QSize, input);
+ QFETCH(const QSizeF, result);
+
+ QCOMPARE(input.toSizeF(), result);
+}
+
void tst_QSize::transpose_data()
{
QTest::addColumn<QSize>("input1");