Unit test for QTBUG-21742
authorDamian Jansen <damian.jansen@nokia.com>
Thu, 20 Oct 2011 02:44:43 +0000 (12:44 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 21 Oct 2011 00:35:29 +0000 (02:35 +0200)
Test for crash when accessing a ListView in an odd way.

Change-Id: I47dd8f4eaa2990c6842cf95a62ce925edac26f9a
Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
tests/auto/declarative/qsglistview/data/qtbug-21742.qml [new file with mode: 0644]
tests/auto/declarative/qsglistview/tst_qsglistview.cpp

diff --git a/tests/auto/declarative/qsglistview/data/qtbug-21742.qml b/tests/auto/declarative/qsglistview/data/qtbug-21742.qml
new file mode 100644 (file)
index 0000000..774f904
--- /dev/null
@@ -0,0 +1,36 @@
+import QtQuick 2.0
+
+Rectangle {
+    height: 200
+    width: 200
+    property int count: menuView.count
+
+    Component.onCompleted: { setModel(); }
+
+    function setModel()
+    {
+        menuModel.append({"enabledItem" : true});
+        menuView.currentIndex = 0;
+    }
+
+    ListModel {
+        id: menuModel
+    }
+
+    ListView {
+        id: menuView
+        anchors.fill: parent
+        model: menuModel
+        delegate: mything
+    }
+
+    Component {
+        id: mything
+        Rectangle {
+            height: 50
+            width: 200
+            color: index == menuView.currentIndex ? "green" : "blue"
+        }
+    }
+
+}
\ No newline at end of file
index a23d3b5..8e2375d 100644 (file)
@@ -114,9 +114,7 @@ private slots:
     void propertyChanges();
     void componentChanges();
     void modelChanges();
-    void QTBUG_9791();
     void manualHighlight();
-    void QTBUG_11105();
     void header();
     void header_data();
     void header_delayItemCreation();
@@ -143,6 +141,10 @@ private slots:
     void snapToItem_data();
     void snapToItem();
 
+    void QTBUG_9791();
+    void QTBUG_11105();
+    void QTBUG_21742();
+
 private:
     template <class T> void items();
     template <class T> void changed();
@@ -4045,6 +4047,18 @@ void tst_QSGListView::creationContext()
     QCOMPARE(item->property("text").toString(), QString("Hello!"));
 }
 
+void tst_QSGListView::QTBUG_21742()
+{
+    QSGView canvas;
+    canvas.setGeometry(0,0,200,200);
+    canvas.setSource(QUrl::fromLocalFile(TESTDATA("qtbug-21742.qml")));
+    qApp->processEvents();
+
+    QSGItem *rootItem = qobject_cast<QSGItem *>(canvas.rootObject());
+    QVERIFY(rootItem);
+    QCOMPARE(rootItem->property("count").toInt(), 1);
+}
+
 QSGView *tst_QSGListView::createView()
 {
     QSGView *canvas = new QSGView(0);