summaryrefslogtreecommitdiffstats
path: root/tests/auto/qinputcontext/tst_qinputcontext.cpp
blob: 93813f9548e461deabd282b7976d8443fa3584fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtTest/QtTest>
#include "../../shared/util.h"

#include <qinputcontext.h>
#include <qlineedit.h>
#include <qplaintextedit.h>
#include <qlayout.h>
#include <qradiobutton.h>
#include <qwindowsstyle.h>
#include <qdesktopwidget.h>

#ifdef Q_OS_SYMBIAN
#include <private/qt_s60_p.h>
#include <private/qcoefepinputcontext_p.h>

#include <w32std.h>
#include <coecntrl.h>
#endif

class tst_QInputContext : public QObject
{
Q_OBJECT

public:
    tst_QInputContext() : m_phoneIsQwerty(false) {}
    virtual ~tst_QInputContext() {}

public slots:
    void initTestCase();
    void cleanupTestCase() {}
    void init() {}
    void cleanup() {}
private slots:
    void maximumTextLength();
    void filterMouseEvents();
    void requestSoftwareInputPanel();
    void closeSoftwareInputPanel();
    void selections();
    void focusProxy();
    void symbianTestCoeFepInputContext_data();
    void symbianTestCoeFepInputContext();

private:
    bool m_phoneIsQwerty;
};

#ifdef Q_OS_SYMBIAN
class KeyEvent : public TWsEvent
{
public:
    KeyEvent(QWidget *w, TInt type, TInt scanCode, TUint code, TUint modifiers, TInt repeats) {
        iHandle = w->effectiveWinId()->DrawableWindow()->WindowGroupId();
        iType = type;
        SetTimeNow();
        TKeyEvent *keyEvent = reinterpret_cast<TKeyEvent *>(iEventData);
        keyEvent->iScanCode = scanCode;
        keyEvent->iCode = code;
        keyEvent->iModifiers = modifiers;
        keyEvent->iRepeats = repeats;
    }
};

class FepReplayEvent
{
public:
    enum Type {
        Pause,
        Key,
        CompleteKey
    };

    FepReplayEvent(int msecsToPause)
        : m_type(Pause)
        , m_msecsToPause(msecsToPause)
    {
    }

    FepReplayEvent(TInt keyType, TInt scanCode, TUint code, TUint modifiers, TInt repeats)
        : m_type(Key)
        , m_keyType(keyType)
        , m_scanCode(scanCode)
        , m_code(code)
        , m_modifiers(modifiers)
        , m_repeats(repeats)
    {
    }

    FepReplayEvent(TInt scanCode, TUint code, TUint modifiers, TInt repeats)
        : m_type(CompleteKey)
        , m_scanCode(scanCode)
        , m_code(code)
        , m_modifiers(modifiers)
        , m_repeats(repeats)
    {
    }

    void sendEvent(QWidget *w, TInt type, TInt scanCode, TUint code, TUint modifiers, TInt repeats)
    {
        KeyEvent event(w, type, scanCode, code, modifiers, repeats);
        S60->wsSession().SendEventToWindowGroup(w->effectiveWinId()->DrawableWindow()->WindowGroupId(), event);
    }

    void pause(int msecs)
    {
        // Don't use qWait here. The polling nature of that function screws up the test.
        QTimer timer;
        QEventLoop loop;
        QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
        timer.setSingleShot(true);
        timer.start(msecs);
        loop.exec();
    }

    // For some reason, the test fails if using processEvents instead of an event loop
    // with a zero timer to quit it, so use the timer.
#define KEY_WAIT 0

    void replay(QWidget *w)
    {
        if (m_type == Pause) {
            pause(m_msecsToPause);
        } else if (m_type == Key) {
            sendEvent(w, m_keyType, m_scanCode, m_code, m_modifiers, m_repeats);
            if (m_keyType != EEventKeyDown)
                // EEventKeyDown events should have no pause before the EEventKey event.
                pause(KEY_WAIT);
        } else if (m_type == CompleteKey) {
            sendEvent(w, EEventKeyDown, m_scanCode, 0, m_modifiers, m_repeats);
            // EEventKeyDown events should have no pause before the EEventKey event.
            sendEvent(w, EEventKey, m_scanCode, m_code, m_modifiers, m_repeats);
            pause(KEY_WAIT);
            sendEvent(w, EEventKeyUp, m_scanCode, 0, m_modifiers, m_repeats);
            pause(KEY_WAIT);
        }
    }

private:
    Type m_type;
    int m_msecsToPause;
    TInt m_keyType;
    TInt m_scanCode;
    TUint m_code;
    TUint m_modifiers;
    TInt m_repeats;
};

