summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-09-10 12:55:05 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-11 01:26:07 +0200
commit8fa0e4d1d202a3d1302469e6827c622423328383 (patch)
treee629f2f818b508e964ade8f4f4373a39a1e7098c /tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
parentbcbec4bc49774b80780872c8234acb256c38d779 (diff)
Add a simple test for QVariant carrying a QSharedPointer<QObject>
Change-Id: Ibe17355c7ed8d4af7fda6261d72cfd64779471a7 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp')
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index a532407ad4..502e2504c9 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -155,6 +155,7 @@ private slots:
void qvariant_cast_QObject();
void qvariant_cast_QObject_derived();
void qvariant_cast_QObject_wrapper();
+ void qvariant_cast_QSharedPointerQObject();
void toLocale();
@@ -2324,6 +2325,41 @@ void tst_QVariant::qvariant_cast_QObject_wrapper()
qRegisterMetaType<MyNS::SmartPointer<double> >("MyNS::SmartPointer<double>");
}
+void tst_QVariant::qvariant_cast_QSharedPointerQObject()
+{
+ // ensure no problems between this form and the auto-registering in QVariant::fromValue
+ qRegisterMetaType<QSharedPointer<QObject> >("QSharedPointer<QObject>");
+
+ QObject *rawptr = new QObject;
+ QSharedPointer<QObject> strong(rawptr);
+ QWeakPointer<QObject> weak(strong);
+ QPointer<QObject> qptr(rawptr);
+
+ QVariant v = QVariant::fromValue(strong);
+ QCOMPARE(v.value<QSharedPointer<QObject> >(), strong);
+
+ // clear our QSP; the copy inside the variant should keep the object alive
+ strong.clear();
+
+ // check that the object didn't get deleted
+ QVERIFY(!weak.isNull());
+ QVERIFY(!qptr.isNull());
+
+ strong = qvariant_cast<QSharedPointer<QObject> >(v);
+ QCOMPARE(strong.data(), rawptr);
+ QVERIFY(strong == weak);
+
+ // now really delete the object and verify
+ strong.clear();
+ v.clear();
+ QVERIFY(weak.isNull());
+ QVERIFY(qptr.isNull());
+
+ // compile test:
+ // QVariant::fromValue has already called this function
+ qRegisterMetaType<QSharedPointer<QObject> >();
+}
+
void tst_QVariant::convertToQUint8() const
{
/* qint8. */