diff options
Diffstat (limited to 'tests/auto/quick/qquicktextinput')
-rw-r--r-- | tests/auto/quick/qquicktextinput/data/qtbug51115.qml | 11 | ||||
-rw-r--r-- | tests/auto/quick/qquicktextinput/qquicktextinput.pro | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 106 |
3 files changed, 100 insertions, 19 deletions
diff --git a/tests/auto/quick/qquicktextinput/data/qtbug51115.qml b/tests/auto/quick/qquicktextinput/data/qtbug51115.qml new file mode 100644 index 0000000000..008ac25844 --- /dev/null +++ b/tests/auto/quick/qquicktextinput/data/qtbug51115.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +TextInput { + Component.onCompleted: { + readOnly = false; + text= "bla bla"; + selectAll(); + readOnly = true; + } +} + diff --git a/tests/auto/quick/qquicktextinput/qquicktextinput.pro b/tests/auto/quick/qquicktextinput/qquicktextinput.pro index 4929289920..7868b60d1b 100644 --- a/tests/auto/quick/qquicktextinput/qquicktextinput.pro +++ b/tests/auto/quick/qquicktextinput/qquicktextinput.pro @@ -14,5 +14,3 @@ TESTDATA = data/* QT += core-private gui-private qml-private quick-private testlib osx: LIBS += -framework AppKit - -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index e57a95184c..18ccd81633 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -193,6 +188,7 @@ private slots: void redo(); void undo_keypressevents_data(); void undo_keypressevents(); + void clear(); void backspaceSurrogatePairs(); @@ -226,6 +222,8 @@ private slots: void ensureVisible(); void padding(); + void QTBUG_51115_readOnlyResetsSelection(); + private: void simulateKey(QWindow *, int key); @@ -2253,6 +2251,19 @@ void tst_qquicktextinput::inputMethods() QGuiApplication::sendEvent(input, &preeditEvent); QCOMPARE(input->text(), QString("Our Goodbye world!")); QCOMPARE(input->displayText(), QString("Our GooPREEDITdbye world!")); + QCOMPARE(input->preeditText(), QString("PREEDIT")); + + QInputMethodEvent preeditEvent2("PREEDIT2", QList<QInputMethodEvent::Attribute>()); + QGuiApplication::sendEvent(input, &preeditEvent2); + QCOMPARE(input->text(), QString("Our Goodbye world!")); + QCOMPARE(input->displayText(), QString("Our GooPREEDIT2dbye world!")); + QCOMPARE(input->preeditText(), QString("PREEDIT2")); + + QInputMethodEvent preeditEvent3("", QList<QInputMethodEvent::Attribute>()); + QGuiApplication::sendEvent(input, &preeditEvent3); + QCOMPARE(input->text(), QString("Our Goodbye world!")); + QCOMPARE(input->displayText(), QString("Our Goodbye world!")); + QCOMPARE(input->preeditText(), QString("")); // input should reset selection even if replacement parameters are out of bounds input->setText("text"); @@ -5750,6 +5761,56 @@ void tst_qquicktextinput::undo_keypressevents() QVERIFY(textInput->text().isEmpty()); } +void tst_qquicktextinput::clear() +{ + QString componentStr = "import QtQuick 2.0\nTextInput { focus: true }"; + QQmlComponent textInputComponent(&engine); + textInputComponent.setData(componentStr.toLatin1(), QUrl()); + QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(textInputComponent.create()); + QVERIFY(textInput != 0); + + QQuickWindow window; + textInput->setParentItem(window.contentItem()); + window.show(); + window.requestActivate(); + QTest::qWaitForWindowActive(&window); + QVERIFY(textInput->hasActiveFocus()); + QVERIFY(!textInput->canUndo()); + + QSignalSpy spy(textInput, SIGNAL(canUndoChanged())); + + textInput->setText("I am Legend"); + QCOMPARE(textInput->text(), QString("I am Legend")); + textInput->clear(); + QVERIFY(textInput->text().isEmpty()); + + QCOMPARE(spy.count(), 1); + + // checks that clears can be undone + textInput->undo(); + QVERIFY(!textInput->canUndo()); + QCOMPARE(spy.count(), 2); + QCOMPARE(textInput->text(), QString("I am Legend")); + + textInput->setCursorPosition(4); + QInputMethodEvent preeditEvent("PREEDIT", QList<QInputMethodEvent::Attribute>()); + QGuiApplication::sendEvent(textInput, &preeditEvent); + QCOMPARE(textInput->text(), QString("I am Legend")); + QCOMPARE(textInput->displayText(), QString("I amPREEDIT Legend")); + QCOMPARE(textInput->preeditText(), QString("PREEDIT")); + + textInput->clear(); + QVERIFY(textInput->text().isEmpty()); + + QCOMPARE(spy.count(), 3); + + // checks that clears can be undone + textInput->undo(); + QVERIFY(!textInput->canUndo()); + QCOMPARE(spy.count(), 4); + QCOMPARE(textInput->text(), QString("I am Legend")); +} + void tst_qquicktextinput::backspaceSurrogatePairs() { // Test backspace, and delete remove both characters in a surrogate pair. @@ -6677,6 +6738,17 @@ void tst_qquicktextinput::padding() delete root; } +void tst_qquicktextinput::QTBUG_51115_readOnlyResetsSelection() +{ + QQuickView view; + view.setSource(testFileUrl("qtbug51115.qml")); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QQuickTextInput *obj = qobject_cast<QQuickTextInput*>(view.rootObject()); + + QCOMPARE(obj->selectedText(), QString()); +} + QTEST_MAIN(tst_qquicktextinput) #include "tst_qquicktextinput.moc" |