autotest for epub internal links

This commit is contained in:
Jaydeep Solanki 2013-10-25 22:13:14 +05:30 committed by Albert Astals Cid
parent 3097f70878
commit b070de5600
4 changed files with 71 additions and 0 deletions

1
part.h
View file

@ -101,6 +101,7 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc
Q_INTERFACES(Okular::ViewerInterface)
friend class PartTest;
friend class EpubInternalLinksTest;
public:
// Default constructor

View file

@ -29,3 +29,6 @@ target_link_libraries( translateannotationtest ${KDE4_KDECORE_LIBS} ${QT_QTGUI_L
kde4_add_unit_test( modifyannotationpropertiestest modifyannotationpropertiestest.cpp testingutils.cpp)
target_link_libraries( modifyannotationpropertiestest ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} ${QT_QTXML_LIBRARY} okularcore )
kde4_add_unit_test( epubinternallinkstest epubinternallinkstest.cpp )
target_link_libraries( epubinternallinkstest ${KDE4_KDECORE_LIBS} ${KDE4_KPARTS_LIBS} ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY} okularpart okularcore )

BIN
tests/data/contents.epub Normal file

Binary file not shown.

View file

@ -0,0 +1,67 @@
/***************************************************************************
* Copyright (C) 2013 Jaydeep Solanki <jaydp17@gmail.com> *
* *
* 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 <qtest_kde.h>
#include "../part.h"
#include "../core/page.h"
namespace Okular
{
class EpubInternalLinksTest : public QObject
{
Q_OBJECT
private slots:
void testInternalLinks_data();
void testInternalLinks();
};
void EpubInternalLinksTest::testInternalLinks()
{
QVariantList dummyArgs;
Okular::Part part(NULL, NULL, dummyArgs, KGlobal::mainComponent());
part.openDocument(KDESRCDIR "data/contents.epub");
Okular::Document *doc = part.m_document;
doc->setViewportPage(0);
QVERIFY(doc);
int width = doc->page( 0 )->width(); // 0 because current page is zero
int height = doc->page( 0 )->height();
QFETCH( double, yCords );
QFETCH( int , pagesNos );
const ObjectRect *rect = doc->page( 0 )->objectRect( ObjectRect::Action, 0.0453564, yCords, width, height);
QVERIFY( rect );
const Okular::Action * action = static_cast< const Okular::Action * >( rect->object() );
doc->processAction( action );
QCOMPARE( doc->currentPage(), ( uint ) pagesNos );
part.slotGotoFirst();
}
void EpubInternalLinksTest::testInternalLinks_data()
{
QTest::addColumn< double >( "yCords" );
QTest::addColumn< int >( "pagesNos" );
QTest::newRow( "0.025" ) << 0.025 << 0;
QTest::newRow( "0.06" ) << 0.06 << 1;
QTest::newRow( "0.095" ) << 0.095 << 0;
QTest::newRow( "0.13" ) << 0.13 << 1;
QTest::newRow( "0.165" ) << 0.165 << 1;
QTest::newRow( "0.2" ) << 0.2 << 1;
QTest::newRow( "0.235" ) << 0.235 << 2;
QTest::newRow( "0.27" ) << 0.27 << 2;
QTest::newRow( "0.305" ) << 0.305 << 2;
QTest::newRow( "0.34" ) << 0.34 << 2;
}
}
QTEST_KDEMAIN( Okular::EpubInternalLinksTest, GUI )
#include "epubinternallinkstest.moc"