diff options
author | Tobias Koenig <tobias.koenig@kdab.com> | 2016-08-06 20:30:22 +0200 |
---|---|---|
committer | Tobias Koenig <tobias.koenig@kdab.com> | 2016-08-08 07:10:23 +0000 |
commit | 322ab60499477ce0860f3a9b697e9b696da9570e (patch) | |
tree | 909624573cff135bcc6f7425b5a2dd9258cc2446 /tests | |
parent | cab3f0279696c5213a33f7875a40dc6d68709d82 (diff) |
Add close() method to QPdfDocument
The close() method will close an open document and emit
the aboutToBeClosed() signal, so that other component, which
keep a pointer to QPdfDocument, can react to it.
Change-Id: I93200eb0b4bf96479fc114b43c9f6f2af4d15ffa
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qpdfdocument/tst_qpdfdocument.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/qpdfdocument/tst_qpdfdocument.cpp index 336c6e8..ef00bdb 100644 --- a/tests/auto/qpdfdocument/tst_qpdfdocument.cpp +++ b/tests/auto/qpdfdocument/tst_qpdfdocument.cpp @@ -19,6 +19,9 @@ private slots: void loadFromIODevice(); void loadAsync(); void password(); + void close(); + void loadAfterClose(); + void closeOnDestroy(); }; struct TemporaryPdf: public QTemporaryFile @@ -107,6 +110,71 @@ void tst_QPdfDocument::password() QCOMPARE(doc.pageCount(), 1); } +void tst_QPdfDocument::close() +{ + TemporaryPdf tempPdf; + QPdfDocument doc; + + QSignalSpy aboutToBeClosedSpy(&doc, SIGNAL(aboutToBeClosed())); + + doc.load(&tempPdf); + QCOMPARE(aboutToBeClosedSpy.count(), 0); + doc.close(); + QCOMPARE(aboutToBeClosedSpy.count(), 1); + QCOMPARE(doc.pageCount(), 0); +} + +void tst_QPdfDocument::loadAfterClose() +{ + TemporaryPdf tempPdf; + QPdfDocument doc; + + QSignalSpy aboutToBeClosedSpy(&doc, SIGNAL(aboutToBeClosed())); + + doc.load(&tempPdf); + QCOMPARE(aboutToBeClosedSpy.count(), 0); + doc.close(); + QCOMPARE(aboutToBeClosedSpy.count(), 1); + + QSignalSpy startedSpy(&doc, SIGNAL(documentLoadStarted())); + QSignalSpy finishedSpy(&doc, SIGNAL(documentLoadFinished())); + doc.load(&tempPdf); + QCOMPARE(startedSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(doc.error(), QPdfDocument::NoError); + QCOMPARE(doc.pageCount(), 2); +} + +void tst_QPdfDocument::closeOnDestroy() +{ + TemporaryPdf tempPdf; + + // deleting an open document should automatically close it + { + QPdfDocument *doc = new QPdfDocument; + + QSignalSpy aboutToBeClosedSpy(doc, SIGNAL(aboutToBeClosed())); + doc->load(&tempPdf); + + delete doc; + + QCOMPARE(aboutToBeClosedSpy.count(), 1); + } + + // deleting a closed document should not emit any signal + { + QPdfDocument *doc = new QPdfDocument; + doc->load(&tempPdf); + doc->close(); + + QSignalSpy aboutToBeClosedSpy(doc, SIGNAL(aboutToBeClosed())); + + delete doc; + + QCOMPARE(aboutToBeClosedSpy.count(), 0); + } +} + QTEST_MAIN(tst_QPdfDocument) #include "tst_qpdfdocument.moc" |