Q_DECLARE_METATYPE(QList<FepReplayEvent>)
Q_DECLARE_METATYPE(Qt::InputMethodHints)
Q_DECLARE_METATYPE(QLineEdit::EchoMode);

#endif // Q_OS_SYMBIAN

void tst_QInputContext::initTestCase()
{
#ifdef Q_OS_SYMBIAN
    // Sanity test. Checks FEP for:
    // - T9 mode is default (it will attempt to fix this)
    // - Language is English (it cannot fix this; bail out if not correct)
    QWidget w;
    QLayout *layout = new QVBoxLayout;
    w.setLayout(layout);
    QLineEdit *lineedit = new QLineEdit;
    layout->addWidget(lineedit);
    lineedit->setFocus();
#ifdef QT_KEYPAD_NAVIGATION
    lineedit->setEditFocus(true);
#endif
    w.show();

    QDesktopWidget desktop;
    QRect screenSize = desktop.screenGeometry(&w);
    if (screenSize.width() > screenSize.height()) {
        // Crude way of finding out we are running on a qwerty phone.
        m_phoneIsQwerty = true;
        return;
    }

    for (int iterations = 0; iterations < 16; iterations++) {
        QTest::qWait(500);

        QList<FepReplayEvent> keyEvents;

        keyEvents << FepReplayEvent('9', '9', 0, 0);
        keyEvents << FepReplayEvent('6', '6', 0, 0);
        keyEvents << FepReplayEvent('8', '8', 0, 0);
        keyEvents << FepReplayEvent(EStdKeyRightArrow, EKeyRightArrow, 0, 0);

        foreach(FepReplayEvent event, keyEvents) {
            event.replay(lineedit);
        }

        QApplication::processEvents();

        if (lineedit->text().endsWith("you", Qt::CaseInsensitive)) {
            // Success!
            return;
        }

        // Try changing modes.
        // After 8 iterations, try to press the mode switch twice before typing.
        for (int c = 0; c <= iterations / 8; c++) {
            FepReplayEvent(EStdKeyHash, '#', 0, 0).replay(lineedit);
        }
    }

    QFAIL("FEP sanity test failed. Either the phone is not set to English, or the test was unable to enable T9");
#endif
}

void tst_QInputContext::maximumTextLength()
{
    QLineEdit le;

    le.setMaxLength(15);
    QVariant variant = le.inputMethodQuery(Qt::ImMaximumTextLength);
    QVERIFY(variant.isValid());
    QCOMPARE(variant.toInt(), 15);

    QPlainTextEdit pte;
    // For BC/historical reasons, QPlainTextEdit::inputMethodQuery is protected.
    variant = static_cast<QWidget *>(&pte)->inputMethodQuery(Qt::ImMaximumTextLength);
    QVERIFY(!variant.isValid());
}

class QFilterInputContext : public QInputContext
{
public:
    QFilterInputContext() {}
    ~QFilterInputContext() {}

    QString identifierName() { return QString(); }
    QString language() { return QString(); }

    void reset() {}

    bool isComposing() const { return false; }

    bool filterEvent( const QEvent *event )
    {
        lastTypes.append(event->type());
        return false;
    }

public:
    QList<QEvent::Type> lastTypes;
};

void tst_QInputContext::filterMouseEvents()
{
    QLineEdit le;
    le.show();
    QApplication::setActiveWindow(&le);

    QFilterInputContext *ic = new QFilterInputContext;
    le.setInputContext(ic);
    QTest::mouseClick(&le, Qt::LeftButton);

    QVERIFY(ic->lastTypes.indexOf(QEvent::MouseButtonRelease) >= 0);

    le.setInputContext(0);
}

class RequestSoftwareInputPanelStyle : public QWindowsStyle
{
public:
    RequestSoftwareInputPanelStyle()
        : m_rsipBehavior(RSIP_OnMouseClickAndAlreadyFocused)
    {
#ifdef Q_OS_WINCE
        qApp->setAutoSipEnabled(true);
#endif
    }
    ~RequestSoftwareInputPanelStyle()
    {
    }

