generic: fix and adjust some tests

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-04-11 20:15:28 +03:00
parent 108c168002
commit d749238e5e
8 changed files with 33 additions and 63 deletions

View file

@ -130,7 +130,7 @@ void ImageScaler::scaleRect(const QRect& rect)
if (qAbs(d->mZoom - 1.0) < REAL_DELTA) {
QImage tmp = d->mDocument->image().copy(rect);
tmp = tmp.convertToFormat(QImage::Format_ARGB32_Premultiplied);
scaledRect(rect.left(), rect.top(), tmp);
emit scaledRect(rect.left(), rect.top(), tmp);
return;
}
@ -208,7 +208,7 @@ void ImageScaler::scaleRect(const QRect& rect)
);
}
scaledRect(destRect.left() + destLeftMargin, destRect.top() + destTopMargin, tmp);
emit scaledRect(destRect.left() + destLeftMargin, destRect.top() + destTopMargin, tmp);
}
} // namespace

View file

@ -46,6 +46,19 @@ QTEST_KDEMAIN(DocumentTest, GUI)
using namespace Gwenview;
static QImage generatTestImage()
{
QImage image1(200, 96, QImage::Format_RGB32);
{
QPainter painter(&image1);
QRadialGradient gradient(QPointF(100, 48), 100);
gradient.setColorAt(0, Qt::white);
gradient.setColorAt(1, Qt::blue);
painter.fillRect(image1.rect(), gradient);
}
return image1;
}
static void waitUntilMetaInfoLoaded(Document::Ptr doc)
{
while (doc->loadingState() < Document::MetaInfoLoaded) {
@ -426,9 +439,10 @@ void DocumentTest::testLosslessSave()
KUrl url1 = urlForTestFile("orient6.jpg");
Document::Ptr doc = DocumentFactory::instance()->load(url1);
doc->startLoadingFullImage();
doc->waitUntilLoaded();
KUrl url2 = urlForTestOutputFile("orient1.jpg");
QVERIFY(waitUntilJobIsDone(doc->save(url2, "jpeg")));
KUrl url2 = urlForTestOutputFile("orient1.png");
QVERIFY(waitUntilJobIsDone(doc->save(url2, "png")));
QImage image1;
QVERIFY(image1.load(url1.toLocalFile()));
@ -442,17 +456,10 @@ void DocumentTest::testLosslessSave()
void DocumentTest::testLosslessRotate()
{
// Generate test image
QImage image1(200, 96, QImage::Format_RGB32);
{
QPainter painter(&image1);
QConicalGradient gradient(QPointF(100, 48), 100);
gradient.setColorAt(0, Qt::white);
gradient.setColorAt(1, Qt::blue);
painter.fillRect(image1.rect(), gradient);
}
QImage image1 = generatTestImage();
KUrl url1 = urlForTestOutputFile("lossless1.jpg");
QVERIFY(image1.save(url1.toLocalFile(), "jpeg"));
KUrl url1 = urlForTestOutputFile("lossless1.png");
QVERIFY(image1.save(url1.toLocalFile(), "png"));
// Load it as a Gwenview document
Document::Ptr doc = DocumentFactory::instance()->load(url1);
@ -464,8 +471,8 @@ void DocumentTest::testLosslessRotate()
doc->editor()->applyTransformation(ROT_90);
// Save it
KUrl url2 = urlForTestOutputFile("lossless2.jpg");
waitUntilJobIsDone(doc->save(url2, "jpeg"));
KUrl url2 = urlForTestOutputFile("lossless2.png");
waitUntilJobIsDone(doc->save(url2, "png"));
// Load the saved image
doc = DocumentFactory::instance()->load(url2);
@ -475,7 +482,7 @@ void DocumentTest::testLosslessRotate()
// Rotate the other way
QVERIFY(doc->editor());
doc->editor()->applyTransformation(ROT_270);
waitUntilJobIsDone(doc->save(url2, "jpeg"));
waitUntilJobIsDone(doc->save(url2, "png"));
// Compare the saved images
QVERIFY(image1.load(url1.toLocalFile()));
@ -565,26 +572,6 @@ void DocumentTest::testMetaInfoJpeg()
QCOMPARE(value, QString::fromUtf8("Canon"));
}
void DocumentTest::testMetaInfoBmp()
{
KUrl url = urlForTestOutputFile("metadata.bmp");
const int width = 200;
const int height = 100;
QImage image(width, height, QImage::Format_ARGB32);
image.fill(Qt::black);
image.save(url.toLocalFile(), "BMP");
Document::Ptr doc = DocumentFactory::instance()->load(url);
QSignalSpy metaInfoUpdatedSpy(doc.data(), SIGNAL(metaInfoUpdated()));
waitUntilMetaInfoLoaded(doc);
Q_ASSERT(metaInfoUpdatedSpy.count() >= 1);
QString value = doc->metaInfo()->getValueForKey("General.ImageSize");
QString expectedValue = QString("%1x%2").arg(width).arg(height);
QCOMPARE(value, expectedValue);
}
void DocumentTest::testForgetModifiedDocument()
{
QSignalSpy spy(DocumentFactory::instance(), SIGNAL(modifiedDocumentListChanged()));
@ -592,14 +579,7 @@ void DocumentTest::testForgetModifiedDocument()
QCOMPARE(spy.count(), 0);
// Generate test image
QImage image1(200, 96, QImage::Format_RGB32);
{
QPainter painter(&image1);
QConicalGradient gradient(QPointF(100, 48), 100);
gradient.setColorAt(0, Qt::white);
gradient.setColorAt(1, Qt::blue);
painter.fillRect(image1.rect(), gradient);
}
QImage image1 = generatTestImage();
KUrl url = urlForTestOutputFile("testForgetModifiedDocument.png");
QVERIFY(image1.save(url.toLocalFile(), "png"));

View file

@ -57,19 +57,15 @@ class JobWatcher : public QObject
public:
JobWatcher(KJob* job)
: mJob(job)
, mDone(false)
, mError(0) {
job->setAutoDelete(false);
connect(job, SIGNAL(result(KJob*)),
SLOT(slotResult(KJob*)));
connect(job, SIGNAL(destroyed(QObject*)),
SLOT(slotDestroyed()));
}
void wait()
{
while (!mDone) {
QApplication::processEvents();
}
mJob->exec();
}
int error() const
@ -81,19 +77,11 @@ private Q_SLOTS:
void slotResult(KJob* job)
{
mError = job->error();
mDone = true;
}
void slotDestroyed()
{
kWarning() << "Destroyed";
mError = -1;
mDone = true;
job->deleteLater();
}
private:
KJob* mJob;
bool mDone;
int mError;
};
@ -121,7 +109,6 @@ private Q_SLOTS:
void testLosslessRotate();
void testModifyAndSaveAs();
void testMetaInfoJpeg();
void testMetaInfoBmp();
void testForgetModifiedDocument();
void testModifiedAndSavedSignals();
void testJobQueue();

View file

@ -51,7 +51,7 @@ void ImageScalerTest::testScaleFullImage()
scaler.setDestinationRegion(QRect(QPoint(0, 0), doc->size() * zoom));
bool ok = QTest::kWaitForSignal(&scaler, SIGNAL(scaledRect(int,int,QImage)), 30);
bool ok = QTest::kWaitForSignal(&scaler, SIGNAL(scaledRect(int,int,QImage)), 1000);
QVERIFY2(ok, "ImageScaler did not emit scaledRect() signal in time");
// Document should be fully loaded by the time image scaler is done

View file

@ -72,7 +72,7 @@ void ImporterTest::testContentsAreIdentical()
file.close();
data[data.size() / 2] = 255 - data[data.size() / 2];
file.open(QIODevice::WriteOnly);
QVERIFY(file.open(QIODevice::WriteOnly));
file.write(data);
file.close();

View file

@ -166,6 +166,7 @@ add_executable(ksystemlog ${ksystemlog_library_sources} ${ksystemlog_sources})
target_link_libraries(ksystemlog
${KDE4_KIO_LIBS}
${KDE4_KDEUI_LIBS}
${KDE4_KFILE_LIBS}
)
if(ENABLE_TESTING)

View file

@ -56,5 +56,6 @@ add_dependencies(
target_link_libraries(ksystemlog_lib
${KDE4_KDEUI_LIBS}
${KDE4_KIO_LIBS}
${KDE4_KFILE_LIBS}
ksystemlog_config
)

View file

@ -23,6 +23,7 @@ macro(ksystemlog_unit_tests)
${KDE4_KDEUI_LIBS}
${KDE4_KIO_LIBS}
${KDE4_KDECORE_LIBS}
${KDE4_KFILE_LIBS}
ksystemlog_library
)
endforeach(unitTest)