1#include <QtTest/QTest>
2
3#include <poppler-qt6.h>
4
5#include <QtCore/QFile>
6
7class TestAttachments : public QObject
8{
9 Q_OBJECT
10public:
11 explicit TestAttachments(QObject *parent = nullptr) : QObject(parent) { }
12private slots:
13 void checkNoAttachments();
14 void checkAttach1();
15 void checkAttach2();
16 void checkAttach3();
17 void checkAttach4();
18};
19
20void TestAttachments::checkNoAttachments()
21{
22 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/truetype.pdf");
23 QVERIFY(doc);
24
25 QCOMPARE(doc->hasEmbeddedFiles(), false);
26}
27
28void TestAttachments::checkAttach1()
29{
30 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/WithAttachments.pdf");
31 QVERIFY(doc);
32
33 QVERIFY(doc->hasEmbeddedFiles());
34
35 QList<Poppler::EmbeddedFile *> fileList = doc->embeddedFiles();
36 QCOMPARE(fileList.size(), 2);
37
38 Poppler::EmbeddedFile *embfile = fileList.at(i: 0);
39 QCOMPARE(embfile->name(), QLatin1String("kroller.png"));
40 QCOMPARE(embfile->description(), QString());
41 QCOMPARE(embfile->createDate(), QDateTime(QDate(), QTime()));
42 QCOMPARE(embfile->modDate(), QDateTime(QDate(), QTime()));
43 QCOMPARE(embfile->mimeType(), QString());
44
45 QFile file(TESTDATADIR "/unittestcases/kroller.png");
46 QVERIFY(file.open(QIODevice::ReadOnly));
47 QByteArray krollerData = file.readAll();
48 QByteArray embdata = embfile->data();
49 QCOMPARE(krollerData, embdata);
50
51 Poppler::EmbeddedFile *embfile2 = fileList.at(i: 1);
52 QCOMPARE(embfile2->name(), QLatin1String("gnome-64.gif"));
53 QCOMPARE(embfile2->description(), QString());
54 QCOMPARE(embfile2->modDate(), QDateTime(QDate(), QTime()));
55 QCOMPARE(embfile2->createDate(), QDateTime(QDate(), QTime()));
56 QCOMPARE(embfile2->mimeType(), QString());
57
58 QFile file2(TESTDATADIR "/unittestcases/gnome-64.gif");
59 QVERIFY(file2.open(QIODevice::ReadOnly));
60 QByteArray g64Data = file2.readAll();
61 QByteArray emb2data = embfile2->data();
62 QCOMPARE(g64Data, emb2data);
63}
64
65void TestAttachments::checkAttach2()
66{
67 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/A6EmbeddedFiles.pdf");
68 QVERIFY(doc);
69
70 QVERIFY(doc->hasEmbeddedFiles());
71
72 QList<Poppler::EmbeddedFile *> fileList;
73 fileList = doc->embeddedFiles();
74 QCOMPARE(fileList.size(), 3);
75
76 Poppler::EmbeddedFile *embfile1 = fileList.at(i: 0);
77 QCOMPARE(embfile1->name(), QLatin1String("Acro7 thoughts"));
78 QCOMPARE(embfile1->description(), QString());
79 QCOMPARE(embfile1->createDate(), QDateTime(QDate(2003, 8, 4), QTime(13, 54, 54), Qt::UTC));
80 QCOMPARE(embfile1->modDate(), QDateTime(QDate(2003, 8, 4), QTime(14, 15, 27), Qt::UTC));
81 QCOMPARE(embfile1->mimeType(), QLatin1String("text/xml"));
82
83 Poppler::EmbeddedFile *embfile2 = fileList.at(i: 1);
84 QCOMPARE(embfile2->name(), QLatin1String("acro transitions 1.xls"));
85 QCOMPARE(embfile2->description(), QString());
86 QCOMPARE(embfile2->createDate(), QDateTime(QDate(2003, 7, 18), QTime(21, 7, 16), Qt::UTC));
87 QCOMPARE(embfile2->modDate(), QDateTime(QDate(2003, 7, 22), QTime(13, 4, 40), Qt::UTC));
88 QCOMPARE(embfile2->mimeType(), QLatin1String("application/excel"));
89
90 Poppler::EmbeddedFile *embfile3 = fileList.at(i: 2);
91 QCOMPARE(embfile3->name(), QLatin1String("apago_pdfe_wide.gif"));
92 QCOMPARE(embfile3->description(), QString());
93 QCOMPARE(embfile3->createDate(), QDateTime(QDate(2003, 1, 31), QTime(15, 54, 29), Qt::UTC));
94 QCOMPARE(embfile3->modDate(), QDateTime(QDate(2003, 1, 31), QTime(15, 52, 58), Qt::UTC));
95 QCOMPARE(embfile3->mimeType(), QString());
96}
97
98void TestAttachments::checkAttach3()
99{
100 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/shapes+attachments.pdf");
101 QVERIFY(doc);
102
103 QVERIFY(doc->hasEmbeddedFiles());
104
105 QList<Poppler::EmbeddedFile *> fileList;
106 fileList = doc->embeddedFiles();
107 QCOMPARE(fileList.size(), 1);
108
109 Poppler::EmbeddedFile *embfile = fileList.at(i: 0);
110 QCOMPARE(embfile->name(), QLatin1String("ADEX1.xpdf.pgp"));
111 QCOMPARE(embfile->description(), QString());
112 QCOMPARE(embfile->createDate(), QDateTime(QDate(2004, 3, 29), QTime(19, 37, 16), Qt::UTC));
113 QCOMPARE(embfile->modDate(), QDateTime(QDate(2004, 3, 29), QTime(19, 37, 16), Qt::UTC));
114 QCOMPARE(embfile->mimeType(), QString());
115}
116
117void TestAttachments::checkAttach4()
118{
119 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/imageretrieve+attachment.pdf");
120 QVERIFY(doc);
121
122 QVERIFY(doc->hasEmbeddedFiles());
123
124 QList<Poppler::EmbeddedFile *> fileList;
125 fileList = doc->embeddedFiles();
126 QCOMPARE(fileList.size(), 1);
127
128 Poppler::EmbeddedFile *embfile = fileList.at(i: 0);
129 QCOMPARE(embfile->name(), QLatin1String("export-altona.csv"));
130 QCOMPARE(embfile->description(), QLatin1String("Altona Export"));
131 QCOMPARE(embfile->createDate(), QDateTime(QDate(2005, 8, 30), QTime(20, 49, 35), Qt::UTC));
132 QCOMPARE(embfile->modDate(), QDateTime(QDate(2005, 8, 30), QTime(20, 49, 52), Qt::UTC));
133 QCOMPARE(embfile->mimeType(), QLatin1String("application/vnd.ms-excel"));
134}
135
136QTEST_GUILESS_MAIN(TestAttachments)
137#include "check_attachments.moc"
138

source code of poppler/qt6/tests/check_attachments.cpp