diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2014-12-15 16:13:52 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2019-11-25 12:01:38 +0100 |
commit | edcffeb3e4c1a81ab86d997b8721dbb67a2ae9c4 (patch) | |
tree | 286a00df7f09dd77361619b2ae135be4bd5fff5d /tests/auto/pdf | |
parent | c03b6371db5c82cb19a5122a3159e46fab2d3a38 (diff) |
Allow loading documents synchronously from a QIODevice
Diffstat (limited to 'tests/auto/pdf')
-rw-r--r-- | tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index f91b407bb..a51c17296 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -13,37 +13,52 @@ public: private slots: void pageCount(); + void loadFromIODevice(); }; +struct TemporaryPdf: public QTemporaryFile +{ + TemporaryPdf(); + QPageLayout pageLayout; +}; -void tst_QPdfDocument::pageCount() + +TemporaryPdf::TemporaryPdf() { - QTemporaryFile tempPdf; - tempPdf.setAutoRemove(true); - QVERIFY(tempPdf.open()); + open(); + pageLayout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()); - QPageLayout layout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()); + QPrinter printer; + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(fileName()); + printer.setPageLayout(pageLayout); { - QPrinter printer; - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setOutputFileName(tempPdf.fileName()); - printer.setPageLayout(layout); - - { - QPainter painter(&printer); - painter.drawText(100, 100, QStringLiteral("Hello Page 1")); - printer.newPage(); - painter.drawText(100, 100, QStringLiteral("Hello Page 2")); - } + QPainter painter(&printer); + painter.drawText(100, 100, QStringLiteral("Hello Page 1")); + printer.newPage(); + painter.drawText(100, 100, QStringLiteral("Hello Page 2")); } +} + +void tst_QPdfDocument::pageCount() +{ + TemporaryPdf tempPdf; QPdfDocument doc; QCOMPARE(doc.pageCount(), 0); QCOMPARE(doc.load(tempPdf.fileName()), QPdfDocument::NoError); QCOMPARE(doc.pageCount(), 2); - QCOMPARE(doc.pageSize(0).toSize(), layout.fullRectPoints().size()); + QCOMPARE(doc.pageSize(0).toSize(), tempPdf.pageLayout.fullRectPoints().size()); +} + +void tst_QPdfDocument::loadFromIODevice() +{ + TemporaryPdf tempPdf; + QPdfDocument doc; + QCOMPARE(doc.load(&tempPdf), QPdfDocument::NoError); + QCOMPARE(doc.pageCount(), 2); } QTEST_MAIN(tst_QPdfDocument) |