1 #include <QtTest/QtTest>
2
3 #include <poppler-qt6.h>
4
5 class TestPassword : public QObject
6 {
7 Q_OBJECT
8 public:
TestPassword(QObject * parent=nullptr)9 explicit TestPassword(QObject *parent = nullptr) : QObject(parent) { }
10 private slots:
11 void password1();
12 void password1a();
13 void password2();
14 void password2a();
15 void password2b();
16 void password3();
17 void password4();
18 void password4b();
19 };
20
21 // BUG:4557
password1()22 void TestPassword::password1()
23 {
24 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - open.pdf"), "", QString::fromUtf8("garçon").toLatin1()); // clazy:exclude=qstring-allocations
25 QVERIFY(doc);
26 QVERIFY(!doc->isLocked());
27 }
28
password1a()29 void TestPassword::password1a()
30 {
31 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - open.pdf")); // clazy:exclude=qstring-allocations
32 QVERIFY(doc);
33 QVERIFY(doc->isLocked());
34 QVERIFY(!doc->unlock("", QString::fromUtf8("garçon").toLatin1())); // clazy:exclude=qstring-allocations
35 QVERIFY(!doc->isLocked());
36 }
37
password2()38 void TestPassword::password2()
39 {
40 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"), QString::fromUtf8("garçon").toLatin1(), ""); // clazy:exclude=qstring-allocations
41 QVERIFY(doc);
42 QVERIFY(!doc->isLocked());
43 }
44
password2a()45 void TestPassword::password2a()
46 {
47 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"), QString::fromUtf8("garçon").toLatin1()); // clazy:exclude=qstring-allocations
48 QVERIFY(doc);
49 QVERIFY(!doc->isLocked());
50 }
51
password2b()52 void TestPassword::password2b()
53 {
54 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"));
55 QVERIFY(doc);
56 QVERIFY(!doc->isLocked());
57 QVERIFY(!doc->unlock(QString::fromUtf8("garçon").toLatin1(), "")); // clazy:exclude=qstring-allocations
58 QVERIFY(!doc->isLocked());
59 }
60
password3()61 void TestPassword::password3()
62 {
63 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/PasswordEncrypted.pdf"));
64 QVERIFY(doc);
65 QVERIFY(doc->isLocked());
66 QVERIFY(!doc->unlock("", "password"));
67 QVERIFY(!doc->isLocked());
68 }
69
70 // issue 690
password4()71 void TestPassword::password4()
72 {
73 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/encrypted-256.pdf"));
74 QVERIFY(doc);
75 QVERIFY(doc->isLocked());
76 QVERIFY(!doc->unlock("owner-secret", ""));
77 QVERIFY(!doc->isLocked());
78 }
79
80 // issue 690
password4b()81 void TestPassword::password4b()
82 {
83 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/encrypted-256.pdf"));
84 QVERIFY(doc);
85 QVERIFY(doc->isLocked());
86 QVERIFY(!doc->unlock("", "user-secret"));
87 QVERIFY(!doc->isLocked());
88 }
89
90 QTEST_GUILESS_MAIN(TestPassword)
91 #include "check_password.moc"
92