tests/auto/qinputcontext/tst_qinputcontext.cpp
changeset 37 758a864f9613
parent 18 2f34d5167611
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    46 #include <qlineedit.h>
    46 #include <qlineedit.h>
    47 #include <qplaintextedit.h>
    47 #include <qplaintextedit.h>
    48 #include <qlayout.h>
    48 #include <qlayout.h>
    49 #include <qradiobutton.h>
    49 #include <qradiobutton.h>
    50 #include <qwindowsstyle.h>
    50 #include <qwindowsstyle.h>
       
    51 #include <qdesktopwidget.h>
       
    52 #include <qpushbutton.h>
       
    53 
       
    54 #ifdef Q_OS_SYMBIAN
       
    55 #include <private/qt_s60_p.h>
       
    56 #include <private/qcoefepinputcontext_p.h>
       
    57 
       
    58 #include <w32std.h>
       
    59 #include <coecntrl.h>
       
    60 #endif
    51 
    61 
    52 class tst_QInputContext : public QObject
    62 class tst_QInputContext : public QObject
    53 {
    63 {
    54 Q_OBJECT
    64 Q_OBJECT
    55 
    65 
    56 public:
    66 public:
    57     tst_QInputContext() {}
    67     tst_QInputContext() : m_phoneIsQwerty(false) {}
    58     virtual ~tst_QInputContext() {}
    68     virtual ~tst_QInputContext() {}
    59 
    69 
    60 public slots:
    70 public slots:
    61     void initTestCase() {}
    71     void initTestCase();
    62     void cleanupTestCase() {}
    72     void cleanupTestCase() {}
    63     void init() {}
    73     void init() {}
    64     void cleanup() {}
    74     void cleanup() {}
    65 private slots:
    75 private slots:
    66     void maximumTextLength();
    76     void maximumTextLength();
    67     void filterMouseEvents();
    77     void filterMouseEvents();
    68     void requestSoftwareInputPanel();
    78     void requestSoftwareInputPanel();
    69     void closeSoftwareInputPanel();
    79     void closeSoftwareInputPanel();
    70     void selections();
    80     void selections();
    71     void focusProxy();
    81     void focusProxy();
       
    82     void symbianTestCoeFepInputContext_data();
       
    83     void symbianTestCoeFepInputContext();
       
    84     void symbianTestCoeFepAutoCommit_data();
       
    85     void symbianTestCoeFepAutoCommit();
       
    86 
       
    87 private:
       
    88     bool m_phoneIsQwerty;
    72 };
    89 };
       
    90 
       
    91 #ifdef Q_OS_SYMBIAN
       
    92 class KeyEvent : public TWsEvent
       
    93 {
       
    94 public:
       
    95     KeyEvent(QWidget *w, TInt type, TInt scanCode, TUint code, TUint modifiers, TInt repeats) {
       
    96         iHandle = w->effectiveWinId()->DrawableWindow()->WindowGroupId();
       
    97         iType = type;
       
    98         SetTimeNow();
       
    99         TKeyEvent *keyEvent = reinterpret_cast<TKeyEvent *>(iEventData);
       
   100         keyEvent->iScanCode = scanCode;
       
   101         keyEvent->iCode = code;
       
   102         keyEvent->iModifiers = modifiers;
       
   103         keyEvent->iRepeats = repeats;
       
   104     }
       
   105 };
       
   106 
       
   107 class FepReplayEvent
       
   108 {
       
   109 public:
       
   110     enum Type {
       
   111         Pause,
       
   112         Key,
       
   113         CompleteKey
       
   114     };
       
   115 
       
   116     FepReplayEvent(int msecsToPause)
       
   117         : m_type(Pause)
       
   118         , m_msecsToPause(msecsToPause)
       
   119     {
       
   120     }
       
   121 
       
   122     FepReplayEvent(TInt keyType, TInt scanCode, TUint code, TUint modifiers, TInt repeats)
       
   123         : m_type(Key)
       
   124         , m_keyType(keyType)
       
   125         , m_scanCode(scanCode)
       
   126         , m_code(code)
       
   127         , m_modifiers(modifiers)
       
   128         , m_repeats(repeats)
       
   129     {
       
   130     }
       
   131 
       
   132     FepReplayEvent(TInt scanCode, TUint code, TUint modifiers, TInt repeats)
       
   133         : m_type(CompleteKey)
       
   134         , m_scanCode(scanCode)
       
   135         , m_code(code)
       
   136         , m_modifiers(modifiers)
       
   137         , m_repeats(repeats)
       
   138     {
       
   139     }
       
   140 
       
   141     void sendEvent(QWidget *w, TInt type, TInt scanCode, TUint code, TUint modifiers, TInt repeats)
       
   142     {
       
   143         KeyEvent event(w, type, scanCode, code, modifiers, repeats);
       
   144         S60->wsSession().SendEventToWindowGroup(w->effectiveWinId()->DrawableWindow()->WindowGroupId(), event);
       
   145     }
       
   146 
       
   147     void pause(int msecs)
       
   148     {
       
   149         // Don't use qWait here. The polling nature of that function screws up the test.
       
   150         QTimer timer;
       
   151         QEventLoop loop;
       
   152         QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
       
   153         timer.setSingleShot(true);
       
   154         timer.start(msecs);
       
   155         loop.exec();
       
   156     }
       
   157 
       
   158     // For some reason, the test fails if using processEvents instead of an event loop
       
   159     // with a zero timer to quit it, so use the timer.
       
   160 #define KEY_WAIT 0
       
   161 
       
   162     void replay(QWidget *w)
       
   163     {
       
   164         if (m_type == Pause) {
       
   165             pause(m_msecsToPause);
       
   166         } else if (m_type == Key) {
       
   167             sendEvent(w, m_keyType, m_scanCode, m_code, m_modifiers, m_repeats);
       
   168             if (m_keyType != EEventKeyDown)
       
   169                 // EEventKeyDown events should have no pause before the EEventKey event.
       
   170                 pause(KEY_WAIT);
       
   171         } else if (m_type == CompleteKey) {
       
   172             sendEvent(w, EEventKeyDown, m_scanCode, 0, m_modifiers, m_repeats);
       
   173             // EEventKeyDown events should have no pause before the EEventKey event.
       
   174             sendEvent(w, EEventKey, m_scanCode, m_code, m_modifiers, m_repeats);
       
   175             pause(KEY_WAIT);
       
   176             sendEvent(w, EEventKeyUp, m_scanCode, 0, m_modifiers, m_repeats);
       
   177             pause(KEY_WAIT);
       
   178         }
       
   179     }
       
   180 
       
   181 private:
       
   182     Type m_type;
       
   183     int m_msecsToPause;
       
   184     TInt m_keyType;
       
   185     TInt m_scanCode;
       
   186     TUint m_code;
       
   187     TUint m_modifiers;
       
   188     TInt m_repeats;
       
   189 };
       
   190 
       
   191 Q_DECLARE_METATYPE(QList<FepReplayEvent>)
       
   192 Q_DECLARE_METATYPE(Qt::InputMethodHints)
       
   193 Q_DECLARE_METATYPE(QLineEdit::EchoMode);
       
   194 
       
   195 #endif // Q_OS_SYMBIAN
       
   196 
       
   197 void tst_QInputContext::initTestCase()
       
   198 {
       
   199 #ifdef Q_OS_SYMBIAN
       
   200     // Sanity test. Checks FEP for:
       
   201     // - T9 mode is default (it will attempt to fix this)
       
   202     // - Language is English (it cannot fix this; bail out if not correct)
       
   203     QWidget w;
       
   204     QLayout *layout = new QVBoxLayout;
       
   205     w.setLayout(layout);
       
   206     QLineEdit *lineedit = new QLineEdit;
       
   207     layout->addWidget(lineedit);
       
   208     lineedit->setFocus();
       
   209 #ifdef QT_KEYPAD_NAVIGATION
       
   210     lineedit->setEditFocus(true);
       
   211 #endif
       
   212     w.show();
       
   213 
       
   214     QDesktopWidget desktop;
       
   215     QRect screenSize = desktop.screenGeometry(&w);
       
   216     if (screenSize.width() > screenSize.height()) {
       
   217         // Crude way of finding out we are running on a qwerty phone.
       
   218         m_phoneIsQwerty = true;
       
   219         return;
       
   220     }
       
   221 
       
   222     for (int iterations = 0; iterations < 16; iterations++) {
       
   223         QTest::qWait(500);
       
   224 
       
   225         QList<FepReplayEvent> keyEvents;
       
   226 
       
   227         keyEvents << FepReplayEvent('9', '9', 0, 0);
       
   228         keyEvents << FepReplayEvent('6', '6', 0, 0);
       
   229         keyEvents << FepReplayEvent('8', '8', 0, 0);
       
   230         keyEvents << FepReplayEvent(EStdKeyRightArrow, EKeyRightArrow, 0, 0);
       
   231 
       
   232         foreach(FepReplayEvent event, keyEvents) {
       
   233             event.replay(lineedit);
       
   234         }
       
   235 
       
   236         QApplication::processEvents();
       
   237 
       
   238         if (lineedit->text().endsWith("you", Qt::CaseInsensitive)) {
       
   239             // Success!
       
   240             return;
       
   241         }
       
   242 
       
   243         // Try changing modes.
       
   244         // After 8 iterations, try to press the mode switch twice before typing.
       
   245         for (int c = 0; c <= iterations / 8; c++) {
       
   246             FepReplayEvent(EStdKeyHash, '#', 0, 0).replay(lineedit);
       
   247         }
       
   248     }
       
   249 
       
   250     QFAIL("FEP sanity test failed. Either the phone is not set to English, or the test was unable to enable T9");
       
   251 #endif
       
   252 }
    73 
   253 
    74 void tst_QInputContext::maximumTextLength()
   254 void tst_QInputContext::maximumTextLength()
    75 {
   255 {
    76     QLineEdit le;
   256     QLineEdit le;
    77 
   257 
   269     proxy2.setFocus();
   449     proxy2.setFocus();
   270     w.setFocus();
   450     w.setFocus();
   271 
   451 
   272     QInputContext *gic = qApp->inputContext();
   452     QInputContext *gic = qApp->inputContext();
   273     QVERIFY(gic);
   453     QVERIFY(gic);
   274     qDebug() << gic->focusWidget() << &proxy;
       
   275     QCOMPARE(gic->focusWidget(), &proxy);
   454     QCOMPARE(gic->focusWidget(), &proxy);
   276 
   455 
   277     // then change the focus proxy and check that input context is valid
   456     // then change the focus proxy and check that input context is valid
   278     QVERIFY(w.hasFocus());
   457     QVERIFY(w.hasFocus());
   279     QVERIFY(proxy.hasFocus());
   458     QVERIFY(proxy.hasFocus());
   283     QVERIFY(proxy.hasFocus());
   462     QVERIFY(proxy.hasFocus());
   284     QVERIFY(!proxy2.hasFocus());
   463     QVERIFY(!proxy2.hasFocus());
   285     QCOMPARE(gic->focusWidget(), &proxy);
   464     QCOMPARE(gic->focusWidget(), &proxy);
   286 }
   465 }
   287 
   466 
       
   467 void tst_QInputContext::symbianTestCoeFepInputContext_data()
       
   468 {
       
   469 #ifdef Q_OS_SYMBIAN
       
   470     QTest::addColumn<bool>                   ("inputMethodEnabled");
       
   471     QTest::addColumn<Qt::InputMethodHints>   ("inputMethodHints");
       
   472     QTest::addColumn<int>                    ("maxLength"); // Zero for no limit
       
   473     QTest::addColumn<QLineEdit::EchoMode>    ("echoMode");
       
   474     QTest::addColumn<QList<FepReplayEvent> > ("keyEvents");
       
   475     QTest::addColumn<QString>                ("finalString");
       
   476     QTest::addColumn<QString>                ("preeditString");
       
   477     QList<FepReplayEvent> events;
       
   478 
       
   479     events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
       
   480     events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
       
   481     events << FepReplayEvent('5', '5', 0, 0);
       
   482     events << FepReplayEvent('4', '4', 0, 0);
       
   483     events << FepReplayEvent('6', '6', 0, 0);
       
   484     events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
       
   485     events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
       
   486     events << FepReplayEvent('1', '1', 0, 0);
       
   487     events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
       
   488     events << FepReplayEvent('2', '2', 0, 0);
       
   489     events << FepReplayEvent('1', '1', 0, 0);
       
   490     QTest::newRow("Numbers (no FEP)")
       
   491             << false
       
   492             << Qt::InputMethodHints(Qt::ImhNone)
       
   493             << 0
       
   494             << QLineEdit::Normal
       
   495             << events
       
   496             << QString("521")
       
   497             << QString("");
       
   498     QTest::newRow("Numbers and password mode (no FEP)")
       
   499             << false
       
   500             << Qt::InputMethodHints(Qt::ImhNone)
       
   501             << 0
       
   502             << QLineEdit::Password
       
   503             << events
       
   504             << QString("521")
       
   505             << QString("");
       
   506     QTest::newRow("Numbers")
       
   507             << true
       
   508             << Qt::InputMethodHints(Qt::ImhDigitsOnly)
       
   509             << 0
       
   510             << QLineEdit::Normal
       
   511             << events
       
   512             << QString("521")
       
   513             << QString("");
       
   514     QTest::newRow("Numbers max length (no FEP)")
       
   515             << false
       
   516             << Qt::InputMethodHints(Qt::ImhNone)
       
   517             << 2
       
   518             << QLineEdit::Normal
       
   519             << events
       
   520             << QString("21")
       
   521             << QString("");
       
   522     QTest::newRow("Numbers max length")
       
   523             << true
       
   524             << Qt::InputMethodHints(Qt::ImhDigitsOnly)
       
   525             << 2
       
   526             << QLineEdit::Normal
       
   527             << events
       
   528             << QString("21")
       
   529             << QString("");
       
   530     events.clear();
       
   531 
       
   532     events << FepReplayEvent(EEventKeyDown, '5', 0, 0, 0);
       
   533     events << FepReplayEvent(EEventKey, '5', '5', 0, 0);
       
   534     events << FepReplayEvent(EEventKey, '5', '5', 0, 1);
       
   535     events << FepReplayEvent(EEventKey, '5', '5', 0, 1);
       
   536     events << FepReplayEvent(EEventKeyUp, '5', 0, 0, 0);
       
   537     QTest::newRow("Numbers and autorepeat (no FEP)")
       
   538             << false
       
   539             << Qt::InputMethodHints(Qt::ImhNone)
       
   540             << 0
       
   541             << QLineEdit::Normal
       
   542             << events
       
   543             << QString("555")
       
   544             << QString("");
       
   545     events.clear();
       
   546 
       
   547     events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
       
   548     events << FepReplayEvent('2', '2', 0, 0);
       
   549     events << FepReplayEvent('3', '3', 0, 0);
       
   550     events << FepReplayEvent('4', '4', 0, 0);
       
   551     events << FepReplayEvent('4', '4', 0, 0);
       
   552     events << FepReplayEvent('5', '5', 0, 0);
       
   553     events << FepReplayEvent('5', '5', 0, 0);
       
   554     events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
       
   555     QTest::newRow("Multitap")
       
   556             << true
       
   557             << Qt::InputMethodHints(Qt::ImhNoPredictiveText)
       
   558             << 0
       
   559             << QLineEdit::Normal
       
   560             << events
       
   561             << QString("Adh")
       
   562             << QString("");
       
   563     QTest::newRow("Multitap with no auto uppercase")
       
   564             << true
       
   565             << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase)
       
   566             << 0
       
   567             << QLineEdit::Normal
       
   568             << events
       
   569             << QString("adh")
       
   570             << QString("");
       
   571     QTest::newRow("Multitap with uppercase")
       
   572             << true
       
   573             << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferUppercase)
       
   574             << 0
       
   575             << QLineEdit::Normal
       
   576             << events
       
   577             << QString("ADH")
       
   578             << QString("");
       
   579     QTest::newRow("Multitap with lowercase")
       
   580             << true
       
   581             << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase)
       
   582             << 0
       
   583             << QLineEdit::Normal
       
   584             << events
       
   585             << QString("adh")
       
   586             << QString("");
       
   587     QTest::newRow("Multitap with forced uppercase")
       
   588             << true
       
   589             << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhUppercaseOnly)
       
   590             << 0
       
   591             << QLineEdit::Normal
       
   592             << events
       
   593             << QString("ADH")
       
   594             << QString("");
       
   595     QTest::newRow("Multitap with forced lowercase")
       
   596             << true
       
   597             << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhLowercaseOnly)
       
   598             << 0
       
   599             << QLineEdit::Normal
       
   600             << events
       
   601             << QString("adh")
       
   602             << QString("");
       
   603     events.clear();
       
   604 
       
   605     events << FepReplayEvent(EStdKeyHash, '#', 0, 0);
       
   606     events << FepReplayEvent('2', '2', 0, 0);
       
   607     events << FepReplayEvent('2', '2', 0, 0);
       
   608     events << FepReplayEvent('3', '3', 0, 0);
       
   609     events << FepReplayEvent('4', '4', 0, 0);
       
   610     events << FepReplayEvent('4', '4', 0, 0);
       
   611     events << FepReplayEvent('5', '5', 0, 0);
       
   612     events << FepReplayEvent('5', '5', 0, 0);
       
   613     events << FepReplayEvent(EStdKeyBackspace, EKeyBackspace, 0, 0);
       
   614     QTest::newRow("Multitap with mode switch")
       
   615             << true
       
   616             << Qt::InputMethodHints(Qt::ImhNoPredictiveText)
       
   617             << 0
       
   618             << QLineEdit::Normal
       
   619             << events
       
   620             << QString("bdh")
       
   621             << QString("");
       
   622     events.clear();
       
   623 
       
   624     events << FepReplayEvent('7', '7', 0, 0);
       
   625     events << FepReplayEvent('7', '7', 0, 0);
       
   626     events << FepReplayEvent('8', '8', 0, 0);
       
   627     events << FepReplayEvent('9', '9', 0, 0);
       
   628     events << FepReplayEvent('9', '9', 0, 0);
       
   629     QTest::newRow("Multitap with unfinished text")
       
   630             << true
       
   631             << Qt::InputMethodHints(Qt::ImhNoPredictiveText)
       
   632             << 0
       
   633             << QLineEdit::Normal
       
   634             << events
       
   635             << QString("Qt")
       
   636             << QString("x");
       
   637     events << FepReplayEvent(2000);
       
   638     QTest::newRow("Multitap with committed text")
       
   639             << true
       
   640             << Qt::InputMethodHints(Qt::ImhNoPredictiveText)
       
   641             << 0
       
   642             << QLineEdit::Normal
       
   643             << events
       
   644             << QString("Qtx")
       
   645             << QString("");
       
   646     events.clear();
       
   647 
       
   648     events << FepReplayEvent('4', '4', 0, 0);
       
   649     events << FepReplayEvent('4', '4', 0, 0);
       
   650     // Simulate holding down hash key.
       
   651     events << FepReplayEvent(EEventKeyDown, EStdKeyHash, 0, 0, 0);
       
   652     events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 0);
       
   653     events << FepReplayEvent(500);
       
   654     events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
       
   655     events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
       
   656     events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
       
   657     events << FepReplayEvent(EEventKeyUp, EStdKeyHash, 0, 0, 0);
       
   658     events << FepReplayEvent('7', '7', 0, 0);
       
   659     events << FepReplayEvent('7', '7', 0, 0);
       
   660     events << FepReplayEvent('8', '8', 0, 0);
       
   661     // QTBUG-9867: Switch back as well to make sure we don't get extra symbols
       
   662     events << FepReplayEvent(EEventKeyDown, EStdKeyHash, 0, 0, 0);
       
   663     events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 0);
       
   664     events << FepReplayEvent(500);
       
   665     events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
       
   666     events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
       
   667     events << FepReplayEvent(EEventKey, EStdKeyHash, '#', 0, 1);
       
   668     events << FepReplayEvent(EEventKeyUp, EStdKeyHash, 0, 0, 0);
       
   669     events << FepReplayEvent('9', '9', 0, 0);
       
   670     events << FepReplayEvent('6', '6', 0, 0);
       
   671     events << FepReplayEvent('8', '8', 0, 0);
       
   672     events << FepReplayEvent(2000);
       
   673     events << FepReplayEvent(EStdKeyDevice3, EKeyDevice3, 0, 0); // Select key
       
   674     QTest::newRow("Multitap and numbers")
       
   675             << true
       
   676             << Qt::InputMethodHints(Qt::ImhNoPredictiveText)
       
   677             << 0
       
   678             << QLineEdit::Normal
       
   679             << events
       
   680             << QString("H778wmt")
       
   681             << QString("");
       
   682     QTest::newRow("T9 and numbers")
       
   683             << true
       
   684             << Qt::InputMethodHints(Qt::ImhPreferLowercase)
       
   685             << 0
       
   686             << QLineEdit::Normal
       
   687             << events
       
   688             << QString("hi778you")
       
   689             << QString("");
       
   690     events.clear();
       
   691 
       
   692     events << FepReplayEvent('4', '4', 0, 0);
       
   693     events << FepReplayEvent('4', '4', 0, 0);
       
   694     events << FepReplayEvent(EStdKeyDevice3, EKeyDevice3, 0, 0); // Select key
       
   695     QTest::newRow("T9")
       
   696             << true
       
   697             << Qt::InputMethodHints(Qt::ImhPreferLowercase)
       
   698             << 0
       
   699             << QLineEdit::Normal
       
   700             << events
       
   701             << QString("hi")
       
   702             << QString("");
       
   703     QTest::newRow("T9 with uppercase")
       
   704             << true
       
   705             << Qt::InputMethodHints(Qt::ImhPreferUppercase)
       
   706             << 0
       
   707             << QLineEdit::Normal
       
   708             << events
       
   709             << QString("HI")
       
   710             << QString("");
       
   711     QTest::newRow("T9 with forced lowercase")
       
   712             << true
       
   713             << Qt::InputMethodHints(Qt::ImhLowercaseOnly)
       
   714             << 0
       
   715             << QLineEdit::Normal
       
   716             << events
       
   717             << QString("hi")
       
   718             << QString("");
       
   719     QTest::newRow("T9 with forced uppercase")
       
   720             << true
       
   721             << Qt::InputMethodHints(Qt::ImhUppercaseOnly)
       
   722             << 0
       
   723             << QLineEdit::Normal
       
   724             << events
       
   725             << QString("HI")
       
   726             << QString("");
       
   727     QTest::newRow("T9 with maxlength")
       
   728             << true
       
   729             << Qt::InputMethodHints(Qt::ImhLowercaseOnly)
       
   730             << 1
       
   731             << QLineEdit::Normal
       
   732             << events
       
   733             << QString("i")
       
   734             << QString("");
       
   735     events.clear();
       
   736 
       
   737     events << FepReplayEvent('4', '4', 0, 0);
       
   738     events << FepReplayEvent('4', '4', 0, 0);
       
   739     events << FepReplayEvent(EStdKeyLeftArrow, EKeyLeftArrow, 0, 0);
       
   740     events << FepReplayEvent(EStdKeyLeftArrow, EKeyLeftArrow, 0, 0);
       
   741     events << FepReplayEvent('9', '9', 0, 0);
       
   742     events << FepReplayEvent('6', '6', 0, 0);
       
   743     events << FepReplayEvent('8', '8', 0, 0);
       
   744     events << FepReplayEvent('0', '0', 0, 0);
       
   745     events << FepReplayEvent(EStdKeyRightArrow, EKeyRightArrow, 0, 0);
       
   746     events << FepReplayEvent(EStdKeyRightArrow, EKeyRightArrow, 0, 0);
       
   747     events << FepReplayEvent('8', '8', 0, 0);
       
   748     events << FepReplayEvent('8', '8', 0, 0);
       
   749     QTest::newRow("T9 with movement and unfinished text")
       
   750             << true
       
   751             << Qt::InputMethodHints(Qt::ImhPreferLowercase)
       
   752             << 0
       
   753             << QLineEdit::Normal
       
   754             << events
       
   755             << QString("you hi")
       
   756             << QString("tv");
       
   757     QTest::newRow("T9 with movement, password and unfinished text")
       
   758             << true
       
   759             << Qt::InputMethodHints(Qt::ImhPreferLowercase)
       
   760             << 0
       
   761             << QLineEdit::Password
       
   762             << events
       
   763             << QString("wmt h")
       
   764             << QString("u");
       
   765     QTest::newRow("T9 with movement, maxlength, password and unfinished text")
       
   766             << true
       
   767             << Qt::InputMethodHints(Qt::ImhPreferLowercase)
       
   768             << 2
       
   769             << QLineEdit::Password
       
   770             << events
       
   771             << QString("wh")
       
   772             << QString("");
       
   773     QTest::newRow("T9 with movement, maxlength and unfinished text")
       
   774             << true
       
   775             << Qt::InputMethodHints(Qt::ImhPreferLowercase)
       
   776             << 2
       
   777             << QLineEdit::Normal
       
   778             << events
       
   779             << QString("hi")
       
   780             << QString("");
       
   781     QTest::newRow("Multitap with movement and unfinished text")
       
   782             << true
       
   783             << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase)
       
   784             << 0
       
   785             << QLineEdit::Normal
       
   786             << events
       
   787             << QString("wmt h")
       
   788             << QString("u");
       
   789     QTest::newRow("Multitap with movement, maxlength and unfinished text")
       
   790             << true
       
   791             << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase)
       
   792             << 2
       
   793             << QLineEdit::Normal
       
   794             << events
       
   795             << QString("wh")
       
   796             << QString("");
       
   797     QTest::newRow("Numbers with movement")
       
   798             << true
       
   799             << Qt::InputMethodHints(Qt::ImhDigitsOnly)
       
   800             << 0
       
   801             << QLineEdit::Normal
       
   802             << events
       
   803             << QString("96804488")
       
   804             << QString("");
       
   805     QTest::newRow("Numbers with movement and maxlength")
       
   806             << true
       
   807             << Qt::InputMethodHints(Qt::ImhDigitsOnly)
       
   808             << 2
       
   809             << QLineEdit::Normal
       
   810             << events
       
   811             << QString("44")
       
   812             << QString("");
       
   813     QTest::newRow("Numbers with movement, password and unfinished text")
       
   814             << true
       
   815             << Qt::InputMethodHints(Qt::ImhDigitsOnly)
       
   816             << 0
       
   817             << QLineEdit::Password
       
   818             << events
       
   819             << QString("9680448")
       
   820             << QString("8");
       
   821     QTest::newRow("Numbers with movement, maxlength, password and unfinished text")
       
   822             << true
       
   823             << Qt::InputMethodHints(Qt::ImhDigitsOnly)
       
   824             << 2
       
   825             << QLineEdit::Password
       
   826             << events
       
   827             << QString("44")
       
   828             << QString("");
       
   829     events << FepReplayEvent(EStdKeyRightArrow, EKeyRightArrow, 0, 0);
       
   830     QTest::newRow("T9 with movement")
       
   831             << true
       
   832             << Qt::InputMethodHints(Qt::ImhPreferLowercase)
       
   833             << 0
       
   834             << QLineEdit::Normal
       
   835             << events
       
   836             << QString("you htvi")
       
   837             << QString("");
       
   838     QTest::newRow("T9 with movement and password")
       
   839             << true
       
   840             << Qt::InputMethodHints(Qt::ImhPreferLowercase)
       
   841             << 0
       
   842             << QLineEdit::Password
       
   843             << events
       
   844             << QString("wmt hu")
       
   845             << QString("");
       
   846     QTest::newRow("T9 with movement, maxlength and password")
       
   847             << true
       
   848             << Qt::InputMethodHints(Qt::ImhPreferLowercase)
       
   849             << 2
       
   850             << QLineEdit::Password
       
   851             << events
       
   852             << QString("wh")
       
   853             << QString("");
       
   854     QTest::newRow("Multitap with movement")
       
   855             << true
       
   856             << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase)
       
   857             << 0
       
   858             << QLineEdit::Normal
       
   859             << events
       
   860             << QString("wmt hu")
       
   861             << QString("");
       
   862     QTest::newRow("Multitap with movement and maxlength")
       
   863             << true
       
   864             << Qt::InputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhPreferLowercase)
       
   865             << 2
       
   866             << QLineEdit::Normal
       
   867             << events
       
   868             << QString("wh")
       
   869             << QString("");
       
   870     QTest::newRow("Numbers with movement and password")
       
   871             << true
       
   872             << Qt::InputMethodHints(Qt::ImhDigitsOnly)
       
   873             << 0
       
   874             << QLineEdit::Password
       
   875             << events
       
   876             << QString("96804488")
       
   877             << QString("");
       
   878     QTest::newRow("Numbers with movement, maxlength and password")
       
   879             << true
       
   880             << Qt::InputMethodHints(Qt::ImhDigitsOnly)
       
   881             << 2
       
   882             << QLineEdit::Password
       
   883             << events
       
   884             << QString("44")
       
   885             << QString("");
       
   886     events.clear();
       
   887 #endif
       
   888 }
       
   889 
       
   890 void tst_QInputContext::symbianTestCoeFepInputContext()
       
   891 {
       
   892 #ifndef Q_OS_SYMBIAN
       
   893     QSKIP("This is a Symbian-only test", SkipAll);
       
   894 #else
       
   895     QCoeFepInputContext *ic = qobject_cast<QCoeFepInputContext *>(qApp->inputContext());
       
   896     if (!ic) {
       
   897         QSKIP("coefep is not the active input context; skipping test", SkipAll);
       
   898     }
       
   899 
       
   900     QFETCH(bool,                  inputMethodEnabled);
       
   901     QFETCH(Qt::InputMethodHints,  inputMethodHints);
       
   902     QFETCH(int,                   maxLength);
       
   903     QFETCH(QLineEdit::EchoMode,   echoMode);
       
   904     QFETCH(QList<FepReplayEvent>, keyEvents);
       
   905     QFETCH(QString,               finalString);
       
   906     QFETCH(QString,               preeditString);
       
   907 
       
   908     if (inputMethodEnabled && m_phoneIsQwerty) {
       
   909         QSKIP("Skipping advanced input method tests on QWERTY phones", SkipSingle);
       
   910     }
       
   911 
       
   912     QWidget w;
       
   913     QLayout *layout = new QVBoxLayout;
       
   914     w.setLayout(layout);
       
   915     QLineEdit *lineedit = new QLineEdit;
       
   916     layout->addWidget(lineedit);
       
   917     lineedit->setFocus();
       
   918 #ifdef QT_KEYPAD_NAVIGATION
       
   919     lineedit->setEditFocus(true);
       
   920 #endif
       
   921     w.show();
       
   922 
       
   923     lineedit->setAttribute(Qt::WA_InputMethodEnabled, inputMethodEnabled);
       
   924     lineedit->setInputMethodHints(inputMethodHints);
       
   925     if (maxLength > 0)
       
   926         lineedit->setMaxLength(maxLength);
       
   927     lineedit->setEchoMode(echoMode);
       
   928 
       
   929     QTest::qWait(200);
       
   930 
       
   931     foreach(FepReplayEvent event, keyEvents) {
       
   932         event.replay(lineedit);
       
   933     }
       
   934 
       
   935     QApplication::processEvents();
       
   936 
       
   937     QCOMPARE(lineedit->text(), finalString);
       
   938     QCOMPARE(ic->m_preeditString, preeditString);
       
   939 #endif
       
   940 }
       
   941 
       
   942 void tst_QInputContext::symbianTestCoeFepAutoCommit_data()
       
   943 {
       
   944 #ifdef Q_OS_SYMBIAN
       
   945     QTest::addColumn<Qt::InputMethodHints>   ("inputMethodHints");
       
   946     QTest::addColumn<QLineEdit::EchoMode>    ("echoMode");
       
   947     QTest::addColumn<QList<FepReplayEvent> > ("keyEvents");
       
   948     QTest::addColumn<QString>                ("finalString");
       
   949 
       
   950     QList<FepReplayEvent> events;
       
   951 
       
   952     events << FepReplayEvent('4', '4', 0, 0);
       
   953     events << FepReplayEvent('4', '4', 0, 0);
       
   954     events << FepReplayEvent('0', '0', 0, 0);
       
   955     events << FepReplayEvent('9', '9', 0, 0);
       
   956     events << FepReplayEvent('6', '6', 0, 0);
       
   957     events << FepReplayEvent('8', '8', 0, 0);
       
   958     QTest::newRow("Numbers")
       
   959             << Qt::InputMethodHints(Qt::ImhDigitsOnly)
       
   960             << QLineEdit::Normal
       
   961             << events
       
   962             << QString("440968");
       
   963     QTest::newRow("Numbers and password")
       
   964             << Qt::InputMethodHints(Qt::ImhDigitsOnly)
       
   965             << QLineEdit::Password
       
   966             << events
       
   967             << QString("440968");
       
   968     QTest::newRow("Multitap")
       
   969             << Qt::InputMethodHints(Qt::ImhPreferLowercase | Qt::ImhNoPredictiveText)
       
   970             << QLineEdit::Normal
       
   971             << events
       
   972             << QString("h wmt");
       
   973     QTest::newRow("T9")
       
   974             << Qt::InputMethodHints(Qt::ImhPreferLowercase)
       
   975             << QLineEdit::Normal
       
   976             << events
       
   977             << QString("hi you");
       
   978     QTest::newRow("Multitap with password")
       
   979             << Qt::InputMethodHints(Qt::ImhPreferLowercase | Qt::ImhNoPredictiveText)
       
   980             << QLineEdit::Password
       
   981             << events
       
   982             << QString("h wmt");
       
   983     QTest::newRow("T9 with password")
       
   984             << Qt::InputMethodHints(Qt::ImhPreferLowercase)
       
   985             << QLineEdit::Password
       
   986             << events
       
   987             << QString("h wmt");
       
   988 #endif
       
   989 }
       
   990 
       
   991 void tst_QInputContext::symbianTestCoeFepAutoCommit()
       
   992 {
       
   993 #ifndef Q_OS_SYMBIAN
       
   994     QSKIP("This is a Symbian-only test", SkipAll);
       
   995 #else
       
   996     QCoeFepInputContext *ic = qobject_cast<QCoeFepInputContext *>(qApp->inputContext());
       
   997     if (!ic) {
       
   998         QSKIP("coefep is not the active input context; skipping test", SkipAll);
       
   999     }
       
  1000 
       
  1001     QFETCH(Qt::InputMethodHints,  inputMethodHints);
       
  1002     QFETCH(QLineEdit::EchoMode,   echoMode);
       
  1003     QFETCH(QList<FepReplayEvent>, keyEvents);
       
  1004     QFETCH(QString,               finalString);
       
  1005 
       
  1006     if (m_phoneIsQwerty) {
       
  1007         QSKIP("Skipping advanced input method tests on QWERTY phones", SkipSingle);
       
  1008     }
       
  1009 
       
  1010     QWidget w;
       
  1011     QLayout *layout = new QVBoxLayout;
       
  1012     w.setLayout(layout);
       
  1013     QLineEdit *lineedit = new QLineEdit;
       
  1014     layout->addWidget(lineedit);
       
  1015     lineedit->setFocus();
       
  1016 #ifdef QT_KEYPAD_NAVIGATION
       
  1017     lineedit->setEditFocus(true);
       
  1018 #endif
       
  1019     QPushButton *pushButton = new QPushButton("Done");
       
  1020     layout->addWidget(pushButton);
       
  1021     QAction softkey("Done", &w);
       
  1022     softkey.setSoftKeyRole(QAction::PositiveSoftKey);
       
  1023     w.addAction(&softkey);
       
  1024     w.show();
       
  1025 
       
  1026     lineedit->setInputMethodHints(inputMethodHints);
       
  1027     lineedit->setEchoMode(echoMode);
       
  1028 
       
  1029     QTest::qWait(200);
       
  1030     foreach(FepReplayEvent event, keyEvents) {
       
  1031         event.replay(lineedit);
       
  1032     }
       
  1033     QApplication::processEvents();
       
  1034 
       
  1035     QTest::mouseClick(pushButton, Qt::LeftButton);
       
  1036 
       
  1037     QCOMPARE(lineedit->text(), finalString);
       
  1038     QVERIFY(ic->m_preeditString.isEmpty());
       
  1039 
       
  1040 #ifdef Q_WS_S60
       
  1041     lineedit->inputContext()->reset();
       
  1042     lineedit->clear();
       
  1043     lineedit->setFocus();
       
  1044 #ifdef QT_KEYPAD_NAVIGATION
       
  1045     lineedit->setEditFocus(true);
       
  1046 #endif
       
  1047 
       
  1048     QTest::qWait(200);
       
  1049     foreach(FepReplayEvent event, keyEvents) {
       
  1050         event.replay(lineedit);
       
  1051     }
       
  1052     QApplication::processEvents();
       
  1053 
       
  1054     FepReplayEvent(EStdKeyDevice0, EKeyDevice0, 0, 0).replay(lineedit); // Left softkey
       
  1055 
       
  1056     QCOMPARE(lineedit->text(), finalString);
       
  1057     QVERIFY(ic->m_preeditString.isEmpty());
       
  1058 
       
  1059 #endif // Q_WS_S60
       
  1060 #endif // Q_OS_SYMBIAN
       
  1061 }
       
  1062 
   288 QTEST_MAIN(tst_QInputContext)
  1063 QTEST_MAIN(tst_QInputContext)
   289 #include "tst_qinputcontext.moc"
  1064 #include "tst_qinputcontext.moc"