author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <QtGui/QDesktopWidget> |
|
45 |
#include <QDebug> |
|
46 |
||
47 |
//TESTED_CLASS= |
|
48 |
||
49 |
class tst_QDesktopWidget : public QObject |
|
50 |
{ |
|
51 |
Q_OBJECT |
|
52 |
||
53 |
public: |
|
54 |
tst_QDesktopWidget(); |
|
55 |
virtual ~tst_QDesktopWidget(); |
|
56 |
||
57 |
public slots: |
|
58 |
void init(); |
|
59 |
void cleanup(); |
|
60 |
||
61 |
private slots: |
|
62 |
void numScreens(); |
|
63 |
void primaryScreen(); |
|
64 |
void screenNumberForQWidget(); |
|
65 |
void screenNumberForQPoint(); |
|
66 |
void availableGeometry(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
void screenGeometry(); |
0 | 68 |
}; |
69 |
||
70 |
tst_QDesktopWidget::tst_QDesktopWidget() |
|
71 |
{ |
|
72 |
} |
|
73 |
||
74 |
tst_QDesktopWidget::~tst_QDesktopWidget() |
|
75 |
{ |
|
76 |
} |
|
77 |
||
78 |
void tst_QDesktopWidget::init() |
|
79 |
{ |
|
80 |
} |
|
81 |
||
82 |
void tst_QDesktopWidget::cleanup() |
|
83 |
{ |
|
84 |
} |
|
85 |
||
86 |
void tst_QDesktopWidget::numScreens() |
|
87 |
{ |
|
88 |
QDesktopWidget desktop; |
|
89 |
QVERIFY(desktop.numScreens() > 0); |
|
90 |
} |
|
91 |
||
92 |
void tst_QDesktopWidget::primaryScreen() |
|
93 |
{ |
|
94 |
QDesktopWidget desktop; |
|
95 |
QVERIFY(desktop.primaryScreen() >= 0); |
|
96 |
QVERIFY(desktop.primaryScreen() < desktop.numScreens()); |
|
97 |
} |
|
98 |
||
99 |
void tst_QDesktopWidget::availableGeometry() |
|
100 |
{ |
|
101 |
QDesktopWidget desktop; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::availableGeometry(): Attempt " |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
"to get the available geometry of a null widget"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
desktop.availableGeometry((QWidget *)0); |
0 | 105 |
|
106 |
QRect total; |
|
107 |
QRect available; |
|
108 |
||
109 |
for (int i = 0; i < desktop.screenCount(); ++i) { |
|
110 |
total = desktop.screenGeometry(i); |
|
111 |
available = desktop.availableGeometry(i); |
|
112 |
QVERIFY(total.contains(available)); |
|
113 |
} |
|
114 |
||
115 |
total = desktop.screenGeometry(); |
|
116 |
available = desktop.availableGeometry(); |
|
117 |
QVERIFY(total.contains(available)); |
|
118 |
QCOMPARE(desktop.availableGeometry(desktop.primaryScreen()), available); |
|
119 |
QCOMPARE(desktop.screenGeometry(desktop.primaryScreen()), total); |
|
120 |
} |
|
121 |
||
122 |
void tst_QDesktopWidget::screenNumberForQWidget() |
|
123 |
{ |
|
124 |
QDesktopWidget desktop; |
|
125 |
||
126 |
QCOMPARE(desktop.screenNumber(0), 0); |
|
127 |
||
128 |
QWidget widget; |
|
129 |
widget.show(); |
|
130 |
QApplication::processEvents(); |
|
131 |
QVERIFY(widget.isVisible()); |
|
132 |
||
133 |
int widgetScreen = desktop.screenNumber(&widget); |
|
134 |
QVERIFY(widgetScreen > -1); |
|
135 |
QVERIFY(widgetScreen < desktop.numScreens()); |
|
136 |
} |
|
137 |
||
138 |
void tst_QDesktopWidget::screenNumberForQPoint() |
|
139 |
{ |
|
140 |
// make sure QDesktopWidget::screenNumber(QPoint) returns the correct screen |
|
141 |
QDesktopWidget *desktopWidget = QApplication::desktop(); |
|
142 |
QRect allScreens; |
|
143 |
for (int i = 0; i < desktopWidget->numScreens(); ++i) { |
|
144 |
QRect screenGeometry = desktopWidget->screenGeometry(i); |
|
145 |
QCOMPARE(desktopWidget->screenNumber(screenGeometry.center()), i); |
|
146 |
allScreens |= screenGeometry; |
|
147 |
} |
|
148 |
||
149 |
// make sure QDesktopWidget::screenNumber(QPoint) returns a valid screen for points that aren't on any screen |
|
150 |
int screen; |
|
151 |
screen = desktopWidget->screenNumber(allScreens.topLeft() - QPoint(1, 1)); |
|
152 |
||
153 |
#ifdef Q_WS_QWS |
|
154 |
QEXPECT_FAIL("", "Task 151710", Abort); |
|
155 |
#endif |
|
156 |
QVERIFY(screen >= 0 && screen < desktopWidget->numScreens()); |
|
157 |
screen = desktopWidget->screenNumber(allScreens.topRight() + QPoint(1, 1)); |
|
158 |
QVERIFY(screen >= 0 && screen < desktopWidget->numScreens()); |
|
159 |
screen = desktopWidget->screenNumber(allScreens.bottomLeft() - QPoint(1, 1)); |
|
160 |
QVERIFY(screen >= 0 && screen < desktopWidget->numScreens()); |
|
161 |
screen = desktopWidget->screenNumber(allScreens.bottomRight() + QPoint(1, 1)); |
|
162 |
QVERIFY(screen >= 0 && screen < desktopWidget->numScreens()); |
|
163 |
} |
|
164 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
void tst_QDesktopWidget::screenGeometry() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
166 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
QDesktopWidget *desktopWidget = QApplication::desktop(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::screenGeometry(): Attempt " |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
"to get the screen geometry of a null widget"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
QRect r = desktopWidget->screenGeometry((QWidget *)0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
QVERIFY(r.isNull()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
QWidget widget; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
widget.show(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
QTest::qWaitForWindowShown(&widget); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
r = desktopWidget->screenGeometry(&widget); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
QRect total; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
QRect available; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
for (int i = 0; i < desktopWidget->screenCount(); ++i) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
total = desktopWidget->screenGeometry(i); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
available = desktopWidget->availableGeometry(i); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
183 |
QVERIFY(total.contains(r)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
|
0 | 186 |
QTEST_MAIN(tst_QDesktopWidget) |
187 |
#include "tst_qdesktopwidget.moc" |
|
188 |