gwenview: fix document test crashes

the testModifyAndSaveAs test case fails tho

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-03-23 14:17:38 +02:00
parent e02661135c
commit c316adfdbb
3 changed files with 23 additions and 15 deletions

View file

@ -522,7 +522,7 @@ void Document::slotJobFinished(KJob* job)
d->mJobQueue.removeAll(documentJob);
}
if (d->mJobQueue.isEmpty()) {
if (d->mJobQueue.isEmpty() && d->mCurrentJob.isNull()) {
kDebug() << "All done";
busyChanged(d->mUrl, false);
allTasksDone();
@ -537,7 +537,7 @@ void Document::slotJobFinished(KJob* job)
bool Document::isBusy() const
{
return !d->mJobQueue.isEmpty();
return (!d->mCurrentJob.isNull() || !d->mJobQueue.isEmpty());
}
} // namespace

View file

@ -64,9 +64,9 @@ static void waitUntilMetaInfoLoaded(Document::Ptr doc)
}
}
static bool waitUntilJobIsDone(DocumentJob* job)
static bool waitUntilJobIsDone(const Document* doc, DocumentJob* job)
{
JobWatcher watcher(job);
JobWatcher watcher(doc, job);
watcher.wait();
return watcher.error() == KJob::NoError;
}
@ -329,7 +329,7 @@ void DocumentTest::testSaveRemote()
doc->waitUntilLoaded();
dstUrl.addPath("testSaveRemote.png");
QVERIFY(waitUntilJobIsDone(doc->save(dstUrl, "png")));
QVERIFY(waitUntilJobIsDone(doc.constData(), doc->save(dstUrl, "png")));
}
/**
@ -405,7 +405,7 @@ void DocumentTest::testSaveAs()
doc->startLoadingFullImage();
KUrl destUrl = urlForTestOutputFile("result.png");
QVERIFY(waitUntilJobIsDone(doc->save(destUrl, "png")));
QVERIFY(waitUntilJobIsDone(doc.constData(), doc->save(destUrl, "png")));
QCOMPARE(doc->format().data(), "png");
QCOMPARE(doc->url(), destUrl);
QCOMPARE(doc->metaInfo()->getValueForKey("General.Name"), destUrl.fileName());
@ -441,7 +441,7 @@ void DocumentTest::testLosslessSave()
doc->waitUntilLoaded();
KUrl url2 = urlForTestOutputFile("orient1.png");
QVERIFY(waitUntilJobIsDone(doc->save(url2, "png")));
QVERIFY(waitUntilJobIsDone(doc.constData(), doc->save(url2, "png")));
QImage image1;
QVERIFY(image1.load(url1.toLocalFile()));
@ -471,7 +471,7 @@ void DocumentTest::testLosslessRotate()
// Save it
KUrl url2 = urlForTestOutputFile("lossless2.png");
waitUntilJobIsDone(doc->save(url2, "png"));
waitUntilJobIsDone(doc.constData(), doc->save(url2, "png"));
// Load the saved image
doc = DocumentFactory::instance()->load(url2);
@ -481,7 +481,7 @@ void DocumentTest::testLosslessRotate()
// Rotate the other way
QVERIFY(doc->editor());
doc->editor()->applyTransformation(ROT_270);
waitUntilJobIsDone(doc->save(url2, "png"));
waitUntilJobIsDone(doc.constData(), doc->save(url2, "png"));
// Compare the saved images
QVERIFY(image1.load(url1.toLocalFile()));
@ -533,12 +533,16 @@ void DocumentTest::testModifyAndSaveAs()
QCOMPARE(args.at(0).value<KUrl>(), url);
// Save it under a new name
KUrl destUrl = urlForTestOutputFile("modify.png");
QVERIFY(waitUntilJobIsDone(doc->save(destUrl, "png")));
KUrl destUrl = urlForTestOutputFile("modify.jpg");
QVERIFY(waitUntilJobIsDone(doc.constData(), doc->save(destUrl, "png")));
// Wait a bit because save() will clear the undo stack when back to the
// event loop
QTest::qWait(100);
QTest::qWait(100); // saved() is emitted asynchronously
QCOMPARE(savedSpy.count(), 1);
args = savedSpy.takeFirst();
QCOMPARE(args.at(0).value<KUrl>(), url);
QCOMPARE(args.at(1).value<KUrl>(), destUrl);
QVERIFY(!doc->isModified());
QVERIFY(!factory->hasUrl(url));

View file

@ -55,8 +55,9 @@ class JobWatcher : public QObject
{
Q_OBJECT
public:
JobWatcher(KJob* job)
: mJob(job)
JobWatcher(const Gwenview::Document* doc, KJob* job)
: mDoc(doc)
, mJob(job)
, mError(0) {
job->setAutoDelete(false);
connect(job, SIGNAL(result(KJob*)),
@ -65,7 +66,9 @@ public:
void wait()
{
mJob->exec();
while (mDoc->isBusy()) {
QTest::qWait(100);
}
}
int error() const
@ -81,6 +84,7 @@ private Q_SLOTS:
}
private:
const Gwenview::Document* mDoc;
KJob* mJob;
int mError;
};