1
/****************************************************************************
2
**
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
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
** GNU Lesser General Public License Usage
11
** This file may be used under the terms of the GNU Lesser General Public
12
** License version 2.1 as published by the Free Software Foundation and
13
** appearing in the file LICENSE.LGPL included in the packaging of this
14
** file. Please review the following information to ensure the GNU Lesser
15
** General Public License version 2.1 requirements will be met:
16
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17
**
18
** In addition, as a special exception, Nokia gives you certain additional
19
** rights. These rights are described in the Nokia Qt LGPL Exception
20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21
**
22
** GNU General Public License Usage
23
** Alternatively, this file may be used under the terms of the GNU General
24
** Public License version 3.0 as published by the Free Software Foundation
25
** and appearing in the file LICENSE.GPL included in the packaging of this
26
** file. Please review the following information to ensure the GNU General
27
** Public License version 3.0 requirements will be met:
28
** http://www.gnu.org/copyleft/gpl.html.
29
**
30
** Other Usage
31
** Alternatively, this file may be used in accordance with the terms and
32
** conditions contained in a signed written agreement between you and Nokia.
33
**
34
**
35
**
36
**
37
**
38
** $QT_END_LICENSE$
39
**
40
****************************************************************************/
41
42
43
#include <QtTest/QtTest>
44
45
#include <q3dockwindow.h>
46
#include <q3mainwindow.h>
47
#include <q3textedit.h>
48
#include <qapplication.h>
49
#include <qevent.h>
50
#include <qlayout.h>
51
#include <qlineedit.h>
52
#include <qtimer.h>
53
#include <qtoolbutton.h>
54
#include <qaction.h>
55
56
//TESTED_CLASS=Q3DockArea Q3DockAreaLayout
57
//TESTED_FILES=
58
59
class testMainWindow : public Q3MainWindow
60
{
61
public:
62
    testMainWindow(QWidget* parent=0, const char* name=0);
63
    ~testMainWindow();
64
    bool keysuccess;
65
protected:
66
    void keyPressEvent(QKeyEvent*);
67
};
68
69
class testLineEdit : public QLineEdit
70
{
71
public:
72
    testLineEdit(QWidget* parent=0, const char* name =0);
73
    ~testLineEdit();
74
protected:
75
    void keyPressEvent(QKeyEvent*);
76
};
77
78
79
class tst_Q3MainWindow : public QObject
80
{
81
    Q_OBJECT
82
public:
83
    tst_Q3MainWindow();
84
    ~tst_Q3MainWindow();
85
86
87
public slots:
88
    void initTestCase();
89
    void cleanupTestCase();
90
    void cleanup();
91
private slots:
92
    void propagateEscapeKeyTest();
93
    void testDockWindowMinimized();
94
    void testSetUsesBigPixmaps();
95
96
    void hideAndShow();
97
98
    // task-specific tests:
99
    void task176544_setDockEnabled();
100
    void task240766_layoutcrash();
101
102
private:
103
    testMainWindow* testWidget;
104
    testLineEdit* le;
105
};
106
107
testMainWindow::testMainWindow( QWidget* parent, const char* name )
108
    : Q3MainWindow( parent, name )
109
{
110
    keysuccess = FALSE;
111
}
112
113
testMainWindow::~testMainWindow()
114
{
115
}
116
117
void testMainWindow::keyPressEvent( QKeyEvent* ke )
118
{
119
    if ( ke->key() == Qt::Key_Escape )
120
	keysuccess = TRUE;
121
}
122
123
124
testLineEdit::testLineEdit( QWidget* parent, const char* name )
125
    : QLineEdit( parent, name )
