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

« back to all changes in this revision

Viewing changes to tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.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
 
 
43
#include <QtTest/QtTest>
 
44
#include <QtWidgets/QDesktopWidget>
 
45
#include <QDebug>
 
46
 
 
47
class tst_QDesktopWidget : public QObject
 
48
{
 
49
    Q_OBJECT
 
50
 
 
51
public:
 
52
    tst_QDesktopWidget();
 
53
    virtual ~tst_QDesktopWidget();
 
54
 
 
55
public slots:
 
56
    void init();
 
57
    void cleanup();
 
58
 
 
59
private slots:
 
60
    void numScreens();
 
61
    void primaryScreen();
 
62
    void screenNumberForQWidget();
 
63
    void screenNumberForQPoint();
 
64
    void availableGeometry();
 
65
    void screenGeometry();
 
66
};
 
67
 
 
68
tst_QDesktopWidget::tst_QDesktopWidget()
 
69
{
 
70
}
 
71
 
 
72
tst_QDesktopWidget::~tst_QDesktopWidget()
 
73
{
 
74
}
 
75
 
 
76
void tst_QDesktopWidget::init()
 
77
{
 
78
}
 
79
 
 
80
void tst_QDesktopWidget::cleanup()
 
81
{
 
82
}
 
83
 
 
84
void tst_QDesktopWidget::numScreens()
 
85
{
 
86
    QDesktopWidget desktop;
 
87
    QVERIFY(desktop.numScreens() > 0);
 
88
}
 
89
 
 
90
void tst_QDesktopWidget::primaryScreen()
 
91
{
 
92
    QDesktopWidget desktop;
 
93
    QVERIFY(desktop.primaryScreen() >= 0);
 
94
    QVERIFY(desktop.primaryScreen() < desktop.numScreens());
 
95
}
 
96
 
 
97
void tst_QDesktopWidget::availableGeometry()
 
98
{
 
99
    QDesktopWidget desktop;
 
100
    QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::availableGeometry(): Attempt "
 
101
                                       "to get the available geometry of a null widget");
 
102
    desktop.availableGeometry((QWidget *)0);
 
103
 
 
104
    QRect total;
 
105
    QRect available;
 
106
 
 
107
    for (int i = 0; i < desktop.screenCount(); ++i) {
 
108
        total = desktop.screenGeometry(i);
 
109
        available = desktop.availableGeometry(i);
 
110
        QVERIFY(total.contains(available));
 
111
    }
 
112
 
 
113
    total = desktop.screenGeometry();
 
114
    available = desktop.availableGeometry();
 
115
    QVERIFY(total.contains(available));
 
116
    QCOMPARE(desktop.availableGeometry(desktop.primaryScreen()), available);
 
117
    QCOMPARE(desktop.screenGeometry(desktop.primaryScreen()), total);
 
118
}
 
119
 
 
120
void tst_QDesktopWidget::screenNumberForQWidget()
 
121
{
 
122
    QDesktopWidget desktop;
 
123
 
 
124
    QCOMPARE(desktop.screenNumber(0), 0);
 
125
 
 
126
    QWidget widget;
 
127
    widget.show();
 
128
    QVERIFY(QTest::qWaitForWindowExposed(&widget));
 
129
    QVERIFY(widget.isVisible());
 
130
 
 
131
    int widgetScreen = desktop.screenNumber(&widget);
 
132
    QVERIFY(widgetScreen > -1);
 
133
    QVERIFY(widgetScreen < desktop.numScreens());
 
134
}
 
135
 
 
136
void tst_QDesktopWidget::screenNumberForQPoint()
 
137
{
 
138
    // make sure QDesktopWidget::screenNumber(QPoint) returns the correct screen
 
139
    QDesktopWidget *desktopWidget = QApplication::desktop();
 
140
    QRect allScreens;
 
141
    for (int i = 0; i < desktopWidget->numScreens(); ++i) {
 
142
        QRect screenGeometry = desktopWidget->screenGeometry(i);
 
143
        QCOMPARE(desktopWidget->screenNumber(screenGeometry.center()), i);
 
144
        allScreens |= screenGeometry;
 
145
    }
 
146
 
 
147
    // make sure QDesktopWidget::screenNumber(QPoint) returns a valid screen for points that aren't on any screen
 
148
    int screen;
 
149
    screen = desktopWidget->screenNumber(allScreens.topLeft() - QPoint(1, 1));
 
150
 
 
151
    QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
 
152
    screen = desktopWidget->screenNumber(allScreens.topRight() + QPoint(1, 1));
 
153
    QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
 
154
    screen = desktopWidget->screenNumber(allScreens.bottomLeft() - QPoint(1, 1));
 
155
    QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
 
156
    screen = desktopWidget->screenNumber(allScreens.bottomRight() + QPoint(1, 1));
 
157
    QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
 
158
}
 
159
 
 
160
void tst_QDesktopWidget::screenGeometry()
 
161
{
 
162
    QDesktopWidget *desktopWidget = QApplication::desktop();
 
163
    QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::screenGeometry(): Attempt "
 
164
                                       "to get the screen geometry of a null widget");
 
165
    QRect r = desktopWidget->screenGeometry((QWidget *)0);
 
166
    QVERIFY(r.isNull());
 
167
    QWidget widget;
 
168
    widget.show();
 
169
    QVERIFY(QTest::qWaitForWindowExposed(&widget));
 
170
    r = desktopWidget->screenGeometry(&widget);
 
171
 
 
172
    QRect total;
 
173
    QRect available;
 
174
    for (int i = 0; i < desktopWidget->screenCount(); ++i) {
 
175
        total = desktopWidget->screenGeometry(i);
 
176
        available = desktopWidget->availableGeometry(i);
 
177
    }
 
178
}
 
179
 
 
180
QTEST_MAIN(tst_QDesktopWidget)
 
181
#include "tst_qdesktopwidget.moc"
 
182