summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-04-01 09:24:51 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-04-01 18:57:25 +0000
commitb7c7beacda529edd642d979064748bdad27b989b (patch)
tree565043444627028d1b958db2079b57212d609ca6 /tests/auto
parenta5456b23f4aee5693c4a24e2cce49ed40c43d71e (diff)
QPointer: add a test for const QPointer<X>
People use this, so make sure there's a test for it. I don't expect this test to fail, but static and dynamic checkers should be presented with this use-case, so they have a chance of warning, because certain implementation strategies of QPointer may make this code undefined. Change-Id: I334bd73204ba4e186c4098fc6b7188917407e020 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
index d7cce4ada4..f3f485297a 100644
--- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
+++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
@@ -59,6 +59,7 @@ private slots:
void qvariantCast();
void constPointer();
+ void constQPointer();
};
void tst_QPointer::constructors()
@@ -402,6 +403,21 @@ void tst_QPointer::constPointer()
delete fp.data();
}
+void tst_QPointer::constQPointer()
+{
+ // Check that const QPointers work. It's a bit weird to mark a pointer
+ // const if its value can change, but the shallow-const principle in C/C++
+ // allows this, and people use it, so document it with a test.
+ //
+ // It's unlikely that this test will fail in and out of itself, but it
+ // presents the use-case to static and dynamic checkers that can raise
+ // a warning (hopefully) should this become an issue.
+ QObject *o = new QObject(this);
+ const QPointer<QObject> p = o;
+ delete o;
+ QVERIFY(!p);
+}
+
QTEST_MAIN(tst_QPointer)
#include "tst_qpointer.moc"