old render cleanup part 1

This commit is contained in:
Agel committed 2026-10-25 14:22:12 +01:00
1 parent 83968646c6
commit acc7e71e7b
38 files changed
+166 -1366

No files matched your search

-81
View File
@@ -1,81 +0,0 @@
#include <QtTest>
#include "backend/ChunkMeasurer.h"
#include "backend/IImageLoader.h"
// A mock image loader that returns a solid-color image of a fixed size
class FixedSizeImageLoader : public IImageLoader {
QSize m_size;
public:
explicit FixedSizeImageLoader(const QSize &size) : m_size(size) {}
QImage load(const QUrl &, int maxWidth) const override {
int w = qMin(m_size.width(), maxWidth);
int h = m_size.height();
if (w <= 0 || h <= 0) return {};
QImage img(w, h, QImage::Format_RGB32);
img.fill(Qt::red);
return img;
}
std::unique_ptr<IImageLoader> clone() const override {
return std::make_unique<FixedSizeImageLoader>(m_size);
}
};
class ChunkMeasurerTest : public QObject {
Q_OBJECT
private slots:
void returnsOneHeightPerChunk() {
ChunkMeasurer m;
QStringList chunks = {"<p>First</p>", "<p>Second</p>", "<p>Third</p>"};
auto h = m.measure(chunks, 800);
QCOMPARE(h.size(), 3);
}
void heightsArePositive() {
ChunkMeasurer m;
auto h = m.measure({"<p>Hello world</p>", "<p>Another paragraph</p>"}, 800);
for (int v : h) QVERIFY(v > 0);
}
void emptyInputReturnsEmpty() {
ChunkMeasurer m;
QVERIFY(m.measure({}, 800).isEmpty());
}
void zeroWidthClampedToOne() {
ChunkMeasurer m;
auto h = m.measure({"<p>text</p>"}, 0);
QCOMPARE(h.size(), 1);
QVERIFY(h.first() > 0);
}
void narrowerWidthGivesGreaterOrEqualHeight() {
ChunkMeasurer m;
QStringList chunks = {"<p>A long paragraph that should wrap when the width is very narrow.</p>"};
int h800 = m.measure(chunks, 800).first();
int h200 = m.measure(chunks, 200).first();
QVERIFY(h200 >= h800);
}
void imageChunkMeasuredWithLoader() {
// 600x400 image, but maxWidth=400 so it gets scaled to 400x267
auto loader = std::make_unique<FixedSizeImageLoader>(QSize(600, 400));
ChunkMeasurer m(std::move(loader));
// Chunk with an image URL
QStringList chunks = {QStringLiteral("<p><img src=\"image://epub/test.jpg\"/></p>")};
auto h = m.measure(chunks, 400);
QCOMPARE(h.size(), 1);
QVERIFY(h.first() > 0); // should include image height
}
void nullLoaderTextOnlyWorks() {
ChunkMeasurer m(nullptr);
auto h = m.measure({"<p>text only</p>"}, 800);
QCOMPARE(h.size(), 1);
QVERIFY(h.first() > 0);
}
void parallelResultsAreConsistent() {
ChunkMeasurer m;
QStringList chunks;
for (int i = 0; i < 100; ++i)
chunks << QStringLiteral("<p>Paragraph number %1 with some text content.</p>").arg(i);
auto h1 = m.measure(chunks, 600);
auto h2 = m.measure(chunks, 600);
QCOMPARE(h1, h2);
}
};
QTEST_MAIN(ChunkMeasurerTest)
#include "ChunkMeasurerTest.moc"
+11 -61
View File
@@ -17,13 +17,12 @@
// Load one zip member through the generic byte-source pipeline (EPUBs are zips).
static QImage loadFromEpub(const QString &epubPath, const QString &entry,
int displayWidth, const QSize &requestedSize)
const QSize &requestedSize)
{
ZipByteSource source;
if (!source.open(epubPath))
return {};
return EntryImageProvider::loadImageFromSource(source, entry, displayWidth,
requestedSize);
return EntryImageProvider::loadImageFromSource(source, entry, requestedSize);
}
static EntryImageProvider makeEpubProvider()
@@ -96,7 +95,7 @@ private slots:
QVERIFY(!epubPath.isEmpty());
const QImage img = loadFromEpub(
epubPath, QStringLiteral("OEBPS/Images/test.png"), 0, QSize());
epubPath, QStringLiteral("OEBPS/Images/test.png"), QSize());
QFile::remove(epubPath);
@@ -112,7 +111,7 @@ private slots:
QVERIFY(!epubPath.isEmpty());
const QImage img = loadFromEpub(
epubPath, QStringLiteral("OEBPS/Images/nonexistent.png"), 0, QSize());
epubPath, QStringLiteral("OEBPS/Images/nonexistent.png"), QSize());
QFile::remove(epubPath);
@@ -122,7 +121,7 @@ private slots:
void requestImageReturnsNullWhenNoPath()
{
const QImage img = loadFromEpub(
QString{}, QStringLiteral("OEBPS/Images/test.png"), 0, QSize());
QString{}, QStringLiteral("OEBPS/Images/test.png"), QSize());
QVERIFY(img.isNull());
}
@@ -133,51 +132,20 @@ private slots:
// After clear the path is empty, so loadImageFromEpub with empty path returns null
const QImage img = loadFromEpub(
QString{}, QStringLiteral("OEBPS/Images/test.png"), 0, QSize());
QString{}, QStringLiteral("OEBPS/Images/test.png"), QSize());
QFile::remove(epubPath);
QVERIFY(img.isNull());
}
void largeImageScaledToDisplayWidth()
{
const QString epubPath = buildEpubWithPng("img.png", 600, 400);
QVERIFY(!epubPath.isEmpty());
const QImage img = loadFromEpub(
epubPath, QStringLiteral("img.png"), 300, QSize());
QFile::remove(epubPath);
QVERIFY(!img.isNull());
QCOMPARE(img.width(), 300);
QCOMPARE(img.height(), 200);
QCOMPARE(img.size(), QSize(300, 200));
}
void smallImageNotEnlarged()
{
const QString epubPath = buildEpubWithPng("img.png", 100, 100);
QVERIFY(!epubPath.isEmpty());
const QImage img = loadFromEpub(
epubPath, QStringLiteral("img.png"), 300, QSize());
QFile::remove(epubPath);
QVERIFY(!img.isNull());
QCOMPARE(img.width(), 100);
QCOMPARE(img.height(), 100);
}
void requestedSizeHonored()
{
const QString epubPath = buildEpubWithPng("img.png", 400, 300);
QVERIFY(!epubPath.isEmpty());
const QImage img = loadFromEpub(
epubPath, QStringLiteral("img.png"), 600, QSize(200, -1));
epubPath, QStringLiteral("img.png"), QSize(200, -1));
QFile::remove(epubPath);
@@ -196,7 +164,7 @@ private slots:
AsyncImageResponse response([epubPath] {
return loadFromEpub(
epubPath, QStringLiteral("img.png"), 0, QSize());
epubPath, QStringLiteral("img.png"), QSize());
});
QSignalSpy spy(&response, &QQuickImageResponse::finished);
response.run();
@@ -214,7 +182,7 @@ private slots:
AsyncImageResponse response([epubPath] {
return loadFromEpub(
epubPath, QStringLiteral("img.png"), 0, QSize());
epubPath, QStringLiteral("img.png"), QSize());
});
QSignalSpy spy(&response, &QQuickImageResponse::finished);
response.cancel();
@@ -232,7 +200,7 @@ private slots:
AsyncImageResponse response([epubPath] {
return loadFromEpub(
epubPath, QStringLiteral("img.png"), 0, QSize());
epubPath, QStringLiteral("img.png"), QSize());
});
response.cancel();
response.run();
@@ -298,24 +266,6 @@ private slots:
delete resp;
}
void loadMethodHandlesEmbeddedUrlFormat()
{
const QString epubPath = buildEpubWithPng("img.png", 4, 4, qRgb(255, 0, 0));
QVERIFY(!epubPath.isEmpty());
EntryImageProvider provider = makeEpubProvider();
// m_epubPath is intentionally NOT set — embedded URL must supply it via query
const QString encodedPath = QString::fromUtf8(QUrl::toPercentEncoding(epubPath));
const QUrl url(QStringLiteral("image://epub/img.png?src=") + encodedPath);
const QImage img = provider.load(url, 0);
QFile::remove(epubPath);
QVERIFY(!img.isNull());
QCOMPARE(img.pixel(0, 0), qRgb(255, 0, 0));
}
void requestImageResponseFallsBackToProviderPath()
{
// Without a leading slash in id, the provider should use m_epubPath.
@@ -387,7 +337,7 @@ private slots:
QCOMPARE(source.listEntries(), QStringList{QStringLiteral("cover.png")});
const QImage img = EntryImageProvider::loadImageFromSource(
source, QStringLiteral("cover.png"), 0, QSize());
source, QStringLiteral("cover.png"), QSize());
QVERIFY(!source.contentHash().isEmpty());
QFile::remove(path);
+2 -13
View File
@@ -3,7 +3,6 @@
#include "backend/formats/FormatRegistry.h"
#include "backend/FormatReader.h"
#include "backend/IImageProvider.h"
#include "backend/IImageLoader.h"
#include "backend/formats/TxtReader.h"
#include "backend/formats/EpubReader.h"
#include "backend/formats/comic/CbzReader.h"
@@ -20,8 +19,7 @@ static FormatRegistry makeRegistry()
[] { return std::make_unique<TxtReader>(); }, nullptr},
{QStringLiteral("epub"), false, QStringLiteral("epub"),
[] { return std::make_unique<EpubReader>(); },
[] { return std::make_unique<ZipByteSource>(); },
/*loaderIncludesWeb=*/true},
[] { return std::make_unique<ZipByteSource>(); }},
{QStringLiteral("cbz"), false, QStringLiteral("cbz"),
[] { return std::make_unique<CbzReader>(); },
[] { return std::make_unique<ZipByteSource>(); }},
@@ -120,21 +118,12 @@ private slots:
QCOMPARE(dir->scheme(), QStringLiteral("dir"));
}
void formatsWithoutImagesHaveNoProviderOrLoader()
void formatsWithoutImagesHaveNoProvider()
{
auto registry = makeRegistry();
QVERIFY(registry.createImageProvider("plain.txt") == nullptr);
QVERIFY(registry.createImageLoader("plain.txt") == nullptr);
QVERIFY(registry.createImageProvider("file.xyz") == nullptr);
}
void createImageLoaderReturnsLoader()
{
auto registry = makeRegistry();
QVERIFY(registry.createImageLoader("comic.cbz") != nullptr);
// epub loader is a composite (epub + web) but still non-null
QVERIFY(registry.createImageLoader("book.epub") != nullptr);
}
};
QTEST_MAIN(FormatRegistryTest)
+1 -2
View File
@@ -22,8 +22,7 @@ static FormatRegistry makeRegistry()
[] { return std::make_unique<TxtReader>(); }, nullptr},
{QStringLiteral("epub"), false, QStringLiteral("epub"),
[] { return std::make_unique<EpubReader>(); },
[] { return std::make_unique<ZipByteSource>(); },
/*loaderIncludesWeb=*/true},
[] { return std::make_unique<ZipByteSource>(); }},
});
}
+59 -173
View File
@@ -51,6 +51,38 @@ public:
QString fileType() const override { return QStringLiteral("txt"); }
};
class FakeMangaReader : public FormatReader {
public:
bool open(const QString &) override { return true; }
QString lastError() override { return {}; }
int chapterCount() override { return 1; }
Chapter loadChapter(int index) override
{
if (index != 0) return {index, {}, {}};
return {0, QStringLiteral("Manga Title"),
{QStringLiteral("<img src=\"image://cbz/0.jpg\"/>"),
QStringLiteral("<img src=\"image://cbz/1.jpg\"/>"),
QStringLiteral("<img src=\"image://cbz/2.jpg\"/>")}};
}
QVector<QSize> chapterPageSizes(int index) const override
{
if (index != 0) return {};
return {QSize(800, 1200), QSize(800, 1200), QSize(800, 1200)};
}
RenderingMode preferredRenderingMode() const override { return RenderingMode::Manga; }
QList<TocEntry> tableOfContents() override { return {}; }
QString title() override { return QStringLiteral("Manga Title"); }
QString author() override { return QStringLiteral("Manga Author"); }
QString filePath() override { return QStringLiteral("/fake/manga.cbz"); }
QString coverImagePath() override { return QStringLiteral("0.jpg"); }
QByteArray contentHash() override { return QByteArray("mangahash"); }
bool loadMetadata(const QString &) override { return true; }
QString fileType() const override { return QStringLiteral("cbz"); }
};
class ReadingModelTest : public QObject {
Q_OBJECT
@@ -78,7 +110,9 @@ private slots:
QCOMPARE(model.totalChapters(), 0);
QCOMPARE(model.progress(), 0.0);
QVERIFY(model.chapterTitle().isEmpty());
QCOMPARE(model.rowCount(QModelIndex()), 0);
QCOMPARE(model.currentPage(), 0);
QCOMPARE(model.totalPages(), 0);
QVERIFY(!model.isMangaMode());
}
void setReaderLoadsAllChapters()
@@ -87,46 +121,11 @@ private slots:
FakeReader reader;
model.setReader(&reader);
// All 3 chapters × 2 chunks = 6 total rows
QCOMPARE(model.rowCount(QModelIndex()), 6);
QCOMPARE(model.totalChapters(), 3);
QCOMPARE(model.currentChapter(), 0);
QCOMPARE(model.chapterTitle(), QStringLiteral("Chapter 0"));
}
void chunkContentAcrossChapters()
{
Ctx ctx; ReadingModel model(*ctx.store);
FakeReader reader;
model.setReader(&reader);
// Chapter 0: chunks 0,1
QCOMPARE(model.data(model.index(0, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk A of 0</p>"));
QCOMPARE(model.data(model.index(1, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk B of 0</p>"));
// Chapter 1: chunks 2,3
QCOMPARE(model.data(model.index(2, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk A of 1</p>"));
QCOMPARE(model.data(model.index(3, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk B of 1</p>"));
// Chapter 2: chunks 4,5
QCOMPARE(model.data(model.index(4, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk A of 2</p>"));
QCOMPARE(model.data(model.index(5, 0), ReadingModel::ContentRole).toString(),
QStringLiteral("<p>Chunk B of 2</p>"));
}
void dataInvalidForOutOfRange()
{
Ctx ctx; ReadingModel model(*ctx.store);
FakeReader reader;
model.setReader(&reader);
QModelIndex badIdx = model.index(99, 0);
QVERIFY(!model.data(badIdx, ReadingModel::ContentRole).isValid());
}
void currentChapterDerivedFromScroll()
{
Ctx ctx; ReadingModel model(*ctx.store);
@@ -259,39 +258,6 @@ private slots:
QCOMPARE(model.totalChapters(), 0);
QCOMPARE(model.progress(), 0.0);
QVERIFY(model.chapterTitle().isEmpty());
QCOMPARE(model.rowCount(QModelIndex()), 0);
}
void roleNamesContainsContent()
{
Ctx ctx; ReadingModel model(*ctx.store);
QHash<int, QByteArray> roles = model.roleNames();
QVERIFY(roles.contains(ReadingModel::ContentRole));
QCOMPARE(roles.value(ReadingModel::ContentRole), QByteArray("content"));
}
void initialPageState()
{
Ctx ctx; ReadingModel model(*ctx.store);
QCOMPARE(model.currentPage(), 0);
QCOMPARE(model.totalPages(), 0);
}
void setScrollInfoUpdatesCurrentPage()
{
Ctx ctx; ReadingModel model(*ctx.store);
FakeReader reader;
model.setReader(&reader);
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, 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()
@@ -318,117 +284,37 @@ private slots:
QVERIFY(!model.hasChapters());
}
// --- Cover image tests ---
void coverImagePrependedToChunks()
void mangaModeDetectionAndPagination()
{
FakeReader reader;
Ctx ctx; ReadingModel model(*ctx.store);
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"));
}
FakeMangaReader reader;
QSignalSpy restoreSpy(&model, &ReadingModel::restoreReady);
void coverImageNotAddedWhenUrlEmpty()
{
FakeReader reader;
Ctx ctx; ReadingModel model(*ctx.store);
model.setReader(&reader);
model.setCoverImageUrl("");
// Should have only original chunks (no cover)
QCOMPARE(model.rowCount(QModelIndex()), 6);
}
void chapterNavigationSkipsCoverImage()
{
FakeReader reader;
Ctx ctx; ReadingModel model(*ctx.store);
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)
QVERIFY(model.isMangaMode());
QCOMPARE(model.imageUrlForChunk(0), QStringLiteral("image://cbz/0.jpg"));
QCOMPARE(model.imageUrlForChunk(1), QStringLiteral("image://cbz/1.jpg"));
QCOMPARE(model.imageUrlForChunk(2), QStringLiteral("image://cbz/2.jpg"));
QCOMPARE(model.totalPagePairs(), 3); // portrait mode: each chunk is solo
// 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)
}
// restoreReady should be queued and emitted
QTRY_COMPARE(restoreSpy.count(), 1);
QCOMPARE(restoreSpy.first().at(0).toInt(), 0);
void coverImageSetAfterReaderReloadsChunks()
{
FakeReader reader;
Ctx ctx; ReadingModel model(*ctx.store);
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;
Ctx ctx; ReadingModel model(*ctx.store);
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()
{
Ctx ctx; ReadingModel model(*ctx.store);
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()
{
Ctx ctx; ReadingModel model(*ctx.store);
QCOMPARE(model.totalPixelHeight(), 0.0);
}
void totalPixelHeightResetOnReaderSet()
{
Ctx ctx; ReadingModel model(*ctx.store);
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
// Landscape mode pairs portrait pages
model.setMangaLandscape(true);
// With pageShift ON (default): chunk 0 solo (cover), chunk 1 solo (shift), chunk 2 solo -> 3 pairs
// If pageShift OFF: chunk 0 solo (cover), chunks 1 and 2 paired -> 2 pairs
model.setPageShift(false);
QCOMPARE(model.totalPagePairs(), 2);
QVariantList pair0 = model.pagePair(0);
QCOMPARE(pair0.size(), 1);
QCOMPARE(pair0.at(0).toInt(), 0);
QVariantList pair1 = model.pagePair(1);
QCOMPARE(pair1.size(), 2);
QCOMPARE(pair1.at(0).toInt(), 1);
QCOMPARE(pair1.at(1).toInt(), 2);
}
};
+3 -13
View File
@@ -207,24 +207,14 @@ private slots:
ctx.book->openFromPath(path);
QTRY_VERIFY_WITH_TIMEOUT(ctx.book->hasBook(), 5000);
ctx.book->saveCurrentPosition(3, 17);
ctx.book->saveCurrentPosition(3, false, true);
const QByteArray hash = ctx.book->reader()->contentHash();
QVERIFY(!hash.isEmpty());
const BookPosition pos = ctx.store->load(hash);
QCOMPARE(pos.chunkIndex, 3);
QCOMPARE(pos.intraOffset, 17);
}
void contentWidthSignal()
{
Ctx ctx;
QSignalSpy spy(ctx.book, &Book::contentWidthChanged);
ctx.book->setContentWidth(800);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.first().first().toInt(), 800);
ctx.book->setContentWidth(800); // no-op
QCOMPARE(spy.count(), 1);
QCOMPARE(pos.mangaRTL, false);
QCOMPARE(pos.pageShift, true);
}
};
+20 -18
View File
@@ -21,8 +21,9 @@ private slots:
BookPositionStore store(appState);
const BookPosition pos = store.load(QByteArray("nonexistent"));
QCOMPARE(pos.chunkIndex, 0);
QCOMPARE(pos.intraOffset, 0);
QCOMPARE(pos.chunkIndex, 0);
QCOMPARE(pos.pageShift, true);
QCOMPARE(pos.mangaRTL, true);
}
void saveAndLoad()
@@ -35,10 +36,11 @@ private slots:
BookPositionStore store(appState);
const QByteArray hash = QByteArray("abc123deadbeef");
store.save(hash, 7, 42);
store.save(hash, 7, false, false);
const BookPosition pos = store.load(hash);
QCOMPARE(pos.chunkIndex, 7);
QCOMPARE(pos.intraOffset, 42);
QCOMPARE(pos.chunkIndex, 7);
QCOMPARE(pos.mangaRTL, false);
QCOMPARE(pos.pageShift, false);
}
void separateHashesStoredIndependently()
@@ -50,13 +52,13 @@ private slots:
AppState appState(s);
BookPositionStore store(appState);
store.save(QByteArray("hash1"), 1, 10);
store.save(QByteArray("hash2"), 2, 20);
store.save(QByteArray("hash1"), 1, true, false);
store.save(QByteArray("hash2"), 2, false, true);
QCOMPARE(store.load(QByteArray("hash1")).chunkIndex, 1);
QCOMPARE(store.load(QByteArray("hash2")).chunkIndex, 2);
QCOMPARE(store.load(QByteArray("hash1")).intraOffset, 10);
QCOMPARE(store.load(QByteArray("hash2")).intraOffset, 20);
QCOMPARE(store.load(QByteArray("hash1")).chunkIndex, 1);
QCOMPARE(store.load(QByteArray("hash2")).chunkIndex, 2);
QCOMPARE(store.load(QByteArray("hash1")).mangaRTL, true);
QCOMPARE(store.load(QByteArray("hash2")).mangaRTL, false);
}
void overwriteExistingPosition()
@@ -69,12 +71,13 @@ private slots:
BookPositionStore store(appState);
const QByteArray hash = QByteArray("overwrite-hash");
store.save(hash, 3, 30);
store.save(hash, 5, 55);
store.save(hash, 3, true, true);
store.save(hash, 5, false, false);
const BookPosition pos = store.load(hash);
QCOMPARE(pos.chunkIndex, 5);
QCOMPARE(pos.intraOffset, 55);
QCOMPARE(pos.chunkIndex, 5);
QCOMPARE(pos.mangaRTL, false);
QCOMPARE(pos.pageShift, false);
}
void emptyHashIgnored()
@@ -87,10 +90,9 @@ private slots:
BookPositionStore store(appState);
// Neither save nor load should crash with an empty hash
store.save(QByteArray(), 1, 1);
store.save(QByteArray(), 1, true, true);
const BookPosition pos = store.load(QByteArray());
QCOMPARE(pos.chunkIndex, 0);
QCOMPARE(pos.intraOffset, 0);
QCOMPARE(pos.chunkIndex, 0);
}
};