CBR and folder formats
This commit is contained in:
40 files changed
+1028
-349
No files matched your search
@@ -0,0 +1,145 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include <QDir>
|
||||
#include <QImage>
|
||||
#include <QTemporaryDir>
|
||||
|
||||
#include "backend/formats/comic/FolderReader.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static bool writePng(const QString &path, int w = 8, int h = 8, QColor color = Qt::blue)
|
||||
{
|
||||
QImage img(w, h, QImage::Format_RGB888);
|
||||
img.fill(color);
|
||||
return img.save(path, "PNG");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class FolderReaderTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void openEmptyDir()
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
QVERIFY(tmp.isValid());
|
||||
FolderReader reader;
|
||||
QVERIFY(!reader.open(tmp.path())); // no images → error
|
||||
}
|
||||
|
||||
void openWithImages()
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
QVERIFY(tmp.isValid());
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("01.png"))));
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("02.png"))));
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("03.png"))));
|
||||
|
||||
FolderReader reader;
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
QCOMPARE(reader.chapterCount(), 1);
|
||||
const Chapter ch = reader.loadChapter(0);
|
||||
QCOMPARE(ch.contentChunks.size(), 3);
|
||||
}
|
||||
|
||||
void sortOrderAlphabetical()
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
QVERIFY(tmp.isValid());
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("c.png"))));
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("a.png"))));
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("b.png"))));
|
||||
|
||||
FolderReader reader;
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
const Chapter ch = reader.loadChapter(0);
|
||||
QCOMPARE(ch.contentChunks.size(), 3);
|
||||
// Chunks contain the entry name — check alphabetical order
|
||||
QVERIFY(ch.contentChunks.at(0).contains(QStringLiteral("a.png")));
|
||||
QVERIFY(ch.contentChunks.at(1).contains(QStringLiteral("b.png")));
|
||||
QVERIFY(ch.contentChunks.at(2).contains(QStringLiteral("c.png")));
|
||||
}
|
||||
|
||||
void coverIsFirstImage()
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
QVERIFY(tmp.isValid());
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("01.png"))));
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("02.png"))));
|
||||
|
||||
FolderReader reader;
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
QCOMPARE(reader.coverImagePath(), QStringLiteral("01.png"));
|
||||
}
|
||||
|
||||
void titleIsFolderBasename()
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
QVERIFY(tmp.isValid());
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("page.png"))));
|
||||
|
||||
FolderReader reader;
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
QCOMPARE(reader.title(), QDir(tmp.path()).dirName());
|
||||
}
|
||||
|
||||
void contentHashIsStableOnFolderRename()
|
||||
{
|
||||
QTemporaryDir tmpA, tmpB;
|
||||
QVERIFY(tmpA.isValid() && tmpB.isValid());
|
||||
|
||||
// Same files (same names+sizes) in two differently-named directories
|
||||
QVERIFY(writePng(tmpA.filePath(QStringLiteral("page.png"))));
|
||||
QVERIFY(writePng(tmpB.filePath(QStringLiteral("page.png"))));
|
||||
|
||||
FolderReader ra, rb;
|
||||
QVERIFY(ra.open(tmpA.path()));
|
||||
QVERIFY(rb.open(tmpB.path()));
|
||||
QCOMPARE(ra.contentHash(), rb.contentHash());
|
||||
}
|
||||
|
||||
void fileTypeAndRenderingMode()
|
||||
{
|
||||
FolderReader reader;
|
||||
QCOMPARE(reader.fileType(), QStringLiteral("<dir>"));
|
||||
QCOMPARE(static_cast<int>(reader.preferredRenderingMode()),
|
||||
static_cast<int>(FormatReader::RenderingMode::Manga));
|
||||
}
|
||||
|
||||
void nonImageFilesIgnored()
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
QVERIFY(tmp.isValid());
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("page.png"))));
|
||||
// Write a non-image file
|
||||
QFile txt(tmp.filePath(QStringLiteral("readme.txt")));
|
||||
QVERIFY(txt.open(QIODevice::WriteOnly));
|
||||
txt.write("hello");
|
||||
txt.close();
|
||||
|
||||
FolderReader reader;
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
QCOMPARE(reader.chapterCount(), 1);
|
||||
QCOMPARE(reader.loadChapter(0).contentChunks.size(), 1);
|
||||
}
|
||||
|
||||
void dotFilesIgnored()
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
QVERIFY(tmp.isValid());
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral("page.png"))));
|
||||
QVERIFY(writePng(tmp.filePath(QStringLiteral(".hidden.png"))));
|
||||
|
||||
FolderReader reader;
|
||||
QVERIFY(reader.open(tmp.path()));
|
||||
QCOMPARE(reader.loadChapter(0).contentChunks.size(), 1);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(FolderReaderTest)
|
||||
#include "FolderReaderTest.moc"
|
||||
Reference in new issue
Block a user