old render cleanup part 3
This commit is contained in:
45 files changed
+1057
-1135
No files matched your search
@@ -48,7 +48,6 @@ static bool addZipEntry(zipFile zf, const char *name, const QByteArray &data)
|
||||
return zipCloseFileInZip(zf) == ZIP_OK;
|
||||
}
|
||||
|
||||
// Create a QByteArray containing a valid PNG for an image of given size and color.
|
||||
static QByteArray makePng(int w, int h, QRgb color = qRgb(255, 0, 0))
|
||||
{
|
||||
QImage img(w, h, QImage::Format_RGB32);
|
||||
@@ -60,8 +59,6 @@ static QByteArray makePng(int w, int h, QRgb color = qRgb(255, 0, 0))
|
||||
return data;
|
||||
}
|
||||
|
||||
// Build a minimal CBZ containing a single image entry.
|
||||
// Returns the path of the temp file (caller removes).
|
||||
static QString buildCbzWithPng(const char *entryPath, int imgW, int imgH,
|
||||
QRgb color = qRgb(255, 0, 0))
|
||||
{
|
||||
@@ -124,19 +121,6 @@ private slots:
|
||||
QVERIFY(img.isNull());
|
||||
}
|
||||
|
||||
void clearResetsState()
|
||||
{
|
||||
const QString cbzPath = buildCbzWithPng("images/test.png", 4, 4);
|
||||
QVERIFY(!cbzPath.isEmpty());
|
||||
|
||||
const QImage img = loadFromCbz(
|
||||
QString{}, QStringLiteral("images/test.png"), QSize());
|
||||
|
||||
QFile::remove(cbzPath);
|
||||
|
||||
QVERIFY(img.isNull());
|
||||
}
|
||||
|
||||
void requestedSizeHonored()
|
||||
{
|
||||
const QString cbzPath = buildCbzWithPng("img.png", 400, 300);
|
||||
@@ -209,28 +193,9 @@ private slots:
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Embedded-path URL format tests
|
||||
// Embedded-path URL format tests (stateless provider)
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
void coverImageUrlEmbedsCbzPath()
|
||||
{
|
||||
const QString cbzPath = buildCbzWithPng("img.png", 4, 4);
|
||||
QVERIFY(!cbzPath.isEmpty());
|
||||
|
||||
EntryImageProvider provider = makeCbzProvider();
|
||||
provider.setFilePath(cbzPath);
|
||||
|
||||
const QString url = provider.coverImageUrl(QStringLiteral("cover.jpg"));
|
||||
|
||||
QFile::remove(cbzPath);
|
||||
|
||||
QVERIFY2(url.startsWith(QStringLiteral("image://cbz/cover.jpg?src=")),
|
||||
qPrintable("Expected query-param URL, got: " + url));
|
||||
const QString encodedPath = QString::fromUtf8(QUrl::toPercentEncoding(cbzPath));
|
||||
QVERIFY2(url.contains(encodedPath),
|
||||
qPrintable("URL should contain encoded cbz path. URL: " + url));
|
||||
}
|
||||
|
||||
void requestImageResponseUsesEmbeddedPath()
|
||||
{
|
||||
const QString cbzA = buildCbzWithPng("img.png", 4, 4, qRgb(255, 0, 0));
|
||||
@@ -238,7 +203,6 @@ private slots:
|
||||
QVERIFY(!cbzA.isEmpty() && !cbzB.isEmpty());
|
||||
|
||||
EntryImageProvider provider = makeCbzProvider();
|
||||
provider.setFilePath(cbzA); // configured for A
|
||||
|
||||
// Build an embedded-format id pointing to B via query parameter
|
||||
const QString encodedB = QString::fromUtf8(QUrl::toPercentEncoding(cbzB));
|
||||
@@ -260,45 +224,15 @@ private slots:
|
||||
delete resp;
|
||||
}
|
||||
|
||||
void requestImageResponseFallsBackToProviderPath()
|
||||
void requestImageResponseWithoutSourcePathReturnsNull()
|
||||
{
|
||||
const QString cbzA = buildCbzWithPng("img.png", 4, 4, qRgb(255, 0, 0));
|
||||
QVERIFY(!cbzA.isEmpty());
|
||||
|
||||
EntryImageProvider provider = makeCbzProvider();
|
||||
provider.setFilePath(cbzA);
|
||||
|
||||
QQuickImageResponse *resp = provider.requestImageResponse(
|
||||
QStringLiteral("img.png"), QSize());
|
||||
QSignalSpy spy(resp, &QQuickImageResponse::finished);
|
||||
QThreadPool::globalInstance()->waitForDone();
|
||||
if (spy.isEmpty()) spy.wait(5000);
|
||||
|
||||
QFile::remove(cbzA);
|
||||
|
||||
QVERIFY(resp->textureFactory() != nullptr);
|
||||
const QImage img = resp->textureFactory()->image();
|
||||
QVERIFY(!img.isNull());
|
||||
QCOMPARE(img.pixel(0, 0), qRgb(255, 0, 0));
|
||||
|
||||
delete resp;
|
||||
}
|
||||
|
||||
void responseAfterClearIsNull()
|
||||
{
|
||||
const QString cbzPath = buildCbzWithPng("img.png", 4, 4);
|
||||
QVERIFY(!cbzPath.isEmpty());
|
||||
|
||||
EntryImageProvider provider = makeCbzProvider();
|
||||
provider.setFilePath(cbzPath);
|
||||
provider.clear();
|
||||
|
||||
// Id without ?src= has no container to load from
|
||||
QQuickImageResponse *resp = provider.requestImageResponse(
|
||||
QStringLiteral("img.png"), QSize());
|
||||
QThreadPool::globalInstance()->waitForDone();
|
||||
|
||||
QFile::remove(cbzPath);
|
||||
|
||||
QVERIFY(resp->textureFactory() == nullptr);
|
||||
delete resp;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
#include <QtTest>
|
||||
#include <QTemporaryDir>
|
||||
#include <QQmlEngine>
|
||||
#include "backend/formats/FormatRegistry.h"
|
||||
#include "backend/FormatReader.h"
|
||||
#include "backend/IImageProvider.h"
|
||||
#include "backend/formats/comic/CbzReader.h"
|
||||
#include "backend/formats/comic/CbrReader.h"
|
||||
#include "backend/formats/comic/FolderReader.h"
|
||||
#include "backend/formats/sources/DirByteSource.h"
|
||||
#include "backend/formats/sources/RarByteSource.h"
|
||||
#include "backend/formats/sources/ZipByteSource.h"
|
||||
@@ -13,15 +10,12 @@
|
||||
static FormatRegistry makeRegistry()
|
||||
{
|
||||
return FormatRegistry({
|
||||
{QStringLiteral("cbz"), false, QStringLiteral("cbz"),
|
||||
[] { return std::make_unique<CbzReader>(); },
|
||||
[] { return std::make_unique<ZipByteSource>(); }},
|
||||
{QStringLiteral("cbr"), false, QStringLiteral("cbr"),
|
||||
[] { return std::make_unique<CbrReader>(); },
|
||||
[] { return std::make_unique<RarByteSource>(); }},
|
||||
{{}, /*matchesDirectory=*/true, QStringLiteral("dir"),
|
||||
[] { return std::make_unique<FolderReader>(); },
|
||||
[] { return std::make_unique<DirByteSource>(); }},
|
||||
FormatSpec::comic(QStringLiteral("cbz"), false, QStringLiteral("cbz"),
|
||||
[] { return std::make_unique<ZipByteSource>(); }),
|
||||
FormatSpec::comic(QStringLiteral("cbr"), false, QStringLiteral("cbr"),
|
||||
[] { return std::make_unique<RarByteSource>(); }),
|
||||
FormatSpec::comic({}, /*matchesDirectory=*/true, QStringLiteral("dir"),
|
||||
[] { return std::make_unique<DirByteSource>(); }),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,7 +26,9 @@ private slots:
|
||||
void createCbzReader()
|
||||
{
|
||||
auto registry = makeRegistry();
|
||||
QVERIFY(registry.createReader("file.cbz") != nullptr);
|
||||
auto reader = registry.createReader("file.cbz");
|
||||
QVERIFY(reader != nullptr);
|
||||
QCOMPARE(reader->mode(), ReadingMode::Comic);
|
||||
}
|
||||
|
||||
void createCbzReaderUpperCase()
|
||||
@@ -72,7 +68,7 @@ private slots:
|
||||
auto registry = makeRegistry();
|
||||
auto reader = registry.createReader(tmp.path());
|
||||
QVERIFY(reader != nullptr);
|
||||
QCOMPARE(reader->fileType(), QStringLiteral("folder"));
|
||||
QCOMPARE(reader->mode(), ReadingMode::Comic);
|
||||
}
|
||||
|
||||
void supportedExtensions()
|
||||
@@ -85,24 +81,16 @@ private slots:
|
||||
QCOMPARE(exts.size(), 2);
|
||||
}
|
||||
|
||||
void imageProviderSchemesMatchTable()
|
||||
void registerImageProvidersRegistersSchemes()
|
||||
{
|
||||
auto registry = makeRegistry();
|
||||
QQmlEngine engine;
|
||||
registry.registerImageProviders(engine);
|
||||
|
||||
std::unique_ptr<IImageProvider> cbz(registry.createImageProvider("comic.cbz"));
|
||||
QVERIFY(cbz);
|
||||
QCOMPARE(cbz->scheme(), QStringLiteral("cbz"));
|
||||
|
||||
QTemporaryDir tmp;
|
||||
std::unique_ptr<IImageProvider> dir(registry.createImageProvider(tmp.path()));
|
||||
QVERIFY(dir);
|
||||
QCOMPARE(dir->scheme(), QStringLiteral("dir"));
|
||||
}
|
||||
|
||||
void formatsWithoutImagesHaveNoProvider()
|
||||
{
|
||||
auto registry = makeRegistry();
|
||||
QVERIFY(registry.createImageProvider("file.xyz") == nullptr);
|
||||
QVERIFY(engine.imageProvider(QStringLiteral("cbz")) != nullptr);
|
||||
QVERIFY(engine.imageProvider(QStringLiteral("cbr")) != nullptr);
|
||||
QVERIFY(engine.imageProvider(QStringLiteral("dir")) != nullptr);
|
||||
QVERIFY(engine.imageProvider(QStringLiteral("unknown")) == nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QBuffer>
|
||||
#include <QDir>
|
||||
#include <QImage>
|
||||
#include <QSignalSpy>
|
||||
#include <QTemporaryFile>
|
||||
#include <QUrl>
|
||||
|
||||
#include <minizip/zip.h>
|
||||
|
||||
#include "backend/HistoryBookModel.h"
|
||||
#include "backend/FormatReader.h"
|
||||
#include "backend/formats/comic/CbzReader.h"
|
||||
#include "backend/formats/FormatRegistry.h"
|
||||
#include "backend/formats/sources/ZipByteSource.h"
|
||||
|
||||
static FormatRegistry makeRegistry()
|
||||
{
|
||||
return FormatRegistry({
|
||||
{QStringLiteral("cbz"), false, QStringLiteral("cbz"),
|
||||
[] { return std::make_unique<CbzReader>(); },
|
||||
[] { return std::make_unique<ZipByteSource>(); }},
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static bool addEntry(zipFile zf, const char *name, const QByteArray &data)
|
||||
{
|
||||
zip_fileinfo fi{};
|
||||
if (zipOpenNewFileInZip(zf, name, &fi,
|
||||
nullptr, 0, nullptr, 0, nullptr,
|
||||
Z_DEFLATED, Z_DEFAULT_COMPRESSION) != ZIP_OK)
|
||||
return false;
|
||||
if (zipWriteInFileInZip(zf, data.constData(), (unsigned)data.size()) != ZIP_OK) {
|
||||
zipCloseFileInZip(zf);
|
||||
return false;
|
||||
}
|
||||
return zipCloseFileInZip(zf) == ZIP_OK;
|
||||
}
|
||||
|
||||
static QByteArray makePng(int w = 4, int h = 4, QRgb color = qRgb(255, 0, 0))
|
||||
{
|
||||
QImage img(w, h, QImage::Format_RGB32);
|
||||
img.fill(color);
|
||||
QByteArray data;
|
||||
QBuffer buf(&data);
|
||||
buf.open(QIODevice::WriteOnly);
|
||||
img.save(&buf, "PNG");
|
||||
return data;
|
||||
}
|
||||
|
||||
static QString buildCbzWithCover()
|
||||
{
|
||||
static const char kComicInfo[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
"<ComicInfo>"
|
||||
" <Title>Cover Test Book</Title>"
|
||||
" <Writer>Test Author</Writer>"
|
||||
"</ComicInfo>";
|
||||
|
||||
QTemporaryFile tmp;
|
||||
tmp.setFileTemplate(QDir::tempPath() + "/hbm_cover_test_XXXXXX.cbz");
|
||||
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, "ComicInfo.xml", QByteArray(kComicInfo));
|
||||
ok = ok && addEntry(zf, "001_cover.png", makePng());
|
||||
|
||||
zipClose(zf, nullptr);
|
||||
return ok ? path : QString{};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Test class
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class HistoryBookModelTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void loadMetadataPopulatesCoverImageUrlForCbz()
|
||||
{
|
||||
const QString cbzPath = buildCbzWithCover();
|
||||
QVERIFY(!cbzPath.isEmpty());
|
||||
|
||||
FormatRegistry registry = makeRegistry();
|
||||
HistoryBookModel model(cbzPath, 0.0, QString(), registry);
|
||||
|
||||
QSignalSpy spy(&model, &HistoryBookModel::metadataLoaded);
|
||||
QSignalSpy coverSpy(&model, &HistoryBookModel::coverImageLoaded);
|
||||
model.loadMetadata();
|
||||
|
||||
QVERIFY(spy.wait(5000));
|
||||
|
||||
QFile::remove(cbzPath);
|
||||
|
||||
QCOMPARE(coverSpy.count(), 1);
|
||||
|
||||
const QString url = model.coverImageUrl();
|
||||
QVERIFY2(!url.isEmpty(), "coverImageUrl should be set after loadMetadata for a CBZ with cover");
|
||||
QVERIFY2(url.startsWith(QStringLiteral("image://cbz/001_cover.png?src=")),
|
||||
qPrintable("Expected query-param URL format, got: " + url));
|
||||
const QString encodedPath = QString::fromUtf8(QUrl::toPercentEncoding(cbzPath));
|
||||
QVERIFY2(url.contains(encodedPath),
|
||||
qPrintable("URL should contain encoded cbz path. URL: " + url));
|
||||
}
|
||||
|
||||
void loadMetadataLeavesCoverImageUrlEmptyForMissingFile()
|
||||
{
|
||||
FormatRegistry registry = makeRegistry();
|
||||
HistoryBookModel model(QStringLiteral("/nonexistent/file.cbz"), 0.0, QString(), registry);
|
||||
|
||||
QSignalSpy spy(&model, &HistoryBookModel::metadataLoaded);
|
||||
model.loadMetadata();
|
||||
|
||||
// Should finish or not crash, coverImageUrl remains empty
|
||||
QVERIFY2(model.coverImageUrl().isEmpty(),
|
||||
"Missing files have no cover; coverImageUrl should remain empty");
|
||||
}
|
||||
|
||||
void loadMetadataPopulatesTitle()
|
||||
{
|
||||
const QString cbzPath = buildCbzWithCover();
|
||||
QVERIFY(!cbzPath.isEmpty());
|
||||
|
||||
FormatRegistry registry = makeRegistry();
|
||||
HistoryBookModel model(cbzPath, 0.0, QString(), registry);
|
||||
|
||||
QSignalSpy spy(&model, &HistoryBookModel::metadataLoaded);
|
||||
model.loadMetadata();
|
||||
QVERIFY(spy.wait(5000));
|
||||
|
||||
QFile::remove(cbzPath);
|
||||
|
||||
QCOMPARE(model.title(), QStringLiteral("Cover Test Book"));
|
||||
QCOMPARE(model.author(), QStringLiteral("Test Author"));
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(HistoryBookModelTest)
|
||||
#include "HistoryBookModelTest.moc"
|
||||
@@ -0,0 +1,175 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QBuffer>
|
||||
#include <QDir>
|
||||
#include <QImage>
|
||||
#include <QSettings>
|
||||
#include <QSignalSpy>
|
||||
#include <QTemporaryFile>
|
||||
#include <QUrl>
|
||||
|
||||
#include <minizip/zip.h>
|
||||
|
||||
#include "backend/AppState.h"
|
||||
#include "backend/FormatReader.h"
|
||||
#include "backend/HistoryModel.h"
|
||||
#include "backend/formats/FormatRegistry.h"
|
||||
#include "backend/formats/sources/ZipByteSource.h"
|
||||
|
||||
static FormatRegistry makeRegistry()
|
||||
{
|
||||
return FormatRegistry({
|
||||
FormatSpec::comic(QStringLiteral("cbz"), false, QStringLiteral("cbz"),
|
||||
[] { return std::make_unique<ZipByteSource>(); }),
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static bool addEntry(zipFile zf, const char *name, const QByteArray &data)
|
||||
{
|
||||
zip_fileinfo fi{};
|
||||
if (zipOpenNewFileInZip(zf, name, &fi,
|
||||
nullptr, 0, nullptr, 0, nullptr,
|
||||
Z_DEFLATED, Z_DEFAULT_COMPRESSION) != ZIP_OK)
|
||||
return false;
|
||||
if (zipWriteInFileInZip(zf, data.constData(), (unsigned)data.size()) != ZIP_OK) {
|
||||
zipCloseFileInZip(zf);
|
||||
return false;
|
||||
}
|
||||
return zipCloseFileInZip(zf) == ZIP_OK;
|
||||
}
|
||||
|
||||
static QByteArray makePng(int w = 4, int h = 4, QRgb color = qRgb(255, 0, 0))
|
||||
{
|
||||
QImage img(w, h, QImage::Format_RGB32);
|
||||
img.fill(color);
|
||||
QByteArray data;
|
||||
QBuffer buf(&data);
|
||||
buf.open(QIODevice::WriteOnly);
|
||||
img.save(&buf, "PNG");
|
||||
return data;
|
||||
}
|
||||
|
||||
static QString buildCbzWithCover()
|
||||
{
|
||||
static const char kComicInfo[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
"<ComicInfo>"
|
||||
" <Title>Cover Test Book</Title>"
|
||||
" <Writer>Test Author</Writer>"
|
||||
"</ComicInfo>";
|
||||
|
||||
QTemporaryFile tmp;
|
||||
tmp.setFileTemplate(QDir::tempPath() + "/hbm_cover_test_XXXXXX.cbz");
|
||||
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, "ComicInfo.xml", QByteArray(kComicInfo));
|
||||
ok = ok && addEntry(zf, "001_cover.png", makePng());
|
||||
|
||||
zipClose(zf, nullptr);
|
||||
return ok ? path : QString{};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Test class
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class HistoryModelTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void addOrUpdateAndRoles()
|
||||
{
|
||||
FormatRegistry registry = makeRegistry();
|
||||
HistoryModel model(registry);
|
||||
|
||||
QSignalSpy countSpy(&model, &HistoryModel::countChanged);
|
||||
model.addOrUpdateBook(QStringLiteral("/path/to/book.cbz"), 0.42, QStringLiteral("2026-01-01"));
|
||||
|
||||
QCOMPARE(countSpy.count(), 1);
|
||||
QCOMPARE(model.rowCount(), 1);
|
||||
|
||||
const QModelIndex idx = model.index(0, 0);
|
||||
QCOMPARE(model.data(idx, HistoryModel::FilePathRole).toString(), QStringLiteral("/path/to/book.cbz"));
|
||||
QCOMPARE(model.data(idx, HistoryModel::ProgressRole).toDouble(), 0.42);
|
||||
QCOMPARE(model.data(idx, HistoryModel::LastOpenedRole).toString(), QStringLiteral("2026-01-01"));
|
||||
QCOMPARE(model.data(idx, HistoryModel::FormatRole).toString(), QStringLiteral("CBZ"));
|
||||
}
|
||||
|
||||
void loadMetadataPopulatesTitleAndCoverUrl()
|
||||
{
|
||||
const QString cbzPath = buildCbzWithCover();
|
||||
QVERIFY(!cbzPath.isEmpty());
|
||||
|
||||
FormatRegistry registry = makeRegistry();
|
||||
HistoryModel model(registry);
|
||||
|
||||
QSignalSpy dataSpy(&model, &QAbstractListModel::dataChanged);
|
||||
model.addOrUpdateBook(cbzPath, 0.0);
|
||||
|
||||
QTRY_VERIFY_WITH_TIMEOUT(dataSpy.count() > 0, 5000);
|
||||
|
||||
QFile::remove(cbzPath);
|
||||
|
||||
const QModelIndex idx = model.index(0, 0);
|
||||
QCOMPARE(model.data(idx, HistoryModel::TitleRole).toString(), QStringLiteral("Cover Test Book"));
|
||||
QCOMPARE(model.data(idx, HistoryModel::AuthorRole).toString(), QStringLiteral("Test Author"));
|
||||
|
||||
const QString coverUrl = model.data(idx, HistoryModel::CoverImageUrlRole).toString();
|
||||
QVERIFY(!coverUrl.isEmpty());
|
||||
QVERIFY(coverUrl.startsWith(QStringLiteral("image://cbz/001_cover.png?src=")));
|
||||
}
|
||||
|
||||
void removeBook()
|
||||
{
|
||||
FormatRegistry registry = makeRegistry();
|
||||
HistoryModel model(registry);
|
||||
|
||||
model.addOrUpdateBook(QStringLiteral("/path/to/1.cbz"), 0.1);
|
||||
model.addOrUpdateBook(QStringLiteral("/path/to/2.cbz"), 0.2);
|
||||
QCOMPARE(model.rowCount(), 2);
|
||||
|
||||
model.removeBook(QStringLiteral("/path/to/1.cbz"));
|
||||
QCOMPARE(model.rowCount(), 1);
|
||||
QCOMPARE(model.filePath(0), QStringLiteral("/path/to/2.cbz"));
|
||||
}
|
||||
|
||||
void loadAndSaveWithAppState()
|
||||
{
|
||||
QTemporaryFile f;
|
||||
f.setFileTemplate(QDir::tempPath() + QStringLiteral("/hist-test-XXXXXX.ini"));
|
||||
(void)f.open(); f.close();
|
||||
QSettings s(f.fileName(), QSettings::IniFormat);
|
||||
AppState appState(s);
|
||||
|
||||
FormatRegistry registry = makeRegistry();
|
||||
|
||||
{
|
||||
HistoryModel model(registry);
|
||||
model.addOrUpdateBook(QStringLiteral("/path/to/book.cbz"), 0.75, QStringLiteral("2026-10-25"));
|
||||
model.save(appState);
|
||||
}
|
||||
|
||||
{
|
||||
HistoryModel model2(registry);
|
||||
model2.load(appState);
|
||||
QCOMPARE(model2.rowCount(), 1);
|
||||
QCOMPARE(model2.filePath(0), QStringLiteral("/path/to/book.cbz"));
|
||||
QCOMPARE(model2.progress(0), 0.75);
|
||||
QCOMPARE(model2.lastOpened(0), QStringLiteral("2026-10-25"));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(HistoryModelTest)
|
||||
#include "HistoryModelTest.moc"
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
|
||||
class FakeMangaReader : public FormatReader {
|
||||
public:
|
||||
ReadingMode mode() const override { return ReadingMode::Comic; }
|
||||
bool open(const QString &) override { return true; }
|
||||
QString lastError() override { return {}; }
|
||||
QString lastError() const override { return {}; }
|
||||
QVector<PageInfo> pages() const override
|
||||
{
|
||||
return {
|
||||
@@ -20,13 +21,37 @@ public:
|
||||
{QStringLiteral("image://cbz/2.jpg"), QSize(800, 1200)}
|
||||
};
|
||||
}
|
||||
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"); }
|
||||
QString title() const override { return QStringLiteral("Manga Title"); }
|
||||
QString author() const override { return QStringLiteral("Manga Author"); }
|
||||
QString filePath() const override { return QStringLiteral("/fake/manga.cbz"); }
|
||||
QString coverImageUrl() const override { return QStringLiteral("image://cbz/0.jpg?src=/fake/manga.cbz"); }
|
||||
QByteArray contentHash() const override { return QByteArray("mangahash"); }
|
||||
bool loadMetadata(const QString &) override { return true; }
|
||||
QString fileType() const override { return QStringLiteral("cbz"); }
|
||||
};
|
||||
|
||||
class FakeTextReader : public FormatReader {
|
||||
public:
|
||||
ReadingMode mode() const override { return ReadingMode::Text; }
|
||||
bool open(const QString &) override { return true; }
|
||||
QString lastError() const override { return {}; }
|
||||
QString title() const override { return QStringLiteral("Text Book"); }
|
||||
QString author() const override { return QStringLiteral("Text Author"); }
|
||||
QString filePath() const override { return QStringLiteral("/fake/book.epub"); }
|
||||
QString coverImageUrl() const override { return QStringLiteral("image://epub/cover.jpg?src=/fake/book.epub"); }
|
||||
QByteArray contentHash() const override { return QByteArray("texthash"); }
|
||||
bool loadMetadata(const QString &) override { return true; }
|
||||
|
||||
int chapterCount() const override { return 2; }
|
||||
Chapter loadChapter(int index) const override
|
||||
{
|
||||
if (index == 0)
|
||||
return {0, QStringLiteral("Chapter 1"), {QStringLiteral("<p>Chunk 1</p>"), QStringLiteral("<p>Chunk 2</p>")}};
|
||||
return {1, QStringLiteral("Chapter 2"), {QStringLiteral("<p>Chunk 3</p>")}};
|
||||
}
|
||||
QVector<TocEntry> tableOfContents() const override
|
||||
{
|
||||
return {{QStringLiteral("Chapter 1"), 0, 0}, {QStringLiteral("Chapter 2"), 1, 0}};
|
||||
}
|
||||
};
|
||||
|
||||
class ReadingModelTest : public QObject {
|
||||
@@ -53,6 +78,7 @@ private slots:
|
||||
void initialState()
|
||||
{
|
||||
Ctx ctx; ReadingModel model(*ctx.store);
|
||||
QVERIFY(!model.isTextMode());
|
||||
QCOMPARE(model.progress(), 0.0);
|
||||
QCOMPARE(model.currentPage(), 0);
|
||||
QCOMPARE(model.totalPages(), 0);
|
||||
@@ -69,6 +95,7 @@ private slots:
|
||||
|
||||
model.setReader(&reader);
|
||||
|
||||
QVERIFY(!model.isTextMode());
|
||||
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"));
|
||||
@@ -80,18 +107,24 @@ private slots:
|
||||
QCOMPARE(restoreSpy.first().at(0).toInt(), 0);
|
||||
}
|
||||
|
||||
void scrollInfoUpdatesCurrentPageAndProgress()
|
||||
void scrollInfoUpdatesCurrentPageAndProgressAndSaves()
|
||||
{
|
||||
Ctx ctx; ReadingModel model(*ctx.store);
|
||||
FakeMangaReader reader;
|
||||
model.setReader(&reader);
|
||||
|
||||
QSignalSpy pageSpy(&model, &ReadingModel::currentPageChanged);
|
||||
QSignalSpy savedSpy(&model, &ReadingModel::positionSaved);
|
||||
model.setScrollInfo(1, 0.5);
|
||||
|
||||
QCOMPARE(model.currentPage(), 2);
|
||||
QCOMPARE(model.progress(), 0.5);
|
||||
QCOMPARE(pageSpy.count(), 1);
|
||||
QCOMPARE(savedSpy.count(), 1);
|
||||
|
||||
const auto savedPos = ctx.store->load(reader.contentHash());
|
||||
QCOMPARE(savedPos.chunkIndex, 1);
|
||||
QCOMPARE(savedPos.progress, 0.5);
|
||||
}
|
||||
|
||||
void landscapeModeAndPageShift()
|
||||
@@ -134,6 +167,44 @@ private slots:
|
||||
QVERIFY(!model.mangaRTL());
|
||||
}
|
||||
|
||||
void textModeChaptersAndChunks()
|
||||
{
|
||||
Ctx ctx; ReadingModel model(*ctx.store);
|
||||
FakeTextReader reader;
|
||||
QSignalSpy modeSpy(&model, &ReadingModel::modeChanged);
|
||||
QSignalSpy restoreSpy(&model, &ReadingModel::restoreReady);
|
||||
|
||||
model.setReader(&reader);
|
||||
|
||||
QCOMPARE(modeSpy.count(), 1);
|
||||
QVERIFY(model.isTextMode());
|
||||
QCOMPARE(model.chapterCount(), 2);
|
||||
QCOMPARE(model.currentChapter(), 0);
|
||||
QCOMPARE(model.chapterTitle(), QStringLiteral("Chapter 1"));
|
||||
QCOMPARE(model.rowCount(), 2);
|
||||
QCOMPARE(model.data(model.index(0, 0), ReadingModel::ContentRole).toString(),
|
||||
QStringLiteral("<p>Chunk 1</p>"));
|
||||
QCOMPARE(model.data(model.index(1, 0), ReadingModel::ContentRole).toString(),
|
||||
QStringLiteral("<p>Chunk 2</p>"));
|
||||
|
||||
QTRY_COMPARE(restoreSpy.count(), 1);
|
||||
|
||||
// Next chapter navigation
|
||||
QSignalSpy chapterSpy(&model, &ReadingModel::currentChapterChanged);
|
||||
model.nextChapter();
|
||||
QCOMPARE(chapterSpy.count(), 1);
|
||||
QCOMPARE(model.currentChapter(), 1);
|
||||
QCOMPARE(model.chapterTitle(), QStringLiteral("Chapter 2"));
|
||||
QCOMPARE(model.rowCount(), 1);
|
||||
QCOMPARE(model.data(model.index(0, 0), ReadingModel::ContentRole).toString(),
|
||||
QStringLiteral("<p>Chunk 3</p>"));
|
||||
|
||||
// Previous chapter navigation
|
||||
model.previousChapter();
|
||||
QCOMPARE(model.currentChapter(), 0);
|
||||
QCOMPARE(model.rowCount(), 2);
|
||||
}
|
||||
|
||||
void setReaderNullResetsState()
|
||||
{
|
||||
Ctx ctx; ReadingModel model(*ctx.store);
|
||||
@@ -145,6 +216,8 @@ private slots:
|
||||
QCOMPARE(model.totalPages(), 0);
|
||||
QCOMPARE(model.currentPage(), 0);
|
||||
QCOMPARE(model.progress(), 0.0);
|
||||
QVERIFY(!model.isTextMode());
|
||||
QCOMPARE(model.rowCount(), 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+5
-40
@@ -1,17 +1,13 @@
|
||||
#include <QtTest>
|
||||
#include <QDir>
|
||||
#include <QImage>
|
||||
#include <QSettings>
|
||||
#include <QSignalSpy>
|
||||
#include <QTemporaryDir>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
#include "backend/AppState.h"
|
||||
#include "backend/IFileDialogService.h"
|
||||
#include "backend/formats/FormatRegistry.h"
|
||||
#include "backend/formats/comic/FolderReader.h"
|
||||
#include "backend/formats/sources/DirByteSource.h"
|
||||
#include "backend/state/BookPositionStore.h"
|
||||
#include "backend/book/Book.h"
|
||||
|
||||
// Minimal fake dialog service — never opens a dialog; used to satisfy the Book constructor.
|
||||
@@ -37,35 +33,22 @@ private:
|
||||
}
|
||||
|
||||
struct Ctx {
|
||||
QTemporaryFile f;
|
||||
QSettings *s = nullptr;
|
||||
AppState *appState = nullptr;
|
||||
BookPositionStore *store = nullptr;
|
||||
FakeDialogService *dialog = nullptr;
|
||||
FormatRegistry *factory = nullptr;
|
||||
Book *book = nullptr;
|
||||
|
||||
Ctx() {
|
||||
f.setFileTemplate(QDir::tempPath() + QStringLiteral("/book-test-XXXXXX.ini"));
|
||||
(void)f.open(); f.close();
|
||||
s = new QSettings(f.fileName(), QSettings::IniFormat);
|
||||
appState = new AppState(*s);
|
||||
store = new BookPositionStore(*appState);
|
||||
dialog = new FakeDialogService;
|
||||
factory = new FormatRegistry({
|
||||
{{}, /*matchesDirectory=*/true, QStringLiteral("dir"),
|
||||
[] { return std::make_unique<FolderReader>(); },
|
||||
[] { return std::make_unique<DirByteSource>(); }},
|
||||
FormatSpec::comic({}, /*matchesDirectory=*/true, QStringLiteral("dir"),
|
||||
[] { return std::make_unique<DirByteSource>(); }),
|
||||
});
|
||||
book = new Book(*dialog, *store, *factory);
|
||||
book = new Book(*dialog, *factory);
|
||||
}
|
||||
~Ctx() {
|
||||
delete book;
|
||||
delete dialog;
|
||||
delete factory;
|
||||
delete store;
|
||||
delete appState;
|
||||
delete s;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -80,6 +63,7 @@ private slots:
|
||||
QCOMPARE(ctx.book->filePath(), QString());
|
||||
QCOMPARE(ctx.book->coverImageUrl(),QString());
|
||||
QCOMPARE(ctx.book->errorMessage(), QString());
|
||||
QVERIFY(ctx.book->tableOfContents().isEmpty());
|
||||
}
|
||||
|
||||
void openValidFile()
|
||||
@@ -101,6 +85,7 @@ private slots:
|
||||
QCOMPARE(ctx.book->filePath(), path);
|
||||
QVERIFY(!ctx.book->title().isEmpty());
|
||||
QVERIFY(bookChanged.count() > 0);
|
||||
QVERIFY(ctx.book->coverImageUrl().startsWith(QStringLiteral("image://dir/")));
|
||||
}
|
||||
|
||||
void openInvalidPath()
|
||||
@@ -181,26 +166,6 @@ private slots:
|
||||
ctx.dialog->triggerFile(path);
|
||||
QTRY_VERIFY_WITH_TIMEOUT(ctx.book->hasBook(), 5000);
|
||||
}
|
||||
|
||||
void saveCurrentPositionUsesHash()
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
const QString path = createSampleComic(tmp);
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
Ctx ctx;
|
||||
ctx.book->openFromPath(path);
|
||||
QTRY_VERIFY_WITH_TIMEOUT(ctx.book->hasBook(), 5000);
|
||||
|
||||
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.mangaRTL, false);
|
||||
QCOMPARE(pos.pageShift, true);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(BookTest)
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
#include <minizip/zip.h>
|
||||
|
||||
#include "backend/formats/comic/CbzReader.h"
|
||||
#include "backend/formats/comic/ComicReader.h"
|
||||
#include "backend/formats/sources/ZipByteSource.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Fixture helpers
|
||||
@@ -67,6 +68,11 @@ static QString buildCbz(const QList<QPair<QString, QByteArray>> &entries)
|
||||
return path;
|
||||
}
|
||||
|
||||
static ComicReader makeCbzReader()
|
||||
{
|
||||
return ComicReader([] { return std::make_unique<ZipByteSource>(); }, QStringLiteral("cbz"));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Test class
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -95,7 +101,7 @@ private slots:
|
||||
|
||||
void openNonexistentFile()
|
||||
{
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(!reader.open("/does/not/exist.cbz"));
|
||||
QVERIFY(!reader.lastError().isEmpty());
|
||||
}
|
||||
@@ -109,7 +115,7 @@ private slots:
|
||||
tmp.close();
|
||||
m_tempFiles.append(tmp.fileName());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(!reader.open(tmp.fileName()));
|
||||
QVERIFY(!reader.lastError().isEmpty());
|
||||
}
|
||||
@@ -119,7 +125,7 @@ private slots:
|
||||
const QString path = makeCbz({{"readme.txt", "hello"}});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(!reader.open(path));
|
||||
QVERIFY(!reader.lastError().isEmpty());
|
||||
}
|
||||
@@ -135,7 +141,7 @@ private slots:
|
||||
});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.open(path));
|
||||
QCOMPARE(reader.pages().size(), 3);
|
||||
}
|
||||
@@ -150,7 +156,7 @@ private slots:
|
||||
});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.open(path));
|
||||
const auto pages = reader.pages();
|
||||
QCOMPARE(pages.size(), 3);
|
||||
@@ -167,19 +173,20 @@ private slots:
|
||||
});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.open(path));
|
||||
const auto pages = reader.pages();
|
||||
QCOMPARE(pages.size(), 2);
|
||||
|
||||
for (const PageInfo &page : pages) {
|
||||
QVERIFY(page.imageUrl.startsWith(QLatin1String("image://cbz/")));
|
||||
QVERIFY(page.imageUrl.contains(QLatin1String("?src=")));
|
||||
}
|
||||
}
|
||||
|
||||
void emptyPagesBeforeOpen()
|
||||
{
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.pages().isEmpty());
|
||||
}
|
||||
|
||||
@@ -197,7 +204,7 @@ private slots:
|
||||
});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.open(path));
|
||||
QCOMPARE(reader.title(), QStringLiteral("My Comic"));
|
||||
QCOMPARE(reader.author(), QStringLiteral("Art Spiegelman"));
|
||||
@@ -215,7 +222,7 @@ private slots:
|
||||
});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.open(path));
|
||||
QCOMPARE(reader.title(), QStringLiteral("Batman #42"));
|
||||
}
|
||||
@@ -235,7 +242,7 @@ private slots:
|
||||
});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.open(path));
|
||||
QCOMPARE(reader.title(), QStringLiteral("Special Edition"));
|
||||
}
|
||||
@@ -247,7 +254,7 @@ private slots:
|
||||
const QString path = makeCbz({{"page001.png", makePng()}});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.open(path));
|
||||
QVERIFY(!reader.title().isEmpty());
|
||||
// Title must equal the file's base name (no extension)
|
||||
@@ -266,9 +273,10 @@ private slots:
|
||||
});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.open(path));
|
||||
QCOMPARE(reader.coverImagePath(), QStringLiteral("page001.jpg"));
|
||||
QVERIFY(reader.coverImageUrl().contains(QStringLiteral("page001.jpg")));
|
||||
QVERIFY(reader.coverImageUrl().startsWith(QStringLiteral("image://cbz/")));
|
||||
}
|
||||
|
||||
void coverFromComicInfoFrontCover()
|
||||
@@ -291,9 +299,9 @@ private slots:
|
||||
});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.open(path));
|
||||
QCOMPARE(reader.coverImagePath(), QStringLiteral("page002.jpg"));
|
||||
QVERIFY(reader.coverImageUrl().contains(QStringLiteral("page002.jpg")));
|
||||
}
|
||||
|
||||
// --- content hash ---
|
||||
@@ -303,7 +311,8 @@ private slots:
|
||||
const QString path = makeCbz({{"page001.png", makePng()}});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader r1, r2;
|
||||
auto r1 = makeCbzReader();
|
||||
auto r2 = makeCbzReader();
|
||||
QVERIFY(r1.open(path));
|
||||
QVERIFY(r2.open(path));
|
||||
QVERIFY(!r1.contentHash().isEmpty());
|
||||
@@ -312,7 +321,7 @@ private slots:
|
||||
|
||||
void contentHashEmptyBeforeOpen()
|
||||
{
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.contentHash().isEmpty());
|
||||
}
|
||||
|
||||
@@ -330,7 +339,7 @@ private slots:
|
||||
});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.loadMetadata(path));
|
||||
QCOMPARE(reader.title(), QStringLiteral("Light Meta"));
|
||||
// contentHash must be empty (loadMetadata is lightweight)
|
||||
@@ -345,17 +354,17 @@ private slots:
|
||||
});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.loadMetadata(path));
|
||||
QCOMPARE(reader.coverImagePath(), QStringLiteral("page001.jpg"));
|
||||
QVERIFY(reader.coverImageUrl().contains(QStringLiteral("page001.jpg")));
|
||||
}
|
||||
|
||||
// --- file type ---
|
||||
// --- reading mode ---
|
||||
|
||||
void fileType()
|
||||
void readingMode()
|
||||
{
|
||||
CbzReader reader;
|
||||
QCOMPARE(reader.fileType(), QStringLiteral("cbz"));
|
||||
auto reader = makeCbzReader();
|
||||
QCOMPARE(reader.mode(), ReadingMode::Comic);
|
||||
}
|
||||
|
||||
// --- skips __MACOSX entries ---
|
||||
@@ -368,7 +377,7 @@ private slots:
|
||||
});
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
CbzReader reader;
|
||||
auto reader = makeCbzReader();
|
||||
QVERIFY(reader.open(path));
|
||||
QCOMPARE(reader.pages().size(), 1);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#include <QImage>
|
||||
#include <QTemporaryDir>
|
||||
|
||||
#include "backend/formats/comic/FolderReader.h"
|
||||
#include "backend/formats/comic/ComicReader.h"
|
||||
#include "backend/formats/sources/DirByteSource.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
@@ -16,6 +17,11 @@ static bool writePng(const QString &path, int w = 8, int h = 8, QColor color = Q
|
||||
return img.save(path, "PNG");
|
||||
}
|
||||
|
||||
static ComicReader makeFolderReader()
|
||||
{
|
||||
return ComicReader([] { return std::make_unique<DirByteSource>(); }, QStringLiteral("dir"));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -28,7 +34,7 @@ private slots:
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
QVERIFY(tmp.isValid());
|
||||
FolderReader reader;
|
||||
auto reader = makeFolderReader();
|
||||
QVERIFY(!reader.open(tmp.path())); // no images → error
|
||||
}
|
||||
|
||||
@@ -40,7 +46,7 @@ private slots:
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("02.png"))));
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("03.png"))));
|
||||
|
||||
FolderReader reader;
|
||||
auto reader = makeFolderReader();
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
QCOMPARE(reader.pages().size(), 3);
|
||||
}
|
||||
@@ -53,7 +59,7 @@ private slots:
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("a.png"))));
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("b.png"))));
|
||||
|
||||
FolderReader reader;
|
||||
auto reader = makeFolderReader();
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
const auto pages = reader.pages();
|
||||
QCOMPARE(pages.size(), 3);
|
||||
@@ -69,9 +75,10 @@ private slots:
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("01.png"))));
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("02.png"))));
|
||||
|
||||
FolderReader reader;
|
||||
auto reader = makeFolderReader();
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
QCOMPARE(reader.coverImagePath(), QStringLiteral("01.png"));
|
||||
QVERIFY(reader.coverImageUrl().contains(QStringLiteral("01.png")));
|
||||
QVERIFY(reader.coverImageUrl().startsWith(QStringLiteral("image://dir/")));
|
||||
}
|
||||
|
||||
void titleIsFolderBasename()
|
||||
@@ -80,7 +87,7 @@ private slots:
|
||||
QVERIFY(tmp.isValid());
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("page.png"))));
|
||||
|
||||
FolderReader reader;
|
||||
auto reader = makeFolderReader();
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
QCOMPARE(reader.title(), QDir(tmp.path()).dirName());
|
||||
}
|
||||
@@ -94,16 +101,17 @@ private slots:
|
||||
QVERIFY(writePng(tmpA.filePath(QStringLiteral("page.png"))));
|
||||
QVERIFY(writePng(tmpB.filePath(QStringLiteral("page.png"))));
|
||||
|
||||
FolderReader ra, rb;
|
||||
auto ra = makeFolderReader();
|
||||
auto rb = makeFolderReader();
|
||||
QVERIFY(ra.open(tmpA.path()));
|
||||
QVERIFY(rb.open(tmpB.path()));
|
||||
QCOMPARE(ra.contentHash(), rb.contentHash());
|
||||
}
|
||||
|
||||
void fileType()
|
||||
void readingMode()
|
||||
{
|
||||
FolderReader reader;
|
||||
QCOMPARE(reader.fileType(), QStringLiteral("folder"));
|
||||
auto reader = makeFolderReader();
|
||||
QCOMPARE(reader.mode(), ReadingMode::Comic);
|
||||
}
|
||||
|
||||
void nonImageFilesIgnored()
|
||||
@@ -117,7 +125,7 @@ private slots:
|
||||
txt.write("hello");
|
||||
txt.close();
|
||||
|
||||
FolderReader reader;
|
||||
auto reader = makeFolderReader();
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
QCOMPARE(reader.pages().size(), 1);
|
||||
}
|
||||
@@ -129,7 +137,7 @@ private slots:
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("page.png"))));
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral(".hidden.png"))));
|
||||
|
||||
FolderReader reader;
|
||||
auto reader = makeFolderReader();
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
QCOMPARE(reader.pages().size(), 1);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,34 @@ private slots:
|
||||
const auto parsed = ImageUrl::parseProviderId(QStringLiteral("page%2001.jpg"));
|
||||
QCOMPARE(parsed.entry, QStringLiteral("page 01.jpg"));
|
||||
}
|
||||
|
||||
void resolveWebUrls()
|
||||
{
|
||||
const QString book = QStringLiteral("/books/test.epub");
|
||||
QCOMPARE(ImageUrl::resolve(QStringLiteral("epub"), QStringLiteral("http://example.com/pic.png"), book),
|
||||
QStringLiteral("image://web/http://example.com/pic.png"));
|
||||
QCOMPARE(ImageUrl::resolve(QStringLiteral("epub"), QStringLiteral("https://example.com/pic.png"), book),
|
||||
QStringLiteral("image://web/https://example.com/pic.png"));
|
||||
}
|
||||
|
||||
void resolveRelativeUrlsWithBaseDir()
|
||||
{
|
||||
const QString book = QStringLiteral("/books/test.epub");
|
||||
const QString url = ImageUrl::resolve(QStringLiteral("epub"),
|
||||
QStringLiteral("../images/pic.png"),
|
||||
book,
|
||||
QStringLiteral("OEBPS/text/"));
|
||||
QVERIFY(url.startsWith(QStringLiteral("image://epub/OEBPS/images/pic.png?src=")));
|
||||
}
|
||||
|
||||
void resolveFb2Fragment()
|
||||
{
|
||||
const QString book = QStringLiteral("/books/test.fb2");
|
||||
const QString url = ImageUrl::resolve(QStringLiteral("fb2"),
|
||||
QStringLiteral("#cover.png"),
|
||||
book);
|
||||
QVERIFY(url.startsWith(QStringLiteral("image://fb2/cover.png?src=")));
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(ImageUrlTest)
|
||||
|
||||
@@ -21,9 +21,11 @@ private slots:
|
||||
BookPositionStore store(appState);
|
||||
|
||||
const BookPosition pos = store.load(QByteArray("nonexistent"));
|
||||
QCOMPARE(pos.chapterIndex, 0);
|
||||
QCOMPARE(pos.chunkIndex, 0);
|
||||
QCOMPARE(pos.pageShift, true);
|
||||
QCOMPARE(pos.mangaRTL, true);
|
||||
QCOMPARE(pos.progress, 0.0);
|
||||
QCOMPARE(pos.pageShift, true);
|
||||
QCOMPARE(pos.mangaRTL, true);
|
||||
}
|
||||
|
||||
void saveAndLoad()
|
||||
@@ -36,11 +38,20 @@ private slots:
|
||||
BookPositionStore store(appState);
|
||||
|
||||
const QByteArray hash = QByteArray("abc123deadbeef");
|
||||
store.save(hash, 7, false, false);
|
||||
BookPosition toSave;
|
||||
toSave.chapterIndex = 2;
|
||||
toSave.chunkIndex = 7;
|
||||
toSave.progress = 0.65;
|
||||
toSave.mangaRTL = false;
|
||||
toSave.pageShift = false;
|
||||
store.save(hash, toSave);
|
||||
|
||||
const BookPosition pos = store.load(hash);
|
||||
QCOMPARE(pos.chapterIndex, 2);
|
||||
QCOMPARE(pos.chunkIndex, 7);
|
||||
QCOMPARE(pos.mangaRTL, false);
|
||||
QCOMPARE(pos.pageShift, false);
|
||||
QCOMPARE(pos.progress, 0.65);
|
||||
QCOMPARE(pos.mangaRTL, false);
|
||||
QCOMPARE(pos.pageShift, false);
|
||||
}
|
||||
|
||||
void separateHashesStoredIndependently()
|
||||
@@ -52,8 +63,17 @@ private slots:
|
||||
AppState appState(s);
|
||||
BookPositionStore store(appState);
|
||||
|
||||
store.save(QByteArray("hash1"), 1, true, false);
|
||||
store.save(QByteArray("hash2"), 2, false, true);
|
||||
BookPosition p1;
|
||||
p1.chunkIndex = 1;
|
||||
p1.mangaRTL = true;
|
||||
p1.pageShift = false;
|
||||
store.save(QByteArray("hash1"), p1);
|
||||
|
||||
BookPosition p2;
|
||||
p2.chunkIndex = 2;
|
||||
p2.mangaRTL = false;
|
||||
p2.pageShift = true;
|
||||
store.save(QByteArray("hash2"), p2);
|
||||
|
||||
QCOMPARE(store.load(QByteArray("hash1")).chunkIndex, 1);
|
||||
QCOMPARE(store.load(QByteArray("hash2")).chunkIndex, 2);
|
||||
@@ -71,8 +91,15 @@ private slots:
|
||||
BookPositionStore store(appState);
|
||||
|
||||
const QByteArray hash = QByteArray("overwrite-hash");
|
||||
store.save(hash, 3, true, true);
|
||||
store.save(hash, 5, false, false);
|
||||
BookPosition p1;
|
||||
p1.chunkIndex = 3;
|
||||
store.save(hash, p1);
|
||||
|
||||
BookPosition p2;
|
||||
p2.chunkIndex = 5;
|
||||
p2.mangaRTL = false;
|
||||
p2.pageShift = false;
|
||||
store.save(hash, p2);
|
||||
|
||||
const BookPosition pos = store.load(hash);
|
||||
QCOMPARE(pos.chunkIndex, 5);
|
||||
@@ -89,8 +116,9 @@ private slots:
|
||||
AppState appState(s);
|
||||
BookPositionStore store(appState);
|
||||
|
||||
// Neither save nor load should crash with an empty hash
|
||||
store.save(QByteArray(), 1, true, true);
|
||||
BookPosition p;
|
||||
p.chunkIndex = 1;
|
||||
store.save(QByteArray(), p);
|
||||
const BookPosition pos = store.load(QByteArray());
|
||||
QCOMPARE(pos.chunkIndex, 0);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user