X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/5f57256a2f293622c7a10844adae29190907b9eb..8b4d3624ad1be3de678cc5fcaa5a6baa43767914:/src/tests/kfileitemmodeltest.cpp diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index b455c521d..c7d5307ed 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -1,37 +1,26 @@ -/*************************************************************************** - * Copyright (C) 2011 by Peter Penz * - * Copyright (C) 2011 by Frank Reininghaus * - * * - * 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 * - ***************************************************************************/ +/* + * SPDX-FileCopyrightText: 2011 Peter Penz + * SPDX-FileCopyrightText: 2011 Frank Reininghaus + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include #include #include +#include #include #include +#include #include #include "kitemviews/kfileitemmodel.h" -#include "kitemviews/private/kfileitemmodeldirlister.h" #include "testdir.h" void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg) { - Q_UNUSED(context); + Q_UNUSED(context) switch (type) { case QtDebugMsg: @@ -57,8 +46,9 @@ class KFileItemModelTest : public QObject { Q_OBJECT -private slots: +private Q_SLOTS: void init(); + void initTestCase(); void cleanup(); void testDefaultRoles(); @@ -105,6 +95,11 @@ private: TestDir* m_testDir; }; +void KFileItemModelTest::initTestCase() +{ + QStandardPaths::setTestModeEnabled(true); +} + void KFileItemModelTest::init() { // The item-model tests result in a huge number of debugging @@ -450,9 +445,9 @@ void KFileItemModelTest::testModelConsistencyWhenInsertingItems() itemsInsertedSpy.clear(); for (int j = 0; j < 10; ++j) { - int itemName = qrand(); + int itemName = QRandomGenerator::global()->generate(); while (insertedItems.contains(itemName)) { - itemName = qrand(); + itemName = QRandomGenerator::global()->generate(); } insertedItems.insert(itemName); @@ -460,7 +455,7 @@ void KFileItemModelTest::testModelConsistencyWhenInsertingItems() } m_model->m_dirLister->updateDirectory(m_testDir->url()); - if (itemsInsertedSpy.count() == 0) { + if (itemsInsertedSpy.isEmpty()) { QVERIFY(itemsInsertedSpy.wait()); } @@ -1551,25 +1546,26 @@ void KFileItemModelTest::testChangeSortRoleWhileFiltering() { KFileItemList items; - KIO::UDSEntry entry; - entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, 0100000); // S_IFREG might not be defined on non-Unix platforms. - entry.insert(KIO::UDSEntry::UDS_ACCESS, 07777); - entry.insert(KIO::UDSEntry::UDS_SIZE, 0); - entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME, 0); - entry.insert(KIO::UDSEntry::UDS_GROUP, "group"); - entry.insert(KIO::UDSEntry::UDS_ACCESS_TIME, 0); - - entry.insert(KIO::UDSEntry::UDS_NAME, "a.txt"); - entry.insert(KIO::UDSEntry::UDS_USER, "user-b"); - items.append(KFileItem(entry, m_testDir->url(), false, true)); - - entry.insert(KIO::UDSEntry::UDS_NAME, "b.txt"); - entry.insert(KIO::UDSEntry::UDS_USER, "user-c"); - items.append(KFileItem(entry, m_testDir->url(), false, true)); - - entry.insert(KIO::UDSEntry::UDS_NAME, "c.txt"); - entry.insert(KIO::UDSEntry::UDS_USER, "user-a"); - items.append(KFileItem(entry, m_testDir->url(), false, true)); + KIO::UDSEntry entry[3]; + + entry[0].fastInsert(KIO::UDSEntry::UDS_NAME, "a.txt"); + entry[0].fastInsert(KIO::UDSEntry::UDS_USER, "user-b"); + + entry[1].fastInsert(KIO::UDSEntry::UDS_NAME, "b.txt"); + entry[1].fastInsert(KIO::UDSEntry::UDS_USER, "user-c"); + + entry[2].fastInsert(KIO::UDSEntry::UDS_NAME, "c.txt"); + entry[2].fastInsert(KIO::UDSEntry::UDS_USER, "user-a"); + + for (int i = 0; i < 3; ++i) { + entry[i].fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, 0100000); // S_IFREG might not be defined on non-Unix platforms. + entry[i].fastInsert(KIO::UDSEntry::UDS_ACCESS, 07777); + entry[i].fastInsert(KIO::UDSEntry::UDS_SIZE, 0); + entry[i].fastInsert(KIO::UDSEntry::UDS_MODIFICATION_TIME, 0); + entry[i].fastInsert(KIO::UDSEntry::UDS_GROUP, "group"); + entry[i].fastInsert(KIO::UDSEntry::UDS_ACCESS_TIME, 0); + items.append(KFileItem(entry[i], m_testDir->url(), false, true)); + } m_model->slotItemsAdded(m_testDir->url(), items); m_model->slotCompleted();