~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to tests/auto/gui/kernel/qscreen/tst_qscreen.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the test suite of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include <qscreen.h>
 
43
#include <qpa/qwindowsysteminterface.h>
 
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
    QWindowSystemInterface::flushWindowSystemEvents();
 
189
    QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
 
190
 
 
191
    QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::PortraitOrientation);
 
192
    QWindowSystemInterface::flushWindowSystemEvents();
 
193
    QTRY_COMPARE(screen->orientation(), Qt::PortraitOrientation);
 
194
 
 
195
    QSignalSpy spy(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)));
 
196
 
 
197
    QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation);
 
198
    QWindowSystemInterface::flushWindowSystemEvents();
 
199
    QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedPortraitOrientation);
 
200
    QWindowSystemInterface::flushWindowSystemEvents();
 
201
    QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
 
202
    QWindowSystemInterface::flushWindowSystemEvents();
 
203
 
 
204
    QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
 
205
    QCOMPARE(spy.count(), 1);
 
206
 
 
207
    spy.clear();
 
208
    QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation);
 
209
    QWindowSystemInterface::flushWindowSystemEvents();
 
210
    QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
 
211
    QCOMPARE(spy.count(), 0);
 
212
 
 
213
    screen->setOrientationUpdateMask(screen->orientationUpdateMask() | Qt::InvertedLandscapeOrientation);
 
214
    QTRY_COMPARE(screen->orientation(), Qt::InvertedLandscapeOrientation);
 
215
    QCOMPARE(spy.count(), 1);
 
216
}
 
217
 
 
218
#include <tst_qscreen.moc>
 
219
QTEST_MAIN(tst_QScreen);