summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/math3d
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-02-24 19:44:09 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-02-25 16:08:44 +0100
commit0e22001a3bb070d4e9956e89543ec0e5ac6f23f8 (patch)
tree54904ff96f88f3bebb98e59b308d30daf9cb02d3 /tests/auto/gui/math3d
parent2af45d0cee253a6bc4e6807076445439cc69c2ce (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/gui/math3d')
-rw-r--r--tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp
index 9d3f7dda7c..c7bcb9d262 100644
--- a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp
+++ b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp
@@ -152,6 +152,8 @@ private slots:
void properties();
void metaTypes();
+
+ void structuredBinding();
};
// Test the creation of QVector2D objects in various ways:
@@ -2682,6 +2684,73 @@ void tst_QVectorND::metaTypes()
QCOMPARE(qMetaTypeId<QVector4D>(), int(QMetaType::QVector4D));
}
+void tst_QVectorND::structuredBinding()
+{
+ {
+ QVector2D v(1.0f, 2.0f);
+ auto [x, y] = v;
+ QCOMPARE(x, 1.0f);
+ QCOMPARE(y, 2.0f);
+ }
+ {
+ QVector2D v(1.0f, 2.0f);
+ auto &[x, y] = v;
+ QCOMPARE(x, 1.0f);
+ QCOMPARE(y, 2.0f);
+
+ x = 10.0f;
+ y = 20.0f;
+ QCOMPARE(v.x(), 10.0f);
+ QCOMPARE(v.y(), 20.0f);
+ }
+ {
+ QVector3D v(1.0f, 2.0f, 3.0);
+ auto [x, y, z] = v;
+ QCOMPARE(x, 1.0f);
+ QCOMPARE(y, 2.0f);
+ QCOMPARE(z, 3.0f);
+ }
+ {
+ QVector3D v(1.0f, 2.0f, 3.0);
+ auto &[x, y, z] = v;
+ QCOMPARE(x, 1.0f);
+ QCOMPARE(y, 2.0f);
+ QCOMPARE(z, 3.0f);
+
+ x = 10.0f;
+ y = 20.0f;
+ z = 30.0f;
+ QCOMPARE(v.x(), 10.0f);
+ QCOMPARE(v.y(), 20.0f);
+ QCOMPARE(v.z(), 30.0f);
+ }
+ {
+ QVector4D v(1.0f, 2.0f, 3.0, 4.0);
+ auto [x, y, z, w] = v;
+ QCOMPARE(x, 1.0f);
+ QCOMPARE(y, 2.0f);
+ QCOMPARE(z, 3.0f);
+ QCOMPARE(w, 4.0f);
+ }
+ {
+ QVector4D v(1.0f, 2.0f, 3.0, 4.0);
+ auto &[x, y, z, w] = v;
+ QCOMPARE(x, 1.0f);
+ QCOMPARE(y, 2.0f);
+ QCOMPARE(z, 3.0f);
+ QCOMPARE(w, 4.0f);
+
+ x = 10.0f;
+ y = 20.0f;
+ z = 30.0f;
+ w = 40.0f;
+ QCOMPARE(v.x(), 10.0f);
+ QCOMPARE(v.y(), 20.0f);
+ QCOMPARE(v.z(), 30.0f);
+ QCOMPARE(v.w(), 40.0f);
+ }
+}
+
QTEST_APPLESS_MAIN(tst_QVectorND)
#include "tst_qvectornd.moc"