diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-02-24 19:44:09 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-02-25 16:08:44 +0100 |
commit | 0e22001a3bb070d4e9956e89543ec0e5ac6f23f8 (patch) | |
tree | 54904ff96f88f3bebb98e59b308d30daf9cb02d3 /tests/auto/corelib/tools | |
parent | 2af45d0cee253a6bc4e6807076445439cc69c2ce (diff) |
Add more support for structured bindings
After QPoint(F), it's now the time of QSize(F) and QVectorND,
which can be unambiguously decomposed.
[ChangeLog][QtCore][QSize] QSize is now usable in a structured
binding declaration.
[ChangeLog][QtCore][QSizeF] QSizeF is now usable in a structured
binding declaration.
[ChangeLog][QtGui][QVector2D] QVector2D is now usable in a
structured binding declaration.
[ChangeLog][QtGui][QVector3D] QVector3D is now usable in a
structured binding declaration.
[ChangeLog][QtGui][QVector4D] QVector4D is now usable in a
structured binding declaration.
Change-Id: I67bb152f4210f2be27607179cd2ec522174cc483
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r-- | tests/auto/corelib/tools/qsize/tst_qsize.cpp | 23 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qsizef/tst_qsizef.cpp | 23 |
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qsize/tst_qsize.cpp b/tests/auto/corelib/tools/qsize/tst_qsize.cpp index 1bac2bd19b..83b4f1bd34 100644 --- a/tests/auto/corelib/tools/qsize/tst_qsize.cpp +++ b/tests/auto/corelib/tools/qsize/tst_qsize.cpp @@ -49,6 +49,8 @@ private slots: void transpose_data(); void transpose(); + + void structuredBinding(); }; // Testing get/set functions @@ -250,5 +252,26 @@ void tst_QSize::transpose() QCOMPARE(input1 , expected); } +void tst_QSize::structuredBinding() +{ + { + QSize size(10, 20); + auto [width, height] = size; + QCOMPARE(width, 10); + QCOMPARE(height, 20); + } + { + QSize size(30, 40); + auto &[width, height] = size; + QCOMPARE(width, 30); + QCOMPARE(height, 40); + + width = 100; + height = 200; + QCOMPARE(size.width(), 100); + QCOMPARE(size.height(), 200); + } +} + QTEST_APPLESS_MAIN(tst_QSize) #include "tst_qsize.moc" diff --git a/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp b/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp index af45c3c91f..3a65506dee 100644 --- a/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp +++ b/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp @@ -51,6 +51,8 @@ private slots: void transpose_data(); void transpose(); + + void structuredBinding(); }; void tst_QSizeF::isNull_data() @@ -214,5 +216,26 @@ void tst_QSizeF::transpose() { QCOMPARE(input1 , expected); } +void tst_QSizeF::structuredBinding() +{ + { + QSizeF size(10.0, 20.0); + auto [width, height] = size; + QCOMPARE(width, 10.0); + QCOMPARE(height, 20.0); + } + { + QSizeF size(30.0, 40.0); + auto &[width, height] = size; + QCOMPARE(width, 30.0); + QCOMPARE(height, 40.0); + + width = 100.0; + height = 200.0; + QCOMPARE(size.width(), 100.0); + QCOMPARE(size.height(), 200.0); + } +} + QTEST_APPLESS_MAIN(tst_QSizeF) #include "tst_qsizef.moc" |