aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@digia.com>2013-11-21 11:06:24 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-28 09:34:28 +0100
commit140400be0f8a8c91ce02ad5691d81d7604e5a4db (patch)
tree036bd1e1d9145ee275a9b2b5c8fc14e6c7354103 /tests
parent956ee62cc24c76569ac49ab209f5f889899c53d6 (diff)
tests: update tst_qquicktextinput
* add signal_accepted() with validator * update signal_editingfinished() with validator * cleanup many qWait() and etc Change-Id: Ic0a8f1cdc4f1f811501c06513efff9b6217fc749 Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktextinput/data/signal_accepted.qml14
-rw-r--r--tests/auto/quick/qquicktextinput/data/signal_editingfinished.qml14
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp204
3 files changed, 140 insertions, 92 deletions
diff --git a/tests/auto/quick/qquicktextinput/data/signal_accepted.qml b/tests/auto/quick/qquicktextinput/data/signal_accepted.qml
new file mode 100644
index 0000000000..94c113dd9f
--- /dev/null
+++ b/tests/auto/quick/qquicktextinput/data/signal_accepted.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.2
+
+Item {
+ property QtObject input: input
+
+ width: 800; height: 600;
+
+ Column{
+ TextInput { id: input;
+ property bool acceptable: acceptableInput
+ validator: RegExpValidator { regExp: /[a-zA-z]{2,4}/ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicktextinput/data/signal_editingfinished.qml b/tests/auto/quick/qquicktextinput/data/signal_editingfinished.qml
index 2ec5ce6676..dba186e765 100644
--- a/tests/auto/quick/qquicktextinput/data/signal_editingfinished.qml
+++ b/tests/auto/quick/qquicktextinput/data/signal_editingfinished.qml
@@ -1,13 +1,19 @@
import QtQuick 2.2
Item {
- property variant input1: input1
- property variant input2: input2
+ property QtObject input1: input1
+ property QtObject input2: input2
width: 800; height: 600;
Column{
- TextInput { id: input1; }
- TextInput { id: input2; }
+ TextInput { id: input1;
+ property bool acceptable: acceptableInput
+ validator: RegExpValidator { regExp: /[a-zA-z]{2,4}/ }
+ }
+ TextInput { id: input2;
+ property bool acceptable: acceptableInput
+ validator: RegExpValidator { regExp: /[a-zA-z]{2,4}/ }
+ }
}
}
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
index b322e1c576..697dba182c 100644
--- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
+++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
@@ -147,6 +147,7 @@ private slots:
void validators();
void inputMethods();
+ void signal_accepted();
void signal_editingfinished();
void passwordCharacter();
@@ -1273,10 +1274,9 @@ void tst_qquicktextinput::dragMouseSelection()
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(x1,y));
QTest::mouseMove(&window, QPoint(x2, y));
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(x2,y));
- QTest::qWait(100);
QString str1;
- QVERIFY((str1 = textInputObject->selectedText()).length() > 3);
- QVERIFY(str1.length() > 3);
+ QTRY_VERIFY((str1 = textInputObject->selectedText()).length() > 3);
+ QTRY_VERIFY(str1.length() > 3);
// press and drag the current selection.
x1 = 40;
@@ -1284,11 +1284,10 @@ void tst_qquicktextinput::dragMouseSelection()
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(x1,y));
QTest::mouseMove(&window, QPoint(x2, y));
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(x2,y));
- QTest::qWait(300);
QString str2 = textInputObject->selectedText();
- QVERIFY(str2.length() > 3);
+ QTRY_VERIFY(str2.length() > 3);
- QVERIFY(str1 != str2);
+ QTRY_VERIFY(str1 != str2);
}
void tst_qquicktextinput::mouseSelectionMode_data()
@@ -1339,7 +1338,6 @@ void tst_qquicktextinput::mouseSelectionMode()
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(x1,y));
QTest::mouseMove(&window, QPoint(x2,y)); // doesn't work
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(x2,y));
- QTest::qWait(300);
if (selectWords) {
QTRY_COMPARE(textInputObject->selectedText(), text);
} else {
@@ -1875,8 +1873,7 @@ void tst_qquicktextinput::maxLength()
QTRY_COMPARE(textinputObject->text().length(), qMin(i,10));
//simulateKey(&window, Qt::Key_A);
QTest::keyPress(&window, Qt::Key_A);
- QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
}
}
@@ -1902,8 +1899,7 @@ void tst_qquicktextinput::masks()
QCOMPARE(i>=4, textinputObject->hasAcceptableInput());
//simulateKey(&window, Qt::Key_A);
QTest::keyPress(&window, Qt::Key_A);
- QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
}
}
@@ -1946,56 +1942,47 @@ void tst_qquicktextinput::validators()
QCOMPARE(intInput->hasAcceptableInput(), false);
QCOMPARE(intInput->property("acceptable").toBool(), false);
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QTRY_COMPARE(intInput->text(), QLatin1String("1"));
QCOMPARE(intInput->hasAcceptableInput(), false);
QCOMPARE(intInput->property("acceptable").toBool(), false);
QCOMPARE(intSpy.count(), 0);
QTest::keyPress(&window, Qt::Key_2);
- QTest::keyRelease(&window, Qt::Key_2, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_2, Qt::NoModifier);
QTRY_COMPARE(intInput->text(), QLatin1String("1"));
QCOMPARE(intInput->hasAcceptableInput(), false);
QCOMPARE(intInput->property("acceptable").toBool(), false);
QCOMPARE(intSpy.count(), 0);
QTest::keyPress(&window, Qt::Key_Period);
- QTest::keyRelease(&window, Qt::Key_Period, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Period, Qt::NoModifier);
QTRY_COMPARE(intInput->text(), QLatin1String("1"));
QCOMPARE(intInput->hasAcceptableInput(), false);
QTest::keyPress(&window, Qt::Key_Comma);
- QTest::keyRelease(&window, Qt::Key_Comma, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Comma, Qt::NoModifier);
QTRY_COMPARE(intInput->text(), QLatin1String("1,"));
QCOMPARE(intInput->hasAcceptableInput(), false);
QTest::keyPress(&window, Qt::Key_Backspace);
- QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier);
QTRY_COMPARE(intInput->text(), QLatin1String("1"));
QCOMPARE(intInput->hasAcceptableInput(), false);
intValidator->setLocaleName(deLocale.name());
QTest::keyPress(&window, Qt::Key_Period);
- QTest::keyRelease(&window, Qt::Key_Period, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Period, Qt::NoModifier);
QTRY_COMPARE(intInput->text(), QLatin1String("1."));
QCOMPARE(intInput->hasAcceptableInput(), false);
QTest::keyPress(&window, Qt::Key_Backspace);
- QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier);
QTRY_COMPARE(intInput->text(), QLatin1String("1"));
QCOMPARE(intInput->hasAcceptableInput(), false);
intValidator->resetLocaleName();
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QCOMPARE(intInput->text(), QLatin1String("11"));
QCOMPARE(intInput->hasAcceptableInput(), true);
QCOMPARE(intInput->property("acceptable").toBool(), true);
QCOMPARE(intSpy.count(), 1);
QTest::keyPress(&window, Qt::Key_0);
- QTest::keyRelease(&window, Qt::Key_0, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_0, Qt::NoModifier);
QCOMPARE(intInput->text(), QLatin1String("11"));
QCOMPARE(intInput->hasAcceptableInput(), true);
QCOMPARE(intInput->property("acceptable").toBool(), true);
@@ -2021,81 +2008,68 @@ void tst_qquicktextinput::validators()
QCOMPARE(dblInput->hasAcceptableInput(), false);
QCOMPARE(dblInput->property("acceptable").toBool(), false);
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("1"));
QCOMPARE(dblInput->hasAcceptableInput(), false);
QCOMPARE(dblInput->property("acceptable").toBool(), false);
QCOMPARE(dblSpy.count(), 0);
QTest::keyPress(&window, Qt::Key_2);
- QTest::keyRelease(&window, Qt::Key_2, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_2, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12"));
QCOMPARE(dblInput->hasAcceptableInput(), true);
QCOMPARE(dblInput->property("acceptable").toBool(), true);
QCOMPARE(dblSpy.count(), 1);
QTest::keyPress(&window, Qt::Key_Comma);
- QTest::keyRelease(&window, Qt::Key_Comma, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Comma, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12,"));
QCOMPARE(dblInput->hasAcceptableInput(), true);
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12,"));
QCOMPARE(dblInput->hasAcceptableInput(), true);
dblValidator->setLocaleName(deLocale.name());
QCOMPARE(dblInput->hasAcceptableInput(), true);
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12,1"));
QCOMPARE(dblInput->hasAcceptableInput(), true);
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12,11"));
QCOMPARE(dblInput->hasAcceptableInput(), true);
QTest::keyPress(&window, Qt::Key_Backspace);
- QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12,1"));
QCOMPARE(dblInput->hasAcceptableInput(), true);
QTest::keyPress(&window, Qt::Key_Backspace);
- QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12,"));
QCOMPARE(dblInput->hasAcceptableInput(), true);
QTest::keyPress(&window, Qt::Key_Backspace);
- QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12"));
QCOMPARE(dblInput->hasAcceptableInput(), true);
dblValidator->resetLocaleName();
QTest::keyPress(&window, Qt::Key_Period);
- QTest::keyRelease(&window, Qt::Key_Period, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Period, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12."));
QCOMPARE(dblInput->hasAcceptableInput(), true);
QCOMPARE(dblInput->property("acceptable").toBool(), true);
QCOMPARE(dblSpy.count(), 1);
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12.1"));
QCOMPARE(dblInput->hasAcceptableInput(), true);
QCOMPARE(dblInput->property("acceptable").toBool(), true);
QCOMPARE(dblSpy.count(), 1);
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12.11"));
QCOMPARE(dblInput->hasAcceptableInput(), true);
QCOMPARE(dblInput->property("acceptable").toBool(), true);
QCOMPARE(dblSpy.count(), 1);
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12.11"));
QCOMPARE(dblInput->hasAcceptableInput(), true);
QCOMPARE(dblInput->property("acceptable").toBool(), true);
@@ -2108,50 +2082,43 @@ void tst_qquicktextinput::validators()
QCOMPARE(dblInput->property("acceptable").toBool(), false);
QCOMPARE(dblSpy.count(), 2);
QTest::keyPress(&window, Qt::Key_Backspace);
- QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12.1"));
QCOMPARE(dblInput->hasAcceptableInput(), false);
QCOMPARE(dblInput->property("acceptable").toBool(), false);
QCOMPARE(dblSpy.count(), 2);
// Once unacceptable input is in anything goes until it reaches an acceptable state again.
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12.11"));
QCOMPARE(dblInput->hasAcceptableInput(), false);
QCOMPARE(dblSpy.count(), 2);
QTest::keyPress(&window, Qt::Key_Backspace);
- QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12.1"));
QCOMPARE(dblInput->hasAcceptableInput(), false);
QCOMPARE(dblInput->property("acceptable").toBool(), false);
QCOMPARE(dblSpy.count(), 2);
QTest::keyPress(&window, Qt::Key_Backspace);
- QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12."));
QCOMPARE(dblInput->hasAcceptableInput(), false);
QCOMPARE(dblInput->property("acceptable").toBool(), false);
QCOMPARE(dblSpy.count(), 2);
QTest::keyPress(&window, Qt::Key_Backspace);
- QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("12"));
QCOMPARE(dblInput->hasAcceptableInput(), false);
QCOMPARE(dblInput->property("acceptable").toBool(), false);
QCOMPARE(dblSpy.count(), 2);
QTest::keyPress(&window, Qt::Key_Backspace);
- QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier);
QTRY_COMPARE(dblInput->text(), QLatin1String("1"));
QCOMPARE(dblInput->hasAcceptableInput(), false);
QCOMPARE(dblInput->property("acceptable").toBool(), false);
QCOMPARE(dblSpy.count(), 2);
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QCOMPARE(dblInput->text(), QLatin1String("11"));
QCOMPARE(dblInput->property("acceptable").toBool(), true);
QCOMPARE(dblInput->hasAcceptableInput(), true);
@@ -2175,43 +2142,37 @@ void tst_qquicktextinput::validators()
QCOMPARE(strInput->hasAcceptableInput(), false);
QCOMPARE(strInput->property("acceptable").toBool(), false);
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QTRY_COMPARE(strInput->text(), QLatin1String(""));
QCOMPARE(strInput->hasAcceptableInput(), false);
QCOMPARE(strInput->property("acceptable").toBool(), false);
QCOMPARE(strSpy.count(), 0);
QTest::keyPress(&window, Qt::Key_A);
- QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
QTRY_COMPARE(strInput->text(), QLatin1String("a"));
QCOMPARE(strInput->hasAcceptableInput(), false);
QCOMPARE(strInput->property("acceptable").toBool(), false);
QCOMPARE(strSpy.count(), 0);
QTest::keyPress(&window, Qt::Key_A);
- QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
QTRY_COMPARE(strInput->text(), QLatin1String("aa"));
QCOMPARE(strInput->hasAcceptableInput(), true);
QCOMPARE(strInput->property("acceptable").toBool(), true);
QCOMPARE(strSpy.count(), 1);
QTest::keyPress(&window, Qt::Key_A);
- QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
QTRY_COMPARE(strInput->text(), QLatin1String("aaa"));
QCOMPARE(strInput->hasAcceptableInput(), true);
QCOMPARE(strInput->property("acceptable").toBool(), true);
QCOMPARE(strSpy.count(), 1);
QTest::keyPress(&window, Qt::Key_A);
- QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
QTRY_COMPARE(strInput->text(), QLatin1String("aaaa"));
QCOMPARE(strInput->hasAcceptableInput(), true);
QCOMPARE(strInput->property("acceptable").toBool(), true);
QCOMPARE(strSpy.count(), 1);
QTest::keyPress(&window, Qt::Key_A);
- QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
QTRY_COMPARE(strInput->text(), QLatin1String("aaaa"));
QCOMPARE(strInput->hasAcceptableInput(), true);
QCOMPARE(strInput->property("acceptable").toBool(), true);
@@ -2225,15 +2186,13 @@ void tst_qquicktextinput::validators()
QCOMPARE(unvalidatedInput->hasAcceptableInput(), true);
QCOMPARE(unvalidatedInput->property("acceptable").toBool(), true);
QTest::keyPress(&window, Qt::Key_1);
- QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier);
QTRY_COMPARE(unvalidatedInput->text(), QLatin1String("1"));
QCOMPARE(unvalidatedInput->hasAcceptableInput(), true);
QCOMPARE(unvalidatedInput->property("acceptable").toBool(), true);
QCOMPARE(unvalidatedSpy.count(), 0);
QTest::keyPress(&window, Qt::Key_A);
- QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier ,10);
- QTest::qWait(50);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
QTRY_COMPARE(unvalidatedInput->text(), QLatin1String("1a"));
QCOMPARE(unvalidatedInput->hasAcceptableInput(), true);
QCOMPARE(unvalidatedInput->property("acceptable").toBool(), true);
@@ -2307,6 +2266,48 @@ void tst_qquicktextinput::inputMethods()
QCOMPARE(enabledQueryEvent.value(Qt::ImEnabled).toBool(), false);
}
+void tst_qquicktextinput::signal_accepted()
+{
+ QQuickView window(testFileUrl("signal_accepted.qml"));
+ window.show();
+ window.requestActivate();
+ QTest::qWaitForWindowActive(&window);
+
+ QVERIFY(window.rootObject() != 0);
+
+ QQuickTextInput *input = qobject_cast<QQuickTextInput *>(qvariant_cast<QObject *>(window.rootObject()->property("input")));
+ QVERIFY(input);
+ QSignalSpy acceptedSpy(input, SIGNAL(accepted()));
+ QSignalSpy inputSpy(input, SIGNAL(acceptableInputChanged()));
+
+ input->setFocus(true);
+ QTRY_VERIFY(input->hasActiveFocus());
+ QCOMPARE(input->hasAcceptableInput(), false);
+ QCOMPARE(input->property("acceptable").toBool(), false);
+
+ QTest::keyPress(&window, Qt::Key_A);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
+ QTRY_COMPARE(input->text(), QLatin1String("a"));
+ QCOMPARE(input->hasAcceptableInput(), false);
+ QCOMPARE(input->property("acceptable").toBool(), false);
+ QTRY_COMPARE(inputSpy.count(), 0);
+
+ QTest::keyPress(&window, Qt::Key_Enter);
+ QTest::keyRelease(&window, Qt::Key_Enter, Qt::NoModifier);
+ QTRY_COMPARE(acceptedSpy.count(), 0);
+
+ QTest::keyPress(&window, Qt::Key_A);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
+ QTRY_COMPARE(input->text(), QLatin1String("aa"));
+ QCOMPARE(input->hasAcceptableInput(), true);
+ QCOMPARE(input->property("acceptable").toBool(), true);
+ QTRY_COMPARE(inputSpy.count(), 1);
+
+ QTest::keyPress(&window, Qt::Key_Enter);
+ QTest::keyRelease(&window, Qt::Key_Enter, Qt::NoModifier);
+ QTRY_COMPARE(acceptedSpy.count(), 1);
+}
+
void tst_qquicktextinput::signal_editingfinished()
{
QQuickView window(testFileUrl("signal_editingfinished.qml"));
@@ -2320,7 +2321,8 @@ void tst_qquicktextinput::signal_editingfinished()
QVERIFY(input1);
QQuickTextInput *input2 = qobject_cast<QQuickTextInput *>(qvariant_cast<QObject *>(window.rootObject()->property("input2")));
QVERIFY(input2);
- QSignalSpy input1Spy(input1, SIGNAL(editingFinished()));
+ QSignalSpy editingFinished1Spy(input1, SIGNAL(editingFinished()));
+ QSignalSpy input1Spy(input1, SIGNAL(acceptableInputChanged()));
input1->setFocus(true);
QTRY_VERIFY(input1->hasActiveFocus());
@@ -2329,12 +2331,28 @@ void tst_qquicktextinput::signal_editingfinished()
QTest::keyPress(&window, Qt::Key_A);
QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
QTRY_COMPARE(input1->text(), QLatin1String("a"));
+ QCOMPARE(input1->hasAcceptableInput(), false);
+ QCOMPARE(input1->property("acceptable").toBool(), false);
+ QTRY_COMPARE(input1Spy.count(), 0);
QTest::keyPress(&window, Qt::Key_Enter);
QTest::keyRelease(&window, Qt::Key_Enter, Qt::NoModifier);
+ QTRY_COMPARE(editingFinished1Spy.count(), 0);
+
+ QTest::keyPress(&window, Qt::Key_A);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
+ QTRY_COMPARE(input1->text(), QLatin1String("aa"));
+ QCOMPARE(input1->hasAcceptableInput(), true);
+ QCOMPARE(input1->property("acceptable").toBool(), true);
+ QTRY_COMPARE(input1Spy.count(), 1);
+
+ QTest::keyPress(&window, Qt::Key_Enter);
+ QTest::keyRelease(&window, Qt::Key_Enter, Qt::NoModifier);
+ QTRY_COMPARE(editingFinished1Spy.count(), 1);
QTRY_COMPARE(input1Spy.count(), 1);
- QSignalSpy input2Spy(input2, SIGNAL(editingFinished()));
+ QSignalSpy editingFinished2Spy(input2, SIGNAL(editingFinished()));
+ QSignalSpy input2Spy(input2, SIGNAL(acceptableInputChanged()));
input2->setFocus(true);
QTRY_VERIFY(!input1->hasActiveFocus());
@@ -2343,11 +2361,21 @@ void tst_qquicktextinput::signal_editingfinished()
QTest::keyPress(&window, Qt::Key_A);
QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
QTRY_COMPARE(input2->text(), QLatin1String("a"));
+ QCOMPARE(input2->hasAcceptableInput(), false);
+ QCOMPARE(input2->property("acceptable").toBool(), false);
+ QTRY_COMPARE(input2Spy.count(), 0);
+
+ QTest::keyPress(&window, Qt::Key_A);
+ QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier);
+ QTRY_COMPARE(input2->text(), QLatin1String("aa"));
+ QCOMPARE(input2->hasAcceptableInput(), true);
+ QCOMPARE(input2->property("acceptable").toBool(), true);
+ QTRY_COMPARE(input2Spy.count(), 1);
input1->setFocus(true);
QTRY_VERIFY(input1->hasActiveFocus());
QTRY_VERIFY(!input2->hasActiveFocus());
- QTRY_COMPARE(input2Spy.count(), 1);
+ QTRY_COMPARE(editingFinished2Spy.count(), 1);
}
/*