From 3928d53003220743eea19cd019b3754ab55094ba Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 14 Aug 2023 15:37:27 +0300 Subject: [PATCH] tst_QQuaternion: compile with QT_NO_FOREACH The size of the container is fixed, so use std::array. QQuaternion is basically four floats, so make the range-for var a value rather than a reference. Task-number: QTBUG-115839 Change-Id: I50b5aaa7daa6a4f10ff55c55ae54259c9aea03e9 Reviewed-by: Marc Mutz --- .../math3d/qquaternion/tst_qquaternion.cpp | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp index 8cdc06354e2..06b6ffc2700 100644 --- a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp +++ b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp @@ -1,8 +1,6 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses - #include #include #include @@ -970,19 +968,23 @@ void tst_QQuaternion::fromDirection_data() QTest::addColumn("direction"); QTest::addColumn("up"); - QList orientations; - orientations << QQuaternion(); + // 1 default constructed element + 360/45 loops, each adding 4 elements + constexpr int size = 1 + (360 / 45) * 4; + std::array orientations; + orientations[0] = {}; + int n = 0; for (int angle = 45; angle <= 360; angle += 45) { - orientations << QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), angle) - << QQuaternion::fromAxisAndAngle(QVector3D(0, 1, 0), angle) - << QQuaternion::fromAxisAndAngle(QVector3D(0, 0, 1), angle) - << QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), angle) - * QQuaternion::fromAxisAndAngle(QVector3D(0, 1, 0), angle) - * QQuaternion::fromAxisAndAngle(QVector3D(0, 0, 1), angle); + orientations[++n] = QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), angle); + orientations[++n] = QQuaternion::fromAxisAndAngle(QVector3D(0, 1, 0), angle); + orientations[++n] = QQuaternion::fromAxisAndAngle(QVector3D(0, 0, 1), angle); + orientations[++n] = QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), angle) + * QQuaternion::fromAxisAndAngle(QVector3D(0, 1, 0), angle) + * QQuaternion::fromAxisAndAngle(QVector3D(0, 0, 1), angle); } + QCOMPARE(n, size - 1); // othonormal up and dir - foreach (const QQuaternion &q, orientations) { + for (QQuaternion q : orientations) { QVector3D xAxis, yAxis, zAxis; q.getAxes(&xAxis, &yAxis, &zAxis); @@ -1004,7 +1006,7 @@ void tst_QQuaternion::fromDirection_data() QTest::newRow("dir: +X+Y+Z, up: -X-Y-Z") << QVector3D(10.0f, 10.0f, 10.0f) << QVector3D(-10.0f, -10.0f, -10.0f); // invalid up - foreach (const QQuaternion &q, orientations) { + for (QQuaternion q : orientations) { QVector3D xAxis, yAxis, zAxis; q.getAxes(&xAxis, &yAxis, &zAxis);