author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
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 |
#include <QtTest/QtTest> |
|
42 |
#include <QtGui/QPushButton> |
|
43 |
#include <QtGui/QStyle> |
|
44 |
#include <QtGui/QLayout> |
|
45 |
#include <QtGui/QDialog> |
|
46 |
#include <QtGui/QAction> |
|
47 |
#include <qdialogbuttonbox.h> |
|
48 |
#include <limits.h> |
|
49 |
||
50 |
//TESTED_CLASS= |
|
51 |
//TESTED_FILES= |
|
52 |
||
53 |
Q_DECLARE_METATYPE(QList<int>) |
|
54 |
Q_DECLARE_METATYPE(QDialogButtonBox::ButtonRole) |
|
55 |
Q_DECLARE_METATYPE(QDialogButtonBox::StandardButton) |
|
56 |
Q_DECLARE_METATYPE(QDialogButtonBox::StandardButtons) |
|
57 |
Q_DECLARE_METATYPE(QAbstractButton*) |
|
58 |
||
59 |
class tst_QDialogButtonBox : public QObject |
|
60 |
{ |
|
61 |
Q_OBJECT |
|
62 |
public: |
|
63 |
tst_QDialogButtonBox(); |
|
64 |
~tst_QDialogButtonBox(); |
|
65 |
||
66 |
||
67 |
public slots: |
|
68 |
void buttonClicked1(QAbstractButton *); |
|
69 |
void acceptClicked(); |
|
70 |
void rejectClicked(); |
|
71 |
void helpRequestedClicked(); |
|
72 |
||
73 |
private slots: |
|
74 |
void standardButtons(); |
|
75 |
void testConstructor1(); |
|
76 |
void testConstrurtor2(); |
|
77 |
void testConstrurtor2_data(); |
|
78 |
void testConstructor3(); |
|
79 |
void testConstructor3_data(); |
|
80 |
void setOrientation_data(); |
|
81 |
void setOrientation(); |
|
82 |
void addButton1_data(); |
|
83 |
void addButton1(); |
|
84 |
void addButton2_data(); |
|
85 |
void addButton2(); |
|
86 |
void addButton3_data(); |
|
87 |
void addButton3(); |
|
88 |
void clear_data(); |
|
89 |
void clear(); |
|
90 |
void removeButton_data(); |
|
91 |
void removeButton(); |
|
92 |
void buttonRole_data(); |
|
93 |
void buttonRole(); |
|
94 |
void setStandardButtons_data(); |
|
95 |
void setStandardButtons(); |
|
96 |
void layoutReuse(); |
|
97 |
||
98 |
||
99 |
// Skip these tests, buttons is used in every test thus far. |
|
100 |
// void buttons_data(); |
|
101 |
// void buttons(); |
|
102 |
||
103 |
void testDelete(); |
|
104 |
void testRemove(); |
|
105 |
void testMultipleAdd(); |
|
106 |
void testStandardButtonMapping_data(); |
|
107 |
void testStandardButtonMapping(); |
|
108 |
void testSignals_data(); |
|
109 |
void testSignals(); |
|
110 |
void testSignalOrder(); |
|
111 |
void testDefaultButton_data(); |
|
112 |
void testDefaultButton(); |
|
113 |
void testS60SoftKeys(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
#ifdef QT_SOFTKEYS_ENABLED |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
115 |
void testSoftKeyReparenting(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
#endif |
0 | 117 |
|
118 |
void task191642_default(); |
|
119 |
private: |
|
120 |
qint64 timeStamp; |
|
121 |
qint64 buttonClicked1TimeStamp; |
|
122 |
qint64 acceptTimeStamp; |
|
123 |
qint64 rejectTimeStamp; |
|
124 |
qint64 helpRequestedTimeStamp; |
|
125 |
}; |
|
126 |
||
127 |
tst_QDialogButtonBox::tst_QDialogButtonBox() |
|
128 |
{ |
|
129 |
} |
|
130 |
||
131 |
tst_QDialogButtonBox::~tst_QDialogButtonBox() |
|
132 |
{ |
|
133 |
} |
|
134 |
||
135 |
void tst_QDialogButtonBox::testConstructor1() |
|
136 |
{ |
|
137 |
QDialogButtonBox buttonbox; |
|
138 |
QCOMPARE(buttonbox.orientation(), Qt::Horizontal); |
|
139 |
||
140 |
QCOMPARE(buttonbox.buttons().count(), 0); |
|
141 |
} |
|
142 |
||
143 |
void tst_QDialogButtonBox::layoutReuse() |
|
144 |
{ |
|
145 |
QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Ok); |
|
146 |
QPointer<QLayout> layout = box->layout(); |
|
147 |
box->setCenterButtons(!box->centerButtons()); |
|
148 |
QVERIFY(layout == box->layout()); |
|
149 |
QEvent event(QEvent::StyleChange); |
|
150 |
QApplication::sendEvent(box, &event); |
|
151 |
QVERIFY(layout == box->layout()); |
|
152 |
box->setOrientation(box->orientation() == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal); |
|
153 |
QVERIFY(layout == 0); |
|
154 |
QVERIFY(layout != box->layout()); |
|
155 |
delete box; |
|
156 |
} |
|
157 |
||
158 |
void tst_QDialogButtonBox::testConstrurtor2_data() |
|
159 |
{ |
|
160 |
QTest::addColumn<int>("orientation"); |
|
161 |
||
162 |
QTest::newRow("horizontal") << int(Qt::Horizontal); |
|
163 |
QTest::newRow("vertical") << int(Qt::Vertical); |
|
164 |
} |
|
165 |
||
166 |
void tst_QDialogButtonBox::testConstrurtor2() |
|
167 |
{ |
|
168 |
QFETCH(int, orientation); |
|
169 |
Qt::Orientation orient = Qt::Orientation(orientation); |
|
170 |
QDialogButtonBox buttonBox(orient); |
|
171 |
||
172 |
QCOMPARE(buttonBox.orientation(), orient); |
|
173 |
QCOMPARE(buttonBox.buttons().count(), 0); |
|
174 |
} |
|
175 |
||
176 |
void tst_QDialogButtonBox::testConstructor3_data() |
|
177 |
{ |
|
178 |
QTest::addColumn<int>("orientation"); |
|
179 |
QTest::addColumn<QDialogButtonBox::StandardButtons>("buttons"); |
|
180 |
QTest::addColumn<int>("buttonCount"); |
|
181 |
||
182 |
QTest::newRow("nothing") << int(Qt::Horizontal) << (QDialogButtonBox::StandardButtons)0 << 0; |
|
183 |
QTest::newRow("only 1") << int(Qt::Horizontal) << QDialogButtonBox::StandardButtons(QDialogButtonBox::Ok) << 1; |
|
184 |
QTest::newRow("only 1.. twice") << int(Qt::Horizontal) |
|
185 |
<< (QDialogButtonBox::Ok | QDialogButtonBox::Ok) |
|
186 |
<< 1; |
|
187 |
QTest::newRow("only 2") << int(Qt::Horizontal) |
|
188 |
<< (QDialogButtonBox::Ok | QDialogButtonBox::Cancel) |
|
189 |
<< 2; |
|
190 |
QTest::newRow("two different things") << int(Qt::Horizontal) |
|
191 |
<< (QDialogButtonBox::Save | QDialogButtonBox::Close) |
|
192 |
<< 2; |
|
193 |
QTest::newRow("three") << int(Qt::Horizontal) |
|
194 |
<< (QDialogButtonBox::Ok |
|
195 |
| QDialogButtonBox::Cancel |
|
196 |
| QDialogButtonBox::Help) |
|
197 |
<< 3; |
|
198 |
QTest::newRow("everything") << int(Qt::Vertical) |
|
199 |
<< (QDialogButtonBox::StandardButtons)UINT_MAX |
|
200 |
<< 18; |
|
201 |
} |
|
202 |
||
203 |
void tst_QDialogButtonBox::testConstructor3() |
|
204 |
{ |
|
205 |
QFETCH(int, orientation); |
|
206 |
QFETCH(QDialogButtonBox::StandardButtons, buttons); |
|
207 |
||
208 |
QDialogButtonBox buttonBox(buttons, (Qt::Orientation)orientation); |
|
209 |
QCOMPARE(int(buttonBox.orientation()), orientation); |
|
210 |
QTEST(buttonBox.buttons().count(), "buttonCount"); |
|
211 |
} |
|
212 |
||
213 |
void tst_QDialogButtonBox::setOrientation_data() |
|
214 |
{ |
|
215 |
QTest::addColumn<int>("orientation"); |
|
216 |
||
217 |
QTest::newRow("Horizontal") << int(Qt::Horizontal); |
|
218 |
QTest::newRow("Vertical") << int(Qt::Vertical); |
|
219 |
} |
|
220 |
||
221 |
void tst_QDialogButtonBox::setOrientation() |
|
222 |
{ |
|
223 |
QFETCH(int, orientation); |
|
224 |
QDialogButtonBox buttonBox; |
|
225 |
QCOMPARE(int(buttonBox.orientation()), int(Qt::Horizontal)); |
|
226 |
||
227 |
buttonBox.setOrientation(Qt::Orientation(orientation)); |
|
228 |
QCOMPARE(int(buttonBox.orientation()), orientation); |
|
229 |
} |
|
230 |
||
231 |
/* |
|
232 |
void tst_QDialogButtonBox::setLayoutPolicy_data() |
|
233 |
{ |
|
234 |
QTest::addColumn<int>("layoutPolicy"); |
|
235 |
||
236 |
QTest::newRow("win") << int(QDialogButtonBox::WinLayout); |
|
237 |
QTest::newRow("mac") << int(QDialogButtonBox::MacLayout); |
|
238 |
QTest::newRow("kde") << int(QDialogButtonBox::KdeLayout); |
|
239 |
QTest::newRow("gnome") << int(QDialogButtonBox::GnomeLayout); |
|
240 |
||
241 |
} |
|
242 |
||
243 |
void tst_QDialogButtonBox::setLayoutPolicy() |
|
244 |
{ |
|
245 |
QFETCH(int, layoutPolicy); |
|
246 |
||
247 |
QDialogButtonBox buttonBox; |
|
248 |
QCOMPARE(int(buttonBox.layoutPolicy()), |
|
249 |
int(buttonBox.style()->styleHint(QStyle::SH_DialogButtonLayout))); |
|
250 |
buttonBox.setLayoutPolicy(QDialogButtonBox::ButtonLayout(layoutPolicy)); |
|
251 |
QCOMPARE(int(buttonBox.layoutPolicy()), layoutPolicy); |
|
252 |
} |
|
253 |
*/ |
|
254 |
||
255 |
void tst_QDialogButtonBox::addButton1_data() |
|
256 |
{ |
|
257 |
QTest::addColumn<QDialogButtonBox::ButtonRole>("role"); |
|
258 |
QTest::addColumn<int>("totalCount"); |
|
259 |
||
260 |
QTest::newRow("InvalidRole") << QDialogButtonBox::InvalidRole << 0; |
|
261 |
QTest::newRow("AcceptRole") << QDialogButtonBox::AcceptRole << 1; |
|
262 |
QTest::newRow("RejectRole") << QDialogButtonBox::RejectRole << 1; |
|
263 |
QTest::newRow("DestructiveRole") << QDialogButtonBox::DestructiveRole << 1; |
|
264 |
QTest::newRow("ActionRole") << QDialogButtonBox::ActionRole << 1; |
|
265 |
QTest::newRow("HelpRole") << QDialogButtonBox::HelpRole << 1; |
|
266 |
QTest::newRow("WackyValue") << (QDialogButtonBox::ButtonRole)-1 << 0; |
|
267 |
} |
|
268 |
||
269 |
void tst_QDialogButtonBox::addButton1() |
|
270 |
{ |
|
271 |
QFETCH(QDialogButtonBox::ButtonRole, role); |
|
272 |
QDialogButtonBox buttonBox; |
|
273 |
QCOMPARE(buttonBox.buttons().count(), 0); |
|
274 |
QPushButton *button = new QPushButton(); |
|
275 |
buttonBox.addButton(button, role); |
|
276 |
QTEST(buttonBox.buttons().count(), "totalCount"); |
|
277 |
QList<QAbstractButton *> children = qFindChildren<QAbstractButton *>(&buttonBox); |
|
278 |
QTEST(children.count(), "totalCount"); |
|
279 |
delete button; |
|
280 |
} |
|
281 |
||
282 |
void tst_QDialogButtonBox::addButton2_data() |
|
283 |
{ |
|
284 |
QTest::addColumn<QString>("text"); |
|
285 |
QTest::addColumn<QDialogButtonBox::ButtonRole>("role"); |
|
286 |
QTest::addColumn<int>("totalCount"); |
|
287 |
QTest::newRow("InvalidRole") << QString("foo") << QDialogButtonBox::InvalidRole << 0; |
|
288 |
QTest::newRow("AcceptRole") << QString("foo") << QDialogButtonBox::AcceptRole << 1; |
|
289 |
QTest::newRow("RejectRole") << QString("foo") << QDialogButtonBox::RejectRole << 1; |
|
290 |
QTest::newRow("DestructiveRole") << QString("foo") << QDialogButtonBox::DestructiveRole << 1; |
|
291 |
QTest::newRow("ActionRole") << QString("foo") << QDialogButtonBox::ActionRole << 1; |
|
292 |
QTest::newRow("HelpRole") << QString("foo") << QDialogButtonBox::HelpRole << 1; |
|
293 |
QTest::newRow("WackyValue") << QString("foo") << (QDialogButtonBox::ButtonRole)-1 << 0; |
|
294 |
} |
|
295 |
||
296 |
void tst_QDialogButtonBox::addButton2() |
|
297 |
{ |
|
298 |
QFETCH(QString, text); |
|
299 |
QFETCH(QDialogButtonBox::ButtonRole, role); |
|
300 |
QDialogButtonBox buttonBox; |
|
301 |
QCOMPARE(buttonBox.buttons().count(), 0); |
|
302 |
buttonBox.addButton(text, role); |
|
303 |
QTEST(buttonBox.buttons().count(), "totalCount"); |
|
304 |
QList<QAbstractButton *> children = qFindChildren<QAbstractButton *>(&buttonBox); |
|
305 |
QTEST(children.count(), "totalCount"); |
|
306 |
} |
|
307 |
||
308 |
void tst_QDialogButtonBox::addButton3_data() |
|
309 |
{ |
|
310 |
QTest::addColumn<QDialogButtonBox::StandardButton>("button"); |
|
311 |
QTest::addColumn<int>("totalCount"); |
|
312 |
QTest::newRow("Ok") << QDialogButtonBox::Ok << 1; |
|
313 |
QTest::newRow("Open") << QDialogButtonBox::Open << 1; |
|
314 |
QTest::newRow("Save") << QDialogButtonBox::Save << 1; |
|
315 |
QTest::newRow("Cancel") << QDialogButtonBox::Cancel << 1; |
|
316 |
QTest::newRow("Close") << QDialogButtonBox::Close << 1; |
|
317 |
QTest::newRow("Discard") << QDialogButtonBox::Discard << 1; |
|
318 |
QTest::newRow("Apply") << QDialogButtonBox::Apply << 1; |
|
319 |
QTest::newRow("Reset") << QDialogButtonBox::Reset << 1; |
|
320 |
QTest::newRow("Help") << QDialogButtonBox::Help << 1; |
|
321 |
QTest::newRow("noButton") << (QDialogButtonBox::StandardButton)0 << 0; |
|
322 |
} |
|
323 |
||
324 |
void tst_QDialogButtonBox::addButton3() |
|
325 |
{ |
|
326 |
QFETCH(QDialogButtonBox::StandardButton, button); |
|
327 |
QDialogButtonBox buttonBox; |
|
328 |
QCOMPARE(buttonBox.buttons().count(), 0); |
|
329 |
buttonBox.addButton(button); |
|
330 |
QTEST(buttonBox.buttons().count(), "totalCount"); |
|
331 |
QList<QAbstractButton *> children = qFindChildren<QAbstractButton *>(&buttonBox); |
|
332 |
QTEST(children.count(), "totalCount"); |
|
333 |
} |
|
334 |
||
335 |
void tst_QDialogButtonBox::clear_data() |
|
336 |
{ |
|
337 |
QTest::addColumn<int>("rolesToAdd"); |
|
338 |
||
339 |
QTest::newRow("nothing") << 0; |
|
340 |
QTest::newRow("one") << 1; |
|
341 |
QTest::newRow("all") << int(QDialogButtonBox::NRoles); |
|
342 |
} |
|
343 |
||
344 |
void tst_QDialogButtonBox::clear() |
|
345 |
{ |
|
346 |
QFETCH(int, rolesToAdd); |
|
347 |
||
348 |
QDialogButtonBox buttonBox; |
|
349 |
for (int i = 1; i < rolesToAdd; ++i) |
|
350 |
buttonBox.addButton("Happy", QDialogButtonBox::ButtonRole(i)); |
|
351 |
buttonBox.clear(); |
|
352 |
QCOMPARE(buttonBox.buttons().count(), 0); |
|
353 |
QList<QAbstractButton *> children = qFindChildren<QAbstractButton *>(&buttonBox); |
|
354 |
QCOMPARE(children.count(), 0); |
|
355 |
} |
|
356 |
||
357 |
void tst_QDialogButtonBox::removeButton_data() |
|
358 |
{ |
|
359 |
QTest::addColumn<QDialogButtonBox::ButtonRole>("roleToAdd"); |
|
360 |
QTest::addColumn<int>("expectedCount"); |
|
361 |
QTest::newRow("no button added") << QDialogButtonBox::InvalidRole << 0; |
|
362 |
QTest::newRow("a button") << QDialogButtonBox::AcceptRole << 1; |
|
363 |
} |
|
364 |
||
365 |
void tst_QDialogButtonBox::removeButton() |
|
366 |
{ |
|
367 |
QFETCH(QDialogButtonBox::ButtonRole, roleToAdd); |
|
368 |
||
369 |
QDialogButtonBox buttonBox; |
|
370 |
QCOMPARE(buttonBox.buttons().count(), 0); |
|
371 |
QPushButton *button = new QPushButton("RemoveButton test"); |
|
372 |
buttonBox.addButton(button, roleToAdd); |
|
373 |
QTEST(buttonBox.buttons().count(), "expectedCount"); |
|
374 |
||
375 |
buttonBox.removeButton(button); |
|
376 |
QCOMPARE(buttonBox.buttons().count(), 0); |
|
377 |
delete button; |
|
378 |
} |
|
379 |
||
380 |
void tst_QDialogButtonBox::testDelete() |
|
381 |
{ |
|
382 |
QDialogButtonBox buttonBox; |
|
383 |
QCOMPARE(buttonBox.buttons().count(), 0); |
|
384 |
||
385 |
QPushButton *deleteMe = new QPushButton("Happy"); |
|
386 |
buttonBox.addButton(deleteMe, QDialogButtonBox::HelpRole); |
|
387 |
QCOMPARE(buttonBox.buttons().count(), 1); |
|
388 |
QList<QAbstractButton *> children = qFindChildren<QAbstractButton *>(&buttonBox); |
|
389 |
QCOMPARE(children.count(), 1); |
|
390 |
||
391 |
delete deleteMe; |
|
392 |
children = qFindChildren<QAbstractButton *>(&buttonBox); |
|
393 |
QCOMPARE(children.count(), 0); |
|
394 |
QCOMPARE(buttonBox.buttons().count(), 0); |
|
395 |
} |
|
396 |
||
397 |
void tst_QDialogButtonBox::testMultipleAdd() |
|
398 |
{ |
|
399 |
// Add a button into the thing multiple times. |
|
400 |
QDialogButtonBox buttonBox; |
|
401 |
QCOMPARE(buttonBox.buttons().count(), 0); |
|
402 |
||
403 |
QPushButton *button = new QPushButton("Foo away"); |
|
404 |
buttonBox.addButton(button, QDialogButtonBox::AcceptRole); |
|
405 |
QCOMPARE(buttonBox.buttons().count(), 1); |
|
406 |
QCOMPARE(buttonBox.buttonRole(button), QDialogButtonBox::AcceptRole); |
|
407 |
buttonBox.addButton(button, QDialogButtonBox::AcceptRole); |
|
408 |
QCOMPARE(buttonBox.buttons().count(), 1); |
|
409 |
QCOMPARE(buttonBox.buttonRole(button), QDialogButtonBox::AcceptRole); |
|
410 |
||
411 |
// Add it again with a different role |
|
412 |
buttonBox.addButton(button, QDialogButtonBox::RejectRole); |
|
413 |
QCOMPARE(buttonBox.buttons().count(), 1); |
|
414 |
QCOMPARE(buttonBox.buttonRole(button), QDialogButtonBox::RejectRole); |
|
415 |
||
416 |
// Add it as an "invalid" role |
|
417 |
buttonBox.addButton(button, QDialogButtonBox::InvalidRole); |
|
418 |
QCOMPARE(buttonBox.buttons().count(), 1); |
|
419 |
QCOMPARE(buttonBox.buttonRole(button), QDialogButtonBox::RejectRole); |
|
420 |
} |
|
421 |
||
422 |
void tst_QDialogButtonBox::buttonRole_data() |
|
423 |
{ |
|
424 |
QTest::addColumn<QDialogButtonBox::ButtonRole>("roleToAdd"); |
|
425 |
QTest::addColumn<QDialogButtonBox::ButtonRole>("expectedRole"); |
|
426 |
||
427 |
QTest::newRow("AcceptRole stuff") << QDialogButtonBox::AcceptRole |
|
428 |
<< QDialogButtonBox::AcceptRole; |
|
429 |
QTest::newRow("Nothing") << QDialogButtonBox::InvalidRole << QDialogButtonBox::InvalidRole; |
|
430 |
QTest::newRow("bad stuff") << (QDialogButtonBox::ButtonRole)-1 << QDialogButtonBox::InvalidRole; |
|
431 |
} |
|
432 |
||
433 |
void tst_QDialogButtonBox::buttonRole() |
|
434 |
{ |
|
435 |
QFETCH(QDialogButtonBox::ButtonRole, roleToAdd); |
|
436 |
QDialogButtonBox buttonBox; |
|
437 |
QAbstractButton *button = buttonBox.addButton("Here's a button", roleToAdd); |
|
438 |
QTEST(buttonBox.buttonRole(button), "expectedRole"); |
|
439 |
} |
|
440 |
||
441 |
void tst_QDialogButtonBox::testStandardButtonMapping_data() |
|
442 |
{ |
|
443 |
QTest::addColumn<QDialogButtonBox::StandardButton>("button"); |
|
444 |
QTest::addColumn<QDialogButtonBox::ButtonRole>("expectedRole"); |
|
445 |
QTest::addColumn<QString>("expectedText"); |
|
446 |
||
447 |
int layoutPolicy = qApp->style()->styleHint(QStyle::SH_DialogButtonLayout); |
|
448 |
||
449 |
QTest::newRow("QDialogButtonBox::Ok") << QDialogButtonBox::Ok |
|
450 |
<< QDialogButtonBox::AcceptRole |
|
451 |
<< QDialogButtonBox::tr("OK"); |
|
452 |
QTest::newRow("QDialogButtonBox::Open") << QDialogButtonBox::Open |
|
453 |
<< QDialogButtonBox::AcceptRole |
|
454 |
<< QDialogButtonBox::tr("Open"); |
|
455 |
QTest::newRow("QDialogButtonBox::Save") << QDialogButtonBox::Save |
|
456 |
<< QDialogButtonBox::AcceptRole |
|
457 |
<< QDialogButtonBox::tr("Save"); |
|
458 |
QTest::newRow("QDialogButtonBox::Cancel") << QDialogButtonBox::Cancel |
|
459 |
<< QDialogButtonBox::RejectRole |
|
460 |
<< QDialogButtonBox::tr("Cancel"); |
|
461 |
QTest::newRow("QDialogButtonBox::Close") << QDialogButtonBox::Close |
|
462 |
<< QDialogButtonBox::RejectRole |
|
463 |
<< QDialogButtonBox::tr("Close"); |
|
464 |
if (layoutPolicy == QDialogButtonBox::MacLayout) { |
|
465 |
QTest::newRow("QDialogButtonBox::Discard") << QDialogButtonBox::Discard |
|
466 |
<< QDialogButtonBox::DestructiveRole |
|
467 |
<< QDialogButtonBox::tr("Don't Save"); |
|
468 |
} else if (layoutPolicy == QDialogButtonBox::GnomeLayout) { |
|
469 |
QTest::newRow("QDialogButtonBox::Discard") |
|
470 |
<< QDialogButtonBox::Discard |
|
471 |
<< QDialogButtonBox::DestructiveRole |
|
472 |
<< QDialogButtonBox::tr("Close without Saving"); |
|
473 |
} else { |
|
474 |
QTest::newRow("QDialogButtonBox::Discard") << QDialogButtonBox::Discard |
|
475 |
<< QDialogButtonBox::DestructiveRole |
|
476 |
<< QDialogButtonBox::tr("Discard"); |
|
477 |
} |
|
478 |
QTest::newRow("QDialogButtonBox::Apply") << QDialogButtonBox::Apply |
|
479 |
<< QDialogButtonBox::ApplyRole |
|
480 |
<< QDialogButtonBox::tr("Apply"); |
|
481 |
QTest::newRow("QDialogButtonBox::Reset") << QDialogButtonBox::Reset |
|
482 |
<< QDialogButtonBox::ResetRole |
|
483 |
<< QDialogButtonBox::tr("Reset"); |
|
484 |
QTest::newRow("QDialogButtonBox::Help") << QDialogButtonBox::Help |
|
485 |
<< QDialogButtonBox::HelpRole |
|
486 |
<< QDialogButtonBox::tr("Help"); |
|
487 |
} |
|
488 |
||
489 |
void tst_QDialogButtonBox::testStandardButtonMapping() |
|
490 |
{ |
|
491 |
QFETCH(QDialogButtonBox::StandardButton, button); |
|
492 |
QDialogButtonBox buttonBox; |
|
493 |
||
494 |
QAbstractButton *theButton = buttonBox.addButton(button); |
|
495 |
QTEST(buttonBox.buttonRole(theButton), "expectedRole"); |
|
496 |
QString textWithoutMnemonic = theButton->text().remove("&"); |
|
497 |
QTEST(textWithoutMnemonic, "expectedText"); |
|
498 |
} |
|
499 |
||
500 |
void tst_QDialogButtonBox::testSignals_data() |
|
501 |
{ |
|
502 |
QTest::addColumn<QDialogButtonBox::ButtonRole>("buttonToClick"); |
|
503 |
QTest::addColumn<int>("clicked2Count"); |
|
504 |
QTest::addColumn<int>("acceptCount"); |
|
505 |
QTest::addColumn<int>("rejectCount"); |
|
506 |
QTest::addColumn<int>("helpRequestedCount"); |
|
507 |
||
508 |
QTest::newRow("nothing") << QDialogButtonBox::InvalidRole << 0 << 0 << 0 << 0; |
|
509 |
QTest::newRow("accept") << QDialogButtonBox::AcceptRole << 1 << 1 << 0 << 0; |
|
510 |
QTest::newRow("reject") << QDialogButtonBox::RejectRole << 1 << 0 << 1 << 0; |
|
511 |
QTest::newRow("destructive") << QDialogButtonBox::DestructiveRole << 1 << 0 << 0 << 0; |
|
512 |
QTest::newRow("Action") << QDialogButtonBox::ActionRole << 1 << 0 << 0 << 0; |
|
513 |
QTest::newRow("Help") << QDialogButtonBox::HelpRole << 1 << 0 << 0 << 1; |
|
514 |
} |
|
515 |
||
516 |
void tst_QDialogButtonBox::testSignals() |
|
517 |
{ |
|
518 |
QFETCH(QDialogButtonBox::ButtonRole, buttonToClick); |
|
519 |
QDialogButtonBox buttonBox; |
|
520 |
qRegisterMetaType<QAbstractButton *>("QAbstractButton*"); |
|
521 |
QSignalSpy clicked2(&buttonBox, SIGNAL(clicked(QAbstractButton*))); |
|
522 |
QSignalSpy accept(&buttonBox, SIGNAL(accepted())); |
|
523 |
QSignalSpy reject(&buttonBox, SIGNAL(rejected())); |
|
524 |
QSignalSpy helpRequested(&buttonBox, SIGNAL(helpRequested())); |
|
525 |
||
526 |
QPushButton *clickMe = 0; |
|
527 |
for (int i = QDialogButtonBox::AcceptRole; i < QDialogButtonBox::NRoles; ++i) { |
|
528 |
QPushButton *button = buttonBox.addButton(QString::number(i), |
|
529 |
QDialogButtonBox::ButtonRole(i)); |
|
530 |
||
531 |
if (i == buttonToClick) |
|
532 |
clickMe = button; |
|
533 |
} |
|
534 |
if (clickMe) { |
|
535 |
clickMe->animateClick(0); |
|
536 |
QTest::qWait(100); |
|
537 |
} |
|
538 |
||
539 |
QTEST(clicked2.count(), "clicked2Count"); |
|
540 |
if (clicked2.count() > 0) |
|
541 |
QCOMPARE(qvariant_cast<QAbstractButton *>(clicked2.at(0).at(0)), (QAbstractButton *)clickMe); |
|
542 |
||
543 |
QTEST(accept.count(), "acceptCount"); |
|
544 |
QTEST(reject.count(), "rejectCount"); |
|
545 |
QTEST(helpRequested.count(), "helpRequestedCount"); |
|
546 |
} |
|
547 |
||
548 |
void tst_QDialogButtonBox::testSignalOrder() |
|
549 |
{ |
|
550 |
const qint64 longLongZero = 0; |
|
551 |
buttonClicked1TimeStamp = acceptTimeStamp |
|
552 |
= rejectTimeStamp = helpRequestedTimeStamp = timeStamp = 0; |
|
553 |
QDialogButtonBox buttonBox; |
|
554 |
connect(&buttonBox, SIGNAL(clicked(QAbstractButton *)), |
|
555 |
this, SLOT(buttonClicked1(QAbstractButton *))); |
|
556 |
connect(&buttonBox, SIGNAL(accepted()), this, SLOT(acceptClicked())); |
|
557 |
connect(&buttonBox, SIGNAL(rejected()), this, SLOT(rejectClicked())); |
|
558 |
connect(&buttonBox, SIGNAL(helpRequested()), this, SLOT(helpRequestedClicked())); |
|
559 |
||
560 |
QPushButton *acceptButton = buttonBox.addButton("OK", QDialogButtonBox::AcceptRole); |
|
561 |
QPushButton *rejectButton = buttonBox.addButton("Cancel", QDialogButtonBox::RejectRole); |
|
562 |
QPushButton *actionButton = buttonBox.addButton("Action This", QDialogButtonBox::ActionRole); |
|
563 |
QPushButton *helpButton = buttonBox.addButton("Help Me!", QDialogButtonBox::HelpRole); |
|
564 |
||
565 |
// Try accept |
|
566 |
acceptButton->animateClick(0); |
|
567 |
QTest::qWait(100); |
|
568 |
QCOMPARE(rejectTimeStamp, longLongZero); |
|
569 |
QCOMPARE(helpRequestedTimeStamp, longLongZero); |
|
570 |
||
571 |
QVERIFY(buttonClicked1TimeStamp < acceptTimeStamp); |
|
572 |
acceptTimeStamp = 0; |
|
573 |
||
574 |
rejectButton->animateClick(0); |
|
575 |
QTest::qWait(100); |
|
576 |
QCOMPARE(acceptTimeStamp, longLongZero); |
|
577 |
QCOMPARE(helpRequestedTimeStamp, longLongZero); |
|
578 |
QVERIFY(buttonClicked1TimeStamp < rejectTimeStamp); |
|
579 |
||
580 |
rejectTimeStamp = 0; |
|
581 |
actionButton->animateClick(0); |
|
582 |
QTest::qWait(100); |
|
583 |
QCOMPARE(acceptTimeStamp, longLongZero); |
|
584 |
QCOMPARE(rejectTimeStamp, longLongZero); |
|
585 |
QCOMPARE(helpRequestedTimeStamp, longLongZero); |
|
586 |
||
587 |
helpButton->animateClick(0); |
|
588 |
QTest::qWait(100); |
|
589 |
QCOMPARE(acceptTimeStamp, longLongZero); |
|
590 |
QCOMPARE(rejectTimeStamp, longLongZero); |
|
591 |
QVERIFY(buttonClicked1TimeStamp < helpRequestedTimeStamp); |
|
592 |
} |
|
593 |
||
594 |
void tst_QDialogButtonBox::buttonClicked1(QAbstractButton *) |
|
595 |
{ |
|
596 |
buttonClicked1TimeStamp = ++timeStamp; |
|
597 |
} |
|
598 |
||
599 |
void tst_QDialogButtonBox::acceptClicked() |
|
600 |
{ |
|
601 |
acceptTimeStamp = ++timeStamp; |
|
602 |
} |
|
603 |
||
604 |
void tst_QDialogButtonBox::rejectClicked() |
|
605 |
{ |
|
606 |
rejectTimeStamp = ++timeStamp; |
|
607 |
} |
|
608 |
||
609 |
void tst_QDialogButtonBox::helpRequestedClicked() |
|
610 |
{ |
|
611 |
helpRequestedTimeStamp = ++timeStamp; |
|
612 |
} |
|
613 |
||
614 |
void tst_QDialogButtonBox::setStandardButtons_data() |
|
615 |
{ |
|
616 |
QTest::addColumn<QDialogButtonBox::StandardButtons>("buttonsToAdd"); |
|
617 |
QTest::addColumn<QDialogButtonBox::StandardButtons>("expectedResult"); |
|
618 |
||
619 |
QTest::newRow("Nothing") << QDialogButtonBox::StandardButtons(QDialogButtonBox::NoButton) |
|
620 |
<< QDialogButtonBox::StandardButtons(QDialogButtonBox::NoButton); |
|
621 |
QTest::newRow("Everything") << (QDialogButtonBox::StandardButtons)0xffffffff |
|
622 |
<< (QDialogButtonBox::Ok |
|
623 |
| QDialogButtonBox::Open |
|
624 |
| QDialogButtonBox::Save |
|
625 |
| QDialogButtonBox::Cancel |
|
626 |
| QDialogButtonBox::Close |
|
627 |
| QDialogButtonBox::Discard |
|
628 |
| QDialogButtonBox::Apply |
|
629 |
| QDialogButtonBox::Reset |
|
630 |
| QDialogButtonBox::Help |
|
631 |
| QDialogButtonBox::Yes |
|
632 |
| QDialogButtonBox::YesToAll |
|
633 |
| QDialogButtonBox::No |
|
634 |
| QDialogButtonBox::NoToAll |
|
635 |
| QDialogButtonBox::SaveAll |
|
636 |
| QDialogButtonBox::Abort |
|
637 |
| QDialogButtonBox::Retry |
|
638 |
| QDialogButtonBox::Ignore |
|
639 |
| QDialogButtonBox::RestoreDefaults |
|
640 |
); |
|
641 |
QTest::newRow("Simple thing") << QDialogButtonBox::StandardButtons(QDialogButtonBox::Help) |
|
642 |
<< QDialogButtonBox::StandardButtons(QDialogButtonBox::Help); |
|
643 |
QTest::newRow("Standard thing") << (QDialogButtonBox::Ok | QDialogButtonBox::Cancel) |
|
644 |
<< (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
|
645 |
} |
|
646 |
||
647 |
void tst_QDialogButtonBox::setStandardButtons() |
|
648 |
{ |
|
649 |
QFETCH(QDialogButtonBox::StandardButtons, buttonsToAdd); |
|
650 |
QDialogButtonBox buttonBox; |
|
651 |
buttonBox.setStandardButtons(buttonsToAdd); |
|
652 |
QTEST(buttonBox.standardButtons(), "expectedResult"); |
|
653 |
} |
|
654 |
||
655 |
void tst_QDialogButtonBox::standardButtons() |
|
656 |
{ |
|
657 |
// Test various cases of setting StandardButtons |
|
658 |
QDialogButtonBox buttonBox; |
|
659 |
||
660 |
QCOMPARE(buttonBox.standardButtons(), |
|
661 |
QDialogButtonBox::StandardButtons(QDialogButtonBox::NoButton)); |
|
662 |
||
663 |
// Set some buttons |
|
664 |
buttonBox.setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
|
665 |
QCOMPARE(buttonBox.standardButtons(), QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
|
666 |
||
667 |
// Now add a button |
|
668 |
buttonBox.addButton(QDialogButtonBox::Apply); |
|
669 |
QCOMPARE(buttonBox.standardButtons(), |
|
670 |
QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply); |
|
671 |
||
672 |
// Set the standard buttons to other things |
|
673 |
buttonBox.setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel |
|
674 |
| QDialogButtonBox::Discard); |
|
675 |
QCOMPARE(buttonBox.standardButtons(), QDialogButtonBox::Save | QDialogButtonBox::Cancel |
|
676 |
| QDialogButtonBox::Discard); |
|
677 |
QCOMPARE(buttonBox.buttons().size(), 3); |
|
678 |
||
679 |
// Add another button (not a standard one) |
|
680 |
buttonBox.addButton(QLatin1String("Help"), QDialogButtonBox::HelpRole); |
|
681 |
QCOMPARE(buttonBox.standardButtons(), QDialogButtonBox::Save | QDialogButtonBox::Cancel |
|
682 |
| QDialogButtonBox::Discard); |
|
683 |
QCOMPARE(buttonBox.buttons().size(), 4); |
|
684 |
||
685 |
// Finally, check if we construct with standard buttons that they show up. |
|
686 |
QDialogButtonBox buttonBox2(QDialogButtonBox::Open | QDialogButtonBox::Reset); |
|
687 |
QCOMPARE(buttonBox2.standardButtons(), QDialogButtonBox::Open | QDialogButtonBox::Reset); |
|
688 |
} |
|
689 |
||
690 |
void tst_QDialogButtonBox::testRemove() |
|
691 |
{ |
|
692 |
// Make sure that removing a button and clicking it, doesn't trigger any latent signals |
|
693 |
QDialogButtonBox buttonBox; |
|
694 |
QSignalSpy clicked(&buttonBox, SIGNAL(clicked(QAbstractButton*))); |
|
695 |
||
696 |
QAbstractButton *button = buttonBox.addButton(QDialogButtonBox::Ok); |
|
697 |
||
698 |
buttonBox.removeButton(button); |
|
699 |
||
700 |
button->animateClick(0); |
|
701 |
QTest::qWait(100); |
|
702 |
QCOMPARE(clicked.count(), 0); |
|
703 |
delete button; |
|
704 |
} |
|
705 |
||
706 |
void tst_QDialogButtonBox::testDefaultButton_data() |
|
707 |
{ |
|
708 |
QTest::addColumn<int>("whenToSetDefault"); // -1 Do nothing, 0 after accept, 1 before accept |
|
709 |
QTest::addColumn<int>("buttonToBeDefault"); |
|
710 |
QTest::addColumn<int>("indexThatIsDefault"); |
|
711 |
||
712 |
QTest::newRow("do nothing First Accept implicit") << -1 << -1 << 0; |
|
713 |
QTest::newRow("First accept explicit before add") << 1 << 0 << 0; |
|
714 |
QTest::newRow("First accept explicit after add") << 0 << 0 << 0; |
|
715 |
QTest::newRow("second accept explicit before add") << 1 << 1 << 1; |
|
716 |
QTest::newRow("second accept explicit after add") << 0 << 1 << 1; |
|
717 |
QTest::newRow("third accept explicit befare add") << 1 << 2 << 2; |
|
718 |
QTest::newRow("third accept explicit after add") << 0 << 2 << 2; |
|
719 |
} |
|
720 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
721 |
static int softKeyCount(QWidget *widget) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
722 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
723 |
int softkeyCount = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
724 |
QList<QAction *> actions = widget->actions(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
725 |
foreach (QAction *action, actions) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
726 |
if (action->softKeyRole() != QAction::NoSoftKey) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
727 |
softkeyCount++; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
728 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
729 |
return softkeyCount; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
730 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
731 |
|
0 | 732 |
void tst_QDialogButtonBox::testS60SoftKeys() |
733 |
{ |
|
734 |
#ifdef Q_WS_S60 |
|
735 |
QDialog dialog(0); |
|
736 |
QDialogButtonBox buttonBox(&dialog); |
|
737 |
buttonBox.setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
|
738 |
dialog.show(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
739 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
740 |
QCOMPARE( softKeyCount(&dialog), 2); |
0 | 741 |
|
742 |
QDialog dialog2(0); |
|
743 |
QDialogButtonBox buttonBox2(&dialog2); |
|
744 |
buttonBox2.setStandardButtons(QDialogButtonBox::Cancel); |
|
745 |
dialog2.show(); |
|
746 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
747 |
QCOMPARE( softKeyCount(&dialog2), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
748 |
|
0 | 749 |
#else |
750 |
QSKIP("S60-specific test", SkipAll ); |
|
751 |
#endif |
|
752 |
} |
|
753 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
754 |
#ifdef QT_SOFTKEYS_ENABLED |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
755 |
void tst_QDialogButtonBox::testSoftKeyReparenting() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
757 |
QDialog dialog; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
758 |
QDialogButtonBox *buttonBox = new QDialogButtonBox; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
759 |
buttonBox->addButton(QDialogButtonBox::Ok); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
760 |
buttonBox->addButton(QDialogButtonBox::Cancel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
761 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
762 |
QCOMPARE(softKeyCount(&dialog), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
763 |
QCOMPARE(softKeyCount(buttonBox), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
764 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
765 |
// Were the softkeys re-parented correctly? |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
766 |
dialog.setLayout(new QVBoxLayout); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
767 |
dialog.layout()->addWidget(buttonBox); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
768 |
QCOMPARE(softKeyCount(&dialog), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
769 |
QCOMPARE(softKeyCount(buttonBox), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
770 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
771 |
// Softkeys are only added to QDialog, not QWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
772 |
QWidget *nested = new QWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
773 |
nested->setLayout(new QVBoxLayout); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
774 |
nested->layout()->addWidget(buttonBox); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
775 |
QCOMPARE(softKeyCount(nested), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
776 |
QCOMPARE(softKeyCount(buttonBox), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
777 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
778 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
779 |
|
0 | 780 |
void tst_QDialogButtonBox::testDefaultButton() |
781 |
{ |
|
782 |
QFETCH(int, whenToSetDefault); |
|
783 |
QFETCH(int, buttonToBeDefault); |
|
784 |
QFETCH(int, indexThatIsDefault); |
|
785 |
QDialogButtonBox buttonBox; |
|
786 |
QPushButton *buttonArray[] = { new QPushButton("Foo"), new QPushButton("Bar"), new QPushButton("Baz") }; |
|
787 |
||
788 |
for (int i = 0; i < 3; ++i) { |
|
789 |
if (whenToSetDefault == 1 && i == buttonToBeDefault) |
|
790 |
buttonArray[i]->setDefault(true); |
|
791 |
buttonBox.addButton(buttonArray[i], QDialogButtonBox::AcceptRole); |
|
792 |
if (whenToSetDefault == 0 && i == buttonToBeDefault) |
|
793 |
buttonArray[i]->setDefault(true); |
|
794 |
} |
|
795 |
buttonBox.show(); |
|
796 |
||
797 |
for (int i = 0; i < 3; ++i) { |
|
798 |
if (i == indexThatIsDefault) |
|
799 |
QVERIFY(buttonArray[i]->isDefault()); |
|
800 |
else |
|
801 |
QVERIFY(!buttonArray[i]->isDefault()); |
|
802 |
} |
|
803 |
} |
|
804 |
||
805 |
void tst_QDialogButtonBox::task191642_default() |
|
806 |
{ |
|
807 |
QDialog dlg; |
|
808 |
QPushButton *def = new QPushButton(&dlg); |
|
809 |
QSignalSpy clicked(def, SIGNAL(clicked(bool))); |
|
810 |
def->setDefault(true); |
|
811 |
QDialogButtonBox *bb = new QDialogButtonBox(&dlg); |
|
812 |
bb->addButton(QDialogButtonBox::Ok); |
|
813 |
bb->addButton(QDialogButtonBox::Cancel); |
|
814 |
bb->addButton(QDialogButtonBox::Help); |
|
815 |
||
816 |
dlg.show(); |
|
817 |
QTest::qWait(10); |
|
818 |
QVERIFY(def->isDefault()); |
|
819 |
QTest::keyPress( &dlg, Qt::Key_Enter ); |
|
820 |
QTest::qWait(100); |
|
821 |
QCOMPARE(clicked.count(), 1); |
|
822 |
} |
|
823 |
||
824 |
QTEST_MAIN(tst_QDialogButtonBox) |
|
825 |
#include "tst_qdialogbuttonbox.moc" |