blob: 080f8085ba1fcf20e35c2b1c2c5a6ebe27e5fdd4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include <QtTest/QtTest>
#include <QPainter>
#include <QPdfDocument>
#include <QPrinter>
#include <QTemporaryFile>
class tst_QPdfDocument: public QObject
{
Q_OBJECT
public:
private slots:
void pageCount();
};
void tst_QPdfDocument::pageCount()
{
QTemporaryFile tempPdf;
tempPdf.setAutoRemove(true);
QVERIFY(tempPdf.open());
{
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(tempPdf.fileName());
{
QPainter painter(&printer);
painter.drawText(0, 0, QStringLiteral("Hello Page 1"));
printer.newPage();
painter.drawText(0, 0, QStringLiteral("Hello Page 2"));
}
}
QPdfDocument doc;
QCOMPARE(doc.pageCount(), 0);
QCOMPARE(doc.load(tempPdf.fileName()), QPdfDocument::NoError);
QCOMPARE(doc.pageCount(), 2);
}
QTEST_MAIN(tst_QPdfDocument)
#include "tst_qpdfdocument.moc"
|