Debian Codegraph @

qt5/tests/check_search.cpp

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