tst_QLineEdit: Use correct keys to move to Start/End of Line

Home/End don't actually work on macOS. The "select all and delete" key
was not actually testing anything at all.

Change-Id: I44d3e9dd27da418afd699bf8720d5369325d20df
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
Daniel Teske 2017-07-13 16:32:53 +02:00
parent 578c96f0bb
commit d6b9cba812

View File

@ -319,6 +319,7 @@ private:
void psKeyClick(QWidget *target, Qt::Key key, Qt::KeyboardModifiers pressState = 0);
void psKeyClick(QTestEventList &keys, Qt::Key key, Qt::KeyboardModifiers pressState = 0);
bool unselectingWithLeftOrRightChangesCursorPosition();
void addKeySequenceStandardKey(QTestEventList &keys, QKeySequence::StandardKey);
QLineEdit *ensureTestWidget();
bool validInput;
@ -724,7 +725,7 @@ void tst_QLineEdit::keypress_inputMask_data()
{
QTestEventList keys;
// inserting 'A1.2B'
keys.addKeyClick(Qt::Key_Home);
addKeySequenceStandardKey(keys, QKeySequence::MoveToStartOfLine);
keys.addKeyClick(Qt::Key_A);
keys.addKeyClick(Qt::Key_1);
keys.addKeyClick(Qt::Key_Period);
@ -735,7 +736,7 @@ void tst_QLineEdit::keypress_inputMask_data()
{
QTestEventList keys;
// inserting 'A1.2B'
keys.addKeyClick(Qt::Key_Home);
addKeySequenceStandardKey(keys, QKeySequence::MoveToStartOfLine);
keys.addKeyClick(Qt::Key_0);
keys.addKeyClick(Qt::Key_Exclam);
keys.addKeyClick('P');
@ -745,22 +746,24 @@ void tst_QLineEdit::keypress_inputMask_data()
{
QTestEventList keys;
// pressing delete
keys.addKeyClick(Qt::Key_Home);
addKeySequenceStandardKey(keys, QKeySequence::MoveToStartOfLine);
keys.addKeyClick(Qt::Key_Delete);
QTest::newRow("delete") << QString("000.000;_") << keys << QString(".") << QString("___.___");
}
{
QTestEventList keys;
// selecting all and delete
keys.addKeyClick(Qt::Key_Home);
keys.addKeyClick(Qt::Key_End, Qt::ShiftModifier);
keys.addKeyClick(Qt::Key_1);
keys.addKeyClick(Qt::Key_2);
addKeySequenceStandardKey(keys, QKeySequence::MoveToStartOfLine);
addKeySequenceStandardKey(keys, QKeySequence::SelectEndOfLine);
keys.addKeyClick(Qt::Key_Delete);
QTest::newRow("deleting all") << QString("000.000;_") << keys << QString(".") << QString("___.___");
}
{
QTestEventList keys;
// inserting '12.12' then two backspaces
keys.addKeyClick(Qt::Key_Home);
addKeySequenceStandardKey(keys, QKeySequence::MoveToStartOfLine);
keys.addKeyClick(Qt::Key_1);
keys.addKeyClick(Qt::Key_2);
keys.addKeyClick(Qt::Key_Period);
@ -773,7 +776,7 @@ void tst_QLineEdit::keypress_inputMask_data()
{
QTestEventList keys;
// inserting '12ab'
keys.addKeyClick(Qt::Key_Home);
addKeySequenceStandardKey(keys, QKeySequence::MoveToStartOfLine);
keys.addKeyClick(Qt::Key_1);
keys.addKeyClick(Qt::Key_2);
keys.addKeyClick(Qt::Key_A);
@ -1971,6 +1974,13 @@ void tst_QLineEdit::psKeyClick(QTestEventList &keys, Qt::Key key, Qt::KeyboardMo
keys.addKeyClick(key, pressState);
}
void tst_QLineEdit::addKeySequenceStandardKey(QTestEventList &keys, QKeySequence::StandardKey key)
{
QKeySequence keyseq = QKeySequence(key);
for (int i = 0; i < keyseq.count(); ++i)
keys.addKeyClick( Qt::Key( keyseq[i] & ~Qt::KeyboardModifierMask), Qt::KeyboardModifier(keyseq[i] & Qt::KeyboardModifierMask) );
}
void tst_QLineEdit::cursorPosition()
{
QLineEdit *testWidget = ensureTestWidget();