~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the test suite of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
 
 
43
#include <QtTest/QtTest>
 
44
 
 
45
 
 
46
 
 
47
#include <qapplication.h>
 
48
#include <qpainter.h>
 
49
#include <qstyleoption.h>
 
50
#include <qkeysequence.h>
 
51
#include <qevent.h>
 
52
#include <qgridlayout.h>
 
53
#include <qabstractbutton.h>
 
54
 
 
55
class tst_QAbstractButton : public QObject
 
56
{
 
57
    Q_OBJECT
 
58
 
 
59
public:
 
60
    tst_QAbstractButton();
 
61
    virtual ~tst_QAbstractButton();
 
62
 
 
63
 
 
64
public slots:
 
65
    void initTestCase();
 
66
    void cleanupTestCase();
 
67
    void init();
 
68
    void cleanup();
 
69
private slots:
 
70
    void setAutoRepeat_data();
 
71
    void setAutoRepeat();
 
72
 
 
73
    void pressed();
 
74
    void released();
 
75
    void setText();
 
76
    void setIcon();
 
77
 
 
78
    void setShortcut();
 
79
 
 
80
    void animateClick();
 
81
 
 
82
    void isCheckable();
 
83
    void setDown();
 
84
    void isChecked();
 
85
    void toggled();
 
86
    void setEnabled();
 
87
    void shortcutEvents();
 
88
    void stopRepeatTimer();
 
89
 
 
90
#ifdef QT_KEYPAD_NAVIGATION
 
91
    void keyNavigation();
 
92
#endif
 
93
 
 
94
protected slots:
 
95
    void onClicked();
 
96
    void onToggled( bool on );
 
97
    void onPressed();
 
98
    void onReleased();
 
99
    void resetValues();
 
100
 
 
101
private:
 
102
    uint click_count;
 
103
    uint toggle_count;
 
104
    uint press_count;
 
105
    uint release_count;
 
106
 
 
107
    QAbstractButton *testWidget;
 
108
};
 
109
 
 
110
// QAbstractButton is an abstract class in 4.0
 
111
class MyButton : public QAbstractButton
 
112
{
 
113
public:
 
114
    MyButton(QWidget *p = 0) : QAbstractButton(p) {}
 
115
    void paintEvent(QPaintEvent *)
 
116
    {
 
117
        QPainter p(this);
 
118
        QRect r = rect();
 
119
        p.fillRect(r, isDown() ? Qt::black : (isChecked() ? Qt::lightGray : Qt::white));
 
120
        p.setPen(isDown() ? Qt::white : Qt::black);
 
121
        p.drawRect(r);
 
122
        p.drawText(r, Qt::AlignCenter | Qt::TextShowMnemonic, text());
 
123
        if (hasFocus()) {
 
124
            r.adjust(2, 2, -2, -2);
 
125
            QStyleOptionFocusRect opt;
 
126
            opt.rect = r;
 
127
            opt.palette = palette();
 
128
            opt.state = QStyle::State_None;
 
129
            style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, &p, this);
 
130
#ifdef Q_OS_MAC
 
131
            p.setPen(Qt::red);
 
132
            p.drawRect(r);
 
133
#endif
 
134
        }
 
135
    }
 
136
    QSize sizeHint() const
 
137
    {
 
138
        QSize sh(8, 8);
 
139
        if (!text().isEmpty())
 
140
            sh += fontMetrics().boundingRect(text()).size();
 
141
        return sh;
 
142
    }
 
143
 
 
144
    void resetTimerEvents() { timerEvents = 0; }
 
145
    int timerEventCount() const { return timerEvents; }
 
146
 
 
147
private:
 
148
 
 
149
    int timerEvents;
 
150
 
 
151
    void timerEvent(QTimerEvent *event)
 
152
    {
 
153
        ++timerEvents;
 
154
        QAbstractButton::timerEvent(event);
 
155
    }
 
156
};
 
157
 
 
158
tst_QAbstractButton::tst_QAbstractButton()
 
159
{
 
160
}
 
161
 
 
162
tst_QAbstractButton::~tst_QAbstractButton()
 
163
{
 
164
}
 
165
 
 
166
void tst_QAbstractButton::initTestCase()
 
