diff options
| author | Serg Podtynnyi <[email protected]> | 2023-02-04 00:14:53 +0700 |
|---|---|---|
| committer | Serg Podtynnyi <[email protected]> | 2023-02-05 12:45:38 +0700 |
| commit | 38c34eeca315c7be58e65d4d3fb72aaf7b866719 (patch) | |
| tree | 886e53f20c9c43edc3eb7fe04789716a9bc98ebe /src/tests | |
| parent | ffff8af851e3a386c44438337779d0ce7ca98a61 (diff) | |
Add clang-format and format code as in Frameworks
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/dolphinmainwindowtest.cpp | 46 | ||||
| -rw-r--r-- | src/tests/dolphinquerytest.cpp | 104 | ||||
| -rw-r--r-- | src/tests/dolphinsearchboxtest.cpp | 2 | ||||
| -rw-r--r-- | src/tests/draganddrophelpertest.cpp | 32 | ||||
| -rw-r--r-- | src/tests/kfileitemlistviewtest.cpp | 10 | ||||
| -rw-r--r-- | src/tests/kfileitemmodelbenchmark.cpp | 12 | ||||
| -rw-r--r-- | src/tests/kfileitemmodeltest.cpp | 672 | ||||
| -rw-r--r-- | src/tests/kitemlistcontrollertest.cpp | 318 | ||||
| -rw-r--r-- | src/tests/kitemlistkeyboardsearchmanagertest.cpp | 2 | ||||
| -rw-r--r-- | src/tests/kitemlistselectionmanagertest.cpp | 151 | ||||
| -rw-r--r-- | src/tests/kitemrangetest.cpp | 2 | ||||
| -rw-r--r-- | src/tests/kitemsettest.cpp | 50 | ||||
| -rw-r--r-- | src/tests/testdir.cpp | 24 | ||||
| -rw-r--r-- | src/tests/testdir.h | 24 | ||||
| -rw-r--r-- | src/tests/viewpropertiestest.cpp | 4 |
15 files changed, 869 insertions, 584 deletions
diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index eefca4204..e849c4937 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -40,7 +40,6 @@ private Q_SLOTS: void testGoActions(); void cleanupTestCase(); - private: QScopedPointer<DolphinMainWindow> m_mainWindow; }; @@ -58,13 +57,13 @@ void DolphinMainWindowTest::init() // See https://bugs.kde.org/show_bug.cgi?id=379135 void DolphinMainWindowTest::testClosingTabsWithSearchBoxVisible() { - m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false); + m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false); m_mainWindow->show(); // Without this call the searchbox doesn't get FocusIn events. QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); - auto tabWidget = m_mainWindow->findChild<DolphinTabWidget*>("tabWidget"); + auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget"); QVERIFY(tabWidget); // Show search box on first tab. @@ -88,12 +87,12 @@ void DolphinMainWindowTest::testActiveViewAfterClosingSplitView_data() void DolphinMainWindowTest::testActiveViewAfterClosingSplitView() { - m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false); + m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false); m_mainWindow->show(); QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); - auto tabWidget = m_mainWindow->findChild<DolphinTabWidget*>("tabWidget"); + auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget"); QVERIFY(tabWidget); QVERIFY(tabWidget->currentTabPage()->primaryViewContainer()); QVERIFY(!tabWidget->currentTabPage()->secondaryViewContainer()); @@ -133,12 +132,12 @@ void DolphinMainWindowTest::testActiveViewAfterClosingSplitView() // Test case for bug #385111 void DolphinMainWindowTest::testUpdateWindowTitleAfterClosingSplitView() { - m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false); + m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false); m_mainWindow->show(); QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); - auto tabWidget = m_mainWindow->findChild<DolphinTabWidget*>("tabWidget"); + auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget"); QVERIFY(tabWidget); QVERIFY(tabWidget->currentTabPage()->primaryViewContainer()); QVERIFY(!tabWidget->currentTabPage()->secondaryViewContainer()); @@ -174,12 +173,12 @@ void DolphinMainWindowTest::testUpdateWindowTitleAfterClosingSplitView() // Test case for bug #402641 void DolphinMainWindowTest::testUpdateWindowTitleAfterChangingSplitView() { - m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false); + m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false); m_mainWindow->show(); QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); - auto tabWidget = m_mainWindow->findChild<DolphinTabWidget*>("tabWidget"); + auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget"); QVERIFY(tabWidget); // Open split view. @@ -204,12 +203,12 @@ void DolphinMainWindowTest::testUpdateWindowTitleAfterChangingSplitView() // Test case for bug #397910 void DolphinMainWindowTest::testOpenInNewTabTitle() { - m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false); + m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false); m_mainWindow->show(); QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); - auto tabWidget = m_mainWindow->findChild<DolphinTabWidget*>("tabWidget"); + auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget"); QVERIFY(tabWidget); tabWidget->openNewTab(QUrl::fromLocalFile(QDir::tempPath())); @@ -234,12 +233,12 @@ void DolphinMainWindowTest::testNewFileMenuEnabled_data() void DolphinMainWindowTest::testNewFileMenuEnabled() { QFETCH(QUrl, activeViewUrl); - m_mainWindow->openDirectories({ activeViewUrl }, false); + m_mainWindow->openDirectories({activeViewUrl}, false); m_mainWindow->show(); QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); - auto newFileMenu = m_mainWindow->findChild<DolphinNewFileMenu*>("new_menu"); + auto newFileMenu = m_mainWindow->findChild<DolphinNewFileMenu *>("new_menu"); QVERIFY(newFileMenu); QFETCH(bool, expectedEnabled); @@ -260,7 +259,7 @@ void DolphinMainWindowTest::testWindowTitle_data() void DolphinMainWindowTest::testWindowTitle() { QFETCH(QUrl, activeViewUrl); - m_mainWindow->openDirectories({ activeViewUrl }, false); + m_mainWindow->openDirectories({activeViewUrl}, false); m_mainWindow->show(); QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); @@ -275,14 +274,19 @@ void DolphinMainWindowTest::testWindowTitle() */ void DolphinMainWindowTest::testPlacesPanelWidthResistance() { - m_mainWindow->openDirectories({ QUrl::fromLocalFile(QDir::homePath()) }, false); + m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false); m_mainWindow->show(); m_mainWindow->resize(800, m_mainWindow->height()); // make sure the size is sufficient so a places panel resize shouldn't be necessary. QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); QWidget *placesPanel = reinterpret_cast<QWidget *>(m_mainWindow->m_placesPanel); - QVERIFY2(QTest::qWaitFor([&](){ return placesPanel && placesPanel->isVisible() && placesPanel->width() > 0; }, 5000), "The test couldn't be initialised properly. The places panel should be visible."); + QVERIFY2(QTest::qWaitFor( + [&]() { + return placesPanel && placesPanel->isVisible() && placesPanel->width() > 0; + }, + 5000), + "The test couldn't be initialised properly. The places panel should be visible."); QTest::qWait(100); const int initialPlacesPanelWidth = placesPanel->width(); @@ -296,7 +300,8 @@ void DolphinMainWindowTest::testPlacesPanelWidthResistance() // Make all selection mode bars appear and test for each that this doesn't affect the places panel's width. // One of the bottom bars (SelectionMode::BottomBar::GeneralContents) only shows up when at least one item is selected so we do that before we begin iterating. m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::SelectAll))->trigger(); - for (int selectionModeStates = SelectionMode::BottomBar::CopyContents; selectionModeStates != SelectionMode::BottomBar::RenameContents; selectionModeStates++) { + for (int selectionModeStates = SelectionMode::BottomBar::CopyContents; selectionModeStates != SelectionMode::BottomBar::RenameContents; + selectionModeStates++) { const auto contents = static_cast<SelectionMode::BottomBar::Contents>(selectionModeStates); m_mainWindow->slotSetSelectionMode(true, contents); QTest::qWait(20); // give time for a paint/resize @@ -345,7 +350,7 @@ void DolphinMainWindowTest::testGoActions() testDir->createFile("b/b-2"); testDir->createDir("c"); QUrl childDirUrl(QDir::cleanPath(testDir->url().toString() + "/b")); - m_mainWindow->openDirectories({ childDirUrl }, false); // Open "b" dir + m_mainWindow->openDirectories({childDirUrl}, false); // Open "b" dir m_mainWindow->show(); QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); QVERIFY(m_mainWindow->isVisible()); @@ -358,7 +363,9 @@ void DolphinMainWindowTest::testGoActions() */ QSignalSpy spyDirectoryLoadingCompleted(m_mainWindow->m_activeViewContainer->view(), &DolphinView::directoryLoadingCompleted); QVERIFY(spyDirectoryLoadingCompleted.wait()); - QVERIFY(QTest::qWaitFor([&](){ return !m_mainWindow->actionCollection()->action(QStringLiteral("stop"))->isEnabled(); })); // "Stop" command should be disabled because it finished loading + QVERIFY(QTest::qWaitFor([&]() { + return !m_mainWindow->actionCollection()->action(QStringLiteral("stop"))->isEnabled(); + })); // "Stop" command should be disabled because it finished loading QTest::qWait(500); // Somehow the item we emerged from doesn't have keyboard focus yet if we don't wait a split second. const QUrl parentDirUrl = m_mainWindow->activeViewContainer()->url(); QVERIFY(parentDirUrl != childDirUrl); @@ -429,7 +436,6 @@ void DolphinMainWindowTest::cleanupTestCase() m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Quit))->trigger(); } - QTEST_MAIN(DolphinMainWindowTest) #include "dolphinmainwindowtest.moc" diff --git a/src/tests/dolphinquerytest.cpp b/src/tests/dolphinquerytest.cpp index 2b025eed7..b6feab686 100644 --- a/src/tests/dolphinquerytest.cpp +++ b/src/tests/dolphinquerytest.cpp @@ -10,8 +10,8 @@ #include <QJsonDocument> #include <QJsonObject> -#include <QStringList> #include <QStandardPaths> +#include <QStringList> #include <QUrl> #include <QUrlQuery> @@ -28,11 +28,9 @@ private Q_SLOTS: /** * Helper function to compose the baloo query URL used for searching */ -QUrl balooQueryUrl(const QString& searchString) +QUrl balooQueryUrl(const QString &searchString) { - const QJsonObject jsonObject { - {"searchString", searchString} - }; + const QJsonObject jsonObject{{"searchString", searchString}}; const QJsonDocument doc(jsonObject); const QString queryString = QString::fromUtf8(doc.toJson(QJsonDocument::Compact)); @@ -57,7 +55,6 @@ void DolphinQueryTest::initTestCase() */ void DolphinQueryTest::testBalooSearchParsing_data() { - QTest::addColumn<QUrl>("searchUrl"); QTest::addColumn<QString>("expectedText"); QTest::addColumn<QStringList>("expectedTerms"); @@ -78,81 +75,76 @@ void DolphinQueryTest::testBalooSearchParsing_data() const QString modified = QStringLiteral("modified>=2019-08-07"); const QString tag = QStringLiteral("tag:tagA"); - const QString tagS = QStringLiteral("tag:\"tagB with spaces\""); // in search url - const QString tagR = QStringLiteral("tag:tagB with spaces"); // in result term + const QString tagS = QStringLiteral("tag:\"tagB with spaces\""); // in search url + const QString tagR = QStringLiteral("tag:tagB with spaces"); // in result term // Test for "Content" - QTest::newRow("content") << balooQueryUrl(text) << text << QStringList() << true << false; - QTest::newRow("content/space") << balooQueryUrl(textS) << textS << QStringList() << true << false; - QTest::newRow("content/quoted") << balooQueryUrl(textQ) << textS << QStringList() << true << false; - QTest::newRow("content/empty") << balooQueryUrl("") << "" << QStringList() << false << false; - QTest::newRow("content/single_quote") << balooQueryUrl("\"") << "\"" << QStringList() << true << false; - QTest::newRow("content/double_quote") << balooQueryUrl("\"\"") << "" << QStringList() << false << false; + QTest::newRow("content") << balooQueryUrl(text) << text << QStringList() << true << false; + QTest::newRow("content/space") << balooQueryUrl(textS) << textS << QStringList() << true << false; + QTest::newRow("content/quoted") << balooQueryUrl(textQ) << textS << QStringList() << true << false; + QTest::newRow("content/empty") << balooQueryUrl("") << "" << QStringList() << false << false; + QTest::newRow("content/single_quote") << balooQueryUrl("\"") << "\"" << QStringList() << true << false; + QTest::newRow("content/double_quote") << balooQueryUrl("\"\"") << "" << QStringList() << false << false; // Test for "FileName" - QTest::newRow("filename") << balooQueryUrl(filename) << text << QStringList() << false << true; - QTest::newRow("filename/space") << balooQueryUrl(filenameS) << textS << QStringList() << false << true; - QTest::newRow("filename/quoted") << balooQueryUrl(filenameQ) << textQ << QStringList() << false << true; - QTest::newRow("filename/mixed") << balooQueryUrl(filenameM) << textM << QStringList() << false << true; - QTest::newRow("filename/empty") << balooQueryUrl("filename:") << "" << QStringList() << false << false; - QTest::newRow("filename/single_quote") << balooQueryUrl("filename:\"") << "\"" << QStringList() << false << true; - QTest::newRow("filename/double_quote") << balooQueryUrl("filename:\"\"") << "" << QStringList() << false << false; + QTest::newRow("filename") << balooQueryUrl(filename) << text << QStringList() << false << true; + QTest::newRow("filename/space") << balooQueryUrl(filenameS) << textS << QStringList() << false << true; + QTest::newRow("filename/quoted") << balooQueryUrl(filenameQ) << textQ << QStringList() << false << true; + QTest::newRow("filename/mixed") << balooQueryUrl(filenameM) << textM << QStringList() << false << true; + QTest::newRow("filename/empty") << balooQueryUrl("filename:") << "" << QStringList() << false << false; + QTest::newRow("filename/single_quote") << balooQueryUrl("filename:\"") << "\"" << QStringList() << false << true; + QTest::newRow("filename/double_quote") << balooQueryUrl("filename:\"\"") << "" << QStringList() << false << false; // Combined content and filename search - QTest::newRow("content+filename") - << balooQueryUrl(text + " " + filename) - << text + " " + filename << QStringList() << true << true; + QTest::newRow("content+filename") << balooQueryUrl(text + " " + filename) << text + " " + filename << QStringList() << true << true; - QTest::newRow("content+filename/quoted") - << balooQueryUrl(textQ + " " + filenameQ) - << textS + " " + filenameQ << QStringList() << true << true; + QTest::newRow("content+filename/quoted") << balooQueryUrl(textQ + " " + filenameQ) << textS + " " + filenameQ << QStringList() << true << true; // Test for rating - QTest::newRow("rating") << balooQueryUrl(rating) << "" << QStringList({rating}) << false << false; - QTest::newRow("rating+content") << balooQueryUrl(rating + " " + text) << text << QStringList({rating}) << true << false; + QTest::newRow("rating") << balooQueryUrl(rating) << "" << QStringList({rating}) << false << false; + QTest::newRow("rating+content") << balooQueryUrl(rating + " " + text) << text << QStringList({rating}) << true << false; QTest::newRow("rating+filename") << balooQueryUrl(rating + " " + filename) << text << QStringList({rating}) << false << true; // Test for modified date - QTest::newRow("modified") << balooQueryUrl(modified) << "" << QStringList({modified}) << false << false; - QTest::newRow("modified+content") << balooQueryUrl(modified + " " + text) << text << QStringList({modified}) << true << false; + QTest::newRow("modified") << balooQueryUrl(modified) << "" << QStringList({modified}) << false << false; + QTest::newRow("modified+content") << balooQueryUrl(modified + " " + text) << text << QStringList({modified}) << true << false; QTest::newRow("modified+filename") << balooQueryUrl(modified + " " + filename) << text << QStringList({modified}) << false << true; // Test for tags - QTest::newRow("tag") << balooQueryUrl(tag) << "" << QStringList({tag}) << false << false; - QTest::newRow("tag/space" ) << balooQueryUrl(tagS) << "" << QStringList({tagR}) << false << false; - QTest::newRow("tag/double") << balooQueryUrl(tag + " " + tagS) << "" << QStringList({tag, tagR}) << false << false; - QTest::newRow("tag+content") << balooQueryUrl(tag + " " + text) << text << QStringList({tag}) << true << false; - QTest::newRow("tag+filename") << balooQueryUrl(tag + " " + filename) << text << QStringList({tag}) << false << true; + QTest::newRow("tag") << balooQueryUrl(tag) << "" << QStringList({tag}) << false << false; + QTest::newRow("tag/space") << balooQueryUrl(tagS) << "" << QStringList({tagR}) << false << false; + QTest::newRow("tag/double") << balooQueryUrl(tag + " " + tagS) << "" << QStringList({tag, tagR}) << false << false; + QTest::newRow("tag+content") << balooQueryUrl(tag + " " + text) << text << QStringList({tag}) << true << false; + QTest::newRow("tag+filename") << balooQueryUrl(tag + " " + filename) << text << QStringList({tag}) << false << true; // Combined search terms - QTest::newRow("searchTerms") - << balooQueryUrl(rating + " AND " + modified + " AND " + tag + " AND " + tagS) - << "" << QStringList({modified, rating, tag, tagR}) << false << false; + QTest::newRow("searchTerms") << balooQueryUrl(rating + " AND " + modified + " AND " + tag + " AND " + tagS) << "" + << QStringList({modified, rating, tag, tagR}) << false << false; - QTest::newRow("searchTerms+content") - << balooQueryUrl(rating + " AND " + modified + " " + text + " " + tag + " AND " + tagS) - << text << QStringList({modified, rating, tag, tagR}) << true << false; + QTest::newRow("searchTerms+content") << balooQueryUrl(rating + " AND " + modified + " " + text + " " + tag + " AND " + tagS) << text + << QStringList({modified, rating, tag, tagR}) << true << false; - QTest::newRow("searchTerms+filename") - << balooQueryUrl(rating + " AND " + modified + " " + filename + " " + tag + " AND " + tagS) - << text << QStringList({modified, rating, tag, tagR}) << false << true; + QTest::newRow("searchTerms+filename") << balooQueryUrl(rating + " AND " + modified + " " + filename + " " + tag + " AND " + tagS) << text + << QStringList({modified, rating, tag, tagR}) << false << true; - QTest::newRow("allTerms") - << balooQueryUrl(text + " " + filename + " " + rating + " AND " + modified + " AND " + tag) - << text + " " + filename << QStringList({modified, rating, tag}) << true << true; + QTest::newRow("allTerms") << balooQueryUrl(text + " " + filename + " " + rating + " AND " + modified + " AND " + tag) << text + " " + filename + << QStringList({modified, rating, tag}) << true << true; - QTest::newRow("allTerms/space") - << balooQueryUrl(textS + " " + filenameS + " " + rating + " AND " + modified + " AND " + tagS) - << textS + " " + filenameS << QStringList({modified, rating, tagR}) << true << true; + QTest::newRow("allTerms/space") << balooQueryUrl(textS + " " + filenameS + " " + rating + " AND " + modified + " AND " + tagS) << textS + " " + filenameS + << QStringList({modified, rating, tagR}) << true << true; // Test tags:/ URL scheme - const auto tagUrl = [](const QString &tag) { return QUrl(QStringLiteral("tags:/%1/").arg(tag)); }; - const auto tagTerms = [](const QString &tag) { return QStringList{QStringLiteral("tag:%1").arg(tag)}; }; + const auto tagUrl = [](const QString &tag) { + return QUrl(QStringLiteral("tags:/%1/").arg(tag)); + }; + const auto tagTerms = [](const QString &tag) { + return QStringList{QStringLiteral("tag:%1").arg(tag)}; + }; - QTest::newRow("tagsUrl") << tagUrl("tagA") << "" << tagTerms("tagA") << false << false; + QTest::newRow("tagsUrl") << tagUrl("tagA") << "" << tagTerms("tagA") << false << false; QTest::newRow("tagsUrl/space") << tagUrl("tagB with spaces") << "" << tagTerms("tagB with spaces") << false << false; - QTest::newRow("tagsUrl/hash") << tagUrl("tagC#hash") << "" << tagTerms("tagC#hash") << false << false; - QTest::newRow("tagsUrl/slash") << tagUrl("tagD/with/slash") << "" << tagTerms("tagD/with/slash") << false << false; + QTest::newRow("tagsUrl/hash") << tagUrl("tagC#hash") << "" << tagTerms("tagC#hash") << false << false; + QTest::newRow("tagsUrl/slash") << tagUrl("tagD/with/slash") << "" << tagTerms("tagD/with/slash") << false << false; } /** diff --git a/src/tests/dolphinsearchboxtest.cpp b/src/tests/dolphinsearchboxtest.cpp index 56420e56e..4bfdff76d 100644 --- a/src/tests/dolphinsearchboxtest.cpp +++ b/src/tests/dolphinsearchboxtest.cpp @@ -21,7 +21,7 @@ private Q_SLOTS: void testTextClearing(); private: - DolphinSearchBox* m_searchBox; + DolphinSearchBox *m_searchBox; }; void DolphinSearchBoxTest::initTestCase() diff --git a/src/tests/draganddrophelpertest.cpp b/src/tests/draganddrophelpertest.cpp index a82e75c7b..f2c75fef0 100644 --- a/src/tests/draganddrophelpertest.cpp +++ b/src/tests/draganddrophelpertest.cpp @@ -29,35 +29,18 @@ void DragAndDropHelperTest::testUrlListMatchesUrl_data() QTest::addColumn<QUrl>("url"); QTest::addColumn<bool>("expected"); - QTest::newRow("test_equal") - << QList<QUrl> {QUrl::fromLocalFile("/root")} - << QUrl::fromLocalFile("/root") - << true; + QTest::newRow("test_equal") << QList<QUrl>{QUrl::fromLocalFile("/root")} << QUrl::fromLocalFile("/root") << true; - QTest::newRow("test_trailing_slash") - << QList<QUrl> {QUrl::fromLocalFile("/root/")} - << QUrl::fromLocalFile("/root") - << true; + QTest::newRow("test_trailing_slash") << QList<QUrl>{QUrl::fromLocalFile("/root/")} << QUrl::fromLocalFile("/root") << true; - QTest::newRow("test_ftp_scheme") - << QList<QUrl> {QUrl("ftp://server:2211/dir")} - << QUrl("ftp://server:2211/dir") - << true; + QTest::newRow("test_ftp_scheme") << QList<QUrl>{QUrl("ftp://server:2211/dir")} << QUrl("ftp://server:2211/dir") << true; - QTest::newRow("test_not_matched") - << QList<QUrl> {QUrl::fromLocalFile("/usr/share"), QUrl::fromLocalFile("/usr/local/bin")} - << QUrl::fromLocalFile("/usr/bin") - << false; + QTest::newRow("test_not_matched") << QList<QUrl>{QUrl::fromLocalFile("/usr/share"), QUrl::fromLocalFile("/usr/local/bin")} + << QUrl::fromLocalFile("/usr/bin") << false; - QTest::newRow("test_empty_target") - << QList<QUrl> {QUrl::fromLocalFile("/usr/share"), QUrl::fromLocalFile("/usr/local/bin")} - << QUrl() - << false; + QTest::newRow("test_empty_target") << QList<QUrl>{QUrl::fromLocalFile("/usr/share"), QUrl::fromLocalFile("/usr/local/bin")} << QUrl() << false; - QTest::newRow("test_empty_list") - << QList<QUrl>() - << QUrl::fromLocalFile("/usr/bin") - << false; + QTest::newRow("test_empty_list") << QList<QUrl>() << QUrl::fromLocalFile("/usr/bin") << false; } void DragAndDropHelperTest::testUrlListMatchesUrl() @@ -69,7 +52,6 @@ void DragAndDropHelperTest::testUrlListMatchesUrl() QCOMPARE(DragAndDropHelper::urlListMatchesUrl(urlList, url), expected); } - QTEST_MAIN(DragAndDropHelperTest) #include "draganddrophelpertest.moc" diff --git a/src/tests/kfileitemlistviewtest.cpp b/src/tests/kfileitemlistviewtest.cpp index 22d5d3a01..42dc4fc77 100644 --- a/src/tests/kfileitemlistviewtest.cpp +++ b/src/tests/kfileitemlistviewtest.cpp @@ -11,9 +11,9 @@ #include <KDirLister> #include <QGraphicsView> -#include <QTest> #include <QSignalSpy> #include <QStandardPaths> +#include <QTest> class KFileItemListViewTest : public QObject { @@ -26,10 +26,10 @@ private Q_SLOTS: void testGroupedItemChanges(); private: - KFileItemListView* m_listView; - KFileItemModel* m_model; - TestDir* m_testDir; - QGraphicsView* m_graphicsView; + KFileItemListView *m_listView; + KFileItemModel *m_model; + TestDir *m_testDir; + QGraphicsView *m_graphicsView; }; void KFileItemListViewTest::initTestCase() diff --git a/src/tests/kfileitemmodelbenchmark.cpp b/src/tests/kfileitemmodelbenchmark.cpp index 8e307e2a1..0daf4abd0 100644 --- a/src/tests/kfileitemmodelbenchmark.cpp +++ b/src/tests/kfileitemmodelbenchmark.cpp @@ -5,16 +5,16 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#include <QTest> #include <QSignalSpy> #include <QStandardPaths> +#include <QTest> #include <random> #include "kitemviews/kfileitemmodel.h" #include "kitemviews/private/kfileitemmodelsortalgorithm.h" -void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg) +void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { Q_UNUSED(context) @@ -30,7 +30,7 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QS fprintf(stderr, "Fatal: %s\n", msg.toLocal8Bit().data()); abort(); default: - break; + break; } } @@ -50,7 +50,7 @@ private Q_SLOTS: 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() @@ -198,13 +198,13 @@ 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(). qInstallMessageHandler(myMessageOutput); KFileItemList result; - for (const QString& name : fileNames) { + for (const QString &name : fileNames) { const KFileItem item(QUrl::fromLocalFile(prefix + name), QString(), KFileItem::Unknown); result << item; } diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index fef8bd581..38d2544aa 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -5,22 +5,21 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ +#include <QMimeData> #include <QRandomGenerator> -#include <QTest> #include <QSignalSpy> #include <QStandardPaths> +#include <QTest> #include <QTimer> -#include <QMimeData> #include <KDirLister> #include <kio/job.h> #include <kio_version.h> - #include "kitemviews/kfileitemmodel.h" #include "testdir.h" -void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg) +void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { Q_UNUSED(context) @@ -36,7 +35,7 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QS fprintf(stderr, "Fatal: %s\n", msg.toLocal8Bit().data()); abort(); default: - break; + break; } } @@ -99,8 +98,8 @@ private: QStringList itemsInModel() const; private: - KFileItemModel* m_model; - TestDir* m_testDir; + KFileItemModel *m_model; + TestDir *m_testDir; }; void KFileItemModelTest::initTestCase() @@ -283,11 +282,11 @@ void KFileItemModelTest::testSetDataWithModifiedSortRole_data() // Index 2 = rating 6 QTest::newRow("Index 0: Rating 3") << 0 << 3 << false << 3 << 4 << 6; - QTest::newRow("Index 0: Rating 5") << 0 << 5 << true << 4 << 5 << 6; - QTest::newRow("Index 0: Rating 8") << 0 << 8 << true << 4 << 6 << 8; + QTest::newRow("Index 0: Rating 5") << 0 << 5 << true << 4 << 5 << 6; + QTest::newRow("Index 0: Rating 8") << 0 << 8 << true << 4 << 6 << 8; - QTest::newRow("Index 2: Rating 1") << 2 << 1 << true << 1 << 2 << 4; - QTest::newRow("Index 2: Rating 3") << 2 << 3 << true << 2 << 3 << 4; + QTest::newRow("Index 2: Rating 1") << 2 << 1 << true << 1 << 2 << 4; + QTest::newRow("Index 2: Rating 3") << 2 << 3 << true << 2 << 3 << 4; QTest::newRow("Index 2: Rating 5") << 2 << 5 << false << 2 << 4 << 5; } @@ -365,7 +364,10 @@ void KFileItemModelTest::testChangeSortRole() m_model->loadDirectory(m_testDir->url()); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.jpg" << "c.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.jpg" + << "c.txt"); // Simulate that KFileItemModelRolesUpdater determines the mime type. // Resorting the files by 'type' will only work immediately if their @@ -382,10 +384,14 @@ void KFileItemModelTest::testChangeSortRole() // The actual order of the files might depend on the translation of the // result of KFileItem::mimeComment() in the user's language. QStringList version1; - version1 << "b.jpg" << "a.txt" << "c.txt"; + version1 << "b.jpg" + << "a.txt" + << "c.txt"; QStringList version2; - version2 << "a.txt" << "c.txt" << "b.jpg"; + version2 << "a.txt" + << "c.txt" + << "b.jpg"; const bool ok1 = (itemsInModel() == version1); const bool ok2 = (itemsInModel() == version2); @@ -407,7 +413,10 @@ void KFileItemModelTest::testResortAfterChangingName() m_model->loadDirectory(m_testDir->url()); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.txt" + << "c.txt"); // We rename a.txt to d.txt. Even though the size has not changed at all, // the model must re-sort the items. @@ -416,7 +425,10 @@ void KFileItemModelTest::testResortAfterChangingName() m_model->setData(0, data); QVERIFY(itemsMovedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "b.txt" << "c.txt" << "d.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "b.txt" + << "c.txt" + << "d.txt"); // We rename d.txt back to a.txt using the dir lister's refreshItems() signal. const KFileItem fileItemD = m_model->fileItem(2); @@ -428,7 +440,10 @@ void KFileItemModelTest::testResortAfterChangingName() m_model->slotRefreshItems({qMakePair(fileItemD, fileItemA)}); QVERIFY(itemsMovedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.txt" + << "c.txt"); } void KFileItemModelTest::testModelConsistencyWhenInsertingItems() @@ -528,15 +543,16 @@ void KFileItemModelTest::testExpandItems() // first three characters. QSet<QByteArray> originalModelRoles = m_model->roles(); QSet<QByteArray> modelRoles = originalModelRoles; - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFiles({"a/a/1", "a/a-1/1"}); // Store the URLs of all folders in a set. QSet<QUrl> allFolders; - allFolders << QUrl::fromLocalFile(m_testDir->path() + "/a") - << QUrl::fromLocalFile(m_testDir->path() + "/a/a") + allFolders << QUrl::fromLocalFile(m_testDir->path() + "/a") << QUrl::fromLocalFile(m_testDir->path() + "/a/a") << QUrl::fromLocalFile(m_testDir->path() + "/a/a-1"); m_model->loadDirectory(m_testDir->url()); @@ -572,9 +588,8 @@ void KFileItemModelTest::testExpandItems() m_model->setExpanded(1, true); QVERIFY(m_model->isExpanded(1)); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(m_model->count(), 4); // 4 items: "a/", "a/a/", "a/a/1", "a/a-1/" - QCOMPARE(m_model->expandedDirectories(), QSet<QUrl>() << QUrl::fromLocalFile(m_testDir->path() + "/a") - << QUrl::fromLocalFile(m_testDir->path() + "/a/a")); + QCOMPARE(m_model->count(), 4); // 4 items: "a/", "a/a/", "a/a/1", "a/a-1/" + QCOMPARE(m_model->expandedDirectories(), QSet<QUrl>() << QUrl::fromLocalFile(m_testDir->path() + "/a") << QUrl::fromLocalFile(m_testDir->path() + "/a/a")); QCOMPARE(itemsInsertedSpy.count(), 1); itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>(); @@ -587,7 +602,7 @@ void KFileItemModelTest::testExpandItems() m_model->setExpanded(3, true); QVERIFY(m_model->isExpanded(3)); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1" + QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1" QCOMPARE(m_model->expandedDirectories(), allFolders); QCOMPARE(itemsInsertedSpy.count(), 1); @@ -616,7 +631,7 @@ void KFileItemModelTest::testExpandItems() m_model->loadDirectory(m_testDir->url()); m_model->restoreExpandedDirectories(allFolders); QVERIFY(loadingCompletedSpy.wait()); - QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1" + QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1" QVERIFY(m_model->isExpanded(0)); QVERIFY(m_model->isExpanded(1)); QVERIFY(!m_model->isExpanded(2)); @@ -629,11 +644,11 @@ void KFileItemModelTest::testExpandItems() // This is how DolphinView restores the expanded folders when navigating in history. m_model->loadDirectory(QUrl::fromLocalFile(m_testDir->path() + "/a/a/")); QVERIFY(loadingCompletedSpy.wait()); - QCOMPARE(m_model->count(), 1); // 1 item: "1" + QCOMPARE(m_model->count(), 1); // 1 item: "1" m_model->restoreExpandedDirectories(allFolders); m_model->loadDirectory(m_testDir->url()); QVERIFY(loadingCompletedSpy.wait()); - QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1" + QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1" QCOMPARE(m_model->expandedDirectories(), allFolders); // Remove all expanded items by changing the roles @@ -664,7 +679,9 @@ void KFileItemModelTest::testExpandParentItems() // a2/b2/c2/ // a2/b2/c2/d2/ QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFiles({"a 1/b1/c1/file.txt", "a2/b2/c2/d2/file.txt"}); @@ -736,7 +753,9 @@ void KFileItemModelTest::testMakeExpandedItemHidden() QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFiles({"1a/2a/3a", "1a/2a/3b", "1a/2b", "1b"}); @@ -759,7 +778,7 @@ void KFileItemModelTest::testMakeExpandedItemHidden() const QUrl oldUrl = QUrl::fromLocalFile(m_model->fileItem(0).url().path() + "/2a"); const QUrl newUrl = QUrl::fromLocalFile(m_model->fileItem(0).url().path() + "/.2a"); - KIO::SimpleJob* job = KIO::rename(oldUrl, newUrl, KIO::HideProgressInfo); + KIO::SimpleJob *job = KIO::rename(oldUrl, newUrl, KIO::HideProgressInfo); bool ok = job->exec(); QVERIFY(ok); QVERIFY(itemsRemovedSpy.wait()); @@ -770,7 +789,6 @@ void KFileItemModelTest::testMakeExpandedItemHidden() m_model->setExpanded(0, false); QCOMPARE(m_model->count(), 2); - } void KFileItemModelTest::testRemoveFilteredExpandedItems() @@ -779,7 +797,9 @@ void KFileItemModelTest::testRemoveFilteredExpandedItems() QSet<QByteArray> originalModelRoles = m_model->roles(); QSet<QByteArray> modelRoles = originalModelRoles; - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFiles({"folder/child", "file"}); @@ -793,17 +813,24 @@ void KFileItemModelTest::testRemoveFilteredExpandedItems() QVERIFY(!m_model->isExpandable(1)); QVERIFY(!m_model->isExpanded(0)); QVERIFY(!m_model->isExpanded(1)); - QCOMPARE(itemsInModel(), QStringList() << "folder" << "file"); + QCOMPARE(itemsInModel(), + QStringList() << "folder" + << "file"); // Expand "folder" -> "folder/child" becomes visible. m_model->setExpanded(0, true); QVERIFY(m_model->isExpanded(0)); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "folder" << "child" << "file"); + QCOMPARE(itemsInModel(), + QStringList() << "folder" + << "child" + << "file"); // Add a name filter. m_model->setNameFilter("f"); - QCOMPARE(itemsInModel(), QStringList() << "folder" << "file"); + QCOMPARE(itemsInModel(), + QStringList() << "folder" + << "file"); m_model->setNameFilter("fo"); QCOMPARE(itemsInModel(), QStringList() << "folder"); @@ -815,7 +842,9 @@ void KFileItemModelTest::testRemoveFilteredExpandedItems() // Remove the name filter and verify that "folder/child" does not reappear. m_model->setNameFilter(QString()); - QCOMPARE(itemsInModel(), QStringList() << "folder" << "file"); + QCOMPARE(itemsInModel(), + QStringList() << "folder" + << "file"); } void KFileItemModelTest::testSorting() @@ -884,83 +913,155 @@ void KFileItemModelTest::testSorting() QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); QVERIFY(m_model->sortDirectoriesFirst()); QVERIFY(!m_model->showHiddenFiles()); - QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "a" << "b" << "d" << "e"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "c-2" + << "c-3" + << "c-1" + << "a" + << "b" + << "d" + << "e"); // Sort by Name, ascending, 'Sort Folders First' disabled m_model->setSortDirectoriesFirst(false); QCOMPARE(m_model->sortRole(), QByteArray("text")); QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); - QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c" << "c-1" << "c-2" << "c-3" << "d" << "e"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "b" + << "c" + << "c-1" + << "c-2" + << "c-3" + << "d" + << "e"); QCOMPARE(itemsMovedSpy.count(), 1); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(0, 6)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 2 << 4 << 5 << 3 << 0 << 1); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 2 << 4 << 5 << 3 << 0 << 1); // Sort by Name, descending m_model->setSortDirectoriesFirst(true); m_model->setSortOrder(Qt::DescendingOrder); QCOMPARE(m_model->sortRole(), QByteArray("text")); QCOMPARE(m_model->sortOrder(), Qt::DescendingOrder); - QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "e" << "d" << "b" << "a"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "c-2" + << "c-3" + << "c-1" + << "e" + << "d" + << "b" + << "a"); QCOMPARE(itemsMovedSpy.count(), 2); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(0, 6)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 4 << 5 << 0 << 3 << 1 << 2); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 4 << 5 << 0 << 3 << 1 << 2); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(4, 4)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 7 << 6 << 5 << 4); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 7 << 6 << 5 << 4); // Sort by Date, descending m_model->setSortDirectoriesFirst(true); m_model->setSortRole("modificationtime"); QCOMPARE(m_model->sortRole(), QByteArray("modificationtime")); QCOMPARE(m_model->sortOrder(), Qt::DescendingOrder); - QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "b" << "d" << "a" << "e"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "c-2" + << "c-3" + << "c-1" + << "b" + << "d" + << "a" + << "e"); QCOMPARE(itemsMovedSpy.count(), 1); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(4, 4)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 7 << 5 << 4 << 6); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 7 << 5 << 4 << 6); // Sort by Date, ascending m_model->setSortOrder(Qt::AscendingOrder); QCOMPARE(m_model->sortRole(), QByteArray("modificationtime")); QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); - QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "e" << "a" << "d" << "b"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "c-2" + << "c-3" + << "c-1" + << "e" + << "a" + << "d" + << "b"); QCOMPARE(itemsMovedSpy.count(), 1); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(4, 4)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 7 << 6 << 5 << 4); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 7 << 6 << 5 << 4); // Sort by Date, ascending, 'Sort Folders First' disabled m_model->setSortDirectoriesFirst(false); QCOMPARE(m_model->sortRole(), QByteArray("modificationtime")); QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); QVERIFY(!m_model->sortDirectoriesFirst()); - QCOMPARE(itemsInModel(), QStringList() << "e" << "a" << "c" << "c-1" << "c-2" << "c-3" << "d" << "b"); + QCOMPARE(itemsInModel(), + QStringList() << "e" + << "a" + << "c" + << "c-1" + << "c-2" + << "c-3" + << "d" + << "b"); QCOMPARE(itemsMovedSpy.count(), 1); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(0, 6)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 2 << 4 << 5 << 3 << 0 << 1); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 2 << 4 << 5 << 3 << 0 << 1); // Sort by Name, ascending, 'Sort Folders First' disabled m_model->setSortRole("text"); QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); QVERIFY(!m_model->sortDirectoriesFirst()); - QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c" << "c-1" << "c-2" << "c-3" << "d" << "e"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "b" + << "c" + << "c-1" + << "c-2" + << "c-3" + << "d" + << "e"); QCOMPARE(itemsMovedSpy.count(), 1); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(0, 8)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 7 << 0 << 2 << 3 << 4 << 5 << 6 << 1); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 7 << 0 << 2 << 3 << 4 << 5 << 6 << 1); // Sort by Size, ascending, 'Sort Folders First' disabled m_model->setSortRole("size"); QCOMPARE(m_model->sortRole(), QByteArray("size")); QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); QVERIFY(!m_model->sortDirectoriesFirst()); - QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "a" << "b" << "e" << "d"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "c-2" + << "c-3" + << "c-1" + << "a" + << "b" + << "e" + << "d"); QCOMPARE(itemsMovedSpy.count(), 1); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(0, 8)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 4 << 5 << 0 << 3 << 1 << 2 << 7 << 6); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 4 << 5 << 0 << 3 << 1 << 2 << 7 << 6); // In 'Sort by Size' mode, folders are always first -> changing 'Sort Folders First' does not resort the model m_model->setSortDirectoriesFirst(true); QCOMPARE(m_model->sortRole(), QByteArray("size")); QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); QVERIFY(m_model->sortDirectoriesFirst()); - QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "a" << "b" << "e" << "d"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "c-2" + << "c-3" + << "c-1" + << "a" + << "b" + << "e" + << "d"); QCOMPARE(itemsMovedSpy.count(), 0); // Sort by Size, descending, 'Sort Folders First' enabled @@ -968,16 +1069,34 @@ void KFileItemModelTest::testSorting() QCOMPARE(m_model->sortRole(), QByteArray("size")); QCOMPARE(m_model->sortOrder(), Qt::DescendingOrder); QVERIFY(m_model->sortDirectoriesFirst()); - QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "d" << "e" << "b" << "a"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "c-2" + << "c-3" + << "c-1" + << "d" + << "e" + << "b" + << "a"); QCOMPARE(itemsMovedSpy.count(), 1); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(4, 4)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 7 << 6 << 5 << 4); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 7 << 6 << 5 << 4); // 'Show Hidden Files' enabled m_model->setShowHiddenFiles(true); QVERIFY(m_model->showHiddenFiles()); QVERIFY(!m_model->sortHiddenLast()); - QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << ".g" << "d" << "e" << "b" << "a" << ".f"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "c-2" + << "c-3" + << "c-1" + << ".g" + << "d" + << "e" + << "b" + << "a" + << ".f"); QCOMPARE(itemsMovedSpy.count(), 0); QCOMPARE(itemsInsertedSpy.count(), 1); QCOMPARE(itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>(), KItemRangeList() << KItemRange(4, 1) << KItemRange(8, 1)); @@ -985,34 +1104,73 @@ void KFileItemModelTest::testSorting() // 'Sort Hidden Files Last' enabled m_model->setSortHiddenLast(true); QVERIFY(m_model->sortHiddenLast()); - QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "d" << "e" << "b" << "a" << ".g" << ".f"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "c-2" + << "c-3" + << "c-1" + << "d" + << "e" + << "b" + << "a" + << ".g" + << ".f"); QCOMPARE(itemsMovedSpy.count(), 1); QCOMPARE(itemsInsertedSpy.count(), 0); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(4, 5)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 8 << 4 << 5 << 6 << 7); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 8 << 4 << 5 << 6 << 7); // Sort by Name m_model->setSortRole("text"); - QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "e" << "d" << "b" << "a" << ".g" << ".f"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "c-2" + << "c-3" + << "c-1" + << "e" + << "d" + << "b" + << "a" + << ".g" + << ".f"); QCOMPARE(itemsMovedSpy.count(), 1); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(4, 2)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 5 << 4); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 5 << 4); // Sort ascending m_model->setSortOrder(Qt::AscendingOrder); - QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "a" << "b" << "d" << "e" << ".g" << ".f"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "c-2" + << "c-3" + << "c-1" + << "a" + << "b" + << "d" + << "e" + << ".g" + << ".f"); QCOMPARE(itemsMovedSpy.count(), 1); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(4, 4)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 7 << 6 << 5 << 4); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 7 << 6 << 5 << 4); // 'Sort Folders First' disabled m_model->setSortDirectoriesFirst(false); QVERIFY(!m_model->sortDirectoriesFirst()); - QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c" << "c-1" << "c-2" << "c-3" << "d" << "e" << ".f" << ".g"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "b" + << "c" + << "c-1" + << "c-2" + << "c-3" + << "d" + << "e" + << ".f" + << ".g"); QCOMPARE(itemsMovedSpy.count(), 1); QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(0, 10)); - QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 2 << 4 << 5 << 3 << 0 << 1 << 6 << 7 << 9 << 8); - + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int>>(), QList<int>() << 2 << 4 << 5 << 3 << 0 << 1 << 6 << 7 << 9 << 8); } void KFileItemModelTest::testIndexForKeyboardSearch() @@ -1129,7 +1287,9 @@ void KFileItemModelTest::testRefreshExpandedItem() QVERIFY(itemsChangedSpy.isValid()); QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFiles({"a/1", "a/2", "3", "4"}); @@ -1160,7 +1320,9 @@ void KFileItemModelTest::testAddItemToFilteredExpandedFolder() QSignalSpy fileItemsChangedSpy(m_model, &KFileItemModel::fileItemsChanged); QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFile("a/b/file"); @@ -1171,7 +1333,7 @@ void KFileItemModelTest::testAddItemToFilteredExpandedFolder() // Expand "a/". m_model->setExpanded(0, true); - QVERIFY(itemsInsertedSpy.wait()); + QVERIFY(itemsInsertedSpy.wait()); // Expand "a/b/". m_model->setExpanded(1, true); @@ -1190,7 +1352,10 @@ void KFileItemModelTest::testAddItemToFilteredExpandedFolder() // Entire parental chain should now be shown QCOMPARE(m_model->count(), 3); // 3 items: "a/", "a/b/", "a/b/newItem.txt" - QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "newItem.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "b" + << "newItem.txt"); // Items should be indented in hierarchy QCOMPARE(m_model->expandedParentsCount(0), 0); @@ -1206,9 +1371,11 @@ void KFileItemModelTest::testDeleteItemsWithExpandedFolderWithFilter() { QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); - + QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFile("a/b/file"); @@ -1219,7 +1386,7 @@ void KFileItemModelTest::testDeleteItemsWithExpandedFolderWithFilter() // Expand "a/". m_model->setExpanded(0, true); - QVERIFY(itemsInsertedSpy.wait()); + QVERIFY(itemsInsertedSpy.wait()); // Expand "a/b/". m_model->setExpanded(1, true); @@ -1263,7 +1430,10 @@ void KFileItemModelTest::testRefreshItemsWithFilter() // Set a filter that matches ".txt" extension m_model->setNameFilter("*.txt"); QCOMPARE(m_model->count(), 3); // Still all items are shown - QCOMPARE(itemsInModel(), QStringList() << "b.txt" << "c.txt" << "d.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "b.txt" + << "c.txt" + << "d.txt"); // Objects used to rename const KFileItem fileItemC_txt = m_model->fileItem(1); @@ -1293,22 +1463,28 @@ void KFileItemModelTest::testRefreshItemsWithFilter() QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 1)); // Re-sorting is done asynchronously: - QCOMPARE(itemsInModel(), QStringList() << "b.txt" << "a.txt"); // Files should still be in the incorrect order + QCOMPARE(itemsInModel(), + QStringList() << "b.txt" + << "a.txt"); // Files should still be in the incorrect order QVERIFY(itemsMovedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt"); // Files were re-sorted and should now be in the correct order + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.txt"); // Files were re-sorted and should now be in the correct order } - /** * Verifies that parental chains are hidden and shown as needed while their children get filtered/unfiltered due to renaming. * Also verifies that the "isExpanded" and "expandedParentsCount" values are kept for expanded folders that get refreshed. */ -void KFileItemModelTest::testRefreshExpandedFolderWithFilter() { +void KFileItemModelTest::testRefreshExpandedFolderWithFilter() +{ QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFile("a/b/someFolder/someFile"); @@ -1320,7 +1496,7 @@ void KFileItemModelTest::testRefreshExpandedFolderWithFilter() { // Expand "a/". m_model->setExpanded(0, true); - QVERIFY(itemsInsertedSpy.wait()); + QVERIFY(itemsInsertedSpy.wait()); // Expand "a/b/". m_model->setExpanded(1, true); @@ -1338,7 +1514,7 @@ void KFileItemModelTest::testRefreshExpandedFolderWithFilter() { // Objects used to rename const KFileItem fileItemA = m_model->fileItem(0); KFileItem fileItemARenamed = fileItemA; - fileItemARenamed.setUrl(QUrl("a_renamed")); + fileItemARenamed.setUrl(QUrl("a_renamed")); const KFileItem fileItemSomeFolder = m_model->fileItem(2); KFileItem fileItemRenamedFolder = fileItemSomeFolder; @@ -1348,7 +1524,10 @@ void KFileItemModelTest::testRefreshExpandedFolderWithFilter() { // This way we test if the algorithm is sane as to NOT hide "a_renamed" since it will have visible children m_model->slotRefreshItems({qMakePair(fileItemA, fileItemARenamed)}); QCOMPARE(m_model->count(), 3); // Entire parental chain must still be shown - QCOMPARE(itemsInModel(), QStringList() << "a_renamed" << "b" << "someFolder"); + QCOMPARE(itemsInModel(), + QStringList() << "a_renamed" + << "b" + << "someFolder"); // Rename "a_renamed" back to "a"; and "someFolder" to "renamedFolder" m_model->slotRefreshItems({qMakePair(fileItemARenamed, fileItemA), qMakePair(fileItemSomeFolder, fileItemRenamedFolder)}); @@ -1357,7 +1536,10 @@ void KFileItemModelTest::testRefreshExpandedFolderWithFilter() { // Rename "renamedFolder" back to "someFolder". Filter is passing again m_model->slotRefreshItems({qMakePair(fileItemRenamedFolder, fileItemSomeFolder)}); QCOMPARE(m_model->count(), 3); // Entire parental chain is shown again - QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "someFolder"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "b" + << "someFolder"); // slotRefreshItems() should preserve "isExpanded" and "expandedParentsCount" values explicitly in this case QCOMPARE(m_model->m_itemData.at(2)->values.value("isExpanded").toBool(), true); @@ -1382,21 +1564,41 @@ void KFileItemModelTest::testRemoveHiddenItems() m_model->setShowHiddenFiles(true); m_model->loadDirectory(m_testDir->url()); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << ".a" << ".b" << "c" << "d" <<".f" << ".g" << "h" << "i"); + QCOMPARE(itemsInModel(), + QStringList() << ".a" + << ".b" + << "c" + << "d" + << ".f" + << ".g" + << "h" + << "i"); QCOMPARE(itemsInsertedSpy.count(), 1); QCOMPARE(itemsRemovedSpy.count(), 0); KItemRangeList itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 8)); m_model->setShowHiddenFiles(false); - QCOMPARE(itemsInModel(), QStringList() << "c" << "d" << "h" << "i"); + QCOMPARE(itemsInModel(), + QStringList() << "c" + << "d" + << "h" + << "i"); QCOMPARE(itemsInsertedSpy.count(), 0); QCOMPARE(itemsRemovedSpy.count(), 1); itemRangeList = itemsRemovedSpy.takeFirst().at(0).value<KItemRangeList>(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 2) << KItemRange(4, 2)); m_model->setShowHiddenFiles(true); - QCOMPARE(itemsInModel(), QStringList() << ".a" << ".b" << "c" << "d" <<".f" << ".g" << "h" << "i"); + QCOMPARE(itemsInModel(), + QStringList() << ".a" + << ".b" + << "c" + << "d" + << ".f" + << ".g" + << "h" + << "i"); QCOMPARE(itemsInsertedSpy.count(), 1); QCOMPARE(itemsRemovedSpy.count(), 0); itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>(); @@ -1423,7 +1625,9 @@ void KFileItemModelTest::collapseParentOfHiddenItems() QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFiles({"a/1", "a/b/1", "a/b/c/1", "a/b/c/d/1"}); @@ -1480,7 +1684,9 @@ void KFileItemModelTest::removeParentOfHiddenItems() QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFiles({"a/1", "a/b/1", "a/b/c/1", "a/b/c/d/1"}); @@ -1514,7 +1720,10 @@ void KFileItemModelTest::removeParentOfHiddenItems() m_model->setNameFilter("c"); QCOMPARE(itemsRemovedSpy.count(), 1); // nothing was removed, itemsRemovedSpy count will remain the same: QCOMPARE(m_model->count(), 3); - QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "b" + << "c"); // Simulate the deletion of the directory "a/b/". m_model->slotItemsDeleted(KFileItemList() << m_model->fileItem(1)); @@ -1524,7 +1733,9 @@ void KFileItemModelTest::removeParentOfHiddenItems() // Remove the filter -> only the file "a/1" should appear. m_model->setNameFilter(QString()); QCOMPARE(m_model->count(), 2); - QCOMPARE(itemsInModel(), QStringList() << "a" << "1"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "1"); } /** @@ -1538,31 +1749,53 @@ void KFileItemModelTest::testGeneralParentChildRelationships() QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFiles({"parent1/realChild1/realGrandChild1", "parent2/realChild2/realGrandChild2"}); m_model->loadDirectory(m_testDir->url()); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "parent1" << "parent2"); + QCOMPARE(itemsInModel(), + QStringList() << "parent1" + << "parent2"); // Expand all folders. m_model->setExpanded(0, true); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "parent2"); + QCOMPARE(itemsInModel(), + QStringList() << "parent1" + << "realChild1" + << "parent2"); m_model->setExpanded(1, true); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "parent2"); + QCOMPARE(itemsInModel(), + QStringList() << "parent1" + << "realChild1" + << "realGrandChild1" + << "parent2"); m_model->setExpanded(3, true); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "parent2" << "realChild2"); + QCOMPARE(itemsInModel(), + QStringList() << "parent1" + << "realChild1" + << "realGrandChild1" + << "parent2" + << "realChild2"); m_model->setExpanded(4, true); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "parent2" << "realChild2" << "realGrandChild2"); + QCOMPARE(itemsInModel(), + QStringList() << "parent1" + << "realChild1" + << "realGrandChild1" + << "parent2" + << "realChild2" + << "realGrandChild2"); // Add some more children and grand-children. const QUrl parent1 = m_model->fileItem(0).url(); @@ -1572,19 +1805,53 @@ void KFileItemModelTest::testGeneralParentChildRelationships() m_model->slotItemsAdded(parent1, KFileItemList() << KFileItem(QUrl("child1"), QString(), KFileItem::Unknown)); m_model->slotCompleted(); - QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2"); + QCOMPARE(itemsInModel(), + QStringList() << "parent1" + << "realChild1" + << "realGrandChild1" + << "child1" + << "parent2" + << "realChild2" + << "realGrandChild2"); m_model->slotItemsAdded(parent2, KFileItemList() << KFileItem(QUrl("child2"), QString(), KFileItem::Unknown)); m_model->slotCompleted(); - QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2" << "child2"); + QCOMPARE(itemsInModel(), + QStringList() << "parent1" + << "realChild1" + << "realGrandChild1" + << "child1" + << "parent2" + << "realChild2" + << "realGrandChild2" + << "child2"); m_model->slotItemsAdded(realChild1, KFileItemList() << KFileItem(QUrl("grandChild1"), QString(), KFileItem::Unknown)); m_model->slotCompleted(); - QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2" << "child2"); + QCOMPARE(itemsInModel(), + QStringList() << "parent1" + << "realChild1" + << "grandChild1" + << "realGrandChild1" + << "child1" + << "parent2" + << "realChild2" + << "realGrandChild2" + << "child2"); m_model->slotItemsAdded(realChild2, KFileItemList() << KFileItem(QUrl("grandChild2"), QString(), KFileItem::Unknown)); m_model->slotCompleted(); - QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "grandChild2" << "realGrandChild2" << "child2"); + QCOMPARE(itemsInModel(), + QStringList() << "parent1" + << "realChild1" + << "grandChild1" + << "realGrandChild1" + << "child1" + << "parent2" + << "realChild2" + << "grandChild2" + << "realGrandChild2" + << "child2"); // Set a name filter that matches nothing -> nothing will remain. m_model->setNameFilter("xyz"); @@ -1596,12 +1863,19 @@ void KFileItemModelTest::testGeneralParentChildRelationships() // Set a name filter that matches only "realChild". Their prarents should still show. m_model->setNameFilter("realChild"); - QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "parent2" << "realChild2"); - QCOMPARE(itemsRemovedSpy.count(), 0); // nothing was removed, itemsRemovedSpy will not be called this time + QCOMPARE(itemsInModel(), + QStringList() << "parent1" + << "realChild1" + << "parent2" + << "realChild2"); + QCOMPARE(itemsRemovedSpy.count(), 0); // nothing was removed, itemsRemovedSpy will not be called this time // Collapse "parent1". m_model->setExpanded(0, false); - QCOMPARE(itemsInModel(), QStringList() << "parent1" << "parent2" << "realChild2"); + QCOMPARE(itemsInModel(), + QStringList() << "parent1" + << "parent2" + << "realChild2"); QCOMPARE(itemsRemovedSpy.count(), 1); arguments = itemsRemovedSpy.takeFirst(); itemRangeList = arguments.at(0).value<KItemRangeList>(); @@ -1633,9 +1907,13 @@ void KFileItemModelTest::testNameRoleGroups() m_model->setGroupedSorting(true); m_model->loadDirectory(m_testDir->url()); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "b.txt" << "c.txt" << "d.txt" << "e.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "b.txt" + << "c.txt" + << "d.txt" + << "e.txt"); - QList<QPair<int, QVariant> > expectedGroups; + QList<QPair<int, QVariant>> expectedGroups; expectedGroups << QPair<int, QVariant>(0, QLatin1String("B")); expectedGroups << QPair<int, QVariant>(1, QLatin1String("C")); expectedGroups << QPair<int, QVariant>(2, QLatin1String("D")); @@ -1647,7 +1925,11 @@ void KFileItemModelTest::testNameRoleGroups() data.insert("text", "a.txt"); m_model->setData(2, data); QVERIFY(itemsMovedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt" << "e.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.txt" + << "c.txt" + << "e.txt"); expectedGroups.clear(); expectedGroups << QPair<int, QVariant>(0, QLatin1String("A")); @@ -1660,7 +1942,11 @@ void KFileItemModelTest::testNameRoleGroups() data.insert("text", "d.txt"); m_model->setData(2, data); QVERIFY(groupsChangedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "d.txt" << "e.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.txt" + << "d.txt" + << "e.txt"); expectedGroups.clear(); expectedGroups << QPair<int, QVariant>(0, QLatin1String("A")); @@ -1678,7 +1964,11 @@ void KFileItemModelTest::testNameRoleGroups() m_model->slotRefreshItems({qMakePair(fileItemD, fileItemC)}); QVERIFY(groupsChangedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt" << "e.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.txt" + << "c.txt" + << "e.txt"); expectedGroups.clear(); expectedGroups << QPair<int, QVariant>(0, QLatin1String("A")); @@ -1693,7 +1983,9 @@ void KFileItemModelTest::testNameRoleGroupsWithExpandedItems() QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFiles({"a/b.txt", "a/c.txt", "d/e.txt", "d/f.txt"}); @@ -1701,9 +1993,11 @@ void KFileItemModelTest::testNameRoleGroupsWithExpandedItems() m_model->setGroupedSorting(true); m_model->loadDirectory(m_testDir->url()); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a" << "d"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "d"); - QList<QPair<int, QVariant> > expectedGroups; + QList<QPair<int, QVariant>> expectedGroups; expectedGroups << QPair<int, QVariant>(0, QLatin1String("A")); expectedGroups << QPair<int, QVariant>(1, QLatin1String("D")); QCOMPARE(m_model->groups(), expectedGroups); @@ -1716,13 +2010,23 @@ void KFileItemModelTest::testNameRoleGroupsWithExpandedItems() m_model->setExpanded(0, true); QVERIFY(m_model->isExpanded(0)); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a" << "b.txt" << "c.txt" << "d"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "b.txt" + << "c.txt" + << "d"); QCOMPARE(m_model->groups(), expectedGroups); m_model->setExpanded(3, true); QVERIFY(m_model->isExpanded(3)); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a" << "b.txt" << "c.txt" << "d" << "e.txt" << "f.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "b.txt" + << "c.txt" + << "d" + << "e.txt" + << "f.txt"); QCOMPARE(m_model->groups(), expectedGroups); } @@ -1731,7 +2035,9 @@ void KFileItemModelTest::testInconsistentModel() QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFiles({"a/b/c1.txt", "a/b/c2.txt"}); @@ -1744,12 +2050,18 @@ void KFileItemModelTest::testInconsistentModel() m_model->setExpanded(0, true); QVERIFY(m_model->isExpanded(0)); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a" << "b"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "b"); m_model->setExpanded(1, true); QVERIFY(m_model->isExpanded(1)); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c1.txt" << "c2.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "b" + << "c1.txt" + << "c2.txt"); // Add the files "c1.txt" and "c2.txt" to the model also as top-level items. // Such a thing can in principle happen when performing a search, and there @@ -1767,19 +2079,29 @@ void KFileItemModelTest::testInconsistentModel() items << newItem << m_model->fileItem(2) << m_model->fileItem(3); m_model->slotItemsAdded(m_model->directory(), items); m_model->slotCompleted(); - QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c1.txt" << "c2.txt" << "a2" << "c1.txt" << "c2.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "b" + << "c1.txt" + << "c2.txt" + << "a2" + << "c1.txt" + << "c2.txt"); m_model->setExpanded(0, false); // Test that the right items have been removed, see // https://bugs.kde.org/show_bug.cgi?id=324371 - QCOMPARE(itemsInModel(), QStringList() << "a" << "a2" << "c1.txt" << "c2.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "a2" + << "c1.txt" + << "c2.txt"); // Test that resorting does not cause a crash, see // https://bugs.kde.org/show_bug.cgi?id=325359 // The crash is not 100% reproducible, but Valgrind will report an invalid memory access. m_model->resortAllItems(); - } void KFileItemModelTest::testChangeRolesForFilteredItems() @@ -1794,7 +2116,10 @@ void KFileItemModelTest::testChangeRolesForFilteredItems() m_model->loadDirectory(m_testDir->url()); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "aa.txt" << "aaa.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "aa.txt" + << "aaa.txt"); for (int index = 0; index < m_model->count(); ++index) { // All items should have the "text" and "owner" roles, but not "group". @@ -1813,7 +2138,9 @@ void KFileItemModelTest::testChangeRolesForFilteredItems() // Modify the filter, such that "aa.txt" reappears, and verify that all items have the expected roles. m_model->setNameFilter("aa"); - QCOMPARE(itemsInModel(), QStringList() << "aa.txt" << "aaa.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "aa.txt" + << "aaa.txt"); for (int index = 0; index < m_model->count(); ++index) { // All items should have the "text", "owner", and "group" roles. @@ -1828,7 +2155,10 @@ void KFileItemModelTest::testChangeRolesForFilteredItems() // Clear the filter, and verify that all items have the expected roles m_model->setNameFilter(QString()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "aa.txt" << "aaa.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "aa.txt" + << "aaa.txt"); for (int index = 0; index < m_model->count(); ++index) { // All items should have the "text" and "group" roles, but now "owner". @@ -1854,7 +2184,7 @@ void KFileItemModelTest::testChangeSortRoleWhileFiltering() 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_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); @@ -1866,7 +2196,10 @@ void KFileItemModelTest::testChangeSortRoleWhileFiltering() m_model->slotItemsAdded(m_testDir->url(), items); m_model->slotCompleted(); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.txt" + << "c.txt"); // Add a filter. m_model->setNameFilter("a"); @@ -1877,7 +2210,10 @@ void KFileItemModelTest::testChangeSortRoleWhileFiltering() // Clear the filter, and verify that the items are sorted correctly. m_model->setNameFilter(QString()); - QCOMPARE(itemsInModel(), QStringList() << "c.txt" << "a.txt" << "b.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "c.txt" + << "a.txt" + << "b.txt"); } void KFileItemModelTest::testRefreshFilteredItems() @@ -1888,13 +2224,19 @@ void KFileItemModelTest::testRefreshFilteredItems() m_model->loadDirectory(m_testDir->url()); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.jpg" << "d.jpg"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.txt" + << "c.jpg" + << "d.jpg"); const KFileItem fileItemC = m_model->fileItem(2); // Show only the .txt files. m_model->setNameFilter(".txt"); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.txt"); // Rename one of the .jpg files. KFileItem fileItemE = fileItemC; @@ -1906,7 +2248,11 @@ void KFileItemModelTest::testRefreshFilteredItems() // Show all files again, and verify that the model has updated the file name. m_model->setNameFilter(QString()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "d.jpg" << "e.jpg"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.txt" + << "d.jpg" + << "e.jpg"); } void KFileItemModelTest::testCreateMimeData() @@ -1914,7 +2260,9 @@ void KFileItemModelTest::testCreateMimeData() QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFile("a/1"); @@ -1926,13 +2274,15 @@ void KFileItemModelTest::testCreateMimeData() // Expand "a/". m_model->setExpanded(0, true); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a" << "1"); + QCOMPARE(itemsInModel(), + QStringList() << "a" + << "1"); // Verify that creating the MIME data for a child of an expanded folder does // not cause a crash, see https://bugs.kde.org/show_bug.cgi?id=329119 KItemSet selection; selection.insert(1); - QMimeData* mimeData = m_model->createMimeData(selection); + QMimeData *mimeData = m_model->createMimeData(selection); delete mimeData; } @@ -1941,7 +2291,9 @@ void KFileItemModelTest::testCollapseFolderWhileLoading() QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); QSet<QByteArray> modelRoles = m_model->roles(); - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFile("a2/b/c1.txt"); @@ -1954,13 +2306,18 @@ void KFileItemModelTest::testCollapseFolderWhileLoading() m_model->setExpanded(0, true); QVERIFY(m_model->isExpanded(0)); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a2" << "b"); + QCOMPARE(itemsInModel(), + QStringList() << "a2" + << "b"); // Expand "a2/b/". m_model->setExpanded(1, true); QVERIFY(m_model->isExpanded(1)); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a2" << "b" << "c1.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a2" + << "b" + << "c1.txt"); // Simulate that a new item "c2.txt" appears, but that the dir lister's completed() // signal is not emitted yet. @@ -1973,7 +2330,10 @@ void KFileItemModelTest::testCollapseFolderWhileLoading() const QUrl urlB = m_model->fileItem(1).url(); m_model->slotItemsAdded(urlB, KFileItemList() << fileItemC2); - QCOMPARE(itemsInModel(), QStringList() << "a2" << "b" << "c1.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a2" + << "b" + << "c1.txt"); // Collapse "a2/". This should also remove all its (indirect) children from // the model and from the model's m_pendingItemsToInsert member. @@ -1992,7 +2352,9 @@ void KFileItemModelTest::testCollapseFolderWhileLoading() m_model->setExpanded(0, true); QVERIFY(m_model->isExpanded(0)); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a2" << "b"); + QCOMPARE(itemsInModel(), + QStringList() << "a2" + << "b"); // Now simulate that a new folder "a1/" is appears, but that the dir lister's // completed() signal is not emitted yet. @@ -2003,13 +2365,17 @@ void KFileItemModelTest::testCollapseFolderWhileLoading() fileItemA1.setUrl(urlA1); m_model->slotItemsAdded(m_model->directory(), KFileItemList() << fileItemA1); - QCOMPARE(itemsInModel(), QStringList() << "a2" << "b"); + QCOMPARE(itemsInModel(), + QStringList() << "a2" + << "b"); // Collapse "a2/". Note that this will cause "a1/" to be added to the model, // i.e., the index of "a2/" will change from 0 to 1. Check that this does not // confuse the code which collapses the folder. m_model->setExpanded(0, false); - QCOMPARE(itemsInModel(), QStringList() << "a1" << "a2"); + QCOMPARE(itemsInModel(), + QStringList() << "a1" + << "a2"); QVERIFY(!m_model->isExpanded(0)); QVERIFY(!m_model->isExpanded(1)); } @@ -2022,7 +2388,11 @@ void KFileItemModelTest::testDeleteFileMoreThanOnce() m_model->loadDirectory(m_testDir->url()); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt" << "d.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "b.txt" + << "c.txt" + << "d.txt"); const KFileItem fileItemB = m_model->fileItem(1); @@ -2032,7 +2402,10 @@ void KFileItemModelTest::testDeleteFileMoreThanOnce() m_model->slotItemsDeleted(list); QVERIFY(m_model->isConsistent()); - QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "c.txt" << "d.txt"); + QCOMPARE(itemsInModel(), + QStringList() << "a.txt" + << "c.txt" + << "d.txt"); } void KFileItemModelTest::testInsertAfterExpand() @@ -2049,7 +2422,9 @@ void KFileItemModelTest::testInsertAfterExpand() // Test expanding subfolders in a folder with the items "a/", "a/a/" QSet<QByteArray> originalModelRoles = m_model->roles(); QSet<QByteArray> modelRoles = originalModelRoles; - modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; + modelRoles << "isExpanded" + << "isExpandable" + << "expandedParentsCount"; m_model->setRoles(modelRoles); m_testDir->createFile("a/b/1"); @@ -2068,7 +2443,6 @@ void KFileItemModelTest::testInsertAfterExpand() KItemRangeList itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 1)); // 1 new item "a/" with index 0 QCOMPARE(m_model->expandedParentsCount(0), 0); - } itemsInsertedSpy.clear(); @@ -2084,15 +2458,13 @@ void KFileItemModelTest::testInsertAfterExpand() KItemRangeList itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 1)); // 1 new item "a/b" with index 1 QCOMPARE(m_model->expandedParentsCount(1), 1); - } itemsInsertedSpy.clear(); // Expand "a/b" -> "a/b/1" becomes visible m_model->setExpanded(1, true); QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(m_model->expandedDirectories(), QSet({QUrl::fromLocalFile(m_testDir->path() + "/a"), - QUrl::fromLocalFile(m_testDir->path() + "/a/b")})); + QCOMPARE(m_model->expandedDirectories(), QSet({QUrl::fromLocalFile(m_testDir->path() + "/a"), QUrl::fromLocalFile(m_testDir->path() + "/a/b")})); QCOMPARE(itemsInsertedSpy.count(), 1); { @@ -2107,22 +2479,22 @@ void KFileItemModelTest::testInsertAfterExpand() // Insert additional files into "a/b/" m_testDir->createFile("a/b/2"); - #if KIO_VERSION < QT_VERSION_CHECK(5, 92, 0) - QEXPECT_FAIL("", "Requires new API from frameworks", Abort); - #endif +#if KIO_VERSION < QT_VERSION_CHECK(5, 92, 0) + QEXPECT_FAIL("", "Requires new API from frameworks", Abort); +#endif QVERIFY(!itemsInsertedSpy.wait(5000)); QCOMPARE(itemsInModel(), {"a"}); - m_model->setExpanded(0, true);; + m_model->setExpanded(0, true); + ; QTRY_COMPARE(itemsInModel(), QStringList({"a", "b", "1", "2"})); QCOMPARE(m_model->expandedParentsCount(0), 0); // a QCOMPARE(m_model->expandedParentsCount(1), 1); // a/b QCOMPARE(m_model->expandedParentsCount(2), 2); // a/b/1 - QCOMPARE(m_model->expandedParentsCount(3), 2) ;// a/b/2 - + QCOMPARE(m_model->expandedParentsCount(3), 2); // a/b/2 } void KFileItemModelTest::testCurrentDirRemoved() diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp index 6fb1b72f9..a7842475a 100644 --- a/src/tests/kitemlistcontrollertest.cpp +++ b/src/tests/kitemlistcontrollertest.cpp @@ -4,19 +4,19 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#include "kitemviews/kitemlistcontainer.h" +#include "kitemviews/kitemlistcontroller.h" #include "kitemviews/kfileitemlistview.h" #include "kitemviews/kfileitemmodel.h" -#include "kitemviews/kitemlistcontroller.h" +#include "kitemviews/kitemlistcontainer.h" #include "kitemviews/kitemlistselectionmanager.h" #include "kitemviews/private/kitemlistviewlayouter.h" #include "testdir.h" -#include <QTest> #include <QGraphicsSceneMouseEvent> -#include <QSignalSpy> #include <QProxyStyle> +#include <QSignalSpy> #include <QStandardPaths> +#include <QTest> /** * \class KItemListControllerTestStyle is a proxy style for testing the @@ -27,9 +27,9 @@ class KItemListControllerTestStyle : public QProxyStyle { Q_OBJECT public: - KItemListControllerTestStyle(QStyle* style) : - QProxyStyle(style), - m_activateItemOnSingleClick((bool)style->styleHint(SH_ItemView_ActivateItemOnSingleClick)) + KItemListControllerTestStyle(QStyle *style) + : QProxyStyle(style) + , m_activateItemOnSingleClick((bool)style->styleHint(SH_ItemView_ActivateItemOnSingleClick)) { } @@ -43,10 +43,7 @@ public: return m_activateItemOnSingleClick; } - int styleHint(StyleHint hint, - const QStyleOption* option = nullptr, - const QWidget* widget = nullptr, - QStyleHintReturn* returnData = nullptr) const override + int styleHint(StyleHint hint, const QStyleOption *option = nullptr, const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const override { switch (hint) { case QStyle::SH_ItemView_ActivateItemOnSingleClick: @@ -88,13 +85,13 @@ private: void adjustGeometryForColumnCount(int count); private: - KFileItemListView* m_view; - KItemListController* m_controller; - KItemListSelectionManager* m_selectionManager; - KFileItemModel* m_model; - TestDir* m_testDir; - KItemListContainer* m_container; - KItemListControllerTestStyle* m_testStyle; + KFileItemListView *m_view; + KItemListController *m_controller; + KItemListSelectionManager *m_selectionManager; + KFileItemModel *m_model; + TestDir *m_testDir; + KItemListContainer *m_container; + KItemListControllerTestStyle *m_testStyle; }; /** @@ -119,12 +116,26 @@ void KItemListControllerTest::initTestCase() m_view->setStyle(m_testStyle); QStringList files; - files - << "a1" << "a2" << "a3" - << "b1" - << "c1" << "c2" << "c3" << "c4" << "c5" - << "d1" << "d2" << "d3" << "d4" - << "e" << "e 2" << "e 3" << "e 4" << "e 5" << "e 6" << "e 7"; + files << "a1" + << "a2" + << "a3" + << "b1" + << "c1" + << "c2" + << "c3" + << "c4" + << "c5" + << "d1" + << "d2" + << "d3" + << "d4" + << "e" + << "e 2" + << "e 3" + << "e 4" + << "e 5" + << "e 6" + << "e 7"; m_testDir->createFiles(files); m_model->loadDirectory(m_testDir->url()); @@ -167,11 +178,11 @@ void KItemListControllerTest::cleanup() * including the key and the keyboard modifiers. */ struct KeyPress { - - KeyPress(Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier) : - m_key(key), - m_modifier(modifier) - {} + KeyPress(Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier) + : m_key(key) + , m_modifier(modifier) + { + } Qt::Key m_key; Qt::KeyboardModifiers m_modifier; @@ -185,12 +196,12 @@ struct KeyPress { * key press. */ struct ViewState { - - ViewState(int current, const KItemSet &selection, bool activated = false) : - m_current(current), - m_selection(selection), - m_activated(activated) - {} + ViewState(int current, const KItemSet &selection, bool activated = false) + : m_current(current) + , m_selection(selection) + , m_activated(activated) + { + } int m_current; KItemSet m_selection; @@ -216,7 +227,7 @@ void KItemListControllerTest::testKeyboardNavigation_data() QTest::addColumn<int>("columnCount"); QTest::addColumn<KItemListController::SelectionBehavior>("selectionBehavior"); QTest::addColumn<bool>("groupingEnabled"); - QTest::addColumn<QList<QPair<KeyPress, ViewState> > >("testList"); + QTest::addColumn<QList<QPair<KeyPress, ViewState>>>("testList"); QList<KFileItemListView::ItemLayout> layoutList; QHash<KFileItemListView::ItemLayout, QString> layoutNames; @@ -243,7 +254,7 @@ void KItemListControllerTest::testKeyboardNavigation_data() groupingEnabledList.append(true); groupingEnabledNames[true] = "grouping enabled"; - for (const KFileItemListView::ItemLayout& layout : layoutList) { + for (const KFileItemListView::ItemLayout &layout : layoutList) { // The following settings depend on the layout. // Note that 'columns' are actually 'rows' in // Compact layout. @@ -282,61 +293,59 @@ void KItemListControllerTest::testKeyboardNavigation_data() } for (int columnCount : qAsConst(columnCountList)) { - for (const KItemListController::SelectionBehavior& selectionBehavior : qAsConst(selectionBehaviorList)) { + for (const KItemListController::SelectionBehavior &selectionBehavior : qAsConst(selectionBehaviorList)) { for (bool groupingEnabled : qAsConst(groupingEnabledList)) { - QList<QPair<KeyPress, ViewState> > testList; + QList<QPair<KeyPress, ViewState>> testList; // First, key presses which should have the same effect // for any layout and any number of columns. - testList - << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) - << qMakePair(KeyPress(Qt::Key_Return), ViewState(1, KItemSet() << 1, true)) - << qMakePair(KeyPress(Qt::Key_Enter), ViewState(1, KItemSet() << 1, true)) - << qMakePair(KeyPress(nextItemKey), ViewState(2, KItemSet() << 2)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) - << qMakePair(KeyPress(Qt::Key_Return), ViewState(3, KItemSet() << 2 << 3, true)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(2, KItemSet() << 2)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 2 << 3)) - << qMakePair(KeyPress(Qt::Key_Return), ViewState(4, KItemSet() << 2 << 3, true)) - << qMakePair(KeyPress(previousItemKey), ViewState(3, KItemSet() << 3)) - << qMakePair(KeyPress(Qt::Key_Home, Qt::ShiftModifier), ViewState(0, KItemSet() << 0 << 1 << 2 << 3)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3)) - << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 2 << 3)) - << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3)) - << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 19)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(18, KItemSet() << 18 << 19)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)) - << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet())) - << qMakePair(KeyPress(Qt::Key_Enter), ViewState(0, KItemSet(), true)) - << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet() << 0)) - << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet())) - << qMakePair(KeyPress(Qt::Key_Space), ViewState(0, KItemSet())) // This used to select, but we are now using it to trigger either - // selection mode or "QuickLook". Ctrl+Space still works for selecting as expected. - << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) - << qMakePair(KeyPress(Qt::Key_Space), ViewState(14, KItemSet() << 14)) - << qMakePair(KeyPress(Qt::Key_3), ViewState(15, KItemSet() << 15)) - << qMakePair(KeyPress(Qt::Key_Escape), ViewState(15, KItemSet())) - << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) - << qMakePair(KeyPress(Qt::Key_E), ViewState(14, KItemSet() << 14)) - << qMakePair(KeyPress(Qt::Key_E), ViewState(15, KItemSet() << 15)) - << qMakePair(KeyPress(Qt::Key_Escape), ViewState(15, KItemSet())) - << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)) - << qMakePair(KeyPress(Qt::Key_Escape), ViewState(0, KItemSet())); + testList << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(Qt::Key_Return), ViewState(1, KItemSet() << 1, true)) + << qMakePair(KeyPress(Qt::Key_Enter), ViewState(1, KItemSet() << 1, true)) + << qMakePair(KeyPress(nextItemKey), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Return), ViewState(3, KItemSet() << 2 << 3, true)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Return), ViewState(4, KItemSet() << 2 << 3, true)) + << qMakePair(KeyPress(previousItemKey), ViewState(3, KItemSet() << 3)) + << qMakePair(KeyPress(Qt::Key_Home, Qt::ShiftModifier), ViewState(0, KItemSet() << 0 << 1 << 2 << 3)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, KItemSet() << 0 << 1 << 2 << 3)) + << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(18, KItemSet() << 18 << 19)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet())) + << qMakePair(KeyPress(Qt::Key_Enter), ViewState(0, KItemSet(), true)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet() << 0)) + << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, KItemSet())) + << qMakePair(KeyPress(Qt::Key_Space), ViewState(0, KItemSet())) // This used to select, but we are now using it to trigger either + // selection mode or "QuickLook". Ctrl+Space still works for selecting as expected. + << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) + << qMakePair(KeyPress(Qt::Key_Space), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(Qt::Key_3), ViewState(15, KItemSet() << 15)) + << qMakePair(KeyPress(Qt::Key_Escape), ViewState(15, KItemSet())) + << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) + << qMakePair(KeyPress(Qt::Key_E), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(Qt::Key_E), ViewState(15, KItemSet() << 15)) + << qMakePair(KeyPress(Qt::Key_Escape), ViewState(15, KItemSet())) + << qMakePair(KeyPress(Qt::Key_E), ViewState(13, KItemSet() << 13)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)) + << qMakePair(KeyPress(Qt::Key_Escape), ViewState(0, KItemSet())); // Next, we test combinations of key presses which only work for a // particular number of columns and either enabled or disabled grouping. // One column. if (columnCount == 1) { - testList - << qMakePair(KeyPress(nextRowKey), ViewState(1, KItemSet() << 1)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(2, KItemSet() << 1 << 2)) - << qMakePair(KeyPress(nextRowKey, Qt::ControlModifier), ViewState(3, KItemSet() << 1 << 2)) - << qMakePair(KeyPress(previousRowKey), ViewState(2, KItemSet() << 2)) - << qMakePair(KeyPress(previousItemKey), ViewState(1, KItemSet() << 1)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + testList << qMakePair(KeyPress(nextRowKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(2, KItemSet() << 1 << 2)) + << qMakePair(KeyPress(nextRowKey, Qt::ControlModifier), ViewState(3, KItemSet() << 1 << 2)) + << qMakePair(KeyPress(previousRowKey), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(previousItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); } // Multiple columns: we test both 3 and 5 columns with grouping @@ -354,27 +363,26 @@ void KItemListControllerTest::testKeyboardNavigation_data() // d4 e1 e2 | 12 13 14 // e3 e4 e5 | 15 16 17 // e6 e7 | 18 19 - testList - << qMakePair(KeyPress(nextRowKey), ViewState(3, KItemSet() << 3)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 3)) - << qMakePair(KeyPress(nextRowKey), ViewState(7, KItemSet() << 7)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 7 << 8)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(9, KItemSet() << 7 << 8 << 9)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 7 << 8)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 6 << 7)) - << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(5, KItemSet() << 5 << 6 << 7)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 6 << 7)) - << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7)) - << qMakePair(KeyPress(nextRowKey), ViewState(10, KItemSet() << 10)) - << qMakePair(KeyPress(nextItemKey), ViewState(11, KItemSet() << 11)) - << qMakePair(KeyPress(nextRowKey), ViewState(14, KItemSet() << 14)) - << qMakePair(KeyPress(nextRowKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) - << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 19)) - << qMakePair(KeyPress(previousRowKey), ViewState(16, KItemSet() << 16)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + testList << qMakePair(KeyPress(nextRowKey), ViewState(3, KItemSet() << 3)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, KItemSet() << 3)) + << qMakePair(KeyPress(nextRowKey), ViewState(7, KItemSet() << 7)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 7 << 8)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(9, KItemSet() << 7 << 8 << 9)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(8, KItemSet() << 7 << 8)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 6 << 7)) + << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(5, KItemSet() << 5 << 6 << 7)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 6 << 7)) + << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7)) + << qMakePair(KeyPress(nextRowKey), ViewState(10, KItemSet() << 10)) + << qMakePair(KeyPress(nextItemKey), ViewState(11, KItemSet() << 11)) + << qMakePair(KeyPress(nextRowKey), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(nextRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(Qt::Key_End), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(16, KItemSet() << 16)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); } if (columnCount == 5 && !groupingEnabled) { @@ -384,18 +392,17 @@ void KItemListControllerTest::testKeyboardNavigation_data() // c2 c3 c4 c5 d1 | 5 6 7 8 9 // d2 d3 d4 e1 e2 | 10 11 12 13 14 // e3 e4 e5 e6 e7 | 15 16 17 18 19 - testList - << qMakePair(KeyPress(nextRowKey), ViewState(5, KItemSet() << 5)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(6, KItemSet() << 5)) - << qMakePair(KeyPress(nextRowKey), ViewState(11, KItemSet() << 11)) - << qMakePair(KeyPress(nextItemKey), ViewState(12, KItemSet() << 12)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(17, KItemSet() << 12 << 13 << 14 << 15 << 16 << 17)) - << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(12, KItemSet() << 12)) - << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7 << 8 << 9 << 10 << 11 << 12)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(12, KItemSet() << 12)) - << qMakePair(KeyPress(Qt::Key_End, Qt::ControlModifier), ViewState(19, KItemSet() << 12)) - << qMakePair(KeyPress(previousRowKey), ViewState(14, KItemSet() << 14)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + testList << qMakePair(KeyPress(nextRowKey), ViewState(5, KItemSet() << 5)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(6, KItemSet() << 5)) + << qMakePair(KeyPress(nextRowKey), ViewState(11, KItemSet() << 11)) + << qMakePair(KeyPress(nextItemKey), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(17, KItemSet() << 12 << 13 << 14 << 15 << 16 << 17)) + << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(7, KItemSet() << 7 << 8 << 9 << 10 << 11 << 12)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(Qt::Key_End, Qt::ControlModifier), ViewState(19, KItemSet() << 12)) + << qMakePair(KeyPress(previousRowKey), ViewState(14, KItemSet() << 14)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); } if (columnCount == 3 && groupingEnabled) { @@ -410,20 +417,19 @@ void KItemListControllerTest::testKeyboardNavigation_data() // e1 e2 e3 | 13 14 15 // e4 e5 e6 | 16 17 18 // e7 | 19 - testList - << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) - << qMakePair(KeyPress(nextItemKey), ViewState(2, KItemSet() << 2)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 2 << 3 << 4 << 5 << 6)) - << qMakePair(KeyPress(nextRowKey), ViewState(8, KItemSet() << 8)) - << qMakePair(KeyPress(nextRowKey), ViewState(11, KItemSet() << 11)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(12, KItemSet() << 11)) - << qMakePair(KeyPress(nextRowKey), ViewState(13, KItemSet() << 13)) - << qMakePair(KeyPress(nextRowKey), ViewState(16, KItemSet() << 16)) - << qMakePair(KeyPress(nextItemKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) - << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + testList << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(nextItemKey), ViewState(2, KItemSet() << 2)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 2 << 3)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(6, KItemSet() << 2 << 3 << 4 << 5 << 6)) + << qMakePair(KeyPress(nextRowKey), ViewState(8, KItemSet() << 8)) + << qMakePair(KeyPress(nextRowKey), ViewState(11, KItemSet() << 11)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(12, KItemSet() << 11)) + << qMakePair(KeyPress(nextRowKey), ViewState(13, KItemSet() << 13)) + << qMakePair(KeyPress(nextRowKey), ViewState(16, KItemSet() << 16)) + << qMakePair(KeyPress(nextItemKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); } if (columnCount == 5 && groupingEnabled) { @@ -435,37 +441,27 @@ void KItemListControllerTest::testKeyboardNavigation_data() // d1 d2 d3 d4 | 9 10 11 12 // e1 e2 e3 e4 e5 | 13 14 15 16 17 // e6 e7 | 18 19 - testList - << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 1 << 2 << 3)) - << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(5, KItemSet() << 1 << 2 << 3 << 4 << 5)) - << qMakePair(KeyPress(nextItemKey), ViewState(6, KItemSet() << 6)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(7, KItemSet() << 6)) - << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(8, KItemSet() << 6)) - << qMakePair(KeyPress(nextRowKey), ViewState(12, KItemSet() << 12)) - << qMakePair(KeyPress(nextRowKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) - << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) - << qMakePair(KeyPress(Qt::Key_End, Qt::ShiftModifier), ViewState(19, KItemSet() << 17 << 18 << 19)) - << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(14, KItemSet() << 14 << 15 << 16 << 17)) - << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); + testList << qMakePair(KeyPress(nextItemKey), ViewState(1, KItemSet() << 1)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, KItemSet() << 1 << 2 << 3)) + << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(5, KItemSet() << 1 << 2 << 3 << 4 << 5)) + << qMakePair(KeyPress(nextItemKey), ViewState(6, KItemSet() << 6)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(7, KItemSet() << 6)) + << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(8, KItemSet() << 6)) + << qMakePair(KeyPress(nextRowKey), ViewState(12, KItemSet() << 12)) + << qMakePair(KeyPress(nextRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(nextRowKey), ViewState(19, KItemSet() << 19)) + << qMakePair(KeyPress(previousRowKey), ViewState(17, KItemSet() << 17)) + << qMakePair(KeyPress(Qt::Key_End, Qt::ShiftModifier), ViewState(19, KItemSet() << 17 << 18 << 19)) + << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(14, KItemSet() << 14 << 15 << 16 << 17)) + << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); } - const QString testName = - layoutNames[layout] + ", " + - QString("%1 columns, ").arg(columnCount) + - selectionBehaviorNames[selectionBehavior] + ", " + - groupingEnabledNames[groupingEnabled]; + const QString testName = layoutNames[layout] + ", " + QString("%1 columns, ").arg(columnCount) + selectionBehaviorNames[selectionBehavior] + + ", " + groupingEnabledNames[groupingEnabled]; const QByteArray testNameAscii = testName.toLatin1(); - QTest::newRow(testNameAscii.data()) - << layout - << scrollOrientation - << columnCount - << selectionBehavior - << groupingEnabled - << testList; + QTest::newRow(testNameAscii.data()) << layout << scrollOrientation << columnCount << selectionBehavior << groupingEnabled << testList; } } } @@ -518,9 +514,15 @@ void KItemListControllerTest::testKeyboardNavigation() QCOMPARE(m_selectionManager->currentItem(), current); switch (selectionBehavior) { - case KItemListController::NoSelection: QVERIFY(m_selectionManager->selectedItems().isEmpty()); break; - case KItemListController::SingleSelection: QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << current); break; - case KItemListController::MultiSelection: QCOMPARE(m_selectionManager->selectedItems(), selection); break; + case KItemListController::NoSelection: + QVERIFY(m_selectionManager->selectedItems().isEmpty()); + break; + case KItemListController::SingleSelection: + QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << current); + break; + case KItemListController::MultiSelection: + QCOMPARE(m_selectionManager->selectedItems(), selection); + break; } if (activated) { diff --git a/src/tests/kitemlistkeyboardsearchmanagertest.cpp b/src/tests/kitemlistkeyboardsearchmanagertest.cpp index 686f98b51..17424c801 100644 --- a/src/tests/kitemlistkeyboardsearchmanagertest.cpp +++ b/src/tests/kitemlistkeyboardsearchmanagertest.cpp @@ -6,9 +6,9 @@ #include "kitemviews/private/kitemlistkeyboardsearchmanager.h" -#include <QTest> #include <QSignalSpy> #include <QStandardPaths> +#include <QTest> class KItemListKeyboardSearchManagerTest : public QObject { diff --git a/src/tests/kitemlistselectionmanagertest.cpp b/src/tests/kitemlistselectionmanagertest.cpp index 7f87fdcc8..da761d9a7 100644 --- a/src/tests/kitemlistselectionmanagertest.cpp +++ b/src/tests/kitemlistselectionmanagertest.cpp @@ -5,12 +5,12 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#include "kitemviews/kitemmodelbase.h" #include "kitemviews/kitemlistselectionmanager.h" +#include "kitemviews/kitemmodelbase.h" -#include <QTest> #include <QSignalSpy> #include <QStandardPaths> +#include <QTest> class DummyModel : public KItemModelBase { @@ -25,9 +25,9 @@ private: int m_count; }; -DummyModel::DummyModel() : - KItemModelBase(), - m_count(100) +DummyModel::DummyModel() + : KItemModelBase() + , m_count(100) { } @@ -47,7 +47,6 @@ QHash<QByteArray, QVariant> DummyModel::data(int index) const return QHash<QByteArray, QVariant>(); } - class KItemListSelectionManagerTest : public QObject { Q_OBJECT @@ -72,10 +71,10 @@ private Q_SLOTS: void testAnchoredSelectionAfterMovingItems(); private: - void verifySelectionChange(QSignalSpy& spy, const KItemSet& currentSelection, const KItemSet& previousSelection) const; + void verifySelectionChange(QSignalSpy &spy, const KItemSet ¤tSelection, const KItemSet &previousSelection) const; - KItemListSelectionManager* m_selectionManager; - DummyModel* m_model; + KItemListSelectionManager *m_selectionManager; + DummyModel *m_model; }; void KItemListSelectionManagerTest::initTestCase() @@ -139,10 +138,7 @@ void KItemListSelectionManagerTest::testCurrentItemAnchorItem() QVERIFY(m_selectionManager->hasSelection()); // Inserting items should update current item and anchor item. - m_selectionManager->itemsInserted(KItemRangeList() << - KItemRange(0, 1) << - KItemRange(2, 2) << - KItemRange(6, 3)); + m_selectionManager->itemsInserted(KItemRangeList() << KItemRange(0, 1) << KItemRange(2, 2) << KItemRange(6, 3)); QCOMPARE(m_selectionManager->currentItem(), 5); QCOMPARE(spyCurrent.count(), 1); @@ -156,10 +152,7 @@ void KItemListSelectionManagerTest::testCurrentItemAnchorItem() QVERIFY(m_selectionManager->hasSelection()); // Removing items should update current item and anchor item. - m_selectionManager->itemsRemoved(KItemRangeList() << - KItemRange(0, 2) << - KItemRange(2, 1) << - KItemRange(9, 2)); + m_selectionManager->itemsRemoved(KItemRangeList() << KItemRange(0, 2) << KItemRange(2, 1) << KItemRange(9, 2)); QCOMPARE(m_selectionManager->currentItem(), 2); QCOMPARE(spyCurrent.count(), 1); @@ -224,10 +217,7 @@ void KItemListSelectionManagerTest::testItemsInserted() QVERIFY(selectedItems.contains(17)); // Insert 3 items between the selections - m_selectionManager->itemsInserted(KItemRangeList() << - KItemRange(15, 1) << - KItemRange(16, 1) << - KItemRange(17, 1)); + m_selectionManager->itemsInserted(KItemRangeList() << KItemRange(15, 1) << KItemRange(16, 1) << KItemRange(17, 1)); selectedItems = m_selectionManager->selectedItems(); QCOMPARE(selectedItems.count(), 3); QVERIFY(selectedItems.contains(16)); @@ -254,10 +244,7 @@ void KItemListSelectionManagerTest::testItemsRemoved() } // Remove the items 6 , 8 and 10 - m_selectionManager->itemsRemoved(KItemRangeList() << - KItemRange(6, 1) << - KItemRange(8, 1) << - KItemRange(10, 1)); + m_selectionManager->itemsRemoved(KItemRangeList() << KItemRange(6, 1) << KItemRange(8, 1) << KItemRange(10, 1)); selectedItems = m_selectionManager->selectedItems(); QCOMPARE(selectedItems.count(), 3); QVERIFY(selectedItems.contains(5)); @@ -306,15 +293,9 @@ void KItemListSelectionManagerTest::testAnchoredSelection() QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6 << 7 << 9 << 10); } -namespace { - enum ChangeType { - NoChange, - InsertItems, - RemoveItems, - MoveItems, - EndAnchoredSelection, - SetSelected - }; +namespace +{ +enum ChangeType { NoChange, InsertItems, RemoveItems, MoveItems, EndAnchoredSelection, SetSelected }; } Q_DECLARE_METATYPE(KItemSet) @@ -356,77 +337,38 @@ void KItemListSelectionManagerTest::testChangeSelection_data() QTest::addColumn<int>("current"); QTest::addColumn<KItemSet>("expectedSelection"); QTest::addColumn<ChangeType>("changeType"); - QTest::addColumn<QList<QVariant> >("data"); + QTest::addColumn<QList<QVariant>>("data"); QTest::addColumn<KItemSet>("finalSelection"); - QTest::newRow("No change") - << (KItemSet() << 5 << 6) - << 2 << 3 - << (KItemSet() << 2 << 3 << 5 << 6) - << NoChange - << QList<QVariant>{} - << (KItemSet() << 2 << 3 << 5 << 6); + QTest::newRow("No change") << (KItemSet() << 5 << 6) << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) << NoChange << QList<QVariant>{} + << (KItemSet() << 2 << 3 << 5 << 6); - QTest::newRow("Insert Items") - << (KItemSet() << 5 << 6) - << 2 << 3 - << (KItemSet() << 2 << 3 << 5 << 6) - << InsertItems - << QList<QVariant>{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 2) << KItemRange(10, 5))} - << (KItemSet() << 3 << 4 << 8 << 9); + QTest::newRow("Insert Items") << (KItemSet() << 5 << 6) << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) << InsertItems + << QList<QVariant>{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 2) << KItemRange(10, 5))} + << (KItemSet() << 3 << 4 << 8 << 9); - QTest::newRow("Remove Items") - << (KItemSet() << 5 << 6) - << 2 << 3 - << (KItemSet() << 2 << 3 << 5 << 6) - << RemoveItems - << QList<QVariant>{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(3, 1) << KItemRange(10, 5))} - << (KItemSet() << 1 << 2 << 3 << 4); + QTest::newRow("Remove Items") << (KItemSet() << 5 << 6) << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) << RemoveItems + << QList<QVariant>{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(3, 1) << KItemRange(10, 5))} + << (KItemSet() << 1 << 2 << 3 << 4); - QTest::newRow("Empty Anchored Selection") - << KItemSet() - << 2 << 2 - << KItemSet() - << EndAnchoredSelection - << QList<QVariant>{} - << KItemSet(); + QTest::newRow("Empty Anchored Selection") << KItemSet() << 2 << 2 << KItemSet() << EndAnchoredSelection << QList<QVariant>{} << KItemSet(); - QTest::newRow("Toggle selection") - << (KItemSet() << 1 << 3 << 4) - << 6 << 8 - << (KItemSet() << 1 << 3 << 4 << 6 << 7 << 8) - << SetSelected - << QList<QVariant>{0, 10, QVariant::fromValue(KItemListSelectionManager::Toggle)} - << (KItemSet() << 0 << 2 << 5 << 9); + QTest::newRow("Toggle selection") << (KItemSet() << 1 << 3 << 4) << 6 << 8 << (KItemSet() << 1 << 3 << 4 << 6 << 7 << 8) << SetSelected + << QList<QVariant>{0, 10, QVariant::fromValue(KItemListSelectionManager::Toggle)} << (KItemSet() << 0 << 2 << 5 << 9); // Swap items 2, 3 and 4, 5 - QTest::newRow("Move items") - << (KItemSet() << 0 << 1 << 2 << 3) - << -1 << -1 - << (KItemSet() << 0 << 1 << 2 << 3) - << MoveItems - << QList<QVariant>{QVariant::fromValue(KItemRange(2, 4)), - QVariant::fromValue(QList<int>{4, 5, 2, 3})} - << (KItemSet() << 0 << 1 << 4 << 5); + QTest::newRow("Move items") << (KItemSet() << 0 << 1 << 2 << 3) << -1 << -1 << (KItemSet() << 0 << 1 << 2 << 3) << MoveItems + << QList<QVariant>{QVariant::fromValue(KItemRange(2, 4)), QVariant::fromValue(QList<int>{4, 5, 2, 3})} + << (KItemSet() << 0 << 1 << 4 << 5); QTest::newRow("Move items with active anchored selection") - << KItemSet() - << 0 << 3 - << (KItemSet() << 0 << 1 << 2 << 3) - << MoveItems - << QList<QVariant>{QVariant::fromValue(KItemRange(2, 4)), - QVariant::fromValue(QList<int>{4, 5, 2, 3})} - << (KItemSet() << 0 << 1 << 4 << 5); + << KItemSet() << 0 << 3 << (KItemSet() << 0 << 1 << 2 << 3) << MoveItems + << QList<QVariant>{QVariant::fromValue(KItemRange(2, 4)), QVariant::fromValue(QList<int>{4, 5, 2, 3})} << (KItemSet() << 0 << 1 << 4 << 5); // Revert sort order - QTest::newRow("Revert sort order") - << (KItemSet() << 0 << 1) - << 3 << 4 - << (KItemSet() << 0 << 1 << 3 << 4) - << MoveItems - << QList<QVariant>{QVariant::fromValue(KItemRange(0, 10)), - QVariant::fromValue(QList<int>{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})} - << (KItemSet() << 5 << 6 << 8 << 9); + QTest::newRow("Revert sort order") << (KItemSet() << 0 << 1) << 3 << 4 << (KItemSet() << 0 << 1 << 3 << 4) << MoveItems + << QList<QVariant>{QVariant::fromValue(KItemRange(0, 10)), QVariant::fromValue(QList<int>{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})} + << (KItemSet() << 5 << 6 << 8 << 9); } void KItemListSelectionManagerTest::testChangeSelection() @@ -470,8 +412,7 @@ void KItemListSelectionManagerTest::testChangeSelection() m_selectionManager->itemsRemoved(data.at(0).value<KItemRangeList>()); break; case MoveItems: - m_selectionManager->itemsMoved(data.at(0).value<KItemRange>(), - data.at(1).value<QList<int>>()); + m_selectionManager->itemsMoved(data.at(0).value<KItemRange>(), data.at(1).value<QList<int>>()); break; case EndAnchoredSelection: m_selectionManager->endAnchoredSelection(); @@ -501,11 +442,11 @@ void KItemListSelectionManagerTest::testDeleteCurrentItem_data() QTest::addColumn<int>("removeCount"); QTest::addColumn<int>("newCurrentItemIndex"); - QTest::newRow("Remove before") << 50 << 0 << 10 << 40; - QTest::newRow("Remove after") << 50 << 51 << 10 << 50; - QTest::newRow("Remove exactly current item") << 50 << 50 << 1 << 50; - QTest::newRow("Remove around current item") << 50 << 45 << 10 << 45; - QTest::newRow("Remove all except one item") << 50 << 1 << 99 << 0; + QTest::newRow("Remove before") << 50 << 0 << 10 << 40; + QTest::newRow("Remove after") << 50 << 51 << 10 << 50; + QTest::newRow("Remove exactly current item") << 50 << 50 << 1 << 50; + QTest::newRow("Remove around current item") << 50 << 45 << 10 << 45; + QTest::newRow("Remove all except one item") << 50 << 1 << 99 << 0; } void KItemListSelectionManagerTest::testDeleteCurrentItem() @@ -540,25 +481,21 @@ void KItemListSelectionManagerTest::testAnchoredSelectionAfterMovingItems() QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 1 << 2); } -void KItemListSelectionManagerTest::verifySelectionChange(QSignalSpy& spy, - const KItemSet& currentSelection, - const KItemSet& previousSelection) const +void KItemListSelectionManagerTest::verifySelectionChange(QSignalSpy &spy, const KItemSet ¤tSelection, const KItemSet &previousSelection) const { QCOMPARE(m_selectionManager->selectedItems(), currentSelection); QCOMPARE(m_selectionManager->hasSelection(), !currentSelection.isEmpty()); for (int index = 0; index < m_selectionManager->model()->count(); ++index) { if (currentSelection.contains(index)) { QVERIFY(m_selectionManager->isSelected(index)); - } - else { + } else { QVERIFY(!m_selectionManager->isSelected(index)); } } if (currentSelection == previousSelection) { QCOMPARE(spy.count(), 0); - } - else { + } else { QCOMPARE(spy.count(), 1); QList<QVariant> arguments = spy.takeFirst(); QCOMPARE(qvariant_cast<KItemSet>(arguments.at(0)), currentSelection); diff --git a/src/tests/kitemrangetest.cpp b/src/tests/kitemrangetest.cpp index c782acee7..93e22f6bc 100644 --- a/src/tests/kitemrangetest.cpp +++ b/src/tests/kitemrangetest.cpp @@ -29,7 +29,7 @@ void KItemRangeTest::initTestCase() void KItemRangeTest::testFromSortedContainer_data() { - QTest::addColumn<QVector<int> >("sortedNumbers"); + QTest::addColumn<QVector<int>>("sortedNumbers"); QTest::addColumn<KItemRangeList>("expected"); QTest::newRow("empty") << QVector<int>{} << KItemRangeList(); diff --git a/src/tests/kitemsettest.cpp b/src/tests/kitemsettest.cpp index b5e0a82cd..e0c536c67 100644 --- a/src/tests/kitemsettest.cpp +++ b/src/tests/kitemsettest.cpp @@ -14,10 +14,10 @@ Q_DECLARE_METATYPE(KItemRangeList) /** * Converts a KItemRangeList to a KItemSet. */ -KItemSet KItemRangeList2KItemSet(const KItemRangeList& itemRanges) +KItemSet KItemRangeList2KItemSet(const KItemRangeList &itemRanges) { KItemSet result; - for (const KItemRange& range : itemRanges) { + for (const KItemRange &range : itemRanges) { for (int i = range.index; i < range.index + range.count; ++i) { result.insert(i); } @@ -28,10 +28,10 @@ KItemSet KItemRangeList2KItemSet(const KItemRangeList& itemRanges) /** * Converts a KItemRangeList to a QSet<int>. */ -QSet<int> KItemRangeList2QSet(const KItemRangeList& itemRanges) +QSet<int> KItemRangeList2QSet(const KItemRangeList &itemRanges) { QSet<int> result; - for (const KItemRange& range : itemRanges) { + for (const KItemRange &range : itemRanges) { for (int i = range.index; i < range.index + range.count; ++i) { result.insert(i); } @@ -42,10 +42,10 @@ QSet<int> KItemRangeList2QSet(const KItemRangeList& itemRanges) /** * Converts a KItemRangeList to a QVector<int>. */ -QVector<int> KItemRangeList2QVector(const KItemRangeList& itemRanges) +QVector<int> KItemRangeList2QVector(const KItemRangeList &itemRanges) { QVector<int> result; - for (const KItemRange& range : itemRanges) { + for (const KItemRange &range : itemRanges) { for (int i = range.index; i < range.index + range.count; ++i) { result.append(i); } @@ -56,7 +56,7 @@ QVector<int> KItemRangeList2QVector(const KItemRangeList& itemRanges) /** * Converts a KItemSet to a QSet<int>. */ -static QSet<int> KItemSet2QSet(const KItemSet& itemSet) +static QSet<int> KItemSet2QSet(const KItemSet &itemSet) { QSet<int> result; for (int i : itemSet) { @@ -77,7 +77,6 @@ static QSet<int> KItemSet2QSet(const KItemSet& itemSet) return result; } - /** * The main test class. */ @@ -106,7 +105,7 @@ private Q_SLOTS: void testSymmetricDifference(); private: - QHash<const char*, KItemRangeList> m_testCases; + QHash<const char *, KItemRangeList> m_testCases; }; void KItemSetTest::initTestCase() @@ -122,7 +121,8 @@ void KItemSetTest::initTestCase() m_testCases.insert("[1, 2] [4, 5]", KItemRangeList() << KItemRange(1, 2) << KItemRange(4, 2)); m_testCases.insert("[1, 5]", KItemRangeList() << KItemRange(1, 5)); m_testCases.insert("[1, 2] [4, 5] [7] [9, 10] [13] [20, 25] [30]", - KItemRangeList() << KItemRange(1, 2) << KItemRange(4, 2) << KItemRange(7, 1) << KItemRange(9, 2) << KItemRange(20, 6) << KItemRange(30, 1)); + KItemRangeList() << KItemRange(1, 2) << KItemRange(4, 2) << KItemRange(7, 1) << KItemRange(9, 2) << KItemRange(20, 6) + << KItemRange(30, 1)); m_testCases.insert("[-10, -1]", KItemRangeList() << KItemRange(-10, 10)); m_testCases.insert("[-10, 0]", KItemRangeList() << KItemRange(-10, 11)); m_testCases.insert("[-10, 1]", KItemRangeList() << KItemRange(-10, 12)); @@ -134,8 +134,8 @@ void KItemSetTest::testConstruction_data() { QTest::addColumn<KItemRangeList>("itemRanges"); - QHash<const char*, KItemRangeList>::const_iterator it = m_testCases.constBegin(); - const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd(); + QHash<const char *, KItemRangeList>::const_iterator it = m_testCases.constBegin(); + const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd(); while (it != end) { QTest::newRow(it.key()) << it.value(); @@ -170,8 +170,8 @@ void KItemSetTest::testIterators_data() { QTest::addColumn<KItemRangeList>("itemRanges"); - QHash<const char*, KItemRangeList>::const_iterator it = m_testCases.constBegin(); - const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd(); + QHash<const char *, KItemRangeList>::const_iterator it = m_testCases.constBegin(); + const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd(); while (it != end) { QTest::newRow(it.key()) << it.value(); @@ -305,8 +305,8 @@ void KItemSetTest::testFind_data() { QTest::addColumn<KItemRangeList>("itemRanges"); - QHash<const char*, KItemRangeList>::const_iterator it = m_testCases.constBegin(); - const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd(); + QHash<const char *, KItemRangeList>::const_iterator it = m_testCases.constBegin(); + const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd(); while (it != end) { QTest::newRow(it.key()) << it.value(); @@ -364,8 +364,8 @@ void KItemSetTest::testChangingOneItem_data() { QTest::addColumn<KItemRangeList>("itemRanges"); - QHash<const char*, KItemRangeList>::const_iterator it = m_testCases.constBegin(); - const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd(); + QHash<const char *, KItemRangeList>::const_iterator it = m_testCases.constBegin(); + const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd(); while (it != end) { QTest::newRow(it.key()) << it.value(); @@ -403,7 +403,6 @@ void KItemSetTest::testChangingOneItem() // Test insert(int), remove(int), and erase(KItemSet::iterator) // for items between min - 2 and max + 2. for (int i = min - 2; i <= max + 2; ++i) { - // Test insert(int). { KItemSet tmp(itemSet); @@ -512,11 +511,11 @@ void KItemSetTest::testAddSets_data() QTest::addColumn<KItemRangeList>("itemRanges1"); QTest::addColumn<KItemRangeList>("itemRanges2"); - QHash<const char*, KItemRangeList>::const_iterator it1 = m_testCases.constBegin(); - const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd(); + QHash<const char *, KItemRangeList>::const_iterator it1 = m_testCases.constBegin(); + const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd(); while (it1 != end) { - QHash<const char*, KItemRangeList>::const_iterator it2 = m_testCases.constBegin(); + QHash<const char *, KItemRangeList>::const_iterator it2 = m_testCases.constBegin(); while (it2 != end) { QByteArray name = it1.key() + QByteArray(" + ") + it2.key(); @@ -551,11 +550,11 @@ void KItemSetTest::testSymmetricDifference_data() QTest::addColumn<KItemRangeList>("itemRanges1"); QTest::addColumn<KItemRangeList>("itemRanges2"); - QHash<const char*, KItemRangeList>::const_iterator it1 = m_testCases.constBegin(); - const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd(); + QHash<const char *, KItemRangeList>::const_iterator it1 = m_testCases.constBegin(); + const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd(); while (it1 != end) { - QHash<const char*, KItemRangeList>::const_iterator it2 = m_testCases.constBegin(); + QHash<const char *, KItemRangeList>::const_iterator it2 = m_testCases.constBegin(); while (it2 != end) { QByteArray name = it1.key() + QByteArray(" ^ ") + it2.key(); @@ -594,7 +593,6 @@ void KItemSetTest::testSymmetricDifference() QCOMPARE(itemSet2 ^ symmetricDifference, itemSet1); } - QTEST_GUILESS_MAIN(KItemSetTest) #include "kitemsettest.moc" diff --git a/src/tests/testdir.cpp b/src/tests/testdir.cpp index 6fbc4c426..30ca6632e 100644 --- a/src/tests/testdir.cpp +++ b/src/tests/testdir.cpp @@ -12,8 +12,8 @@ #include <sys/utime.h> #endif -TestDir::TestDir(const QString& directoryPrefix) : - QTemporaryDir(directoryPrefix) +TestDir::TestDir(const QString &directoryPrefix) + : QTemporaryDir(directoryPrefix) { } @@ -27,7 +27,7 @@ QUrl TestDir::url() const } /** The following function is taken from kdelibs/kio/tests/kiotesthelper.h, copyright (C) 2006 by David Faure */ -static void setTimeStamp(const QString& path, const QDateTime& mtime) +static void setTimeStamp(const QString &path, const QDateTime &mtime) { #ifdef Q_OS_UNIX struct utimbuf utbuf; @@ -42,7 +42,7 @@ static void setTimeStamp(const QString& path, const QDateTime& mtime) #endif } -void TestDir::createFile(const QString& path, const QByteArray& data, const QDateTime& time) +void TestDir::createFile(const QString &path, const QByteArray &data, const QDateTime &time) { QString absolutePath = path; makePathAbsoluteAndCreateParents(absolutePath); @@ -59,14 +59,14 @@ void TestDir::createFile(const QString& path, const QByteArray& data, const QDat Q_ASSERT(QFile::exists(absolutePath)); } -void TestDir::createFiles(const QStringList& files) +void TestDir::createFiles(const QStringList &files) { - for (const QString& path : files) { + for (const QString &path : files) { createFile(path); } } -void TestDir::createDir(const QString& path, const QDateTime& time) +void TestDir::createDir(const QString &path, const QDateTime &time) { QString absolutePath = path; makePathAbsoluteAndCreateParents(absolutePath); @@ -79,14 +79,14 @@ void TestDir::createDir(const QString& path, const QDateTime& time) Q_ASSERT(QFile::exists(absolutePath)); } -void TestDir::removeFiles(const QStringList& files) +void TestDir::removeFiles(const QStringList &files) { - for (const QString& path : files) { + for (const QString &path : files) { removeFile(path); } } -void TestDir::removeFile(const QString& path) +void TestDir::removeFile(const QString &path) { QString absolutePath = path; QFileInfo fileInfo(absolutePath); @@ -96,7 +96,7 @@ void TestDir::removeFile(const QString& path) QFile::remove(absolutePath); } -void TestDir::removeDir(const QString& path) +void TestDir::removeDir(const QString &path) { QString absolutePath = path; QFileInfo fileInfo(absolutePath); @@ -107,7 +107,7 @@ void TestDir::removeDir(const QString& path) dirToRemove.removeRecursively(); } -void TestDir::makePathAbsoluteAndCreateParents(QString& path) +void TestDir::makePathAbsoluteAndCreateParents(QString &path) { QFileInfo fileInfo(path); if (!fileInfo.isAbsolute()) { diff --git a/src/tests/testdir.h b/src/tests/testdir.h index 921a89185..10d7614c2 100644 --- a/src/tests/testdir.h +++ b/src/tests/testdir.h @@ -7,9 +7,9 @@ #ifndef TESTDIR_H #define TESTDIR_H -#include <QUrl> -#include <QTemporaryDir> #include <QDateTime> +#include <QTemporaryDir> +#include <QUrl> /** * TestDir provides a temporary directory. In addition to QTemporaryDir, it has @@ -17,9 +17,8 @@ */ class TestDir : public QTemporaryDir { - public: - TestDir(const QString& directoryPrefix = QString()); + TestDir(const QString &directoryPrefix = QString()); virtual ~TestDir(); QUrl url() const; @@ -29,19 +28,16 @@ public: * The paths may be absolute or relative to the test directory. Any missing parent * directories will be created automatically. */ - void createFile(const QString& path, - const QByteArray& data = QByteArray("test"), - const QDateTime& time = QDateTime()); - void createFiles(const QStringList& files); - void createDir(const QString& path, const QDateTime& time = QDateTime()); + void createFile(const QString &path, const QByteArray &data = QByteArray("test"), const QDateTime &time = QDateTime()); + void createFiles(const QStringList &files); + void createDir(const QString &path, const QDateTime &time = QDateTime()); - void removeFile(const QString& path); - void removeFiles(const QStringList& files); - void removeDir(const QString& path); + void removeFile(const QString &path); + void removeFiles(const QStringList &files); + void removeDir(const QString &path); private: - void makePathAbsoluteAndCreateParents(QString& path); - + void makePathAbsoluteAndCreateParents(QString &path); }; #endif diff --git a/src/tests/viewpropertiestest.cpp b/src/tests/viewpropertiestest.cpp index 14d59be0a..7b30203d2 100644 --- a/src/tests/viewpropertiestest.cpp +++ b/src/tests/viewpropertiestest.cpp @@ -4,8 +4,8 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#include "dolphin_generalsettings.h" #include "views/viewproperties.h" +#include "dolphin_generalsettings.h" #include "testdir.h" #include <QTest> @@ -24,7 +24,7 @@ private Q_SLOTS: private: bool m_globalViewProps; - TestDir* m_testDir; + TestDir *m_testDir; }; void ViewPropertiesTest::initTestCase() |
