summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSami Nurmenniemi <sami.nurmenniemi@qt.io>2017-04-03 15:37:16 +0300
committerSami Nurmenniemi <sami.nurmenniemi@qt.io>2017-04-26 12:42:08 +0000
commite5a1c7fff7b17a149ad5bea9f7e3694382e7674b (patch)
treecc0623793d951732a70e86d41fd94c1e1690f094 /tests
parent99017d78ee7f357fee80ddc844a18f1d7fad4292 (diff)
Fix tst_QLineEdit for offscreen and minimal platforms
Unselecting with offscreen and minimal platforms behave similarly as in Windows and QNX. If left or right key is used for unselecting, cursor position is changed. Change-Id: I022cd2fec80ad1875fec983e1e3536a105e18bb2 Reviewed-by: Teemu Holappa <teemu.holappa@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index 139aaa7371..a0ba91ba4a 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -325,6 +325,7 @@ private:
// keyClicks(..) is moved to QtTestCase
void psKeyClick(QWidget *target, Qt::Key key, Qt::KeyboardModifiers pressState = 0);
void psKeyClick(QTestEventList &keys, Qt::Key key, Qt::KeyboardModifiers pressState = 0);
+ bool unselectingWithLeftOrRightChangesCursorPosition();
QLineEdit *ensureTestWidget();
bool validInput;
@@ -1315,9 +1316,10 @@ void tst_QLineEdit::undo_keypressevents_data()
// unselect any current selection
keys.addKeyClick(Qt::Key_Right);
-#if defined Q_OS_WIN || defined Q_OS_QNX //Windows and QNX do not jump to the beginning of the selection
- keys.addKeyClick(Qt::Key_Left);
-#endif
+
+ // If previous right changed cursor position, go back left
+ if (unselectingWithLeftOrRightChangesCursorPosition())
+ keys.addKeyClick(Qt::Key_Left);
// selecting '12'
keys.addKeyClick(Qt::Key_Right, Qt::ShiftModifier);
@@ -3298,14 +3300,11 @@ void tst_QLineEdit::leftKeyOnSelectedText()
QCOMPARE(testWidget->cursorPosition(), 2);
QCOMPARE(testWidget->selectedText(), QString("23"));
QTest::keyClick(testWidget, Qt::Key_Left);
-#if defined Q_OS_WIN || defined Q_OS_QNX
- QCOMPARE(testWidget->cursorPosition(), 1);
-#else
- // Selection is cleared ands cursor remains at position 2.
- // X11 used to behave like window prior to 4.2. Changes caused by QKeySequence
- // resulted in an inadvertant change in behavior
- QCOMPARE(testWidget->cursorPosition(), 2);
-#endif
+
+ if (unselectingWithLeftOrRightChangesCursorPosition())
+ QCOMPARE(testWidget->cursorPosition(), 1);
+ else
+ QCOMPARE(testWidget->cursorPosition(), 2);
}
void tst_QLineEdit::inlineCompletion()
@@ -4639,5 +4638,22 @@ void tst_QLineEdit::QTBUG59957_clearButtonLeftmostAction()
#endif // QT_BUILD_INTERNAL
}
+bool tst_QLineEdit::unselectingWithLeftOrRightChangesCursorPosition()
+{
+#if defined Q_OS_WIN || defined Q_OS_QNX //Windows and QNX do not jump to the beginning of the selection
+ return true;
+#endif
+ // Platforms minimal/offscreen also need left after unselecting with right
+ if (!QGuiApplication::platformName().compare("minimal", Qt::CaseInsensitive)
+ || !QGuiApplication::platformName().compare("offscreen", Qt::CaseInsensitive)) {
+ return true;
+ }
+
+ // Selection is cleared ands cursor remains at previous position.
+ // X11 used to behave like window prior to 4.2. Changes caused by QKeySequence
+ // resulted in an inadvertant change in behavior
+ return false;
+}
+
QTEST_MAIN(tst_QLineEdit)
#include "tst_qlineedit.moc"