tst_qflags: test w/and w/o QT_TYPESAFE_FLAGS

Also contains some fixes which fix the Windows build, amending
e1b8257dee.

Pick-to: 6.3
Fixes: QTBUG-101294
Fixes: QTBUG-101304
Change-Id: I779f50fc705ed32f0314daf28b39b477a7fe925d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2022-02-26 02:23:40 +01:00
parent 0335755e52
commit b142d2ad73
2 changed files with 31 additions and 14 deletions

View File

@ -1,5 +1,3 @@
# Generated from qflags.pro.
#####################################################################
## tst_qflags Test:
#####################################################################
@ -9,5 +7,9 @@ qt_internal_add_test(tst_qflags
tst_qflags.cpp
)
## Scopes:
#####################################################################
qt_internal_add_test(tst_qflags_non_typesafe
SOURCES
tst_qflags.cpp
DEFINES
QFLAGS_TEST_NO_TYPESAFE_FLAGS
)

View File

@ -25,8 +25,18 @@
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QTest>
#ifdef QFLAGS_TEST_NO_TYPESAFE_FLAGS
# ifdef QT_TYPESAFE_FLAGS
# undef QT_TYPESAFE_FLAGS
# endif
#else
# ifndef QT_TYPESAFE_FLAGS
# define QT_TYPESAFE_FLAGS
# endif
#endif
#include <QTest>
class tst_QFlags: public QObject
{
@ -238,20 +248,25 @@ void tst_QFlags::constExpr()
default: QFAIL(qPrintable(QStringLiteral("Unexpected button: %1").arg(btn.toInt())));
}
QVERIFY(verifyConstExpr<uint((Qt::LeftButton | Qt::RightButton) & Qt::LeftButton)>(Qt::LeftButton));
QVERIFY(verifyConstExpr<uint((Qt::LeftButton | Qt::RightButton) & Qt::MiddleButton)>(0));
QVERIFY(verifyConstExpr<uint((Qt::LeftButton | Qt::RightButton) | Qt::MiddleButton)>(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton));
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));
#define VERIFY_CONSTEXPR(expression, expected) \
QVERIFY(verifyConstExpr<(expression).toInt()>(expected))
VERIFY_CONSTEXPR((Qt::LeftButton | Qt::RightButton) & Qt::LeftButton, Qt::LeftButton);
VERIFY_CONSTEXPR((Qt::LeftButton | Qt::RightButton) & Qt::MiddleButton, 0);
VERIFY_CONSTEXPR((Qt::LeftButton | Qt::RightButton) | Qt::MiddleButton, Qt::LeftButton | Qt::RightButton | Qt::MiddleButton);
VERIFY_CONSTEXPR(~(Qt::LeftButton | Qt::RightButton), ~(Qt::LeftButton | Qt::RightButton));
VERIFY_CONSTEXPR(Qt::MouseButtons(Qt::LeftButton) ^ Qt::RightButton, Qt::LeftButton ^ Qt::RightButton);
VERIFY_CONSTEXPR(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));
QVERIFY(verifyConstExpr<(Qt::MouseButtons(Qt::RightButton) & 0xff)>(Qt::RightButton));
QVERIFY(verifyConstExpr<(Qt::MouseButtons(Qt::RightButton) | 0xff)>(0xff));
#endif
QVERIFY(!verifyConstExpr<Qt::RightButton>(~Qt::MouseButtons(Qt::LeftButton)));
QVERIFY(verifyConstExpr<uint(testRelaxedConstExpr())>(Qt::MiddleButton));
VERIFY_CONSTEXPR(testRelaxedConstExpr(), Qt::MiddleButton);
#undef VERIFY_CONSTEXPR
}
void tst_QFlags::signedness()