]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tests/kfileitemmodelbenchmark.cpp
Clean up includes
[dolphin.git] / src / tests / kfileitemmodelbenchmark.cpp
index b1e777c065fe66295364c1d9247fa34ee67df377..c970a7198c422db41c558a88a5d573bd70172b28 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
  ***************************************************************************/
 
-#include <qtest_kde.h>
+#include <QTest>
+#include <QSignalSpy>
+
+#include <algorithm>
+#include <random>
 
 #include "kitemviews/kfileitemmodel.h"
 #include "kitemviews/private/kfileitemmodelsortalgorithm.h"
 
 #include "testdir.h"
 
-#include <KRandomSequence>
-
 void myMessageOutput(QtMsgType type, const char* msg)
 {
     switch (type) {
@@ -45,10 +47,6 @@ void myMessageOutput(QtMsgType type, const char* msg)
     }
 }
 
-namespace {
-    const int DefaultTimeout = 5000;
-};
-
 Q_DECLARE_METATYPE(KFileItemList)
 Q_DECLARE_METATYPE(KItemRangeList)
 
@@ -167,25 +165,25 @@ void KFileItemModelBenchmark::insertAndRemoveManyItems()
     // Avoid overhead caused by natural sorting
     // and determining the isDir/isLink roles.
     model.m_naturalSorting = false;
-    model.setRoles(QSet<QByteArray>() << "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 +209,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 +292,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,6 +311,7 @@ void KFileItemModelBenchmark::insertManyChildItems()
         QCOMPARE(model.count(), numberOfFolders);
         QVERIFY(model.isConsistent());
     }
+#endif
 }
 
 KFileItemList KFileItemModelBenchmark::createFileItemList(const QStringList& fileNames, const QString& prefix)
@@ -316,13 +321,12 @@ KFileItemList KFileItemModelBenchmark::createFileItemList(const QStringList& fil
 
     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"