1 | #include <QtTest/QTest> |
---|---|
2 | |
3 | #include "PDFDoc.h" |
4 | #include "GlobalParams.h" |
5 | |
6 | #include "Outline.h" |
7 | #include "poppler-private.h" |
8 | |
9 | class TestUtf8Document : public QObject |
10 | { |
11 | Q_OBJECT |
12 | public: |
13 | explicit TestUtf8Document(QObject *parent = nullptr) : QObject(parent) { } |
14 | private Q_SLOTS: |
15 | void checkStrings(); |
16 | }; |
17 | |
18 | inline QString outlineItemTitle(OutlineItem *item) |
19 | { |
20 | if (!item) { |
21 | return {}; |
22 | } |
23 | const std::vector<Unicode> &title = item->getTitle(); |
24 | return QString::fromUcs4(str: title.data(), size: title.size()); |
25 | } |
26 | |
27 | void TestUtf8Document::checkStrings() |
28 | { |
29 | |
30 | globalParams = std::make_unique<GlobalParams>(); |
31 | auto doc = std::make_unique<PDFDoc>(args: std::make_unique<GooString>(TESTDATADIR "/unittestcases/pdf20-utf8-test.pdf")); |
32 | QVERIFY(doc); |
33 | QVERIFY(doc->isOk()); |
34 | |
35 | QVERIFY(doc->getOptContentConfig() && doc->getOptContentConfig()->hasOCGs()); |
36 | |
37 | QCOMPARE(Poppler::UnicodeParsedString(doc->getDocInfoTitle().get()), QString::fromUtf8("表ポあA鷗ŒéB逍Üߪąñ丂㐀𠀀")); // clazy:exclude=qstring-allocations |
38 | |
39 | QSet<QString> expectedNames { QString::fromUtf8(utf8: "گچپژ"), QString::fromUtf8(utf8: "Layer 1") }; // clazy:exclude=qstring-allocations |
40 | QSet<QString> foundNames; |
41 | |
42 | for (auto &[ref, group] : doc->getOptContentConfig()->getOCGs()) { |
43 | foundNames.insert(value: Poppler::UnicodeParsedString(s1: group->getName())); |
44 | } |
45 | QCOMPARE(expectedNames, foundNames); |
46 | |
47 | auto outlineItems = doc->getOutline()->getItems(); |
48 | QVERIFY(outlineItems); |
49 | QCOMPARE(outlineItems->size(), 3); |
50 | |
51 | QCOMPARE(outlineItemTitle(outlineItems->at(0)), QString::fromUtf8("PDF 2.0 with UTF-8 test file")); // clazy:exclude=qstring-allocations |
52 | QCOMPARE(outlineItemTitle(outlineItems->at(1)), QString::fromUtf8("\u202A\u202Atest\u202A")); // clazy:exclude=qstring-allocations |
53 | QCOMPARE(outlineItemTitle(outlineItems->at(2)), QString::fromUtf8("🌈️\n"/*emoji rainbow flag*/)); // clazy:exclude=qstring-allocations |
54 | } |
55 | |
56 | QTEST_GUILESS_MAIN(TestUtf8Document) |
57 | |
58 | #include "check_utf8document.moc" |
59 |