File indexing completed on 2024-04-21 07:41:43

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 #ifndef KDIRLISTERTEST_H
0008 #define KDIRLISTERTEST_H
0009 
0010 #include <QDate>
0011 #include <QEventLoop>
0012 #include <QObject>
0013 #include <QSignalSpy>
0014 #include <QTemporaryDir>
0015 #include <kdirlister.h>
0016 
0017 #include <memory>
0018 
0019 Q_DECLARE_METATYPE(KFileItemList)
0020 
0021 class GlobalInits
0022 {
0023 public:
0024     GlobalInits();
0025 };
0026 
0027 class MyDirLister : public KDirLister, GlobalInits
0028 {
0029 public:
0030     MyDirLister()
0031         : spyStarted(this, &KCoreDirLister::started)
0032         , spyItemsDeleted(this, &KCoreDirLister::itemsDeleted)
0033         , spyClear(this, qOverload<>(&KCoreDirLister::clear))
0034         , spyClearDir(this, &KCoreDirLister::clearDir)
0035         , spyCompleted(this, qOverload<>(&KCoreDirLister::completed))
0036         , spyCanceled(this, qOverload<>(&KCoreDirLister::canceled))
0037         , spyCompletedQUrl(this, &KCoreDirLister::listingDirCompleted)
0038         , spyCanceledQUrl(this, &KCoreDirLister::listingDirCanceled)
0039         , spyRedirection(this, &KCoreDirLister::redirection)
0040         , spyJobError(this, &KCoreDirLister::jobError)
0041     {
0042     }
0043 
0044     void clearSpies()
0045     {
0046         spyStarted.clear();
0047         spyClear.clear();
0048         spyCompleted.clear();
0049         spyCompletedQUrl.clear();
0050         spyCanceled.clear();
0051         spyCanceledQUrl.clear();
0052         spyRedirection.clear();
0053         spyItemsDeleted.clear();
0054         spyJobError.clear();
0055     }
0056 
0057     QSignalSpy spyStarted;
0058     QSignalSpy spyItemsDeleted;
0059     QSignalSpy spyClear;
0060     QSignalSpy spyClearDir;
0061     QSignalSpy spyCompleted;
0062     QSignalSpy spyCanceled;
0063     QSignalSpy spyCompletedQUrl;
0064     QSignalSpy spyCanceledQUrl;
0065     QSignalSpy spyRedirection;
0066     QSignalSpy spyJobError;
0067 };
0068 
0069 class KDirListerTest : public QObject
0070 {
0071     Q_OBJECT
0072 private Q_SLOTS:
0073     void initTestCase();
0074     void cleanup();
0075     void testInvalidUrl();
0076     void testNonListableUrl();
0077     void testOpenUrl();
0078     void testOpenUrlFromCache();
0079     void testNewItem();
0080     void testNewItems();
0081     void benchFindByUrl();
0082     void testNewItemByCopy();
0083     void testNewItemByCopyInSubDir();
0084     void testNewItemsInSymlink();
0085     void testRefreshItems();
0086     void testRefreshRootItem();
0087     void testDeleteItem();
0088     void testDeleteItems();
0089     void testRenameItem();
0090     void testRenameAndOverwrite();
0091     void testConcurrentListing();
0092     void testConcurrentHoldingListing();
0093     void testConcurrentListingAndStop();
0094     void testDeleteListerEarly();
0095     void testOpenUrlTwice();
0096     void testOpenUrlTwiceWithKeep();
0097     void testOpenAndStop();
0098     void testBug211472();
0099     void testRenameCurrentDir();
0100     void testRenameCurrentDirOpenUrl();
0101     void testRedirection();
0102     void testListEmptyDirFromCache();
0103     void testWatchingAfterCopyJob();
0104     void testRemoveWatchedDirectory();
0105     void testDirPermissionChange();
0106     void testCopyAfterListingAndMove(); // #353195
0107     void testRenameDirectory(); // #401552
0108     void testRequestMimeType();
0109     void testMimeFilter_data();
0110     void testMimeFilter();
0111     void testBug386763();
0112     void testCacheEviction();
0113     void testDeleteCurrentDir(); // must be just before last!
0114     void testForgetDir(); // must be last!
0115 
0116 protected Q_SLOTS: // 'more private than private slots' - i.e. not seen by qtestlib
0117     void slotNewItems(const KFileItemList &);
0118     void slotNewItems2(const KFileItemList &);
0119     void slotRefreshItems(const QList<QPair<KFileItem, KFileItem>> &);
0120     void slotRefreshItems2(const QList<QPair<KFileItem, KFileItem>> &);
0121     void slotOpenUrlOnRename(const QUrl &);
0122 
0123 Q_SIGNALS:
0124     void refreshItemsReceived();
0125 
0126 private:
0127     int fileCount() const;
0128     QString tempPath() const;
0129     void createSimpleFile(const QString &fileName);
0130     void fillDirLister2(MyDirLister &lister, const QString &path);
0131     void waitUntilMTimeChange(const QString &path);
0132     void waitUntilAfter(const QDateTime &ctime);
0133 
0134 private:
0135     int m_exitCount;
0136     QEventLoop m_eventLoop;
0137     std::unique_ptr<QTemporaryDir> m_tempDir;
0138     MyDirLister m_dirLister;
0139     KFileItemList m_items;
0140     KFileItemList m_items2;
0141     QList<QPair<KFileItem, KFileItem>> m_refreshedItems, m_refreshedItems2;
0142 };
0143 
0144 #endif