diff options
Diffstat (limited to 'tests/auto/qsharedpointer')
-rw-r--r-- | tests/auto/qsharedpointer/externaltests.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qsharedpointer/externaltests.h | 2 | ||||
-rw-r--r-- | tests/auto/qsharedpointer/forwarddeclaration.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qsharedpointer/forwarddeclared.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qsharedpointer/forwarddeclared.h | 2 | ||||
-rw-r--r-- | tests/auto/qsharedpointer/tst_qsharedpointer.cpp | 51 | ||||
-rw-r--r-- | tests/auto/qsharedpointer/wrapper.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qsharedpointer/wrapper.h | 2 |
8 files changed, 57 insertions, 8 deletions
diff --git a/tests/auto/qsharedpointer/externaltests.cpp b/tests/auto/qsharedpointer/externaltests.cpp index aaef779..edf055c 100644 --- a/tests/auto/qsharedpointer/externaltests.cpp +++ b/tests/auto/qsharedpointer/externaltests.cpp @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/tests/auto/qsharedpointer/externaltests.h b/tests/auto/qsharedpointer/externaltests.h index ecc107e..17a6543 100644 --- a/tests/auto/qsharedpointer/externaltests.h +++ b/tests/auto/qsharedpointer/externaltests.h @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/tests/auto/qsharedpointer/forwarddeclaration.cpp b/tests/auto/qsharedpointer/forwarddeclaration.cpp index 1dbbeec..ee7e591 100644 --- a/tests/auto/qsharedpointer/forwarddeclaration.cpp +++ b/tests/auto/qsharedpointer/forwarddeclaration.cpp @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/tests/auto/qsharedpointer/forwarddeclared.cpp b/tests/auto/qsharedpointer/forwarddeclared.cpp index 4ab467a..ddf839a 100644 --- a/tests/auto/qsharedpointer/forwarddeclared.cpp +++ b/tests/auto/qsharedpointer/forwarddeclared.cpp @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/tests/auto/qsharedpointer/forwarddeclared.h b/tests/auto/qsharedpointer/forwarddeclared.h index a4cc2b4..71e7a66 100644 --- a/tests/auto/qsharedpointer/forwarddeclared.h +++ b/tests/auto/qsharedpointer/forwarddeclared.h @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp index 1101a08..ab75c91 100644 --- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -62,6 +62,7 @@ class tst_QSharedPointer: public QObject private slots: void basics_data(); void basics(); + void swap(); void forwardDeclaration1(); void forwardDeclaration2(); void memoryManagement(); @@ -263,6 +264,37 @@ void tst_QSharedPointer::basics() // aData is deleted here } +void tst_QSharedPointer::swap() +{ + QSharedPointer<int> p1, p2(new int(42)), control = p2; + QVERIFY(p1 != control); + QVERIFY(p1.isNull()); + QVERIFY(p2 == control); + QVERIFY(!p2.isNull()); + QVERIFY(*p2 == 42); + + p1.swap(p2); + QVERIFY(p1 == control); + QVERIFY(!p1.isNull()); + QVERIFY(p2 != control); + QVERIFY(p2.isNull()); + QVERIFY(*p1 == 42); + + p1.swap(p2); + QVERIFY(p1 != control); + QVERIFY(p1.isNull()); + QVERIFY(p2 == control); + QVERIFY(!p2.isNull()); + QVERIFY(*p2 == 42); + + qSwap(p1, p2); + QVERIFY(p1 == control); + QVERIFY(!p1.isNull()); + QVERIFY(p2 != control); + QVERIFY(p2.isNull()); + QVERIFY(*p1 == 42); +} + class ForwardDeclared; ForwardDeclared *forwardPointer(); void externalForwardDeclaration(); @@ -1373,7 +1405,9 @@ void tst_QSharedPointer::threadStressTest_data() QTest::newRow("5+10") << 5 << 10; QTest::newRow("5+30") << 5 << 30; +#ifndef Q_OS_WINCE QTest::newRow("100+100") << 100 << 100; +#endif } void tst_QSharedPointer::threadStressTest() @@ -1591,6 +1625,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() diff --git a/tests/auto/qsharedpointer/wrapper.cpp b/tests/auto/qsharedpointer/wrapper.cpp index 7640e68..25d0f42 100644 --- a/tests/auto/qsharedpointer/wrapper.cpp +++ b/tests/auto/qsharedpointer/wrapper.cpp @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/tests/auto/qsharedpointer/wrapper.h b/tests/auto/qsharedpointer/wrapper.h index a888063..c006686 100644 --- a/tests/auto/qsharedpointer/wrapper.h +++ b/tests/auto/qsharedpointer/wrapper.h @@ -34,7 +34,7 @@ ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ |