2013-09-19 21:02:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2016-12-31 11:01:36 +00:00
|
|
|
# Copyright (c) 2008-2017 OpenLP Developers #
|
2013-09-19 21:02:28 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import MagicMock
|
2013-02-16 10:28:37 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
from PyQt5 import QtCore, QtWidgets
|
2013-02-16 10:28:37 +00:00
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
2017-12-02 05:31:23 +00:00
|
|
|
from openlp.core.display.screens import ScreenList, Screen
|
2013-02-16 10:28:37 +00:00
|
|
|
|
2013-02-16 18:14:41 +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 18:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
self.application = QtWidgets.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):
|
|
|
|
"""
|
2013-02-16 18:14:41 +00:00
|
|
|
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
|
|
|
|
|
2017-12-02 05:31:23 +00:00
|
|
|
def test_current_display_screen(self):
|
|
|
|
"""
|
|
|
|
Test that the "current" property returns the first display screen
|
|
|
|
"""
|
|
|
|
# GIVEN: A new ScreenList object with some screens
|
|
|
|
screen_list = ScreenList()
|
|
|
|
screen_list.screens = [
|
|
|
|
Screen(number=0, geometry=QtCore.QRect(0, 0, 1024, 768), is_primary=True),
|
|
|
|
Screen(number=1, geometry=QtCore.QRect(1024, 0, 1024, 768), is_primary=False, is_display=True)
|
|
|
|
]
|
|
|
|
|
|
|
|
# WHEN: The current property is accessed
|
|
|
|
screen = screen_list.current
|
|
|
|
|
|
|
|
# THEN: It should be the display screen
|
|
|
|
assert screen.number == 1
|
|
|
|
assert screen.geometry == QtCore.QRect(1024, 0, 1024, 768)
|
|
|
|
assert screen.is_primary is False
|
|
|
|
assert screen.is_display is True
|
|
|
|
|
|
|
|
def test_current_primary_screen(self):
|
|
|
|
"""
|
|
|
|
Test that the "current" property returns the first primary screen
|
|
|
|
"""
|
|
|
|
# GIVEN: A new ScreenList object with some screens
|
|
|
|
screen_list = ScreenList()
|
|
|
|
screen_list.screens = [
|
|
|
|
Screen(number=0, geometry=QtCore.QRect(0, 0, 1024, 768), is_primary=True)
|
|
|
|
]
|
|
|
|
|
|
|
|
# WHEN: The current property is accessed
|
|
|
|
screen = screen_list.current
|
|
|
|
|
|
|
|
# THEN: It should be the display screen
|
|
|
|
assert screen.number == 0
|
|
|
|
assert screen.geometry == QtCore.QRect(0, 0, 1024, 768)
|
|
|
|
assert screen.is_primary is True
|
|
|
|
assert screen.is_display is False
|
|
|
|
|
2017-12-02 00:35:21 +00:00
|
|
|
def test_create_screen_list(self):
|
2013-02-16 10:28:37 +00:00
|
|
|
"""
|
2017-12-02 00:35:21 +00:00
|
|
|
Create the screen list
|
2013-02-16 10:28:37 +00:00
|
|
|
"""
|
2017-12-02 00:35:21 +00:00
|
|
|
# GIVEN: Mocked desktop
|
|
|
|
mocked_desktop = MagicMock()
|
|
|
|
mocked_desktop.screenCount.return_value = 2
|
|
|
|
mocked_desktop.screenGeometry.side_effect = [
|
|
|
|
QtCore.QRect(0, 0, 1024, 768),
|
|
|
|
QtCore.QRect(1024, 0, 1024, 768)
|
|
|
|
]
|
|
|
|
mocked_desktop.primaryScreen.return_value = 0
|
2013-03-07 12:34:35 +00:00
|
|
|
|
2017-12-02 00:35:21 +00:00
|
|
|
# WHEN: create() is called
|
|
|
|
screen_list = ScreenList.create(mocked_desktop)
|
2013-03-07 12:34:35 +00:00
|
|
|
|
2017-12-02 00:35:21 +00:00
|
|
|
# THEN: The correct screens have been set up
|
|
|
|
assert screen_list.screens[0].number == 0
|
|
|
|
assert screen_list.screens[0].geometry == QtCore.QRect(0, 0, 1024, 768)
|
|
|
|
assert screen_list.screens[0].is_primary is True
|
|
|
|
assert screen_list.screens[1].number == 1
|
|
|
|
assert screen_list.screens[1].geometry == QtCore.QRect(1024, 0, 1024, 768)
|
|
|
|
assert screen_list.screens[1].is_primary is False
|