diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 116307f39..800a2a7f6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,6 +6,9 @@ target_link_libraries( shelltest ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY} ) kde4_add_unit_test( parttest parttest.cpp ) target_link_libraries( parttest ${KDE4_KDECORE_LIBS} ${KDE4_KPARTS_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} okularpart okularcore ) +kde4_add_unit_test( documenttest documenttest.cpp ) +target_link_libraries( documenttest ${KDE4_KDECORE_LIBS} ${KDE4_THREADWEAVER_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} okularcore ) + kde4_add_unit_test( searchtest searchtest.cpp ) target_link_libraries( searchtest ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} okularcore ) diff --git a/tests/documenttest.cpp b/tests/documenttest.cpp new file mode 100644 index 000000000..8a56136a3 --- /dev/null +++ b/tests/documenttest.cpp @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2013 by Fabio D'Urso * + * * + * 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 + +#include "../core/document.h" +#include "../core/generator.h" +#include "../core/observer.h" +#include "../core/rotationjob_p.h" +#include "../settings_core.h" + +class DocumentTest +: public QObject +{ + Q_OBJECT + + private slots: + void testCloseDuringRotationJob(); +}; + +// Test that we don't crash if the document is closed while a RotationJob +// is enqueued/running +void DocumentTest::testCloseDuringRotationJob() +{ + Okular::SettingsCore::instance( "documenttest" ); + Okular::Document *m_document = new Okular::Document( 0 ); + const QString testFile = KDESRCDIR "data/file1.pdf"; + const KMimeType::Ptr mime = KMimeType::findByPath( testFile ); + + Okular::DocumentObserver *dummyDocumentObserver = new Okular::DocumentObserver(); + m_document->addObserver( dummyDocumentObserver ); + + m_document->openDocument( testFile, KUrl(), mime ); + m_document->setRotation( 1 ); + + // Tell ThreadWeaver not to start any new job + ThreadWeaver::Weaver::instance()->suspend(); + + // Request a pixmap. A RotationJob will be enqueued but not started + Okular::PixmapRequest *pixmapReq = new Okular::PixmapRequest( + dummyDocumentObserver, 0, 100, 100, 1, Okular::PixmapRequest::NoFeature ); + m_document->requestPixmaps( QLinkedList() << pixmapReq ); + + // Delete the document + delete m_document; + + // Resume job processing and wait for the RotationJob to finish + ThreadWeaver::Weaver::instance()->resume(); + ThreadWeaver::Weaver::instance()->finish(); + qApp->processEvents(); +} + +QTEST_KDEMAIN( DocumentTest, GUI ) +#include "documenttest.moc"