    int styleHint(StyleHint hint, const QStyleOption *opt = 0,
                  const QWidget *widget = 0, QStyleHintReturn* returnData = 0) const
    {
        if (hint == SH_RequestSoftwareInputPanel) {
            return m_rsipBehavior;
        } else {
            return QWindowsStyle::styleHint(hint, opt, widget, returnData);
        }
    }

    RequestSoftwareInputPanel m_rsipBehavior;
};

void tst_QInputContext::requestSoftwareInputPanel()
{
    QStyle *oldStyle = qApp->style();
    oldStyle->setParent(this); // Prevent it being deleted.
    RequestSoftwareInputPanelStyle *newStyle = new RequestSoftwareInputPanelStyle;
    qApp->setStyle(newStyle);

    QWidget w;
    QLayout *layout = new QVBoxLayout;
    QLineEdit *le1, *le2;
    le1 = new QLineEdit;
    le2 = new QLineEdit;
    layout->addWidget(le1);
    layout->addWidget(le2);
    w.setLayout(layout);

    QFilterInputContext *ic1, *ic2;
    ic1 = new QFilterInputContext;
    ic2 = new QFilterInputContext;
    le1->setInputContext(ic1);
    le2->setInputContext(ic2);

    w.show();
    QApplication::setActiveWindow(&w);

    // Testing single click panel activation.
    newStyle->m_rsipBehavior = QStyle::RSIP_OnMouseClick;
    QTest::mouseClick(le2, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
    QVERIFY(ic2->lastTypes.indexOf(QEvent::RequestSoftwareInputPanel) >= 0);
    ic2->lastTypes.clear();

    // Testing double click panel activation.
    newStyle->m_rsipBehavior = QStyle::RSIP_OnMouseClickAndAlreadyFocused;
    QTest::mouseClick(le1, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
    QVERIFY(ic1->lastTypes.indexOf(QEvent::RequestSoftwareInputPanel) < 0);
    QTest::mouseClick(le1, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
    QVERIFY(ic1->lastTypes.indexOf(QEvent::RequestSoftwareInputPanel) >= 0);
    ic1->lastTypes.clear();

    // Testing right mouse button
    QTest::mouseClick(le1, Qt::RightButton, Qt::NoModifier, QPoint(5, 5));
    QVERIFY(ic1->lastTypes.indexOf(QEvent::RequestSoftwareInputPanel) < 0);

    qApp->setStyle(oldStyle);
    oldStyle->setParent(qApp);
}

void tst_QInputContext::closeSoftwareInputPanel()
{
    QWidget w;
    QLayout *layout = new QVBoxLayout;
    QLineEdit *le1, *le2;
    QRadioButton *rb;
    le1 = new QLineEdit;
    le2 = new QLineEdit;
    rb = new QRadioButton;
    layout->addWidget(le1);
    layout->addWidget(le2);
    layout->addWidget(rb);
    w.setLayout(layout);

    QFilterInputContext *ic1, *ic2;
    ic1 = new QFilterInputContext;
    ic2 = new QFilterInputContext;
    le1->setInputContext(ic1);
    le2->setInputContext(ic2);

    w.show();
    QApplication::setActiveWindow(&w);

    // Testing that panel doesn't close between two input methods aware widgets.
    QTest::mouseClick(le1, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
    QTest::mouseClick(le2, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
    QVERIFY(ic2->lastTypes.indexOf(QEvent::CloseSoftwareInputPanel) < 0);

    // Testing that panel closes when focusing non-aware widget.
    QTest::mouseClick(rb, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
    QVERIFY(ic2->lastTypes.indexOf(QEvent::CloseSoftwareInputPanel) >= 0);
}

void tst_QInputContext::selections()
{
    QLineEdit le;
    le.setText("Test text");
    le.setSelection(2, 2);
    QCOMPARE(le.inputMethodQuery(Qt::ImCursorPosition).toInt(), 4);
    QCOMPARE(le.inputMethodQuery(Qt::ImAnchorPosition).toInt(), 2);

    QList<QInputMethodEvent::Attribute> attributes;
    attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 5, 3, QVariant()));
    QInputMethodEvent event("", attributes);
    QApplication::sendEvent(&le, &event);
    QCOMPARE(le.cursorPosition(), 8);
    QCOMPARE(le.selectionStart(), 5);
    QCOMPARE(le.inputMethodQuery(Qt::ImCursorPosition).toInt(), 8);
    QCOMPARE(le.inputMethodQuery(Qt::ImAnchorPosition).toInt(), 5);
}

void tst_QInputContext::focusProxy()
{
    QWidget toplevel(0, Qt::X11BypassWindowManagerHint); toplevel.setObjectName("toplevel");
    QWidget w(&toplevel); w.setObjectName("w");
    QWidget proxy(&w); proxy.setObjectName("proxy");
    QWidget proxy2(&w); proxy2.setObjectName("proxy2");
    w.setFocusProxy(&proxy);
    w.setAttribute(Qt::WA_InputMethodEnabled);
    toplevel.show();
    QApplication::setActiveWindow(&toplevel);
    QTest::qWaitForWindowShown(&toplevel);
    w.setFocus();
    w.setAttribute(Qt::WA_NativeWindow); // we shouldn't crash!

    proxy.setAttribute(Qt::WA_InputMethodEnabled);
    proxy2.setAttribute(Qt::WA_InputMethodEnabled);

    proxy2.setFocus();
    w.setFocus();

    QInputContext *gic = qApp->inputContext();
    QVERIFY(gic);
    QCOMPARE(gic->focusWidget(), &proxy);

    // then change the focus proxy and check that input context is valid
    QVERIFY(w.hasFocus());
    QVERIFY(proxy.hasFocus());
    QVERIFY(!proxy2.hasFocus());
    w.setFocusProxy(&proxy2);
    QVERIFY(!w.hasFocus());
    QVERIFY(proxy.hasFocus());
    QVERIFY(!proxy2.hasFocus());
    QCOMPARE(gic->focusWidget(), &proxy);
}

void tst_QInputContext::symbianTestCoeFepInputContext_data()
{
#ifdef Q_OS_SYMBIAN
    QTest::addColumn<bool>                   ("inputMethodEnabled");
    QTest::addColumn<Qt::InputMethodHints>   ("inputMethodHints");
    QTest::addColumn<int>                    ("maxLength"); // Zero for no limit
    QTest::addColumn<QLineEdit::EchoMode>    ("echoMode");
    QTest::addColumn<QList<FepReplayEvent> > ("keyEvents");
    QTest::addColumn<QString>                ("finalString");
    QTest::addColumn<QString>                ("preeditString");
    QList<FepReplayEvent> events;

    events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
    events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
    events << FepReplayEvent('5', '5', 0, 0);
    events << FepReplayEvent('4', '4', 0, 0);
    events << FepReplayEvent('6', '6', 0, 0);
    events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
    events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
    events << FepReplayEvent('1', '1', 0, 0);
    events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
    events << FepReplayEvent('2', '2', 0, 0);
    events << FepReplayEvent('1', '1', 0, 0);
    QTest::newRow("Numbers (no FEP)")
            << false
            << Qt::InputMethodHints(Qt::ImhNone)
            << 0
            << QLineEdit::Normal
            << events
            << QString("521")
            << QString("");
    QTest::newRow("Numbers and password mode (no FEP)")
            << false
            << Qt::InputMethodHints(Qt::ImhNone)
            << 0
            << QLineEdit::Password
            << events
            << QString("521")
            << QString("");
    QTest::newRow("Numbers")
            << true
            << Qt::InputMethodHints(Qt::ImhDigitsOnly)
            << 0
            << QLineEdit::Normal
            << events
            << QString("521")
            << QString("");
    QTest::newRow("Numbers max length (no FEP)")
            << false
            << Qt::InputMethodHints(Qt::ImhNone)
            << 2
            << QLineEdit::Normal
            << events
            << QString("21")
            << QString("");
    QTest::newRow("Numbers max length")
            << true
            << Qt::InputMethodHints(Qt::ImhDigitsOnly)
            << 2
            << QLineEdit::Normal
            << events
            << QString("21")
            << QString("");
    events.clear();

    events << FepReplayEvent(EEventKeyDown, '5', 0, 0, 0);
    events << FepReplayEvent(EEventKey, '5', '5', 0, 0);
    events << FepReplayEvent(EEventKey, '5', '5', 0, 1);
    events << FepReplayEvent(EEventKey, '5', '5', 0, 1);
    events << FepReplayEvent(EEventKeyUp, '5', 0, 0, 0);
    QTest::newRow("Numbers and autorepeat (no FEP)")
            << false
            << Qt::InputMethodHints(Qt::ImhNone)
            << 0
            << QLineEdit::Normal
            << events
            << QString("555")
            << QString("");
    events.clear();

    events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
    events << FepReplayEvent('2', '2', 0, 0);
    events << FepReplayEvent('3', '3', 0, 0);
    events << FepReplayEvent('4', '4', 0, 0);
    events << FepReplayEvent('4', '4', 0, 0);
    events << FepReplayEvent('5', '5', 0, 0);
    events << FepReplayEvent('5', '5', 0, 0);
    events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
    QTest::newRow("Multitap")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText)
            << 0
            << QLineEdit::Normal
            << events
            << QString("Adh")
            << QString("");
    QTest::newRow("Multitap with no auto uppercase")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase)
            << 0
            << QLineEdit::Normal
            << events
            << QString("adh")
            << QString("");
    QTest::newRow("Multitap with uppercase")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferUppercase)
            << 0
            << QLineEdit::Normal
            << events
            << QString("ADH")
            << QString("");
    QTest::newRow("Multitap with lowercase")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase)
            << 0
            << QLineEdit::Normal
            << events
            << QString("adh")
            << QString("");
    QTest::newRow("Multitap with forced uppercase")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhUppercaseOnly)
            << 0
            << QLineEdit::Normal
            << events
            << QString("ADH")
            << QString("");
    QTest::newRow("Multitap with forced lowercase")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhLowercaseOnly)
            << 0
            << QLineEdit::Normal
            << events
            << QString("adh")
            << QString("");
    events.clear();

    events << FepReplayEvent(EStdKeyHash, '#', 0, 0);
    events << FepReplayEvent('2', '2', 0, 0);
    events << FepReplayEvent('2', '2', 0, 0);
    events << FepReplayEvent('3', '3', 0, 0);
    events << FepReplayEvent('4', '4', 0, 0);
    events << FepReplayEvent('4', '4', 0, 0);
    events << FepReplayEvent('5', '5', 0, 0);
    events << FepReplayEvent('5', '5', 0, 0);
    events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
    QTest::newRow("Multitap with mode switch")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText)
            << 0
            << QLineEdit::Normal
            << events
            << QString("bdh")
            << QString("");
    events.clear();

    events << FepReplayEvent('7', '7', 0, 0);
    events << FepReplayEvent('7', '7', 0, 0);
    events << FepReplayEvent('8', '8', 0, 0);
    events << FepReplayEvent('9', '9', 0, 0);
    events << FepReplayEvent('9', '9', 0, 0);
    QTest::newRow("Multitap with unfinished text")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText)
            << 0
            << QLineEdit::Normal
            << events
            << QString("Qt")
            << QString("x");
    events << FepReplayEvent(2000);
    QTest::newRow("Multitap with committed text")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText)
            << 0
            << QLineEdit::Normal
            << events
            << QString("Qtx")
            << QString("");
    events.clear();

    events << FepReplayEvent('4', '4', 0, 0);
    events << FepReplayEvent('4', '4', 0, 0);
    // Simulate holding down hash key.
    events << FepReplayEvent(EEventKeyDown, EStdKeyHash, 0, 0, 0);
    events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 0);
    events << FepReplayEvent(500);
    events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
    events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
    events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
    events << FepReplayEvent(EEventKeyUp, EStdKeyHash, 0, 0, 0);
    events << FepReplayEvent('7', '7', 0, 0);
    events << FepReplayEvent('7', '7', 0, 0);
    events << FepReplayEvent('8', '8', 0, 0);
    // QTBUG-9867: Switch back as well to make sure we don't get extra symbols
    events << FepReplayEvent(EEventKeyDown, EStdKeyHash, 0, 0, 0);
    events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 0);
    events << FepReplayEvent(500);
    events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
    events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
    events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
    events << FepReplayEvent(EEventKeyUp, EStdKeyHash, 0, 0, 0);
    events << FepReplayEvent('9', '9', 0, 0);
    events << FepReplayEvent('6', '6', 0, 0);
    events << FepReplayEvent('8', '8', 0, 0);
    events << FepReplayEvent(2000);
    events << FepReplayEvent(EStdKeyDevice3, EKeyDevice3, 0, 0); // Select key
    QTest::newRow("Multitap and numbers")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText)
            << 0
            << QLineEdit::Normal
            << events
            << QString("H778wmt")
            << QString("");
    QTest::newRow("T9 and numbers")
            << true
            << Qt::InputMethodHints(Qt::ImhPreferLowercase)
            << 0
            << QLineEdit::Normal
            << events
            << QString("hi778you")
            << QString("");
    events.clear();

    events << FepReplayEvent('4', '4', 0, 0);
    events << FepReplayEvent('4', '4', 0, 0);
    events << FepReplayEvent(EStdKeyDevice3, EKeyDevice3, 0, 0); // Select key
    QTest::newRow("T9")
            << true
            << Qt::InputMethodHints(Qt::ImhPreferLowercase)
            << 0
            << QLineEdit::Normal
            << events
            << QString("hi")
            << QString("");
    QTest::newRow("T9 with uppercase")
            << true
            << Qt::InputMethodHints(Qt::ImhPreferUppercase)
            << 0
            << QLineEdit::Normal
            << events
            << QString("HI")
            << QString("");
    QTest::newRow("T9 with forced lowercase")
            << true
            << Qt::InputMethodHints(Qt::ImhLowercaseOnly)
            << 0
            << QLineEdit::Normal
            << events
            << QString("hi")
            << QString("");
    QTest::newRow("T9 with forced uppercase")
            << true
            << Qt::InputMethodHints(Qt::ImhUppercaseOnly)
            << 0
            << QLineEdit::Normal
            << events
            << QString("HI")
            << QString("");
    QTest::newRow("T9 with maxlength")
            << true
            << Qt::InputMethodHints(Qt::ImhLowercaseOnly)
            << 1
            << QLineEdit::Normal
            << events
            << QString("i")
            << QString("");
    events.clear();

    events << FepReplayEvent('4', '4', 0, 0);
    events << FepReplayEvent('4', '4', 0, 0);
    events << FepReplayEvent(EStdKeyLeftArrow, EKeyLeftArrow, 0, 0);
    events << FepReplayEvent(EStdKeyLeftArrow, EKeyLeftArrow, 0, 0);
    events << FepReplayEvent('9', '9', 0, 0);
    events << FepReplayEvent('6', '6', 0, 0);
    events << FepReplayEvent('8', '8', 0, 0);
    events << FepReplayEvent('0', '0', 0, 0);
    events << FepReplayEvent(EStdKeyRightArrow, EKeyRightArrow, 0, 0);
    events << FepReplayEvent(EStdKeyRightArrow, EKeyRightArrow, 0, 0);
    events << FepReplayEvent('8', '8', 0, 0);
    events << FepReplayEvent('8', '8', 0, 0);
    QTest::newRow("T9 with movement and unfinished text")
            << true
            << Qt::InputMethodHints(Qt::ImhPreferLowercase)
            << 0
            << QLineEdit::Normal
            << events
            << QString("you hi")
            << QString("tv");
    QTest::newRow("T9 with movement, password and unfinished text")
            << true
            << Qt::InputMethodHints(Qt::ImhPreferLowercase)
            << 0
            << QLineEdit::Password
            << events
            << QString("wmt h")
            << QString("u");
    QTest::newRow("T9 with movement, maxlength, password and unfinished text")
            << true
            << Qt::InputMethodHints(Qt::ImhPreferLowercase)
            << 2
            << QLineEdit::Password
            << events
            << QString("wh")
            << QString("");
    QTest::newRow("T9 with movement, maxlength and unfinished text")
            << true
            << Qt::InputMethodHints(Qt::ImhPreferLowercase)
            << 2
            << QLineEdit::Normal
            << events
            << QString("hi")
            << QString("");
    QTest::newRow("Multitap with movement and unfinished text")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase)
            << 0
            << QLineEdit::Normal
            << events
            << QString("wmt h")
            << QString("u");
    QTest::newRow("Multitap with movement, maxlength and unfinished text")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase)
            << 2
            << QLineEdit::Normal
            << events
            << QString("wh")
            << QString("");
    QTest::newRow("Numbers with movement")
            << true
            << Qt::InputMethodHints(Qt::ImhDigitsOnly)
            << 0
            << QLineEdit::Normal
            << events
            << QString("96804488")
            << QString("");
    QTest::newRow("Numbers with movement and maxlength")
            << true
            << Qt::InputMethodHints(Qt::ImhDigitsOnly)
            << 2
            << QLineEdit::Normal
            << events
            << QString("44")
            << QString("");
    QTest::newRow("Numbers with movement, password and unfinished text")
            << true
            << Qt::InputMethodHints(Qt::ImhDigitsOnly)
            << 0
            << QLineEdit::Password
            << events
            << QString("9680448")
            << QString("8");
    QTest::newRow("Numbers with movement, maxlength, password and unfinished text")
            << true
            << Qt::InputMethodHints(Qt::ImhDigitsOnly)
            << 2
            << QLineEdit::Password
            << events
            << QString("44")
            << QString("");
    events << FepReplayEvent(EStdKeyRightArrow, EKeyRightArrow, 0, 0);
    QTest::newRow("T9 with movement")
            << true
            << Qt::InputMethodHints(Qt::ImhPreferLowercase)
            << 0
            << QLineEdit::Normal
            << events
            << QString("you htvi")
            << QString("");
    QTest::newRow("T9 with movement and password")
            << true
            << Qt::InputMethodHints(Qt::ImhPreferLowercase)
            << 0
            << QLineEdit::Password
            << events
            << QString("wmt hu")
            << QString("");
    QTest::newRow("T9 with movement, maxlength and password")
            << true
            << Qt::InputMethodHints(Qt::ImhPreferLowercase)
            << 2
            << QLineEdit::Password
            << events
            << QString("wh")
            << QString("");
    QTest::newRow("Multitap with movement")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase)
            << 0
            << QLineEdit::Normal
            << events
            << QString("wmt hu")
            << QString("");
    QTest::newRow("Multitap with movement and maxlength")
            << true
            << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase)
            << 2
            << QLineEdit::Normal
            << events
            << QString("wh")
            << QString("");
    QTest::newRow("Numbers with movement and password")
            << true
            << Qt::InputMethodHints(Qt::ImhDigitsOnly)
            << 0
            << QLineEdit::Password
            << events
            << QString("96804488")
            << QString("");
    QTest::newRow("Numbers with movement, maxlength and password")
            << true
            << Qt::InputMethodHints(Qt::ImhDigitsOnly)
            << 2
            << QLineEdit::Password
            << events
            << QString("44")
            << QString("");
    events.clear();
