test to make sure the toc reload feature works

This commit is contained in:
Albert Astals Cid 2013-01-19 15:05:39 +01:00
parent f40b42f8db
commit 5261272e45
6 changed files with 91 additions and 2 deletions

33
okular_part_export.h Normal file
View file

@ -0,0 +1,33 @@
/***************************************************************************
* Copyright (C) 2013 by Albert Astals Cid <aacid@kde.org> *
* *
* 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. *
***************************************************************************/
#ifndef OKULAR_PART_EXPORT_H
#define OKULAR_PART_EXPORT_H
/* needed for KDE_EXPORT macros */
#include <kdemacros.h>
#if defined _WIN32 || defined _WIN64
#ifndef OKULAR_PART_EXPORT
# ifdef MAKE_OKULARPART_LIB
# define OKULAR_PART_EXPORT KDE_EXPORT
# else
# define OKULAR_PART_EXPORT KDE_IMPORT
# endif
#endif
#else /* UNIX*/
/* export statements for unix */
#define OKULAR_PART_EXPORT KDE_EXPORT
#endif
#endif

6
part.h
View file

@ -27,6 +27,8 @@
#include "kdocumentviewer.h" #include "kdocumentviewer.h"
#include "interfaces/viewerinterface.h" #include "interfaces/viewerinterface.h"
#include "okular_part_export.h"
#include <QtDBus/QtDBus> #include <QtDBus/QtDBus>
class QAction; class QAction;
@ -90,12 +92,14 @@ enum EmbedMode
* @author Wilco Greven <greven@kde.org> * @author Wilco Greven <greven@kde.org>
* @version 0.2 * @version 0.2
*/ */
class Part : public KParts::ReadWritePart, public Okular::DocumentObserver, public KDocumentViewer, public Okular::ViewerInterface class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::DocumentObserver, public KDocumentViewer, public Okular::ViewerInterface
{ {
Q_OBJECT Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.okular") Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
Q_INTERFACES(KDocumentViewer) Q_INTERFACES(KDocumentViewer)
Q_INTERFACES(Okular::ViewerInterface) Q_INTERFACES(Okular::ViewerInterface)
friend class PartTest;
public: public:
// Default constructor // Default constructor

View file

@ -2,3 +2,6 @@ set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
kde4_add_unit_test( shelltest shelltest.cpp ../shell/shellutils.cpp ) kde4_add_unit_test( shelltest shelltest.cpp ../shell/shellutils.cpp )
target_link_libraries( shelltest ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY} ) target_link_libraries( shelltest ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY} )
kde4_add_unit_test( parttest parttest.cpp )
target_link_libraries( parttest ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY} okularpart )

BIN
tests/data/tocreload.pdf Normal file

Binary file not shown.

44
tests/parttest.cpp Normal file
View file

@ -0,0 +1,44 @@
/***************************************************************************
* Copyright (C) 2013 by Albert Astals Cid <aacid@kde.org> *
* *
* 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 "../ui/toc.h"
#include <QTreeView>
namespace Okular
{
class PartTest
: public QObject
{
Q_OBJECT
private slots:
void testTOCReload();
};
void PartTest::testTOCReload()
{
QVariantList dummyArgs;
Okular::Part part(NULL, NULL, dummyArgs, KGlobal::mainComponent());
part.openDocument(KDESRCDIR "data/tocreload.pdf");
QCOMPARE(part.m_toc->expandedNodes().count(), 0);
part.m_toc->m_treeView->expandAll();
QCOMPARE(part.m_toc->expandedNodes().count(), 3);
part.reload();
qApp->processEvents();
QCOMPARE(part.m_toc->expandedNodes().count(), 3);
}
}
QTEST_KDEMAIN( Okular::PartTest, GUI )
#include "parttest.moc"

View file

@ -14,6 +14,8 @@
#include "core/observer.h" #include "core/observer.h"
#include <QModelIndex> #include <QModelIndex>
#include "okular_part_export.h"
class QDomNode; class QDomNode;
class QModelIndex; class QModelIndex;
class QTreeView; class QTreeView;
@ -22,11 +24,14 @@ class TOCModel;
namespace Okular { namespace Okular {
class Document; class Document;
class PartTest;
} }
class TOC : public QWidget, public Okular::DocumentObserver class OKULAR_PART_EXPORT TOC : public QWidget, public Okular::DocumentObserver
{ {
Q_OBJECT Q_OBJECT
friend class Okular::PartTest;
public: public:
TOC(QWidget *parent, Okular::Document *document); TOC(QWidget *parent, Okular::Document *document);
~TOC(); ~TOC();