Skip to content

Commit

Permalink
Test for changing bounds of validators and acceptableInput
Browse files Browse the repository at this point in the history
Task-number: QTBUG-19956
Change-Id: I771477d99939ef986bf3fa53e64a372f23ef5593
Reviewed-by: Charles Yin <charles.yin@nokia.com>
  • Loading branch information
Damian Jansen authored and Qt by Nokia committed Oct 21, 2011
1 parent 2bf7113 commit 7fdeed1
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 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
}
}
15 changes: 15 additions & 0 deletions 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
}
}
13 changes: 13 additions & 0 deletions 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
}
}
73 changes: 73 additions & 0 deletions tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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"

0 comments on commit 7fdeed1

Please sign in to comment.