167
{
 
168
    testWidget = new MyButton(0);
 
169
    testWidget->setObjectName("testObject");
 
170
    testWidget->resize( 200, 200 );
 
171
    testWidget->show();
 
172
 
 
173
    connect( testWidget, SIGNAL(clicked()), this, SLOT(onClicked()) );
 
174
    connect( testWidget, SIGNAL(pressed()), this, SLOT(onPressed()) );
 
175
    connect( testWidget, SIGNAL(released()), this, SLOT(onReleased()) );
 
176
    connect( testWidget, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)) );
 
177
}
 
178
 
 
179
void tst_QAbstractButton::cleanupTestCase()
 
180
{
 
181
    delete testWidget;
 
182
}
 
183
 
 
184
void tst_QAbstractButton::init()
 
185
{
 
186
    testWidget->setText("Test");
 
187
    testWidget->setEnabled( true );
 
188
    testWidget->setDown( false );
 
189
    testWidget->setAutoRepeat( false );
 
190
    QKeySequence seq;
 
191
    testWidget->setShortcut( seq );
 
192
 
 
193
    toggle_count = 0;
 
194
    press_count = 0;
 
195
    release_count = 0;
 
196
    click_count = 0;
 
197
}
 
198
 
 
199
void tst_QAbstractButton::cleanup()
 
200
{
 
201
}
 
202
 
 
203
void tst_QAbstractButton::resetValues()
 
204
{
 
205
    toggle_count = 0;
 
206
    press_count = 0;
 
207
    release_count = 0;
 
208
    click_count = 0;
 
209
}
 
210
 
 
211
void tst_QAbstractButton::onClicked()
 
212
{
 
213
    click_count++;
 
214
}
 
215
 
 
216
void tst_QAbstractButton::onToggled( bool /*on*/ )
 
217
{
 
218
    toggle_count++;
 
219
}
 
220
 
 
221
void tst_QAbstractButton::onPressed()
 
222
{
 
223
    press_count++;
 
224
}
 
225
 
 
226
void tst_QAbstractButton::onReleased()
 
227
{
 
228
    release_count++;
 
229
}
 
230
 
 
231
void tst_QAbstractButton::setAutoRepeat_data()
 
232
{
 
233
    QTest::addColumn<int>("mode");
 
234
    QTest::newRow("mode 0") << 0;
 
235
    QTest::newRow("mode 1") << 1;
 
236
    QTest::newRow("mode 2") << 2;
 
237
    QTest::newRow("mode 3") << 3;
 
238
    QTest::newRow("mode 4") << 4;
 
239
    QTest::newRow("mode 5") << 5;
 
240
    QTest::newRow("mode 6") << 6;
 
241
}
 
242
 
 
243
#define REPEAT_DELAY 1000
 
244
 
 
245
int test_count = 0;
 
246
int last_mode = 0;
 
247
 
 
248
void tst_QAbstractButton::setAutoRepeat()
 
