* 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) {
}
}
-namespace {
- const int DefaultTimeout = 5000;
-};
-
Q_DECLARE_METATYPE(KFileItemList)
Q_DECLARE_METATYPE(KItemRangeList)
// 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());
}
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;
}
// 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 {
QCOMPARE(model.count(), numberOfFolders);
QVERIFY(model.isConsistent());
}
+#endif
}
KFileItemList KFileItemModelBenchmark::createFileItemList(const QStringList& fileNames, const QString& prefix)
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"