old render cleanup part 2
This commit is contained in:
40 files changed
+329
-3643
No files matched your search
+37
-52
@@ -1,14 +1,16 @@
|
||||
#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/TxtReader.h"
|
||||
#include "backend/formats/EpubReader.h"
|
||||
#include "backend/formats/comic/FolderReader.h"
|
||||
#include "backend/formats/sources/DirByteSource.h"
|
||||
#include "backend/state/BookPositionStore.h"
|
||||
#include "backend/book/Book.h"
|
||||
|
||||
@@ -25,22 +27,13 @@ class BookTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
static QString epubFixture()
|
||||
static QString createSampleComic(QTemporaryDir &tmp)
|
||||
{
|
||||
#ifdef FIXTURES_DIR
|
||||
return QStringLiteral(FIXTURES_DIR) + QStringLiteral("/sample.epub");
|
||||
#else
|
||||
return QString();
|
||||
#endif
|
||||
}
|
||||
|
||||
static QString txtFixture()
|
||||
{
|
||||
#ifdef FIXTURES_DIR
|
||||
return QStringLiteral(FIXTURES_DIR) + QStringLiteral("/sample.txt");
|
||||
#else
|
||||
return QString();
|
||||
#endif
|
||||
if (!tmp.isValid()) return {};
|
||||
QImage img(8, 8, QImage::Format_RGB888);
|
||||
img.fill(Qt::blue);
|
||||
img.save(tmp.filePath(QStringLiteral("page01.png")), "PNG");
|
||||
return tmp.path();
|
||||
}
|
||||
|
||||
struct Ctx {
|
||||
@@ -60,10 +53,9 @@ private:
|
||||
store = new BookPositionStore(*appState);
|
||||
dialog = new FakeDialogService;
|
||||
factory = new FormatRegistry({
|
||||
{QStringLiteral("txt"), false, {},
|
||||
[] { return std::make_unique<TxtReader>(); }, nullptr},
|
||||
{QStringLiteral("epub"), false, QStringLiteral("epub"),
|
||||
[] { return std::make_unique<EpubReader>(); }, nullptr},
|
||||
{{}, /*matchesDirectory=*/true, QStringLiteral("dir"),
|
||||
[] { return std::make_unique<FolderReader>(); },
|
||||
[] { return std::make_unique<DirByteSource>(); }},
|
||||
});
|
||||
book = new Book(*dialog, *store, *factory);
|
||||
}
|
||||
@@ -88,14 +80,13 @@ private slots:
|
||||
QCOMPARE(ctx.book->filePath(), QString());
|
||||
QCOMPARE(ctx.book->coverImageUrl(),QString());
|
||||
QCOMPARE(ctx.book->errorMessage(), QString());
|
||||
QVERIFY(ctx.book->toc().isEmpty());
|
||||
}
|
||||
|
||||
void openValidTxtFile()
|
||||
void openValidFile()
|
||||
{
|
||||
const QString path = txtFixture();
|
||||
if (path.isEmpty() || !QFileInfo::exists(path))
|
||||
QSKIP("No TXT fixture");
|
||||
QTemporaryDir tmp;
|
||||
const QString path = createSampleComic(tmp);
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
Ctx ctx;
|
||||
QSignalSpy bookChanged(ctx.book, &Book::bookChanged);
|
||||
@@ -103,10 +94,7 @@ private slots:
|
||||
|
||||
ctx.book->openFromPath(path);
|
||||
|
||||
// loading should have become true
|
||||
QVERIFY(loading.count() > 0 || ctx.book->loading());
|
||||
|
||||
// Wait for the async open to complete
|
||||
QTRY_VERIFY_WITH_TIMEOUT(ctx.book->hasBook(), 5000);
|
||||
|
||||
QVERIFY(!ctx.book->loading());
|
||||
@@ -120,7 +108,7 @@ private slots:
|
||||
Ctx ctx;
|
||||
QSignalSpy errorSpy(ctx.book, &Book::errorMessageChanged);
|
||||
|
||||
ctx.book->openFromPath(QStringLiteral("/nonexistent/file.txt"));
|
||||
ctx.book->openFromPath(QStringLiteral("/nonexistent/file.cbz"));
|
||||
|
||||
QTRY_VERIFY_WITH_TIMEOUT(!ctx.book->errorMessage().isEmpty(), 5000);
|
||||
QVERIFY(!ctx.book->hasBook());
|
||||
@@ -130,7 +118,7 @@ private slots:
|
||||
void clearError()
|
||||
{
|
||||
Ctx ctx;
|
||||
ctx.book->openFromPath(QStringLiteral("/nonexistent/file.txt"));
|
||||
ctx.book->openFromPath(QStringLiteral("/nonexistent/file.cbz"));
|
||||
QTRY_VERIFY_WITH_TIMEOUT(!ctx.book->errorMessage().isEmpty(), 5000);
|
||||
|
||||
QSignalSpy errorSpy(ctx.book, &Book::errorMessageChanged);
|
||||
@@ -141,9 +129,9 @@ private slots:
|
||||
|
||||
void closeBook()
|
||||
{
|
||||
const QString path = txtFixture();
|
||||
if (path.isEmpty() || !QFileInfo::exists(path))
|
||||
QSKIP("No TXT fixture");
|
||||
QTemporaryDir tmp;
|
||||
const QString path = createSampleComic(tmp);
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
Ctx ctx;
|
||||
ctx.book->openFromPath(path);
|
||||
@@ -157,24 +145,24 @@ private slots:
|
||||
|
||||
void willOpenNewBookFiredBeforeSwap()
|
||||
{
|
||||
const QString path = txtFixture();
|
||||
if (path.isEmpty() || !QFileInfo::exists(path))
|
||||
QSKIP("No TXT fixture");
|
||||
QTemporaryDir tmp;
|
||||
const QString path = createSampleComic(tmp);
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
Ctx ctx;
|
||||
ctx.book->openFromPath(path);
|
||||
QTRY_VERIFY_WITH_TIMEOUT(ctx.book->hasBook(), 5000);
|
||||
|
||||
QSignalSpy willOpen(ctx.book, &Book::willOpenNewBook);
|
||||
ctx.book->openFromPath(path); // second open triggers willOpenNewBook
|
||||
ctx.book->openFromPath(path);
|
||||
QCOMPARE(willOpen.count(), 1);
|
||||
}
|
||||
|
||||
void openFromUrl()
|
||||
{
|
||||
const QString path = txtFixture();
|
||||
if (path.isEmpty() || !QFileInfo::exists(path))
|
||||
QSKIP("No TXT fixture");
|
||||
QTemporaryDir tmp;
|
||||
const QString path = createSampleComic(tmp);
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
Ctx ctx;
|
||||
ctx.book->openFromUrl(QUrl::fromLocalFile(path));
|
||||
@@ -184,24 +172,21 @@ private slots:
|
||||
|
||||
void browseAndOpenDelegatesToDialog()
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
const QString path = createSampleComic(tmp);
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
Ctx ctx;
|
||||
QSignalSpy loading(ctx.book, &Book::loadingChanged);
|
||||
|
||||
const QString path = txtFixture();
|
||||
if (path.isEmpty() || !QFileInfo::exists(path))
|
||||
QSKIP("No TXT fixture");
|
||||
|
||||
// Simulate the dialog emitting fileSelected
|
||||
ctx.book->browseAndOpen(); // calls dialog.open() which in FakeDialogService is a no-op
|
||||
ctx.book->browseAndOpen();
|
||||
ctx.dialog->triggerFile(path);
|
||||
QTRY_VERIFY_WITH_TIMEOUT(ctx.book->hasBook(), 5000);
|
||||
}
|
||||
|
||||
void saveCurrentPositionUsesHash()
|
||||
{
|
||||
const QString path = txtFixture();
|
||||
if (path.isEmpty() || !QFileInfo::exists(path))
|
||||
QSKIP("No TXT fixture");
|
||||
QTemporaryDir tmp;
|
||||
const QString path = createSampleComic(tmp);
|
||||
QVERIFY(!path.isEmpty());
|
||||
|
||||
Ctx ctx;
|
||||
ctx.book->openFromPath(path);
|
||||
|
||||
Reference in new issue
Block a user