1 #include <QtTest/QtTest>
2 
3 #include <poppler-qt5.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     Poppler::Document *doc;
25     doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - open.pdf"), "", QString::fromUtf8("garçon").toLatin1()); // clazy:exclude=qstring-allocations
26     QVERIFY(doc);
27     QVERIFY(!doc->isLocked());
28 
29     delete doc;
30 }
31 
password1a()32 void TestPassword::password1a()
33 {
34     Poppler::Document *doc;
35     doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - open.pdf")); // clazy:exclude=qstring-allocations
36     QVERIFY(doc);
37     QVERIFY(doc->isLocked());
38     QVERIFY(!doc->unlock("", QString::fromUtf8("garçon").toLatin1())); // clazy:exclude=qstring-allocations
39     QVERIFY(!doc->isLocked());
40 
41     delete doc;
42 }
43 
password2()44 void TestPassword::password2()
45 {
46     Poppler::Document *doc;
47     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     delete doc;
52 }
53 
password2a()54 void TestPassword::password2a()
55 {
56     Poppler::Document *doc;
57     doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"), QString::fromUtf8("garçon").toLatin1()); // clazy:exclude=qstring-allocations
58     QVERIFY(doc);
59     QVERIFY(!doc->isLocked());
60 
61     delete doc;
62 }
63 
password2b()64 void TestPassword::password2b()
65 {
66     Poppler::Document *doc;
67     doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"));
68     QVERIFY(doc);
69     QVERIFY(!doc->isLocked());
70     QVERIFY(!doc->unlock(QString::fromUtf8("garçon").toLatin1(), "")); // clazy:exclude=qstring-allocations
71     QVERIFY(!doc->isLocked());
72 
73     delete doc;
74 }
75 
password3()76 void TestPassword::password3()
77 {
78     Poppler::Document *doc;
79     doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/PasswordEncrypted.pdf"));
80     QVERIFY(doc);
81     QVERIFY(doc->isLocked());
82     QVERIFY(!doc->unlock("", "password"));
83     QVERIFY(!doc->isLocked());
84 
85     delete doc;
86 }
87 
88 // issue 690
password4()89 void TestPassword::password4()
90 {
91     Poppler::Document *doc;
92     doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/encrypted-256.pdf"));
93     QVERIFY(doc);
94     QVERIFY(doc->isLocked());
95     QVERIFY(!doc->unlock("owner-secret", ""));
96     QVERIFY(!doc->isLocked());
97 
98     delete doc;
99 }
100 
101 // issue 690
password4b()102 void TestPassword::password4b()
103 {
104     Poppler::Document *doc;
105     doc = Poppler::Document::load(QString::fromUtf8(TESTDATADIR "/unittestcases/encrypted-256.pdf"));
106     QVERIFY(doc);
107     QVERIFY(doc->isLocked());
108     QVERIFY(!doc->unlock("", "user-secret"));
109     QVERIFY(!doc->isLocked());
110 
111     delete doc;
112 }
113 
114 QTEST_GUILESS_MAIN(TestPassword)
115 #include "check_password.moc"
116