diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-12 09:03:49 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-12 09:12:36 (GMT) |
commit | 171d92dc8b800b24d28c7b4abf34d6961763bbf4 (patch) | |
tree | bcf2ce2ebf6546faa5cc2dc69e01687adb82f947 /tests/auto/qsharedpointer | |
parent | c8563ec79f01ec54a03bb2fdbba11a73a01370f7 (diff) | |
download | Qt-171d92dc8b800b24d28c7b4abf34d6961763bbf4.zip Qt-171d92dc8b800b24d28c7b4abf34d6961763bbf4.tar.gz Qt-171d92dc8b800b24d28c7b4abf34d6961763bbf4.tar.bz2 |
Autotest: make sure we can't create QWeakPointer from a QObject in destruction.
This test only works in debug mode
Diffstat (limited to 'tests/auto/qsharedpointer')
-rw-r--r-- | tests/auto/qsharedpointer/tst_qsharedpointer.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp index 6bc3aa0..58e5401 100644 --- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp @@ -1593,6 +1593,21 @@ void tst_QSharedPointer::invalidConstructs_data() << "QObject *ptr = new QObject;\n" "QWeakPointer<QObject> weak = ptr;\n" // this makes the object unmanaged "QSharedPointer<QObject> shared(ptr);\n"; + +#ifndef QT_NO_DEBUG + // this tests a Q_ASSERT, so it is only valid in debug mode + // the DerivedFromQObject destructor below creates a QWeakPointer from parent(). + // parent() is not 0 in the current Qt implementation, but has started destruction, + // so the code should detect that issue + QTest::newRow("shared-pointer-from-qobject-in-destruction") + << &QTest::QExternalTest::tryRunFail + << "class DerivedFromQObject: public QObject { public:\n" + " DerivedFromQObject(QObject *parent): QObject(parent) {}\n" + " ~DerivedFromQObject() { QWeakPointer<QObject> weak = parent(); }\n" + "};\n" + "QObject obj;\n" + "new DerivedFromQObject(&obj);"; +#endif } void tst_QSharedPointer::invalidConstructs() |