249
{
 
250
    QFETCH( int, mode );
 
251
 
 
252
    //FIXME: temp code to check that the test fails consistenly
 
253
    //retest( 3 );
 
254
 
 
255
    switch (mode)
 
256
    {
 
257
    case 0:
 
258
        QVERIFY( !testWidget->isCheckable() );
 
259
        break;
 
260
    case 1:
 
261
        // check if we can toggle the mode
 
262
        testWidget->setAutoRepeat( true );
 
263
        QVERIFY( testWidget->autoRepeat() );
 
264
 
 
265
        testWidget->setAutoRepeat( false );
 
266
        QVERIFY( !testWidget->autoRepeat() );
 
267
        break;
 
268
    case 2:
 
269
        // check that the button is down if we press space and not in autorepeat
 
270
        testWidget->setDown( false );
 
271
        testWidget->setAutoRepeat( false );
 
272
        QTest::keyPress( testWidget, Qt::Key_Space );
 
273
 
 
274
        QTest::qWait( REPEAT_DELAY );
 
275
 
 
276
        QVERIFY( release_count == 0 );
 
277
        QVERIFY( testWidget->isDown() );
 
278
        QVERIFY( toggle_count == 0 );
 
279
        QVERIFY( press_count == 1 );
 
280
        QVERIFY( click_count == 0 );
 
281
 
 
282
        QTest::keyRelease( testWidget, Qt::Key_Space );
 
283
        QVERIFY( click_count == 1 );
 
284
        QVERIFY( release_count == 1 );
 
285
        break;
 
286
    case 3:
 
287
        // check that the button is down if we press space while in autorepeat
 
288
        testWidget->setDown(false);
 
289
        testWidget->setAutoRepeat(true);
 
290
        QTest::keyPress(testWidget, Qt::Key_Space);
 
291
        QTest::qWait(REPEAT_DELAY);
 
292
        QVERIFY(testWidget->isDown());
 
293
        QTest::keyRelease(testWidget, Qt::Key_Space);
 
294
        QVERIFY(release_count == press_count);
 
295
        QVERIFY(toggle_count == 0);
 
296
        QVERIFY(press_count == click_count);
 
297
        QVERIFY(click_count > 1);
 
298
        break;
 
299
    case 4:
 
300
        // check that pressing ENTER has no effect when autorepeat is false
 
301
        testWidget->setDown( false );
 
302
        testWidget->setAutoRepeat( false );
 
303
        QTest::keyPress( testWidget, Qt::Key_Enter );
 
304
 
 
305
        QTest::qWait( REPEAT_DELAY );
 
306
 
 
307
        QVERIFY( !testWidget->isDown() );
 
308
        QVERIFY( toggle_count == 0 );
 
309
        QVERIFY( press_count == 0 );
 
310
        QVERIFY( release_count == 0 );
 
311
        QVERIFY( click_count == 0 );
 
312
        QTest::keyRelease( testWidget, Qt::Key_Enter );
 
313
 
 
314
        QVERIFY( click_count == 0 );
 
315
        break;
 
316
    case 5:
 
317
        // check that pressing ENTER has no effect when autorepeat is true
 
318
        testWidget->setDown( false );
 
319
        testWidget->setAutoRepeat( true );
 
320
        QTest::keyPress( testWidget, Qt::Key_Enter );
 
321
 
 
322
        QTest::qWait( REPEAT_DELAY );
 
323
 
 
324
        QVERIFY( !testWidget->isDown() );
 
325
        QVERIFY( toggle_count == 0 );
 
326
        QVERIFY( press_count == 0 );
 
327
        QVERIFY( release_count == 0 );
 
328
        QVERIFY( click_count == 0 );
 
329
 
 
330
        QTest::keyRelease( testWidget, Qt::Key_Enter );
 
331
 
 
332
        QVERIFY( click_count == 0 );
 
333
        break;
 
334
    case 6:
 
335
        // verify autorepeat is off by default.
 
336
        MyButton tmp( 0);
 
337
        tmp.setObjectName("tmp" );
 
338
        QVERIFY( !tmp.autoRepeat() );
 
339
        break;
 
340
    }
 
341
}
 
342
 
 
343
void tst_QAbstractButton::pressed()
 
344
{
 
345
    // pressed/released signals expected for a QAbstractButton
 
346
    QTest::keyPress( testWidget, ' ' );
 
347
    QCOMPARE( press_count, (uint)1 );
 
348
}
 
349
 
 
350
void tst_QAbstractButton::released()
 
351
{
 
352
    // pressed/released signals expected for a QAbstractButton
 
353
    QTest::keyPress( testWidget, ' ' );
 
354
    QTest::keyRelease( testWidget, ' ' );
 
355
    QCOMPARE( release_count, (uint)1 );
 
356
}
 
357
 
 
358
void tst_QAbstractButton::setText()
 
359
{
 
360
    testWidget->setText("");
 
361
    QCOMPARE( testWidget->text(), QString("") );
 
362
    testWidget->setText("simple");
 
363
    QCOMPARE( testWidget->text(), QString("simple") );
 
364
    testWidget->setText("&ampersand");
 
365
    QCOMPARE( testWidget->text(), QString("&ampersand") );
 
366
#ifndef Q_OS_MAC // no mneonics on Mac.
 
367
    QCOMPARE( testWidget->shortcut(), QKeySequence("ALT+A"));
 
368
#endif
 
369
    testWidget->setText("te&st");
 
370
    QCOMPARE( testWidget->text(), QString("te&st") );
 
371
#ifndef Q_OS_MAC // no mneonics on Mac.
 
372
    QCOMPARE( testWidget->shortcut(), QKeySequence("ALT+S"));
 
373
#endif
 
374
    testWidget->setText("foo");
 
375
    QCOMPARE( testWidget->text(), QString("foo") );
 
376
#ifndef Q_OS_MAC // no mneonics on Mac.
 
377
    QCOMPARE( testWidget->shortcut(), QKeySequence());
 
378
#endif
 
379
}
 
