summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global/qflags
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-02-26 01:03:46 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-02-28 22:09:31 +0000
commite1b8257deeff67025d75b4b3c27b571b418eefee (patch)
tree209b7647d4b8e735d8b0ba740e9b95453bd9ee91 /tests/auto/corelib/global/qflags
parent6f50e54138f9a2aa9ab6d84add449f197d545de3 (diff)
tst_qflags: compile with QT_TYPESAFE_FLAGS
In constExpr(), where code incorrectly assumed conversions to int or uint were implicit, make them explicit. In classEnum(), don't test bitwise operators between QFlags and int/uint when QT_TYPESAFE_FLAGS is in effect. Pick-to: 6.3 Fixes: QTBUG-101294 Change-Id: If119bf56dd12778f7231a9e76293c76e75354809 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/global/qflags')
-rw-r--r--tests/auto/corelib/global/qflags/tst_qflags.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp
index 881c407a36..5857767c20 100644
--- a/tests/auto/corelib/global/qflags/tst_qflags.cpp
+++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp
@@ -173,6 +173,7 @@ void tst_QFlags::testAnyFlag()
}
template <unsigned int N, typename T> bool verifyConstExpr(T n) { return n == N; }
+template <unsigned int N, typename T> bool verifyConstExpr(QFlags<T> n) { return n.toInt() == N; }
constexpr Qt::MouseButtons testRelaxedConstExpr()
{
@@ -187,11 +188,11 @@ constexpr Qt::MouseButtons testRelaxedConstExpr()
void tst_QFlags::constExpr()
{
Qt::MouseButtons btn = Qt::LeftButton | Qt::RightButton;
- switch (btn) {
+ switch (btn.toInt()) {
case Qt::LeftButton: QVERIFY(false); break;
case Qt::RightButton: QVERIFY(false); break;
- case int(Qt::LeftButton | Qt::RightButton): QVERIFY(true); break;
- default: QFAIL(qPrintable(QStringLiteral("Unexpected button: %1").arg(btn)));
+ case (Qt::LeftButton | Qt::RightButton).toInt(): QVERIFY(true); break;
+ default: QFAIL(qPrintable(QStringLiteral("Unexpected button: %1").arg(btn.toInt())));
}
QVERIFY(verifyConstExpr<uint((Qt::LeftButton | Qt::RightButton) & Qt::LeftButton)>(Qt::LeftButton));
@@ -200,8 +201,10 @@ void tst_QFlags::constExpr()
QVERIFY(verifyConstExpr<uint(~(Qt::LeftButton | Qt::RightButton))>(~(Qt::LeftButton | Qt::RightButton)));
QVERIFY(verifyConstExpr<uint(Qt::MouseButtons(Qt::LeftButton) ^ Qt::RightButton)>(Qt::LeftButton ^ Qt::RightButton));
QVERIFY(verifyConstExpr<uint(Qt::MouseButtons(0))>(0));
+#ifndef QT_TYPESAFE_FLAGS
QVERIFY(verifyConstExpr<uint(Qt::MouseButtons(Qt::RightButton) & 0xff)>(Qt::RightButton));
QVERIFY(verifyConstExpr<uint(Qt::MouseButtons(Qt::RightButton) | 0xff)>(0xff));
+#endif
QVERIFY(!verifyConstExpr<Qt::RightButton>(~Qt::MouseButtons(Qt::LeftButton)));
@@ -256,11 +259,14 @@ void tst_QFlags::classEnum()
QVERIFY(!f0);
+#ifndef QT_TYPESAFE_FLAGS
QCOMPARE(f3 & int(1), 1);
QCOMPARE(f3 & uint(1), 1);
+#endif
QCOMPARE(f3 & MyStrictEnum::StrictOne, 1);
MyStrictFlags aux;
+#ifndef QT_TYPESAFE_FLAGS
aux = f3;
aux &= int(1);
QCOMPARE(aux, 1);
@@ -268,6 +274,7 @@ void tst_QFlags::classEnum()
aux = f3;
aux &= uint(1);
QCOMPARE(aux, 1);
+#endif
aux = f3;
aux &= MyStrictEnum::StrictOne;