diff options
author | Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de> | 2024-03-30 19:20:38 +0100 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2024-04-07 17:25:04 +0000 |
commit | 7ecb49e8cf696e836663afa159c4ae809b3861a7 (patch) | |
tree | c7f98c74f346f0abcce0a3ce2cd5094b22ea088a | |
parent | 0f1ad3e4c1e4baacaec1771af23e4706a2d25cff (diff) |
Cover Landscape etc in Qt Page::text tests
Currently, the "Lanscape" with default page rectangle test fails, as the
page orientation is not taken into account.
(Seascape is also incorrect, but as the text lies inside the unrotated
A4 cropbox rectangle (bottom left), the text is extracted.)
-rw-r--r-- | qt5/tests/check_actualtext.cpp | 50 | ||||
-rw-r--r-- | qt6/tests/check_actualtext.cpp | 50 |
2 files changed, 100 insertions, 0 deletions
diff --git a/qt5/tests/check_actualtext.cpp b/qt5/tests/check_actualtext.cpp index 37fd5a9e..f1a04dfd 100644 --- a/qt5/tests/check_actualtext.cpp +++ b/qt5/tests/check_actualtext.cpp @@ -13,6 +13,8 @@ private slots: void checkActualText1(); void checkActualText2(); void checkActualText2_data(); + void checkAllOrientations(); + void checkAllOrientations_data(); private: void checkActualText(Poppler::Document *doc, const QRectF &area, const QString &text); @@ -77,6 +79,54 @@ void TestActualText::checkActualText2_data() QTest::newRow("middle 'x'") << QRectF { 200.0, 90.0, 5.0, 20.0 } << QStringLiteral("x"); } +void TestActualText::checkAllOrientations() +{ + QFETCH(int, pageNr); + QFETCH(QRectF, area); + QFETCH(QString, text); + + QString path { TESTDATADIR "/unittestcases/orientation.pdf" }; + std::unique_ptr<Poppler::Document> doc { Poppler::Document::load(path) }; + QVERIFY(doc); + + std::unique_ptr<Poppler::Page> page { doc->page(pageNr) }; + QVERIFY(page); + + QEXPECT_FAIL("Landscape", "Cropbox not rotated", Continue); + QCOMPARE(page->text(area), text); +} + +void TestActualText::checkAllOrientations_data() +{ + QTest::addColumn<int>("pageNr"); + QTest::addColumn<QRectF>("area"); + QTest::addColumn<QString>("text"); + + QTest::newRow("Portrait") << 0 << QRectF {} << QStringLiteral("Portrait"); + QTest::newRow("Landscape") << 1 << QRectF {} << QStringLiteral("Landscape"); + QTest::newRow("Upside down") << 2 << QRectF {} << QStringLiteral("Upside down"); + QTest::newRow("Seacape") << 3 << QRectF {} << QStringLiteral("Seascape"); + + QTest::newRow("Portrait A4 rect") << 0 << QRectF { 0, 0, 595, 842 } << QStringLiteral("Portrait"); + QTest::newRow("Landscape A4 rect") << 1 << QRectF { 0, 0, 842, 595 } << QStringLiteral("Landscape"); + QTest::newRow("Upside down A4 rect") << 2 << QRectF { 0, 0, 595, 842 } << QStringLiteral("Upside down"); + QTest::newRow("Seacape A4 rect") << 3 << QRectF { 0, 0, 842, 595 } << QStringLiteral("Seascape"); + + QTest::newRow("Portrait line rect") << 0 << QRectF { 30, 30, 60, 20 } << QStringLiteral("Portrait"); + QTest::newRow("Landscape line rect") << 1 << QRectF { 790, 30, 20, 80 } << QStringLiteral("Landscape"); + QTest::newRow("Upside down line rect") << 2 << QRectF { 485, 790, 75, 20 } << QStringLiteral("Upside down"); + QTest::newRow("Seacape line rect") << 3 << QRectF { 30, 500, 20, 70 } << QStringLiteral("Seascape"); + + QTest::newRow("Portrait small rect B") << 0 << QRectF { 30, 35, 10, 10 } << QStringLiteral("P"); + QTest::newRow("Portrait small rect E") << 0 << QRectF { 80, 35, 10, 10 } << QStringLiteral("t"); + QTest::newRow("Landscape small rect B") << 1 << QRectF { 800, 30, 10, 10 } << QStringLiteral("L"); + QTest::newRow("Landscape small rect E") << 1 << QRectF { 800, 90, 10, 10 } << QStringLiteral("e"); + QTest::newRow("Upside down small rect B") << 2 << QRectF { 550, 800, 10, 10 } << QStringLiteral("U"); + QTest::newRow("Upside down small rect E") << 2 << QRectF { 485, 800, 10, 10 } << QStringLiteral("n"); + QTest::newRow("Seacape small rect B") << 3 << QRectF { 40, 550, 10, 10 } << QStringLiteral("S"); + QTest::newRow("Seacape small rect E") << 3 << QRectF { 40, 510, 10, 10 } << QStringLiteral("p"); +} + QTEST_GUILESS_MAIN(TestActualText) #include "check_actualtext.moc" diff --git a/qt6/tests/check_actualtext.cpp b/qt6/tests/check_actualtext.cpp index 41ee04db..655626be 100644 --- a/qt6/tests/check_actualtext.cpp +++ b/qt6/tests/check_actualtext.cpp @@ -13,6 +13,8 @@ private slots: void checkActualText1(); void checkActualText2(); void checkActualText2_data(); + void checkAllOrientations(); + void checkAllOrientations_data(); private: void checkActualText(Poppler::Document &doc, const QRectF &area, const QString &text); @@ -69,6 +71,54 @@ void TestActualText::checkActualText2_data() QTest::newRow("middle 'x'") << QRectF { 200.0, 90.0, 5.0, 20.0 } << QStringLiteral("x"); } +void TestActualText::checkAllOrientations() +{ + QFETCH(int, pageNr); + QFETCH(QRectF, area); + QFETCH(QString, text); + + QString path { TESTDATADIR "/unittestcases/orientation.pdf" }; + std::unique_ptr<Poppler::Document> doc { Poppler::Document::load(path) }; + QVERIFY(doc); + + std::unique_ptr<Poppler::Page> page { doc->page(pageNr) }; + QVERIFY(page); + + QEXPECT_FAIL("Landscape", "Cropbox not rotated", Continue); + QCOMPARE(page->text(area), text); +} + +void TestActualText::checkAllOrientations_data() +{ + QTest::addColumn<int>("pageNr"); + QTest::addColumn<QRectF>("area"); + QTest::addColumn<QString>("text"); + + QTest::newRow("Portrait") << 0 << QRectF {} << QStringLiteral("Portrait"); + QTest::newRow("Landscape") << 1 << QRectF {} << QStringLiteral("Landscape"); + QTest::newRow("Upside down") << 2 << QRectF {} << QStringLiteral("Upside down"); + QTest::newRow("Seacape") << 3 << QRectF {} << QStringLiteral("Seascape"); + + QTest::newRow("Portrait A4 rect") << 0 << QRectF { 0, 0, 595, 842 } << QStringLiteral("Portrait"); + QTest::newRow("Landscape A4 rect") << 1 << QRectF { 0, 0, 842, 595 } << QStringLiteral("Landscape"); + QTest::newRow("Upside down A4 rect") << 2 << QRectF { 0, 0, 595, 842 } << QStringLiteral("Upside down"); + QTest::newRow("Seacape A4 rect") << 3 << QRectF { 0, 0, 842, 595 } << QStringLiteral("Seascape"); + + QTest::newRow("Portrait line rect") << 0 << QRectF { 30, 30, 60, 20 } << QStringLiteral("Portrait"); + QTest::newRow("Landscape line rect") << 1 << QRectF { 790, 30, 20, 80 } << QStringLiteral("Landscape"); + QTest::newRow("Upside down line rect") << 2 << QRectF { 485, 790, 75, 20 } << QStringLiteral("Upside down"); + QTest::newRow("Seacape line rect") << 3 << QRectF { 30, 500, 20, 70 } << QStringLiteral("Seascape"); + + QTest::newRow("Portrait small rect B") << 0 << QRectF { 30, 35, 10, 10 } << QStringLiteral("P"); + QTest::newRow("Portrait small rect E") << 0 << QRectF { 80, 35, 10, 10 } << QStringLiteral("t"); + QTest::newRow("Landscape small rect B") << 1 << QRectF { 800, 30, 10, 10 } << QStringLiteral("L"); + QTest::newRow("Landscape small rect E") << 1 << QRectF { 800, 90, 10, 10 } << QStringLiteral("e"); + QTest::newRow("Upside down small rect B") << 2 << QRectF { 550, 800, 10, 10 } << QStringLiteral("U"); + QTest::newRow("Upside down small rect E") << 2 << QRectF { 485, 800, 10, 10 } << QStringLiteral("n"); + QTest::newRow("Seacape small rect B") << 3 << QRectF { 40, 550, 10, 10 } << QStringLiteral("S"); + QTest::newRow("Seacape small rect E") << 3 << QRectF { 40, 510, 10, 10 } << QStringLiteral("p"); +} + QTEST_GUILESS_MAIN(TestActualText) #include "check_actualtext.moc" |