~gabriel1984sibiu/minitube/qt5.6

« back to all changes in this revision

Viewing changes to tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp

  • Committer: Grevutiu Gabriel
  • Date: 2017-06-13 08:43:17 UTC
  • Revision ID: gabriel1984sibiu@gmail.com-20170613084317-ek0zqe0u9g3ocvi8
OriginalĀ upstreamĀ code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2016 The Qt Company Ltd.
 
4
** Contact: https://www.qt.io/licensing/
 
5
**
 
6
** This file is part of the test suite of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
 
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 The Qt Company. For licensing terms
 
14
** and conditions see https://www.qt.io/terms-conditions. For further
 
15
** information use the contact form at https://www.qt.io/contact-us.
 
16
**
 
17
** GNU General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU
 
19
** General Public License version 3 as published by the Free Software
 
20
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
 
21
** included in the packaging of this file. Please review the following
 
22
** information to ensure the GNU General Public License requirements will
 
23
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
 
24
**
 
25
** $QT_END_LICENSE$
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
 
 
30
#include <QtTest/QtTest>
 
31
#include <QtWidgets/QDesktopWidget>
 
32
#include <QtGui/QWindow>
 
33
#include <QDebug>
 
34
 
 
35
class tst_QDesktopWidget : public QObject
 
36
{
 
37
    Q_OBJECT
 
38
 
 
39
private slots:
 
40
    void cleanup();
 
41
 
 
42
    void numScreens();
 
43
    void primaryScreen();
 
44
    void screenNumberForQWidget();
 
45
    void screenNumberForQPoint();
 
46
    void availableGeometry();
 
47
    void screenGeometry();
 
48
    void topLevels();
 
49
};
 
50
 
 
51
void tst_QDesktopWidget::cleanup()
 
52
{
 
53
    QVERIFY(QApplication::topLevelWidgets().isEmpty());
 
54
}
 
55
 
 
56
void tst_QDesktopWidget::numScreens()
 
57
{
 
58
    QDesktopWidget desktop;
 
59
    QVERIFY(desktop.numScreens() > 0);
 
60
}
 
61
 
 
62
void tst_QDesktopWidget::primaryScreen()
 
63
{
 
64
    QDesktopWidget desktop;
 
65
    QVERIFY(desktop.primaryScreen() >= 0);
 
66
    QVERIFY(desktop.primaryScreen() < desktop.numScreens());
 
67
}
 
68
 
 
69
void tst_QDesktopWidget::availableGeometry()
 
70
{
 
71
    QDesktopWidget desktop;
 
72
    QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::availableGeometry(): Attempt "
 
73
                                       "to get the available geometry of a null widget");
 
74
    desktop.availableGeometry((QWidget *)0);
 
75
 
 
76
    QRect total;
 
77
    QRect available;
 
78
 
 
79
    for (int i = 0; i < desktop.screenCount(); ++i) {
 
80
        total = desktop.screenGeometry(i);
 
81
        available = desktop.availableGeometry(i);
 
82
        QVERIFY(total.contains(available));
 
83
    }
 
84
 
 
85
    total = desktop.screenGeometry();
 
86
    available = desktop.availableGeometry();
 
87
    QVERIFY(total.contains(available));
 
88
    QCOMPARE(desktop.availableGeometry(desktop.primaryScreen()), available);
 
89
    QCOMPARE(desktop.screenGeometry(desktop.primaryScreen()), total);
 
90
}
 
91
 
 
92
void tst_QDesktopWidget::screenNumberForQWidget()
 
93
{
 
94
    QDesktopWidget desktop;
 
95
 
 
96
    QCOMPARE(desktop.screenNumber(0), 0);
 
97
 
 
98
    QWidget widget;
 
99
    widget.show();
 
100
    QVERIFY(QTest::qWaitForWindowExposed(&widget));
 
101
    QVERIFY(widget.isVisible());
 
102
 
 
103
    int widgetScreen = desktop.screenNumber(&widget);
 
104
    QVERIFY(widgetScreen > -1);
 
105
    QVERIFY(widgetScreen < desktop.numScreens());
 
106
}
 
107
 
 
108
void tst_QDesktopWidget::screenNumberForQPoint()
 
109
{
 
110
    // make sure QDesktopWidget::screenNumber(QPoint) returns the correct screen
 
111
    QDesktopWidget *desktopWidget = QApplication::desktop();
 
112
    QRect allScreens;
 
113
    for (int i = 0; i < desktopWidget->numScreens(); ++i) {
 
114
        QRect screenGeometry = desktopWidget->screenGeometry(i);
 
115
        QCOMPARE(desktopWidget->screenNumber(screenGeometry.center()), i);
 
116
        allScreens |= screenGeometry;
 
117
    }
 
118
 
 
119
    // make sure QDesktopWidget::screenNumber(QPoint) returns a valid screen for points that aren't on any screen
 
120
    int screen;
 
121
    screen = desktopWidget->screenNumber(allScreens.topLeft() - QPoint(1, 1));
 
122
 
 
123
    QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
 
124
    screen = desktopWidget->screenNumber(allScreens.topRight() + QPoint(1, 1));
 
125
    QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
 
126
    screen = desktopWidget->screenNumber(allScreens.bottomLeft() - QPoint(1, 1));
 
127
    QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
 
128
    screen = desktopWidget->screenNumber(allScreens.bottomRight() + QPoint(1, 1));
 
129
    QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
 
130
}
 
131
 
 
132
void tst_QDesktopWidget::screenGeometry()
 
133
{
 
134
    QDesktopWidget *desktopWidget = QApplication::desktop();
 
135
    QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::screenGeometry(): Attempt "
 
136
                                       "to get the screen geometry of a null widget");
 
137
    QRect r = desktopWidget->screenGeometry((QWidget *)0);
 
138
    QVERIFY(r.isNull());
 
139
    QWidget widget;
 
140
    widget.show();
 
141
    QVERIFY(QTest::qWaitForWindowExposed(&widget));
 
142
    r = desktopWidget->screenGeometry(&widget);
 
143
 
 
144
    QRect total;
 
145
    QRect available;
 
146
    for (int i = 0; i < desktopWidget->screenCount(); ++i) {
 
147
        total = desktopWidget->screenGeometry(i);
 
148
        available = desktopWidget->availableGeometry(i);
 
149
    }
 
150
}
 
151
 
 
152
void tst_QDesktopWidget::topLevels()
 
153
{
 
154
    // Desktop widgets/windows should not be listed as top-levels.
 
155
    int topLevelDesktopWidgets = 0;
 
156
    int topLevelDesktopWindows = 0;
 
157
    foreach (const QWidget *w, QApplication::topLevelWidgets())
 
158
        if (w->windowType() == Qt::Desktop)
 
159
            topLevelDesktopWidgets++;
 
160
    foreach (const QWindow *w, QGuiApplication::topLevelWindows())
 
161
        if (w->type() == Qt::Desktop)
 
162
            topLevelDesktopWindows++;
 
163
    QCOMPARE(topLevelDesktopWidgets, 0);
 
164
    QCOMPARE(topLevelDesktopWindows, 0);
 
165
}
 
166
 
 
167
QTEST_MAIN(tst_QDesktopWidget)
 
168
#include "tst_qdesktopwidget.moc"
 
169