summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2014-12-15 17:40:41 +0100
committerMichal Klocek <michal.klocek@qt.io>2019-11-25 12:01:38 +0100
commit09ad4d74cea40dd3d88c0a39b1dcbc8db5347c6e (patch)
tree2fcbecba988dabb521c6fe2ff6feb7b497a77b32 /tests
parentaf10ffdc4cf31c29a15a83ed7dd9b7ed516585ea (diff)
Provide async loading through QNetworkReply
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/pdf/qpdfdocument/qpdfdocument.pro2
-rw-r--r--tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp44
2 files changed, 36 insertions, 10 deletions
diff --git a/tests/auto/pdf/qpdfdocument/qpdfdocument.pro b/tests/auto/pdf/qpdfdocument/qpdfdocument.pro
index 28e56e0bd..8382a25e3 100644
--- a/tests/auto/pdf/qpdfdocument/qpdfdocument.pro
+++ b/tests/auto/pdf/qpdfdocument/qpdfdocument.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qpdfdocument
-QT += pdf printsupport testlib
+QT += pdf printsupport testlib network
macx:CONFIG -= app_bundle
SOURCES += tst_qpdfdocument.cpp
diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp
index a51c17296..c0fe93cef 100644
--- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp
+++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp
@@ -5,6 +5,9 @@
#include <QPdfDocument>
#include <QPrinter>
#include <QTemporaryFile>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
class tst_QPdfDocument: public QObject
{
@@ -14,6 +17,7 @@ public:
private slots:
void pageCount();
void loadFromIODevice();
+ void loadAsync();
};
struct TemporaryPdf: public QTemporaryFile
@@ -28,17 +32,21 @@ TemporaryPdf::TemporaryPdf()
open();
pageLayout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF());
- QPrinter printer;
- printer.setOutputFormat(QPrinter::PdfFormat);
- printer.setOutputFileName(fileName());
- printer.setPageLayout(pageLayout);
-
{
- QPainter painter(&printer);
- painter.drawText(100, 100, QStringLiteral("Hello Page 1"));
- printer.newPage();
- painter.drawText(100, 100, QStringLiteral("Hello Page 2"));
+ QPrinter printer;
+ printer.setOutputFormat(QPrinter::PdfFormat);
+ printer.setOutputFileName(fileName());
+ printer.setPageLayout(pageLayout);
+
+ {
+ QPainter painter(&printer);
+ painter.drawText(100, 100, QStringLiteral("Hello Page 1"));
+ printer.newPage();
+ painter.drawText(100, 100, QStringLiteral("Hello Page 2"));
+ }
}
+
+ seek(0);
}
void tst_QPdfDocument::pageCount()
@@ -61,6 +69,24 @@ void tst_QPdfDocument::loadFromIODevice()
QCOMPARE(doc.pageCount(), 2);
}
+void tst_QPdfDocument::loadAsync()
+{
+ TemporaryPdf tempPdf;
+
+ QNetworkAccessManager nam;
+
+ QUrl url = QUrl::fromLocalFile(tempPdf.fileName());
+ QScopedPointer<QNetworkReply> reply(nam.get(QNetworkRequest(url)));
+
+ QPdfDocument doc;
+ QSignalSpy readySpy(&doc, SIGNAL(documentReady()));
+
+ doc.loadAsynchronously(reply.data());
+
+ QCOMPARE(readySpy.count(), 1);
+ QCOMPARE(doc.pageCount(), 2);
+}
+
QTEST_MAIN(tst_QPdfDocument)
#include "tst_qpdfdocument.moc"