diff options
author | Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de> | 2024-03-30 14:21:24 +0100 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2024-04-07 17:25:04 +0000 |
commit | 0f1ad3e4c1e4baacaec1771af23e4706a2d25cff (patch) | |
tree | 6e1013aa81542ead05d92b7d7999bb2f7d6258b6 | |
parent | a741a6ef9062ba3733f0cab7a6b1d55bec2b53df (diff) |
Extend unit tests for Qt Page::text functionality
The unit tests only covered extraction from the whole page, make sure
the various cases for smaller selections are also covered.
-rw-r--r-- | qt5/tests/check_actualtext.cpp | 35 | ||||
-rw-r--r-- | qt6/tests/check_actualtext.cpp | 35 |
2 files changed, 60 insertions, 10 deletions
diff --git a/qt5/tests/check_actualtext.cpp b/qt5/tests/check_actualtext.cpp index f1128ee2..37fd5a9e 100644 --- a/qt5/tests/check_actualtext.cpp +++ b/qt5/tests/check_actualtext.cpp @@ -12,17 +12,18 @@ public: private slots: void checkActualText1(); void checkActualText2(); + void checkActualText2_data(); private: - void checkActualText(Poppler::Document *doc); + void checkActualText(Poppler::Document *doc, const QRectF &area, const QString &text); }; -void TestActualText::checkActualText(Poppler::Document *doc) +void TestActualText::checkActualText(Poppler::Document *doc, const QRectF &area, const QString &text) { Poppler::Page *page = doc->page(0); QVERIFY(page); - QCOMPARE(page->text(QRectF()), QLatin1String("The slow brown fox jumps over the black dog.")); + QCOMPARE(page->text(area), text); delete page; } @@ -33,13 +34,16 @@ void TestActualText::checkActualText1() doc = Poppler::Document::load(TESTDATADIR "/unittestcases/WithActualText.pdf"); QVERIFY(doc); - checkActualText(doc); + checkActualText(doc, QRectF {}, QStringLiteral("The slow brown fox jumps over the black dog.")); delete doc; } void TestActualText::checkActualText2() { + QFETCH(QRectF, area); + QFETCH(QString, text); + QFile file(TESTDATADIR "/unittestcases/WithActualText.pdf"); QVERIFY(file.open(QIODevice::ReadOnly)); @@ -47,11 +51,32 @@ void TestActualText::checkActualText2() doc = Poppler::Document::load(&file); QVERIFY(doc); - checkActualText(doc); + checkActualText(doc, area, text); delete doc; } +void TestActualText::checkActualText2_data() +{ + QTest::addColumn<QRectF>("area"); + QTest::addColumn<QString>("text"); + + // Line bounding box is [100.000 90.720 331.012110 102.350] + + QTest::newRow("full page") << QRectF {} << QStringLiteral("The slow brown fox jumps over the black dog."); + QTest::newRow("full line") << QRectF { 50.0, 90.0, 290.0, 20.0 } << QStringLiteral("The slow brown fox jumps over the black dog."); + QTest::newRow("full line [narrow]") << QRectF { 50.0, 95.0, 290.0, 5.0 } << QStringLiteral("The slow brown fox jumps over the black dog."); + QTest::newRow("above line") << QRectF { 50.0, 85.0, 290.0, 10.0 } << QString {}; + QTest::newRow("above line mid") << QRectF { 50.0, 90.0, 290.0, 5.0 } << QString {}; + QTest::newRow("first two words") << QRectF { 50.0, 90.0, 100.0, 20.0 } << QStringLiteral("The slow"); + QTest::newRow("first two words [narrow]") << QRectF { 50.0, 95.0, 100.0, 5.0 } << QStringLiteral("The slow"); + QTest::newRow("first character") << QRectF { 103.0, 95.0, 1.0, 5.0 } << QStringLiteral("T"); + QTest::newRow("last two words") << QRectF { 285.0, 90.0, 100.0, 20.0 } << QStringLiteral("black dog."); + QTest::newRow("last character") << QRectF { 320.0, 90.0, 8.0, 20.0 } << QStringLiteral("g"); + QTest::newRow("middle 'fox'") << QRectF { 190.0, 90.0, 15.0, 20.0 } << QStringLiteral("fox"); + QTest::newRow("middle 'x'") << QRectF { 200.0, 90.0, 5.0, 20.0 } << QStringLiteral("x"); +} + QTEST_GUILESS_MAIN(TestActualText) #include "check_actualtext.moc" diff --git a/qt6/tests/check_actualtext.cpp b/qt6/tests/check_actualtext.cpp index 1faf082e..41ee04db 100644 --- a/qt6/tests/check_actualtext.cpp +++ b/qt6/tests/check_actualtext.cpp @@ -12,17 +12,18 @@ public: private slots: void checkActualText1(); void checkActualText2(); + void checkActualText2_data(); private: - void checkActualText(Poppler::Document &doc); + void checkActualText(Poppler::Document &doc, const QRectF &area, const QString &text); }; -void TestActualText::checkActualText(Poppler::Document &doc) +void TestActualText::checkActualText(Poppler::Document &doc, const QRectF &area, const QString &text) { std::unique_ptr<Poppler::Page> page = doc.page(0); QVERIFY(page); - QCOMPARE(page->text(QRectF()), QLatin1String("The slow brown fox jumps over the black dog.")); + QCOMPARE(page->text(area), text); } void TestActualText::checkActualText1() @@ -30,18 +31,42 @@ void TestActualText::checkActualText1() std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/WithActualText.pdf"); QVERIFY(doc); - checkActualText(*doc); + checkActualText(*doc, QRectF {}, QStringLiteral("The slow brown fox jumps over the black dog.")); } void TestActualText::checkActualText2() { + QFETCH(QRectF, area); + QFETCH(QString, text); + QFile file(TESTDATADIR "/unittestcases/WithActualText.pdf"); QVERIFY(file.open(QIODevice::ReadOnly)); std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(&file); QVERIFY(doc); - checkActualText(*doc); + checkActualText(*doc, area, text); +} + +void TestActualText::checkActualText2_data() +{ + QTest::addColumn<QRectF>("area"); + QTest::addColumn<QString>("text"); + + // Line bounding box is [100.000 90.720 331.012110 102.350] + + QTest::newRow("full page") << QRectF {} << QStringLiteral("The slow brown fox jumps over the black dog."); + QTest::newRow("full line") << QRectF { 50.0, 90.0, 290.0, 20.0 } << QStringLiteral("The slow brown fox jumps over the black dog."); + QTest::newRow("full line [narrow]") << QRectF { 50.0, 95.0, 290.0, 5.0 } << QStringLiteral("The slow brown fox jumps over the black dog."); + QTest::newRow("above line") << QRectF { 50.0, 85.0, 290.0, 10.0 } << QString {}; + QTest::newRow("above line mid") << QRectF { 50.0, 90.0, 290.0, 5.0 } << QString {}; + QTest::newRow("first two words") << QRectF { 50.0, 90.0, 100.0, 20.0 } << QStringLiteral("The slow"); + QTest::newRow("first two words [narrow]") << QRectF { 50.0, 95.0, 100.0, 5.0 } << QStringLiteral("The slow"); + QTest::newRow("first character") << QRectF { 103.0, 95.0, 1.0, 5.0 } << QStringLiteral("T"); + QTest::newRow("last two words") << QRectF { 285.0, 90.0, 100.0, 20.0 } << QStringLiteral("black dog."); + QTest::newRow("last character") << QRectF { 320.0, 90.0, 8.0, 20.0 } << QStringLiteral("g"); + QTest::newRow("middle 'fox'") << QRectF { 190.0, 90.0, 15.0, 20.0 } << QStringLiteral("fox"); + QTest::newRow("middle 'x'") << QRectF { 200.0, 90.0, 5.0, 20.0 } << QStringLiteral("x"); } QTEST_GUILESS_MAIN(TestActualText) |