aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickxmllistmodel
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2014-04-09 16:00:49 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-10 09:19:55 +0200
commit7254e09442278f9e083a423c832c24b58e8fedec (patch)
tree923e2e060581c609f269e09ef0cfcb17642ee4d9 /tests/auto/quick/qquickxmllistmodel
parent1eace58364d8abf89e08686396d7e34b140a0aa5 (diff)
Fix the initial value of XmlListModel::count
QAbstractItemModel::rowCount() should under no circumstances return -1 or it will crash QSortFilterProxyModel. Change-Id: Ib3d4a57d5fc3761a7fc6f6925c3d25bdea20ce78 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'tests/auto/quick/qquickxmllistmodel')
-rw-r--r--tests/auto/quick/qquickxmllistmodel/data/proxyCrash.qml9
-rw-r--r--tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp24
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickxmllistmodel/data/proxyCrash.qml b/tests/auto/quick/qquickxmllistmodel/data/proxyCrash.qml
new file mode 100644
index 0000000000..c0c5a25e3c
--- /dev/null
+++ b/tests/auto/quick/qquickxmllistmodel/data/proxyCrash.qml
@@ -0,0 +1,9 @@
+import QtQuick 2.0
+import QtQuick.XmlListModel 2.0
+import SortFilterProxyModel 1.0
+
+SortFilterProxyModel {
+ source: XmlListModel {
+ XmlRole { }
+ }
+}
diff --git a/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp b/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp
index a3cfa0011a..1d5518047f 100644
--- a/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp
+++ b/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp
@@ -51,6 +51,7 @@
#include <QtCore/qtimer.h>
#include <QtCore/qfile.h>
#include <QtCore/qtemporaryfile.h>
+#include <QtCore/qsortfilterproxymodel.h>
#include "../../shared/util.h"
#include <private/qqmlengine_p.h>
@@ -106,6 +107,7 @@ private slots:
void selectAncestor();
void roleCrash();
+ void proxyCrash();
private:
QString errorString(QAbstractItemModel *model) {
@@ -988,6 +990,28 @@ void tst_qquickxmllistmodel::roleCrash()
delete model;
}
+class SortFilterProxyModel : public QSortFilterProxyModel
+{
+ Q_OBJECT
+ Q_PROPERTY(QObject *source READ source WRITE setSource)
+
+public:
+ SortFilterProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) { sort(0); }
+ QObject *source() const { return sourceModel(); }
+ void setSource(QObject *source) { setSourceModel(qobject_cast<QAbstractItemModel *>(source)); }
+};
+
+void tst_qquickxmllistmodel::proxyCrash()
+{
+ qmlRegisterType<SortFilterProxyModel>("SortFilterProxyModel", 1, 0, "SortFilterProxyModel");
+
+ // don't crash
+ QQmlComponent component(&engine, testFileUrl("proxyCrash.qml"));
+ QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(component.create());
+ QVERIFY(model != 0);
+ delete model;
+}
+
QTEST_MAIN(tst_qquickxmllistmodel)
#include "tst_qquickxmllistmodel.moc"