author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <q3toolbar.h> |
|
45 |
#include <q3mainwindow.h> |
|
46 |
#include <qaction.h> |
|
47 |
#include <qapplication.h> |
|
48 |
#include <QToolButton> |
|
49 |
#include <q3action.h> |
|
50 |
#include <qmenu.h> |
|
51 |
||
52 |
//TESTED_CLASS= |
|
53 |
//TESTED_FILES= |
|
54 |
||
55 |
#if defined Q_CC_MSVC && _MSC_VER <= 1200 |
|
56 |
#define NOFINDCHILDRENMETHOD |
|
57 |
#endif |
|
58 |
||
59 |
class tst_Q3ToolBar : public QObject |
|
60 |
{ |
|
61 |
Q_OBJECT |
|
62 |
||
63 |
public: |
|
64 |
tst_Q3ToolBar(); |
|
65 |
virtual ~tst_Q3ToolBar(); |
|
66 |
||
67 |
public slots: |
|
68 |
void initTestCase(); |
|
69 |
void cleanupTestCase(); |
|
70 |
void init(); |
|
71 |
void cleanup(); |
|
72 |
||
73 |
private slots: |
|
74 |
void toggled(); |
|
75 |
void actionGroupPopup(); |
|
76 |
||
77 |
// task-specific tests below me |
|
78 |
void task182657(); |
|
79 |
||
80 |
private: |
|
81 |
Q3ToolBar* testWidget; |
|
82 |
}; |
|
83 |
||
84 |
tst_Q3ToolBar::tst_Q3ToolBar() |
|
85 |
{ |
|
86 |
} |
|
87 |
||
88 |
tst_Q3ToolBar::~tst_Q3ToolBar() |
|
89 |
{ |
|
90 |
||
91 |
} |
|
92 |
||
93 |
void tst_Q3ToolBar::initTestCase() |
|
94 |
{ |
|
95 |
testWidget = new Q3ToolBar(0, "testWidget"); |
|
96 |
testWidget->show(); |
|
97 |
qApp->setMainWidget(testWidget); |
|
98 |
||
99 |
QTest::qWait(100); |
|
100 |
} |
|
101 |
||
102 |
void tst_Q3ToolBar::cleanupTestCase() |
|
103 |
{ |
|
104 |
delete testWidget; |
|
105 |
} |
|
106 |
||
107 |
void tst_Q3ToolBar::init() |
|
108 |
{ |
|
109 |
} |
|
110 |
||
111 |
void tst_Q3ToolBar::cleanup() |
|
112 |
{ |
|
113 |
} |
|
114 |
||
115 |
void tst_Q3ToolBar::toggled() |
|
116 |
{ |
|
117 |
// When clicking on a toggled action it should emit a signal |
|
118 |
QAction *action = new QAction( this, "action" ); |
|
119 |
action->setToggleAction( true ); |
|
120 |
action->addTo(testWidget); |
|
121 |
testWidget->show(); |
|
122 |
QSignalSpy spy(action, SIGNAL(toggled(bool))); |
|
123 |
#ifndef NOFINDCHILDRENMETHOD |
|
124 |
QList<QToolButton *> list = testWidget->findChildren<QToolButton *>(); |
|
125 |
#else |
|
126 |
QList<QToolButton *> list = qFindChildren<QToolButton *>(testWidget, QString()); |
|
127 |
||
128 |
#endif |
|
129 |
for (int i = 0; i < list.size(); ++i) |
|
130 |
QTest::mouseClick(list.at(i), Qt::LeftButton); |
|
131 |
QCOMPARE(spy.count(), 1); |
|
132 |
||
133 |
// Also try the othe case (a toggled action will emit the toolbuttons toggled) |
|
134 |
QSignalSpy spy2(list.at(1), SIGNAL(toggled(bool))); |
|
135 |
action->setChecked(!action->isChecked()); |
|
136 |
QCOMPARE(spy2.count(), 1); |
|
137 |
||
138 |
} |
|
139 |
||
140 |
class MenuEventFilter : public QObject |
|
141 |
{ |
|
142 |
public: |
|
143 |
MenuEventFilter(QObject *parent = 0) : QObject(parent), menuShown(false) {} |
|
144 |
bool wasMenuShown() const { return menuShown; } |
|
145 |
void setMenuShown(bool b) { menuShown = b; } |
|
146 |
protected: |
|
147 |
bool eventFilter(QObject *o, QEvent *e) |
|
148 |
{ |
|
149 |
if (e->type() == QEvent::Show) { |
|
150 |
menuShown = true; |
|
151 |
QTimer::singleShot(0, o, SLOT(hide())); |
|
152 |
} |
|
153 |
return false; |
|
154 |
} |
|
155 |
private: |
|
156 |
bool menuShown; |
|
157 |
}; |
|
158 |
||
159 |
void tst_Q3ToolBar::actionGroupPopup() |
|
160 |
{ |
|
161 |
Q3ActionGroup* ag = new Q3ActionGroup(testWidget); |
|
162 |
ag->setText("Group"); |
|
163 |
ag->setUsesDropDown(true); |
|
164 |
ag->setExclusive(false); |
|
165 |
Q3Action *a = new Q3Action(QIcon(), "ActionA", QKeySequence(), ag); |
|
166 |
a->setToggleAction(true); |
|
167 |
Q3Action *b = new Q3Action(QIcon(), "ActionB", QKeySequence(), ag); |
|
168 |
b->setToggleAction(true); |
|
169 |
ag->addTo(testWidget); |
|
170 |
QTest::qWait(100); |
|
171 |
#ifndef NOFINDCHILDRENMETHOD |
|
172 |
QList<QToolButton *> list = testWidget->findChildren<QToolButton *>(); |
|
173 |
#else |
|
174 |
QList<QToolButton *> list = qFindChildren<QToolButton *>(testWidget, QString()); |
|
175 |
#endif |
|
176 |
QToolButton *tb = 0; |
|
177 |
for (int i=0;i<list.size();i++) { |
|
178 |
if (list.at(i)->menu()) { |
|
179 |
tb = list.at(i); |
|
180 |
break; |
|
181 |
} |
|
182 |
} |
|
183 |
MenuEventFilter mef; |
|
184 |
tb->menu()->installEventFilter(&mef); |
|
185 |
QTest::mouseClick(tb, Qt::LeftButton, 0, QPoint(5,5)); |
|
186 |
QVERIFY(!mef.wasMenuShown()); |
|
187 |
QTest::mouseClick(tb, Qt::LeftButton, 0, QPoint(tb->rect().right() - 5, tb->rect().bottom() - 5)); |
|
188 |
QVERIFY(mef.wasMenuShown()); |
|
189 |
} |
|
190 |
||
191 |
class Q3MainWindow_task182657 : public Q3MainWindow |
|
192 |
{ |
|
193 |
Q3ToolBar *toolbar; |
|
194 |
||
195 |
public: |
|
196 |
Q3MainWindow_task182657(QWidget *parent = 0) |
|
197 |
: Q3MainWindow(parent) |
|
198 |
{ |
|
199 |
toolbar = new Q3ToolBar(this); |
|
200 |
} |
|
201 |
||
202 |
void rebuild() |
|
203 |
{ |
|
204 |
toolbar->clear(); |
|
205 |
new QToolButton(toolbar, "b"); |
|
206 |
new QToolButton(toolbar, "a"); |
|
207 |
} |
|
208 |
}; |
|
209 |
||
210 |
void tst_Q3ToolBar::task182657() |
|
211 |
{ |
|
212 |
Q3MainWindow_task182657 *window = new Q3MainWindow_task182657; |
|
213 |
window->show(); |
|
214 |
qApp->processEvents(); |
|
215 |
window->rebuild(); |
|
216 |
qApp->processEvents(); |
|
217 |
window->rebuild(); |
|
218 |
qApp->processEvents(); |
|
219 |
} |
|
220 |
||
221 |
QTEST_MAIN(tst_Q3ToolBar) |
|
222 |
#include "tst_q3toolbar.moc" |