~gabriel1984sibiu/minitube/qt5.6

« back to all changes in this revision

Viewing changes to tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.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
#include <QApplication>
 
30
#include <QtWidgets>
 
31
#include <QtTest/QtTest>
 
32
#include <QtCore/qcoreapplication.h>
 
33
 
 
34
#include "tst_qaccessibilitymac_helpers.h"
 
35
 
 
36
QT_USE_NAMESPACE
 
37
 
 
38
 
 
39
class AccessibleTestWindow : public QWidget
 
40
{
 
41
    Q_OBJECT
 
42
public:
 
43
    AccessibleTestWindow()
 
44
    {
 
45
        new QHBoxLayout(this);
 
46
    }
 
47
 
 
48
    void addWidget(QWidget* widget)
 
49
    {
 
50
        layout()->addWidget(widget);
 
51
        widget->show();
 
52
        QTest::qWaitForWindowExposed(widget);
 
53
    }
 
54
 
 
55
    void clearChildren()
 
56
    {
 
57
        qDeleteAll(children());
 
58
        new QHBoxLayout(this);
 
59
    }
 
60
};
 
61
 
 
62
class tst_QAccessibilityMac : public QObject
 
63
{
 
64
Q_OBJECT
 
65
private slots:
 
66
    void init();
 
67
    void cleanup();
 
68
 
 
69
    void singleWidgetTest();
 
70
    void lineEditTest();
 
71
    void hierarchyTest();
 
72
    void notificationsTest();
 
73
    void checkBoxTest();
 
74
 
 
75
private:
 
76
    AccessibleTestWindow *m_window;
 
77
};
 
78
 
 
79
 
 
80
void tst_QAccessibilityMac::init()
 
81
{
 
82
    m_window = new AccessibleTestWindow();
 
83
    m_window->setWindowTitle("Test window");
 
84
    m_window->show();
 
85
    m_window->resize(400, 400);
 
86
 
 
87
    QTest::qWaitForWindowExposed(m_window);
 
88
}
 
89
 
 
90
void tst_QAccessibilityMac::cleanup()
 
91
{
 
92
    delete m_window;
 
93
}
 
94
 
 
95
void tst_QAccessibilityMac::singleWidgetTest()
 
96
{
 
97
    if (!macNativeAccessibilityEnabled())
 
98
        return;
 
99
 
 
100
    delete m_window;
 
101
    m_window = 0;
 
102
 
 
103
    QVERIFY(singleWidget());
 
104
}
 
105
 
 
106
void tst_QAccessibilityMac::lineEditTest()
 
107
{
 
108
    if (!macNativeAccessibilityEnabled())
 
109
        return;
 
110
 
 
111
    QLineEdit *lineEdit = new QLineEdit(m_window);
 
112
    lineEdit->setText("a11y test QLineEdit");
 
113
    m_window->addWidget(lineEdit);
 
114
    QVERIFY(QTest::qWaitForWindowExposed(m_window));
 
115
    QCoreApplication::processEvents();
 
116
 
 
117
    QVERIFY(testLineEdit());
 
118
}
 
119
 
 
120
void tst_QAccessibilityMac::hierarchyTest()
 
121
{
 
122
    if (!macNativeAccessibilityEnabled())
 
123
        return;
 
124
 
 
125
    QWidget *w = new QWidget(m_window);
 
126
    m_window->addWidget(w);
 
127
 
 
128
    w->setLayout(new QVBoxLayout());
 
129
    QPushButton *b = new QPushButton(w);
 
130
    w->layout()->addWidget(b);
 
131
    b->setText("I am a button");
 
132
 
 
133
    QPushButton *b2 = new QPushButton(w);
 
134
    w->layout()->addWidget(b2);
 
135
    b2->setText("Button 2");
 
136
 
 
137
    QVERIFY(QTest::qWaitForWindowExposed(m_window));
 
138
    QCoreApplication::processEvents();
 
139
    QVERIFY(testHierarchy(w));
 
140
}
 
141
 
 
142
void tst_QAccessibilityMac::notificationsTest()
 
143
{
 
144
    if (!macNativeAccessibilityEnabled())
 
145
        return;
 
146
 
 
147
    QVERIFY(notifications(m_window));
 
148
}
 
149
 
 
150
void tst_QAccessibilityMac::checkBoxTest()
 
151
{
 
152
    if (!macNativeAccessibilityEnabled())
 
153
        return;
 
154
 
 
155
    QCheckBox *cb = new QCheckBox(m_window);
 
156
    cb->setText("Great option");
 
157
    m_window->addWidget(cb);
 
158
    QVERIFY(QTest::qWaitForWindowExposed(m_window));
 
159
    QCoreApplication::processEvents();
 
160
 
 
161
    QVERIFY(testCheckBox());
 
162
}
 
163
 
 
164
QTEST_MAIN(tst_QAccessibilityMac)
 
165
#include "tst_qaccessibilitymac.moc"