From 824a35ced051842a1518b95146042d3567a89ba1 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Fri, 14 Aug 2015 01:21:11 +0100 Subject: [PATCH] Ensure KImageIO test always finds the currently built generator REVIEW: 123895 --- generators/kimgio/CMakeLists.txt | 2 ++ generators/kimgio/tests/kimgiotest.cpp | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/generators/kimgio/CMakeLists.txt b/generators/kimgio/CMakeLists.txt index ab0644559..5d9011b02 100644 --- a/generators/kimgio/CMakeLists.txt +++ b/generators/kimgio/CMakeLists.txt @@ -14,6 +14,8 @@ install(TARGETS okularGenerator_kimgio DESTINATION ${KDE_INSTALL_PLUGINDIR}) add_definitions( -DKDESRCDIR="${CMAKE_CURRENT_SOURCE_DIR}/" ) set( kimgiotest_SRCS tests/kimgiotest.cpp ${CMAKE_SOURCE_DIR}/ui/pagepainter.cpp ${CMAKE_SOURCE_DIR}/ui/guiutils.cpp ) ecm_add_test(${kimgiotest_SRCS} TEST_NAME "kimgiotest" LINK_LIBRARIES okularcore okularpart Qt5::Svg Qt5::Test) +target_compile_definitions(kimgiotest PRIVATE -DGENERATOR_PATH="$") + ########### install files ############### diff --git a/generators/kimgio/tests/kimgiotest.cpp b/generators/kimgio/tests/kimgiotest.cpp index f81972411..56f204740 100644 --- a/generators/kimgio/tests/kimgiotest.cpp +++ b/generators/kimgio/tests/kimgiotest.cpp @@ -19,7 +19,9 @@ #include #include +#include #include +#include class KIMGIOTest : public QObject @@ -27,10 +29,26 @@ class KIMGIOTest Q_OBJECT private slots: + void initTestCase(); void testExifOrientation_data(); void testExifOrientation(); }; +void KIMGIOTest::initTestCase() +{ + // Make sure we find the okularGenerator_kimgio that we build just now and not the system one + QFileInfo lib( GENERATOR_PATH ); + QVERIFY2( lib.exists(), GENERATOR_PATH ); + QStringList libPaths = QCoreApplication::libraryPaths(); + libPaths.prepend( lib.absolutePath() ); + QCoreApplication::setLibraryPaths( libPaths ); + QVERIFY( !KPluginLoader::findPlugin( "okularGenerator_kimgio" ).isEmpty() ); + // make sure we didn't break the search path for image formats: + auto availableFormats = QImageReader::supportedImageFormats(); + QVERIFY2(availableFormats.contains( "jpeg" ), availableFormats.join( ", " ).data() ); +} + + // The following images have different Exif orientation tags, but they all // are a 3x2 rectangle whose top-left pixel is black, and whose other pixels are // white. Note that, due to JPEG lossy compression, some pixels are not pure @@ -60,8 +78,8 @@ void KIMGIOTest::testExifOrientation_data() void KIMGIOTest::testExifOrientation() { QFETCH( QString, imgPath ); - QMimeDatabase db; - + QMimeDatabase db; + Okular::SettingsCore::instance( "kimgiotest" ); Okular::Document *m_document = new Okular::Document( 0 ); const QMimeType mime = db.mimeTypeForFile( imgPath ); @@ -70,7 +88,7 @@ void KIMGIOTest::testExifOrientation() m_document->addObserver( dummyDocumentObserver ); // Load image - m_document->openDocument( imgPath, QUrl(), mime ); + QCOMPARE((int)m_document->openDocument( imgPath, QUrl(), mime ), (int)Okular::Document::OpenSuccess); m_document->setRotation( 0 ); // Test the default rotation QCOMPARE( m_document->pages(), 1u );