summaryrefslogtreecommitdiffstats
path: root/tests/auto/q3mainwindow/tst_q3mainwindow.cpp
blob: d837596a7964c711b28d422ff2fce11ef504bce7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/


#include <QtTest/QtTest>

#include <q3dockwindow.h>
#include <q3mainwindow.h>
#include <q3textedit.h>
#include <qapplication.h>
#include <qevent.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qtimer.h>
#include <qtoolbutton.h>
#include <qaction.h>

//TESTED_CLASS=Q3DockArea Q3DockAreaLayout
//TESTED_FILES=

class testMainWindow : public Q3MainWindow
{
public:
    testMainWindow(QWidget* parent=0, const char* name=0);
    ~testMainWindow();
    bool keysuccess;
protected:
    void keyPressEvent(QKeyEvent*);
};

class testLineEdit : public QLineEdit
{
public:
    testLineEdit(QWidget* parent=0, const char* name =0);
    ~testLineEdit();
protected:
    void keyPressEvent(QKeyEvent*);
};


class tst_Q3MainWindow : public QObject
{
    Q_OBJECT
public:
    tst_Q3MainWindow();
    ~tst_Q3MainWindow();


public slots:
    void initTestCase();
    void cleanupTestCase();
    void cleanup();
private slots:
    void propagateEscapeKeyTest();
    void testDockWindowMinimized();
    void testSetUsesBigPixmaps();

    void hideAndShow();

    // task-specific tests:
    void task176544_setDockEnabled();
    void task240766_layoutcrash();

private:
    testMainWindow* testWidget;
    testLineEdit* le;
};

testMainWindow::testMainWindow( QWidget* parent, const char* name )
    : Q3MainWindow( parent, name )
{
    keysuccess = FALSE;
}

testMainWindow::~testMainWindow()
{
}

void testMainWindow::keyPressEvent( QKeyEvent* ke )
{
    if ( ke->key() == Qt::Key_Escape )
	keysuccess = TRUE;
}


testLineEdit::testLineEdit( QWidget* parent, const char* name )
    : QLineEdit( parent, name )
{
}

testLineEdit::~testLineEdit()
{
}

void testLineEdit::keyPressEvent( QKeyEvent* ke )
{
    if ( ke->key() == Qt::Key_Escape )
	ke->ignore();
}

/*
    Nothing to do here.
*/

tst_Q3MainWindow::tst_Q3MainWindow()
{
}

/*
    Nothing to do here.
    The testwidget is deleted automatically.
*/

tst_Q3MainWindow::~tst_Q3MainWindow()
{
}

/*
    This function is called once when a testcase is being executed.
    You can use it to create the instance of a widget class and set it for instance
    as the mainwidget.
*/

void tst_Q3MainWindow::initTestCase()
{
    testWidget = new testMainWindow(0);
    QWidget *w = new QWidget(testWidget);
    testWidget->setCentralWidget(w);
    QVBoxLayout *vbl = new QVBoxLayout(w);
    le = new testLineEdit( w );
    vbl->addWidget(le);
    new Q3ToolBar(testWidget);
    qApp->setMainWidget( testWidget );
    testWidget->show();
}

void tst_Q3MainWindow::cleanupTestCase()
{
    delete testWidget;
}

/*
    Nothing to do here, but you could for instance use this to clean up temporary files
    you have been using in a test.
*/

void tst_Q3MainWindow::cleanup()
{
}

void tst_Q3MainWindow::propagateEscapeKeyTest()
{
    QTest::keyClick( testWidget, Qt::Key_Escape );
    QVERIFY( testWidget->keysuccess );
}

void tst_Q3MainWindow::testDockWindowMinimized()
{
    Q3MainWindow mw;
    Q3DockWindow *dw = new Q3DockWindow(&mw);
    QToolButton *btn = new QToolButton(dw);
    btn->setUsesTextLabel(true);
    btn->setTextLabel("foo");
    dw->setWidget(btn);
    mw.addDockWindow(dw, Qt::DockMinimized);
    mw.show();
#ifdef Q_WS_X11
    qt_x11_wait_for_window_manager(&mw);
#endif
    qApp->processEvents();
    QEXPECT_FAIL(0, "This test started failing sometime during the 3.x lifetime", Continue);
    QVERIFY(dw->x() + dw->width() < 0);
    QEXPECT_FAIL(0, "This test started failing sometime during the 3.x lifetime", Continue);
    QVERIFY(dw->y() + dw->height() < 0);
}

void tst_Q3MainWindow::hideAndShow()
{
    Q3MainWindow mw;
    mw.show();

    Q3DockWindow *dw = new Q3DockWindow(&mw);
    QToolButton *btn = new QToolButton(dw);
    dw->setWidget(btn);
    mw.addDockWindow(dw, Qt::DockTornOff);

    QVERIFY(dw->isVisible());
    mw.hide();
    QTest::qWait(250);
    QVERIFY(!dw->isVisible());
    mw.show();
    QTest::qWait(250);

    QVERIFY(dw->isVisible());
}

void tst_Q3MainWindow::testSetUsesBigPixmaps()
{
    Q3MainWindow mw;
    Q3ToolBar toolbar(&mw);
    QAction action(&toolbar);
    toolbar.addAction(&action);

    QPixmap pix(16,16);
    action.setIcon(pix);

    mw.show();
    qApp->processEvents();

    mw.setUsesBigPixmaps(false);
    QToolButton *button = qFindChild<QToolButton*>(&toolbar);
    const QSize smallSize = button->size();

    mw.setUsesBigPixmaps(true);
    QVERIFY(button->width() > smallSize.width() && button->height() > smallSize.height());

}

void tst_Q3MainWindow::task176544_setDockEnabled()
{
    Q3MainWindow *mainWindow = new Q3MainWindow;
    mainWindow->setWindowTitle("Main Window");
    mainWindow->show();
    QCOMPARE(mainWindow->dockWindows().size(), 0);

    Q3DockWindow *dockWindow = new Q3DockWindow(mainWindow);
    dockWindow->show();
    QCOMPARE(mainWindow->dockWindows().size(), 1);

    mainWindow->setDockEnabled(dockWindow, Qt::DockLeft, false);
    QCOMPARE(mainWindow->dockWindows().size(), 1);

    mainWindow->setDockEnabled(dockWindow, Qt::DockRight, false);
    QCOMPARE(mainWindow->dockWindows().size(), 1);
}

void tst_Q3MainWindow::task240766_layoutcrash()
{
    Q3MainWindow main;
    
    QMenuBar* menubar = main.menuBar();
    
    Q3DockWindow *emptyDock = new Q3DockWindow(Q3DockWindow::InDock, &main);
    main.addDockWindow(emptyDock, Qt::DockLeft);
    
    Q3DockWindow *dock = new Q3DockWindow(Q3DockWindow::InDock, &main);
    main.addDockWindow(dock, Qt::DockLeft);
    dock->setResizeEnabled(true);
    
    Q3TextEdit *plotDialog = new Q3TextEdit(dock);
    dock->setWidget(plotDialog);
    main.show();
    QTest::qWait(100); 
    main.resize(180,180);
    QTest::qWait(100); //should not crash;
}

QTEST_MAIN(tst_Q3MainWindow)
#include "tst_q3mainwindow.moc"