aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2016-01-13 12:55:46 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2016-01-19 05:53:00 +0000
commitb923553bea186e5d50b94ee8875f4d5ff6f0446a (patch)
tree4389108bca6dc81bd20ccc61daa904a46a2fa805 /tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
parentf644f86c84287065535fbd8c3478a5b2550437ac (diff)
QQuickTextInput: added clear() method
Task-number: QTBUG-50428 Change-Id: I394c2cf1bc397dcbf6d82d3211a6b39519d7582b Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp')
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp51
1 files changed, 51 insertions, 0 deletions
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<QQuickTextInput*>(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<QInputMethodEvent::Attribute>());
+ 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.