From 8f555a824d30e754d0fa6c69ff0a6e2562224eab Mon Sep 17 00:00:00 2001 From: Samuel Nevala Date: Mon, 6 Jun 2011 09:29:06 +0300 Subject: [PATCH] TextInput autotest for QInputMethodEvent::Selection Task-number: QTBUG-XXXXX Reviewed-by: pending --- .../tst_qdeclarativetextinput.cpp | 40 ++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-) diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 19b7a76..d16c2c5 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -142,6 +142,7 @@ private slots: void inputContextMouseHandler(); void inputMethodComposing(); void cursorRectangleSize(); + void inputMethodSelection(); private: void simulateKey(QDeclarativeView *, int key); @@ -2741,6 +2742,45 @@ void tst_qdeclarativetextinput::cursorRectangleSize() QCOMPARE(microFocusFromApp.size(), cursorRect.size()); } +void tst_qdeclarativetextinput::inputMethodSelection() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/PositionAt.qml"); + QVERIFY(canvas->rootObject() != 0); + canvas->show(); + canvas->setFocus(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QDeclarativeTextInput *textInput = qobject_cast(canvas->rootObject()); + QVERIFY(textInput != 0); + textInput->setFocus(Qt::OtherFocusReason); + textInput->setProperty("text", "Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + textInput->select(0,0); + QSignalSpy selectionStartSpy(textInput, SIGNAL(selectionStartChanged())); + QSignalSpy selectionEndSpy(textInput, SIGNAL(selectionEndChanged())); + + QCOMPARE(selectionStartSpy.count(), 0); + QCOMPARE(selectionEndSpy.count(), 0); + QCOMPARE(textInput->property("selectionStart"), QVariant(0)); + QCOMPARE(textInput->property("selectionEnd"), QVariant(0)); + + textInput->select(0,5); + + QCOMPARE(selectionStartSpy.count(), 0); + QCOMPARE(selectionEndSpy.count(), 1); + QCOMPARE(textInput->property("selectionStart"), QVariant(0)); + QCOMPARE(textInput->property("selectionEnd"), QVariant(5)); + + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 12, 5, QVariant()); + QInputMethodEvent event("", attributes); + QApplication::sendEvent(canvas, &event); + + QCOMPARE(selectionStartSpy.count(), 1); + QCOMPARE(selectionEndSpy.count(), 2); + QCOMPARE(textInput->property("selectionStart"), QVariant(12)); + QCOMPARE(textInput->property("selectionEnd"), QVariant(17)); +} + QTEST_MAIN(tst_qdeclarativetextinput) #include "tst_qdeclarativetextinput.moc" -- 1.7.3.1.msysgit.0