2013-04-27 10:00:46 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.core.ui.listpreviewwidget.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2014-03-10 19:56:36 +00:00
|
|
|
from PyQt4 import QtGui, QtCore
|
2013-04-27 10:00:46 +00:00
|
|
|
|
2013-12-13 17:44:05 +00:00
|
|
|
from openlp.core.common import Registry
|
|
|
|
from openlp.core.lib import ServiceItem
|
2013-04-27 10:00:46 +00:00
|
|
|
from openlp.core.ui import listpreviewwidget
|
2013-10-04 21:45:38 +00:00
|
|
|
from tests.interfaces import MagicMock, patch
|
2013-04-27 10:00:46 +00:00
|
|
|
from tests.utils.osdinteraction import read_service_from_file
|
|
|
|
|
2013-08-25 18:31:15 +00:00
|
|
|
|
2013-04-27 10:06:08 +00:00
|
|
|
class TestListPreviewWidget(TestCase):
|
2013-04-27 10:00:46 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the UI.
|
|
|
|
"""
|
|
|
|
Registry.create()
|
2014-03-10 19:56:36 +00:00
|
|
|
old_app_instance = QtCore.QCoreApplication.instance()
|
|
|
|
if old_app_instance is None:
|
|
|
|
self.app = QtGui.QApplication([])
|
|
|
|
else:
|
|
|
|
self.app = old_app_instance
|
2013-04-27 10:00:46 +00:00
|
|
|
self.main_window = QtGui.QMainWindow()
|
|
|
|
self.image = QtGui.QImage(1, 1, QtGui.QImage.Format_RGB32)
|
|
|
|
self.image_manager = MagicMock()
|
|
|
|
self.image_manager.get_image.return_value = self.image
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register('image_manager', self.image_manager)
|
2013-04-27 10:00:46 +00:00
|
|
|
self.preview_widget = listpreviewwidget.ListPreviewWidget(self.main_window, 2)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Delete all the C++ objects at the end so that we don't have a segfault.
|
|
|
|
"""
|
|
|
|
del self.preview_widget
|
|
|
|
del self.main_window
|
|
|
|
|
|
|
|
def initial_slide_count_test(self):
|
|
|
|
"""
|
2014-01-01 14:59:57 +00:00
|
|
|
Test the initial slide count .
|
2013-04-27 10:00:46 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A new ListPreviewWidget instance.
|
|
|
|
# WHEN: No SlideItem has been added yet.
|
|
|
|
# THEN: The count of items should be zero.
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(self.preview_widget.slide_count(), 0, 'The slide list should be empty.')
|
2013-04-27 10:00:46 +00:00
|
|
|
|
|
|
|
def initial_slide_number_test(self):
|
|
|
|
"""
|
2014-01-01 14:59:57 +00:00
|
|
|
Test the initial current slide number.
|
2013-04-27 10:00:46 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A new ListPreviewWidget instance.
|
|
|
|
# WHEN: No SlideItem has been added yet.
|
|
|
|
# THEN: The number of the current item should be -1.
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(self.preview_widget.current_slide_number(), -1, 'The slide number should be -1.')
|
2013-04-27 10:00:46 +00:00
|
|
|
|
|
|
|
def replace_service_item_test(self):
|
|
|
|
"""
|
|
|
|
Test item counts and current number with a service item.
|
|
|
|
"""
|
|
|
|
# GIVEN: A ServiceItem with two frames.
|
|
|
|
service_item = ServiceItem(None)
|
2013-08-31 18:17:38 +00:00
|
|
|
service = read_service_from_file('serviceitem_image_3.osj')
|
2013-04-27 10:00:46 +00:00
|
|
|
with patch('os.path.exists'):
|
|
|
|
service_item.set_from_service(service[0])
|
|
|
|
# WHEN: Added to the preview widget.
|
|
|
|
self.preview_widget.replace_service_item(service_item, 1, 1)
|
|
|
|
# THEN: The slide count and number should fit.
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(self.preview_widget.slide_count(), 2, 'The slide count should be 2.')
|
|
|
|
self.assertEqual(self.preview_widget.current_slide_number(), 1, 'The current slide number should be 1.')
|
2013-04-27 10:00:46 +00:00
|
|
|
|
|
|
|
def change_slide_test(self):
|
|
|
|
"""
|
|
|
|
Test the change_slide method.
|
|
|
|
"""
|
|
|
|
# GIVEN: A ServiceItem with two frames content.
|
|
|
|
service_item = ServiceItem(None)
|
2013-08-31 18:17:38 +00:00
|
|
|
service = read_service_from_file('serviceitem_image_3.osj')
|
2013-04-27 10:00:46 +00:00
|
|
|
with patch('os.path.exists'):
|
|
|
|
service_item.set_from_service(service[0])
|
|
|
|
# WHEN: Added to the preview widget and switched to the second frame.
|
|
|
|
self.preview_widget.replace_service_item(service_item, 1, 0)
|
|
|
|
self.preview_widget.change_slide(1)
|
|
|
|
# THEN: The current_slide_number should reflect the change.
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(self.preview_widget.current_slide_number(), 1, 'The current slide number should be 1.')
|