diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2011-07-06 14:37:14 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2011-07-06 17:11:46 (GMT) |
commit | de85cf25be61c746b1a47a58873b5758d8e8ad5d (patch) | |
tree | 06a878f35a099aed7faa3ee63867fd97e9de7ace /tests/auto/qflags | |
parent | db1c29aaed0730db38f19dfb376fd2c03d08c04e (diff) | |
download | Qt-de85cf25be61c746b1a47a58873b5758d8e8ad5d.zip Qt-de85cf25be61c746b1a47a58873b5758d8e8ad5d.tar.gz Qt-de85cf25be61c746b1a47a58873b5758d8e8ad5d.tar.bz2 |
Use Q_DECL_CONSTEXPR in QFlags
Change-Id: I851e0b1c3f80a7b33a38cb1ab2665dc0f3c73adc
Reviewed-on: http://codereview.qt.nokia.com/1248
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Gabriel de Dietrich <gabriel.dietrich-de@nokia.com>
(cherry picked from commit c0c6dd2b022cfd667f32b8a48bcac86ac07d3880)
Diffstat (limited to 'tests/auto/qflags')
-rw-r--r-- | tests/auto/qflags/tst_qflags.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/qflags/tst_qflags.cpp b/tests/auto/qflags/tst_qflags.cpp index 87025b6..85e64a6 100644 --- a/tests/auto/qflags/tst_qflags.cpp +++ b/tests/auto/qflags/tst_qflags.cpp @@ -47,6 +47,7 @@ private slots: void testFlag() const; void testFlagZeroFlag() const; void testFlagMultiBits() const; + void constExpr(); }; void tst_QFlags::testFlag() const @@ -96,5 +97,32 @@ void tst_QFlags::testFlagMultiBits() const } } +template <int N, typename T> bool verifyConstExpr(T n) { return n == N; } + +void tst_QFlags::constExpr() +{ +#ifdef Q_COMPILER_CONSTEXPR + Qt::MouseButtons btn = Qt::LeftButton | Qt::RightButton; + switch (btn) { + case Qt::LeftButton: QVERIFY(false); break; + case Qt::RightButton: QVERIFY(false); break; + case Qt::LeftButton | Qt::RightButton: QVERIFY(true); break; + default: QVERIFY(false); + } + + QVERIFY(verifyConstExpr<(Qt::LeftButton | Qt::RightButton) & Qt::LeftButton>(Qt::LeftButton)); + QVERIFY(verifyConstExpr<(Qt::LeftButton | Qt::RightButton) & Qt::MiddleButton>(0)); + QVERIFY(verifyConstExpr<(Qt::LeftButton | Qt::RightButton) | Qt::MiddleButton>(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton)); + QVERIFY(verifyConstExpr<~(Qt::LeftButton | Qt::RightButton)>(~(Qt::LeftButton | Qt::RightButton))); + QVERIFY(verifyConstExpr<Qt::MouseButtons(Qt::LeftButton) ^ Qt::RightButton>(Qt::LeftButton ^ Qt::RightButton)); + QVERIFY(verifyConstExpr<Qt::MouseButtons(0)>(0)); + QVERIFY(verifyConstExpr<Qt::MouseButtons(Qt::RightButton) & 0xff>(Qt::RightButton)); + QVERIFY(verifyConstExpr<Qt::MouseButtons(Qt::RightButton) | 0xff>(0xff)); + + QVERIFY(!verifyConstExpr<Qt::RightButton>(!Qt::MouseButtons(Qt::LeftButton))); +#endif +} + + QTEST_MAIN(tst_QFlags) #include "tst_qflags.moc" |