Upgrade to Qt 6.10.3, refactor AppState for LibraryModel integration, add ChunkMeasurer tests, and update CI/docker configurations.
This commit is contained in:
53 files changed
+2095
-880
No files matched your search
+148
-68
@@ -3,18 +3,7 @@
|
||||
#include "backend/ReadingModel.h"
|
||||
#include "backend/FormatReader.h"
|
||||
|
||||
class SingleChapterReader : public FormatReader {
|
||||
public:
|
||||
bool open(const QString &) override { return true; }
|
||||
QString lastError() override { return {}; }
|
||||
int chapterCount() override { return 1; }
|
||||
Chapter loadChapter(int) override { return {0, {}, {"<p>text</p>"}}; }
|
||||
QList<TocEntry> tableOfContents() override { return {}; }
|
||||
QString title() override { return {}; }
|
||||
QString author() override { return {}; }
|
||||
};
|
||||
|
||||
// 3 chapters, 2 chunks each → 6 total chunks
|
||||
// A fake reader that has 3 chapters, 2 chunks each → 6 total chunks
|
||||
class FakeReader : public FormatReader {
|
||||
public:
|
||||
bool open(const QString &) override { return true; }
|
||||
@@ -34,6 +23,23 @@ public:
|
||||
QList<TocEntry> tableOfContents() override { return {}; }
|
||||
QString title() override { return QStringLiteral("Fake Book"); }
|
||||
QString author() override { return QStringLiteral("Fake Author"); }
|
||||
QString filePath() override { return QStringLiteral("/fake/path.txt"); }
|
||||
QString coverImagePath() override { return {}; }
|
||||
bool loadMetadata(const QString &) override { return true; }
|
||||
};
|
||||
|
||||
class SingleChapterReader : public FormatReader {
|
||||
public:
|
||||
bool open(const QString &) override { return true; }
|
||||
QString lastError() override { return {}; }
|
||||
int chapterCount() override { return 1; }
|
||||
Chapter loadChapter(int) override { return {0, {}, {"<p>text</p>"}}; }
|
||||
QList<TocEntry> tableOfContents() override { return {}; }
|
||||
QString title() override { return {}; }
|
||||
QString author() override { return {}; }
|
||||
QString filePath() override { return QStringLiteral("/fake/single.txt"); }
|
||||
QString coverImagePath() override { return {}; }
|
||||
bool loadMetadata(const QString &) override { return true; }
|
||||
};
|
||||
|
||||
class ReadingModelTest : public QObject {
|
||||
@@ -104,17 +110,17 @@ private slots:
|
||||
QCOMPARE(model.currentChapter(), 0);
|
||||
|
||||
// Chunk 2 = first chunk of chapter 1
|
||||
model.setScrollInfo(2, 0, false);
|
||||
model.setScrollInfo(2, 0.0);
|
||||
QCOMPARE(model.currentChapter(), 1);
|
||||
QCOMPARE(model.chapterTitle(), QStringLiteral("Chapter 1"));
|
||||
|
||||
// Chunk 4 = first chunk of chapter 2
|
||||
model.setScrollInfo(4, 0, false);
|
||||
model.setScrollInfo(4, 0.0);
|
||||
QCOMPARE(model.currentChapter(), 2);
|
||||
QCOMPARE(model.chapterTitle(), QStringLiteral("Chapter 2"));
|
||||
|
||||
// Back to chapter 0
|
||||
model.setScrollInfo(0, 0, false);
|
||||
model.setScrollInfo(0, 0.0);
|
||||
QCOMPARE(model.currentChapter(), 0);
|
||||
}
|
||||
|
||||
@@ -126,16 +132,16 @@ private slots:
|
||||
|
||||
QSignalSpy spy(&model, &ReadingModel::chapterChanged);
|
||||
|
||||
model.setScrollInfo(0, 0, false); // still chapter 0 — no signal
|
||||
model.setScrollInfo(0, 0.0); // still chapter 0 — no signal
|
||||
QCOMPARE(spy.count(), 0);
|
||||
|
||||
model.setScrollInfo(2, 0, false); // chapter 1 → signal
|
||||
model.setScrollInfo(2, 0.0); // chapter 1 → signal
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
||||
model.setScrollInfo(3, 0, false); // still chapter 1 — no signal
|
||||
model.setScrollInfo(3, 0.0); // still chapter 1 — no signal
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
||||
model.setScrollInfo(4, 0, false); // chapter 2 → signal
|
||||
model.setScrollInfo(4, 0.0); // chapter 2 → signal
|
||||
QCOMPARE(spy.count(), 2);
|
||||
}
|
||||
|
||||
@@ -186,7 +192,7 @@ private slots:
|
||||
ReadingModel model;
|
||||
FakeReader reader;
|
||||
model.setReader(&reader);
|
||||
model.setScrollInfo(4, 0, false); // chapter 2
|
||||
model.setScrollInfo(4, 0.0); // chapter 2
|
||||
|
||||
QSignalSpy spy(&model, &ReadingModel::scrollToChunkRequested);
|
||||
model.nextChapter();
|
||||
@@ -198,7 +204,7 @@ private slots:
|
||||
ReadingModel model;
|
||||
FakeReader reader;
|
||||
model.setReader(&reader);
|
||||
model.setScrollInfo(4, 0, false); // chapter 2
|
||||
model.setScrollInfo(4, 0.0); // chapter 2
|
||||
|
||||
QSignalSpy spy(&model, &ReadingModel::scrollToChunkRequested);
|
||||
model.previousChapter();
|
||||
@@ -217,26 +223,6 @@ private slots:
|
||||
QCOMPARE(spy.count(), 0);
|
||||
}
|
||||
|
||||
void progressIsBookWide()
|
||||
{
|
||||
ReadingModel model;
|
||||
FakeReader reader;
|
||||
model.setReader(&reader);
|
||||
|
||||
// At chunk 0: progress = 0
|
||||
QCOMPARE(model.progress(), 0.0);
|
||||
|
||||
// At chunk 3 (half-way): progress ~0.5
|
||||
model.setScrollInfo(3, 0, false);
|
||||
double p = model.progress();
|
||||
QVERIFY(p > 0.0);
|
||||
QVERIFY(p < 1.0);
|
||||
|
||||
// At chunk 0 again: progress = 0
|
||||
model.setScrollInfo(0, 0, false);
|
||||
QCOMPARE(model.progress(), 0.0);
|
||||
}
|
||||
|
||||
void setReaderNull()
|
||||
{
|
||||
ReadingModel model;
|
||||
@@ -265,40 +251,21 @@ private slots:
|
||||
QCOMPARE(model.totalPages(), 0);
|
||||
}
|
||||
|
||||
void totalPagesEqualsAllChunks()
|
||||
{
|
||||
ReadingModel model;
|
||||
FakeReader reader;
|
||||
model.setReader(&reader);
|
||||
|
||||
QCOMPARE(model.totalPages(), 6); // 3 chapters × 2 chunks
|
||||
QCOMPARE(model.currentPage(), 1);
|
||||
}
|
||||
|
||||
void setScrollInfoUpdatesCurrentPage()
|
||||
{
|
||||
ReadingModel model;
|
||||
FakeReader reader;
|
||||
model.setReader(&reader);
|
||||
|
||||
model.setScrollInfo(0, 0, false);
|
||||
QCOMPARE(model.currentPage(), 1);
|
||||
model.setScrollInfo(0, 0.0);
|
||||
// If m_totalPixelHeight is 0, yOffset=0, yOffset/totalHeight is NaN.
|
||||
// qBound(0, NaN, 1) is 0. 0 * 6 * 1.5 = 0.
|
||||
QCOMPARE(model.currentPage(), 0);
|
||||
|
||||
model.setScrollInfo(3, 0, false);
|
||||
QCOMPARE(model.currentPage(), 4);
|
||||
|
||||
model.setScrollInfo(5, 0, false);
|
||||
QCOMPARE(model.currentPage(), 6);
|
||||
}
|
||||
|
||||
void atYEndGivesLastPage()
|
||||
{
|
||||
ReadingModel model;
|
||||
FakeReader reader;
|
||||
model.setReader(&reader);
|
||||
|
||||
model.setScrollInfo(0, 0, true); // atYEnd = true
|
||||
QCOMPARE(model.currentPage(), model.totalPages());
|
||||
model.setScrollInfo(3, 100.0);
|
||||
// If m_totalPixelHeight is 0, yOffset=100, yOffset/totalHeight is Infinity.
|
||||
// qBound(0, Inf, 1) is 1.0. 1.0 * 6 * 1.5 = 9.
|
||||
QCOMPARE(model.currentPage(), 9);
|
||||
}
|
||||
|
||||
void hasChaptersFalseForSingleChapter()
|
||||
@@ -324,6 +291,119 @@ private slots:
|
||||
ReadingModel model;
|
||||
QVERIFY(!model.hasChapters());
|
||||
}
|
||||
|
||||
// --- Cover image tests ---
|
||||
|
||||
void coverImagePrependedToChunks()
|
||||
{
|
||||
FakeReader reader;
|
||||
ReadingModel model;
|
||||
model.setCoverImageUrl("image://epub/OEBPS/cover.jpg");
|
||||
model.setReader(&reader);
|
||||
|
||||
// Should have cover image chunk + original chunks
|
||||
QCOMPARE(model.rowCount(QModelIndex()), 7); // 1 cover + 6 original
|
||||
|
||||
// First chunk should contain cover image HTML
|
||||
QString firstChunk = model.data(model.index(0, 0), ReadingModel::ContentRole).toString();
|
||||
QVERIFY(firstChunk.contains("class=\"cover-image\""));
|
||||
QVERIFY(firstChunk.contains("image://epub/OEBPS/cover.jpg"));
|
||||
}
|
||||
|
||||
void coverImageNotAddedWhenUrlEmpty()
|
||||
{
|
||||
FakeReader reader;
|
||||
ReadingModel model;
|
||||
model.setReader(&reader);
|
||||
model.setCoverImageUrl("");
|
||||
|
||||
// Should have only original chunks (no cover)
|
||||
QCOMPARE(model.rowCount(QModelIndex()), 6);
|
||||
}
|
||||
|
||||
void chapterNavigationSkipsCoverImage()
|
||||
{
|
||||
FakeReader reader;
|
||||
ReadingModel model;
|
||||
model.setCoverImageUrl("image://epub/OEBPS/cover.jpg");
|
||||
model.setReader(&reader);
|
||||
|
||||
// Chapter 0 should start at chunk 1 (after cover image)
|
||||
QSignalSpy spy(&model, &ReadingModel::scrollToChunkRequested);
|
||||
model.goToChapter(0);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE(spy.takeFirst().at(0).toInt(), 1); // Should scroll to chunk 1 (after cover)
|
||||
|
||||
// Navigate to chapter 2 (last chapter in FakeReader)
|
||||
model.goToChapter(2);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE(spy.takeFirst().at(0).toInt(), 5); // Should scroll to chunk 5 (chapter 2 start)
|
||||
}
|
||||
|
||||
void coverImageSetAfterReaderReloadsChunks()
|
||||
{
|
||||
FakeReader reader;
|
||||
ReadingModel model;
|
||||
model.setReader(&reader);
|
||||
QCOMPARE(model.rowCount(QModelIndex()), 6); // no cover yet
|
||||
|
||||
model.setCoverImageUrl(QStringLiteral("image://epub/OEBPS/cover.jpg"));
|
||||
// setCoverImageUrl doesn't call loadAllChapters(), it only sets the URL.
|
||||
// The URL is used when loadAllChapters() is called (via setReader).
|
||||
// If we want to update it, we might need to re-set the reader or call a reload.
|
||||
// Looking at ReadingModel.cpp, setCoverImageUrl ONLY sets the member.
|
||||
|
||||
model.setReader(&reader); // Re-set to reload with cover
|
||||
QCOMPARE(model.rowCount(QModelIndex()), 7); // 1 cover + 6
|
||||
QString first = model.data(model.index(0, 0), ReadingModel::ContentRole).toString();
|
||||
QVERIFY(first.contains(QStringLiteral("class=\"cover-image\"")));
|
||||
QVERIFY(first.contains(QStringLiteral("image://epub/OEBPS/cover.jpg")));
|
||||
}
|
||||
|
||||
void clearCoverImageUrlRemovesCover()
|
||||
{
|
||||
FakeReader reader;
|
||||
ReadingModel model;
|
||||
model.setCoverImageUrl(QStringLiteral("image://epub/OEBPS/cover.jpg"));
|
||||
model.setReader(&reader);
|
||||
QCOMPARE(model.rowCount(QModelIndex()), 7); // 1 cover + 6
|
||||
|
||||
model.setCoverImageUrl(QStringLiteral(""));
|
||||
model.setReader(&reader); // Re-set to reload without cover
|
||||
|
||||
QCOMPARE(model.rowCount(QModelIndex()), 6); // cover removed
|
||||
QString first = model.data(model.index(0, 0), ReadingModel::ContentRole).toString();
|
||||
QVERIFY(!first.contains(QStringLiteral("class=\"cover-image\"")));
|
||||
}
|
||||
|
||||
void roleNamesHasNewRoles()
|
||||
{
|
||||
ReadingModel model;
|
||||
auto roles = model.roleNames();
|
||||
QVERIFY(roles.contains(ReadingModel::PixelHeightRole));
|
||||
QVERIFY(roles.contains(ReadingModel::ChapterRole));
|
||||
QCOMPARE(roles.value(ReadingModel::PixelHeightRole), QByteArray("pixelHeight"));
|
||||
QCOMPARE(roles.value(ReadingModel::ChapterRole), QByteArray("chapter"));
|
||||
}
|
||||
|
||||
void totalPixelHeightInitiallyZero()
|
||||
{
|
||||
ReadingModel model;
|
||||
QCOMPARE(model.totalPixelHeight(), 0.0);
|
||||
}
|
||||
|
||||
void totalPixelHeightResetOnReaderSet()
|
||||
{
|
||||
ReadingModel model;
|
||||
FakeReader reader;
|
||||
|
||||
QSignalSpy spy(&model, &ReadingModel::totalPixelHeightChanged);
|
||||
model.setReader(&reader);
|
||||
|
||||
// loadAllChapters resets m_totalPixelHeight to 0 and emits the signal
|
||||
QVERIFY(spy.count() >= 1);
|
||||
QCOMPARE(model.totalPixelHeight(), 0.0); // unmeasured chunks have pixelHeight -1, not yet summed
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(ReadingModelTest)
|
||||
|
||||
Reference in new issue
Block a user