aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-11-29 16:00:17 +0100
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2013-11-29 16:00:17 +0100
commit7c7665bbd6609d5c0ee7abd635e37c626b60802b (patch)
treecaf634b0df75f66a3812a0f839da3f0ad66d28ff /tests/auto
parent536e1cccf15963b586f3112a0654ddc0d101fa69 (diff)
parentdd1bd3b01b506a05b475514fb2ba7e387f7b17fa (diff)
Merge remote-tracking branch 'origin/stable' into dev
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp20
-rw-r--r--tests/auto/qml/qqmlecmascript/data/signalHandlers.qml34
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp7
-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.cpp238
6 files changed, 225 insertions, 102 deletions
diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp
index f2b82db630..929b079a51 100644
--- a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp
+++ b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp
@@ -418,22 +418,22 @@ void tst_QQmlProfilerService::pixmapCacheData()
QCOMPARE(m_client->traceMessages.first().detailType, (int)QQmlProfilerClient::StartTrace);
// image starting to load
- QCOMPARE(m_client->traceMessages[8].messageType, (int)QQmlProfilerClient::PixmapCacheEvent);
- QCOMPARE(m_client->traceMessages[8].detailType, (int)QQmlProfilerClient::PixmapLoadingStarted);
+ QCOMPARE(m_client->traceMessages[16].messageType, (int)QQmlProfilerClient::PixmapCacheEvent);
+ QCOMPARE(m_client->traceMessages[16].detailType, (int)QQmlProfilerClient::PixmapLoadingStarted);
// image loaded
- QCOMPARE(m_client->traceMessages[9].messageType, (int)QQmlProfilerClient::PixmapCacheEvent);
- QCOMPARE(m_client->traceMessages[9].detailType, (int)QQmlProfilerClient::PixmapLoadingFinished);
+ QCOMPARE(m_client->traceMessages[17].messageType, (int)QQmlProfilerClient::PixmapCacheEvent);
+ QCOMPARE(m_client->traceMessages[17].detailType, (int)QQmlProfilerClient::PixmapLoadingFinished);
// image size
- QCOMPARE(m_client->traceMessages[10].messageType, (int)QQmlProfilerClient::PixmapCacheEvent);
- QCOMPARE(m_client->traceMessages[10].detailType, (int)QQmlProfilerClient::PixmapSizeKnown);
- QCOMPARE(m_client->traceMessages[10].line, 2); // width
- QCOMPARE(m_client->traceMessages[10].column, 2); // height
+ QCOMPARE(m_client->traceMessages[18].messageType, (int)QQmlProfilerClient::PixmapCacheEvent);
+ QCOMPARE(m_client->traceMessages[18].detailType, (int)QQmlProfilerClient::PixmapSizeKnown);
+ QCOMPARE(m_client->traceMessages[18].line, 2); // width
+ QCOMPARE(m_client->traceMessages[18].column, 2); // height
// cache size
- QCOMPARE(m_client->traceMessages[11].messageType, (int)QQmlProfilerClient::PixmapCacheEvent);
- QCOMPARE(m_client->traceMessages[11].detailType, (int)QQmlProfilerClient::PixmapCacheCountChanged);
+ QCOMPARE(m_client->traceMessages[19].messageType, (int)QQmlProfilerClient::PixmapCacheEvent);
+ QCOMPARE(m_client->traceMessages[19].detailType, (int)QQmlProfilerClient::PixmapCacheCountChanged);
// must end with "EndTrace"
QCOMPARE(m_client->traceMessages.last().messageType, (int)QQmlProfilerClient::Event);
diff --git a/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml
index 975be1b2ad..7e85312692 100644
--- a/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml
+++ b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml
@@ -57,4 +57,38 @@ QtObject {
if (onTestSignal !== undefined)
definedHandlerResult = true;
}
+
+ property QtObject objWithAlias: QtObject {
+ id: testObjectWithAlias
+
+ property int count: 0;
+ property alias countAlias: testObjectWithAlias.count
+ }
+
+ function testConnectionOnAlias() {
+ var called = false;
+
+ testObjectWithAlias.onCountAliasChanged.connect(function() {
+ called = true
+ })
+
+ testObjectWithAlias.count++;
+ return called;
+ }
+
+ property QtObject objWithAliasHandler: QtObject {
+ id: testObjectWithAliasHandler
+
+ property bool testSuccess: false
+
+ property int count: 0
+ property alias countAlias: testObjectWithAliasHandler.count
+ onCountAliasChanged: testSuccess = true
+ }
+
+ function testAliasSignalHandler() {
+ testObjectWithAliasHandler.testSuccess = false
+ testObjectWithAliasHandler.count++
+ return testObjectWithAliasHandler.testSuccess
+ }
}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 6b19c13109..660be13f71 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -6060,6 +6060,13 @@ void tst_qqmlecmascript::signalHandlers()
QMetaObject::invokeMethod(o, "testSignalHandlerDefined");
QCOMPARE(o->property("definedHandlerResult").toBool(), true);
+ QVariant result;
+ QMetaObject::invokeMethod(o, "testConnectionOnAlias", Q_RETURN_ARG(QVariant, result));
+ QCOMPARE(result.toBool(), true);
+
+ QMetaObject::invokeMethod(o, "testAliasSignalHandler", Q_RETURN_ARG(QVariant, result));
+ QCOMPARE(result.toBool(), true);
+
delete o;
}
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 80726720e4..697dba182c 100644
--- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
+++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
@@ -49,6 +49,7 @@
#include <QtQuick/qquickview.h>
#include <QtGui/qguiapplication.h>
#include <QtGui/qstylehints.h>
+#include <QtGui/qvalidator.h>
#include <QInputMethod>
#include <private/qquicktextinput_p.h>
#include <private/qquicktextinput_p_p.h>
@@ -146,6 +147,7 @@ private slots:
void validators();
void inputMethods();
+ void signal_accepted();
void signal_editingfinished();
void passwordCharacter();
@@ -226,6 +228,7 @@ private slots:
void hasAcceptableInputMask();
void maskCharacter_data();
void maskCharacter();
+ void fixup();
private:
void simulateKey(QWindow *, int key);
@@ -1271,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;
@@ -1282,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()
@@ -1337,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 {
@@ -1873,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);
}
}
@@ -1900,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);
}
}
@@ -1944,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);
@@ -2019,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);
@@ -2106,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);
@@ -2173,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);
@@ -2223,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);
@@ -2305,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"));
@@ -2318,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());
@@ -2327,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());
@@ -2341,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);
}
/*
@@ -6296,6 +6326,38 @@ void tst_qquicktextinput::maskCharacter()
}
}
+class TestValidator : public QValidator
+{
+public:
+ TestValidator(QObject *parent = 0) : QValidator(parent) { }
+
+ State validate(QString &input, int &) const { return input == QStringLiteral("ok") ? Acceptable : Intermediate; }
+ void fixup(QString &input) const { input = QStringLiteral("ok"); }
+};
+
+void tst_qquicktextinput::fixup()
+{
+ QQuickWindow window;
+ window.show();
+ window.requestActivate();
+ QTest::qWaitForWindowActive(&window);
+
+ QQuickTextInput *input = new QQuickTextInput(window.contentItem());
+ input->setValidator(new TestValidator(input));
+
+ // fixup() on accept
+ input->setFocus(true);
+ QVERIFY(input->hasActiveFocus());
+ QTest::keyClick(&window, Qt::Key_Enter);
+ QCOMPARE(input->text(), QStringLiteral("ok"));
+
+ // fixup() on defocus
+ input->setText(QString());
+ input->setFocus(false);
+ QVERIFY(!input->hasActiveFocus());
+ QCOMPARE(input->text(), QStringLiteral("ok"));
+}
+
QTEST_MAIN(tst_qquicktextinput)
#include "tst_qquicktextinput.moc"