summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp37
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp71
2 files changed, 108 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
index 3540df17ac..fd20a1cf5d 100644
--- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
+++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
@@ -63,6 +63,8 @@ private slots:
void disconnect();
void castDuringDestruction();
void threadSafety();
+
+ void qvariantCast();
};
void tst_QPointer::constructors()
@@ -348,6 +350,41 @@ void tst_QPointer::threadSafety()
owner.wait();
}
+void tst_QPointer::qvariantCast()
+{
+ QPointer<QFile> tracking = new QFile;
+ tracking->setObjectName("A test name");
+ QVariant v = QVariant::fromValue(tracking);
+
+ {
+ QPointer<QObject> other = qPointerFromVariant<QObject>(v);
+ QCOMPARE(other->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QPointer<QIODevice> other = qPointerFromVariant<QIODevice>(v);
+ QCOMPARE(other->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QPointer<QFile> other = qPointerFromVariant<QFile>(v);
+ QCOMPARE(other->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QPointer<QThread> other = qPointerFromVariant<QThread>(v);
+ QVERIFY(!other);
+ }
+ {
+ QPointer<QFile> toBeDeleted = new QFile;
+ QVariant deletedVariant = QVariant::fromValue(toBeDeleted);
+ delete toBeDeleted;
+ QPointer<QObject> deleted = qPointerFromVariant<QObject>(deletedVariant);
+ QVERIFY(!deleted);
+ }
+
+ // Intentionally does not compile.
+// QPointer<int> sop = qPointerFromVariant<int>(v);
+}
+
+
QTEST_MAIN(tst_QPointer)
#include "tst_qpointer.moc"
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index 70caad856b..6896b328d0 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -105,6 +105,8 @@ private slots:
void invalidConstructs_data();
void invalidConstructs();
+ void qvariantCast();
+
public slots:
void cleanup() { safetyCheck(); }
@@ -1853,6 +1855,75 @@ void tst_QSharedPointer::invalidConstructs()
}
}
+void tst_QSharedPointer::qvariantCast()
+{
+ QSharedPointer<QFile> sp = QSharedPointer<QFile>::create();
+ sp->setObjectName("A test name");
+ QVariant v = QVariant::fromValue(sp);
+
+ {
+ QSharedPointer<QObject> other = qSharedPointerFromVariant<QObject>(v);
+ QCOMPARE(other->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QSharedPointer<QIODevice> other = qSharedPointerFromVariant<QIODevice>(v);
+ QCOMPARE(other->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QSharedPointer<QFile> other = qSharedPointerFromVariant<QFile>(v);
+ QCOMPARE(other->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QSharedPointer<QThread> other = qSharedPointerFromVariant<QThread>(v);
+ QVERIFY(!other);
+ }
+ // Intentionally does not compile.
+// QSharedPointer<int> sop = qSharedPointerFromVariant<int>(v);
+
+ v = QVariant::fromValue(sp.toWeakRef());
+
+ {
+ QWeakPointer<QObject> other = qWeakPointerFromVariant<QObject>(v);
+ QCOMPARE(other.data()->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QWeakPointer<QIODevice> other = qWeakPointerFromVariant<QIODevice>(v);
+ QCOMPARE(other.data()->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QWeakPointer<QFile> other = qWeakPointerFromVariant<QFile>(v);
+ QCOMPARE(other.data()->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QWeakPointer<QThread> other = qWeakPointerFromVariant<QThread>(v);
+ QVERIFY(!other);
+ }
+
+ // Intentionally does not compile.
+// QWeakPointer<int> sop = qWeakPointerFromVariant<int>(v);
+
+ QWeakPointer<QFile> tracking = new QFile;
+ tracking.data()->setObjectName("A test name");
+ v = QVariant::fromValue(tracking);
+
+ {
+ QWeakPointer<QObject> other = qWeakPointerFromVariant<QObject>(v);
+ QCOMPARE(other.data()->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QWeakPointer<QIODevice> other = qWeakPointerFromVariant<QIODevice>(v);
+ QCOMPARE(other.data()->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QWeakPointer<QFile> other = qWeakPointerFromVariant<QFile>(v);
+ QCOMPARE(other.data()->objectName(), QString::fromLatin1("A test name"));
+ }
+ {
+ QWeakPointer<QThread> other = qWeakPointerFromVariant<QThread>(v);
+ QVERIFY(!other);
+ }
+}
+
namespace ReentrancyWhileDestructing {
struct IB
{