X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/ced9de5b82046d6eb6f6b828fa9bbc874bbea857..42e52a1eea1c70b38cb1a8bed8aafdcb5fdea804:/src/tests/kfileitemmodelbenchmark.cpp diff --git a/src/tests/kfileitemmodelbenchmark.cpp b/src/tests/kfileitemmodelbenchmark.cpp index b1e777c06..b73485efb 100644 --- a/src/tests/kfileitemmodelbenchmark.cpp +++ b/src/tests/kfileitemmodelbenchmark.cpp @@ -18,37 +18,37 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include +#include +#include + +#include +#include #include "kitemviews/kfileitemmodel.h" #include "kitemviews/private/kfileitemmodelsortalgorithm.h" #include "testdir.h" -#include - -void myMessageOutput(QtMsgType type, const char* msg) +void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg) { + Q_UNUSED(context); + switch (type) { case QtDebugMsg: break; case QtWarningMsg: break; case QtCriticalMsg: - fprintf(stderr, "Critical: %s\n", msg); + fprintf(stderr, "Critical: %s\n", msg.toLocal8Bit().data()); break; case QtFatalMsg: - fprintf(stderr, "Fatal: %s\n", msg); + fprintf(stderr, "Fatal: %s\n", msg.toLocal8Bit().data()); abort(); default: break; } } -namespace { - const int DefaultTimeout = 5000; -}; - Q_DECLARE_METATYPE(KFileItemList) Q_DECLARE_METATYPE(KItemRangeList) @@ -167,25 +167,25 @@ void KFileItemModelBenchmark::insertAndRemoveManyItems() // Avoid overhead caused by natural sorting // and determining the isDir/isLink roles. model.m_naturalSorting = false; - model.setRoles(QSet() << "text"); + model.setRoles({"text"}); QSignalSpy spyItemsInserted(&model, SIGNAL(itemsInserted(KItemRangeList))); QSignalSpy spyItemsRemoved(&model, SIGNAL(itemsRemoved(KItemRangeList))); QBENCHMARK { model.slotClear(); - model.slotNewItems(initialItems); + model.slotItemsAdded(model.directory(), initialItems); model.slotCompleted(); QCOMPARE(model.count(), initialItems.count()); if (!newItems.isEmpty()) { - model.slotNewItems(newItems); + model.slotItemsAdded(model.directory(), newItems); model.slotCompleted(); } QCOMPARE(model.count(), initialItems.count() + newItems.count()); if (!removedItems.isEmpty()) { - model.removeItems(removedItems); + model.slotItemsDeleted(removedItems); } QCOMPARE(model.count(), initialItems.count() + newItems.count() - removedItems.count()); } @@ -211,6 +211,11 @@ void KFileItemModelBenchmark::insertAndRemoveManyItems() void KFileItemModelBenchmark::insertManyChildItems() { + // TODO: this function needs to be adjusted to the changes in KFileItemModel + // (replacement of slotNewItems(KFileItemList) by slotItemsAdded(KUrl,KFileItemList)) + // Currently, this function tries to insert child items of multiple + // directories by invoking the slot only once. +#if 0 qInstallMsgHandler(myMessageOutput); KFileItemModel model; @@ -289,8 +294,9 @@ void KFileItemModelBenchmark::insertManyChildItems() } // Bring the items into random order. - KRandomSequence randomSequence(0); - randomSequence.randomize(newItems); + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(newItems.begin(), newItems.end(), g); // Measure how long it takes to insert and then remove all files. QBENCHMARK { @@ -307,22 +313,22 @@ void KFileItemModelBenchmark::insertManyChildItems() QCOMPARE(model.count(), numberOfFolders); QVERIFY(model.isConsistent()); } +#endif } KFileItemList KFileItemModelBenchmark::createFileItemList(const QStringList& fileNames, const QString& prefix) { // Suppress 'file does not exist anymore' messages from KFileItemPrivate::init(). - qInstallMsgHandler(myMessageOutput); + qInstallMessageHandler(myMessageOutput); KFileItemList result; foreach (const QString& name, fileNames) { - const KUrl url(prefix + name); - const KFileItem item(url, QString(), KFileItem::Unknown); + const KFileItem item(QUrl::fromLocalFile(prefix + name), QString(), KFileItem::Unknown); result << item; } return result; } -QTEST_KDEMAIN(KFileItemModelBenchmark, NoGUI) +QTEST_MAIN(KFileItemModelBenchmark) #include "kfileitemmodelbenchmark.moc"