1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 #include <QtGui/QWindowSystemInterface>
45 #include <QtTest/QtTest>
47 class tst_QScreen: public QObject
52 void angleBetween_data();
54 void transformBetween_data();
55 void transformBetween();
56 void orientationChange();
59 void tst_QScreen::angleBetween_data()
61 QTest::addColumn<uint>("oa");
62 QTest::addColumn<uint>("ob");
63 QTest::addColumn<int>("expected");
65 QTest::newRow("Portrait Portrait")
66 << uint(Qt::PortraitOrientation)
67 << uint(Qt::PortraitOrientation)
70 QTest::newRow("Portrait Landscape")
71 << uint(Qt::PortraitOrientation)
72 << uint(Qt::LandscapeOrientation)
75 QTest::newRow("Portrait InvertedPortrait")
76 << uint(Qt::PortraitOrientation)
77 << uint(Qt::InvertedPortraitOrientation)
80 QTest::newRow("Portrait InvertedLandscape")
81 << uint(Qt::PortraitOrientation)
82 << uint(Qt::InvertedLandscapeOrientation)
85 QTest::newRow("InvertedLandscape InvertedPortrait")
86 << uint(Qt::InvertedLandscapeOrientation)
87 << uint(Qt::InvertedPortraitOrientation)
90 QTest::newRow("InvertedLandscape Landscape")
91 << uint(Qt::InvertedLandscapeOrientation)
92 << uint(Qt::LandscapeOrientation)
95 QTest::newRow("Landscape Primary")
96 << uint(Qt::LandscapeOrientation)
97 << uint(Qt::PrimaryOrientation)
98 << QGuiApplication::primaryScreen()->angleBetween(Qt::LandscapeOrientation, QGuiApplication::primaryScreen()->primaryOrientation());
101 void tst_QScreen::angleBetween()
105 QFETCH( int, expected );
107 Qt::ScreenOrientation a = Qt::ScreenOrientation(oa);
108 Qt::ScreenOrientation b = Qt::ScreenOrientation(ob);
110 QCOMPARE(QGuiApplication::primaryScreen()->angleBetween(a, b), expected);
111 QCOMPARE(QGuiApplication::primaryScreen()->angleBetween(b, a), (360 - expected) % 360);
114 void tst_QScreen::transformBetween_data()
116 QTest::addColumn<uint>("oa");
117 QTest::addColumn<uint>("ob");
118 QTest::addColumn<QRect>("rect");
119 QTest::addColumn<QTransform>("expected");
121 QRect rect(0, 0, 480, 640);
123 QTest::newRow("Portrait Portrait")
124 << uint(Qt::PortraitOrientation)
125 << uint(Qt::PortraitOrientation)
129 QTest::newRow("Portrait Landscape")
130 << uint(Qt::PortraitOrientation)
131 << uint(Qt::LandscapeOrientation)
133 << QTransform(0, -1, 1, 0, 0, rect.height());
135 QTest::newRow("Portrait InvertedPortrait")
136 << uint(Qt::PortraitOrientation)
137 << uint(Qt::InvertedPortraitOrientation)
139 << QTransform(-1, 0, 0, -1, rect.width(), rect.height());
141 QTest::newRow("Portrait InvertedLandscape")
142 << uint(Qt::PortraitOrientation)
143 << uint(Qt::InvertedLandscapeOrientation)
145 << QTransform(0, 1, -1, 0, rect.width(), 0);
147 QTest::newRow("InvertedLandscape InvertedPortrait")
148 << uint(Qt::InvertedLandscapeOrientation)
149 << uint(Qt::InvertedPortraitOrientation)
151 << QTransform(0, 1, -1, 0, rect.width(), 0);
153 QTest::newRow("InvertedLandscape Landscape")
154 << uint(Qt::InvertedLandscapeOrientation)
155 << uint(Qt::LandscapeOrientation)
157 << QTransform(-1, 0, 0, -1, rect.width(), rect.height());
159 QTest::newRow("Landscape Primary")
160 << uint(Qt::LandscapeOrientation)
161 << uint(Qt::PrimaryOrientation)
163 << QGuiApplication::primaryScreen()->transformBetween(Qt::LandscapeOrientation, QGuiApplication::primaryScreen()->primaryOrientation(), rect);
166 void tst_QScreen::transformBetween()
170 QFETCH( QRect, rect );
171 QFETCH( QTransform, expected );
173 Qt::ScreenOrientation a = Qt::ScreenOrientation(oa);
174 Qt::ScreenOrientation b = Qt::ScreenOrientation(ob);
176 QCOMPARE(QGuiApplication::primaryScreen()->transformBetween(a, b, rect), expected);
179 void tst_QScreen::orientationChange()
181 qRegisterMetaType<Qt::ScreenOrientation>("Qt::ScreenOrientation");
183 QScreen *screen = QGuiApplication::primaryScreen();
185 screen->setOrientationUpdateMask(Qt::LandscapeOrientation | Qt::PortraitOrientation);
187 QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
188 QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
190 QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::PortraitOrientation);
191 QTRY_COMPARE(screen->orientation(), Qt::PortraitOrientation);
193 QSignalSpy spy(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)));
195 QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation);
196 QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedPortraitOrientation);
197 QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
199 QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
200 QCOMPARE(spy.count(), 1);
203 #include <tst_qscreen.moc>
204 QTEST_MAIN(tst_QScreen);