File indexing completed on 2024-02-25 04:00:01

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 putPermissionKept();
0041     void storedPut();
0042     void storedPutIODevice();
0043     void storedPutIODeviceFile();
0044     void storedPutIODeviceTempFile();
0045     void storedPutIODeviceFastDevice();
0046     void storedPutIODeviceSlowDevice();
0047     void storedPutIODeviceSlowDeviceBigChunk();
0048     void asyncStoredPutReadyReadAfterFinish();
0049     void copyFileToSamePartition();
0050     void testCopyFilePermissionsToSamePartition();
0051     void copyDirectoryToSamePartition();
0052     void copyDirectoryToExistingDirectory();
0053     void copyDirectoryToExistingSymlinkedDirectory();
0054     void copyFileToOtherPartition();
0055     void copyDirectoryToOtherPartition();
0056     void copyRelativeSymlinkToSamePartition();
0057     void copyAbsoluteSymlinkToOtherPartition();
0058     void copyFolderWithUnaccessibleSubfolder();
0059     void copyDataUrl();
0060     void suspendFileCopy();
0061     void suspendCopy();
0062     void listRecursive();
0063     void multipleListRecursive();
0064     void listFile();
0065     void killJob();
0066     void killJobBeforeStart();
0067     void deleteJobBeforeStart();
0068     void directorySize();
0069     void directorySizeError();
0070     void moveFileToSamePartition();
0071     void moveDirectoryToSamePartition();
0072     void moveDirectoryIntoItself();
0073     void moveFileToOtherPartition();
0074     void moveSymlinkToOtherPartition();
0075     void moveDirectoryToOtherPartition();
0076     void moveFileNoPermissions();
0077     void moveDirectoryNoPermissions();
0078     void moveDirectoryToReadonlyFilesystem_data();
0079     void moveDirectoryToReadonlyFilesystem();
0080     void deleteFile();
0081     void deleteDirectory();
0082     void deleteSymlink();
0083     void deleteManyDirs();
0084     void deleteManyFilesIndependently();
0085     void deleteManyFilesTogether();
0086     void rmdirEmpty();
0087     void rmdirNotEmpty();
0088     void stat();
0089     void statDetailsBasic();
0090     void statDetailsBasicSetDetails();
0091     void statWithInode();
0092 #ifndef Q_OS_WIN
0093     void statSymlink();
0094     void statTimeResolution();
0095 #endif
0096     void mostLocalUrl();
0097     void mostLocalUrlHttp();
0098     void chmodFile();
0099 #ifdef Q_OS_UNIX
0100     void chmodSticky();
0101 #endif
0102     void chmodFileError();
0103     void mimeType();
0104     void mimeTypeError();
0105     void calculateRemainingSeconds();
0106     void moveFileDestAlreadyExists_data();
0107     void moveFileDestAlreadyExists();
0108     void copyFileDestAlreadyExists_data();
0109     void copyFileDestAlreadyExists();
0110     void moveDestAlreadyExistsAutoRename_data();
0111     void moveDestAlreadyExistsAutoRename();
0112 
0113     void copyDirectoryAlreadyExistsSkip();
0114     void copyFileAlreadyExistsRename();
0115 
0116     void safeOverwrite();
0117     void safeOverwrite_data();
0118     void overwriteOlderFiles();
0119     void overwriteOlderFiles_data();
0120     void moveAndOverwrite();
0121     void moveOverSymlinkToSelf();
0122     void createSymlink();
0123     void createSymlinkTargetDirDoesntExist();
0124     void createSymlinkAsShouldSucceed();
0125     void createSymlinkAsShouldFailDirectoryExists();
0126     void createSymlinkAsShouldFailFileExists();
0127     void createSymlinkWithOverwriteShouldWork();
0128     void createBrokenSymlink();
0129 
0130     void cancelCopyAndCleanDest();
0131     void cancelCopyAndCleanDest_data();
0132 
0133     // Remote tests
0134     // void copyFileToSystem();
0135 
0136     void getInvalidUrl();
0137 
0138 Q_SIGNALS:
0139     void exitLoop();
0140 
0141 protected Q_SLOTS:
0142     void slotEntries(KIO::Job *, const KIO::UDSEntryList &lst);
0143     void slotGetResult(KJob *);
0144     void slotDataReq(KIO::Job *, QByteArray &);
0145     void slotResult(KJob *);
0146     void slotMimetype(KIO::Job *, const QString &);
0147 
0148 private:
0149     void enterLoop();
0150     enum { AlreadyExists = 1 };
0151     void copyLocalFile(const QString &src, const QString &dest);
0152     bool checkXattrFsSupport(const QString &writeTest);
0153     bool setXattr(const QString &src);
0154     QList<QByteArray> readXattr(const QString &src);
0155     void compareXattr(const QString &src, const QString &dest);
0156     void copyLocalDirectory(const QString &src, const QString &dest, int flags = 0);
0157     void moveLocalFile(const QString &src, const QString &dest);
0158     void moveLocalDirectory(const QString &src, const QString &dest);
0159     // void copyFileToSystem( bool resolve_local_urls );
0160     void deleteSymlink(bool using_fast_path);
0161     void deleteManyDirs(bool using_fast_path);
0162     void deleteManyFilesTogether(bool using_fast_path);
0163     void moveDestAlreadyExistsAutoRename(const QString &destDir, bool moveDirs);
0164 
0165     int m_result;
0166     QByteArray m_data;
0167     QStringList m_names;
0168     int m_dataReqCount;
0169     QString m_mimetype;
0170     QString m_setXattrCmd;
0171     QString m_getXattrCmd;
0172     std::function<QStringList(const QString &, const QString &, const QString &)> m_setXattrFormatArgs;
0173 };
0174 
0175 #endif