File indexing completed on 2024-05-19 04:39:58

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2014 Milian Wolff <mail@milianw.de>
0004     SPDX-FileCopyrightText: 2023 Igor Kushnir <igorkuo@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #ifndef KSEQUENTIALCOMPOUNDJOBTEST_H
0010 #define KSEQUENTIALCOMPOUNDJOBTEST_H
0011 
0012 #include <KJob>
0013 
0014 #include <QObject>
0015 
0016 class TestJob : public KJob
0017 {
0018     Q_OBJECT
0019 public:
0020     void start() override
0021     {
0022         Q_EMIT started(this);
0023     }
0024 
0025     void emitInfoMessage(const QString &info)
0026     {
0027         Q_EMIT infoMessage(this, info);
0028     }
0029 
0030     using KJob::emitResult;
0031     using KJob::setError;
0032     using KJob::setErrorText;
0033     using KJob::setPercent;
0034 
0035 Q_SIGNALS:
0036     void started(KJob *job);
0037 };
0038 
0039 class KillableTestJob : public TestJob
0040 {
0041     Q_OBJECT
0042 public:
0043     explicit KillableTestJob()
0044     {
0045         setCapabilities(Killable);
0046     }
0047 
0048     void setKillingSucceeds(bool succeeds)
0049     {
0050         m_killingSucceeds = succeeds;
0051     }
0052 
0053 Q_SIGNALS:
0054     void killed(bool successfully);
0055 
0056 protected:
0057     bool doKill() override
0058     {
0059         Q_EMIT killed(m_killingSucceeds);
0060         return m_killingSucceeds;
0061     }
0062 
0063 private:
0064     bool m_killingSucceeds = true;
0065 };
0066 
0067 class KSequentialCompoundJobTest : public QObject
0068 {
0069     Q_OBJECT
0070 private Q_SLOTS:
0071     void initTestCase();
0072 
0073     void runZeroJobs();
0074     void runOneJob();
0075     void runTwoJobs();
0076 
0077     void addRemoveClearSubjob_data();
0078     void addRemoveClearSubjob();
0079     void addClearSubjobs();
0080 
0081     void subjobPercentChanged();
0082 
0083     void abortOnSubjobError();
0084     void disableAbortOnSubjobError_data();
0085     void disableAbortOnSubjobError();
0086 
0087     void finishWrongSubjob_data();
0088     void finishWrongSubjob();
0089 
0090     void killUnstartedCompoundJob_data();
0091     void killUnstartedCompoundJob();
0092     void killFinishedCompoundJob_data();
0093     void killFinishedCompoundJob();
0094 
0095     void killRunningCompoundJob();
0096     void killingSubjobFails();
0097 
0098     void killRunningCompoundJobRepeatedly_data();
0099     void killRunningCompoundJobRepeatedly();
0100 };
0101 
0102 #endif // KSEQUENTIALCOMPOUNDJOBTEST_H