diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-12-14 10:58:59 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-01-04 18:00:21 +0000 |
commit | 154cb38a7744c1cb46e9c2194c696724936beacd (patch) | |
tree | ab29e414073cb6a5c8aef197fbb3203b0e9f6b91 /tests | |
parent | 3d0b32c93c0d45bf61a77e76ef9ab54efd2b2eeb (diff) |
QtPdf: add a very rudimentary test for QPdfSelection
... as part of tst_QPdfDocument.
The smaller QtPdf classes should probably all have their own
tests. The existing tests are far from being sufficient.
Pick-to: 6.3
Change-Id: I01ff2b7abbdbe43ee596d682c256001539fde1bf
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp index 24c4e988d..a0f73bb88 100644 --- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp @@ -69,12 +69,23 @@ private slots: void status(); void passwordClearedOnClose(); void metaData(); + +private: + void consistencyCheck(QPdfDocument &doc) const; }; struct TemporaryPdf: public QTemporaryFile { TemporaryPdf(); QPageLayout pageLayout; + + static QString pageText(int page) { + switch (page) { + case 0: return QStringLiteral("Hello Page 1"); + case 1: return QStringLiteral("Hello Page 2"); + default: return {}; + } + } }; @@ -91,9 +102,9 @@ TemporaryPdf::TemporaryPdf() { QPainter painter(&printer); - painter.drawText(100, 100, QStringLiteral("Hello Page 1")); + painter.drawText(100, 100, pageText(0)); printer.newPage(); - painter.drawText(100, 100, QStringLiteral("Hello Page 2")); + painter.drawText(100, 100, pageText(1)); } } @@ -130,6 +141,19 @@ void tst_QPdfDocument::loadFromIODevice() QCOMPARE(doc.pageCount(), 2); QCOMPARE(pageCountChangedSpy.count(), 1); QCOMPARE(pageCountChangedSpy[0][0].toInt(), doc.pageCount()); + + consistencyCheck(doc); +} + +void tst_QPdfDocument::consistencyCheck(QPdfDocument &doc) const +{ + for (int i = 0; i < doc.pageCount(); ++i) { + const QString expected = TemporaryPdf::pageText(i); + QPdfSelection page = doc.getAllText(i); + QCOMPARE(page.text(), expected); + auto pageMoved = std::move(page); + QCOMPARE(pageMoved.text(), expected); + } } void tst_QPdfDocument::loadAsync() @@ -153,6 +177,8 @@ void tst_QPdfDocument::loadAsync() QCOMPARE(doc.pageCount(), 2); QCOMPARE(pageCountChangedSpy.count(), 1); QCOMPARE(pageCountChangedSpy[0][0].toInt(), doc.pageCount()); + + consistencyCheck(doc); } void tst_QPdfDocument::password() @@ -192,6 +218,10 @@ void tst_QPdfDocument::close() statusChangedSpy.clear(); pageCountChangedSpy.clear(); + consistencyCheck(doc); + if (QTest::currentTestFailed()) + return; + doc.close(); QCOMPARE(statusChangedSpy.count(), 2); QCOMPARE(statusChangedSpy[0][0].value<QPdfDocument::Status>(), QPdfDocument::Unloading); @@ -235,6 +265,8 @@ void tst_QPdfDocument::loadAfterClose() QCOMPARE(doc.pageCount(), 2); QCOMPARE(pageCountChangedSpy.count(), 1); QCOMPARE(pageCountChangedSpy[0][0].toInt(), doc.pageCount()); + + consistencyCheck(doc); } void tst_QPdfDocument::closeOnDestroy() |