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
commitc52ebb3aba3d771b908c03e3b171af64b6f9058a (patch)
treec43931b9124eabd149bad4a6125fd5b59f6718f2 /tests/auto/corelib/tools
parent5dc570f8b16debfda916b10bb1235aeea9650699 (diff)
QRect: add toRectF()
For symmetry with QRectF::toRect(). [ChangeLog][QtCore][QRect] Added toRectF(). Fixes: QTBUG-73160 Change-Id: If2bda64b8fe4bc113191dda927e9bb86ebcb4c69 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qrect/tst_qrect.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp
index 4057eb67fb..181cc8bbdb 100644
--- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp
+++ b/tests/auto/corelib/tools/qrect/tst_qrect.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.
@@ -32,6 +32,7 @@
#include <limits.h>
#include <qdebug.h>
+#include <array>
class tst_QRect : public QObject
{
@@ -124,6 +125,9 @@ private slots:
void margins();
void marginsf();
+ void toRectF_data();
+ void toRectF();
+
void translate_data();
void translate();
@@ -3536,6 +3540,39 @@ void tst_QRect::marginsf()
QCOMPARE(a, rectangle.marginsRemoved(margins));
}
+void tst_QRect::toRectF_data()
+{
+ QTest::addColumn<QRect>("input");
+ QTest::addColumn<QRectF>("result");
+
+ auto row = [](int x1, int y1, int w, int h) {
+ // QRectF -> QRect conversion tries to maintain size(), not bottomRight(),
+ // so compare in (topLeft(), size()) space
+ QTest::addRow("((%d, %d) (%dx%d))", x1, y1, w, h)
+ << QRect({x1, y1}, QSize{w, h}) << QRectF(QPointF(x1, y1), QSizeF(w, h));
+ };
+ constexpr std::array samples = {-1, 0, 1};
+ for (int x1 : samples) {
+ for (int y1 : samples) {
+ for (int w : samples) {
+ for (int h : samples) {
+ row(x1, y1, w, h);
+ }
+ }
+ }
+ }
+}
+
+void tst_QRect::toRectF()
+{
+ QFETCH(const QRect, input);
+ QFETCH(const QRectF, result);
+
+ QCOMPARE(result.toRect(), input); // consistency check
+ QCOMPARE(input.toRectF(), result);
+}
+
+
void tst_QRect::translate_data()
{
QTest::addColumn<QRect>("r");