/* This file is part of the KDE libraries SPDX-FileCopyrightText: 2024 Méven Car SPDX-License-Identifier: LGPL-2.0-or-later */ #include "../tests/kjobtrackerstest.h" #include #include #include #include #include #include #include #include #include #include class KTestJobTracker : public KJobTrackerInterface { Q_OBJECT public: KTestJobTracker(QObject *parent = nullptr) : KJobTrackerInterface(parent) { } public Q_SLOTS: void registerJob(KJob *job) override { registeredJobs.append(job); } void unregisterJob(KJob *job) override { unregisteredJobs.append(job); } protected Q_SLOTS: void finished(KJob *job) override { finishedSpy.append(job); } void suspended(KJob *job) override { suspendedSpy.append(job); } void resumed(KJob *job) override { resumedSpy.append(job); } void description(KJob * /*job */, const QString &title, const QPair &field1, const QPair &field2) override { jobTitle = title; jobField1 = field1; jobField2 = field2; } void infoMessage(KJob * /* job */, const QString &message) override { jobInfoMessage = message; } void warning(KJob * /* job */, const QString &message) override { jobWarning = message; } void totalAmount(KJob * /* job */, KJob::Unit unit, qulonglong amount) override { jobTotalUnit = unit; jobTotalAmount = amount; } void processedAmount(KJob * /* job */, KJob::Unit unit, qulonglong amount) override { jobUnit = unit; jobAmount = amount; } void percent(KJob * /* job */, unsigned long percent) override { jobPercent = percent; } void speed(KJob * /* job */, unsigned long value) override { jobSpeed = value; } public: QList registeredJobs; QList unregisteredJobs; QList finishedSpy; QList suspendedSpy; QList resumedSpy; QString jobTitle; QPair jobField1; QPair jobField2; QString jobInfoMessage; QString jobWarning; KJob::Unit jobTotalUnit; qulonglong jobTotalAmount; KJob::Unit jobUnit; qulonglong jobAmount; unsigned long jobPercent; unsigned long jobSpeed; }; class KUiServerV2JobTrackerTest : public QObject { void simpleTest() { KTestJob *testJob = new KTestJob(10 /* 100000 bytes to process */, 5); KTestJobTracker *tracker = new KTestJobTracker(this); tracker->registerJob(testJob); QCOMPARE(tracker->registeredJobs.at(0), testJob); QCOMPARE(tracker->finishedSpy.count(), 0); testJob->start(); QSignalSpy jobFinishedSpy(testJob, &KJob::finished); QVERIFY(jobFinishedSpy.wait()); QCOMPARE(tracker->finishedSpy.count(), 1); } }; QTEST_GUILESS_MAIN(KUiServerV2JobTrackerTest) #include "kuiserver2jobtrackertest.moc"