File indexing completed on 2024-05-26 04:37:23

0001 /*
0002     SPDX-FileCopyrightText: 2017 Gilbert Assaf <gassaf@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include <QMimeDatabase>
0008 #include <QTest>
0009 
0010 #include "core/document.h"
0011 #include "core/page.h"
0012 #include "core/textpage.h"
0013 #include "settings_core.h"
0014 
0015 class EpubGeneratorTest : public QObject
0016 {
0017     Q_OBJECT
0018 
0019 private Q_SLOTS:
0020     void initTestCase();
0021     void testDocumentStructure();
0022     void testDocumentContent();
0023     void cleanupTestCase();
0024 
0025 private:
0026     Okular::Document *m_document;
0027 };
0028 
0029 void EpubGeneratorTest::initTestCase()
0030 {
0031     Okular::SettingsCore::instance(QStringLiteral("EpubGeneratorTest"));
0032     m_document = new Okular::Document(nullptr);
0033     const QString testFile = QStringLiteral(KDESRCDIR "autotests/data/test.epub");
0034     QMimeDatabase db;
0035     const QMimeType mime = db.mimeTypeForFile(testFile);
0036     QCOMPARE(m_document->openDocument(testFile, QUrl(), mime), Okular::Document::OpenSuccess);
0037 }
0038 
0039 void EpubGeneratorTest::cleanupTestCase()
0040 {
0041     m_document->closeDocument();
0042     delete m_document;
0043 }
0044 
0045 void EpubGeneratorTest::testDocumentStructure()
0046 {
0047     unsigned int expectedPageNr = 3;
0048     QCOMPARE(m_document->pages(), expectedPageNr);
0049     QCOMPARE(m_document->metaData(QStringLiteral("DocumentTitle")).toString(), QStringLiteral("Okular Test"));
0050 
0051     const Okular::DocumentSynopsis *docSyn = m_document->documentSynopsis();
0052     QDomElement heading1 = docSyn->documentElement();
0053     QCOMPARE(heading1.tagName(), QStringLiteral("Lorem ipsum Section 1"));
0054 
0055     QDomElement heading2 = heading1.nextSiblingElement();
0056     QCOMPARE(heading2.tagName(), QStringLiteral("Lorem ipsum Section 2"));
0057 }
0058 
0059 void EpubGeneratorTest::testDocumentContent()
0060 {
0061     const Okular::Page *page0 = m_document->page(0);
0062     QCOMPARE(page0->number(), 0);
0063     m_document->requestTextPage(page0->number());
0064     QVERIFY(page0->hasTextPage());
0065     QCOMPARE(page0->text().trimmed(), QStringLiteral("Lorem ipsum Section 1\n\u2029This is an example Text.\n\uFFFC"));
0066 
0067     const Okular::Page *page1 = m_document->page(1);
0068     QCOMPARE(page1->number(), 1);
0069     m_document->requestTextPage(page1->number());
0070     QVERIFY(page1->hasTextPage());
0071     QCOMPARE(page1->text().trimmed(), QStringLiteral("Lorem ipsum Section 2\n\u2029This is an example Text."));
0072 }
0073 
0074 QTEST_MAIN(EpubGeneratorTest)
0075 #include "epubgeneratortest.moc"
0076 
0077 /* kate: replace-tabs on; tab-width 4; */