tst_QMatrixNxN: fix type-punning warning
... by making the test class a friend of the CUT, as we do elsewhere for the same reason. This allows to remove the duplicated enum and struct in favor of using The Real Thing™, which means the test can no longer go out of sync with the CUT anymore. Change-Id: I87dc8bb4a5476ae4fc99e006c4690e96d2f530d2 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
0ed1f8b54e
commit
bc1808794d
@ -47,6 +47,8 @@
|
||||
#include <QtGui/qgenericmatrix.h>
|
||||
#include <QtCore/qrect.h>
|
||||
|
||||
class tst_QMatrixNxN;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
@ -210,6 +212,8 @@ private:
|
||||
Flags flagBits;
|
||||
|
||||
QMatrix4x4 orthonormalInverse() const;
|
||||
|
||||
friend class ::tst_QMatrixNxN; // for access to flagBits
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QMatrix4x4::Flags)
|
||||
|
@ -2871,24 +2871,6 @@ void tst_QMatrixNxN::convertGeneric()
|
||||
QVERIFY(isSame(m10, conv4x4));
|
||||
}
|
||||
|
||||
// Copy of "flagBits" in qmatrix4x4.h.
|
||||
enum {
|
||||
Identity = 0x0000, // Identity matrix
|
||||
Translation = 0x0001, // Contains a translation
|
||||
Scale = 0x0002, // Contains a scale
|
||||
Rotation2D = 0x0004, // Contains a rotation about the Z axis
|
||||
Rotation = 0x0008, // Contains an arbitrary rotation
|
||||
Perspective = 0x0010, // Last row is different from (0, 0, 0, 1)
|
||||
General = 0x001f // General matrix, unknown contents
|
||||
};
|
||||
|
||||
// Structure that allows direct access to "flagBits" for testing.
|
||||
struct Matrix4x4
|
||||
{
|
||||
float m[4][4];
|
||||
int flagBits;
|
||||
};
|
||||
|
||||
// Test the inferring of special matrix types.
|
||||
void tst_QMatrixNxN::optimize_data()
|
||||
{
|
||||
@ -2896,11 +2878,11 @@ void tst_QMatrixNxN::optimize_data()
|
||||
QTest::addColumn<int>("flagBits");
|
||||
|
||||
QTest::newRow("null")
|
||||
<< (void *)nullValues4 << (int)General;
|
||||
<< (void *)nullValues4 << int{QMatrix4x4::General};
|
||||
QTest::newRow("identity")
|
||||
<< (void *)identityValues4 << (int)Identity;
|
||||
<< (void *)identityValues4 << int{QMatrix4x4::Identity};
|
||||
QTest::newRow("unique")
|
||||
<< (void *)uniqueValues4 << (int)General;
|
||||
<< (void *)uniqueValues4 << int{QMatrix4x4::General};
|
||||
|
||||
static float scaleValues[16] = {
|
||||
2.0f, 0.0f, 0.0f, 0.0f,
|
||||
@ -2909,7 +2891,7 @@ void tst_QMatrixNxN::optimize_data()
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
QTest::newRow("scale")
|
||||
<< (void *)scaleValues << (int)Scale;
|
||||
<< (void *)scaleValues << int{QMatrix4x4::Scale};
|
||||
|
||||
static float translateValues[16] = {
|
||||
1.0f, 0.0f, 0.0f, 2.0f,
|
||||
@ -2918,7 +2900,7 @@ void tst_QMatrixNxN::optimize_data()
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
QTest::newRow("translate")
|
||||
<< (void *)translateValues << (int)Translation;
|
||||
<< (void *)translateValues << int{QMatrix4x4::Translation};
|
||||
|
||||
static float scaleTranslateValues[16] = {
|
||||
1.0f, 0.0f, 0.0f, 2.0f,
|
||||
@ -2927,7 +2909,7 @@ void tst_QMatrixNxN::optimize_data()
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
QTest::newRow("scaleTranslate")
|
||||
<< (void *)scaleTranslateValues << (int)(Scale | Translation);
|
||||
<< (void *)scaleTranslateValues << int{QMatrix4x4::Scale | QMatrix4x4::Translation};
|
||||
|
||||
static float rotateValues[16] = {
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
@ -2936,7 +2918,7 @@ void tst_QMatrixNxN::optimize_data()
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
QTest::newRow("rotate")
|
||||
<< (void *)rotateValues << (int)Rotation2D;
|
||||
<< (void *)rotateValues << int{QMatrix4x4::Rotation2D};
|
||||
|
||||
// Left-handed system, not a simple rotation.
|
||||
static float scaleRotateValues[16] = {
|
||||
@ -2946,7 +2928,7 @@ void tst_QMatrixNxN::optimize_data()
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
QTest::newRow("scaleRotate")
|
||||
<< (void *)scaleRotateValues << (int)(Scale | Rotation2D);
|
||||
<< (void *)scaleRotateValues << int{QMatrix4x4::Scale | QMatrix4x4::Rotation2D};
|
||||
|
||||
static float matrix2x2Values[16] = {
|
||||
1.0f, 2.0f, 0.0f, 0.0f,
|
||||
@ -2955,7 +2937,7 @@ void tst_QMatrixNxN::optimize_data()
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
QTest::newRow("matrix2x2")
|
||||
<< (void *)matrix2x2Values << (int)(Scale | Rotation2D);
|
||||
<< (void *)matrix2x2Values << int{QMatrix4x4::Scale | QMatrix4x4::Rotation2D};
|
||||
|
||||
static float matrix3x3Values[16] = {
|
||||
1.0f, 2.0f, 4.0f, 0.0f,
|
||||
@ -2964,7 +2946,7 @@ void tst_QMatrixNxN::optimize_data()
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
QTest::newRow("matrix3x3")
|
||||
<< (void *)matrix3x3Values << (int)(Scale | Rotation2D | Rotation);
|
||||
<< (void *)matrix3x3Values << int{QMatrix4x4::Scale | QMatrix4x4::Rotation2D | QMatrix4x4::Rotation};
|
||||
|
||||
static float rotateTranslateValues[16] = {
|
||||
0.0f, 1.0f, 0.0f, 1.0f,
|
||||
@ -2973,7 +2955,7 @@ void tst_QMatrixNxN::optimize_data()
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
QTest::newRow("rotateTranslate")
|
||||
<< (void *)rotateTranslateValues << (int)(Translation | Rotation2D);
|
||||
<< (void *)rotateTranslateValues << int{QMatrix4x4::Translation | QMatrix4x4::Rotation2D};
|
||||
|
||||
// Left-handed system, not a simple rotation.
|
||||
static float scaleRotateTranslateValues[16] = {
|
||||
@ -2983,7 +2965,7 @@ void tst_QMatrixNxN::optimize_data()
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
QTest::newRow("scaleRotateTranslate")
|
||||
<< (void *)scaleRotateTranslateValues << (int)(Translation | Scale | Rotation2D);
|
||||
<< (void *)scaleRotateTranslateValues << int{QMatrix4x4::Translation | QMatrix4x4::Scale | QMatrix4x4::Rotation2D};
|
||||
|
||||
static float belowValues[16] = {
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
@ -2992,7 +2974,7 @@ void tst_QMatrixNxN::optimize_data()
|
||||
4.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
QTest::newRow("below")
|
||||
<< (void *)belowValues << (int)General;
|
||||
<< (void *)belowValues << int{QMatrix4x4::General};
|
||||
}
|
||||
void tst_QMatrixNxN::optimize()
|
||||
{
|
||||
@ -3002,7 +2984,7 @@ void tst_QMatrixNxN::optimize()
|
||||
QMatrix4x4 m((const float *)mValues);
|
||||
m.optimize();
|
||||
|
||||
QCOMPARE(reinterpret_cast<Matrix4x4 *>(&m)->flagBits, flagBits);
|
||||
QCOMPARE(m.flagBits, flagBits);
|
||||
}
|
||||
|
||||
void tst_QMatrixNxN::columnsAndRows()
|
||||
|
Loading…
x
Reference in New Issue
Block a user