380
 
 
381
void tst_QAbstractButton::setIcon()
 
382
{
 
383
    const char *test1_xpm[] = {
 
384
    "12 8 2 1",
 
385
    ". c None",
 
386
    "c c #ff0000",
 
387
    ".........ccc",
 
388
    "........ccc.",
 
389
    ".......ccc..",
 
390
    "ccc...ccc...",
 
391
    ".ccc.ccc....",
 
392
    "..ccccc.....",
 
393
    "...ccc......",
 
394
    "....c.......",
 
395
    };
 
396
 
 
397
    QPixmap p(test1_xpm);
 
398
    testWidget->setIcon( p );
 
399
    QCOMPARE( testWidget->icon().pixmap(12, 8), p );
 
400
 
 
401
    // Test for #14793
 
402
 
 
403
    const char *test2_xpm[] = {
 
404
    "12 8 2 1",
 
405
    ". c None",
 
406
    "c c #ff0000",
 
407
    "ccc......ccc",
 
408
    ".ccc....ccc.",
 
409
    "..ccc..ccc..",
 
410
    "....cc.cc...",
 
411
    ".....ccc....",
 
412
    "....cc.cc...",
 
413
    "...ccc.ccc..",
 
414
    "..ccc...ccc.",
 
415
    };
 
416
 
 
417
    int currentHeight = testWidget->height();
 
418
    int currentWidth = testWidget->width();
 
419
 
 
420
    QPixmap p2( test2_xpm );
 
421
    for ( int a = 0; a<5; a++ )
 
422
        testWidget->setIcon( p2 );
 
423
 
 
424
    QCOMPARE( testWidget->icon().pixmap(12, 8), p2 );
 
425
 
 
426
    QCOMPARE( testWidget->height(), currentHeight );
 
427
    QCOMPARE( testWidget->width(), currentWidth );
 
428
}
 
429
 
 
430
void tst_QAbstractButton::setEnabled()
 
431
{
 
432
    testWidget->setEnabled( false );
 
433
    QVERIFY( !testWidget->isEnabled() );
 
434
//    QTEST( testWidget, "disabled" );
 
435
 
 
436
    testWidget->setEnabled( true );
 
437
    QVERIFY( testWidget->isEnabled() );
 
438
//    QTEST( testWidget, "enabled" );
 
439
}
 
440
 
 
441
void tst_QAbstractButton::isCheckable()
 
442
{
 
443
    QVERIFY( !testWidget->isCheckable() );
 
444
}
 
445
 
 
446
void tst_QAbstractButton::setDown()
 
447
{
 
448
    testWidget->setDown( false );
 
449
    QVERIFY( !testWidget->isDown() );
 
450
 
 
451
    testWidget->setDown( true );
 
452
    QTest::qWait(300);
 
453
    QVERIFY( testWidget->isDown() );
 
454
 
 
455
    testWidget->setDown( true );
 
456
 
 
457
    // add some debugging stuff
 
458
    QWidget *grab = QWidget::keyboardGrabber();
 
459
    if (grab != 0 && grab != testWidget)
 
460
        qDebug( "testWidget != keyboardGrabber" );
 
461
    grab = qApp->focusWidget();
 
462
    if (grab != 0 && grab != testWidget)
 
463
        qDebug( "testWidget != focusWidget" );
 
464
 
 
465
    QTest::keyClick( testWidget, Qt::Key_Escape );
 
466
    QVERIFY( !testWidget->isDown() );
 
467
}
 
468
 
 
469
void tst_QAbstractButton::isChecked()
 
