diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2010-02-08 15:09:00 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2010-02-08 15:09:00 (GMT) |
commit | a764c32ee5cab4b40a0ce6807e1e7c3efcc7bdc8 (patch) | |
tree | d863b90b7ca56df159593d2a74c35000097491df /tests/auto/declarative/qmlgraphicstextinput | |
parent | 3e8e1b369752d8a0b42f088f577f3d33eb29f8a9 (diff) | |
download | Qt-a764c32ee5cab4b40a0ce6807e1e7c3efcc7bdc8.zip Qt-a764c32ee5cab4b40a0ce6807e1e7c3efcc7bdc8.tar.gz Qt-a764c32ee5cab4b40a0ce6807e1e7c3efcc7bdc8.tar.bz2 |
Support the other validators
Note that a resolution will be required for QTBUG-8025 before the
QRegExpValidator is useful.
Task-number: QTBUG-7068
Diffstat (limited to 'tests/auto/declarative/qmlgraphicstextinput')
-rw-r--r-- | tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp | 95 |
1 files changed, 89 insertions, 6 deletions
diff --git a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp index 7223ff9..7896464 100644 --- a/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp +++ b/tests/auto/declarative/qmlgraphicstextinput/tst_qmlgraphicstextinput.cpp @@ -397,13 +397,96 @@ void tst_qmlgraphicstextinput::masks() void tst_qmlgraphicstextinput::validators() { - QString componentStr = "import Qt 4.6\nTextInput { maximumLength: 10; }"; - QmlComponent textinputComponent(&engine); - textinputComponent.setData(componentStr.toLatin1(), QUrl()); - QmlGraphicsTextInput *textinputObject = qobject_cast<QmlGraphicsTextInput*>(textinputComponent.create()); - QVERIFY(textinputObject != 0); + // Note that this test assumes that the validators are working properly + // so you may need to run their tests first. All validators are checked + // here to ensure that their exposure to QML is working. + + QmlView *canvas = createView(SRCDIR "/data/validators.qml"); + canvas->execute(); + canvas->show(); + canvas->setFocus(); + + QVERIFY(canvas->root() != 0); - //TODO: Me + QmlGraphicsTextInput *intInput = qobject_cast<QmlGraphicsTextInput *>(qvariant_cast<QObject *>(canvas->root()->property("intInput"))); + QVERIFY(intInput); + intInput->setFocus(true); + QTRY_VERIFY(intInput->hasFocus()); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(intInput->text(), QLatin1String("1")); + QCOMPARE(intInput->hasAcceptableInput(), false); + QTest::keyPress(canvas, Qt::Key_2); + QTest::keyRelease(canvas, Qt::Key_2, Qt::NoModifier ,10); + QCOMPARE(intInput->text(), QLatin1String("1")); + QCOMPARE(intInput->hasAcceptableInput(), false); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(intInput->text(), QLatin1String("11")); + QCOMPARE(intInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_0); + QTest::keyRelease(canvas, Qt::Key_0, Qt::NoModifier ,10); + QCOMPARE(intInput->text(), QLatin1String("11")); + QCOMPARE(intInput->hasAcceptableInput(), true); + + QmlGraphicsTextInput *dblInput = qobject_cast<QmlGraphicsTextInput *>(qvariant_cast<QObject *>(canvas->root()->property("dblInput"))); + QTRY_VERIFY(dblInput); + dblInput->setFocus(true); + QVERIFY(dblInput->hasFocus() == true); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("1")); + QCOMPARE(dblInput->hasAcceptableInput(), false); + QTest::keyPress(canvas, Qt::Key_2); + QTest::keyRelease(canvas, Qt::Key_2, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("12")); + QCOMPARE(dblInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_Period); + QTest::keyRelease(canvas, Qt::Key_Period, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("12.")); + QCOMPARE(dblInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("12.1")); + QCOMPARE(dblInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("12.11")); + QCOMPARE(dblInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QCOMPARE(dblInput->text(), QLatin1String("12.11")); + QCOMPARE(dblInput->hasAcceptableInput(), true); + + QmlGraphicsTextInput *strInput = qobject_cast<QmlGraphicsTextInput *>(qvariant_cast<QObject *>(canvas->root()->property("strInput"))); + QTRY_VERIFY(strInput); + strInput->setFocus(true); + QVERIFY(strInput->hasFocus() == true); + QTest::keyPress(canvas, Qt::Key_1); + QTest::keyRelease(canvas, Qt::Key_1, Qt::NoModifier ,10); + QEXPECT_FAIL("","Will not work until QTBUG-8025 is resolved", Abort); + QCOMPARE(strInput->text(), QLatin1String("")); + QCOMPARE(strInput->hasAcceptableInput(), false); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + QCOMPARE(strInput->text(), QLatin1String("a")); + QCOMPARE(strInput->hasAcceptableInput(), false); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + QCOMPARE(strInput->text(), QLatin1String("aa")); + QCOMPARE(strInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + QCOMPARE(strInput->text(), QLatin1String("aaa")); + QCOMPARE(strInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + QCOMPARE(strInput->text(), QLatin1String("aaaa")); + QCOMPARE(strInput->hasAcceptableInput(), true); + QTest::keyPress(canvas, Qt::Key_A); + QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10); + QCOMPARE(strInput->text(), QLatin1String("aaaa")); + QCOMPARE(strInput->hasAcceptableInput(), true); } /* |