summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2011-09-22 09:36:15 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2011-09-22 09:36:15 (GMT)
commitcf5c144770c08691260b14212afe646b1b23afe2 (patch)
treec6177cfc9c1c127cc4ed70936ee9083d8c35eb46 /tests
parent0981754cb42a7943cb3cc12345c82b4f301d65a3 (diff)
parenta9e50cd2fe243a912a5c70f157b043bbfc6413fb (diff)
downloadQt-cf5c144770c08691260b14212afe646b1b23afe2.zip
Qt-cf5c144770c08691260b14212afe646b1b23afe2.tar.gz
Qt-cf5c144770c08691260b14212afe646b1b23afe2.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-s60-public into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-s60-public: QLineControl: selectedTextChanged() signal is omitted in some cases
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp115
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp117
2 files changed, 231 insertions, 1 deletions
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index 33f74a9..4d8bd0b 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -156,6 +156,7 @@ private slots:
void inputContextMouseHandler();
void inputMethodComposing();
void cursorRectangleSize();
+ void deselect();
private:
void simulateKey(QDeclarativeView *, int key, Qt::KeyboardModifiers modifiers = 0);
@@ -2699,6 +2700,120 @@ void tst_qdeclarativetextedit::cursorRectangleSize()
QCOMPARE(microFocusFromScene.size(), cursorRect.size());
QCOMPARE(microFocusFromApp.size(), cursorRect.size());
}
+
+void tst_qdeclarativetextedit::deselect()
+{
+ QDeclarativeView *canvas = createView(SRCDIR "/data/CursorRect.qml");
+ QVERIFY(canvas->rootObject() != 0);
+ canvas->show();
+ canvas->setFocus();
+ QApplication::setActiveWindow(canvas);
+ QTest::qWaitForWindowShown(canvas);
+
+ QDeclarativeTextEdit *textEdit = qobject_cast<QDeclarativeTextEdit *>(canvas->rootObject());
+ QVERIFY(textEdit != 0);
+
+ textEdit->setText("Select");
+
+ QSignalSpy selectionStartSpy(textEdit, SIGNAL(selectionStartChanged()));
+ QSignalSpy selectionEndSpy(textEdit, SIGNAL(selectionEndChanged()));
+ QSignalSpy selectionSpy(textEdit, SIGNAL(selectionChanged()));
+
+ textEdit->select(5, 6);
+
+ QCOMPARE(selectionStartSpy.count(), 1);
+ QCOMPARE(selectionEndSpy.count(), 1);
+ QCOMPARE(selectionSpy.count(), 1);
+ QCOMPARE(textEdit->selectionStart(), 5);
+ QCOMPARE(textEdit->selectionEnd(), 6);
+ QCOMPARE(textEdit->selectedText(), QLatin1String("t"));
+ QCOMPARE(textEdit->cursorPosition(), 6);
+
+ textEdit->deselect();
+
+ QCOMPARE(selectionStartSpy.count(), 2);
+ QCOMPARE(selectionEndSpy.count(), 1);
+ QCOMPARE(selectionSpy.count(), 2);
+ QCOMPARE(textEdit->selectionStart(), textEdit->cursorPosition());
+ QCOMPARE(textEdit->selectionEnd(), textEdit->cursorPosition());
+ QCOMPARE(textEdit->selectedText(), QLatin1String(""));
+ QCOMPARE(textEdit->cursorPosition(), 6);
+
+ textEdit->select(5, 6);
+
+ QCOMPARE(selectionStartSpy.count(), 3);
+ QCOMPARE(selectionEndSpy.count(), 1);
+ QCOMPARE(selectionSpy.count(), 3);
+ QCOMPARE(textEdit->selectionStart(), 5);
+ QCOMPARE(textEdit->selectionEnd(), 6);
+ QCOMPARE(textEdit->selectedText(), QLatin1String("t"));
+ QCOMPARE(textEdit->cursorPosition(), 6);
+
+ QKeyEvent leftArrowPress(QEvent::KeyPress, Qt::Key_Left, Qt::NoModifier);
+ QKeyEvent leftArrowRelese(QEvent::KeyRelease, Qt::Key_Left, Qt::NoModifier);
+ QApplication::sendEvent(canvas, &leftArrowPress);
+ QApplication::sendEvent(canvas, &leftArrowRelese);
+
+ QCOMPARE(selectionStartSpy.count(), 3);
+ QCOMPARE(selectionEndSpy.count(), 2);
+ QCOMPARE(selectionSpy.count(), 4);
+ QCOMPARE(textEdit->selectionStart(), textEdit->cursorPosition());
+ QCOMPARE(textEdit->selectionEnd(), textEdit->cursorPosition());
+ QCOMPARE(textEdit->selectedText(), QLatin1String(""));
+ QCOMPARE(textEdit->cursorPosition(), 5);
+
+ textEdit->select(5, 6);
+
+ QCOMPARE(selectionStartSpy.count(), 3);
+ QCOMPARE(selectionEndSpy.count(), 3);
+ QCOMPARE(selectionSpy.count(), 5);
+ QCOMPARE(textEdit->selectionStart(), 5);
+ QCOMPARE(textEdit->selectionEnd(), 6);
+ QCOMPARE(textEdit->selectedText(), QLatin1String("t"));
+ QCOMPARE(textEdit->cursorPosition(), 6);
+
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant());
+ QInputMethodEvent event(QLatin1String(""), attributes);
+ QApplication::sendEvent(canvas, &event);
+
+ QCOMPARE(selectionStartSpy.count(), 4);
+ QCOMPARE(selectionEndSpy.count(), 4);
+ QCOMPARE(selectionSpy.count(), 6);
+ QCOMPARE(textEdit->selectionStart(), textEdit->cursorPosition());
+ QCOMPARE(textEdit->selectionEnd(), textEdit->cursorPosition());
+ QCOMPARE(textEdit->selectedText(), QLatin1String(""));
+ QCOMPARE(textEdit->cursorPosition(), 0);
+
+ textEdit->setCursorPosition(1);
+
+ QCOMPARE(selectionStartSpy.count(), 5);
+ QCOMPARE(selectionEndSpy.count(), 5);
+ QCOMPARE(selectionSpy.count(), 6);
+
+ QKeyEvent leftArrowShiftPress(QEvent::KeyPress, Qt::Key_Left, Qt::ShiftModifier);
+ QKeyEvent leftArrowShiftRelese(QEvent::KeyRelease, Qt::Key_Left, Qt::ShiftModifier);
+ QApplication::sendEvent(canvas, &leftArrowShiftPress);
+ QApplication::sendEvent(canvas, &leftArrowShiftRelese);
+
+ QCOMPARE(selectionStartSpy.count(), 6);
+ QCOMPARE(selectionEndSpy.count(), 5);
+ QCOMPARE(selectionSpy.count(), 7);
+ QCOMPARE(textEdit->selectionStart(), 0);
+ QCOMPARE(textEdit->selectionEnd(), 1);
+ QCOMPARE(textEdit->selectedText(), QLatin1String("S"));
+ QCOMPARE(textEdit->cursorPosition(), 0);
+
+ QApplication::sendEvent(canvas, &event);
+
+ QCOMPARE(selectionStartSpy.count(), 6);
+ QCOMPARE(selectionEndSpy.count(), 6);
+ QCOMPARE(selectionSpy.count(), 8);
+ QCOMPARE(textEdit->selectionStart(), textEdit->cursorPosition());
+ QCOMPARE(textEdit->selectionEnd(), textEdit->cursorPosition());
+ QCOMPARE(textEdit->selectedText(), QLatin1String(""));
+ QCOMPARE(textEdit->cursorPosition(), 0);
+}
QTEST_MAIN(tst_qdeclarativetextedit)
#include "tst_qdeclarativetextedit.moc"
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index bb895bf..b077670 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -147,6 +147,7 @@ private slots:
void inputContextMouseHandler();
void inputMethodComposing();
void cursorRectangleSize();
+ void deselect();
private:
void simulateKey(QDeclarativeView *, int key);
@@ -2367,7 +2368,7 @@ void tst_qdeclarativetextinput::openInputPanelOnFocus()
QVERIFY(!view.testAttribute(Qt::WA_InputMethodEnabled));
// input method should not be enabled
- // if TextEdit is read only.
+ // if TextInput is read only.
input.setReadOnly(true);
ic.openInputPanelReceived = false;
input.setFocus(true);
@@ -2815,6 +2816,120 @@ void tst_qdeclarativetextinput::cursorRectangleSize()
QCOMPARE(microFocusFromApp.size(), cursorRect.size());
}
+void tst_qdeclarativetextinput::deselect()
+{
+ QDeclarativeView *canvas = createView(SRCDIR "/data/positionAt.qml");
+ QVERIFY(canvas->rootObject() != 0);
+ canvas->show();
+ canvas->setFocus();
+ QApplication::setActiveWindow(canvas);
+ QTest::qWaitForWindowShown(canvas);
+
+ QDeclarativeTextInput *textInput = qobject_cast<QDeclarativeTextInput *>(canvas->rootObject());
+ QVERIFY(textInput != 0);
+
+ textInput->setText("Select");
+
+ QSignalSpy selectionStartSpy(textInput, SIGNAL(selectionStartChanged()));
+ QSignalSpy selectionEndSpy(textInput, SIGNAL(selectionEndChanged()));
+ QSignalSpy selectedTextSpy(textInput, SIGNAL(selectedTextChanged()));
+
+ textInput->select(5, 6);
+
+ QCOMPARE(selectionStartSpy.count(), 1);
+ QCOMPARE(selectionEndSpy.count(), 0);
+ QCOMPARE(selectedTextSpy.count(), 1);
+ QCOMPARE(textInput->selectionStart(), 5);
+ QCOMPARE(textInput->selectionEnd(), 6);
+ QCOMPARE(textInput->selectedText(), QLatin1String("t"));
+ QCOMPARE(textInput->cursorPosition(), 6);
+
+ textInput->deselect();
+
+ QCOMPARE(selectionStartSpy.count(), 2);
+ QCOMPARE(selectionEndSpy.count(), 1);
+ QCOMPARE(selectedTextSpy.count(), 2);
+ QCOMPARE(textInput->selectionStart(), textInput->cursorPosition());
+ QCOMPARE(textInput->selectionEnd(), textInput->cursorPosition());
+ QCOMPARE(textInput->selectedText(), QLatin1String(""));
+ QCOMPARE(textInput->cursorPosition(), 6);
+
+ textInput->select(5, 6);
+
+ QCOMPARE(selectionStartSpy.count(), 3);
+ QCOMPARE(selectionEndSpy.count(), 1);
+ QCOMPARE(selectedTextSpy.count(), 3);
+ QCOMPARE(textInput->selectionStart(), 5);
+ QCOMPARE(textInput->selectionEnd(), 6);
+ QCOMPARE(textInput->selectedText(), QLatin1String("t"));
+ QCOMPARE(textInput->cursorPosition(), 6);
+
+ QKeyEvent leftArrowPress(QEvent::KeyPress, Qt::Key_Left, Qt::NoModifier);
+ QKeyEvent leftArrowRelese(QEvent::KeyRelease, Qt::Key_Left, Qt::NoModifier);
+ QApplication::sendEvent(canvas, &leftArrowPress);
+ QApplication::sendEvent(canvas, &leftArrowRelese);
+
+ QCOMPARE(selectionStartSpy.count(), 4);
+ QCOMPARE(selectionEndSpy.count(), 2);
+ QCOMPARE(selectedTextSpy.count(), 4);
+ QCOMPARE(textInput->selectionStart(), textInput->cursorPosition());
+ QCOMPARE(textInput->selectionEnd(), textInput->cursorPosition());
+ QCOMPARE(textInput->selectedText(), QLatin1String(""));
+ QCOMPARE(textInput->cursorPosition(), 5);
+
+ textInput->select(5, 6);
+
+ QCOMPARE(selectionStartSpy.count(), 4);
+ QCOMPARE(selectionEndSpy.count(), 3);
+ QCOMPARE(selectedTextSpy.count(), 5);
+ QCOMPARE(textInput->selectionStart(), 5);
+ QCOMPARE(textInput->selectionEnd(), 6);
+ QCOMPARE(textInput->selectedText(), QLatin1String("t"));
+ QCOMPARE(textInput->cursorPosition(), 6);
+
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant());
+ QInputMethodEvent event(QLatin1String(""), attributes);
+ QApplication::sendEvent(canvas, &event);
+
+ QCOMPARE(selectionStartSpy.count(), 5);
+ QCOMPARE(selectionEndSpy.count(), 4);
+ QCOMPARE(selectedTextSpy.count(), 6);
+ QCOMPARE(textInput->selectionStart(), textInput->cursorPosition());
+ QCOMPARE(textInput->selectionEnd(), textInput->cursorPosition());
+ QCOMPARE(textInput->selectedText(), QLatin1String(""));
+ QCOMPARE(textInput->cursorPosition(), 0);
+
+ textInput->setCursorPosition(1);
+
+ QCOMPARE(selectionStartSpy.count(), 6);
+ QCOMPARE(selectionEndSpy.count(), 5);
+ QCOMPARE(selectedTextSpy.count(), 6);
+
+ QKeyEvent leftArrowShiftPress(QEvent::KeyPress, Qt::Key_Left, Qt::ShiftModifier);
+ QKeyEvent leftArrowShiftRelese(QEvent::KeyRelease, Qt::Key_Left, Qt::ShiftModifier);
+ QApplication::sendEvent(canvas, &leftArrowShiftPress);
+ QApplication::sendEvent(canvas, &leftArrowShiftRelese);
+
+ QCOMPARE(selectionStartSpy.count(), 7);
+ QCOMPARE(selectionEndSpy.count(), 5);
+ QCOMPARE(selectedTextSpy.count(), 7);
+ QCOMPARE(textInput->selectionStart(), 0);
+ QCOMPARE(textInput->selectionEnd(), 1);
+ QCOMPARE(textInput->selectedText(), QLatin1String("S"));
+ QCOMPARE(textInput->cursorPosition(), 0);
+
+ QApplication::sendEvent(canvas, &event);
+
+ QCOMPARE(selectionStartSpy.count(), 8);
+ QCOMPARE(selectionEndSpy.count(), 6);
+ QCOMPARE(selectedTextSpy.count(), 8);
+ QCOMPARE(textInput->selectionStart(), textInput->cursorPosition());
+ QCOMPARE(textInput->selectionEnd(), textInput->cursorPosition());
+ QCOMPARE(textInput->selectedText(), QLatin1String(""));
+ QCOMPARE(textInput->cursorPosition(), 0);
+}
+
QTEST_MAIN(tst_qdeclarativetextinput)
#include "tst_qdeclarativetextinput.moc"