126
{
127
}
128
129
testLineEdit::~testLineEdit()
130
{
131
}
132
133
void testLineEdit::keyPressEvent( QKeyEvent* ke )
134
{
135
    if ( ke->key() == Qt::Key_Escape )
136
	ke->ignore();
137
}
138
139
/*
140
    Nothing to do here.
141
*/
142
143
tst_Q3MainWindow::tst_Q3MainWindow()
144
{
145
}
146
147
/*
148
    Nothing to do here.
149
    The testwidget is deleted automatically.
150
*/
151
152
tst_Q3MainWindow::~tst_Q3MainWindow()
153
{
154
}
155
156
/*
157
    This function is called once when a testcase is being executed.
158
    You can use it to create the instance of a widget class and set it for instance
159
    as the mainwidget.
160
*/
161
162
void tst_Q3MainWindow::initTestCase()
163
{
164
    testWidget = new testMainWindow(0);
165
    QWidget *w = new QWidget(testWidget);
166
    testWidget->setCentralWidget(w);
167
    QVBoxLayout *vbl = new QVBoxLayout(w);
168
    le = new testLineEdit( w );
169
    vbl->addWidget(le);
170
    new Q3ToolBar(testWidget);
171
    qApp->setMainWidget( testWidget );
172
    testWidget->show();
173
}
174
175
void tst_Q3MainWindow::cleanupTestCase()
176
{
177
    delete testWidget;
178
}
179
180
/*
181
    Nothing to do here, but you could for instance use this to clean up temporary files
182
    you have been using in a test.
183
*/
184
185
void tst_Q3MainWindow::cleanup()
186
{
187
}
188
189
void tst_Q3MainWindow::propagateEscapeKeyTest()
190
{
191
    QTest::keyClick( testWidget, Qt::Key_Escape );
192
    QVERIFY( testWidget->keysuccess );
193
}
194
195
void tst_Q3MainWindow::testDockWindowMinimized()
196
{
197
    Q3MainWindow mw;
198
    Q3DockWindow *dw = new Q3DockWindow(&mw);
199
    QToolButton *btn = new QToolButton(dw);
200
    btn->setUsesTextLabel(true);
201
    btn->setTextLabel("foo");
202
    dw->setWidget(btn);
203
    mw.addDockWindow(dw, Qt::DockMinimized);
204
    mw.show();
205
#ifdef Q_WS_X11
206
    qt_x11_wait_for_window_manager(&mw);
207
#endif
208
    qApp->processEvents();
209
    QEXPECT_FAIL(0, "This test started failing sometime during the 3.x lifetime", Continue);
210
    QVERIFY(dw->x() + dw->width() < 0);
211
    QEXPECT_FAIL(0, "This test started failing sometime during the 3.x lifetime", Continue);
212
    QVERIFY(dw->y() + dw->height() < 0);
213
}
214
215
void tst_Q3MainWindow::hideAndShow()
216
{
217
    Q3MainWindow mw;
218
    mw.show();
219
220
    Q3DockWindow *dw = new Q3DockWindow(&mw);
221
    QToolButton *btn = new QToolButton(dw);
222
    dw->setWidget(btn);
223
    mw.addDockWindow(dw, Qt::DockTornOff);
224
225
    QVERIFY(dw->isVisible());
226
    mw.hide();
227
    QTest::qWait(250);
228
    QVERIFY(!dw->isVisible());
229
    mw.show();
230
    QTest::qWait(250);
231
232
    QVERIFY(dw->isVisible());
233
}
234
235
void tst_Q3MainWindow::testSetUsesBigPixmaps()
236
{
237
    Q3MainWindow mw;
238
    Q3ToolBar toolbar(&mw);
239
    QAction action(&toolbar);
240
    toolbar.addAction(&action);
241
242
    QPixmap pix(16,16);
243
    action.setIcon(pix);
244
245
    mw.show();
246
    qApp->processEvents();
247
248
    mw.setUsesBigPixmaps(false);
249
    QToolButton *button = qFindChild<QToolButton*>(&toolbar);
250
    const QSize smallSize = button->size();
251
252
    mw.setUsesBigPixmaps(true);
253
    QVERIFY(button->width() > smallSize.width() && button->height() > smallSize.height());
254
255
}
256
257
void tst_Q3MainWindow::task176544_setDockEnabled()
258
{
259
    Q3MainWindow *mainWindow = new Q3MainWindow;
260
    mainWindow->setWindowTitle("Main Window");
261
    mainWindow->show();
262
    QCOMPARE(mainWindow->dockWindows().size(), 0);
263
264
    Q3DockWindow *dockWindow = new Q3DockWindow(mainWindow);
265
    dockWindow->show();
266
    QCOMPARE(mainWindow->dockWindows().size(), 1);
267
268
    mainWindow->setDockEnabled(dockWindow, Qt::DockLeft, false);
269
    QCOMPARE(mainWindow->dockWindows().size(), 1);
270
271
    mainWindow->setDockEnabled(dockWindow, Qt::DockRight, false);
272
    QCOMPARE(mainWindow->dockWindows().size(), 1);
273
}
274
275
void tst_Q3MainWindow::task240766_layoutcrash()
276
{
277
    Q3MainWindow main;
278
    
279
    QMenuBar* menubar = main.menuBar();
280
    
281
    Q3DockWindow *emptyDock = new Q3DockWindow(Q3DockWindow::InDock, &main);
282
    main.addDockWindow(emptyDock, Qt::DockLeft);
283
    
284
    Q3DockWindow *dock = new Q3DockWindow(Q3DockWindow::InDock, &main);
285
    main.addDockWindow(dock, Qt::DockLeft);
286
    dock->setResizeEnabled(true);
287
    
288
    Q3TextEdit *plotDialog = new Q3TextEdit(dock);
289
    dock->setWidget(plotDialog);
290
    main.show();
291
    QTest::qWait(100); 
292
    main.resize(180,180);
293
    QTest::qWait(100); //should not crash;
294
}
295
296
QTEST_MAIN(tst_Q3MainWindow)
297
#include "tst_q3mainwindow.moc"