diff --git a/generators/epub/CMakeLists.txt b/generators/epub/CMakeLists.txt --- a/generators/epub/CMakeLists.txt +++ b/generators/epub/CMakeLists.txt @@ -20,6 +20,16 @@ target_link_libraries(okularGenerator_epub okularcore ${EPUB_LIBRARIES} KF5::I18n Qt5::Widgets Qt5::Xml) + +########### autotests ############### + +add_definitions( -DKDESRCDIR="${CMAKE_CURRENT_SOURCE_DIR}/" ) +ecm_add_test(autotests/epubgeneratortest.cpp + TEST_NAME "epubgeneratortest" + LINK_LIBRARIES Qt5::Test KF5::CoreAddons okularcore +) + + ########### install files ############### install( FILES okularEPub.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) install( PROGRAMS okularApplication_epub.desktop org.kde.mobile.okular_epub.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) diff --git a/generators/epub/autotests/data/test.epub b/generators/epub/autotests/data/test.epub new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include + +#include "core/document.h" +#include "core/page.h" +#include "settings_core.h" +#include "core/textpage.h" + + +class EpubGeneratorTest +: public QObject +{ + Q_OBJECT + + private slots: + void initTestCase(); + void testDocumentStructure(); + void testDocumentContent(); + void cleanupTestCase(); + + private: + Okular::Document *m_document; +}; + +void EpubGeneratorTest::initTestCase() +{ + Okular::SettingsCore::instance( QStringLiteral("EpubGeneratorTest") ); + m_document = new Okular::Document( 0 ); + const QString testFile = QStringLiteral(KDESRCDIR "autotests/data/test.epub"); + QMimeDatabase db; + const QMimeType mime = db.mimeTypeForFile( testFile ); + QCOMPARE( m_document->openDocument(testFile, QUrl(), mime), Okular::Document::OpenSuccess ); +} + + +void EpubGeneratorTest::cleanupTestCase() +{ + m_document->closeDocument(); + delete m_document; +} + +void EpubGeneratorTest::testDocumentStructure() +{ + unsigned int expectedPageNr = 3; + QCOMPARE( m_document->pages(), expectedPageNr); + QCOMPARE( m_document->metaData(QLatin1String("DocumentTitle")).toString(), QStringLiteral("Okular Test") ); + + const Okular::DocumentSynopsis *docSyn = m_document->documentSynopsis(); + QDomElement heading1 = docSyn->documentElement(); + QCOMPARE( heading1.tagName(), QStringLiteral("Lorem ipsum Section 1") ); + + QDomElement heading2 = heading1.nextSiblingElement(); + QCOMPARE( heading2.tagName(), QStringLiteral("Lorem ipsum Section 2") ); +} + +void EpubGeneratorTest::testDocumentContent() +{ + const Okular::Page *page0 = m_document->page(0); + QCOMPARE( page0->number(), 0); + m_document->requestTextPage( page0->number() ); + QVERIFY( page0->hasTextPage() ); + QCOMPARE( page0->text().trimmed(), QStringLiteral("Lorem ipsum Section 1\n\u2029This is an example Text.\n\uFFFC") ); + + const Okular::Page *page1 = m_document->page(1); + QCOMPARE( page1->number(), 1); + m_document->requestTextPage( page1->number() ); + QVERIFY( page1->hasTextPage() ); + QCOMPARE( page1->text().trimmed(), QStringLiteral("Lorem ipsum Section 2\n\u2029This is an example Text.") ); + +} + +QTEST_MAIN( EpubGeneratorTest ) +#include "epubgeneratortest.moc" + +/* kate: replace-tabs on; tab-width 4; */ + diff --git a/generators/epub/converter.cpp b/generators/epub/converter.cpp --- a/generators/epub/converter.cpp +++ b/generators/epub/converter.cpp @@ -379,7 +379,11 @@ block = mSectionMap.value(link); } else { // load missing resource char *data = 0; - int size = epub_get_data(mTextDocument->getEpub(), clink, &data); + //epub_get_data can't handle whitespace url encodings + QByteArray ba = link.replace("%20", " ").toLatin1(); + const char *clinkClean = ba.data(); + int size = epub_get_data(mTextDocument->getEpub(), clinkClean, &data); + if (data) { _cursor->insertBlock();