added txt support
This commit is contained in:
1 parent
3c0037cfc9
commit
64a70bc4cf
22 files changed
+800
-186
No files matched your search
@@ -0,0 +1,80 @@
|
||||
#include <QtTest>
|
||||
#include "backend/formats/TxtReader.h"
|
||||
|
||||
class TxtReaderTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QString fixturePath(const QString &filename) const
|
||||
{
|
||||
return QStringLiteral(FIXTURES_DIR) + "/" + filename;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void openValidFile()
|
||||
{
|
||||
TxtReader reader;
|
||||
QVERIFY(reader.open(fixturePath("sample.txt")));
|
||||
QCOMPARE(reader.chapterCount(), 1);
|
||||
QCOMPARE(reader.title(), QStringLiteral("sample"));
|
||||
}
|
||||
|
||||
void loadChapter()
|
||||
{
|
||||
TxtReader reader;
|
||||
reader.open(fixturePath("sample.txt"));
|
||||
|
||||
Chapter ch = reader.loadChapter(0);
|
||||
QCOMPARE(ch.index, 0);
|
||||
QVERIFY(!ch.contentHtml.isEmpty());
|
||||
QVERIFY(ch.contentHtml.contains("Books are a uniquely portable magic"));
|
||||
// Verify Cyrillic content survived
|
||||
QVERIFY(ch.contentHtml.contains(QString::fromUtf8("Искусство чтения")));
|
||||
// Verify HTML paragraph structure
|
||||
QVERIFY(ch.contentHtml.contains("<p>"));
|
||||
}
|
||||
|
||||
void tableOfContentsEmpty()
|
||||
{
|
||||
TxtReader reader;
|
||||
reader.open(fixturePath("sample.txt"));
|
||||
QVERIFY(reader.tableOfContents().isEmpty());
|
||||
}
|
||||
|
||||
void authorEmpty()
|
||||
{
|
||||
TxtReader reader;
|
||||
reader.open(fixturePath("sample.txt"));
|
||||
QVERIFY(reader.author().isEmpty());
|
||||
}
|
||||
|
||||
void openNonexistentFile()
|
||||
{
|
||||
TxtReader reader;
|
||||
QVERIFY(!reader.open("/tmp/does_not_exist_asteria.txt"));
|
||||
QVERIFY(!reader.lastError().isEmpty());
|
||||
}
|
||||
|
||||
void loadChapterOutOfRange()
|
||||
{
|
||||
TxtReader reader;
|
||||
reader.open(fixturePath("sample.txt"));
|
||||
|
||||
Chapter ch = reader.loadChapter(1);
|
||||
QVERIFY(ch.contentHtml.isEmpty());
|
||||
}
|
||||
|
||||
void openCp1251File()
|
||||
{
|
||||
TxtReader reader;
|
||||
QVERIFY(reader.open(fixturePath("sample_cp1251.txt")));
|
||||
QCOMPARE(reader.chapterCount(), 1);
|
||||
|
||||
Chapter ch = reader.loadChapter(0);
|
||||
QVERIFY(ch.contentHtml.contains(QString::fromUtf8("Привет, мир!")));
|
||||
QVERIFY(ch.contentHtml.contains(QString::fromUtf8("Русская литература")));
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TxtReaderTest)
|
||||
#include "TxtReaderTest.moc"
|
||||
Reference in new issue
Block a user