Test for changing bounds of validators and acceptableInput
authorDamian Jansen <damian.jansen@nokia.com>
Fri, 21 Oct 2011 01:01:39 +0000 (11:01 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 21 Oct 2011 05:29:06 +0000 (07:29 +0200)
Task-number: QTBUG-19956
Change-Id: I771477d99939ef986bf3fa53e64a372f23ef5593
Reviewed-by: Charles Yin <charles.yin@nokia.com>
tests/auto/declarative/qsgtextinput/data/qtbug-19956double.qml [new file with mode: 0644]
tests/auto/declarative/qsgtextinput/data/qtbug-19956int.qml [new file with mode: 0644]
tests/auto/declarative/qsgtextinput/data/qtbug-19956regexp.qml [new file with mode: 0644]
tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp

diff --git a/tests/auto/declarative/qsgtextinput/data/qtbug-19956double.qml b/tests/auto/declarative/qsgtextinput/data/qtbug-19956double.qml
new file mode 100644 (file)
index 0000000..e9b80fc
--- /dev/null
@@ -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 (file)
index 0000000..0d70eed
--- /dev/null
@@ -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 (file)
index 0000000..b5af13c
--- /dev/null
@@ -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
+    }
+}
index 0a733b5..09f4fb8 100644 (file)
@@ -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<QString>("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<QSGTextInput*>(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<QSGTextInput*>(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"