From 0f0e09a2825cf743a10f40d03415dccd41b36412 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sat, 29 Mar 2014 20:56:20 +0100 Subject: [PATCH 1/2] Fixed wrong dll load path. --- openlp/plugins/presentations/lib/pptviewcontroller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index 16008f7e9..a9090dd1e 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -87,7 +87,7 @@ class PptviewController(PresentationController): return log.debug('start PPTView') dll_path = os.path.join(AppLocation.get_directory(AppLocation.AppDir), - 'presentations', 'lib', 'pptviewlib', 'pptviewlib.dll') + 'plugins', 'presentations', 'lib', 'pptviewlib', 'pptviewlib.dll') self.process = cdll.LoadLibrary(dll_path) if log.isEnabledFor(logging.DEBUG): self.process.SetDebug(1) From 7ef62293f3392e9fd714c0cbb7466e975ff54e54 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Thu, 3 Apr 2014 22:22:10 +0200 Subject: [PATCH 2/2] Added test --- .../presentations/test_pdfcontroller.py | 51 ++++++++++++++++--- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/tests/functional/openlp_plugins/presentations/test_pdfcontroller.py b/tests/functional/openlp_plugins/presentations/test_pdfcontroller.py index 65c7bf916..b1e356249 100644 --- a/tests/functional/openlp_plugins/presentations/test_pdfcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_pdfcontroller.py @@ -33,6 +33,7 @@ import os import shutil from unittest import TestCase, SkipTest from tempfile import mkdtemp +from PyQt4 import QtCore, QtGui from openlp.plugins.presentations.lib.pdfcontroller import PdfController, PdfDocument from tests.functional import MagicMock @@ -45,6 +46,11 @@ __default_settings__ = { 'presentations/enable_pdf_program': False } +SCREEN = { + 'primary': False, + 'number': 1, + 'size': QtCore.QRect(0, 0, 1024, 768) +} class TestPdfController(TestCase, TestMixin): """ @@ -56,7 +62,12 @@ class TestPdfController(TestCase, TestMixin): """ self.get_application() self.build_settings() - ScreenList.create(self.app.desktop()) + # Mocked out desktop object + self.desktop = MagicMock() + self.desktop.primaryScreen.return_value = SCREEN['primary'] + self.desktop.screenCount.return_value = SCREEN['number'] + self.desktop.screenGeometry.return_value = SCREEN['size'] + self.screens = ScreenList.create(self.desktop) Settings().extend_default_settings(__default_settings__) self.temp_folder = mkdtemp() self.thumbnail_folder = mkdtemp() @@ -67,12 +78,11 @@ class TestPdfController(TestCase, TestMixin): """ Delete all the C++ objects at the end so that we don't have a segfault """ - try: - self.destroy_settings() - shutil.rmtree(self.thumbnail_folder) - shutil.rmtree(self.temp_folder) - except OSError: - pass + del self.screens + self.destroy_settings() + shutil.rmtree(self.thumbnail_folder) + shutil.rmtree(self.temp_folder) + def constructor_test(self): """ @@ -106,3 +116,30 @@ class TestPdfController(TestCase, TestMixin): # THEN: The load should succeed and we should be able to get a pagecount self.assertTrue(loaded, 'The loading of the PDF should succeed.') self.assertEqual(3, document.get_slide_count(), 'The pagecount of the PDF should be 3.') + + def load_pdf_pictures_test(self): + """ + Test loading of a Pdf and check size of generate pictures + """ + # GIVEN: A Pdf-file + test_file = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'pdf_test1.pdf') + + # WHEN: The Pdf is loaded + controller = PdfController(plugin=self.mock_plugin) + if not controller.check_available(): + raise SkipTest('Could not detect mudraw or ghostscript, so skipping PDF test') + controller.temp_folder = self.temp_folder + controller.thumbnail_folder = self.thumbnail_folder + document = PdfDocument(controller, test_file) + loaded = document.load_presentation() + + # THEN: The load should succeed and pictures should be created and have been scales to fit the screen + self.assertTrue(loaded, 'The loading of the PDF should succeed.') + image = QtGui.QImage(os.path.join(self.temp_folder, 'pdf_test1.pdf', 'mainslide001.png')) + # Based on the converter used the resolution will differ a bit + if controller.gsbin: + self.assertEqual(760, image.height(), 'The height should be 760') + self.assertEqual(537, image.width(), 'The width should be 537') + else: + self.assertEqual(767, image.height(), 'The height should be 767') + self.assertEqual(543, image.width(), 'The width should be 543')