aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-07-31 16:25:16 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-06 06:04:47 +0200
commit082dff2c8f5383e8372c1a4d7c61bc2eebe5c9df (patch)
treefc8074040d3d504173d21ce42a43a9d5c1d51f78 /tests
parent49496cf8812c33f2796289a455da105710567e1c (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')
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp70
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp68
2 files changed, 138 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index 6684e68869..9f381053a9 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -2618,6 +2618,9 @@ void tst_qquicktextedit::copyAndPaste() {
QVERIFY(textEdit->canPaste());
textEdit->setReadOnly(true);
QVERIFY(!textEdit->canPaste());
+ textEdit->paste();
+ QCOMPARE(textEdit->text(), QString("Hello world!Hello world!"));
+ QCOMPARE(textEdit->text().length(), 24);
textEdit->setReadOnly(false);
QVERIFY(textEdit->canPaste());
@@ -2627,11 +2630,21 @@ void tst_qquicktextedit::copyAndPaste() {
QQuickTextEditPrivate *editPrivate = static_cast<QQuickTextEditPrivate*>(pri);
QCOMPARE(textEdit->text(), editPrivate->text);
+ // cut: no selection
+ textEdit->cut();
+ QCOMPARE(textEdit->text(), QString("Hello world!Hello world!"));
+
// select word
textEdit->setCursorPosition(0);
textEdit->selectWord();
QCOMPARE(textEdit->selectedText(), QString("Hello"));
+ // cut: read only.
+ textEdit->setReadOnly(true);
+ textEdit->cut();
+ QCOMPARE(textEdit->text(), QString("Hello world!Hello world!"));
+ textEdit->setReadOnly(false);
+
// select all and cut
textEdit->selectAll();
textEdit->cut();
@@ -2639,6 +2652,18 @@ void tst_qquicktextedit::copyAndPaste() {
textEdit->paste();
QCOMPARE(textEdit->text(), QString("Hello world!Hello world!"));
QCOMPARE(textEdit->text().length(), 24);
+
+ // Copy first word.
+ textEdit->setCursorPosition(0);
+ textEdit->selectWord();
+ textEdit->copy();
+ // copy: no selection, previous copy retained;
+ textEdit->setCursorPosition(0);
+ QCOMPARE(textEdit->selectedText(), QString());
+ textEdit->copy();
+ textEdit->setText(QString());
+ textEdit->paste();
+ QCOMPARE(textEdit->text(), QString("Hello"));
#endif
}
@@ -2680,6 +2705,7 @@ void tst_qquicktextedit::canPasteEmpty() {
#endif
}
+
void tst_qquicktextedit::readOnly()
{
QQuickView window(testFileUrl("readOnly.qml"));
@@ -4667,6 +4693,50 @@ void tst_qquicktextedit::undo_keypressevents_data()
QTest::newRow("Inserts,moving,selection and overwriting") << 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"
+ << ""
+ << "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"
+ << "A"
+ << "123";
+ QTest::newRow("Copy,paste") << keys << expectedString;
+ }
+
+#endif
}
void tst_qquicktextedit::undo_keypressevents()
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()