diff --git a/okular_part_export.h b/okular_part_export.h new file mode 100644 index 000000000..e478414bd --- /dev/null +++ b/okular_part_export.h @@ -0,0 +1,33 @@ +/*************************************************************************** + * Copyright (C) 2013 by Albert Astals Cid * + * * + * 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 + + +#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 diff --git a/part.h b/part.h index 0c575609a..e3a941821 100644 --- a/part.h +++ b/part.h @@ -27,6 +27,8 @@ #include "kdocumentviewer.h" #include "interfaces/viewerinterface.h" +#include "okular_part_export.h" + #include class QAction; @@ -90,12 +92,14 @@ enum EmbedMode * @author Wilco Greven * @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_CLASSINFO("D-Bus Interface", "org.kde.okular") Q_INTERFACES(KDocumentViewer) Q_INTERFACES(Okular::ViewerInterface) + + friend class PartTest; public: // Default constructor diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9f8c288a7..9a98aa1e2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,3 +2,6 @@ set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) kde4_add_unit_test( shelltest shelltest.cpp ../shell/shellutils.cpp ) 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 ) diff --git a/tests/data/tocreload.pdf b/tests/data/tocreload.pdf new file mode 100644 index 000000000..9525ad86c Binary files /dev/null and b/tests/data/tocreload.pdf differ diff --git a/tests/parttest.cpp b/tests/parttest.cpp new file mode 100644 index 000000000..cc9d9ef31 --- /dev/null +++ b/tests/parttest.cpp @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2013 by Albert Astals Cid * + * * + * 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 "../part.h" +#include "../ui/toc.h" + +#include + +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" diff --git a/ui/toc.h b/ui/toc.h index d89889632..867964820 100644 --- a/ui/toc.h +++ b/ui/toc.h @@ -14,6 +14,8 @@ #include "core/observer.h" #include +#include "okular_part_export.h" + class QDomNode; class QModelIndex; class QTreeView; @@ -22,11 +24,14 @@ class TOCModel; namespace Okular { class Document; +class PartTest; } -class TOC : public QWidget, public Okular::DocumentObserver +class OKULAR_PART_EXPORT TOC : public QWidget, public Okular::DocumentObserver { Q_OBJECT + friend class Okular::PartTest; + public: TOC(QWidget *parent, Okular::Document *document); ~TOC();