aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlcpputils
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-06-12 17:47:15 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-12 14:10:24 +0200
commiteacbc7805e937e64b7e117705919b214aed4f736 (patch)
tree5416f535f54bf67920acc4c673586e982c024a7e /tests/auto/qml/qqmlcpputils
parent38540f6091c2ffedaea3afbf093d8079840c9ea2 (diff)
Check for null ptr in qmlobject_cast definition
Previously, the input object wasn't checked for nullness, and thus the qmlobject_cast could assert. Change-Id: I3552150953cef8411a860a381e28b1d681494b08 Reviewed-by: Kent Hansen <kent.hansen@nokia.com> Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlcpputils')
-rw-r--r--tests/auto/qml/qqmlcpputils/tst_qqmlcpputils.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcpputils/tst_qqmlcpputils.cpp b/tests/auto/qml/qqmlcpputils/tst_qqmlcpputils.cpp
index 4189f441a2..40c93fe603 100644
--- a/tests/auto/qml/qqmlcpputils/tst_qqmlcpputils.cpp
+++ b/tests/auto/qml/qqmlcpputils/tst_qqmlcpputils.cpp
@@ -51,6 +51,7 @@ public:
private slots:
void fastConnect();
+ void fastCast();
};
class MyObject : public QObject {
@@ -101,6 +102,25 @@ void tst_qqmlcpputils::fastConnect()
}
}
+void tst_qqmlcpputils::fastCast()
+{
+ {
+ QObject *myObj = new MyObject;
+ MyObject *obj = qmlobject_cast<MyObject*>(myObj);
+ QVERIFY(obj);
+ QCOMPARE(obj->metaObject(), myObj->metaObject());
+ obj->slot1();
+ QCOMPARE(obj->slotCount, 1);
+ delete myObj;
+ }
+
+ {
+ QObject *nullObj = 0;
+ QObject *obj = qmlobject_cast<QObject *>(nullObj);
+ QCOMPARE(obj, nullObj); // shouldn't crash/assert.
+ }
+}
+
QTEST_MAIN(tst_qqmlcpputils)
#include "tst_qqmlcpputils.moc"