diff options
Diffstat (limited to 'tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp')
-rw-r--r-- | tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp index a6e6345223..4296ae4f09 100644 --- a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp +++ b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp @@ -73,6 +73,7 @@ private slots: void basicProperties(); void showFiles(); void resetFiltering(); + void nameFilters(); void refresh(); void cdUp(); #ifdef Q_OS_WIN32 @@ -169,26 +170,50 @@ void tst_qquickfolderlistmodel::resetFiltering() QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create()); QVERIFY(flm != 0); + flm->setProperty("folder", testFileUrl("resetfiltering")); + // _q_directoryUpdated may be triggered if model was empty before, but there won't be a rowsRemoved signal + QTRY_COMPARE(flm->property("count").toInt(),3); // all files visible + + flm->setProperty("folder", testFileUrl("resetfiltering/innerdir")); + // _q_directoryChanged is triggered so it's a total model refresh + QTRY_COMPARE(flm->property("count").toInt(),1); // should just be "test2.txt" visible + + flm->setProperty("folder", testFileUrl("resetfiltering")); + // _q_directoryChanged is triggered so it's a total model refresh + QTRY_COMPARE(flm->property("count").toInt(),3); // all files visible +} + +void tst_qquickfolderlistmodel::nameFilters() +{ + // see QTBUG-36576 + QQmlComponent component(&engine, testFileUrl("resetFiltering.qml")); + checkNoErrors(component); + + QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create()); + QVERIFY(flm != 0); + connect(flm, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(removed(QModelIndex,int,int))); + QTRY_VERIFY(flm->rowCount() > 0); flm->setProperty("folder", testFileUrl("resetfiltering")); - QTRY_COMPARE(flm->property("count").toInt(),1); // should just be "test.txt" visible + QTRY_COMPARE(flm->property("count").toInt(),3); // all files visible + int count = flm->rowCount(); + flm->setProperty("nameFilters", QStringList() << "*.txt"); + // _q_directoryUpdated triggered with range 0:1 + QTRY_COMPARE(flm->property("count").toInt(),1); + QCOMPARE(flm->data(flm->index(0),FileNameRole), QVariant("test.txt")); QCOMPARE(removeStart, 0); QCOMPARE(removeEnd, count-1); - flm->setProperty("folder", testFileUrl("resetfiltering/innerdir")); - QTRY_COMPARE(flm->property("count").toInt(),1); // should just be "test2.txt" visible - count = flm->rowCount(); - QCOMPARE(removeStart, 0); - QCOMPARE(removeEnd, count-1); + flm->setProperty("nameFilters", QStringList() << "*.html"); + QTRY_COMPARE(flm->property("count").toInt(),2); + QCOMPARE(flm->data(flm->index(0),FileNameRole), QVariant("test1.html")); + QCOMPARE(flm->data(flm->index(1),FileNameRole), QVariant("test2.html")); - flm->setProperty("folder", testFileUrl("resetfiltering")); - QTRY_COMPARE(flm->property("count").toInt(),1); // should just be "test.txt" visible - count = flm->rowCount(); - QCOMPARE(removeStart, 0); - QCOMPARE(removeEnd, count-1); + flm->setProperty("nameFilters", QStringList()); + QTRY_COMPARE(flm->property("count").toInt(),3); // all files visible } void tst_qquickfolderlistmodel::refresh() |