Commit 0b6dd107 authored by Laurent Montel's avatar Laurent Montel 😁

Add more autotests + remove duplicate code

parent 70241704
......@@ -19,6 +19,7 @@
#include "../printwebengineviewjob.h"
#include <QTest>
#include <QPageLayout>
#include <QSignalSpy>
PrintWebEngineViewJobTest::PrintWebEngineViewJobTest(QObject *parent)
: QObject(parent)
......@@ -38,4 +39,14 @@ void PrintWebEngineViewJobTest::shouldHaveDefaultValue()
QVERIFY(!job.pageLayout().isValid());
}
void PrintWebEngineViewJobTest::shouldFailedWhenWebEngineIsNotDefined()
{
WebEngineViewer::PrintWebEngineViewJob job;
QSignalSpy spyFailed(&job, SIGNAL(failed()));
QSignalSpy spySuccess(&job, SIGNAL(success(QString)));
job.start();
QCOMPARE(spyFailed.count(), 1);
QCOMPARE(spySuccess.count(), 0);
}
QTEST_MAIN(PrintWebEngineViewJobTest)
......@@ -28,6 +28,7 @@ public:
~PrintWebEngineViewJobTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldFailedWhenWebEngineIsNotDefined();
};
#endif // PRINTWEBENGINEVIEWJOBTEST_H
......@@ -49,26 +49,31 @@ PrintWebEngineViewJob::~PrintWebEngineViewJob()
}
void PrintWebEngineViewJob::unableToPrint()
{
Q_EMIT failed();
deleteLater();
}
void PrintWebEngineViewJob::start()
{
if (mEngineView) {
if (!mTemporaryFile.open()) {
Q_EMIT failed();
deleteLater();
unableToPrint();
} else {
if (mPageLayout.isValid()) {
mTemporaryFile.setAutoRemove(false);
#if QT_VERSION >= 0x050700
mEngineView->page()->printToPdf(invoke(this, &PrintWebEngineViewJob::slotHandlePdfPrinted), mPageLayout);
#else
unableToPrint();
#endif
} else {
Q_EMIT failed();
deleteLater();
unableToPrint();
}
}
} else {
Q_EMIT failed();
deleteLater();
unableToPrint();
}
}
......@@ -80,8 +85,7 @@ void PrintWebEngineViewJob::slotHandlePdfPrinted(const QByteArray &result)
QFile file(mTemporaryFile.fileName());
if (!file.open(QFile::WriteOnly)) {
//TODO warning.
Q_EMIT failed();
deleteLater();
unableToPrint();
return;
}
......
......@@ -50,6 +50,7 @@ private Q_SLOTS:
void slotHandlePdfPrinted(const QByteArray &result);
private:
void unableToPrint();
QPageLayout mPageLayout;
QTemporaryFile mTemporaryFile;
QWebEngineView *mEngineView;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment