author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
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:
3
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 |
||
45 |
#include <qcombobox.h> |
|
46 |
#include <qmainwindow.h> |
|
47 |
#include <qmenubar.h> |
|
48 |
#include <qmenu.h> |
|
49 |
#include <qtoolbar.h> |
|
50 |
||
51 |
||
52 |
#include <qaction.h> |
|
53 |
||
54 |
//TESTED_CLASS= |
|
55 |
//TESTED_FILES= |
|
56 |
||
57 |
class tst_QActionGroup : public QObject |
|
58 |
{ |
|
59 |
Q_OBJECT |
|
60 |
||
61 |
public: |
|
62 |
tst_QActionGroup(); |
|
63 |
virtual ~tst_QActionGroup(); |
|
64 |
||
65 |
private slots: |
|
66 |
void enabledPropagation(); |
|
67 |
void visiblePropagation(); |
|
68 |
void dropDownDeleted(); |
|
69 |
void exclusive(); |
|
70 |
||
71 |
void separators(); |
|
72 |
void testActionInTwoQActionGroup(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
void unCheckCurrentAction(); |
0 | 74 |
}; |
75 |
||
76 |
tst_QActionGroup::tst_QActionGroup() |
|
77 |
{ |
|
78 |
} |
|
79 |
||
80 |
tst_QActionGroup::~tst_QActionGroup() |
|
81 |
{ |
|
82 |
} |
|
83 |
||
84 |
void tst_QActionGroup::enabledPropagation() |
|
85 |
{ |
|
86 |
QActionGroup testActionGroup( 0 ); |
|
87 |
||
88 |
QAction* childAction = new QAction( &testActionGroup ); |
|
89 |
QAction* anotherChildAction = new QAction( &testActionGroup ); |
|
90 |
QAction* freeAction = new QAction(0); |
|
91 |
||
92 |
QVERIFY( testActionGroup.isEnabled() ); |
|
93 |
QVERIFY( childAction->isEnabled() ); |
|
94 |
||
95 |
testActionGroup.setEnabled( false ); |
|
96 |
QVERIFY( !testActionGroup.isEnabled() ); |
|
97 |
QVERIFY( !childAction->isEnabled() ); |
|
98 |
QVERIFY( !anotherChildAction->isEnabled() ); |
|
99 |
||
100 |
childAction->setEnabled(true); |
|
101 |
QVERIFY( !childAction->isEnabled()); |
|
102 |
||
103 |
anotherChildAction->setEnabled( false ); |
|
104 |
||
105 |
testActionGroup.setEnabled( true ); |
|
106 |
QVERIFY( testActionGroup.isEnabled() ); |
|
107 |
QVERIFY( childAction->isEnabled() ); |
|
108 |
QVERIFY( !anotherChildAction->isEnabled() ); |
|
109 |
||
110 |
testActionGroup.setEnabled( false ); |
|
111 |
QAction *lastChildAction = new QAction(&testActionGroup); |
|
112 |
||
113 |
QVERIFY(!lastChildAction->isEnabled()); |
|
114 |
testActionGroup.setEnabled( true ); |
|
115 |
QVERIFY(lastChildAction->isEnabled()); |
|
116 |
||
117 |
freeAction->setEnabled(false); |
|
118 |
testActionGroup.addAction(freeAction); |
|
119 |
QVERIFY(!freeAction->isEnabled()); |
|
120 |
delete freeAction; |
|
121 |
} |
|
122 |
||
123 |
void tst_QActionGroup::visiblePropagation() |
|
124 |
{ |
|
125 |
QActionGroup testActionGroup( 0 ); |
|
126 |
||
127 |
QAction* childAction = new QAction( &testActionGroup ); |
|
128 |
QAction* anotherChildAction = new QAction( &testActionGroup ); |
|
129 |
QAction* freeAction = new QAction(0); |
|
130 |
||
131 |
QVERIFY( testActionGroup.isVisible() ); |
|
132 |
QVERIFY( childAction->isVisible() ); |
|
133 |
||
134 |
testActionGroup.setVisible( false ); |
|
135 |
QVERIFY( !testActionGroup.isVisible() ); |
|
136 |
QVERIFY( !childAction->isVisible() ); |
|
137 |
QVERIFY( !anotherChildAction->isVisible() ); |
|
138 |
||
139 |
anotherChildAction->setVisible(false); |
|
140 |
||
141 |
testActionGroup.setVisible( true ); |
|
142 |
QVERIFY( testActionGroup.isVisible() ); |
|
143 |
QVERIFY( childAction->isVisible() ); |
|
144 |
||
145 |
QVERIFY( !anotherChildAction->isVisible() ); |
|
146 |
||
147 |
testActionGroup.setVisible( false ); |
|
148 |
QAction *lastChildAction = new QAction(&testActionGroup); |
|
149 |
||
150 |
QVERIFY(!lastChildAction->isVisible()); |
|
151 |
testActionGroup.setVisible( true ); |
|
152 |
QVERIFY(lastChildAction->isVisible()); |
|
153 |
||
154 |
freeAction->setVisible(false); |
|
155 |
testActionGroup.addAction(freeAction); |
|
156 |
QVERIFY(!freeAction->isVisible()); |
|
157 |
delete freeAction; |
|
158 |
} |
|
159 |
||
160 |
void tst_QActionGroup::exclusive() |
|
161 |
{ |
|
162 |
QActionGroup group(0); |
|
163 |
group.setExclusive(false); |
|
164 |
QVERIFY( !group.isExclusive() ); |
|
165 |
||
166 |
QAction* actOne = new QAction( &group ); |
|
167 |
actOne->setCheckable( true ); |
|
168 |
QAction* actTwo = new QAction( &group ); |
|
169 |
actTwo->setCheckable( true ); |
|
170 |
QAction* actThree = new QAction( &group ); |
|
171 |
actThree->setCheckable( true ); |
|
172 |
||
173 |
group.setExclusive( true ); |
|
174 |
QVERIFY( !actOne->isChecked() ); |
|
175 |
QVERIFY( !actTwo->isChecked() ); |
|
176 |
QVERIFY( !actThree->isChecked() ); |
|
177 |
||
178 |
actOne->setChecked( true ); |
|
179 |
QVERIFY( actOne->isChecked() ); |
|
180 |
QVERIFY( !actTwo->isChecked() ); |
|
181 |
QVERIFY( !actThree->isChecked() ); |
|
182 |
||
183 |
actTwo->setChecked( true ); |
|
184 |
QVERIFY( !actOne->isChecked() ); |
|
185 |
QVERIFY( actTwo->isChecked() ); |
|
186 |
QVERIFY( !actThree->isChecked() ); |
|
187 |
} |
|
188 |
||
189 |
void tst_QActionGroup::dropDownDeleted() |
|
190 |
{ |
|
191 |
QSKIP("dropDownDeleted test for Qt 4.0 not expected to work since it is not implemented yet", SkipAll); |
|
192 |
||
193 |
QMainWindow mw; |
|
194 |
QToolBar *tb = new QToolBar(&mw); |
|
195 |
QActionGroup *actGroup = new QActionGroup(&mw); |
|
196 |
||
197 |
/// ### actGroup->setUsesDropDown(true); |
|
198 |
QAction *actOne = new QAction(actGroup); |
|
199 |
actOne->setText("test one"); |
|
200 |
QAction *actTwo = new QAction(actGroup); |
|
201 |
actOne->setText("test one"); |
|
202 |
QAction *actThree= new QAction(actGroup); |
|
203 |
actOne->setText("test one"); |
|
204 |
||
205 |
QListIterator<QAction*> it(actGroup->actions()); |
|
206 |
while (it.hasNext()) |
|
207 |
tb->addAction(it.next()); |
|
208 |
||
209 |
QList<QComboBox*> comboList = qFindChildren<QComboBox*>(tb); |
|
210 |
QCOMPARE(comboList[0]->count(), 3); |
|
211 |
||
212 |
delete actOne; |
|
213 |
QCOMPARE((int)comboList[0]->count(), 2); |
|
214 |
delete actTwo; |
|
215 |
QCOMPARE((int)comboList[0]->count(), 1); |
|
216 |
delete actThree; |
|
217 |
QCOMPARE((int)comboList[0]->count(), 0); |
|
218 |
||
219 |
delete actGroup; |
|
220 |
} |
|
221 |
||
222 |
void tst_QActionGroup::separators() |
|
223 |
{ |
|
224 |
QMainWindow mw; |
|
225 |
QMenu menu(&mw); |
|
226 |
QActionGroup actGroup(&mw); |
|
227 |
||
228 |
mw.show(); |
|
229 |
||
230 |
#ifdef QT_SOFTKEYS_ENABLED |
|
231 |
// Softkeys add extra "Select" and "Back" actions to menu by default. |
|
232 |
// Two first actions will be Select and Back when softkeys are enabled |
|
233 |
int numSoftkeyActions = 2; |
|
234 |
#else |
|
235 |
int numSoftkeyActions = 0; |
|
236 |
#endif |
|
237 |
||
238 |
QAction *action = new QAction(&actGroup); |
|
239 |
action->setText("test one"); |
|
240 |
||
241 |
QAction *separator = new QAction(&actGroup); |
|
242 |
separator->setSeparator(true); |
|
243 |
actGroup.addAction(separator); |
|
244 |
||
245 |
QListIterator<QAction*> it(actGroup.actions()); |
|
246 |
while (it.hasNext()) |
|
247 |
menu.addAction(it.next()); |
|
248 |
||
249 |
QCOMPARE((int)menu.actions().size(), 2 + numSoftkeyActions); |
|
250 |
||
251 |
it = QListIterator<QAction*>(actGroup.actions()); |
|
252 |
while (it.hasNext()) |
|
253 |
menu.removeAction(it.next()); |
|
254 |
||
255 |
QCOMPARE((int)menu.actions().size(), 0 + numSoftkeyActions); |
|
256 |
||
257 |
action = new QAction(&actGroup); |
|
258 |
action->setText("test two"); |
|
259 |
||
260 |
it = QListIterator<QAction*>(actGroup.actions()); |
|
261 |
while (it.hasNext()) |
|
262 |
menu.addAction(it.next()); |
|
263 |
||
264 |
QCOMPARE((int)menu.actions().size(), 3 + numSoftkeyActions); |
|
265 |
} |
|
266 |
||
267 |
void tst_QActionGroup::testActionInTwoQActionGroup() |
|
268 |
{ |
|
269 |
QAction action1("Action 1", this); |
|
270 |
||
271 |
QActionGroup group1(this); |
|
272 |
QActionGroup group2(this); |
|
273 |
||
274 |
group1.addAction(&action1); |
|
275 |
group2.addAction(&action1); |
|
276 |
||
277 |
QCOMPARE(action1.actionGroup(), &group2); |
|
278 |
QCOMPARE(group2.actions().first(), &action1); |
|
279 |
QCOMPARE(group1.actions().isEmpty(), true); |
|
280 |
} |
|
281 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
void tst_QActionGroup::unCheckCurrentAction() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
QActionGroup group(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
QAction action1(&group) ,action2(&group); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
action1.setCheckable(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
action2.setCheckable(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
QVERIFY(!action1.isChecked()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
QVERIFY(!action2.isChecked()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
action1.setChecked(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
QVERIFY(action1.isChecked()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
292 |
QVERIFY(!action2.isChecked()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
QAction *current = group.checkedAction(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
QCOMPARE(current, &action1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
295 |
current->setChecked(false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
296 |
QVERIFY(!action1.isChecked()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
QVERIFY(!action2.isChecked()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
QVERIFY(group.checkedAction() == 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
300 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
301 |
|
0 | 302 |
QTEST_MAIN(tst_QActionGroup) |
303 |
#include "tst_qactiongroup.moc" |