diff options
Diffstat (limited to 'tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp')
-rw-r--r-- | tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp | 123 |
1 files changed, 102 insertions, 21 deletions
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index d007e7c98d..cb2a7bfd83 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.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$ ** @@ -194,6 +189,7 @@ private slots: void redo(); void undo_keypressevents_data(); void undo_keypressevents(); + void clear(); void baseUrl(); void embeddedImages(); @@ -205,6 +201,7 @@ private slots: void doubleSelect_QTBUG_38704(); void padding(); + void QTBUG_51115_readOnlyResetsSelection(); private: void simulateKeys(QWindow *window, const QList<Key> &keys); @@ -3039,6 +3036,23 @@ void tst_qquicktextedit::textInput() edit->setReadOnly(true); QGuiApplication::sendEvent(edit, &queryEvent); QCOMPARE(queryEvent.value(Qt::ImEnabled).toBool(), false); + + edit->setReadOnly(false); + + QInputMethodEvent preeditEvent("PREEDIT", QList<QInputMethodEvent::Attribute>()); + QGuiApplication::sendEvent(edit, &preeditEvent); + QCOMPARE(edit->text(), QString("Hello world!")); + QCOMPARE(edit->preeditText(), QString("PREEDIT")); + + QInputMethodEvent preeditEvent2("PREEDIT2", QList<QInputMethodEvent::Attribute>()); + QGuiApplication::sendEvent(edit, &preeditEvent2); + QCOMPARE(edit->text(), QString("Hello world!")); + QCOMPARE(edit->preeditText(), QString("PREEDIT2")); + + QInputMethodEvent preeditEvent3("", QList<QInputMethodEvent::Attribute>()); + QGuiApplication::sendEvent(edit, &preeditEvent3); + QCOMPARE(edit->text(), QString("Hello world!")); + QCOMPARE(edit->preeditText(), QString("")); } void tst_qquicktextedit::inputMethodUpdate() @@ -4876,7 +4890,6 @@ void tst_qquicktextedit::undo_data() insertString << " unique instance."; expectedString << "Ensuring a unique instance."; - expectedString << "Ensuring a "; // ### Not present in TextEdit. expectedString << "Ensuring an instan"; expectedString << "Ensuring instan"; expectedString << ""; @@ -5164,8 +5177,6 @@ void tst_qquicktextedit::undo_keypressevents_data() << "ABC"; expectedString << "ABC"; - // ### One operation in TextEdit. - expectedString << "A"; expectedString << "123"; QTest::newRow("Inserts,moving,selection and overwriting") << keys << expectedString; @@ -5197,7 +5208,6 @@ void tst_qquicktextedit::undo_keypressevents_data() QStringList expectedString = QStringList() << "ABC123" << "ABC" - << "A" << "123"; QTest::newRow("Copy,paste") << keys << expectedString; } @@ -5230,6 +5240,66 @@ void tst_qquicktextedit::undo_keypressevents() QVERIFY(textEdit->text().isEmpty()); } +void tst_qquicktextedit::clear() +{ + QString componentStr = "import QtQuick 2.0\nTextEdit { focus: true }"; + QQmlComponent textEditComponent(&engine); + textEditComponent.setData(componentStr.toLatin1(), QUrl()); + QQuickTextEdit *textEdit = qobject_cast<QQuickTextEdit*>(textEditComponent.create()); + QVERIFY(textEdit != 0); + + QQuickWindow window; + textEdit->setParentItem(window.contentItem()); + window.show(); + window.requestActivate(); + QTest::qWaitForWindowActive(&window); + QVERIFY(textEdit->hasActiveFocus()); + + QSignalSpy spy(textEdit, SIGNAL(canUndoChanged())); + + textEdit->setText("I am Legend"); + QCOMPARE(textEdit->text(), QString("I am Legend")); + textEdit->clear(); + QVERIFY(textEdit->text().isEmpty()); + + QCOMPARE(spy.count(), 1); + + // checks that clears can be undone + textEdit->undo(); + QVERIFY(!textEdit->canUndo()); + QCOMPARE(spy.count(), 2); + QCOMPARE(textEdit->text(), QString("I am Legend")); + + textEdit->setCursorPosition(4); + QInputMethodEvent preeditEvent("PREEDIT", QList<QInputMethodEvent::Attribute>()); + QGuiApplication::sendEvent(textEdit, &preeditEvent); + QCOMPARE(textEdit->text(), QString("I am Legend")); + QCOMPARE(textEdit->preeditText(), QString("PREEDIT")); + + textEdit->clear(); + QVERIFY(textEdit->text().isEmpty()); + + QCOMPARE(spy.count(), 3); + + // checks that clears can be undone + textEdit->undo(); + QVERIFY(!textEdit->canUndo()); + QCOMPARE(spy.count(), 4); + QCOMPARE(textEdit->text(), QString("I am Legend")); + + textEdit->setText(QString("<i>I am Legend</i>")); + QCOMPARE(textEdit->text(), QString("<i>I am Legend</i>")); + textEdit->clear(); + QVERIFY(textEdit->text().isEmpty()); + + QCOMPARE(spy.count(), 5); + + // checks that clears can be undone + textEdit->undo(); + QCOMPARE(spy.count(), 6); + QCOMPARE(textEdit->text(), QString("<i>I am Legend</i>")); +} + void tst_qquicktextedit::baseUrl() { QUrl localUrl("file:///tests/text.qml"); @@ -5467,6 +5537,17 @@ void tst_qquicktextedit::padding() delete root; } +void tst_qquicktextedit::QTBUG_51115_readOnlyResetsSelection() +{ + QQuickView view; + view.setSource(testFileUrl("qtbug51115.qml")); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QQuickTextEdit *obj = qobject_cast<QQuickTextEdit*>(view.rootObject()); + + QCOMPARE(obj->selectedText(), QString()); +} + QTEST_MAIN(tst_qquicktextedit) #include "tst_qquicktextedit.moc" |