470
{
 
471
    testWidget->setDown( false );
 
472
    QVERIFY( !testWidget->isChecked() );
 
473
 
 
474
    testWidget->setDown( true );
 
475
    QVERIFY( !testWidget->isChecked() );
 
476
 
 
477
    testWidget->setDown( false );
 
478
    testWidget->toggle();
 
479
    QVERIFY( testWidget->isChecked() == testWidget->isCheckable() );
 
480
}
 
481
 
 
482
void tst_QAbstractButton::toggled()
 
483
{
 
484
    testWidget->toggle();
 
485
    QVERIFY( toggle_count == 0 );
 
486
 
 
487
    QTest::mousePress( testWidget, Qt::LeftButton );
 
488
    QVERIFY( toggle_count == 0 );
 
489
    QVERIFY( click_count == 0 );
 
490
 
 
491
    QTest::mouseRelease( testWidget, Qt::LeftButton );
 
492
    QVERIFY( click_count == 1 );
 
493
}
 
494
 
 
495
void tst_QAbstractButton::setShortcut()
 
496
{
 
497
    QKeySequence seq( Qt::Key_A );
 
498
    testWidget->setShortcut( seq );
 
499
    QApplication::setActiveWindow(testWidget);
 
500
 
 
501
    // must be active to get shortcuts
 
502
    for (int i = 0; !testWidget->isActiveWindow() && i < 100; ++i) {
 
503
       testWidget->activateWindow();
 
504
       QApplication::instance()->processEvents();
 
505
       QTest::qWait(100);
 
506
    }
 
507
    QVERIFY(testWidget->isActiveWindow());
 
508
 
 
509
    QTest::keyClick( testWidget, 'A' );
 
510
    QTest::qWait(300);                      // Animate click takes time
 
511
    QCOMPARE(click_count,  (uint)1);
 
512
    QCOMPARE(press_count,  (uint)1); // Press is part of a click
 
513
    QCOMPARE(release_count,(uint)1); // Release is part of a click
 
514
 
 
515
    QVERIFY( toggle_count == 0 );
 
516
 
 
517
//     resetValues();
 
518
//     QTest::keyPress( testWidget, 'A' );
 
519
//     QTest::qWait(10000);
 
520
//     QTest::keyRelease( testWidget, 'A' );
 
521
//     QCOMPARE(click_count,  (uint)1);
 
522
//     QCOMPARE(press_count,  (uint)1);
 
523
//     QCOMPARE(release_count,(uint)1);
 
524
 
 
525
//     qDebug() << click_count;
 
526
 
 
527
}
 
528
 
 
529
void tst_QAbstractButton::animateClick()
 
530
{
 
531
    testWidget->animateClick();
 
532
    QVERIFY( testWidget->isDown() );
 
533
    qApp->processEvents();
 
534
    QVERIFY( testWidget->isDown() );
 
535
    QTest::qWait(200);
 
536
    qApp->processEvents();
 
537
    QVERIFY( !testWidget->isDown() );
 
538
}
 
539
 
 
540
void tst_QAbstractButton::shortcutEvents()
 
541
{
 
542
    MyButton button;
 
543
    QSignalSpy pressedSpy(&button, SIGNAL(pressed()));
 
544
    QSignalSpy releasedSpy(&button, SIGNAL(released()));
 
545
    QSignalSpy clickedSpy(&button, SIGNAL(clicked(bool)));
 
546
 
 
547
    for (int i = 0; i < 4; ++i) {
 
548
        QKeySequence sequence;
 
549
        // Default shortcutId for QAbstractButton is 0, so the shortcut event will work.
 
550
        QShortcutEvent event(sequence, /*shortcutId*/ 0);
 
551
        QApplication::sendEvent(&button, &event);
 
552
        if (i < 2)
 
553
            QTest::qWait(500);
 
554
    }
 
555
 
 
556
    QTest::qWait(1000); // ensure animate timer is expired
 
557
 
 
558
    QCOMPARE(pressedSpy.count(), 3);
 
559
    QCOMPARE(releasedSpy.count(), 3);
 
560
    QCOMPARE(clickedSpy.count(), 3);
 
561
}
 
562
 
 
563
void tst_QAbstractButton::stopRepeatTimer()
 
