old render cleanup part 3

This commit is contained in:
Agel committed 2026-10-25 15:43:51 +01:00
1 parent cef762c3ee
commit 3faedd4251
45 files changed
+1057 -1135

No files matched your search

+5 -40
View File
@@ -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)