8a0246c71ed27aa252657cf7efbbe133b8b753d2
[profile/ivi/qtbase.git] / tests / auto / gui / kernel / qscreen / tst_qscreen.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qscreen.h>
43 #include <QtGui/QWindowSystemInterface>
44
45 #include <QtTest/QtTest>
46
47 class tst_QScreen: public QObject
48 {
49     Q_OBJECT
50
51 private slots:
52     void angleBetween_data();
53     void angleBetween();
54     void transformBetween_data();
55     void transformBetween();
56     void orientationChange();
57 };
58
59 void tst_QScreen::angleBetween_data()
60 {
61     QTest::addColumn<uint>("oa");
62     QTest::addColumn<uint>("ob");
63     QTest::addColumn<int>("expected");
64
65     QTest::newRow("Portrait Portrait")
66         << uint(Qt::PortraitOrientation)
67         << uint(Qt::PortraitOrientation)
68         << 0;
69
70     QTest::newRow("Portrait Landscape")
71         << uint(Qt::PortraitOrientation)
72         << uint(Qt::LandscapeOrientation)
73         << 270;
74
75     QTest::newRow("Portrait InvertedPortrait")
76         << uint(Qt::PortraitOrientation)
77         << uint(Qt::InvertedPortraitOrientation)
78         << 180;
79
80     QTest::newRow("Portrait InvertedLandscape")
81         << uint(Qt::PortraitOrientation)
82         << uint(Qt::InvertedLandscapeOrientation)
83         << 90;
84
85     QTest::newRow("InvertedLandscape InvertedPortrait")
86         << uint(Qt::InvertedLandscapeOrientation)
87         << uint(Qt::InvertedPortraitOrientation)
88         << 90;
89
90     QTest::newRow("InvertedLandscape Landscape")
91         << uint(Qt::InvertedLandscapeOrientation)
92         << uint(Qt::LandscapeOrientation)
93         << 180;
94
95     QTest::newRow("Landscape Primary")
96         << uint(Qt::LandscapeOrientation)
97         << uint(Qt::PrimaryOrientation)
98         << QGuiApplication::primaryScreen()->angleBetween(Qt::LandscapeOrientation, QGuiApplication::primaryScreen()->primaryOrientation());
99 }
100
101 void tst_QScreen::angleBetween()
102 {
103     QFETCH( uint, oa );
104     QFETCH( uint, ob );
105     QFETCH( int, expected );
106
107     Qt::ScreenOrientation a = Qt::ScreenOrientation(oa);
108     Qt::ScreenOrientation b = Qt::ScreenOrientation(ob);
109
110     QCOMPARE(QGuiApplication::primaryScreen()->angleBetween(a, b), expected);
111     QCOMPARE(QGuiApplication::primaryScreen()->angleBetween(b, a), (360 - expected) % 360);
112 }
113
114 void tst_QScreen::transformBetween_data()
115 {
116     QTest::addColumn<uint>("oa");
117     QTest::addColumn<uint>("ob");
118     QTest::addColumn<QRect>("rect");
119     QTest::addColumn<QTransform>("expected");
120
121     QRect rect(0, 0, 480, 640);
122
123     QTest::newRow("Portrait Portrait")
124         << uint(Qt::PortraitOrientation)
125         << uint(Qt::PortraitOrientation)
126         << rect
127         << QTransform();
128
129     QTest::newRow("Portrait Landscape")
130         << uint(Qt::PortraitOrientation)
131         << uint(Qt::LandscapeOrientation)
132         << rect
133         << QTransform(0, -1, 1, 0, 0, rect.height());
134
135     QTest::newRow("Portrait InvertedPortrait")
136         << uint(Qt::PortraitOrientation)
137         << uint(Qt::InvertedPortraitOrientation)
138         << rect
139         << QTransform(-1, 0, 0, -1, rect.width(), rect.height());
140
141     QTest::newRow("Portrait InvertedLandscape")
142         << uint(Qt::PortraitOrientation)
143         << uint(Qt::InvertedLandscapeOrientation)
144         << rect
145         << QTransform(0, 1, -1, 0, rect.width(), 0);
146
147     QTest::newRow("InvertedLandscape InvertedPortrait")
148         << uint(Qt::InvertedLandscapeOrientation)
149         << uint(Qt::InvertedPortraitOrientation)
150         << rect
151         << QTransform(0, 1, -1, 0, rect.width(), 0);
152
153     QTest::newRow("InvertedLandscape Landscape")
154         << uint(Qt::InvertedLandscapeOrientation)
155         << uint(Qt::LandscapeOrientation)
156         << rect
157         << QTransform(-1, 0, 0, -1, rect.width(), rect.height());
158
159     QTest::newRow("Landscape Primary")
160         << uint(Qt::LandscapeOrientation)
161         << uint(Qt::PrimaryOrientation)
162         << rect
163         << QGuiApplication::primaryScreen()->transformBetween(Qt::LandscapeOrientation, QGuiApplication::primaryScreen()->primaryOrientation(), rect);
164 }
165
166 void tst_QScreen::transformBetween()
167 {
168     QFETCH( uint, oa );
169     QFETCH( uint, ob );
170     QFETCH( QRect, rect );
171     QFETCH( QTransform, expected );
172
173     Qt::ScreenOrientation a = Qt::ScreenOrientation(oa);
174     Qt::ScreenOrientation b = Qt::ScreenOrientation(ob);
175
176     QCOMPARE(QGuiApplication::primaryScreen()->transformBetween(a, b, rect), expected);
177 }
178
179 void tst_QScreen::orientationChange()
180 {
181     qRegisterMetaType<Qt::ScreenOrientation>("Qt::ScreenOrientation");
182
183     QScreen *screen = QGuiApplication::primaryScreen();
184
185     screen->setOrientationUpdateMask(Qt::LandscapeOrientation | Qt::PortraitOrientation);
186
187     QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
188     QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
189
190     QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::PortraitOrientation);
191     QTRY_COMPARE(screen->orientation(), Qt::PortraitOrientation);
192
193     QSignalSpy spy(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)));
194
195     QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation);
196     QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedPortraitOrientation);
197     QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
198
199     QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
200     QCOMPARE(spy.count(), 1);
201 }
202
203 #include <tst_qscreen.moc>
204 QTEST_MAIN(tst_QScreen);