Upgrade to Qt 6.10.3, refactor AppState for LibraryModel integration, add ChunkMeasurer tests, and update CI/docker configurations.

This commit is contained in:
Agel committed 2026-04-03 13:55:28 +02:00
1 parent 0303107fa2
commit a31b20534a
53 files changed
+2095 -880

No files matched your search

+119 -4
View File
@@ -305,6 +305,88 @@ static QString buildEpubLargeChapter()
return ok ? path : QString{};
}
// Build an EPUB with a cover image using both meta tag and properties attribute
static QString buildEpubWithCoverImage()
{
static const char opfCover[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<package xmlns=\"http://www.idpf.org/2007/opf\" version=\"2.0\">"
" <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\">"
" <dc:title>Cover Book</dc:title>"
" <dc:creator>Cover Tester</dc:creator>"
" <meta name=\"cover\" content=\"cover-id\"/>"
" </metadata>"
" <manifest>"
" <item id=\"cover-id\" href=\"cover.jpg\" media-type=\"image/jpeg\" properties=\"cover-image\"/>"
" <item id=\"ch1\" href=\"chapter1.xhtml\" media-type=\"application/xhtml+xml\"/>"
" </manifest>"
" <spine>"
" <itemref idref=\"ch1\"/>"
" </spine>"
"</package>";
QTemporaryFile tmp;
tmp.setFileTemplate(QDir::tempPath() + "/epub_cover_XXXXXX.epub");
tmp.setAutoRemove(false);
if (!tmp.open()) return {};
const QString path = tmp.fileName();
tmp.close();
zipFile zf = zipOpen(path.toUtf8().constData(), APPEND_STATUS_CREATE);
if (!zf) return {};
bool ok = true;
ok = ok && addEntry(zf, "mimetype", QByteArray(kMimetype), true);
ok = ok && addEntry(zf, "META-INF/container.xml", QByteArray(kContainer));
ok = ok && addEntry(zf, "OEBPS/content.opf", QByteArray(opfCover));
ok = ok && addEntry(zf, "OEBPS/cover.jpg", QByteArray("DUMMY_JPEG"));
ok = ok && addEntry(zf, "OEBPS/chapter1.xhtml", QByteArray(kChapter1));
zipClose(zf, nullptr);
return ok ? path : QString{};
}
// Build an EPUB with cover image in subdirectory
static QString buildEpubWithCoverImageInSubdir()
{
static const char opfCoverSubdir[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<package xmlns=\"http://www.idpf.org/2007/opf\" version=\"2.0\">"
" <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\">"
" <dc:title>Cover Subdir Book</dc:title>"
" <dc:creator>Subdir Tester</dc:creator>"
" <meta name=\"cover\" content=\"cover-img\"/>"
" </metadata>"
" <manifest>"
" <item id=\"cover-img\" href=\"Images/cover.jpg\" media-type=\"image/jpeg\" properties=\"cover-image\"/>"
" <item id=\"ch1\" href=\"chapter1.xhtml\" media-type=\"application/xhtml+xml\"/>"
" </manifest>"
" <spine>"
" <itemref idref=\"ch1\"/>"
" </spine>"
"</package>";
QTemporaryFile tmp;
tmp.setFileTemplate(QDir::tempPath() + "/epub_coversub_XXXXXX.epub");
tmp.setAutoRemove(false);
if (!tmp.open()) return {};
const QString path = tmp.fileName();
tmp.close();
zipFile zf = zipOpen(path.toUtf8().constData(), APPEND_STATUS_CREATE);
if (!zf) return {};
bool ok = true;
ok = ok && addEntry(zf, "mimetype", QByteArray(kMimetype), true);
ok = ok && addEntry(zf, "META-INF/container.xml", QByteArray(kContainer));
ok = ok && addEntry(zf, "OEBPS/content.opf", QByteArray(opfCoverSubdir));
ok = ok && addEntry(zf, "OEBPS/Images/cover.jpg", QByteArray("DUMMY_JPEG"));
ok = ok && addEntry(zf, "OEBPS/chapter1.xhtml", QByteArray(kChapter1));
zipClose(zf, nullptr);
return ok ? path : QString{};
}
// ---------------------------------------------------------------------------
// Test class
// ---------------------------------------------------------------------------
@@ -318,6 +400,8 @@ private:
QString m_largePath;
QString m_imgPath;
QString m_relImgPath;
QString m_coverPath;
QString m_coverSubdirPath;
private slots:
void initTestCase()
@@ -327,11 +411,15 @@ private slots:
m_largePath = buildEpubLargeChapter();
m_imgPath = buildEpubWithImage();
m_relImgPath = buildEpubWithRelativeImage();
m_coverPath = buildEpubWithCoverImage();
m_coverSubdirPath = buildEpubWithCoverImageInSubdir();
QVERIFY2(!m_epubPath.isEmpty(), "Failed to build sample EPUB fixture");
QVERIFY2(!m_noNcxPath.isEmpty(), "Failed to build no-NCX EPUB fixture");
QVERIFY2(!m_largePath.isEmpty(), "Failed to build large chapter EPUB fixture");
QVERIFY2(!m_imgPath.isEmpty(), "Failed to build image EPUB fixture");
QVERIFY2(!m_relImgPath.isEmpty(), "Failed to build relative-image EPUB fixture");
QVERIFY2(!m_coverPath.isEmpty(), "Failed to build cover image EPUB fixture");
QVERIFY2(!m_coverSubdirPath.isEmpty(), "Failed to build cover image subdir EPUB fixture");
}
void cleanupTestCase()
@@ -341,6 +429,8 @@ private slots:
QFile::remove(m_largePath);
QFile::remove(m_imgPath);
QFile::remove(m_relImgPath);
QFile::remove(m_coverPath);
QFile::remove(m_coverSubdirPath);
}
// --- Phase 2: error handling ---
@@ -479,8 +569,9 @@ private slots:
const Chapter ch = reader.loadChapter(0);
QVERIFY(!ch.contentChunks.isEmpty());
const QString combined = ch.contentChunks.join('\n');
QVERIFY2(combined.contains(QStringLiteral("image://epub/OEBPS/Images/test.png")),
qPrintable(QStringLiteral("Expected image://epub/OEBPS/Images/test.png in: ") + combined));
const QString expected = QStringLiteral("image://epub/OEBPS/Images/test.png");
QVERIFY2(combined.contains(expected),
qPrintable(QStringLiteral("Expected ") + expected + QStringLiteral(" in: ") + combined));
}
void relativeImagePathResolved()
@@ -490,8 +581,32 @@ private slots:
const Chapter ch = reader.loadChapter(0);
QVERIFY(!ch.contentChunks.isEmpty());
const QString combined = ch.contentChunks.join('\n');
QVERIFY2(combined.contains(QStringLiteral("image://epub/OEBPS/Images/test.png")),
qPrintable(QStringLiteral("Expected image://epub/OEBPS/Images/test.png in: ") + combined));
const QString expected = QStringLiteral("image://epub/OEBPS/Images/test.png");
QVERIFY2(combined.contains(expected),
qPrintable(QStringLiteral("Expected ") + expected + QStringLiteral(" in: ") + combined));
}
// --- Phase 8: cover image detection ---
void coverImagePathExtracted()
{
EpubReader reader;
QVERIFY(reader.open(m_coverPath));
QCOMPARE(reader.coverImagePath(), QStringLiteral("OEBPS/cover.jpg"));
}
void coverImagePathWithSubdirectory()
{
EpubReader reader;
QVERIFY(reader.open(m_coverSubdirPath));
QCOMPARE(reader.coverImagePath(), QStringLiteral("OEBPS/Images/cover.jpg"));
}
void coverImagePathEmptyForEpubWithoutCover()
{
EpubReader reader;
QVERIFY(reader.open(m_epubPath));
QVERIFY(reader.coverImagePath().isEmpty());
}
};