From: Damian Jansen Date: Fri, 21 Oct 2011 01:01:39 +0000 (+1000) Subject: Test for changing bounds of validators and acceptableInput X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=7fdeed1b085476f87e7f0d53351746b77d99161d;p=konrad%2Fqtdeclarative.git Test for changing bounds of validators and acceptableInput Task-number: QTBUG-19956 Change-Id: I771477d99939ef986bf3fa53e64a372f23ef5593 Reviewed-by: Charles Yin --- diff --git a/tests/auto/declarative/qsgtextinput/data/qtbug-19956double.qml b/tests/auto/declarative/qsgtextinput/data/qtbug-19956double.qml new file mode 100644 index 0000000..e9b80fc --- /dev/null +++ b/tests/auto/declarative/qsgtextinput/data/qtbug-19956double.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +TextInput { + id: textinput + property real topvalue: 30 + property real bottomvalue: 10 + height: 50 + width: 200 + text: "20" + validator: DoubleValidator { + id: doublevalidator + bottom: bottomvalue + top: topvalue + } +} diff --git a/tests/auto/declarative/qsgtextinput/data/qtbug-19956int.qml b/tests/auto/declarative/qsgtextinput/data/qtbug-19956int.qml new file mode 100644 index 0000000..0d70eed --- /dev/null +++ b/tests/auto/declarative/qsgtextinput/data/qtbug-19956int.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +TextInput { + id: textinput + property real topvalue: 30 + property real bottomvalue: 10 + height: 50 + width: 200 + text: "20" + validator: IntValidator { + id: intvalidator + bottom: bottomvalue + top: topvalue + } +} diff --git a/tests/auto/declarative/qsgtextinput/data/qtbug-19956regexp.qml b/tests/auto/declarative/qsgtextinput/data/qtbug-19956regexp.qml new file mode 100644 index 0000000..b5af13c --- /dev/null +++ b/tests/auto/declarative/qsgtextinput/data/qtbug-19956regexp.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +TextInput { + id: textinput + property variant regexvalue + height: 50 + width: 200 + text: "abc" + validator: RegExpValidator { + id: regexpvalidator + regExp: regexvalue + } +} diff --git a/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp b/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp index 0a733b5..09f4fb8 100644 --- a/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp +++ b/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp @@ -147,6 +147,10 @@ private slots: void inputMethodComposing(); void cursorRectangleSize(); + void QTBUG_19956(); + void QTBUG_19956_data(); + void QTBUG_19956_regexp(); + private: void simulateKey(QSGView *, int key); @@ -2647,6 +2651,75 @@ void tst_qsgtextinput::tripleClickSelectsAll() QVERIFY(input->selectedText().isEmpty()); } +void tst_qsgtextinput::QTBUG_19956_data() +{ + QTest::addColumn("url"); + QTest::newRow("intvalidator") << "qtbug-19956int.qml"; + QTest::newRow("doublevalidator") << "qtbug-19956double.qml"; +} + +void tst_qsgtextinput::QTBUG_19956() +{ + QFETCH(QString, url); + + QSGView canvas(QUrl::fromLocalFile(TESTDATA(url))); + canvas.show(); + canvas.requestActivateWindow(); + QTest::qWaitForWindowShown(&canvas); + QVERIFY(canvas.rootObject() != 0); + QSGTextInput *input = qobject_cast(canvas.rootObject()); + QVERIFY(input); + input->setFocus(true); + QVERIFY(input->hasActiveFocus()); + + QCOMPARE(canvas.rootObject()->property("topvalue").toInt(), 30); + QCOMPARE(canvas.rootObject()->property("bottomvalue").toInt(), 10); + QCOMPARE(canvas.rootObject()->property("text").toString(), QString("20")); + QVERIFY(canvas.rootObject()->property("acceptableInput").toBool()); + + canvas.rootObject()->setProperty("topvalue", 15); + QCOMPARE(canvas.rootObject()->property("topvalue").toInt(), 15); + QVERIFY(!canvas.rootObject()->property("acceptableInput").toBool()); + + canvas.rootObject()->setProperty("topvalue", 25); + QCOMPARE(canvas.rootObject()->property("topvalue").toInt(), 25); + QVERIFY(canvas.rootObject()->property("acceptableInput").toBool()); + + canvas.rootObject()->setProperty("bottomvalue", 21); + QCOMPARE(canvas.rootObject()->property("bottomvalue").toInt(), 21); + QVERIFY(!canvas.rootObject()->property("acceptableInput").toBool()); + + canvas.rootObject()->setProperty("bottomvalue", 10); + QCOMPARE(canvas.rootObject()->property("bottomvalue").toInt(), 10); + QVERIFY(canvas.rootObject()->property("acceptableInput").toBool()); +} + +void tst_qsgtextinput::QTBUG_19956_regexp() +{ + QSGView canvas(QUrl::fromLocalFile(TESTDATA("qtbug-19956regexp.qml"))); + canvas.show(); + canvas.requestActivateWindow(); + QTest::qWaitForWindowShown(&canvas); + QVERIFY(canvas.rootObject() != 0); + QSGTextInput *input = qobject_cast(canvas.rootObject()); + QVERIFY(input); + input->setFocus(true); + QVERIFY(input->hasActiveFocus()); + + canvas.rootObject()->setProperty("regexvalue", QRegExp("abc")); + QCOMPARE(canvas.rootObject()->property("regexvalue").toRegExp(), QRegExp("abc")); + QCOMPARE(canvas.rootObject()->property("text").toString(), QString("abc")); + QVERIFY(canvas.rootObject()->property("acceptableInput").toBool()); + + canvas.rootObject()->setProperty("regexvalue", QRegExp("abcd")); + QCOMPARE(canvas.rootObject()->property("regexvalue").toRegExp(), QRegExp("abcd")); + QVERIFY(!canvas.rootObject()->property("acceptableInput").toBool()); + + canvas.rootObject()->setProperty("regexvalue", QRegExp("abc")); + QCOMPARE(canvas.rootObject()->property("regexvalue").toRegExp(), QRegExp("abc")); + QVERIFY(canvas.rootObject()->property("acceptableInput").toBool()); +} + QTEST_MAIN(tst_qsgtextinput) #include "tst_qsgtextinput.moc"