diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/tools/qpoint/tst_qpoint.cpp | 59 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qpointf/tst_qpointf.cpp | 60 |
2 files changed, 119 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp index 0f3edb3eed..59ea28454e 100644 --- a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp +++ b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp @@ -75,6 +75,8 @@ private slots: void stream_data(); void stream(); #endif + + void structuredBinding(); }; void tst_QPoint::isNull() @@ -381,5 +383,62 @@ void tst_QPoint::stream() } #endif +void tst_QPoint::structuredBinding() +{ + { + QPoint p(1, 2); + auto [x, y] = p; + QCOMPARE(x, 1); + QCOMPARE(y, 2); + + p.setX(42); + QCOMPARE(x, 1); + QCOMPARE(y, 2); + + p.setY(-123); + QCOMPARE(x, 1); + QCOMPARE(y, 2); + } + { + QPoint p(1, 2); + + auto &[x, y] = p; + QCOMPARE(x, 1); + QCOMPARE(y, 2); + + x = 42; + QCOMPARE(x, 42); + QCOMPARE(p.x(), 42); + QCOMPARE(p.rx(), 42); + QCOMPARE(y, 2); + QCOMPARE(p.y(), 2); + QCOMPARE(p.ry(), 2); + + y = -123; + QCOMPARE(x, 42); + QCOMPARE(p.x(), 42); + QCOMPARE(p.rx(), 42); + QCOMPARE(y, -123); + QCOMPARE(p.y(), -123); + QCOMPARE(p.ry(), -123); + + p.setX(0); + QCOMPARE(x, 0); + QCOMPARE(p.x(), 0); + QCOMPARE(p.rx(), 0); + QCOMPARE(y, -123); + QCOMPARE(p.y(), -123); + QCOMPARE(p.ry(), -123); + + p.ry() = 10; + QCOMPARE(x, 0); + QCOMPARE(p.x(), 0); + QCOMPARE(p.rx(), 0); + QCOMPARE(y, 10); + QCOMPARE(p.y(), 10); + QCOMPARE(p.ry(), 10); + } +} + QTEST_MAIN(tst_QPoint) #include "tst_qpoint.moc" diff --git a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp index ef08352dfc..21b9d56737 100644 --- a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp +++ b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp @@ -86,6 +86,8 @@ private slots: void stream(); #endif + void structuredBinding(); + private: const qreal QREAL_MIN; const qreal QREAL_MAX; @@ -462,5 +464,63 @@ void tst_QPointF::compare() QVERIFY(QPointF(1.9543e-14, -32.0) == QPointF(0.0, -32.0)); } + +void tst_QPointF::structuredBinding() +{ + { + QPointF p(1.5, 2.25); + auto [x, y] = p; + QCOMPARE(x, 1.5); + QCOMPARE(y, 2.25); + + p.setX(42); + QCOMPARE(x, 1.5); + QCOMPARE(y, 2.25); + + p.setY(-123); + QCOMPARE(x, 1.5); + QCOMPARE(y, 2.25); + } + { + QPointF p(1.5, 2.25); + + auto &[x, y] = p; + QCOMPARE(x, 1.5); + QCOMPARE(y, 2.25); + + x = 42.0; + QCOMPARE(x, 42.0); + QCOMPARE(p.x(), 42.0); + QCOMPARE(p.rx(), 42.0); + QCOMPARE(y, 2.25); + QCOMPARE(p.y(), 2.25); + QCOMPARE(p.ry(), 2.25); + + y = -123.5; + QCOMPARE(x, 42.0); + QCOMPARE(p.x(), 42.0); + QCOMPARE(p.rx(), 42.0); + QCOMPARE(y, -123.5); + QCOMPARE(p.y(), -123.5); + QCOMPARE(p.ry(), -123.5); + + p.setX(0.0); + QCOMPARE(x, 0.0); + QCOMPARE(p.x(), 0.0); + QCOMPARE(p.rx(), 0.0); + QCOMPARE(y, -123.5); + QCOMPARE(p.y(), -123.5); + QCOMPARE(p.ry(), -123.5); + + p.ry() = 10.5; + QCOMPARE(x, 0.0); + QCOMPARE(p.x(), 0.0); + QCOMPARE(p.rx(), 0.0); + QCOMPARE(y, 10.5); + QCOMPARE(p.y(), 10.5); + QCOMPARE(p.ry(), 10.5); + } +} + QTEST_MAIN(tst_QPointF) #include "tst_qpointf.moc" |