openlp/tests/functional/openlp_core_lib/test_screen.py

88 lines
4.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2013-12-24 08:56:50 +00:00
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# 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; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2013-02-16 10:28:37 +00:00
"""
Package to test the openlp.core.lib.screenlist package.
"""
from unittest import TestCase
2013-02-16 12:33:54 +00:00
from PyQt4 import QtGui, QtCore
2013-02-16 10:28:37 +00:00
2013-12-13 17:44:05 +00:00
from openlp.core.common import Registry
from openlp.core.lib import ScreenList
from tests.functional import MagicMock
2013-02-16 10:28:37 +00:00
SCREEN = {
2013-08-31 18:17:38 +00:00
'primary': False,
'number': 1,
'size': QtCore.QRect(0, 0, 1024, 768)
}
2013-02-16 12:27:13 +00:00
class TestScreenList(TestCase):
2013-02-16 10:28:37 +00:00
def setUp(self):
"""
Set up the components need for all tests.
"""
2013-03-07 12:34:35 +00:00
# Mocked out desktop object
self.desktop = MagicMock()
2013-08-31 18:17:38 +00:00
self.desktop.primaryScreen.return_value = SCREEN['primary']
self.desktop.screenCount.return_value = SCREEN['number']
self.desktop.screenGeometry.return_value = SCREEN['size']
2013-03-07 12:34:35 +00:00
self.application = QtGui.QApplication.instance()
2013-02-17 07:54:43 +00:00
Registry.create()
2013-08-31 18:17:38 +00:00
self.application.setOrganizationName('OpenLP-tests')
self.application.setOrganizationDomain('openlp.org')
2013-03-07 12:34:35 +00:00
self.screens = ScreenList.create(self.desktop)
2013-02-16 10:28:37 +00:00
2013-02-16 15:02:19 +00:00
def tearDown(self):
"""
Delete QApplication.
2013-02-16 15:02:19 +00:00
"""
2013-02-17 07:54:43 +00:00
del self.screens
2013-02-16 15:02:19 +00:00
del self.application
2013-02-16 10:28:37 +00:00
def add_desktop_test(self):
"""
2013-03-07 12:34:35 +00:00
Test the ScreenList.screen_count_changed method to check if new monitors are detected by OpenLP.
2013-02-16 10:28:37 +00:00
"""
2013-03-07 12:34:35 +00:00
# GIVEN: The screen list at its current size
old_screen_count = len(self.screens.screen_list)
# WHEN: We add a new screen
2013-08-31 18:17:38 +00:00
self.desktop.screenCount.return_value = SCREEN['number'] + 1
2013-03-07 12:34:35 +00:00
self.screens.screen_count_changed(old_screen_count)
# THEN: The screen should have been added and the screens should be identical
new_screen_count = len(self.screens.screen_list)
2013-09-22 21:11:03 +00:00
self.assertEqual(old_screen_count + 1, new_screen_count, 'The new_screens list should be bigger')
self.assertEqual(SCREEN, self.screens.screen_list.pop(),
2013-12-31 07:27:07 +00:00
'The 2nd screen should be identical to the first screen')