tests/auto/qinputcontext/tst_qinputcontext.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 0 1918ee327afb
child 37 758a864f9613
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the test suite of the Qt Toolkit.
     7 ** This file is part of the test suite of the Qt Toolkit.
     8 **
     8 **
    66     void maximumTextLength();
    66     void maximumTextLength();
    67     void filterMouseEvents();
    67     void filterMouseEvents();
    68     void requestSoftwareInputPanel();
    68     void requestSoftwareInputPanel();
    69     void closeSoftwareInputPanel();
    69     void closeSoftwareInputPanel();
    70     void selections();
    70     void selections();
       
    71     void focusProxy();
    71 };
    72 };
    72 
    73 
    73 void tst_QInputContext::maximumTextLength()
    74 void tst_QInputContext::maximumTextLength()
    74 {
    75 {
    75     QLineEdit le;
    76     QLineEdit le;
   246     QCOMPARE(le.selectionStart(), 5);
   247     QCOMPARE(le.selectionStart(), 5);
   247     QCOMPARE(le.inputMethodQuery(Qt::ImCursorPosition).toInt(), 8);
   248     QCOMPARE(le.inputMethodQuery(Qt::ImCursorPosition).toInt(), 8);
   248     QCOMPARE(le.inputMethodQuery(Qt::ImAnchorPosition).toInt(), 5);
   249     QCOMPARE(le.inputMethodQuery(Qt::ImAnchorPosition).toInt(), 5);
   249 }
   250 }
   250 
   251 
       
   252 void tst_QInputContext::focusProxy()
       
   253 {
       
   254     QWidget toplevel(0, Qt::X11BypassWindowManagerHint); toplevel.setObjectName("toplevel");
       
   255     QWidget w(&toplevel); w.setObjectName("w");
       
   256     QWidget proxy(&w); proxy.setObjectName("proxy");
       
   257     QWidget proxy2(&w); proxy2.setObjectName("proxy2");
       
   258     w.setFocusProxy(&proxy);
       
   259     w.setAttribute(Qt::WA_InputMethodEnabled);
       
   260     toplevel.show();
       
   261     QApplication::setActiveWindow(&toplevel);
       
   262     QTest::qWaitForWindowShown(&toplevel);
       
   263     w.setFocus();
       
   264     w.setAttribute(Qt::WA_NativeWindow); // we shouldn't crash!
       
   265 
       
   266     proxy.setAttribute(Qt::WA_InputMethodEnabled);
       
   267     proxy2.setAttribute(Qt::WA_InputMethodEnabled);
       
   268 
       
   269     proxy2.setFocus();
       
   270     w.setFocus();
       
   271 
       
   272     QInputContext *gic = qApp->inputContext();
       
   273     QVERIFY(gic);
       
   274     qDebug() << gic->focusWidget() << &proxy;
       
   275     QCOMPARE(gic->focusWidget(), &proxy);
       
   276 
       
   277     // then change the focus proxy and check that input context is valid
       
   278     QVERIFY(w.hasFocus());
       
   279     QVERIFY(proxy.hasFocus());
       
   280     QVERIFY(!proxy2.hasFocus());
       
   281     w.setFocusProxy(&proxy2);
       
   282     QVERIFY(!w.hasFocus());
       
   283     QVERIFY(proxy.hasFocus());
       
   284     QVERIFY(!proxy2.hasFocus());
       
   285     QCOMPARE(gic->focusWidget(), &proxy);
       
   286 }
       
   287 
   251 QTEST_MAIN(tst_QInputContext)
   288 QTEST_MAIN(tst_QInputContext)
   252 #include "tst_qinputcontext.moc"
   289 #include "tst_qinputcontext.moc"