Warning, file /graphics/okular/generators/chm/autotests/chmgeneratortest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 ChmGeneratorTest : 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 ChmGeneratorTest::initTestCase() 0030 { 0031 Okular::SettingsCore::instance(QStringLiteral("ChmGeneratorTest")); 0032 m_document = new Okular::Document(nullptr); 0033 const QString testFile = QStringLiteral(KDESRCDIR "autotests/data/test.chm"); 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 ChmGeneratorTest::cleanupTestCase() 0040 { 0041 m_document->closeDocument(); 0042 delete m_document; 0043 } 0044 0045 void ChmGeneratorTest::testDocumentStructure() 0046 { 0047 unsigned int expectedPageNr = 6; 0048 QCOMPARE(m_document->pages(), expectedPageNr); 0049 QCOMPARE(m_document->metaData(QStringLiteral("DocumentTitle")).toString(), QStringLiteral("okular test chm")); 0050 0051 const Okular::DocumentSynopsis *docSyn = m_document->documentSynopsis(); 0052 QDomElement heading1 = docSyn->documentElement(); 0053 QCOMPARE(heading1.tagName(), QStringLiteral("Heading 1")); 0054 0055 QDomElement topic1 = heading1.firstChildElement(); 0056 QCOMPARE(topic1.tagName(), QStringLiteral("Topic 1")); 0057 0058 QDomElement heading1_1 = topic1.nextSiblingElement(); 0059 QCOMPARE(heading1_1.tagName(), QStringLiteral("Heading 1.1")); 0060 0061 QDomElement topic1_1 = heading1_1.firstChildElement(); 0062 QCOMPARE(topic1_1.tagName(), QStringLiteral("Topic 1.1")); 0063 0064 QDomElement heading2 = heading1.nextSiblingElement(); 0065 QCOMPARE(heading2.tagName(), QStringLiteral("Heading 2")); 0066 } 0067 0068 void ChmGeneratorTest::testDocumentContent() 0069 { 0070 const Okular::Page *page0 = m_document->page(0); 0071 QCOMPARE(page0->number(), 0); 0072 m_document->requestTextPage(page0->number()); 0073 QVERIFY(page0->hasTextPage()); 0074 QCOMPARE(page0->text(), QStringLiteral("Heading 1This is an example Text.")); 0075 0076 const Okular::Page *page1 = m_document->page(1); 0077 QCOMPARE(page1->number(), 1); 0078 m_document->requestTextPage(page1->number()); 0079 QVERIFY(page1->hasTextPage()); 0080 QCOMPARE(page1->text(), QStringLiteral("Topic 1This is an example Text.")); 0081 0082 const Okular::Page *page2 = m_document->page(2); 0083 QCOMPARE(page2->number(), 2); 0084 m_document->requestTextPage(page2->number()); 0085 QVERIFY(page2->hasTextPage()); 0086 QCOMPARE(page2->text(), QStringLiteral("Heading 1.1With html title.")); 0087 0088 // Test page, who doesn't have an TOC entry, but one in chm index 0089 const Okular::Page *indexPage1 = m_document->page(5); 0090 QCOMPARE(indexPage1->number(), 5); 0091 m_document->requestTextPage(indexPage1->number()); 0092 QVERIFY(indexPage1->hasTextPage()); 0093 QCOMPARE(indexPage1->text(), QStringLiteral("Index 1This is an example Text.")); 0094 } 0095 0096 QTEST_MAIN(ChmGeneratorTest) 0097 #include "chmgeneratortest.moc" 0098 0099 /* kate: replace-tabs on; tab-width 4; */