|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 ** 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(); |
|
73 }; |
|
74 |
|
75 tst_QActionGroup::tst_QActionGroup() |
|
76 { |
|
77 } |
|
78 |
|
79 tst_QActionGroup::~tst_QActionGroup() |
|
80 { |
|
81 } |
|
82 |
|
83 void tst_QActionGroup::enabledPropagation() |
|
84 { |
|
85 QActionGroup testActionGroup( 0 ); |
|
86 |
|
87 QAction* childAction = new QAction( &testActionGroup ); |
|
88 QAction* anotherChildAction = new QAction( &testActionGroup ); |
|
89 QAction* freeAction = new QAction(0); |
|
90 |
|
91 QVERIFY( testActionGroup.isEnabled() ); |
|
92 QVERIFY( childAction->isEnabled() ); |
|
93 |
|
94 testActionGroup.setEnabled( false ); |
|
95 QVERIFY( !testActionGroup.isEnabled() ); |
|
96 QVERIFY( !childAction->isEnabled() ); |
|
97 QVERIFY( !anotherChildAction->isEnabled() ); |
|
98 |
|
99 childAction->setEnabled(true); |
|
100 QVERIFY( !childAction->isEnabled()); |
|
101 |
|
102 anotherChildAction->setEnabled( false ); |
|
103 |
|
104 testActionGroup.setEnabled( true ); |
|
105 QVERIFY( testActionGroup.isEnabled() ); |
|
106 QVERIFY( childAction->isEnabled() ); |
|
107 QVERIFY( !anotherChildAction->isEnabled() ); |
|
108 |
|
109 testActionGroup.setEnabled( false ); |
|
110 QAction *lastChildAction = new QAction(&testActionGroup); |
|
111 |
|
112 QVERIFY(!lastChildAction->isEnabled()); |
|
113 testActionGroup.setEnabled( true ); |
|
114 QVERIFY(lastChildAction->isEnabled()); |
|
115 |
|
116 freeAction->setEnabled(false); |
|
117 testActionGroup.addAction(freeAction); |
|
118 QVERIFY(!freeAction->isEnabled()); |
|
119 delete freeAction; |
|
120 } |
|
121 |
|
122 void tst_QActionGroup::visiblePropagation() |
|
123 { |
|
124 QActionGroup testActionGroup( 0 ); |
|
125 |
|
126 QAction* childAction = new QAction( &testActionGroup ); |
|
127 QAction* anotherChildAction = new QAction( &testActionGroup ); |
|
128 QAction* freeAction = new QAction(0); |
|
129 |
|
130 QVERIFY( testActionGroup.isVisible() ); |
|
131 QVERIFY( childAction->isVisible() ); |
|
132 |
|
133 testActionGroup.setVisible( false ); |
|
134 QVERIFY( !testActionGroup.isVisible() ); |
|
135 QVERIFY( !childAction->isVisible() ); |
|
136 QVERIFY( !anotherChildAction->isVisible() ); |
|
137 |
|
138 anotherChildAction->setVisible(false); |
|
139 |
|
140 testActionGroup.setVisible( true ); |
|
141 QVERIFY( testActionGroup.isVisible() ); |
|
142 QVERIFY( childAction->isVisible() ); |
|
143 |
|
144 QVERIFY( !anotherChildAction->isVisible() ); |
|
145 |
|
146 testActionGroup.setVisible( false ); |
|
147 QAction *lastChildAction = new QAction(&testActionGroup); |
|
148 |
|
149 QVERIFY(!lastChildAction->isVisible()); |
|
150 testActionGroup.setVisible( true ); |
|
151 QVERIFY(lastChildAction->isVisible()); |
|
152 |
|
153 freeAction->setVisible(false); |
|
154 testActionGroup.addAction(freeAction); |
|
155 QVERIFY(!freeAction->isVisible()); |
|
156 delete freeAction; |
|
157 } |
|
158 |
|
159 void tst_QActionGroup::exclusive() |
|
160 { |
|
161 QActionGroup group(0); |
|
162 group.setExclusive(false); |
|
163 QVERIFY( !group.isExclusive() ); |
|
164 |
|
165 QAction* actOne = new QAction( &group ); |
|
166 actOne->setCheckable( true ); |
|
167 QAction* actTwo = new QAction( &group ); |
|
168 actTwo->setCheckable( true ); |
|
169 QAction* actThree = new QAction( &group ); |
|
170 actThree->setCheckable( true ); |
|
171 |
|
172 group.setExclusive( true ); |
|
173 QVERIFY( !actOne->isChecked() ); |
|
174 QVERIFY( !actTwo->isChecked() ); |
|
175 QVERIFY( !actThree->isChecked() ); |
|
176 |
|
177 actOne->setChecked( true ); |
|
178 QVERIFY( actOne->isChecked() ); |
|
179 QVERIFY( !actTwo->isChecked() ); |
|
180 QVERIFY( !actThree->isChecked() ); |
|
181 |
|
182 actTwo->setChecked( true ); |
|
183 QVERIFY( !actOne->isChecked() ); |
|
184 QVERIFY( actTwo->isChecked() ); |
|
185 QVERIFY( !actThree->isChecked() ); |
|
186 } |
|
187 |
|
188 void tst_QActionGroup::dropDownDeleted() |
|
189 { |
|
190 QSKIP("dropDownDeleted test for Qt 4.0 not expected to work since it is not implemented yet", SkipAll); |
|
191 |
|
192 QMainWindow mw; |
|
193 QToolBar *tb = new QToolBar(&mw); |
|
194 QActionGroup *actGroup = new QActionGroup(&mw); |
|
195 |
|
196 /// ### actGroup->setUsesDropDown(true); |
|
197 QAction *actOne = new QAction(actGroup); |
|
198 actOne->setText("test one"); |
|
199 QAction *actTwo = new QAction(actGroup); |
|
200 actOne->setText("test one"); |
|
201 QAction *actThree= new QAction(actGroup); |
|
202 actOne->setText("test one"); |
|
203 |
|
204 QListIterator<QAction*> it(actGroup->actions()); |
|
205 while (it.hasNext()) |
|
206 tb->addAction(it.next()); |
|
207 |
|
208 QList<QComboBox*> comboList = qFindChildren<QComboBox*>(tb); |
|
209 QCOMPARE(comboList[0]->count(), 3); |
|
210 |
|
211 delete actOne; |
|
212 QCOMPARE((int)comboList[0]->count(), 2); |
|
213 delete actTwo; |
|
214 QCOMPARE((int)comboList[0]->count(), 1); |
|
215 delete actThree; |
|
216 QCOMPARE((int)comboList[0]->count(), 0); |
|
217 |
|
218 delete actGroup; |
|
219 } |
|
220 |
|
221 void tst_QActionGroup::separators() |
|
222 { |
|
223 QMainWindow mw; |
|
224 QMenu menu(&mw); |
|
225 QActionGroup actGroup(&mw); |
|
226 |
|
227 mw.show(); |
|
228 |
|
229 #ifdef QT_SOFTKEYS_ENABLED |
|
230 // Softkeys add extra "Select" and "Back" actions to menu by default. |
|
231 // Two first actions will be Select and Back when softkeys are enabled |
|
232 int numSoftkeyActions = 2; |
|
233 #else |
|
234 int numSoftkeyActions = 0; |
|
235 #endif |
|
236 |
|
237 QAction *action = new QAction(&actGroup); |
|
238 action->setText("test one"); |
|
239 |
|
240 QAction *separator = new QAction(&actGroup); |
|
241 separator->setSeparator(true); |
|
242 actGroup.addAction(separator); |
|
243 |
|
244 QListIterator<QAction*> it(actGroup.actions()); |
|
245 while (it.hasNext()) |
|
246 menu.addAction(it.next()); |
|
247 |
|
248 QCOMPARE((int)menu.actions().size(), 2 + numSoftkeyActions); |
|
249 |
|
250 it = QListIterator<QAction*>(actGroup.actions()); |
|
251 while (it.hasNext()) |
|
252 menu.removeAction(it.next()); |
|
253 |
|
254 QCOMPARE((int)menu.actions().size(), 0 + numSoftkeyActions); |
|
255 |
|
256 action = new QAction(&actGroup); |
|
257 action->setText("test two"); |
|
258 |
|
259 it = QListIterator<QAction*>(actGroup.actions()); |
|
260 while (it.hasNext()) |
|
261 menu.addAction(it.next()); |
|
262 |
|
263 QCOMPARE((int)menu.actions().size(), 3 + numSoftkeyActions); |
|
264 } |
|
265 |
|
266 void tst_QActionGroup::testActionInTwoQActionGroup() |
|
267 { |
|
268 QAction action1("Action 1", this); |
|
269 |
|
270 QActionGroup group1(this); |
|
271 QActionGroup group2(this); |
|
272 |
|
273 group1.addAction(&action1); |
|
274 group2.addAction(&action1); |
|
275 |
|
276 QCOMPARE(action1.actionGroup(), &group2); |
|
277 QCOMPARE(group2.actions().first(), &action1); |
|
278 QCOMPARE(group1.actions().isEmpty(), true); |
|
279 } |
|
280 |
|
281 QTEST_MAIN(tst_QActionGroup) |
|
282 #include "tst_qactiongroup.moc" |