summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrans Englich <frans.englich@nokia.com>2009-07-13 11:02:20 (GMT)
committerFrans Englich <frans.englich@nokia.com>2009-07-13 11:41:56 (GMT)
commit9b6eacab99673d7d9848b341c4cf36a7c35f07c0 (patch)
tree28ffe6a4e49da251658b2042486a5c884aeab5dd
parent425f9035d6309111cdc8f30e1fdb4995e96c38a6 (diff)
downloadQt-9b6eacab99673d7d9848b341c4cf36a7c35f07c0.zip
Qt-9b6eacab99673d7d9848b341c4cf36a7c35f07c0.tar.gz
Qt-9b6eacab99673d7d9848b341c4cf36a7c35f07c0.tar.bz2
QFlags::testFlag(): handle the zero case appropriately.
Brought up by Andy. See perforce change 314809, 17b07e3ab6192b31f77fd2f126705b9ab53b3937. Related to task 221708. Reviewed-By: Andy Shaw (cherry picked from commit cc24c46c117248ecb98200416e7f25375e6bb476)
-rw-r--r--src/corelib/global/qglobal.h2
-rw-r--r--tests/auto/qflags/tst_qflags.cpp24
2 files changed, 25 insertions, 1 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 63f6c31..f650bd2 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -2017,7 +2017,7 @@ public:
inline bool operator!() const { return !i; }
- inline bool testFlag(Enum f) const { return (i & f) == f; }
+ inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == f ); }
};
#define Q_DECLARE_FLAGS(Flags, Enum)\
diff --git a/tests/auto/qflags/tst_qflags.cpp b/tests/auto/qflags/tst_qflags.cpp
index a5f68dc..87d8258 100644
--- a/tests/auto/qflags/tst_qflags.cpp
+++ b/tests/auto/qflags/tst_qflags.cpp
@@ -45,6 +45,7 @@ class tst_QFlags: public QObject
Q_OBJECT
private slots:
void testFlag() const;
+ void testFlagZeroFlag() const;
void testFlagMultiBits() const;
};
@@ -59,8 +60,31 @@ void tst_QFlags::testFlag() const
QVERIFY(!btn.testFlag(Qt::LeftButton));
}
+void tst_QFlags::testFlagZeroFlag() const
+{
+ {
+ Qt::MouseButtons btn = Qt::LeftButton | Qt::RightButton;
+ /* Qt::NoButton has the value 0. */
+
+ QVERIFY(!btn.testFlag(Qt::NoButton));
+ }
+
+ {
+ /* A zero enum set should test true with zero. */
+ QVERIFY(Qt::MouseButtons().testFlag(Qt::NoButton));
+ }
+
+ {
+ Qt::MouseButtons btn = Qt::NoButton;
+ QVERIFY(btn.testFlag(Qt::NoButton));
+ }
+}
+
void tst_QFlags::testFlagMultiBits() const
{
+ /* Qt::Window is 0x00000001
+ * Qt::Dialog is 0x00000002 | Window
+ */
{
const Qt::WindowFlags onlyWindow(Qt::Window);
QVERIFY(!onlyWindow.testFlag(Qt::Dialog));