Check for null ptr in qmlobject_cast definition
[profile/ivi/qtdeclarative.git] / tests / auto / qml / qqmlcpputils / tst_qqmlcpputils.cpp
index 4189f44..40c93fe 100644 (file)
@@ -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"