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