diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-07-31 16:25:16 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-06 06:04:47 +0200 |
commit | 082dff2c8f5383e8372c1a4d7c61bc2eebe5c9df (patch) | |
tree | fc8074040d3d504173d21ce42a43a9d5c1d51f78 /tests/auto/quick/qquicktextinput | |
parent | 49496cf8812c33f2796289a455da105710567e1c (diff) |
Add tests for copy and paste using keyboard shortcuts.
Fixes TextInput.cut() removing text while read only.
Change-Id: I03cd44d381be9d53f71ba168b8be7971ab0bbad7
Reviewed-by: Damian Jansen <damian.jansen@nokia.com>
Diffstat (limited to 'tests/auto/quick/qquicktextinput')
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 09d21196ba..8beb871212 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -2459,14 +2459,27 @@ void tst_qquicktextinput::copyAndPaste() { QVERIFY(textInput->canPaste()); textInput->setReadOnly(true); QVERIFY(!textInput->canPaste()); + textInput->paste(); + QCOMPARE(textInput->text(), QString("Hello world!Hello world!")); + QCOMPARE(textInput->text().length(), 24); textInput->setReadOnly(false); QVERIFY(textInput->canPaste()); + // cut: no selection + textInput->cut(); + QCOMPARE(textInput->text(), QString("Hello world!Hello world!")); + // select word textInput->setCursorPosition(0); textInput->selectWord(); QCOMPARE(textInput->selectedText(), QString("Hello")); + // cut: read only. + textInput->setReadOnly(true); + textInput->cut(); + QCOMPARE(textInput->text(), QString("Hello world!Hello world!")); + textInput->setReadOnly(false); + // select all and cut textInput->selectAll(); textInput->cut(); @@ -2475,6 +2488,18 @@ void tst_qquicktextinput::copyAndPaste() { QCOMPARE(textInput->text(), QString("Hello world!Hello world!")); QCOMPARE(textInput->text().length(), 24); + // Copy first word. + textInput->setCursorPosition(0); + textInput->selectWord(); + textInput->copy(); + // copy: no selection, previous copy retained; + textInput->setCursorPosition(0); + QCOMPARE(textInput->selectedText(), QString()); + textInput->copy(); + textInput->setText(QString()); + textInput->paste(); + QCOMPARE(textInput->text(), QString("Hello")); + // clear copy buffer QClipboard *clipboard = QGuiApplication::clipboard(); QVERIFY(clipboard); @@ -5483,6 +5508,49 @@ void tst_qquicktextinput::undo_keypressevents_data() QTest::newRow("Insert,move,select,delete next word,undo,insert") << keys << expectedString; } + +#ifndef QT_NO_CLIPBOARD + + bool canCopyPaste = true; +#ifdef Q_OS_MAC + + { + PasteboardRef pasteboard; + OSStatus status = PasteboardCreate(0, &pasteboard); + canCopyPaste = status == noErr; + } +#endif + + if (canCopyPaste) { + KeyList keys; + keys << "123" + << QKeySequence(QKeySequence::SelectStartOfLine) + << QKeySequence(QKeySequence::Cut) + << "ABC" + << QKeySequence(QKeySequence::Paste); + QStringList expectedString = QStringList() + << "ABC123" + << "ABC" + // TextEdit: "" + << "123"; + QTest::newRow("Cut,paste") << keys << expectedString; + } + if (canCopyPaste) { + KeyList keys; + keys << "123" + << QKeySequence(QKeySequence::SelectStartOfLine) + << QKeySequence(QKeySequence::Copy) + << "ABC" + << QKeySequence(QKeySequence::Paste); + QStringList expectedString = QStringList() + << "ABC123" + << "ABC" + // TextEdit: "A" + << "123"; + QTest::newRow("Copy,paste") << keys << expectedString; + } + +#endif } void tst_qquicktextinput::undo_keypressevents() |