#endif
}

void tst_QInputContext::symbianTestCoeFepInputContext()
{
#ifndef Q_OS_SYMBIAN
    QSKIP("This is a Symbian-only test", SkipAll);
#else
    QCoeFepInputContext *ic = qobject_cast<QCoeFepInputContext *>(qApp->inputContext());
    if (!ic) {
        QSKIP("coefep is not the active input context; skipping test", SkipAll);
    }

    QFETCH(bool,                  inputMethodEnabled);
    QFETCH(Qt::InputMethodHints,  inputMethodHints);
    QFETCH(int,                   maxLength);
    QFETCH(QLineEdit::EchoMode,   echoMode);
    QFETCH(QList<FepReplayEvent>, keyEvents);
    QFETCH(QString,               finalString);
    QFETCH(QString,               preeditString);

    if (inputMethodEnabled && m_phoneIsQwerty) {
        QSKIP("Skipping advanced input method tests on QWERTY phones", SkipSingle);
    }

    QWidget w;
    QLayout *layout = new QVBoxLayout;
    w.setLayout(layout);
    QLineEdit *lineedit = new QLineEdit;
    layout->addWidget(lineedit);
    lineedit->setFocus();
#ifdef QT_KEYPAD_NAVIGATION
    lineedit->setEditFocus(true);
#endif
    w.show();

    lineedit->setAttribute(Qt::WA_InputMethodEnabled, inputMethodEnabled);
    lineedit->setInputMethodHints(inputMethodHints);
    if (maxLength > 0)
        lineedit->setMaxLength(maxLength);
    lineedit->setEchoMode(echoMode);

    QTest::qWait(200);

    foreach(FepReplayEvent event, keyEvents) {
        event.replay(lineedit);
    }

    QApplication::processEvents();

    QCOMPARE(lineedit->text(), finalString);
    QCOMPARE(ic->m_preeditString, preeditString);
#endif
}

QTEST_MAIN(tst_QInputContext)
#include "tst_qinputcontext.moc"