summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2024-03-21 14:28:07 -0700
committerShawn Rutledge <shawn.rutledge@qt.io>2024-03-24 16:11:10 -0700
commit832484634fc714ac3d5a54d33df5e3de13f75a40 (patch)
tree5029f53bcd1af15a3b91cdc49595b4f2c10bf499
parent5642f33e17aa82fd361b972cd8ac88ba83604273 (diff)
Get tst_QPdfSearchModel working; check search results in rotated text
API has changed since b6dd845ec4a6bfb6b620686681e20d38a2f24101, and this test wasn't included in CMakeLists so we haven't been running it. Now it checks search result rectangle bounds. The new test PDFs are from the pdfium repository https://pdfium.googlesource.com/pdfium and include different kinds of transforms (the Tm command apparently). Task-number: QTBUG-120764 Change-Id: I25cf5944dd227dd4d2c70cbbac470d1d0fcc181a Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit f99e5ccf03e1b8fa3dd9725cbd9992850b9e4159) Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--tests/auto/pdf/CMakeLists.txt1
-rw-r--r--tests/auto/pdf/qpdfsearchmodel/CMakeLists.txt2
-rw-r--r--tests/auto/pdf/qpdfsearchmodel/rotated_text.pdf70
-rw-r--r--tests/auto/pdf/qpdfsearchmodel/tagged_mcr_multipage.pdf136
-rw-r--r--tests/auto/pdf/qpdfsearchmodel/tst_qpdfsearchmodel.cpp41
5 files changed, 246 insertions, 4 deletions
diff --git a/tests/auto/pdf/CMakeLists.txt b/tests/auto/pdf/CMakeLists.txt
index 2f3f73961..205bd24d0 100644
--- a/tests/auto/pdf/CMakeLists.txt
+++ b/tests/auto/pdf/CMakeLists.txt
@@ -6,6 +6,7 @@ if (TARGET Qt::PdfWidgets)
add_subdirectory(qpdfpagenavigator)
endif()
add_subdirectory(qpdfpagerenderer)
+add_subdirectory(qpdfsearchmodel)
if(TARGET Qt::PrintSupport)
add_subdirectory(qpdfdocument)
endif()
diff --git a/tests/auto/pdf/qpdfsearchmodel/CMakeLists.txt b/tests/auto/pdf/qpdfsearchmodel/CMakeLists.txt
index 3a0486be5..668d1ea36 100644
--- a/tests/auto/pdf/qpdfsearchmodel/CMakeLists.txt
+++ b/tests/auto/pdf/qpdfsearchmodel/CMakeLists.txt
@@ -9,5 +9,7 @@ qt_internal_add_test(tst_qpdfsearchmodel
Qt::Network
Qt::Pdf
TESTDATA
+ rotated_text.pdf
+ tagged_mcr_multipage.pdf
test.pdf
)
diff --git a/tests/auto/pdf/qpdfsearchmodel/rotated_text.pdf b/tests/auto/pdf/qpdfsearchmodel/rotated_text.pdf
new file mode 100644
index 000000000..d6d8db84e
--- /dev/null
+++ b/tests/auto/pdf/qpdfsearchmodel/rotated_text.pdf
@@ -0,0 +1,70 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+ /Type /Pages
+ /MediaBox [ 0 0 200 200 ]
+ /Count 1
+ /Kids [ 3 0 R ]
+>>
+endobj
+3 0 obj <<
+ /Type /Page
+ /Parent 2 0 R
+ /Resources <<
+ /Font <<
+ /F1 4 0 R
+ >>
+ >>
+ /Contents 5 0 R
+>>
+endobj
+4 0 obj <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Times-Roman
+>>
+endobj
+5 0 obj <<
+ /Length 406
+>>
+stream
+BT
+0 0 Td
+/F1 12 Tf
+0.70710678118 -0.70710678118 0.70710678118 0.70710678118 100 100 Tm
+(Hello,) Tj
+0 0 Td
+/F1 12 Tf
+-0.70710678118 -0.70710678118 0.70710678118 -0.70710678118 100 100 Tm
+( world!\r\n) Tj
+0 0 Td
+/F1 12 Tf
+-0.70710678118 0.70710678118 -0.70710678118 -0.70710678118 100 100 Tm
+(Goodbye,) Tj
+0 0 Td
+/F1 12 Tf
+0.70710678118 0.70710678118 -0.70710678118 0.70710678118 100 100 Tm
+( world!) Tj
+ET
+endstream
+endobj
+xref
+0 6
+0000000000 65535 f
+0000000015 00000 n
+0000000068 00000 n
+0000000161 00000 n
+0000000287 00000 n
+0000000365 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 6
+>>
+startxref
+823
+%%EOF
diff --git a/tests/auto/pdf/qpdfsearchmodel/tagged_mcr_multipage.pdf b/tests/auto/pdf/qpdfsearchmodel/tagged_mcr_multipage.pdf
new file mode 100644
index 000000000..fcc5fafda
--- /dev/null
+++ b/tests/auto/pdf/qpdfsearchmodel/tagged_mcr_multipage.pdf
@@ -0,0 +1,136 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /MarkInfo <<
+ /Type /MarkInfo
+ /Marked true
+ >>
+ /Pages 2 0 R
+ /StructTreeRoot 8 0 R
+>>
+endobj
+2 0 obj <<
+ /Type /Pages
+ /CropBox [ 10.8197 8.459 605.705 801.639 ]
+ /MediaBox [ 0.0 0.0 616.721 809.902 ]
+ /Count 2
+ /Kids [
+ 4 0 R
+ 6 0 R
+ ]
+>>
+endobj
+3 0 obj <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Times-Roman
+>>
+endobj
+4 0 obj <<
+ /Type /Page
+ /Tabs /S
+ /Parent 2 0 R
+ /StructParents 0
+ /Contents 5 0 R
+ /Resources <<
+ /ProcSet [/PDF /Text]
+ /Font <<
+ /F1 3 0 R
+ >>
+ >>
+>>
+endobj
+5 0 obj <<
+ /Length 83
+>>
+stream
+BT
+/Document <</MCID 0 >>BDC
+0 i
+/F1 1 Tf
+12 0 0 12 43.073 771.625 Tm
+(1)Tj
+EMC
+ET
+endstream
+endobj
+6 0 obj <<
+ /Type /Page
+ /Tabs /S
+ /Parent 2 0 R
+ /StructParents 1
+ /Contents 7 0 R
+ /Resources <<
+ /ProcSet [/PDF /Text]
+ /Font <<
+ /F1 3 0 R
+ >>
+ >>
+>>
+endobj
+7 0 obj <<
+ /Length 83
+>>
+stream
+BT
+/Document <</MCID 0 >>BDC
+0 i
+/F1 1 Tf
+12 0 0 12 43.073 771.625 Tm
+(2)Tj
+EMC
+ET
+endstream
+endobj
+8 0 obj <<
+ /Type /StructTreeRoot
+ /K 10 0 R
+ /ParentTree 9 0 R
+ /ParentTreeNextKey 2
+>>
+endobj
+9 0 obj <<
+ /Nums [
+ 0
+ [10 0 R]
+ 1
+ [10 0 R]
+ ]
+>>
+endobj
+10 0 obj <<
+ /T ()
+ /S /Document
+ /P 8 0 R
+ /Pg 4 0 R
+ /K [
+ 0
+ <<
+ /MCID 0
+ /Pg 6 0 R
+ /Type /MCR
+ >>
+ ]
+>>
+%endobj
+xref
+0 11
+0000000000 65535 f
+0000000015 00000 n
+0000000149 00000 n
+0000000315 00000 n
+0000000393 00000 n
+0000000575 00000 n
+0000000709 00000 n
+0000000891 00000 n
+0000001025 00000 n
+0000001125 00000 n
+0000001198 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 11
+>>
+startxref
+1345
+%%EOF
diff --git a/tests/auto/pdf/qpdfsearchmodel/tst_qpdfsearchmodel.cpp b/tests/auto/pdf/qpdfsearchmodel/tst_qpdfsearchmodel.cpp
index 0bdb9296b..b41fa3143 100644
--- a/tests/auto/pdf/qpdfsearchmodel/tst_qpdfsearchmodel.cpp
+++ b/tests/auto/pdf/qpdfsearchmodel/tst_qpdfsearchmodel.cpp
@@ -7,6 +7,8 @@
#include <QPdfDocument>
#include <QPdfSearchModel>
+Q_LOGGING_CATEGORY(lcTests, "qt.pdf.tests")
+
class tst_QPdfSearchModel: public QObject
{
Q_OBJECT
@@ -15,20 +17,51 @@ public:
tst_QPdfSearchModel() {}
private slots:
+ void findText_data();
void findText();
};
+void tst_QPdfSearchModel::findText_data()
+{
+ QTest::addColumn<QString>("pdfPath");
+ QTest::addColumn<QString>("searchString");
+ QTest::addColumn<int>("expectedMatchCount");
+ QTest::addColumn<int>("matchIndexToCheck");
+ QTest::addColumn<int>("expectedRectangleCount");
+ QTest::addColumn<int>("rectIndexToCheck");
+ QTest::addColumn<QRect>("expectedMatchBounds");
+
+ QTest::newRow("the search for ai") << QFINDTESTDATA("test.pdf")
+ << "ai" << 3 << 0 << 1 << 0 << QRect(321, 202, 9, 11);
+ QTest::newRow("rotated text") << QFINDTESTDATA("rotated_text.pdf")
+ << "world!" << 2 << 0 << 1 << 0 << QRect(76, 102, 26, 28);
+ QTest::newRow("displaced text") << QFINDTESTDATA("tagged_mcr_multipage.pdf")
+ << "1" << 1 << 0 << 1 << 0 << QRect(34, 22, 3, 8);
+}
+
void tst_QPdfSearchModel::findText()
{
+ QFETCH(QString, pdfPath);
+ QFETCH(QString, searchString);
+ QFETCH(int, expectedMatchCount);
+ QFETCH(int, matchIndexToCheck);
+ QFETCH(int, expectedRectangleCount);
+ QFETCH(int, rectIndexToCheck);
+ QFETCH(QRect, expectedMatchBounds);
+
QPdfDocument document;
- QCOMPARE(document.load(QFINDTESTDATA("test.pdf")), QPdfDocument::NoError);
+ QCOMPARE(document.load(pdfPath), QPdfDocument::Error::None);
QPdfSearchModel model;
model.setDocument(&document);
- QList<QRectF> matches = model.matches(1, "ai");
+ model.setSearchString(searchString);
- qDebug() << matches;
- QCOMPARE(matches.count(), 3);
+ QTRY_COMPARE(model.rowCount({}), expectedMatchCount); // wait for the timer
+ QPdfLink match = model.resultAtIndex(matchIndexToCheck);
+ qCDebug(lcTests) << match;
+ QList<QRectF> rects = match.rectangles();
+ QCOMPARE(rects.size(), expectedRectangleCount);
+ QCOMPARE(rects.at(rectIndexToCheck).toRect(), expectedMatchBounds);
}
QTEST_MAIN(tst_QPdfSearchModel)