]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tests/kfileitemmodelbenchmark.cpp
SVN_SILENT made messages (.desktop file) - always resolve ours
[dolphin.git] / src / tests / kfileitemmodelbenchmark.cpp
index 7017863ab177636df5484d7bd3e0270ddfc29eb7..4eeb9ff55f38ec35087b5ae432513a0d7b5dc076 100644 (file)
@@ -1,45 +1,36 @@
-/***************************************************************************
- *   Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>             *
- *   Copyright (C) 2013 by Frank Reininghaus <frank78ac@googlemail.com>    *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
-
-#include <qtest_kde.h>
-
-#include <KGlobalSettings>
+/*
+ * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
+ * SPDX-FileCopyrightText: 2013 Frank Reininghaus <frank78ac@googlemail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <QSignalSpy>
+#include <QStandardPaths>
+#include <QTest>
+
+#include <random>
 
 #include "kitemviews/kfileitemmodel.h"
 #include "kitemviews/private/kfileitemmodelsortalgorithm.h"
 
-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;
+        break;
     }
 }
 
@@ -53,18 +44,24 @@ class KFileItemModelBenchmark : public QObject
 public:
     KFileItemModelBenchmark();
 
-private slots:
+private Q_SLOTS:
+    void initTestCase();
     void insertAndRemoveManyItems_data();
     void insertAndRemoveManyItems();
 
 private:
-    static KFileItemList createFileItemList(const QStringList& fileNames, const QString& urlPrefix = QLatin1String("file:///"));
+    static KFileItemList createFileItemList(const QStringList &fileNames, const QString &urlPrefix = QLatin1String("file:///"));
 };
 
 KFileItemModelBenchmark::KFileItemModelBenchmark()
 {
 }
 
+void KFileItemModelBenchmark::initTestCase()
+{
+    QStandardPaths::setTestModeEnabled(true);
+}
+
 void KFileItemModelBenchmark::insertAndRemoveManyItems_data()
 {
     QTest::addColumn<KFileItemList>("initialItems");
@@ -75,10 +72,9 @@ void KFileItemModelBenchmark::insertAndRemoveManyItems_data()
     QTest::addColumn<KItemRangeList>("expectedItemsRemoved");
 
     QList<int> sizes;
-    sizes << 1000 << 4000 << 16000 << 64000 << 256000;
-    //sizes << 50000 << 100000 << 150000 << 200000 << 250000;
+    sizes << 100000;
 
-    foreach (int n, sizes) {
+    for (int n : std::as_const(sizes)) {
         QStringList allStrings;
         for (int i = 0; i < n; ++i) {
             allStrings << QString::number(i);
@@ -160,25 +156,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)));
+    QSignalSpy spyItemsInserted(&model, &KFileItemModel::itemsInserted);
+    QSignalSpy spyItemsRemoved(&model, &KFileItemModel::itemsRemoved);
 
     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());
     }
@@ -202,20 +198,19 @@ void KFileItemModelBenchmark::insertAndRemoveManyItems()
     }
 }
 
-KFileItemList KFileItemModelBenchmark::createFileItemList(const QStringList& fileNames, const QString& prefix)
+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);
+    for (const QString &name : fileNames) {
+        const KFileItem item(QUrl::fromLocalFile(prefix + name), QString(), KFileItem::Unknown);
         result << item;
     }
     return result;
 }
 
-QTEST_KDEMAIN(KFileItemModelBenchmark, NoGUI)
+QTEST_MAIN(KFileItemModelBenchmark)
 
 #include "kfileitemmodelbenchmark.moc"