diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-05-04 08:44:53 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-05-04 08:54:05 (GMT) |
commit | aa077a8bd3ee3a134629ef6ac2367b7f11593724 (patch) | |
tree | c86331ff0e219e8ff4ffd4780e1aed33649380e4 /tests/auto | |
parent | 279a45131ba60fad9f429c7c429271da5b9cc9ac (diff) | |
download | Qt-aa077a8bd3ee3a134629ef6ac2367b7f11593724.zip Qt-aa077a8bd3ee3a134629ef6ac2367b7f11593724.tar.gz Qt-aa077a8bd3ee3a134629ef6ac2367b7f11593724.tar.bz2 |
Do not crash when passing wrong indexes to QSortFilterProxyModel::indexFomSource and *ToSource
Show a warning instead
Task-number: 252507
Reviewed-by: Marius Bugge Monsen
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 18aa5fc..bd66fdf 100644 --- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -133,6 +133,7 @@ private slots: void task248868_dynamicSorting(); void task250023_fetchMore(); void task251296_hiddenChildren(); + void task252507_mapFromToSource(); protected: void buildHierarchy(const QStringList &data, QAbstractItemModel *model); @@ -2612,6 +2613,7 @@ class QtTestModel: public QAbstractItemModel return fetched.contains(parent) ? rows : 0; } int columnCount(const QModelIndex& parent = QModelIndex()) const { + Q_UNUSED(parent); return cols; } @@ -2717,6 +2719,22 @@ void tst_QSortFilterProxyModel::task251296_hiddenChildren() QCOMPARE(proxy.data(indexC).toString(), QString::fromLatin1("C VISIBLE")); } +void tst_QSortFilterProxyModel::task252507_mapFromToSource() +{ + QtTestModel source(10,10); + source.fetchMore(QModelIndex()); + QSortFilterProxyModel proxy; + proxy.setSourceModel(&source); + QCOMPARE(proxy.mapFromSource(source.index(5, 4)), proxy.index(5, 4)); + QCOMPARE(proxy.mapToSource(proxy.index(3, 2)), source.index(3, 2)); + QCOMPARE(proxy.mapFromSource(QModelIndex()), QModelIndex()); + QCOMPARE(proxy.mapToSource(QModelIndex()), QModelIndex()); + + QTest::ignoreMessage(QtWarningMsg, "QSortFilterProxyModel: index from wrong model passed to mapToSource "); + QCOMPARE(proxy.mapToSource(source.index(2, 3)), QModelIndex()); + QTest::ignoreMessage(QtWarningMsg, "QSortFilterProxyModel: index from wrong model passed to mapFromSource "); + QCOMPARE(proxy.mapFromSource(proxy.index(6, 2)), QModelIndex()); +} QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc" |