From b923553bea186e5d50b94ee8875f4d5ff6f0446a Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Wed, 13 Jan 2016 12:55:46 +0100 Subject: QQuickTextInput: added clear() method Task-number: QTBUG-50428 Change-Id: I394c2cf1bc397dcbf6d82d3211a6b39519d7582b Reviewed-by: J-P Nurmi --- .../quick/qquicktextinput/tst_qquicktextinput.cpp | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp') diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 1e5b7b3848..ecaf0975a9 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -192,6 +192,7 @@ private slots: void redo(); void undo_keypressevents_data(); void undo_keypressevents(); + void clear(); void backspaceSurrogatePairs(); @@ -5724,6 +5725,56 @@ void tst_qquicktextinput::undo_keypressevents() QVERIFY(textInput->text().isEmpty()); } +void tst_qquicktextinput::clear() +{ + QString componentStr = "import QtQuick 2.0\nTextInput { focus: true }"; + QQmlComponent textInputComponent(&engine); + textInputComponent.setData(componentStr.toLatin1(), QUrl()); + QQuickTextInput *textInput = qobject_cast(textInputComponent.create()); + QVERIFY(textInput != 0); + + QQuickWindow window; + textInput->setParentItem(window.contentItem()); + window.show(); + window.requestActivate(); + QTest::qWaitForWindowActive(&window); + QVERIFY(textInput->hasActiveFocus()); + QVERIFY(!textInput->canUndo()); + + QSignalSpy spy(textInput, SIGNAL(canUndoChanged())); + + textInput->setText("I am Legend"); + QCOMPARE(textInput->text(), QString("I am Legend")); + textInput->clear(); + QVERIFY(textInput->text().isEmpty()); + + QCOMPARE(spy.count(), 1); + + // checks that clears can be undone + textInput->undo(); + QVERIFY(!textInput->canUndo()); + QCOMPARE(spy.count(), 2); + QCOMPARE(textInput->text(), QString("I am Legend")); + + textInput->setCursorPosition(4); + QInputMethodEvent preeditEvent("PREEDIT", QList()); + QGuiApplication::sendEvent(textInput, &preeditEvent); + QCOMPARE(textInput->text(), QString("I am Legend")); + QCOMPARE(textInput->displayText(), QString("I amPREEDIT Legend")); + QCOMPARE(textInput->preeditText(), QString("PREEDIT")); + + textInput->clear(); + QVERIFY(textInput->text().isEmpty()); + + QCOMPARE(spy.count(), 3); + + // checks that clears can be undone + textInput->undo(); + QVERIFY(!textInput->canUndo()); + QCOMPARE(spy.count(), 4); + QCOMPARE(textInput->text(), QString("I am Legend")); +} + void tst_qquicktextinput::backspaceSurrogatePairs() { // Test backspace, and delete remove both characters in a surrogate pair. -- cgit v1.2.3