564
{
 
565
    MyButton button;
 
566
    button.setAutoRepeat(true);
 
567
 
 
568
    // Mouse trigger case:
 
569
    button.resetTimerEvents();
 
570
    QTest::mousePress(&button, Qt::LeftButton);
 
571
    QTest::qWait(1000);
 
572
    QVERIFY(button.timerEventCount() > 0);
 
573
 
 
574
    QTest::mouseRelease(&button, Qt::LeftButton);
 
575
    button.resetTimerEvents();
 
576
    QTest::qWait(1000);
 
577
    QCOMPARE(button.timerEventCount(), 0);
 
578
 
 
579
    // Key trigger case:
 
580
    button.resetTimerEvents();
 
581
    QTest::keyPress(&button, Qt::Key_Space);
 
582
    QTest::qWait(1000);
 
583
    QVERIFY(button.timerEventCount() > 0);
 
584
 
 
585
    QTest::keyRelease(&button, Qt::Key_Space);
 
586
    button.resetTimerEvents();
 
587
    QTest::qWait(1000);
 
588
    QCOMPARE(button.timerEventCount(), 0);
 
589
}
 
590
 
 
591
#ifdef QT_KEYPAD_NAVIGATION
 
592
void tst_QAbstractButton::keyNavigation()
 
593
{
 
594
    QApplication::setNavigationMode(Qt::NavigationModeKeypadDirectional);
 
595
 
 
596
    QWidget widget;
 
597
    QGridLayout *layout = new QGridLayout(&widget);
 
598
    QAbstractButton *buttons[3][3];
 
599
    for(int y = 0; y < 3; y++) {
 
600
        for(int x = 0; x < 3; x++) {
 
601
            buttons[y][x] = new MyButton(&widget);
 
602
            buttons[y][x]->setFocusPolicy(Qt::StrongFocus);
 
603
            layout->addWidget(buttons[y][x], y, x);
 
604
        }
 
605
    }
 
606
 
 
607
    widget.show();
 
608
    qApp->setActiveWindow(&widget);
 
609
    widget.activateWindow();
 
610
    QTest::qWait(30);
 
611
 
 
612
    buttons[1][1]->setFocus();
 
613
    QTest::qWait(400);
 
614
    QVERIFY(buttons[1][1]->hasFocus());
 
615
    QTest::keyPress(buttons[1][1], Qt::Key_Up);
 
616
    QTest::qWait(100);
 
617
    QVERIFY(buttons[0][1]->hasFocus());
 
618
    QTest::keyPress(buttons[0][1], Qt::Key_Down);
 
619
    QTest::qWait(100);
 
620
    QVERIFY(buttons[1][1]->hasFocus());
 
621
    QTest::keyPress(buttons[1][1], Qt::Key_Left);
 
622
    QTest::qWait(100);
 
623
    QVERIFY(buttons[1][0]->hasFocus());
 
624
    QTest::keyPress(buttons[1][0], Qt::Key_Down);
 
625
    QTest::qWait(100);
 
626
    QVERIFY(buttons[2][0]->hasFocus());
 
627
    QTest::keyPress(buttons[2][0], Qt::Key_Right);
 
628
    QTest::qWait(100);
 
629
    QVERIFY(buttons[2][1]->hasFocus());
 
630
    QTest::keyPress(buttons[2][1], Qt::Key_Right);
 
631
    QTest::qWait(100);
 
632
    QVERIFY(buttons[2][2]->hasFocus());
 
633
    QTest::keyPress(buttons[2][2], Qt::Key_Up);
 
634
    QTest::qWait(100);
 
635
    QVERIFY(buttons[1][2]->hasFocus());
 
636
    QTest::keyPress(buttons[1][2], Qt::Key_Up);
 
637
    QTest::qWait(100);
 
638
    QVERIFY(buttons[0][2]->hasFocus());
 
639
    buttons[0][1]->hide();
 
640
    QTest::keyPress(buttons[0][2], Qt::Key_Left);
 
641
    QTest::qWait(100);
 
642
    QTest::keyPress(buttons[0][2], Qt::Key_Left);
 
643
    QEXPECT_FAIL("", "QTBUG-22286" ,Abort);
 
644
    QVERIFY(buttons[0][0]->hasFocus());
 
645
}
 
646
#endif
 
647
 
 
648
QTEST_MAIN(tst_QAbstractButton)
 
649
#include "tst_qabstractbutton.moc"