1 #include <QtTest/QtTest>
2 
3 #include <poppler-qt5.h>
4 
5 // clazy:excludeall=qstring-allocations
6 
7 class TestSearch : public QObject
8 {
9     Q_OBJECT
10 public:
TestSearch(QObject * parent=nullptr)11     explicit TestSearch(QObject *parent = nullptr) : QObject(parent) { }
12 private slots:
13     void testAcrossLinesSearch(); // leave it first
14     void bug7063();
15     void testNextAndPrevious();
16     void testWholeWordsOnly();
17     void testIgnoreDiacritics();
18     void testRussianSearch(); // Issue #743
19     void testDeseretSearch(); // Issue #853
20 };
21 
bug7063()22 void TestSearch::bug7063()
23 {
24     QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/bug7063.pdf"));
25     QVERIFY(document);
26 
27     QScopedPointer<Poppler::Page> page(document->page(0));
28     QVERIFY(page);
29 
30     double rectLeft = 0.0, rectTop = 0.0, rectRight = page->pageSizeF().width(), rectBottom = page->pageSizeF().height();
31 
32     QCOMPARE(page->search(QStringLiteral(u"non-ascii:"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
33 
34     QCOMPARE(page->search(QStringLiteral(u"Ascii"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false);
35     QCOMPARE(page->search(QStringLiteral(u"Ascii"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::IgnoreCase), true);
36 
37     QCOMPARE(page->search(QStringLiteral(u"latin1:"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false);
38 
39     QCOMPARE(page->search(QString::fromUtf8("é"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
40     QCOMPARE(page->search(QString::fromUtf8("à"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
41     QCOMPARE(page->search(QString::fromUtf8("ç"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
42     QCOMPARE(page->search(QString::fromUtf8("search \"é\", \"à\" or \"ç\""), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
43     QCOMPARE(page->search(QString::fromUtf8("¥µ©"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
44     QCOMPARE(page->search(QString::fromUtf8("¥©"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false);
45 
46     QCOMPARE(page->search(QStringLiteral(u"non-ascii:"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
47 
48     QCOMPARE(page->search(QStringLiteral(u"Ascii"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false);
49     QCOMPARE(page->search(QStringLiteral(u"Ascii"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop, Poppler::Page::IgnoreCase), true);
50 
51     QCOMPARE(page->search(QStringLiteral(u"latin1:"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false);
52 
53     QCOMPARE(page->search(QString::fromUtf8("é"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
54     QCOMPARE(page->search(QString::fromUtf8("à"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
55     QCOMPARE(page->search(QString::fromUtf8("ç"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
56     QCOMPARE(page->search(QString::fromUtf8("search \"é\", \"à\" or \"ç\""), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
57     QCOMPARE(page->search(QString::fromUtf8("¥µ©"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
58     QCOMPARE(page->search(QString::fromUtf8("¥©"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), false);
59 }
60 
testNextAndPrevious()61 void TestSearch::testNextAndPrevious()
62 {
63     QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/xr01.pdf"));
64     QVERIFY(document);
65 
66     QScopedPointer<Poppler::Page> page(document->page(0));
67     QVERIFY(page);
68 
69     double rectLeft = 0.0, rectTop = 0.0, rectRight = page->pageSizeF().width(), rectBottom = page->pageSizeF().height();
70 
71     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
72     QVERIFY(qAbs(rectLeft - 161.44) < 0.01);
73     QVERIFY(qAbs(rectTop - 127.85) < 0.01);
74     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
75     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
76     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true);
77     QVERIFY(qAbs(rectLeft - 171.46) < 0.01);
78     QVERIFY(qAbs(rectTop - 127.85) < 0.01);
79     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
80     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
81     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true);
82     QVERIFY(qAbs(rectLeft - 161.44) < 0.01);
83     QVERIFY(qAbs(rectTop - 139.81) < 0.01);
84     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
85     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
86     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true);
87     QVERIFY(qAbs(rectLeft - 171.46) < 0.01);
88     QVERIFY(qAbs(rectTop - 139.81) < 0.01);
89     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
90     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
91     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), false);
92     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true);
93     QVERIFY(qAbs(rectLeft - 161.44) < 0.01);
94     QVERIFY(qAbs(rectTop - 139.81) < 0.01);
95     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
96     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
97     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true);
98     QVERIFY(qAbs(rectLeft - 171.46) < 0.01);
99     QVERIFY(qAbs(rectTop - 127.85) < 0.01);
100     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
101     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
102     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true);
103     QVERIFY(qAbs(rectLeft - 161.44) < 0.01);
104     QVERIFY(qAbs(rectTop - 127.85) < 0.01);
105     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
106     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
107     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), false);
108 
109     rectLeft = 0.0, rectTop = 0.0, rectRight = page->pageSizeF().width(), rectBottom = page->pageSizeF().height();
110 
111     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::FromTop), true);
112     QVERIFY(qAbs(rectLeft - 161.44) < 0.01);
113     QVERIFY(qAbs(rectTop - 127.85) < 0.01);
114     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
115     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
116     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true);
117     QVERIFY(qAbs(rectLeft - 171.46) < 0.01);
118     QVERIFY(qAbs(rectTop - 127.85) < 0.01);
119     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
120     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
121     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true);
122     QVERIFY(qAbs(rectLeft - 161.44) < 0.01);
123     QVERIFY(qAbs(rectTop - 139.81) < 0.01);
124     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
125     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
126     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), true);
127     QVERIFY(qAbs(rectLeft - 171.46) < 0.01);
128     QVERIFY(qAbs(rectTop - 139.81) < 0.01);
129     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
130     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
131     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::NextResult), false);
132     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true);
133     QVERIFY(qAbs(rectLeft - 161.44) < 0.01);
134     QVERIFY(qAbs(rectTop - 139.81) < 0.01);
135     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
136     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
137     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true);
138     QVERIFY(qAbs(rectLeft - 171.46) < 0.01);
139     QVERIFY(qAbs(rectTop - 127.85) < 0.01);
140     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
141     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
142     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), true);
143     QVERIFY(qAbs(rectLeft - 161.44) < 0.01);
144     QVERIFY(qAbs(rectTop - 127.85) < 0.01);
145     QVERIFY(qAbs(rectRight - rectLeft - 6.70) < 0.01);
146     QVERIFY(qAbs(rectBottom - rectTop - 8.85) < 0.01);
147     QCOMPARE(page->search(QStringLiteral(u"is"), rectLeft, rectTop, rectRight, rectBottom, Poppler::Page::PreviousResult), false);
148 }
149 
testWholeWordsOnly()150 void TestSearch::testWholeWordsOnly()
151 {
152     QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/WithActualText.pdf"));
153     QVERIFY(document);
154 
155     QScopedPointer<Poppler::Page> page(document->page(0));
156     QVERIFY(page);
157 
158     const Poppler::Page::SearchDirection direction = Poppler::Page::FromTop;
159 
160     const Poppler::Page::SearchFlags mode0 = nullptr;
161     const Poppler::Page::SearchFlags mode1 = Poppler::Page::IgnoreCase;
162     const Poppler::Page::SearchFlags mode2 = Poppler::Page::WholeWords;
163     const Poppler::Page::SearchFlags mode3 = Poppler::Page::IgnoreCase | Poppler::Page::WholeWords;
164 
165     double left, top, right, bottom;
166 
167     QCOMPARE(page->search(QStringLiteral(u"brown"), left, top, right, bottom, direction, mode0), true);
168     QCOMPARE(page->search(QStringLiteral(u"brOwn"), left, top, right, bottom, direction, mode0), false);
169 
170     QCOMPARE(page->search(QStringLiteral(u"brOwn"), left, top, right, bottom, direction, mode1), true);
171     QCOMPARE(page->search(QStringLiteral(u"brawn"), left, top, right, bottom, direction, mode1), false);
172 
173     QCOMPARE(page->search(QStringLiteral(u"brown"), left, top, right, bottom, direction, mode2), true);
174     QCOMPARE(page->search(QStringLiteral(u"own"), left, top, right, bottom, direction, mode2), false);
175 
176     QCOMPARE(page->search(QStringLiteral(u"brOwn"), left, top, right, bottom, direction, mode3), true);
177     QCOMPARE(page->search(QStringLiteral(u"Own"), left, top, right, bottom, direction, mode3), false);
178 }
179 
testIgnoreDiacritics()180 void TestSearch::testIgnoreDiacritics()
181 {
182     QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/Issue637.pdf"));
183     QVERIFY(document);
184 
185     QScopedPointer<Poppler::Page> page(document->page(0));
186     QVERIFY(page);
187 
188     const Poppler::Page::SearchDirection direction = Poppler::Page::FromTop;
189 
190     const Poppler::Page::SearchFlags mode0 = nullptr;
191     const Poppler::Page::SearchFlags mode1 = Poppler::Page::IgnoreDiacritics;
192     const Poppler::Page::SearchFlags mode2 = Poppler::Page::IgnoreDiacritics | Poppler::Page::IgnoreCase;
193     const Poppler::Page::SearchFlags mode3 = Poppler::Page::IgnoreDiacritics | Poppler::Page::IgnoreCase | Poppler::Page::WholeWords;
194     const Poppler::Page::SearchFlags mode4 = Poppler::Page::IgnoreCase | Poppler::Page::WholeWords;
195 
196     double left, top, right, bottom;
197 
198     // Test pdf (Issue637.pdf) just contains the following three lines:
199     // La cigüeña voló sobre nuestras cabezas.
200     // La cigogne a survolé nos têtes.
201     // Der Storch flog über unsere Köpfe hinweg.
202 
203     QCOMPARE(page->search(QString(), left, top, right, bottom, direction, mode0), false);
204     QCOMPARE(page->search(QStringLiteral("ciguena"), left, top, right, bottom, direction, mode0), false);
205     QCOMPARE(page->search(QStringLiteral("Ciguena"), left, top, right, bottom, direction, mode1), false);
206     QCOMPARE(page->search(QStringLiteral("ciguena"), left, top, right, bottom, direction, mode1), true);
207     QCOMPARE(page->search(QString::fromUtf8("cigüeña"), left, top, right, bottom, direction, mode1), true);
208     QCOMPARE(page->search(QString::fromUtf8("cigüena"), left, top, right, bottom, direction, mode1), false);
209     QCOMPARE(page->search(QString::fromUtf8("Cigüeña"), left, top, right, bottom, direction, mode1), false);
210     QCOMPARE(page->search(QStringLiteral("Ciguena"), left, top, right, bottom, direction, mode2), true);
211     QCOMPARE(page->search(QStringLiteral("ciguena"), left, top, right, bottom, direction, mode2), true);
212     QCOMPARE(page->search(QStringLiteral("Ciguena"), left, top, right, bottom, direction, mode3), true);
213     QCOMPARE(page->search(QStringLiteral("ciguena"), left, top, right, bottom, direction, mode3), true);
214 
215     QCOMPARE(page->search(QString::fromUtf8("cigüeña"), left, top, right, bottom, direction, mode4), true);
216     QCOMPARE(page->search(QString::fromUtf8("Cigüeña"), left, top, right, bottom, direction, mode4), true);
217     QCOMPARE(page->search(QString::fromUtf8("cigüena"), left, top, right, bottom, direction, mode4), false);
218     QCOMPARE(page->search(QStringLiteral("Ciguena"), left, top, right, bottom, direction, mode4), false);
219 
220     QCOMPARE(page->search(QStringLiteral("kopfe"), left, top, right, bottom, direction, mode2), true);
221     QCOMPARE(page->search(QStringLiteral("kopfe"), left, top, right, bottom, direction, mode3), true);
222     QCOMPARE(page->search(QStringLiteral("uber"), left, top, right, bottom, direction, mode0), false);
223     QCOMPARE(page->search(QStringLiteral("uber"), left, top, right, bottom, direction, mode1), true);
224     QCOMPARE(page->search(QStringLiteral("uber"), left, top, right, bottom, direction, mode2), true);
225     QCOMPARE(page->search(QStringLiteral("uber"), left, top, right, bottom, direction, mode3), true);
226 
227     QCOMPARE(page->search(QStringLiteral("vole"), left, top, right, bottom, direction, mode2), true);
228     QCOMPARE(page->search(QStringLiteral("vole"), left, top, right, bottom, direction, mode3), false);
229     QCOMPARE(page->search(QStringLiteral("survole"), left, top, right, bottom, direction, mode3), true);
230     QCOMPARE(page->search(QStringLiteral("tete"), left, top, right, bottom, direction, mode3), false);
231     QCOMPARE(page->search(QStringLiteral("tete"), left, top, right, bottom, direction, mode2), true);
232 
233     QCOMPARE(page->search(QStringLiteral("La Ciguena Volo"), left, top, right, bottom, direction, mode2), true);
234     QCOMPARE(page->search(QStringLiteral("Survole Nos Tetes"), left, top, right, bottom, direction, mode2), true);
235     QCOMPARE(page->search(QStringLiteral("Uber Unsere Kopfe"), left, top, right, bottom, direction, mode2), true);
236 }
237 
testRussianSearch()238 void TestSearch::testRussianSearch()
239 {
240     // Test for issue #743
241     QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/russian.pdf"));
242     QVERIFY(document);
243 
244     QScopedPointer<Poppler::Page> page(document->page(0));
245     QVERIFY(page);
246 
247     const Poppler::Page::SearchDirection direction = Poppler::Page::FromTop;
248 
249     const Poppler::Page::SearchFlags mode0 = Poppler::Page::NoSearchFlags;
250     const Poppler::Page::SearchFlags mode1 = Poppler::Page::IgnoreDiacritics;
251     const Poppler::Page::SearchFlags mode2 = Poppler::Page::IgnoreDiacritics | Poppler::Page::IgnoreCase;
252     const Poppler::Page::SearchFlags mode0W = mode0 | Poppler::Page::WholeWords;
253     const Poppler::Page::SearchFlags mode1W = mode1 | Poppler::Page::WholeWords;
254     const Poppler::Page::SearchFlags mode2W = mode2 | Poppler::Page::WholeWords;
255 
256     double l, t, r, b; // left, top, right, bottom
257 
258     // In the searched page 5, these two words do exist: простой and Простой
259     const QString str = QString::fromUtf8("простой");
260     QCOMPARE(page->search(str, l, t, r, b, direction, mode0), true);
261     QCOMPARE(page->search(str, l, t, r, b, direction, mode1), true);
262     QCOMPARE(page->search(str, l, t, r, b, direction, mode2), true);
263     QCOMPARE(page->search(str, l, t, r, b, direction, mode0W), true);
264     QCOMPARE(page->search(str, l, t, r, b, direction, mode1W), true);
265     QCOMPARE(page->search(str, l, t, r, b, direction, mode2W), true);
266 }
267 
testDeseretSearch()268 void TestSearch::testDeseretSearch()
269 {
270     QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/deseret.pdf"));
271     QVERIFY(document);
272 
273     QScopedPointer<Poppler::Page> page(document->page(0));
274     QVERIFY(page);
275 
276     double l, t, r, b; // left, top, right, bottom
277 
278     const QString str = QString::fromUtf8("��������");
279     QCOMPARE(page->search(str, l, t, r, b, Poppler::Page::FromTop, Poppler::Page::NoSearchFlags), true);
280 
281     const QString str2 = QString::fromUtf8("��������");
282     QCOMPARE(page->search(str2, l, t, r, b, Poppler::Page::FromTop, Poppler::Page::IgnoreCase), true);
283 }
284 
testAcrossLinesSearch()285 void TestSearch::testAcrossLinesSearch()
286 {
287     // Test for searching across lines with new flag Poppler::Page::AcrossLines
288     // and its automatic features like ignoring hyphen at end of line or allowing
289     // whitespace in the search term to match on newline character.
290     QScopedPointer<Poppler::Document> document(Poppler::Document::load(TESTDATADIR "/unittestcases/searchAcrossLines.pdf"));
291     QVERIFY(document);
292 
293     QScopedPointer<Poppler::Page> page(document->page(1));
294     QVERIFY(page);
295 
296     const Poppler::Page::SearchDirection direction = Poppler::Page::FromTop;
297 
298     const Poppler::Page::SearchFlags empty = Poppler::Page::NoSearchFlags;
299     const Poppler::Page::SearchFlags mode0 = Poppler::Page::AcrossLines;
300     const Poppler::Page::SearchFlags mode1 = Poppler::Page::AcrossLines | Poppler::Page::IgnoreDiacritics;
301     const Poppler::Page::SearchFlags mode2 = Poppler::Page::AcrossLines | Poppler::Page::IgnoreDiacritics | Poppler::Page::IgnoreCase;
302     const Poppler::Page::SearchFlags mode2W = mode2 | Poppler::Page::WholeWords;
303 
304     double l, t, r, b; // left, top, right, bottom
305 
306     // In the searched page, each of "re-conocimiento" "PRUE-BA" "imáge-nes" happen split across lines
307     const QString str1 = QString::fromUtf8("reconocimiento");
308     const QString str2 = QString::fromUtf8("IMagenes");
309     // Test it cannot be found with empty search flags
310     QCOMPARE(page->search(str1, l, t, r, b, direction, empty), false);
311     // Test it is found with AcrossLines option
312     QCOMPARE(page->search(str1, l, t, r, b, direction, mode0), true);
313     // Test AcrossLines with IgnoreDiacritics and IgnoreCase options
314     QCOMPARE(page->search(str2, l, t, r, b, direction, mode0), false);
315     QCOMPARE(page->search(str2, l, t, r, b, direction, mode1), false);
316     QCOMPARE(page->search(str2, l, t, r, b, direction, mode2), true);
317     // Test with WholeWords too
318     QCOMPARE(page->search(str2, l, t, r, b, direction, mode2W), true);
319 
320     // Now test that AcrossLines also allows whitespace in the search term to match on newline char.
321     // In the searched page, "podrá" ends a line and "acordar" starts the next line, so we
322     // now test we match it with "podrá acordar"
323     const QString str3 = QString::fromUtf8("podrá acordar,");
324     QCOMPARE(page->search(str3, l, t, r, b, direction, mode0), true);
325     QCOMPARE(page->search(str3, l, t, r, b, direction, mode1), true);
326     QCOMPARE(page->search(str3, l, t, r, b, direction, mode2), true);
327     QCOMPARE(page->search(str3, l, t, r, b, direction, mode2W), true);
328     // now test it also works with IgnoreDiacritics and IgnoreCase
329     const QString str4 = QString::fromUtf8("PODRA acordar");
330     QCOMPARE(page->search(str4, l, t, r, b, direction, mode0), false);
331     QCOMPARE(page->search(str4, l, t, r, b, direction, mode1), false);
332     QCOMPARE(page->search(str4, l, t, r, b, direction, mode2), true);
333     QCOMPARE(page->search(str4, l, t, r, b, direction, mode2W), false); // false as it lacks ending comma
334 
335     // Now test that when a hyphen char in the search term matches a hyphen at end of line,
336     // then we don't automatically ignore it, but treat it as a normal char.
337     // In the searched page, "CC BY-NC-SA 4.0" is split across two lines on the second hyphen
338     const QString str5 = QString::fromUtf8("CC BY-NC-SA 4.0");
339     QScopedPointer<Poppler::Page> page0(document->page(0));
340     QVERIFY(page0);
341     QCOMPARE(page0->search(str5, l, t, r, b, direction, mode0), true);
342     QCOMPARE(page0->search(str5, l, t, r, b, direction, mode1), true);
343     QCOMPARE(page0->search(str5, l, t, r, b, direction, mode2), true);
344     QCOMPARE(page0->search(str5, l, t, r, b, direction, mode2W), true);
345     QCOMPARE(page0->search(QString::fromUtf8("NC-SA"), l, t, r, b, direction, mode2W), false);
346     // Searching for "CC BY-NCSA 4.0" should also match, because hyphen is now ignored at end of line
347     const QString str6 = QString::fromUtf8("CC BY-NCSA 4.0");
348     QCOMPARE(page0->search(str6, l, t, r, b, direction, mode0), true);
349     QCOMPARE(page0->search(str6, l, t, r, b, direction, mode1), true);
350     QCOMPARE(page0->search(str6, l, t, r, b, direction, mode2), true);
351     QCOMPARE(page0->search(str6, l, t, r, b, direction, mode2W), true);
352 
353     // Now for completeness, we will match the full text of two lines
354     const QString full2lines = QString::fromUtf8("Las pruebas se practicarán en vista pública, si bien, excepcionalmente, el Tribunal podrá acordar, mediante providencia, que determinadas pruebas se celebren fuera del acto de juicio");
355     QCOMPARE(page->search(full2lines, l, t, r, b, direction, mode0), true);
356     QCOMPARE(page->search(full2lines, l, t, r, b, direction, mode1), true);
357     QCOMPARE(page->search(full2lines, l, t, r, b, direction, mode2), true);
358     QCOMPARE(page->search(full2lines, l, t, r, b, direction, mode2W), true);
359     // And now the full text of two lines split by a hyphenated word
360     const QString full2linesHyphenated = QString::fromUtf8("Consiste básicamente en información digitalizada, codificados y alojados en un elemento contenedor digital (equipos, dispositivos periféricos, unidades de memoria, unidades "
361                                                            "virtualizadas, tramas");
362     QCOMPARE(page->search(full2linesHyphenated, l, t, r, b, direction, mode0), true);
363     QCOMPARE(page->search(full2linesHyphenated, l, t, r, b, direction, mode1), true);
364     QCOMPARE(page->search(full2linesHyphenated, l, t, r, b, direction, mode2), true);
365     QCOMPARE(page->search(full2linesHyphenated, l, t, r, b, direction, mode2W), true);
366 }
367 
368 QTEST_GUILESS_MAIN(TestSearch)
369 #include "check_search.moc"
370