Changeset View
Changeset View
Standalone View
Standalone View
autotests/searchtest.cpp
Show All 40 Lines | 39 | private slots: | |||
---|---|---|---|---|---|
41 | void testNextAndPrevious(); | 41 | void testNextAndPrevious(); | ||
42 | void test311232(); | 42 | void test311232(); | ||
43 | void test323262(); | 43 | void test323262(); | ||
44 | void test323263(); | 44 | void test323263(); | ||
45 | void testDottedI(); | 45 | void testDottedI(); | ||
46 | void testHyphenAtEndOfLineWithoutYOverlap(); | 46 | void testHyphenAtEndOfLineWithoutYOverlap(); | ||
47 | void testHyphenWithYOverlap(); | 47 | void testHyphenWithYOverlap(); | ||
48 | void testHyphenAtEndOfPage(); | 48 | void testHyphenAtEndOfPage(); | ||
49 | void testWholeWords(); | ||||
49 | void testOneColumn(); | 50 | void testOneColumn(); | ||
50 | void testTwoColumns(); | 51 | void testTwoColumns(); | ||
51 | }; | 52 | }; | ||
52 | 53 | | |||
53 | void SearchTest::initTestCase() | 54 | void SearchTest::initTestCase() | ||
54 | { | 55 | { | ||
55 | qRegisterMetaType<Okular::Document::SearchStatus>(); | 56 | qRegisterMetaType<Okular::Document::SearchStatus>(); | ||
56 | Okular::SettingsCore::instance( QStringLiteral("searchtest") ); | 57 | Okular::SettingsCore::instance( QStringLiteral("searchtest") ); | ||
Show All 18 Lines | |||||
75 | #define CREATE_PAGE \ | 76 | #define CREATE_PAGE \ | ||
76 | QCOMPARE(text.size(), rect.size()); \ | 77 | QCOMPARE(text.size(), rect.size()); \ | ||
77 | Okular::Page* page; \ | 78 | Okular::Page* page; \ | ||
78 | Okular::TextPage* tp; \ | 79 | Okular::TextPage* tp; \ | ||
79 | createTextPage(text, rect, tp, page); | 80 | createTextPage(text, rect, tp, page); | ||
80 | 81 | | |||
81 | #define TEST_NEXT_PREV(searchType, expectedStatus) \ | 82 | #define TEST_NEXT_PREV(searchType, expectedStatus) \ | ||
82 | { \ | 83 | { \ | ||
83 | Okular::RegularAreaRect* result = tp->findText(0, searchString, searchType, Qt::CaseSensitive, NULL); \ | 84 | Okular::RegularAreaRect* result = tp->findText(0, searchString, searchType, Qt::CaseSensitive, NULL, false); \ | ||
84 | QCOMPARE(!!result, expectedStatus); \ | 85 | QCOMPARE(!!result, expectedStatus); \ | ||
85 | delete result; \ | 86 | delete result; \ | ||
86 | } | 87 | } | ||
87 | 88 | | |||
88 | //The test testNextAndPrevious checks that | 89 | //The test testNextAndPrevious checks that | ||
89 | //a) if one starts a new search, then the first or last match is found, depending on the search direction | 90 | //a) if one starts a new search, then the first or last match is found, depending on the search direction | ||
90 | // (2 cases: FromTop/FromBottom) | 91 | // (2 cases: FromTop/FromBottom) | ||
91 | //b) if the last search has found a match, | 92 | //b) if the last search has found a match, | ||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | 169 | { | |||
173 | QObject::connect(&d, SIGNAL(searchFinished(int,Okular::Document::SearchStatus)), &receiver, SLOT(searchFinished(int,Okular::Document::SearchStatus))); | 174 | QObject::connect(&d, SIGNAL(searchFinished(int,Okular::Document::SearchStatus)), &receiver, SLOT(searchFinished(int,Okular::Document::SearchStatus))); | ||
174 | 175 | | |||
175 | const QString testFile = QStringLiteral(KDESRCDIR "data/file1.pdf"); | 176 | const QString testFile = QStringLiteral(KDESRCDIR "data/file1.pdf"); | ||
176 | QMimeDatabase db; | 177 | QMimeDatabase db; | ||
177 | const QMimeType mime = db.mimeTypeForFile( testFile ); | 178 | const QMimeType mime = db.mimeTypeForFile( testFile ); | ||
178 | d.openDocument(testFile, QUrl(), mime); | 179 | d.openDocument(testFile, QUrl(), mime); | ||
179 | 180 | | |||
180 | const int searchId = 0; | 181 | const int searchId = 0; | ||
181 | d.searchText(searchId, QStringLiteral(" i "), true, Qt::CaseSensitive, Okular::Document::NextMatch, false, QColor()); | 182 | d.searchText(searchId, QStringLiteral(" i "), true, Qt::CaseSensitive, Okular::Document::NextMatch, false, QColor(), false); | ||
182 | QTRY_COMPARE(spy.count(), 1); | 183 | QTRY_COMPARE(spy.count(), 1); | ||
183 | QCOMPARE(receiver.m_id, searchId); | 184 | QCOMPARE(receiver.m_id, searchId); | ||
184 | QCOMPARE(receiver.m_status, Okular::Document::MatchFound); | 185 | QCOMPARE(receiver.m_status, Okular::Document::MatchFound); | ||
185 | 186 | | |||
186 | 187 | | |||
187 | d.continueSearch( searchId, Okular::Document::PreviousMatch ); | 188 | d.continueSearch( searchId, Okular::Document::PreviousMatch ); | ||
188 | QTRY_COMPARE(spy.count(), 2); | 189 | QTRY_COMPARE(spy.count(), 2); | ||
189 | QCOMPARE(receiver.m_id, searchId); | 190 | QCOMPARE(receiver.m_id, searchId); | ||
190 | QCOMPARE(receiver.m_status, Okular::Document::NoMatchFound); | 191 | QCOMPARE(receiver.m_status, Okular::Document::NoMatchFound); | ||
191 | } | 192 | } | ||
192 | 193 | | |||
193 | void SearchTest::test323262() | 194 | void SearchTest::test323262() | ||
194 | { | 195 | { | ||
195 | QVector<QString> text; | 196 | QVector<QString> text; | ||
196 | text << QStringLiteral("a\n"); | 197 | text << QStringLiteral("a\n"); | ||
197 | 198 | | |||
198 | QVector<Okular::NormalizedRect> rect; | 199 | QVector<Okular::NormalizedRect> rect; | ||
199 | rect << Okular::NormalizedRect(1, 2, 3, 4); | 200 | rect << Okular::NormalizedRect(1, 2, 3, 4); | ||
200 | 201 | | |||
201 | CREATE_PAGE; | 202 | CREATE_PAGE; | ||
202 | 203 | | |||
203 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("a"), Okular::FromBottom, Qt::CaseSensitive, nullptr); | 204 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("a"), Okular::FromBottom, Qt::CaseSensitive, nullptr, false); | ||
204 | QVERIFY(result); | 205 | QVERIFY(result); | ||
205 | delete result; | 206 | delete result; | ||
206 | 207 | | |||
207 | delete page; | 208 | delete page; | ||
208 | } | 209 | } | ||
209 | 210 | | |||
210 | void SearchTest::test323263() | 211 | void SearchTest::test323263() | ||
211 | { | 212 | { | ||
212 | QVector<QString> text; | 213 | QVector<QString> text; | ||
213 | text << QStringLiteral("a") << QStringLiteral("a") << QStringLiteral("b"); | 214 | text << QStringLiteral("a") << QStringLiteral("a") << QStringLiteral("b"); | ||
214 | 215 | | |||
215 | QVector<Okular::NormalizedRect> rect; | 216 | QVector<Okular::NormalizedRect> rect; | ||
216 | rect << Okular::NormalizedRect(0, 0, 1, 1) | 217 | rect << Okular::NormalizedRect(0, 0, 1, 1) | ||
217 | << Okular::NormalizedRect(1, 0, 2, 1) | 218 | << Okular::NormalizedRect(1, 0, 2, 1) | ||
218 | << Okular::NormalizedRect(2, 0, 3, 1); | 219 | << Okular::NormalizedRect(2, 0, 3, 1); | ||
219 | 220 | | |||
220 | CREATE_PAGE; | 221 | CREATE_PAGE; | ||
221 | 222 | | |||
222 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("ab"), Okular::FromTop, Qt::CaseSensitive, nullptr); | 223 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("ab"), Okular::FromTop, Qt::CaseSensitive, nullptr, false); | ||
223 | QVERIFY(result); | 224 | QVERIFY(result); | ||
224 | Okular::RegularAreaRect expected; | 225 | Okular::RegularAreaRect expected; | ||
225 | expected.append(rect[1]); | 226 | expected.append(rect[1]); | ||
226 | expected.append(rect[2]); | 227 | expected.append(rect[2]); | ||
227 | expected.simplify(); | 228 | expected.simplify(); | ||
228 | QCOMPARE(*result, expected); | 229 | QCOMPARE(*result, expected); | ||
229 | delete result; | 230 | delete result; | ||
230 | 231 | | |||
Show All 14 Lines | 236 | { | |||
245 | QVector<QString> text; | 246 | QVector<QString> text; | ||
246 | text << QString::fromUtf8("İ"); | 247 | text << QString::fromUtf8("İ"); | ||
247 | 248 | | |||
248 | QVector<Okular::NormalizedRect> rect; | 249 | QVector<Okular::NormalizedRect> rect; | ||
249 | rect << Okular::NormalizedRect(1, 2, 3, 4); | 250 | rect << Okular::NormalizedRect(1, 2, 3, 4); | ||
250 | 251 | | |||
251 | CREATE_PAGE; | 252 | CREATE_PAGE; | ||
252 | 253 | | |||
253 | Okular::RegularAreaRect* result = tp->findText(0, QString::fromUtf8("İ"), Okular::FromTop, Qt::CaseInsensitive, nullptr); | 254 | Okular::RegularAreaRect* result = tp->findText(0, QString::fromUtf8("İ"), Okular::FromTop, Qt::CaseInsensitive, nullptr, false); | ||
254 | QVERIFY(result); | 255 | QVERIFY(result); | ||
255 | delete result; | 256 | delete result; | ||
256 | 257 | | |||
257 | delete page; | 258 | delete page; | ||
258 | } | 259 | } | ||
259 | 260 | | |||
260 | void SearchTest::testHyphenAtEndOfLineWithoutYOverlap() | 261 | void SearchTest::testHyphenAtEndOfLineWithoutYOverlap() | ||
261 | { | 262 | { | ||
Show All 9 Lines | 271 | rect << Okular::NormalizedRect(0.4, 0.0, 0.9, 0.1) | |||
271 | << Okular::NormalizedRect(0.0, 0.1, 0.6, 0.2) | 272 | << Okular::NormalizedRect(0.0, 0.1, 0.6, 0.2) | ||
272 | << Okular::NormalizedRect(0.0, 0.2, 0.8, 0.3) << Okular::NormalizedRect(0.8, 0.2, 0.9, 0.3) | 273 | << Okular::NormalizedRect(0.0, 0.2, 0.8, 0.3) << Okular::NormalizedRect(0.8, 0.2, 0.9, 0.3) | ||
273 | << Okular::NormalizedRect(0.0, 0.3, 0.8, 0.4) << Okular::NormalizedRect(0.8, 0.3, 0.9, 0.4) | 274 | << Okular::NormalizedRect(0.0, 0.3, 0.8, 0.4) << Okular::NormalizedRect(0.8, 0.3, 0.9, 0.4) | ||
274 | << Okular::NormalizedRect(0.0, 0.4, 0.7, 0.5); | 275 | << Okular::NormalizedRect(0.0, 0.4, 0.7, 0.5); | ||
275 | 276 | | |||
276 | CREATE_PAGE; | 277 | CREATE_PAGE; | ||
277 | 278 | | |||
278 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("supercalifragilisticexpialidocious"), | 279 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("supercalifragilisticexpialidocious"), | ||
279 | Okular::FromTop, Qt::CaseSensitive, nullptr); | 280 | Okular::FromTop, Qt::CaseSensitive, nullptr, false); | ||
280 | QVERIFY(result); | 281 | QVERIFY(result); | ||
281 | Okular::RegularAreaRect expected; | 282 | Okular::RegularAreaRect expected; | ||
282 | for (int i = 0; i < text.size(); i++) { | 283 | for (int i = 0; i < text.size(); i++) { | ||
283 | expected.append(rect[i]); | 284 | expected.append(rect[i]); | ||
284 | } | 285 | } | ||
285 | expected.simplify(); | 286 | expected.simplify(); | ||
286 | QCOMPARE(*result, expected); | 287 | QCOMPARE(*result, expected); | ||
287 | delete result; | 288 | delete result; | ||
288 | 289 | | |||
289 | delete page; | 290 | delete page; | ||
290 | } | 291 | } | ||
291 | 292 | | |||
292 | #define CREATE_PAGE_AND_TEST_SEARCH(searchString, matchExpected) \ | 293 | #define CREATE_PAGE_AND_TEST_SEARCH(searchString, matchExpected) \ | ||
293 | { \ | 294 | { \ | ||
294 | CREATE_PAGE; \ | 295 | CREATE_PAGE; \ | ||
295 | \ | 296 | \ | ||
296 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral(searchString), \ | 297 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral(searchString), \ | ||
297 | Okular::FromTop, Qt::CaseSensitive, NULL); \ | 298 | Okular::FromTop, Qt::CaseSensitive, NULL, false); \ | ||
298 | \ | 299 | \ | ||
299 | QCOMPARE(!!result, matchExpected); \ | 300 | QCOMPARE(!!result, matchExpected); \ | ||
300 | \ | 301 | \ | ||
301 | delete result; \ | 302 | delete result; \ | ||
302 | delete page; \ | 303 | delete page; \ | ||
303 | } | 304 | } | ||
304 | 305 | | |||
305 | void SearchTest::testHyphenWithYOverlap() | 306 | void SearchTest::testHyphenWithYOverlap() | ||
Show All 38 Lines | 338 | { | |||
344 | 345 | | |||
345 | QVector<Okular::NormalizedRect> rect; | 346 | QVector<Okular::NormalizedRect> rect; | ||
346 | rect << Okular::NormalizedRect(0, 0, 1, 1); | 347 | rect << Okular::NormalizedRect(0, 0, 1, 1); | ||
347 | 348 | | |||
348 | CREATE_PAGE; | 349 | CREATE_PAGE; | ||
349 | 350 | | |||
350 | { | 351 | { | ||
351 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("a"), | 352 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("a"), | ||
352 | Okular::FromTop, Qt::CaseSensitive, nullptr); | 353 | Okular::FromTop, Qt::CaseSensitive, nullptr, false); | ||
353 | QVERIFY(result); | 354 | QVERIFY(result); | ||
354 | delete result; | 355 | delete result; | ||
355 | } | 356 | } | ||
356 | 357 | | |||
357 | { | 358 | { | ||
358 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("a"), | 359 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("a"), | ||
359 | Okular::FromBottom, Qt::CaseSensitive, nullptr); | 360 | Okular::FromBottom, Qt::CaseSensitive, nullptr, false); | ||
360 | QVERIFY(result); | 361 | QVERIFY(result); | ||
361 | delete result; | 362 | delete result; | ||
362 | } | 363 | } | ||
363 | 364 | | |||
364 | delete page; | 365 | delete page; | ||
365 | } | 366 | } | ||
366 | 367 | | |||
368 | void SearchTest::testWholeWords(){ | ||||
aacid: Seems like using a _data function here so that "test data" and "test code" are separated may be… | |||||
369 | //Tests if we are encountering whole words. | ||||
370 | //The first test searchs for bcd, should encounter only one ocurrence. | ||||
371 | //The second test searchs for abc, and should encounter the first two results | ||||
372 | //The third test is looking for abcde, it will find the first result. | ||||
373 | QVector < QString > text; | ||||
374 | text << QStringLiteral("abcd bcdad bcd") << QStringLiteral("abc.abc.abcd") | ||||
375 | << QStringLiteral("abc-\nde abc-\ndef"); | ||||
376 | | ||||
377 | // CREATE_PAGE; | ||||
378 | | ||||
379 | | ||||
380 | | ||||
381 | // delete page; | ||||
382 | } | ||||
383 | | ||||
367 | void SearchTest::testOneColumn() | 384 | void SearchTest::testOneColumn() | ||
368 | { | 385 | { | ||
369 | //Tests that the layout analysis algorithm does not create too many columns. | 386 | //Tests that the layout analysis algorithm does not create too many columns. | ||
370 | //Bug 326207 was caused by the fact that if all the horizontal breaks in a line | 387 | //Bug 326207 was caused by the fact that if all the horizontal breaks in a line | ||
371 | //had the same length and were smaller than vertical breaks between lines then | 388 | //had the same length and were smaller than vertical breaks between lines then | ||
372 | //the horizontal breaks were treated as column separators. | 389 | //the horizontal breaks were treated as column separators. | ||
373 | //(Note that "same length" means "same length after rounding rectangles to integer pixels". | 390 | //(Note that "same length" means "same length after rounding rectangles to integer pixels". | ||
374 | //The resolution used by the XY Cut algorithm with a square page is 1000 x 1000, | 391 | //The resolution used by the XY Cut algorithm with a square page is 1000 x 1000, | ||
375 | //and the horizontal spaces in the example are 0.1, so they are indeed both exactly 100 pixels.) | 392 | //and the horizontal spaces in the example are 0.1, so they are indeed both exactly 100 pixels.) | ||
376 | 393 | | |||
377 | QVector<QString> text; | 394 | QVector<QString> text; | ||
378 | text << QStringLiteral("Only") << QStringLiteral("one") << QStringLiteral("column") | 395 | text << QStringLiteral("Only") << QStringLiteral("one") << QStringLiteral("column") | ||
379 | << QStringLiteral("here"); | 396 | << QStringLiteral("here"); | ||
380 | 397 | | |||
381 | //characters and line breaks have length 0.05, word breaks 0.1 | 398 | //characters and line breaks have length 0.05, word breaks 0.1 | ||
382 | QVector<Okular::NormalizedRect> rect; | 399 | QVector<Okular::NormalizedRect> rect; | ||
383 | rect << Okular::NormalizedRect(0.0, 0.0, 0.2, 0.1) | 400 | rect << Okular::NormalizedRect(0.0, 0.0, 0.2, 0.1) | ||
384 | << Okular::NormalizedRect(0.3, 0.0, 0.5, 0.1) | 401 | << Okular::NormalizedRect(0.3, 0.0, 0.5, 0.1) | ||
385 | << Okular::NormalizedRect(0.6, 0.0, 0.9, 0.1) | 402 | << Okular::NormalizedRect(0.6, 0.0, 0.9, 0.1) | ||
386 | << Okular::NormalizedRect(0.0, 0.15, 0.2, 0.25); | 403 | << Okular::NormalizedRect(0.0, 0.15, 0.2, 0.25); | ||
387 | 404 | | |||
388 | CREATE_PAGE; | 405 | CREATE_PAGE; | ||
389 | 406 | | |||
390 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("Only one column"), | 407 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("Only one column"), | ||
391 | Okular::FromTop, Qt::CaseSensitive, nullptr); | 408 | Okular::FromTop, Qt::CaseSensitive, nullptr, false); | ||
392 | QVERIFY(result); | 409 | QVERIFY(result); | ||
393 | delete result; | 410 | delete result; | ||
394 | 411 | | |||
395 | delete page; | 412 | delete page; | ||
396 | } | 413 | } | ||
397 | 414 | | |||
398 | void SearchTest::testTwoColumns() | 415 | void SearchTest::testTwoColumns() | ||
399 | { | 416 | { | ||
Show All 11 Lines | 425 | rect << Okular::NormalizedRect(0.0, 0.0, 0.20, 0.1) | |||
411 | << Okular::NormalizedRect(0.75, 0.0, 0.9, 0.1) | 428 | << Okular::NormalizedRect(0.75, 0.0, 0.9, 0.1) | ||
412 | << Okular::NormalizedRect(0.0, 0.15, 0.1, 0.25) | 429 | << Okular::NormalizedRect(0.0, 0.15, 0.1, 0.25) | ||
413 | << Okular::NormalizedRect(0.15, 0.15, 0.3, 0.25) | 430 | << Okular::NormalizedRect(0.15, 0.15, 0.3, 0.25) | ||
414 | << Okular::NormalizedRect(0.6, 0.15, 1.0, 0.25); | 431 | << Okular::NormalizedRect(0.6, 0.15, 1.0, 0.25); | ||
415 | 432 | | |||
416 | CREATE_PAGE; | 433 | CREATE_PAGE; | ||
417 | 434 | | |||
418 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("This text in"), | 435 | Okular::RegularAreaRect* result = tp->findText(0, QStringLiteral("This text in"), | ||
419 | Okular::FromTop, Qt::CaseSensitive, nullptr); | 436 | Okular::FromTop, Qt::CaseSensitive, nullptr, false); | ||
420 | QVERIFY(!result); | 437 | QVERIFY(!result); | ||
421 | delete result; | 438 | delete result; | ||
422 | 439 | | |||
423 | delete page; | 440 | delete page; | ||
424 | } | 441 | } | ||
425 | 442 | | |||
426 | QTEST_MAIN( SearchTest ) | 443 | QTEST_MAIN( SearchTest ) | ||
427 | #include "searchtest.moc" | 444 | #include "searchtest.moc" |
Seems like using a _data function here so that "test data" and "test code" are separated may be a good idea.
Can you please investigate?