File indexing completed on 2024-06-23 10:37:19

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2004 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef JOBTEST_H
0009 #define JOBTEST_H
0010 
0011 #include <kio/udsentry.h>
0012 #include <kiocore_export.h>
0013 
0014 #include <QObject>
0015 #include <QString>
0016 
0017 namespace KIO
0018 {
0019 class Job;
0020 }
0021 
0022 class KJob;
0023 
0024 class JobTest : public QObject
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     JobTest()
0030     {
0031     }
0032 
0033 private Q_SLOTS:
0034     void initTestCase();
0035     void cleanupTestCase();
0036 
0037     // Local tests (kio_file only)
0038     void storedGet();
0039     void put();
0040     void storedPut();
0041     void storedPutIODevice();
0042     void storedPutIODeviceFile();
0043     void storedPutIODeviceTempFile();
0044     void storedPutIODeviceFastDevice();
0045     void storedPutIODeviceSlowDevice();
0046     void storedPutIODeviceSlowDeviceBigChunk();
0047     void asyncStoredPutReadyReadAfterFinish();
0048     void copyFileToSamePartition();
0049     void testCopyFilePermissionsToSamePartition();
0050     void copyDirectoryToSamePartition();
0051     void copyDirectoryToExistingDirectory();
0052     void copyDirectoryToExistingSymlinkedDirectory();
0053     void copyFileToOtherPartition();
0054     void copyDirectoryToOtherPartition();
0055     void copyRelativeSymlinkToSamePartition();
0056     void copyAbsoluteSymlinkToOtherPartition();
0057     void copyFolderWithUnaccessibleSubfolder();
0058     void copyDataUrl();
0059     void suspendFileCopy();
0060     void suspendCopy();
0061     void listRecursive();
0062     void multipleListRecursive();
0063     void listFile();
0064     void killJob();
0065     void killJobBeforeStart();
0066     void deleteJobBeforeStart();
0067     void directorySize();
0068     void directorySizeError();
0069     void moveFileToSamePartition();
0070     void moveDirectoryToSamePartition();
0071     void moveDirectoryIntoItself();
0072     void moveFileToOtherPartition();
0073     void moveSymlinkToOtherPartition();
0074     void moveDirectoryToOtherPartition();
0075     void moveFileNoPermissions();
0076     void moveDirectoryNoPermissions();
0077     void moveDirectoryToReadonlyFilesystem_data();
0078     void moveDirectoryToReadonlyFilesystem();
0079     void deleteFile();
0080     void deleteDirectory();
0081     void deleteSymlink();
0082     void deleteManyDirs();
0083     void deleteManyFilesIndependently();
0084     void deleteManyFilesTogether();
0085     void rmdirEmpty();
0086     void rmdirNotEmpty();
0087     void stat();
0088     void statDetailsBasic();
0089     void statDetailsBasicSetDetails();
0090     void statWithInode();
0091 #ifndef Q_OS_WIN
0092     void statSymlink();
0093     void statTimeResolution();
0094 #endif
0095     void mostLocalUrl();
0096     void mostLocalUrlHttp();
0097     void chmodFile();
0098 #ifdef Q_OS_UNIX
0099     void chmodSticky();
0100 #endif
0101     void chmodFileError();
0102     void mimeType();
0103     void mimeTypeError();
0104     void calculateRemainingSeconds();
0105     void moveFileDestAlreadyExists_data();
0106     void moveFileDestAlreadyExists();
0107     void copyFileDestAlreadyExists_data();
0108     void copyFileDestAlreadyExists();
0109     void moveDestAlreadyExistsAutoRename_data();
0110     void moveDestAlreadyExistsAutoRename();
0111 
0112     void copyDirectoryAlreadyExistsSkip();
0113     void copyFileAlreadyExistsRename();
0114 
0115     void safeOverwrite();
0116     void safeOverwrite_data();
0117     void overwriteOlderFiles();
0118     void overwriteOlderFiles_data();
0119     void moveAndOverwrite();
0120     void moveOverSymlinkToSelf();
0121     void createSymlink();
0122     void createSymlinkTargetDirDoesntExist();
0123     void createSymlinkAsShouldSucceed();
0124     void createSymlinkAsShouldFailDirectoryExists();
0125     void createSymlinkAsShouldFailFileExists();
0126     void createSymlinkWithOverwriteShouldWork();
0127     void createBrokenSymlink();
0128 
0129     void cancelCopyAndCleanDest();
0130     void cancelCopyAndCleanDest_data();
0131 
0132     // Remote tests
0133     // void copyFileToSystem();
0134 
0135     void getInvalidUrl();
0136 #if KIOCORE_BUILD_DEPRECATED_SINCE(5, 84)
0137     void multiGet();
0138 #endif
0139 
0140 Q_SIGNALS:
0141     void exitLoop();
0142 
0143 protected Q_SLOTS:
0144     void slotEntries(KIO::Job *, const KIO::UDSEntryList &lst);
0145     void slotGetResult(KJob *);
0146     void slotDataReq(KIO::Job *, QByteArray &);
0147     void slotResult(KJob *);
0148     void slotMimetype(KIO::Job *, const QString &);
0149 
0150 private:
0151     void enterLoop();
0152     enum { AlreadyExists = 1 };
0153     void copyLocalFile(const QString &src, const QString &dest);
0154     bool checkXattrFsSupport(const QString &writeTest);
0155     bool setXattr(const QString &src);
0156     QList<QByteArray> readXattr(const QString &src);
0157     void compareXattr(const QString &src, const QString &dest);
0158     void copyLocalDirectory(const QString &src, const QString &dest, int flags = 0);
0159     void moveLocalFile(const QString &src, const QString &dest);
0160     void moveLocalDirectory(const QString &src, const QString &dest);
0161     // void copyFileToSystem( bool resolve_local_urls );
0162     void deleteSymlink(bool using_fast_path);
0163     void deleteManyDirs(bool using_fast_path);
0164     void deleteManyFilesTogether(bool using_fast_path);
0165     void moveDestAlreadyExistsAutoRename(const QString &destDir, bool moveDirs);
0166 
0167     int m_result;
0168     QByteArray m_data;
0169     QStringList m_names;
0170     int m_dataReqCount;
0171     QString m_mimetype;
0172     QString m_setXattrCmd;
0173     QString m_getXattrCmd;
0174     std::function<QStringList(const QString &, const QString &, const QString &)> m_setXattrFormatArgs;
0175 };
0176 
0177 #endif