summaryrefslogtreecommitdiffstats
path: root/tests/auto/pdf
diff options
context:
space:
mode:
authorTobias Koenig <tobias.koenig@kdab.com>2016-08-06 20:30:22 +0200
committerMichal Klocek <michal.klocek@qt.io>2019-11-25 12:01:39 +0100
commit40dc7d593ed95988130eaa8abde33e20fbfc50a3 (patch)
treea78b9c6124be61e0dcce4b317d5ef8835417df2d /tests/auto/pdf
parentec88c8ebbf050756cad20618361b5ae70a067466 (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/auto/pdf')
-rw-r--r--tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp b/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp
index 336c6e8d9..ef00bdbeb 100644
--- a/tests/auto/pdf/qpdfdocument/tst_qpdfdocument.cpp
+++ b/tests/auto/pdf/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"