diff --git a/autotests/kdirlistertest.h b/autotests/kdirlistertest.h --- a/autotests/kdirlistertest.h +++ b/autotests/kdirlistertest.h @@ -93,7 +93,7 @@ void testNewItemsInSymlink(); void testRefreshItems(); void testRefreshRootItem(); - void testDeleteItem(); + void testDeleteItems(); void testRenameItem(); void testRenameAndOverwrite(); void testConcurrentListing(); diff --git a/autotests/kdirlistertest.cpp b/autotests/kdirlistertest.cpp --- a/autotests/kdirlistertest.cpp +++ b/autotests/kdirlistertest.cpp @@ -25,6 +25,7 @@ QTEST_MAIN(KDirListerTest) #include +#include #include "kiotesthelper.h" #include #include @@ -179,26 +180,31 @@ } // This test assumes testOpenUrl was run before. So m_dirLister is holding the items already. +// This test creates 1000 files in the temp directory void KDirListerTest::testNewItems() { QCOMPARE(m_items.count(), 4); const QString path = m_tempDir.path() + '/'; connect(&m_dirLister, SIGNAL(newItems(KFileItemList)), this, SLOT(slotNewItems(KFileItemList))); QTest::qWait(1000); // We need a 1s timestamp difference on the dir, otherwise FAM won't notice anything. - qDebug() << "Creating new file"; - const QString fileName = QStringLiteral("toplevelfile_new"); - createSimpleFile(path + fileName); + qDebug() << "Creating new 1000 files"; + for (int i = 0; i < 1000 ; i++) { + createSimpleFile(path + QString("toplevelfile_new_%1").arg(i)); + } + + // choose one of the new created files + const QString fileName = QStringLiteral("toplevelfile_new_500"); int numTries = 0; // Give time for KDirWatch to notify us while (m_items.count() == 4) { QVERIFY(++numTries < 20); QTest::qWait(100); } //qDebug() << "numTries=" << numTries; - QCOMPARE(m_items.count(), 5); + QCOMPARE(m_items.count(), 1004); QCOMPARE(m_dirLister.spyStarted.count(), 1); // Updates call started QCOMPARE(m_dirLister.spyCompleted.count(), 1); // and completed @@ -284,7 +290,7 @@ QCOMPARE(m_items2.count(), origItemCount); QVERIFY(dirLister2.isFinished()); - QTest::qWait(1000); // We need a 1s timestamp difference on the dir, otherwise FAM won't notice anything. + QTest::qWait(4000); // We need a 4s timestamp difference on the dir, otherwise FAM won't notice enough. qDebug() << "Creating new file"; const QString fileName = QStringLiteral("toplevelfile_newinlink"); @@ -335,9 +341,11 @@ } // This test assumes testOpenUrl was run before. So m_dirLister is holding the items already. +// Modifies one of the files to have html content void KDirListerTest::testRefreshItems() { m_refreshedItems.clear(); + m_dirLister.clearSpies(); const QString path = m_tempDir.path() + '/'; const QString fileName = path + "toplevelfile_1"; @@ -450,25 +458,29 @@ // Hidden though, shouldn't matter. } -void KDirListerTest::testDeleteItem() +void KDirListerTest::testDeleteItems() { testOpenUrl(); // ensure m_items is uptodate const int origItemCount = m_items.count(); QCOMPARE(fileCount(), origItemCount); const QString path = m_tempDir.path() + '/'; + connect(&m_dirLister, SIGNAL(itemsDeleted(KFileItemList)), this, SLOT(exitLoop())); - //qDebug() << "Removing " << path+"toplevelfile_1"; - QFile::remove(path + "toplevelfile_1"); + qDebug() << "Removing 1000 files from " << path; + for (int i=0; i < 1000; ++i) { + QFile::remove(path + QString("toplevelfile_new_%1").arg(i)); + } // the remove() doesn't always trigger kdirwatch in stat mode, if this all happens in the same second KDirWatch::self()->setDirty(path); if (m_dirLister.spyItemsDeleted.count() == 0) { qDebug("waiting for itemsDeleted"); enterLoop(); } - QCOMPARE(m_dirLister.spyItemsDeleted.count(), 1); + // The signal could be emited 1 time with all the deleted files or more times + QVERIFY(m_dirLister.spyItemsDeleted.count() > 0); // OK now kdirlister told us the file was deleted, let's try a re-listing m_items.clear(); @@ -478,14 +490,18 @@ connect(&m_dirLister, SIGNAL(completed()), this, SLOT(exitLoop())); enterLoop(); QVERIFY(m_dirLister.isFinished()); - QCOMPARE(m_items.count(), origItemCount - 1); + QCOMPARE(m_items.count(), origItemCount - 1000); disconnect(&m_dirLister, nullptr, this, nullptr); QCOMPARE(fileCount(), m_items.count()); } + void KDirListerTest::testRenameItem() { + QMimeDatabase db; + const QMimeType htmlType = db.mimeTypeForUrl(QUrl(QLatin1String("file://index.html"))); + m_refreshedItems2.clear(); const QString dirPath = m_tempDir.path() + '/'; connect(&m_dirLister, SIGNAL(refreshItems(QList >)), @@ -504,7 +520,7 @@ QCOMPARE(entry.first.url().toLocalFile(), path); QCOMPARE(entry.first.mimetype(), QString("application/octet-stream")); QCOMPARE(entry.second.url().toLocalFile(), newPath); - QCOMPARE(entry.second.mimetype(), QString("text/html")); + QCOMPARE(entry.second.mimetype(), htmlType.name()); disconnect(&m_dirLister, nullptr, this, nullptr); // Let's see what KDirLister has in cache now @@ -1329,7 +1345,7 @@ if (++numTries == 20) { return false; } - QTest::qWait(100); + QTest::qWait(150); } return true; }