summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp')
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp96
1 files changed, 79 insertions, 17 deletions
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index b46609c371..db42ed3119 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -64,6 +64,7 @@
#include <qsortfilterproxymodel.h>
#include <qdebug.h>
#include <qscreen.h>
+#include <qshortcut.h>
#include "qcommonstyle.h"
#include "qstyleoption.h"
@@ -131,14 +132,13 @@ public:
enum EventStates { Press, Release, Click };
tst_QLineEdit();
- virtual ~tst_QLineEdit();
-public slots:
+private slots:
void initTestCase();
void cleanupTestCase();
void init();
void cleanup();
-private slots:
+
void getSetCheck();
void experimental();
@@ -313,6 +313,9 @@ private slots:
void shouldShowPlaceholderText();
void QTBUG1266_setInputMaskEmittingTextEdited();
+ void shortcutOverrideOnReadonlyLineEdit_data();
+ void shortcutOverrideOnReadonlyLineEdit();
+
protected slots:
void editingFinished();
@@ -377,10 +380,6 @@ tst_QLineEdit::tst_QLineEdit() : validInput(false), m_testWidget(0), m_keyboardS
}
}
-tst_QLineEdit::~tst_QLineEdit()
-{
-}
-
QLineEdit *tst_QLineEdit::ensureTestWidget()
{
if (!m_testWidget) {
@@ -2245,6 +2244,7 @@ void tst_QLineEdit::deleteSelectedText()
edit.setText(text);
edit.selectAll();
+#ifndef QT_NO_CONTEXTMENU
QMenu *menu = edit.createStandardContextMenu();
for (int i = 0; i < menu->actions().count(); ++i) {
QAction *current = menu->actions().at(i);
@@ -2253,6 +2253,7 @@ void tst_QLineEdit::deleteSelectedText()
QVERIFY(edit.text().isEmpty());
}
}
+#endif // QT_NO_CONTEXTMENU
}
@@ -2888,6 +2889,11 @@ void tst_QLineEdit::insert()
QCOMPARE(testWidget->text(), QString("No Crash! This is a nice test"));
}
+static inline QByteArray selectionTestName(int start, int length)
+{
+ return "selection start: " + QByteArray::number(start) + " length: " + QByteArray::number(length);
+}
+
void tst_QLineEdit::setSelection_data()
{
QTest::addColumn<QString>("text");
@@ -2901,39 +2907,39 @@ void tst_QLineEdit::setSelection_data()
int start, length, pos;
start = 0; length = 1; pos = 1;
- QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
+ QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString("A") << true;
start = 0; length = 2; pos = 2;
- QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
+ QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString("Ab") << true;
start = 0; length = 4; pos = 4;
- QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
+ QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString("Abc ") << true;
start = -1; length = 0; pos = text.length();
- QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
+ QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString() << false;
start = 34; length = 1; pos = 35;
- QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
+ QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString("z") << true;
start = 34; length = 2; pos = 35;
- QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
+ QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString("z") << true;
start = 34; length = -1; pos = 33;
- QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
+ QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString("y") << true;
start = 1; length = -2; pos = 0;
- QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
+ QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString("A") << true;
start = -1; length = -1; pos = text.length();
- QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
+ QTest::newRow(selectionTestName(start, length).constData())
<< text << start << length << pos << QString() << false;
}
@@ -3314,7 +3320,7 @@ void tst_QLineEdit::inlineCompletion()
QStandardItem *root = model->invisibleRootItem();
QStandardItem *items[5];
for (int i = 0; i < 5; i++) {
- items[i] = new QStandardItem(QString("item%1").arg(i));
+ items[i] = new QStandardItem(QLatin1String("item") + QString::number(i));
if ((i+2)%2 == 0) { // disable 0,2,4
items[i]->setFlags(items[i]->flags() & ~Qt::ItemIsEnabled);
}
@@ -4504,5 +4510,61 @@ void tst_QLineEdit::QTBUG1266_setInputMaskEmittingTextEdited()
QCOMPARE(spy.count(), 0);
}
+void tst_QLineEdit::shortcutOverrideOnReadonlyLineEdit_data()
+{
+ QTest::addColumn<QKeySequence>("keySequence");
+ QTest::addColumn<bool>("shouldBeHandledByQLineEdit");
+
+ QTest::newRow("Copy") << QKeySequence(QKeySequence::Copy) << true;
+ QTest::newRow("MoveToNextChar") << QKeySequence(QKeySequence::MoveToNextChar) << true;
+ QTest::newRow("SelectAll") << QKeySequence(QKeySequence::SelectAll) << true;
+ QTest::newRow("Right press") << QKeySequence(Qt::Key_Right) << true;
+ QTest::newRow("Left press") << QKeySequence(Qt::Key_Left) << true;
+
+ QTest::newRow("Paste") << QKeySequence(QKeySequence::Paste) << false;
+ QTest::newRow("Paste") << QKeySequence(QKeySequence::Cut) << false;
+ QTest::newRow("Undo") << QKeySequence(QKeySequence::Undo) << false;
+ QTest::newRow("Redo") << QKeySequence(QKeySequence::Redo) << false;
+
+ QTest::newRow("a") << QKeySequence(Qt::Key_A) << false;
+ QTest::newRow("b") << QKeySequence(Qt::Key_B) << false;
+ QTest::newRow("c") << QKeySequence(Qt::Key_C) << false;
+ QTest::newRow("x") << QKeySequence(Qt::Key_X) << false;
+ QTest::newRow("X") << QKeySequence(Qt::ShiftModifier + Qt::Key_X) << false;
+
+ QTest::newRow("Alt+Home") << QKeySequence(Qt::AltModifier + Qt::Key_Home) << false;
+}
+
+void tst_QLineEdit::shortcutOverrideOnReadonlyLineEdit()
+{
+ QFETCH(QKeySequence, keySequence);
+ QFETCH(bool, shouldBeHandledByQLineEdit);
+
+ QWidget widget;
+
+ QShortcut *shortcut = new QShortcut(keySequence, &widget);
+ QSignalSpy spy(shortcut, &QShortcut::activated);
+ QVERIFY(spy.isValid());
+
+ QLineEdit *lineEdit = new QLineEdit(QStringLiteral("Test"), &widget);
+ lineEdit->setReadOnly(true);
+ lineEdit->setFocus();
+
+ widget.show();
+
+ QVERIFY(QTest::qWaitForWindowActive(&widget));
+
+ const int keySequenceCount = keySequence.count();
+ for (int i = 0; i < keySequenceCount; ++i) {
+ const uint key = keySequence[i];
+ QTest::keyClick(lineEdit,
+ Qt::Key(key & ~Qt::KeyboardModifierMask),
+ Qt::KeyboardModifier(key & Qt::KeyboardModifierMask));
+ }
+
+ const int activationCount = shouldBeHandledByQLineEdit ? 0 : 1;
+ QCOMPARE(spy.count(), activationCount);
+}
+
QTEST_MAIN(tst_QLineEdit)
#include "tst_qlineedit.moc"