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
|
From 260026c1db12cdecf7ec51af9b90292d5b7e157f Mon Sep 17 00:00:00 2001
From: Pino Toscano <pino@kde.org>
Date: Fri, 20 Feb 2026 11:05:50 +0100
Subject: [PATCH] tests: fix/skip PdfTest::testBookCollectionMetadata in
certain setups
PdfTest::testBookCollectionMetadata tests Tellico::Import::EBookImporter
for a PDF file; since Tellico::Import::EBookImporter fetches the
metadata of PDF files using KFileMetaData (and its extractors), then
the test can fail in two setups:
1) in case the KFileMetaData support is not built in
2) in case there are no PDF extractors of KFileMetaData available
To fix (1): the test is now "built" only when the KFileMetaData support
is built in.
To fix (2): KFileMetaData is queried for PDF extractors, and the test
is skipped if none is available.
(cherry picked from commit cc79dec2b00d24da0cc75fbfd4d051772f3f9d56)
---
src/tests/pdftest.cpp | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/tests/pdftest.cpp b/src/tests/pdftest.cpp
index 60c9046c1..abca95981 100644
--- a/src/tests/pdftest.cpp
+++ b/src/tests/pdftest.cpp
@@ -36,6 +36,9 @@
#include "../utils/datafileregistry.h"
#include <KLocalizedString>
+#ifdef HAVE_KFILEMETADATA
+#include <KFileMetaData/ExtractorCollection>
+#endif
#include <QTest>
#include <QStandardPaths>
@@ -43,6 +46,14 @@
// needs a GUI for QPixmaps
QTEST_MAIN( PdfTest )
+#ifdef HAVE_KFILEMETADATA
+static bool kfilemetadataCanReadPdf() {
+ const KFileMetaData::ExtractorCollection collection;
+ const QList<KFileMetaData::Extractor *> extractors = collection.fetchExtractors(QStringLiteral("application/pdf"));
+ return !extractors.isEmpty();
+}
+#endif
+
void PdfTest::initTestCase() {
QStandardPaths::setTestModeEnabled(true);
KLocalizedString::setApplicationDomain("tellico");
@@ -135,6 +146,11 @@ void PdfTest::testBookCollection() {
}
void PdfTest::testBookCollectionMetadata() {
+#ifdef HAVE_KFILEMETADATA
+ if (!kfilemetadataCanReadPdf()) {
+ QSKIP("KFileMetaData does not have plugins to extract PDF metadata.", SkipAll);
+ }
+
QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-metadata.pdf"));
Tellico::Import::EBookImporter importer(QList<QUrl>() << url);
@@ -153,4 +169,5 @@ void PdfTest::testBookCollectionMetadata() {
QCOMPARE(entry->field("author"), QStringLiteral("Happy Man"));
QCOMPARE(entry->field("keyword"), QStringLiteral("PDF Metadata"));
QCOMPARE(entry->field("comments"), url.toLocalFile());
+#endif
}
--
2.51.0
|