0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
#include "../../shared/util.h"
|
|
45 |
|
|
46 |
#include "qlineedit.h"
|
|
47 |
#include "qapplication.h"
|
|
48 |
#include "qstringlist.h"
|
|
49 |
#include "qstyle.h"
|
|
50 |
#include "qvalidator.h"
|
|
51 |
#include "qcompleter.h"
|
|
52 |
#include "qstandarditemmodel.h"
|
|
53 |
|
|
54 |
#ifdef Q_WS_MAC
|
|
55 |
#include <Carbon/Carbon.h> // For the random function.
|
|
56 |
#include <cstdlib> // For the random function.
|
|
57 |
#endif
|
|
58 |
|
|
59 |
#include <qlineedit.h>
|
|
60 |
#include <qmenu.h>
|
|
61 |
#include <qlayout.h>
|
|
62 |
#include <qspinbox.h>
|
|
63 |
#include <qdebug.h>
|
|
64 |
|
|
65 |
|
|
66 |
//TESTED_CLASS=
|
|
67 |
//TESTED_FILES=
|
|
68 |
|
|
69 |
#include "qcommonstyle.h"
|
|
70 |
#include "qstyleoption.h"
|
|
71 |
|
|
72 |
QT_BEGIN_NAMESPACE
|
|
73 |
class QPainter;
|
|
74 |
QT_END_NAMESPACE
|
|
75 |
|
|
76 |
class StyleOptionTestStyle : public QCommonStyle
|
|
77 |
{
|
|
78 |
private:
|
|
79 |
bool readOnly;
|
|
80 |
|
|
81 |
public:
|
|
82 |
inline StyleOptionTestStyle() : QCommonStyle(), readOnly(false)
|
|
83 |
{
|
|
84 |
}
|
|
85 |
|
|
86 |
inline void setReadOnly(bool readOnly)
|
|
87 |
{
|
|
88 |
this->readOnly = readOnly;
|
|
89 |
}
|
|
90 |
|
|
91 |
inline void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *,
|
|
92 |
const QWidget *) const
|
|
93 |
{
|
|
94 |
switch (pe) {
|
|
95 |
case PE_PanelLineEdit:
|
|
96 |
if (readOnly)
|
|
97 |
QVERIFY(opt->state & QStyle::State_ReadOnly);
|
|
98 |
else
|
|
99 |
QVERIFY(!(opt->state & QStyle::State_ReadOnly));
|
|
100 |
break;
|
|
101 |
|
|
102 |
default:
|
|
103 |
break;
|
|
104 |
}
|
|
105 |
}
|
|
106 |
};
|
|
107 |
|
|
108 |
class tst_QLineEdit : public QObject
|
|
109 |
{
|
|
110 |
Q_OBJECT
|
|
111 |
|
|
112 |
public:
|
|
113 |
enum EventStates { Press, Release, Click };
|
|
114 |
|
|
115 |
tst_QLineEdit();
|
|
116 |
virtual ~tst_QLineEdit();
|
|
117 |
|
|
118 |
public slots:
|
|
119 |
void initTestCase();
|
|
120 |
void cleanupTestCase();
|
|
121 |
void init();
|
|
122 |
void cleanup();
|
|
123 |
private slots:
|
|
124 |
void getSetCheck();
|
|
125 |
void experimental();
|
|
126 |
|
|
127 |
void upperAndLowercase();
|
|
128 |
|
|
129 |
void setInputMask_data();
|
|
130 |
void setInputMask();
|
|
131 |
|
|
132 |
void inputMask_data();
|
|
133 |
void inputMask();
|
|
134 |
|
|
135 |
void clearInputMask();
|
|
136 |
|
|
137 |
void keypress_inputMask_data();
|
|
138 |
void keypress_inputMask();
|
|
139 |
|
|
140 |
void inputMaskAndValidator_data();
|
|
141 |
void inputMaskAndValidator();
|
|
142 |
|
|
143 |
void hasAcceptableInputMask_data();
|
|
144 |
void hasAcceptableInputMask();
|
|
145 |
|
|
146 |
void hasAcceptableInputValidator();
|
|
147 |
|
|
148 |
|
|
149 |
void redo_data();
|
|
150 |
void redo();
|
|
151 |
void isRedoAvailable();
|
|
152 |
|
|
153 |
void undo_data();
|
|
154 |
void undo();
|
|
155 |
void isUndoAvailable();
|
|
156 |
|
|
157 |
void undo_keypressevents_data();
|
|
158 |
void undo_keypressevents();
|
|
159 |
|
|
160 |
void clear();
|
|
161 |
|
|
162 |
void text_data();
|
|
163 |
void text();
|
|
164 |
void textMask_data();
|
|
165 |
void textMask();
|
|
166 |
void maskCharacter();
|
|
167 |
void maskCharacter_data();
|
|
168 |
void setText();
|
|
169 |
|
|
170 |
void displayText_data();
|
|
171 |
void displayText();
|
|
172 |
void setEchoMode();
|
|
173 |
void echoMode();
|
|
174 |
void passwordEchoOnEdit();
|
|
175 |
|
|
176 |
void maxLength_mask_data();
|
|
177 |
void maxLength_mask();
|
|
178 |
|
|
179 |
void maxLength_data();
|
|
180 |
void maxLength();
|
|
181 |
void setMaxLength();
|
|
182 |
|
|
183 |
void isReadOnly();
|
|
184 |
void setReadOnly();
|
|
185 |
|
|
186 |
void cursorPosition();
|
|
187 |
|
|
188 |
void cursorPositionChanged_data();
|
|
189 |
void cursorPositionChanged();
|
|
190 |
|
|
191 |
void selectedText();
|
|
192 |
void hasSelectedText();
|
|
193 |
void deleteSelectedText();
|
|
194 |
|
|
195 |
void textChangedAndTextEdited();
|
|
196 |
void returnPressed();
|
|
197 |
void returnPressed_maskvalidator_data();
|
|
198 |
void returnPressed_maskvalidator();
|
|
199 |
|
|
200 |
void setValidator();
|
|
201 |
void validator();
|
|
202 |
void clearValidator();
|
|
203 |
|
|
204 |
void setValidator_QIntValidator_data();
|
|
205 |
void setValidator_QIntValidator();
|
|
206 |
|
|
207 |
void frame_data();
|
|
208 |
void frame();
|
|
209 |
|
|
210 |
void leftKeyOnSelectedText();
|
|
211 |
|
|
212 |
void setAlignment_data();
|
|
213 |
void setAlignment();
|
|
214 |
void alignment();
|
|
215 |
|
|
216 |
void isModified();
|
|
217 |
void edited();
|
|
218 |
void setEdited();
|
|
219 |
|
|
220 |
void insert();
|
|
221 |
void setSelection_data();
|
|
222 |
void setSelection();
|
|
223 |
|
|
224 |
#ifndef QT_NO_CLIPBOARD
|
|
225 |
void cut();
|
|
226 |
void copy();
|
|
227 |
void paste();
|
|
228 |
#endif
|
|
229 |
void maxLengthAndInputMask();
|
|
230 |
void returnPressedKeyEvent();
|
|
231 |
|
|
232 |
void keepSelectionOnTabFocusIn();
|
|
233 |
|
|
234 |
void readOnlyStyleOption();
|
|
235 |
|
|
236 |
void validateOnFocusOut();
|
|
237 |
|
|
238 |
void editInvalidText();
|
|
239 |
|
|
240 |
void charWithAltOrCtrlModifier();
|
|
241 |
|
|
242 |
void inlineCompletion();
|
|
243 |
|
|
244 |
void noTextEditedOnClear();
|
|
245 |
|
|
246 |
void cursor();
|
|
247 |
|
|
248 |
void textMargin_data();
|
|
249 |
void textMargin();
|
|
250 |
|
|
251 |
// task-specific tests:
|
|
252 |
void task180999_focus();
|
|
253 |
void task174640_editingFinished();
|
|
254 |
#ifndef QT_NO_COMPLETER
|
|
255 |
void task198789_currentCompletion();
|
|
256 |
void task210502_caseInsensitiveInlineCompletion();
|
|
257 |
#endif
|
|
258 |
void task229938_dontEmitChangedWhenTextIsNotChanged();
|
|
259 |
void task233101_cursorPosAfterInputMethod_data();
|
|
260 |
void task233101_cursorPosAfterInputMethod();
|
|
261 |
void task241436_passwordEchoOnEditRestoreEchoMode();
|
|
262 |
void task248948_redoRemovedSelection();
|
|
263 |
|
|
264 |
protected slots:
|
|
265 |
#ifdef QT3_SUPPORT
|
|
266 |
void lostFocus();
|
|
267 |
#endif
|
|
268 |
void editingFinished();
|
|
269 |
|
|
270 |
void onTextChanged( const QString &newString );
|
|
271 |
void onTextEdited( const QString &newString );
|
|
272 |
void onReturnPressed();
|
|
273 |
void onSelectionChanged();
|
|
274 |
void onCursorPositionChanged(int oldpos, int newpos);
|
|
275 |
|
|
276 |
private:
|
|
277 |
// keyClicks(..) is moved to QtTestCase
|
|
278 |
void psKeyClick(QWidget *target, Qt::Key key, Qt::KeyboardModifiers pressState = 0);
|
|
279 |
void psKeyClick(QTestEventList &keys, Qt::Key key, Qt::KeyboardModifiers pressState = 0);
|
|
280 |
|
|
281 |
bool validInput;
|
|
282 |
QString changed_string;
|
|
283 |
int changed_count;
|
|
284 |
int edited_count;
|
|
285 |
int return_count;
|
|
286 |
int selection_count;
|
|
287 |
int lastCursorPos;
|
|
288 |
int newCursorPos;
|
|
289 |
QLineEdit *testWidget;
|
|
290 |
};
|
|
291 |
|
|
292 |
typedef QList<int> IntList;
|
|
293 |
Q_DECLARE_METATYPE(IntList)
|
|
294 |
Q_DECLARE_METATYPE(QLineEdit::EchoMode)
|
|
295 |
|
|
296 |
// Testing get/set functions
|
|
297 |
void tst_QLineEdit::getSetCheck()
|
|
298 |
{
|
|
299 |
QLineEdit obj1;
|
|
300 |
// const QValidator * QLineEdit::validator()
|
|
301 |
// void QLineEdit::setValidator(const QValidator *)
|
|
302 |
QIntValidator *var1 = new QIntValidator(0);
|
|
303 |
obj1.setValidator(var1);
|
|
304 |
QCOMPARE((const QValidator *)var1, obj1.validator());
|
|
305 |
obj1.setValidator((QValidator *)0);
|
|
306 |
QCOMPARE((const QValidator *)0, obj1.validator());
|
|
307 |
delete var1;
|
|
308 |
|
|
309 |
// bool QLineEdit::dragEnabled()
|
|
310 |
// void QLineEdit::setDragEnabled(bool)
|
|
311 |
obj1.setDragEnabled(false);
|
|
312 |
QCOMPARE(false, obj1.dragEnabled());
|
|
313 |
obj1.setDragEnabled(true);
|
|
314 |
QCOMPARE(true, obj1.dragEnabled());
|
|
315 |
}
|
|
316 |
|
|
317 |
tst_QLineEdit::tst_QLineEdit()
|
|
318 |
{
|
|
319 |
validInput = false;
|
|
320 |
}
|
|
321 |
|
|
322 |
tst_QLineEdit::~tst_QLineEdit()
|
|
323 |
{
|
|
324 |
}
|
|
325 |
|
|
326 |
void tst_QLineEdit::initTestCase()
|
|
327 |
{
|
|
328 |
testWidget = new QLineEdit(0);
|
|
329 |
testWidget->setObjectName("testWidget");
|
|
330 |
connect(testWidget, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(onCursorPositionChanged(int, int)));
|
|
331 |
connect(testWidget, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
|
|
332 |
connect(testWidget, SIGNAL(textEdited(const QString&)), this, SLOT(onTextEdited(const QString&)));
|
|
333 |
connect(testWidget, SIGNAL(returnPressed()), this, SLOT(onReturnPressed()));
|
|
334 |
connect(testWidget, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
|
|
335 |
connect(testWidget, SIGNAL(editingFinished()), this, SLOT(editingFinished()));
|
|
336 |
#ifdef QT3_SUPPORT
|
|
337 |
connect(testWidget, SIGNAL(lostFocus()), this, SLOT(lostFocus()));
|
|
338 |
#endif
|
|
339 |
|
|
340 |
testWidget->resize(200,50);
|
|
341 |
testWidget->show();
|
|
342 |
QApplication::setActiveWindow(testWidget);
|
|
343 |
#ifdef Q_WS_X11
|
|
344 |
// to be safe and avoid failing setFocus with window managers
|
|
345 |
qt_x11_wait_for_window_manager(testWidget);
|
|
346 |
#endif
|
|
347 |
QTRY_VERIFY(testWidget->hasFocus());
|
|
348 |
|
|
349 |
changed_count = 0;
|
|
350 |
edited_count = 0;
|
|
351 |
selection_count = 0;
|
|
352 |
}
|
|
353 |
|
|
354 |
void tst_QLineEdit::cleanupTestCase()
|
|
355 |
{
|
|
356 |
delete testWidget;
|
|
357 |
}
|
|
358 |
|
|
359 |
void tst_QLineEdit::init()
|
|
360 |
{
|
|
361 |
return_count = 0;
|
|
362 |
testWidget->clear();
|
|
363 |
testWidget->setEchoMode(QLineEdit::Normal);
|
|
364 |
testWidget->setMaxLength(32767);
|
|
365 |
testWidget->setReadOnly(false);
|
|
366 |
testWidget->setText("");
|
|
367 |
testWidget->setInputMask("");
|
|
368 |
testWidget->setFrame(true);
|
|
369 |
testWidget->setValidator(0);
|
|
370 |
testWidget->setDragEnabled(true);
|
|
371 |
}
|
|
372 |
|
|
373 |
void tst_QLineEdit::cleanup()
|
|
374 |
{
|
|
375 |
}
|
|
376 |
|
|
377 |
void tst_QLineEdit::experimental()
|
|
378 |
{
|
|
379 |
QIntValidator intValidator(3, 7, 0);
|
|
380 |
testWidget->setValidator(&intValidator);
|
|
381 |
testWidget->setText("");
|
|
382 |
|
|
383 |
|
|
384 |
// test the order of setting these
|
|
385 |
testWidget->setInputMask("");
|
|
386 |
testWidget->setText("abc123");
|
|
387 |
testWidget->setInputMask("000.000.000.000");
|
|
388 |
QCOMPARE(testWidget->text(), QString("123..."));
|
|
389 |
testWidget->setText("");
|
|
390 |
|
|
391 |
|
|
392 |
}
|
|
393 |
|
|
394 |
void tst_QLineEdit::upperAndLowercase()
|
|
395 |
{
|
|
396 |
testWidget->setInputMask("");
|
|
397 |
testWidget->setText("");
|
|
398 |
|
|
399 |
QTest::keyClicks(testWidget, "aAzZ`1234567890-=~!@#$%^&*()_+[]{}\\|;:'\",.<>/?");
|
|
400 |
qApp->processEvents();
|
|
401 |
QCOMPARE(testWidget->text(), QString("aAzZ`1234567890-=~!@#$%^&*()_+[]{}\\|;:'\",.<>/?"));
|
|
402 |
}
|
|
403 |
|
|
404 |
void tst_QLineEdit::setInputMask_data()
|
|
405 |
{
|
|
406 |
QTest::addColumn<QString>("mask");
|
|
407 |
QTest::addColumn<QString>("input");
|
|
408 |
QTest::addColumn<QString>("expectedText");
|
|
409 |
QTest::addColumn<QString>("expectedDisplay");
|
|
410 |
QTest::addColumn<bool>("insert_text");
|
|
411 |
|
|
412 |
// both keyboard and insert()
|
|
413 |
for (int i=0; i<2; i++) {
|
|
414 |
bool insert_text = i==0 ? false : true;
|
|
415 |
QString insert_mode = "keys ";
|
|
416 |
if (insert_text)
|
|
417 |
insert_mode = "insert ";
|
|
418 |
|
|
419 |
QTest::newRow(QString(insert_mode + "ip_localhost").toLatin1())
|
|
420 |
<< QString("000.000.000.000")
|
|
421 |
<< QString("127.0.0.1")
|
|
422 |
<< QString("127.0.0.1")
|
|
423 |
<< QString("127.0 .0 .1 ")
|
|
424 |
<< bool(insert_text);
|
|
425 |
QTest::newRow(QString(insert_mode + "mac").toLatin1())
|
|
426 |
<< QString("HH:HH:HH:HH:HH:HH;#")
|
|
427 |
<< QString("00:E0:81:21:9E:8E")
|
|
428 |
<< QString("00:E0:81:21:9E:8E")
|
|
429 |
<< QString("00:E0:81:21:9E:8E")
|
|
430 |
<< bool(insert_text);
|
|
431 |
QTest::newRow(QString(insert_mode + "mac2").toLatin1())
|
|
432 |
<< QString("<HH:>HH:!HH:HH:HH:HH;#")
|
|
433 |
<< QString("AAe081219E8E")
|
|
434 |
<< QString("aa:E0:81:21:9E:8E")
|
|
435 |
<< QString("aa:E0:81:21:9E:8E")
|
|
436 |
<< bool(insert_text);
|
|
437 |
QTest::newRow(QString(insert_mode + "byte").toLatin1())
|
|
438 |
<< QString("BBBBBBBB;0")
|
|
439 |
<< QString("11011001")
|
|
440 |
<< QString("11111")
|
|
441 |
<< QString("11011001")
|
|
442 |
<< bool(insert_text);
|
|
443 |
QTest::newRow(QString(insert_mode + "halfbytes").toLatin1())
|
|
444 |
<< QString("bbbb.bbbb;-")
|
|
445 |
<< QString("110. 0001")
|
|
446 |
<< QString("110.0001")
|
|
447 |
<< QString("110-.0001")
|
|
448 |
<< bool(insert_text);
|
|
449 |
QTest::newRow(QString(insert_mode + "blank char same type as content").toLatin1())
|
|
450 |
<< QString("000.000.000.000;0")
|
|
451 |
<< QString("127.0.0.1")
|
|
452 |
<< QString("127...1")
|
|
453 |
<< QString("127.000.000.100")
|
|
454 |
<< bool(insert_text);
|
|
455 |
QTest::newRow(QString(insert_mode + "parts of ip_localhost").toLatin1())
|
|
456 |
<< QString("000.000.000.000")
|
|
457 |
<< QString(".0.0.1")
|
|
458 |
<< QString(".0.0.1")
|
|
459 |
<< QString(" .0 .0 .1 ")
|
|
460 |
<< bool(insert_text);
|
|
461 |
QTest::newRow(QString(insert_mode + "ip_null").toLatin1())
|
|
462 |
<< QString("000.000.000.000")
|
|
463 |
<< QString()
|
|
464 |
<< QString("...")
|
|
465 |
<< QString(" . . . ")
|
|
466 |
<< bool(insert_text);
|
|
467 |
QTest::newRow(QString(insert_mode + "ip_null_hash").toLatin1())
|
|
468 |
<< QString("000.000.000.000;#")
|
|
469 |
<< QString()
|
|
470 |
<< QString("...")
|
|
471 |
<< QString("###.###.###.###")
|
|
472 |
<< bool(insert_text);
|
|
473 |
QTest::newRow(QString(insert_mode + "ip_overflow").toLatin1())
|
|
474 |
<< QString("000.000.000.000")
|
|
475 |
<< QString("1234123412341234")
|
|
476 |
<< QString("123.412.341.234")
|
|
477 |
<< QString("123.412.341.234")
|
|
478 |
<< bool(insert_text);
|
|
479 |
QTest::newRow(QString(insert_mode + "uppercase").toLatin1())
|
|
480 |
<< QString(">AAAA")
|
|
481 |
<< QString("AbCd")
|
|
482 |
<< QString("ABCD")
|
|
483 |
<< QString("ABCD")
|
|
484 |
<< bool(insert_text);
|
|
485 |
QTest::newRow(QString(insert_mode + "lowercase").toLatin1())
|
|
486 |
<< QString("<AAAA")
|
|
487 |
<< QString("AbCd")
|
|
488 |
<< QString("abcd")
|
|
489 |
<< QString("abcd")
|
|
490 |
<< bool(insert_text);
|
|
491 |
|
|
492 |
QTest::newRow(QString(insert_mode + "nocase").toLatin1())
|
|
493 |
<< QString("!AAAA")
|
|
494 |
<< QString("AbCd")
|
|
495 |
<< QString("AbCd")
|
|
496 |
<< QString("AbCd")
|
|
497 |
<< bool(insert_text);
|
|
498 |
QTest::newRow(QString(insert_mode + "nocase1").toLatin1())
|
|
499 |
<< QString("!A!A!A!A")
|
|
500 |
<< QString("AbCd")
|
|
501 |
<< QString("AbCd")
|
|
502 |
<< QString("AbCd")
|
|
503 |
<< bool(insert_text);
|
|
504 |
QTest::newRow(QString(insert_mode + "nocase2").toLatin1())
|
|
505 |
<< QString("AAAA")
|
|
506 |
<< QString("AbCd")
|
|
507 |
<< QString("AbCd")
|
|
508 |
<< QString("AbCd")
|
|
509 |
<< bool(insert_text);
|
|
510 |
|
|
511 |
QTest::newRow(QString(insert_mode + "reserved").toLatin1())
|
|
512 |
<< QString("{n}[0]")
|
|
513 |
<< QString("A9")
|
|
514 |
<< QString("A9")
|
|
515 |
<< QString("A9")
|
|
516 |
<< bool(insert_text);
|
|
517 |
QTest::newRow(QString(insert_mode + "escape01").toLatin1())
|
|
518 |
<< QString("\\N\\n00")
|
|
519 |
<< QString("9")
|
|
520 |
<< QString("Nn9")
|
|
521 |
<< QString("Nn9 ")
|
|
522 |
<< bool(insert_text);
|
|
523 |
QTest::newRow(QString(insert_mode + "escape02").toLatin1())
|
|
524 |
<< QString("\\\\00")
|
|
525 |
<< QString("0")
|
|
526 |
<< QString("\\0")
|
|
527 |
<< QString("\\0 ")
|
|
528 |
<< bool(insert_text);
|
|
529 |
QTest::newRow(QString(insert_mode + "escape03").toLatin1())
|
|
530 |
<< QString("\\(00\\)")
|
|
531 |
<< QString("0")
|
|
532 |
<< QString("(0)")
|
|
533 |
<< QString("(0 )")
|
|
534 |
<< bool(insert_text);
|
|
535 |
|
|
536 |
QTest::newRow(QString(insert_mode + "upper_lower_nocase1").toLatin1())
|
|
537 |
<< QString(">AAAA<AAAA!AAAA")
|
|
538 |
<< QString("AbCdEfGhIjKl")
|
|
539 |
<< QString("ABCDefghIjKl")
|
|
540 |
<< QString("ABCDefghIjKl")
|
|
541 |
<< bool(insert_text);
|
|
542 |
QTest::newRow(QString(insert_mode + "upper_lower_nocase2").toLatin1())
|
|
543 |
<< QString(">aaaa<aaaa!aaaa")
|
|
544 |
<< QString("AbCdEfGhIjKl")
|
|
545 |
<< QString("ABCDefghIjKl")
|
|
546 |
<< QString("ABCDefghIjKl")
|
|
547 |
<< bool(insert_text);
|
|
548 |
|
|
549 |
QTest::newRow(QString(insert_mode + "exact_case1").toLatin1())
|
|
550 |
<< QString(">A<A<A>A>A<A!A!A")
|
|
551 |
<< QString("AbCdEFGH")
|
|
552 |
<< QString("AbcDEfGH")
|
|
553 |
<< QString("AbcDEfGH")
|
|
554 |
<< bool(insert_text);
|
|
555 |
QTest::newRow(QString(insert_mode + "exact_case2").toLatin1())
|
|
556 |
<< QString(">A<A<A>A>A<A!A!A")
|
|
557 |
<< QString("aBcDefgh")
|
|
558 |
<< QString("AbcDEfgh")
|
|
559 |
<< QString("AbcDEfgh")
|
|
560 |
<< bool(insert_text);
|
|
561 |
QTest::newRow(QString(insert_mode + "exact_case3").toLatin1())
|
|
562 |
<< QString(">a<a<a>a>a<a!a!a")
|
|
563 |
<< QString("AbCdEFGH")
|
|
564 |
<< QString("AbcDEfGH")
|
|
565 |
<< QString("AbcDEfGH")
|
|
566 |
<< bool(insert_text);
|
|
567 |
QTest::newRow(QString(insert_mode + "exact_case4").toLatin1())
|
|
568 |
<< QString(">a<a<a>a>a<a!a!a")
|
|
569 |
<< QString("aBcDefgh")
|
|
570 |
<< QString("AbcDEfgh")
|
|
571 |
<< QString("AbcDEfgh")
|
|
572 |
<< bool(insert_text);
|
|
573 |
QTest::newRow(QString(insert_mode + "exact_case5").toLatin1())
|
|
574 |
<< QString(">H<H<H>H>H<H!H!H")
|
|
575 |
<< QString("aBcDef01")
|
|
576 |
<< QString("AbcDEf01")
|
|
577 |
<< QString("AbcDEf01")
|
|
578 |
<< bool(insert_text);
|
|
579 |
QTest::newRow(QString(insert_mode + "exact_case6").toLatin1())
|
|
580 |
<< QString(">h<h<h>h>h<h!h!h")
|
|
581 |
<< QString("aBcDef92")
|
|
582 |
<< QString("AbcDEf92")
|
|
583 |
<< QString("AbcDEf92")
|
|
584 |
<< bool(insert_text);
|
|
585 |
|
|
586 |
QTest::newRow(QString(insert_mode + "illegal_keys1").toLatin1())
|
|
587 |
<< QString("AAAAAAAA")
|
|
588 |
<< QString("A2#a;.0!")
|
|
589 |
<< QString("Aa")
|
|
590 |
<< QString("Aa ")
|
|
591 |
<< bool(insert_text);
|
|
592 |
QTest::newRow(QString(insert_mode + "illegal_keys2").toLatin1())
|
|
593 |
<< QString("AAAA")
|
|
594 |
<< QString("f4f4f4f4")
|
|
595 |
<< QString("ffff")
|
|
596 |
<< QString("ffff")
|
|
597 |
<< bool(insert_text);
|
|
598 |
QTest::newRow(QString(insert_mode + "blank=input").toLatin1())
|
|
599 |
<< QString("9999;0")
|
|
600 |
<< QString("2004")
|
|
601 |
<< QString("2004")
|
|
602 |
<< QString("2004")
|
|
603 |
<< bool(insert_text);
|
|
604 |
}
|
|
605 |
}
|
|
606 |
|
|
607 |
void tst_QLineEdit::setInputMask()
|
|
608 |
{
|
|
609 |
QFETCH(QString, mask);
|
|
610 |
QFETCH(QString, input);
|
|
611 |
QFETCH(QString, expectedText);
|
|
612 |
QFETCH(QString, expectedDisplay);
|
|
613 |
QFETCH(bool, insert_text);
|
|
614 |
|
|
615 |
QEXPECT_FAIL( "keys blank=input", "To eat blanks or not? Known issue. Task 43172", Abort);
|
|
616 |
QEXPECT_FAIL( "insert blank=input", "To eat blanks or not? Known issue. Task 43172", Abort);
|
|
617 |
|
|
618 |
// First set the input mask
|
|
619 |
testWidget->setInputMask(mask);
|
|
620 |
|
|
621 |
// then either insert using insert() or keyboard
|
|
622 |
if (insert_text) {
|
|
623 |
testWidget->insert(input);
|
|
624 |
} else {
|
|
625 |
psKeyClick(testWidget, Qt::Key_Home);
|
|
626 |
for (int i=0; i<input.length(); i++)
|
|
627 |
QTest::keyClick(testWidget, input.at(i).toLatin1());
|
|
628 |
}
|
|
629 |
|
|
630 |
QCOMPARE(testWidget->text(), expectedText);
|
|
631 |
QCOMPARE(testWidget->displayText(), expectedDisplay);
|
|
632 |
}
|
|
633 |
|
|
634 |
void tst_QLineEdit::inputMask_data()
|
|
635 |
{
|
|
636 |
QTest::addColumn<QString>("mask");
|
|
637 |
QTest::addColumn<QString>("expectedMask");
|
|
638 |
|
|
639 |
// if no mask is set a nul string should be returned
|
|
640 |
QTest::newRow("") << QString("") << QString();
|
|
641 |
QTest::newRow("") << QString() << QString();
|
|
642 |
|
|
643 |
// try different masks
|
|
644 |
QTest::newRow("") << QString("000.000.000.000") << QString("000.000.000.000; ");
|
|
645 |
QTest::newRow("") << QString("000.000.000.000;#") << QString("000.000.000.000;#");
|
|
646 |
QTest::newRow("") << QString("AAA.aa.999.###;") << QString("AAA.aa.999.###; ");
|
|
647 |
QTest::newRow("") << QString(">abcdef<GHIJK") << QString(">abcdef<GHIJK; ");
|
|
648 |
// QTest::newRow("") << QString() << QString();
|
|
649 |
|
|
650 |
// set an invalid input mask...
|
|
651 |
// the current behaviour is that this exact (faulty) string is returned.
|
|
652 |
QTest::newRow("") << QString("ABCDEFGHIKLMNOP;") << QString("ABCDEFGHIKLMNOP; ");
|
|
653 |
|
|
654 |
// verify that we can unset the mask again
|
|
655 |
QTest::newRow("") << QString("") << QString();
|
|
656 |
}
|
|
657 |
|
|
658 |
void tst_QLineEdit::inputMask()
|
|
659 |
{
|
|
660 |
QFETCH(QString, mask);
|
|
661 |
QFETCH(QString, expectedMask);
|
|
662 |
|
|
663 |
testWidget->setInputMask(mask);
|
|
664 |
QCOMPARE(testWidget->inputMask(), expectedMask);
|
|
665 |
}
|
|
666 |
|
|
667 |
void tst_QLineEdit::clearInputMask()
|
|
668 |
{
|
|
669 |
testWidget->setInputMask("000.000.000.000");
|
|
670 |
QVERIFY(testWidget->inputMask() != QString::null);
|
|
671 |
testWidget->setInputMask(QString::null);
|
|
672 |
QCOMPARE(testWidget->inputMask(), QString());
|
|
673 |
}
|
|
674 |
|
|
675 |
void tst_QLineEdit::keypress_inputMask_data()
|
|
676 |
{
|
|
677 |
QTest::addColumn<QString>("mask");
|
|
678 |
QTest::addColumn<QTestEventList>("keys");
|
|
679 |
QTest::addColumn<QString>("expectedText");
|
|
680 |
QTest::addColumn<QString>("expectedDisplayText");
|
|
681 |
|
|
682 |
{
|
|
683 |
QTestEventList keys;
|
|
684 |
// inserting 'A1.2B'
|
|
685 |
keys.addKeyClick(Qt::Key_Home);
|
|
686 |
keys.addKeyClick(Qt::Key_A);
|
|
687 |
keys.addKeyClick(Qt::Key_1);
|
|
688 |
keys.addKeyClick(Qt::Key_Period);
|
|
689 |
keys.addKeyClick(Qt::Key_2);
|
|
690 |
keys.addKeyClick(Qt::Key_B);
|
|
691 |
QTest::newRow("jumping on period(separator)") << QString("000.000;_") << keys << QString("1.2") << QString("1__.2__");
|
|
692 |
}
|
|
693 |
{
|
|
694 |
QTestEventList keys;
|
|
695 |
// inserting 'A1.2B'
|
|
696 |
keys.addKeyClick(Qt::Key_Home);
|
|
697 |
keys.addKeyClick(Qt::Key_0);
|
|
698 |
keys.addKeyClick(Qt::Key_Exclam);
|
|
699 |
keys.addKeyClick('P');
|
|
700 |
keys.addKeyClick(Qt::Key_3);
|
|
701 |
QTest::newRow("jumping on input") << QString("D0.AA.XX.AA.00;_") << keys << QString("0..!P..3") << QString("_0.__.!P.__.3_");
|
|
702 |
}
|
|
703 |
{
|
|
704 |
QTestEventList keys;
|
|
705 |
// pressing delete
|
|
706 |
keys.addKeyClick(Qt::Key_Home);
|
|
707 |
keys.addKeyClick(Qt::Key_Delete);
|
|
708 |
QTest::newRow("delete") << QString("000.000;_") << keys << QString(".") << QString("___.___");
|
|
709 |
}
|
|
710 |
{
|
|
711 |
QTestEventList keys;
|
|
712 |
// selecting all and delete
|
|
713 |
keys.addKeyClick(Qt::Key_Home);
|
|
714 |
keys.addKeyClick(Qt::Key_End, Qt::ShiftModifier);
|
|
715 |
keys.addKeyClick(Qt::Key_Delete);
|
|
716 |
QTest::newRow("deleting all") << QString("000.000;_") << keys << QString(".") << QString("___.___");
|
|
717 |
}
|
|
718 |
{
|
|
719 |
QTestEventList keys;
|
|
720 |
// inserting '12.12' then two backspaces
|
|
721 |
keys.addKeyClick(Qt::Key_Home);
|
|
722 |
keys.addKeyClick(Qt::Key_1);
|
|
723 |
keys.addKeyClick(Qt::Key_2);
|
|
724 |
keys.addKeyClick(Qt::Key_Period);
|
|
725 |
keys.addKeyClick(Qt::Key_1);
|
|
726 |
keys.addKeyClick(Qt::Key_2);
|
|
727 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
728 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
729 |
QTest::newRow("backspace") << QString("000.000;_") << keys << QString("12.") << QString("12_.___");
|
|
730 |
}
|
|
731 |
{
|
|
732 |
QTestEventList keys;
|
|
733 |
// inserting '12ab'
|
|
734 |
keys.addKeyClick(Qt::Key_Home);
|
|
735 |
keys.addKeyClick(Qt::Key_1);
|
|
736 |
keys.addKeyClick(Qt::Key_2);
|
|
737 |
keys.addKeyClick(Qt::Key_A);
|
|
738 |
keys.addKeyClick(Qt::Key_B);
|
|
739 |
QTest::newRow("uppercase") << QString("9999 >AA;_") << keys << QString("12 AB") << QString("12__ AB");
|
|
740 |
}
|
|
741 |
}
|
|
742 |
|
|
743 |
void tst_QLineEdit::keypress_inputMask()
|
|
744 |
{
|
|
745 |
QFETCH(QString, mask);
|
|
746 |
QFETCH(QTestEventList, keys);
|
|
747 |
QFETCH(QString, expectedText);
|
|
748 |
QFETCH(QString, expectedDisplayText);
|
|
749 |
|
|
750 |
testWidget->setInputMask(mask);
|
|
751 |
keys.simulate(testWidget);
|
|
752 |
|
|
753 |
QCOMPARE(testWidget->text(), expectedText);
|
|
754 |
QCOMPARE(testWidget->displayText(), expectedDisplayText);
|
|
755 |
}
|
|
756 |
|
|
757 |
|
|
758 |
void tst_QLineEdit::hasAcceptableInputMask_data()
|
|
759 |
{
|
|
760 |
QTest::addColumn<QString>("optionalMask");
|
|
761 |
QTest::addColumn<QString>("requiredMask");
|
|
762 |
QTest::addColumn<QString>("invalid");
|
|
763 |
QTest::addColumn<QString>("valid");
|
|
764 |
|
|
765 |
QTest::newRow("Alphabetic optional and required")
|
|
766 |
<< QString("aaaa") << QString("AAAA") << QString("ab") << QString("abcd");
|
|
767 |
QTest::newRow("Alphanumeric optional and require")
|
|
768 |
<< QString("nnnn") << QString("NNNN") << QString("R2") << QString("R2D2");
|
|
769 |
QTest::newRow("Any optional and required")
|
|
770 |
<< QString("xxxx") << QString("XXXX") << QString("+-") << QString("+-*/");
|
|
771 |
QTest::newRow("Numeric (0-9) required")
|
|
772 |
<< QString("0000") << QString("9999") << QString("11") << QString("1138");
|
|
773 |
QTest::newRow("Numeric (1-9) optional and required")
|
|
774 |
<< QString("dddd") << QString("DDDD") << QString("12") << QString("1234");
|
|
775 |
}
|
|
776 |
|
|
777 |
void tst_QLineEdit::hasAcceptableInputMask()
|
|
778 |
{
|
|
779 |
QFocusEvent lostFocus(QEvent::FocusOut);
|
|
780 |
QFETCH(QString, optionalMask);
|
|
781 |
QFETCH(QString, requiredMask);
|
|
782 |
QFETCH(QString, invalid);
|
|
783 |
QFETCH(QString, valid);
|
|
784 |
|
|
785 |
// test that invalid input (for required) work for optionalMask
|
|
786 |
testWidget->setInputMask(optionalMask);
|
|
787 |
validInput = false;
|
|
788 |
testWidget->setText(invalid);
|
|
789 |
qApp->sendEvent(testWidget, &lostFocus);
|
|
790 |
QVERIFY(validInput);
|
|
791 |
|
|
792 |
// at the moment we don't strip the blank character if it is valid input, this makes the test between x vs X useless
|
|
793 |
QEXPECT_FAIL( "Any optional and required", "To eat blanks or not? Known issue. Task 43172", Abort);
|
|
794 |
|
|
795 |
// test requiredMask
|
|
796 |
testWidget->setInputMask(requiredMask);
|
|
797 |
validInput = true;
|
|
798 |
testWidget->setText(invalid);
|
|
799 |
validInput = testWidget->hasAcceptableInput();
|
|
800 |
QVERIFY(!validInput);
|
|
801 |
|
|
802 |
validInput = false;
|
|
803 |
testWidget->setText(valid);
|
|
804 |
qApp->sendEvent(testWidget, &lostFocus);
|
|
805 |
QVERIFY(validInput);
|
|
806 |
}
|
|
807 |
|
|
808 |
static const int chars = 8;
|
|
809 |
class ValidatorWithFixup : public QValidator
|
|
810 |
{
|
|
811 |
public:
|
|
812 |
ValidatorWithFixup(QWidget *parent = 0)
|
|
813 |
: QValidator(parent)
|
|
814 |
{}
|
|
815 |
|
|
816 |
QValidator::State validate(QString &str, int &) const
|
|
817 |
{
|
|
818 |
const int s = str.size();
|
|
819 |
if (s < chars) {
|
|
820 |
return Intermediate;
|
|
821 |
} else if (s > chars) {
|
|
822 |
return Invalid;
|
|
823 |
}
|
|
824 |
return Acceptable;
|
|
825 |
}
|
|
826 |
|
|
827 |
void fixup(QString &str) const
|
|
828 |
{
|
|
829 |
str = str.leftJustified(chars, 'X', true);
|
|
830 |
}
|
|
831 |
};
|
|
832 |
|
|
833 |
|
|
834 |
|
|
835 |
void tst_QLineEdit::hasAcceptableInputValidator()
|
|
836 |
{
|
|
837 |
QFocusEvent lostFocus(QEvent::FocusOut);
|
|
838 |
ValidatorWithFixup val;
|
|
839 |
testWidget->setValidator(&val);
|
|
840 |
testWidget->setText("foobar");
|
|
841 |
qApp->sendEvent(testWidget, &lostFocus);
|
|
842 |
QVERIFY(testWidget->hasAcceptableInput());
|
|
843 |
}
|
|
844 |
|
|
845 |
|
|
846 |
|
|
847 |
void tst_QLineEdit::maskCharacter_data()
|
|
848 |
{
|
|
849 |
QTest::addColumn<QString>("mask");
|
|
850 |
QTest::addColumn<QString>("input");
|
|
851 |
QTest::addColumn<bool>("expectedValid");
|
|
852 |
|
|
853 |
QTest::newRow("Hex") << QString("H")
|
|
854 |
<< QString("0123456789abcdefABCDEF") << true;
|
|
855 |
QTest::newRow("hex") << QString("h")
|
|
856 |
<< QString("0123456789abcdefABCDEF") << true;
|
|
857 |
QTest::newRow("HexInvalid") << QString("H")
|
|
858 |
<< QString("ghijklmnopqrstuvwxyzGHIJKLMNOPQRSTUVWXYZ")
|
|
859 |
<< false;
|
|
860 |
QTest::newRow("hexInvalid") << QString("h")
|
|
861 |
<< QString("ghijklmnopqrstuvwxyzGHIJKLMNOPQRSTUVWXYZ")
|
|
862 |
<< false;
|
|
863 |
QTest::newRow("Bin") << QString("B")
|
|
864 |
<< QString("01") << true;
|
|
865 |
QTest::newRow("bin") << QString("b")
|
|
866 |
<< QString("01") << true;
|
|
867 |
QTest::newRow("BinInvalid") << QString("B")
|
|
868 |
<< QString("23456789qwertyuiopasdfghjklzxcvbnm")
|
|
869 |
<< false;
|
|
870 |
QTest::newRow("binInvalid") << QString("b")
|
|
871 |
<< QString("23456789qwertyuiopasdfghjklzxcvbnm")
|
|
872 |
<< false;
|
|
873 |
}
|
|
874 |
|
|
875 |
void tst_QLineEdit::maskCharacter()
|
|
876 |
{
|
|
877 |
QFETCH(QString, mask);
|
|
878 |
QFETCH(QString, input);
|
|
879 |
QFETCH(bool, expectedValid);
|
|
880 |
|
|
881 |
QFocusEvent lostFocus(QEvent::FocusOut);
|
|
882 |
|
|
883 |
testWidget->setInputMask(mask);
|
|
884 |
for (int i = 0; i < input.size(); ++i) {
|
|
885 |
QString in = QString(input.at(i));
|
|
886 |
QString expected = expectedValid ? in : QString();
|
|
887 |
testWidget->setText(QString(input.at(i)));
|
|
888 |
qApp->sendEvent(testWidget, &lostFocus);
|
|
889 |
QCOMPARE(testWidget->text(), expected);
|
|
890 |
}
|
|
891 |
}
|
|
892 |
|
|
893 |
#define NORMAL 0
|
|
894 |
#define REPLACE_UNTIL_END 1
|
|
895 |
|
|
896 |
void tst_QLineEdit::undo_data()
|
|
897 |
{
|
|
898 |
QTest::addColumn<QStringList>("insertString");
|
|
899 |
QTest::addColumn<IntList>("insertIndex");
|
|
900 |
QTest::addColumn<IntList>("insertMode");
|
|
901 |
QTest::addColumn<QStringList>("expectedString");
|
|
902 |
QTest::addColumn<bool>("use_keys");
|
|
903 |
|
|
904 |
for (int i=0; i<2; i++) {
|
|
905 |
QString keys_str = "keyboard";
|
|
906 |
bool use_keys = true;
|
|
907 |
if (i==0) {
|
|
908 |
keys_str = "insert";
|
|
909 |
use_keys = false;
|
|
910 |
}
|
|
911 |
|
|
912 |
{
|
|
913 |
IntList insertIndex;
|
|
914 |
IntList insertMode;
|
|
915 |
QStringList insertString;
|
|
916 |
QStringList expectedString;
|
|
917 |
|
|
918 |
insertIndex << -1;
|
|
919 |
insertMode << NORMAL;
|
|
920 |
insertString << "1";
|
|
921 |
|
|
922 |
insertIndex << -1;
|
|
923 |
insertMode << NORMAL;
|
|
924 |
insertString << "5";
|
|
925 |
|
|
926 |
insertIndex << 1;
|
|
927 |
insertMode << NORMAL;
|
|
928 |
insertString << "3";
|
|
929 |
|
|
930 |
insertIndex << 1;
|
|
931 |
insertMode << NORMAL;
|
|
932 |
insertString << "2";
|
|
933 |
|
|
934 |
insertIndex << 3;
|
|
935 |
insertMode << NORMAL;
|
|
936 |
insertString << "4";
|
|
937 |
|
|
938 |
expectedString << "12345";
|
|
939 |
expectedString << "1235";
|
|
940 |
expectedString << "135";
|
|
941 |
expectedString << "15";
|
|
942 |
expectedString << "";
|
|
943 |
|
|
944 |
QTest::newRow(QString(keys_str + "_numbers").toLatin1()) <<
|
|
945 |
insertString <<
|
|
946 |
insertIndex <<
|
|
947 |
insertMode <<
|
|
948 |
expectedString <<
|
|
949 |
bool(use_keys);
|
|
950 |
}
|
|
951 |
{
|
|
952 |
IntList insertIndex;
|
|
953 |
IntList insertMode;
|
|
954 |
QStringList insertString;
|
|
955 |
QStringList expectedString;
|
|
956 |
|
|
957 |
insertIndex << -1;
|
|
958 |
insertMode << NORMAL;
|
|
959 |
insertString << "World"; // World
|
|
960 |
|
|
961 |
insertIndex << 0;
|
|
962 |
insertMode << NORMAL;
|
|
963 |
insertString << "Hello"; // HelloWorld
|
|
964 |
|
|
965 |
insertIndex << 0;
|
|
966 |
insertMode << NORMAL;
|
|
967 |
insertString << "Well"; // WellHelloWorld
|
|
968 |
|
|
969 |
insertIndex << 9;
|
|
970 |
insertMode << NORMAL;
|
|
971 |
insertString << "There"; // WellHelloThereWorld;
|
|
972 |
|
|
973 |
expectedString << "WellHelloThereWorld";
|
|
974 |
expectedString << "WellHelloWorld";
|
|
975 |
expectedString << "HelloWorld";
|
|
976 |
expectedString << "World";
|
|
977 |
expectedString << "";
|
|
978 |
|
|
979 |
QTest::newRow(QString(keys_str + "_helloworld").toLatin1()) <<
|
|
980 |
insertString <<
|
|
981 |
insertIndex <<
|
|
982 |
insertMode <<
|
|
983 |
expectedString <<
|
|
984 |
bool(use_keys);
|
|
985 |
}
|
|
986 |
{
|
|
987 |
IntList insertIndex;
|
|
988 |
IntList insertMode;
|
|
989 |
QStringList insertString;
|
|
990 |
QStringList expectedString;
|
|
991 |
|
|
992 |
insertIndex << -1;
|
|
993 |
insertMode << NORMAL;
|
|
994 |
insertString << "Ensuring";
|
|
995 |
|
|
996 |
insertIndex << -1;
|
|
997 |
insertMode << NORMAL;
|
|
998 |
insertString << " instan";
|
|
999 |
|
|
1000 |
insertIndex << 9;
|
|
1001 |
insertMode << NORMAL;
|
|
1002 |
insertString << "an ";
|
|
1003 |
|
|
1004 |
insertIndex << 10;
|
|
1005 |
insertMode << REPLACE_UNTIL_END;
|
|
1006 |
insertString << " unique instance.";
|
|
1007 |
|
|
1008 |
expectedString << "Ensuring a unique instance.";
|
|
1009 |
expectedString << "Ensuring an instan";
|
|
1010 |
expectedString << "Ensuring instan";
|
|
1011 |
expectedString << "";
|
|
1012 |
|
|
1013 |
QTest::newRow(QString(keys_str + "_patterns").toLatin1()) <<
|
|
1014 |
insertString <<
|
|
1015 |
insertIndex <<
|
|
1016 |
insertMode <<
|
|
1017 |
expectedString <<
|
|
1018 |
bool(use_keys);
|
|
1019 |
}
|
|
1020 |
}
|
|
1021 |
}
|
|
1022 |
|
|
1023 |
void tst_QLineEdit::undo()
|
|
1024 |
{
|
|
1025 |
QFETCH(QStringList, insertString);
|
|
1026 |
QFETCH(IntList, insertIndex);
|
|
1027 |
QFETCH(IntList, insertMode);
|
|
1028 |
QFETCH(QStringList, expectedString);
|
|
1029 |
QFETCH(bool, use_keys);
|
|
1030 |
|
|
1031 |
QVERIFY(!testWidget->isUndoAvailable());
|
|
1032 |
|
|
1033 |
int i;
|
|
1034 |
|
|
1035 |
// STEP 1: First build up an undo history by inserting or typing some strings...
|
|
1036 |
for (i=0; i<insertString.size(); ++i) {
|
|
1037 |
if (insertIndex[i] > -1)
|
|
1038 |
testWidget->setCursorPosition(insertIndex[i]);
|
|
1039 |
|
|
1040 |
// experimental stuff
|
|
1041 |
if (insertMode[i] == REPLACE_UNTIL_END) {
|
|
1042 |
testWidget->setSelection(insertIndex[i], 8);
|
|
1043 |
|
|
1044 |
// This is what I actually want...
|
|
1045 |
// QTest::keyClick(testWidget, Qt::Key_End, Qt::ShiftModifier);
|
|
1046 |
}
|
|
1047 |
|
|
1048 |
if (use_keys)
|
|
1049 |
QTest::keyClicks(testWidget, insertString[i]);
|
|
1050 |
else
|
|
1051 |
testWidget->insert(insertString[i]);
|
|
1052 |
}
|
|
1053 |
|
|
1054 |
// STEP 2: Next call undo several times and see if we can restore to the previous state
|
|
1055 |
for (i=0; i<expectedString.size()-1; ++i) {
|
|
1056 |
QCOMPARE(testWidget->text(), expectedString[i]);
|
|
1057 |
QVERIFY(testWidget->isUndoAvailable());
|
|
1058 |
testWidget->undo();
|
|
1059 |
}
|
|
1060 |
|
|
1061 |
// STEP 3: Verify that we have undone everything
|
|
1062 |
QVERIFY(!testWidget->isUndoAvailable());
|
|
1063 |
QVERIFY(testWidget->text().isEmpty());
|
|
1064 |
|
|
1065 |
#ifdef Q_WS_WIN
|
|
1066 |
// Repeat the test using shortcut instead of undo()
|
|
1067 |
for (i=0; i<insertString.size(); ++i) {
|
|
1068 |
if (insertIndex[i] > -1)
|
|
1069 |
testWidget->setCursorPosition(insertIndex[i]);
|
|
1070 |
if (insertMode[i] == REPLACE_UNTIL_END) {
|
|
1071 |
testWidget->setSelection(insertIndex[i], 8);
|
|
1072 |
}
|
|
1073 |
if (use_keys)
|
|
1074 |
QTest::keyClicks(testWidget, insertString[i]);
|
|
1075 |
else
|
|
1076 |
testWidget->insert(insertString[i]);
|
|
1077 |
}
|
|
1078 |
for (i=0; i<expectedString.size()-1; ++i) {
|
|
1079 |
QCOMPARE(testWidget->text(), expectedString[i]);
|
|
1080 |
QVERIFY(testWidget->isUndoAvailable());
|
|
1081 |
QTest::keyClick(testWidget, Qt::Key_Backspace, Qt::AltModifier);
|
|
1082 |
}
|
|
1083 |
#endif
|
|
1084 |
}
|
|
1085 |
|
|
1086 |
void tst_QLineEdit::isUndoAvailable()
|
|
1087 |
{
|
|
1088 |
DEPENDS_ON("undo");
|
|
1089 |
}
|
|
1090 |
|
|
1091 |
void tst_QLineEdit::redo_data()
|
|
1092 |
{
|
|
1093 |
QTest::addColumn<QStringList>("insertString");
|
|
1094 |
QTest::addColumn<IntList>("insertIndex");
|
|
1095 |
QTest::addColumn<QStringList>("expectedString");
|
|
1096 |
|
|
1097 |
{
|
|
1098 |
IntList insertIndex;
|
|
1099 |
QStringList insertString;
|
|
1100 |
QStringList expectedString;
|
|
1101 |
|
|
1102 |
insertIndex << -1;
|
|
1103 |
insertString << "World"; // World
|
|
1104 |
insertIndex << 0;
|
|
1105 |
insertString << "Hello"; // HelloWorld
|
|
1106 |
insertIndex << 0;
|
|
1107 |
insertString << "Well"; // WellHelloWorld
|
|
1108 |
insertIndex << 9;
|
|
1109 |
insertString << "There"; // WellHelloThereWorld;
|
|
1110 |
|
|
1111 |
expectedString << "World";
|
|
1112 |
expectedString << "HelloWorld";
|
|
1113 |
expectedString << "WellHelloWorld";
|
|
1114 |
expectedString << "WellHelloThereWorld";
|
|
1115 |
|
|
1116 |
QTest::newRow("Inserts and setting cursor") << insertString << insertIndex << expectedString;
|
|
1117 |
}
|
|
1118 |
}
|
|
1119 |
|
|
1120 |
void tst_QLineEdit::redo()
|
|
1121 |
{
|
|
1122 |
QFETCH(QStringList, insertString);
|
|
1123 |
QFETCH(IntList, insertIndex);
|
|
1124 |
QFETCH(QStringList, expectedString);
|
|
1125 |
|
|
1126 |
QVERIFY(!testWidget->isUndoAvailable());
|
|
1127 |
QVERIFY(!testWidget->isRedoAvailable());
|
|
1128 |
|
|
1129 |
int i;
|
|
1130 |
// inserts the diff strings at diff positions
|
|
1131 |
for (i=0; i<insertString.size(); ++i) {
|
|
1132 |
if (insertIndex[i] > -1)
|
|
1133 |
testWidget->setCursorPosition(insertIndex[i]);
|
|
1134 |
testWidget->insert(insertString[i]);
|
|
1135 |
}
|
|
1136 |
|
|
1137 |
QVERIFY(!testWidget->isRedoAvailable());
|
|
1138 |
|
|
1139 |
// undo everything
|
|
1140 |
while (!testWidget->text().isEmpty())
|
|
1141 |
testWidget->undo();
|
|
1142 |
|
|
1143 |
for (i=0; i<expectedString.size(); ++i) {
|
|
1144 |
QVERIFY(testWidget->isRedoAvailable());
|
|
1145 |
testWidget->redo();
|
|
1146 |
QCOMPARE(testWidget->text() , expectedString[i]);
|
|
1147 |
}
|
|
1148 |
|
|
1149 |
QVERIFY(!testWidget->isRedoAvailable());
|
|
1150 |
|
|
1151 |
#ifdef Q_WS_WIN
|
|
1152 |
// repeat test, this time using shortcuts instead of undo()/redo()
|
|
1153 |
|
|
1154 |
while (!testWidget->text().isEmpty())
|
|
1155 |
QTest::keyClick(testWidget, Qt::Key_Backspace, Qt::AltModifier);
|
|
1156 |
|
|
1157 |
for (i = 0; i < expectedString.size(); ++i) {
|
|
1158 |
QVERIFY(testWidget->isRedoAvailable());
|
|
1159 |
QTest::keyClick(testWidget, Qt::Key_Backspace,
|
|
1160 |
Qt::ShiftModifier | Qt::AltModifier);
|
|
1161 |
QCOMPARE(testWidget->text() , expectedString[i]);
|
|
1162 |
}
|
|
1163 |
|
|
1164 |
QVERIFY(!testWidget->isRedoAvailable());
|
|
1165 |
#endif
|
|
1166 |
}
|
|
1167 |
|
|
1168 |
void tst_QLineEdit::isRedoAvailable()
|
|
1169 |
{
|
|
1170 |
DEPENDS_ON("redo");
|
|
1171 |
}
|
|
1172 |
|
|
1173 |
void tst_QLineEdit::undo_keypressevents_data()
|
|
1174 |
{
|
|
1175 |
QTest::addColumn<QTestEventList>("keys");
|
|
1176 |
QTest::addColumn<QStringList>("expectedString");
|
|
1177 |
|
|
1178 |
{
|
|
1179 |
QTestEventList keys;
|
|
1180 |
QStringList expectedString;
|
|
1181 |
|
|
1182 |
keys.addKeyClick('A');
|
|
1183 |
keys.addKeyClick('F');
|
|
1184 |
keys.addKeyClick('R');
|
|
1185 |
keys.addKeyClick('A');
|
|
1186 |
keys.addKeyClick('I');
|
|
1187 |
keys.addKeyClick('D');
|
|
1188 |
psKeyClick(keys, Qt::Key_Home);
|
|
1189 |
|
|
1190 |
keys.addKeyClick('V');
|
|
1191 |
keys.addKeyClick('E');
|
|
1192 |
keys.addKeyClick('R');
|
|
1193 |
keys.addKeyClick('Y');
|
|
1194 |
|
|
1195 |
keys.addKeyClick(Qt::Key_Left);
|
|
1196 |
keys.addKeyClick(Qt::Key_Left);
|
|
1197 |
keys.addKeyClick(Qt::Key_Left);
|
|
1198 |
keys.addKeyClick(Qt::Key_Left);
|
|
1199 |
|
|
1200 |
keys.addKeyClick('B');
|
|
1201 |
keys.addKeyClick('E');
|
|
1202 |
psKeyClick(keys, Qt::Key_End);
|
|
1203 |
|
|
1204 |
keys.addKeyClick(Qt::Key_Exclam);
|
|
1205 |
|
|
1206 |
expectedString << "BEVERYAFRAID!";
|
|
1207 |
expectedString << "BEVERYAFRAID";
|
|
1208 |
expectedString << "VERYAFRAID";
|
|
1209 |
expectedString << "AFRAID";
|
|
1210 |
|
|
1211 |
QTest::newRow("Inserts and moving cursor") << keys << expectedString;
|
|
1212 |
}
|
|
1213 |
|
|
1214 |
{
|
|
1215 |
QTestEventList keys;
|
|
1216 |
QStringList expectedString;
|
|
1217 |
|
|
1218 |
// inserting '1234'
|
|
1219 |
keys.addKeyClick(Qt::Key_1);
|
|
1220 |
keys.addKeyClick(Qt::Key_2);
|
|
1221 |
keys.addKeyClick(Qt::Key_3);
|
|
1222 |
keys.addKeyClick(Qt::Key_4);
|
|
1223 |
psKeyClick(keys, Qt::Key_Home);
|
|
1224 |
|
|
1225 |
// skipping '12'
|
|
1226 |
keys.addKeyClick(Qt::Key_Right);
|
|
1227 |
keys.addKeyClick(Qt::Key_Right);
|
|
1228 |
|
|
1229 |
// selecting '34'
|
|
1230 |
keys.addKeyClick(Qt::Key_Right, Qt::ShiftModifier);
|
|
1231 |
keys.addKeyClick(Qt::Key_Right, Qt::ShiftModifier);
|
|
1232 |
|
|
1233 |
// deleting '34'
|
|
1234 |
keys.addKeyClick(Qt::Key_Delete);
|
|
1235 |
|
|
1236 |
expectedString << "12";
|
|
1237 |
expectedString << "1234";
|
|
1238 |
|
|
1239 |
QTest::newRow("Inserts,moving,selection and delete") << keys << expectedString;
|
|
1240 |
}
|
|
1241 |
|
|
1242 |
{
|
|
1243 |
QTestEventList keys;
|
|
1244 |
QStringList expectedString;
|
|
1245 |
|
|
1246 |
// inserting 'AB12'
|
|
1247 |
keys.addKeyClick('A');
|
|
1248 |
keys.addKeyClick('B');
|
|
1249 |
|
|
1250 |
keys.addKeyClick(Qt::Key_1);
|
|
1251 |
keys.addKeyClick(Qt::Key_2);
|
|
1252 |
|
|
1253 |
psKeyClick(keys, Qt::Key_Home);
|
|
1254 |
|
|
1255 |
// selecting 'AB'
|
|
1256 |
keys.addKeyClick(Qt::Key_Right, Qt::ShiftModifier);
|
|
1257 |
keys.addKeyClick(Qt::Key_Right, Qt::ShiftModifier);
|
|
1258 |
|
|
1259 |
// deleting 'AB'
|
|
1260 |
keys.addKeyClick(Qt::Key_Delete);
|
|
1261 |
|
|
1262 |
// undoing deletion of 'AB'
|
|
1263 |
keys.addKeyClick(Qt::Key_Z, Qt::ControlModifier);
|
|
1264 |
|
|
1265 |
// unselect any current selection
|
|
1266 |
keys.addKeyClick(Qt::Key_Right);
|
|
1267 |
#ifdef Q_WS_WIN //Mac has a specialcase to handle jumping to the end of a selection
|
|
1268 |
keys.addKeyClick(Qt::Key_Left);
|
|
1269 |
#endif
|
|
1270 |
|
|
1271 |
// selecting '12'
|
|
1272 |
keys.addKeyClick(Qt::Key_Right, Qt::ShiftModifier);
|
|
1273 |
keys.addKeyClick(Qt::Key_Right, Qt::ShiftModifier);
|
|
1274 |
|
|
1275 |
// deleting '12'
|
|
1276 |
keys.addKeyClick(Qt::Key_Delete);
|
|
1277 |
|
|
1278 |
expectedString << "AB";
|
|
1279 |
expectedString << "AB12";
|
|
1280 |
|
|
1281 |
QTest::newRow("Inserts,moving,selection, delete and undo") << keys << expectedString;
|
|
1282 |
}
|
|
1283 |
|
|
1284 |
{
|
|
1285 |
QTestEventList keys;
|
|
1286 |
QStringList expectedString;
|
|
1287 |
|
|
1288 |
// inserting 'ABCD'
|
|
1289 |
keys.addKeyClick(Qt::Key_A);
|
|
1290 |
keys.addKeyClick(Qt::Key_B);
|
|
1291 |
keys.addKeyClick(Qt::Key_C);
|
|
1292 |
keys.addKeyClick(Qt::Key_D);
|
|
1293 |
|
|
1294 |
//move left two
|
|
1295 |
keys.addKeyClick(Qt::Key_Left);
|
|
1296 |
keys.addKeyClick(Qt::Key_Left);
|
|
1297 |
|
|
1298 |
// inserting '1234'
|
|
1299 |
keys.addKeyClick(Qt::Key_1);
|
|
1300 |
keys.addKeyClick(Qt::Key_2);
|
|
1301 |
keys.addKeyClick(Qt::Key_3);
|
|
1302 |
keys.addKeyClick(Qt::Key_4);
|
|
1303 |
|
|
1304 |
// selecting '1234'
|
|
1305 |
keys.addKeyClick(Qt::Key_Left, Qt::ShiftModifier);
|
|
1306 |
keys.addKeyClick(Qt::Key_Left, Qt::ShiftModifier);
|
|
1307 |
keys.addKeyClick(Qt::Key_Left, Qt::ShiftModifier);
|
|
1308 |
keys.addKeyClick(Qt::Key_Left, Qt::ShiftModifier);
|
|
1309 |
|
|
1310 |
// overwriting '1234' with '5'
|
|
1311 |
keys.addKeyClick(Qt::Key_5);
|
|
1312 |
|
|
1313 |
// undoing deletion of 'AB'
|
|
1314 |
keys.addKeyClick(Qt::Key_Z, Qt::ControlModifier);
|
|
1315 |
|
|
1316 |
// overwriting '1234' with '6'
|
|
1317 |
keys.addKeyClick(Qt::Key_6);
|
|
1318 |
|
|
1319 |
expectedString << "ab6cd";
|
|
1320 |
// for versions previous to 3.2 we overwrite needed two undo operations
|
|
1321 |
expectedString << "ab1234cd";
|
|
1322 |
expectedString << "abcd";
|
|
1323 |
|
|
1324 |
QTest::newRow("Inserts,moving,selection and undo, removing selection") << keys << expectedString;
|
|
1325 |
}
|
|
1326 |
|
|
1327 |
{
|
|
1328 |
QTestEventList keys;
|
|
1329 |
QStringList expectedString;
|
|
1330 |
|
|
1331 |
// inserting 'ABC'
|
|
1332 |
keys.addKeyClick('A');
|
|
1333 |
keys.addKeyClick('B');
|
|
1334 |
keys.addKeyClick('C');
|
|
1335 |
|
|
1336 |
// removes 'C'
|
|
1337 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
1338 |
|
|
1339 |
expectedString << "AB";
|
|
1340 |
expectedString << "ABC";
|
|
1341 |
|
|
1342 |
QTest::newRow("Inserts,backspace") << keys << expectedString;
|
|
1343 |
}
|
|
1344 |
|
|
1345 |
{
|
|
1346 |
QTestEventList keys;
|
|
1347 |
QStringList expectedString;
|
|
1348 |
|
|
1349 |
// inserting 'ABC'
|
|
1350 |
keys.addKeyClick('A');
|
|
1351 |
keys.addKeyClick('B');
|
|
1352 |
keys.addKeyClick('C');
|
|
1353 |
|
|
1354 |
// removes 'C'
|
|
1355 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
1356 |
|
|
1357 |
// inserting 'Z'
|
|
1358 |
keys.addKeyClick('Z');
|
|
1359 |
|
|
1360 |
expectedString << "ABZ";
|
|
1361 |
expectedString << "AB";
|
|
1362 |
expectedString << "ABC";
|
|
1363 |
|
|
1364 |
QTest::newRow("Inserts,backspace,inserts") << keys << expectedString;
|
|
1365 |
}
|
|
1366 |
|
|
1367 |
|
|
1368 |
{
|
|
1369 |
QTestEventList keys;
|
|
1370 |
QStringList expectedString;
|
|
1371 |
|
|
1372 |
// inserting '123'
|
|
1373 |
keys.addKeyClick(Qt::Key_1);
|
|
1374 |
keys.addKeyClick(Qt::Key_2);
|
|
1375 |
keys.addKeyClick(Qt::Key_3);
|
|
1376 |
psKeyClick(keys, Qt::Key_Home);
|
|
1377 |
|
|
1378 |
// selecting '123'
|
|
1379 |
psKeyClick(keys, Qt::Key_End, Qt::ShiftModifier);
|
|
1380 |
|
|
1381 |
// overwriting '123' with 'ABC'
|
|
1382 |
keys.addKeyClick('A');
|
|
1383 |
keys.addKeyClick('B');
|
|
1384 |
keys.addKeyClick('C');
|
|
1385 |
|
|
1386 |
expectedString << "ABC";
|
|
1387 |
// for versions previous to 3.2 we overwrite needed two undo operations
|
|
1388 |
expectedString << "123";
|
|
1389 |
|
|
1390 |
QTest::newRow("Inserts,moving,selection and overwriting") << keys << expectedString;
|
|
1391 |
}
|
|
1392 |
}
|
|
1393 |
|
|
1394 |
void tst_QLineEdit::undo_keypressevents()
|
|
1395 |
{
|
|
1396 |
QFETCH(QTestEventList, keys);
|
|
1397 |
QFETCH(QStringList, expectedString);
|
|
1398 |
|
|
1399 |
keys.simulate(testWidget);
|
|
1400 |
|
|
1401 |
for (int i=0; i<expectedString.size(); ++i) {
|
|
1402 |
QCOMPARE(testWidget->text() , expectedString[i]);
|
|
1403 |
testWidget->undo();
|
|
1404 |
}
|
|
1405 |
QVERIFY(testWidget->text().isEmpty());
|
|
1406 |
}
|
|
1407 |
|
|
1408 |
void tst_QLineEdit::clear()
|
|
1409 |
{
|
|
1410 |
// checking that clear of empty/nullstring doesn't add to undo history
|
|
1411 |
int max = 5000;
|
|
1412 |
while (max > 0 && testWidget->isUndoAvailable()) {
|
|
1413 |
max--;
|
|
1414 |
testWidget->undo();
|
|
1415 |
}
|
|
1416 |
|
|
1417 |
testWidget->clear();
|
|
1418 |
// QVERIFY(!testWidget->isUndoAvailable());
|
|
1419 |
|
|
1420 |
// checks that clear actually clears
|
|
1421 |
testWidget->insert("I am Legend");
|
|
1422 |
testWidget->clear();
|
|
1423 |
QVERIFY(testWidget->text().isEmpty());
|
|
1424 |
|
|
1425 |
// checks that clears can be undone
|
|
1426 |
testWidget->undo();
|
|
1427 |
QCOMPARE(testWidget->text(), QString("I am Legend"));
|
|
1428 |
}
|
|
1429 |
|
|
1430 |
#ifdef QT3_SUPPORT
|
|
1431 |
void tst_QLineEdit::lostFocus()
|
|
1432 |
{
|
|
1433 |
editingFinished();
|
|
1434 |
}
|
|
1435 |
#endif
|
|
1436 |
void tst_QLineEdit::editingFinished()
|
|
1437 |
{
|
|
1438 |
if (testWidget->hasAcceptableInput())
|
|
1439 |
validInput = true;
|
|
1440 |
else
|
|
1441 |
validInput = false;
|
|
1442 |
}
|
|
1443 |
|
|
1444 |
void tst_QLineEdit::text_data()
|
|
1445 |
{
|
|
1446 |
QTest::addColumn<QString>("insertString");
|
|
1447 |
|
|
1448 |
QTest::newRow("Plain text0") << QString("Hello World");
|
|
1449 |
QTest::newRow("Plain text1") << QString("");
|
|
1450 |
QTest::newRow("Plain text2") << QString("A");
|
|
1451 |
QTest::newRow("Plain text3") << QString("ryyryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryry");
|
|
1452 |
QTest::newRow("Plain text4") << QString("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890`~!@#$%^&*()_-+={[}]|\\:;'?/>.<,\"");
|
|
1453 |
QTest::newRow("Newlines") << QString("A\nB\nC\n");
|
|
1454 |
QTest::newRow("Text with nbsp") << QString("Hello") + QChar(0xa0) + "World";
|
|
1455 |
}
|
|
1456 |
|
|
1457 |
void tst_QLineEdit::text()
|
|
1458 |
{
|
|
1459 |
QFETCH(QString, insertString);
|
|
1460 |
testWidget->setText(insertString);
|
|
1461 |
QCOMPARE(testWidget->text(), insertString);
|
|
1462 |
}
|
|
1463 |
|
|
1464 |
void tst_QLineEdit::textMask_data()
|
|
1465 |
{
|
|
1466 |
QTest::addColumn<QString>("insertString");
|
|
1467 |
|
|
1468 |
QTest::newRow( "Plain text1" ) << QString( "" );
|
|
1469 |
}
|
|
1470 |
|
|
1471 |
void tst_QLineEdit::textMask()
|
|
1472 |
{
|
|
1473 |
QFETCH( QString, insertString );
|
|
1474 |
testWidget->setInputMask( "#" );
|
|
1475 |
testWidget->setText( insertString );
|
|
1476 |
QCOMPARE( testWidget->text(), insertString );
|
|
1477 |
}
|
|
1478 |
|
|
1479 |
void tst_QLineEdit::setText()
|
|
1480 |
{
|
|
1481 |
QSignalSpy editedSpy(testWidget, SIGNAL(textEdited(QString)));
|
|
1482 |
QSignalSpy changedSpy(testWidget, SIGNAL(textChanged(QString)));
|
|
1483 |
testWidget->setText("hello");
|
|
1484 |
QCOMPARE(editedSpy.count(), 0);
|
|
1485 |
QCOMPARE(changedSpy.value(0).value(0).toString(), QString("hello"));
|
|
1486 |
}
|
|
1487 |
|
|
1488 |
void tst_QLineEdit::displayText_data()
|
|
1489 |
{
|
|
1490 |
QTest::addColumn<QString>("insertString");
|
|
1491 |
QTest::addColumn<QString>("expectedString");
|
|
1492 |
QTest::addColumn<QLineEdit::EchoMode>("mode");
|
|
1493 |
QTest::addColumn<bool>("use_setText");
|
|
1494 |
|
|
1495 |
QString s;
|
|
1496 |
QLineEdit::EchoMode m;
|
|
1497 |
|
|
1498 |
for (int i=0; i<2; i++) {
|
|
1499 |
QString key_mode_str;
|
|
1500 |
bool use_setText;
|
|
1501 |
if (i==0) {
|
|
1502 |
key_mode_str = "setText_";
|
|
1503 |
use_setText = true;
|
|
1504 |
} else {
|
|
1505 |
key_mode_str = "useKeys_";
|
|
1506 |
use_setText = false;
|
|
1507 |
}
|
|
1508 |
s = key_mode_str + "Normal";
|
|
1509 |
m = QLineEdit::Normal;
|
|
1510 |
QTest::newRow(QString(s + " text0").toLatin1()) << QString("Hello World") <<
|
|
1511 |
QString("Hello World") <<
|
|
1512 |
m << bool(use_setText);
|
|
1513 |
QTest::newRow(QString(s + " text1").toLatin1()) << QString("") <<
|
|
1514 |
QString("") <<
|
|
1515 |
m << bool(use_setText);
|
|
1516 |
QTest::newRow(QString(s + " text2").toLatin1()) << QString("A") <<
|
|
1517 |
QString("A") <<
|
|
1518 |
m << bool(use_setText);
|
|
1519 |
QTest::newRow(QString(s + " text3").toLatin1()) << QString("ryyryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryry") <<
|
|
1520 |
QString("ryyryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryry") <<
|
|
1521 |
m << bool(use_setText);
|
|
1522 |
QTest::newRow(QString(s + " text4").toLatin1()) << QString("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890`~!@#$%^&*()_-+={[}]|\\:;'?/>.<,\"") <<
|
|
1523 |
QString("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890`~!@#$%^&*()_-+={[}]|\\:;'?/>.<,\"") <<
|
|
1524 |
m << bool(use_setText);
|
|
1525 |
QTest::newRow(QString(s + " text with nbsp").toLatin1()) << QString("Hello") + QChar(0xa0) + "World" <<
|
|
1526 |
QString("Hello") + QChar(0xa0) + "World" <<
|
|
1527 |
m << bool(use_setText);
|
|
1528 |
s = key_mode_str + "NoEcho";
|
|
1529 |
m = QLineEdit::NoEcho;
|
|
1530 |
QTest::newRow(QString(s + " text0").toLatin1()) << QString("Hello World") <<
|
|
1531 |
QString("") <<
|
|
1532 |
m << bool(use_setText);
|
|
1533 |
QTest::newRow(QString(s + " text1").toLatin1()) << QString("") <<
|
|
1534 |
QString("") <<
|
|
1535 |
m << bool(use_setText);
|
|
1536 |
QTest::newRow(QString(s + " text2").toLatin1()) << QString("A") <<
|
|
1537 |
QString("") <<
|
|
1538 |
m << bool(use_setText);
|
|
1539 |
QTest::newRow(QString(s + " text3").toLatin1()) << QString("ryyryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryry") <<
|
|
1540 |
QString("") <<
|
|
1541 |
m << bool(use_setText);
|
|
1542 |
QTest::newRow(QString(s + " text4").toLatin1()) << QString("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890`~!@#$%^&*()_-+={[}]|\\:;'?/>.<,\"") <<
|
|
1543 |
QString("") <<
|
|
1544 |
m << bool(use_setText);
|
|
1545 |
QTest::newRow(QString(s + " text with nbsp").toLatin1()) << QString("Hello") + QChar(0xa0) + "World" <<
|
|
1546 |
QString("") <<
|
|
1547 |
m << bool(use_setText);
|
|
1548 |
s = key_mode_str + "Password";
|
|
1549 |
m = QLineEdit::Password;
|
|
1550 |
QChar passChar = qApp->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, 0, testWidget);
|
|
1551 |
QString input;
|
|
1552 |
QString pass;
|
|
1553 |
input = "Hello World";
|
|
1554 |
pass.resize(input.length());
|
|
1555 |
pass.fill(passChar);
|
|
1556 |
QTest::newRow(QString(s + " text0").toLatin1()) << input << pass << m << bool(use_setText);
|
|
1557 |
QTest::newRow(QString(s + " text1").toLatin1()) << QString("") <<
|
|
1558 |
QString("") <<
|
|
1559 |
m << bool(use_setText);
|
|
1560 |
QTest::newRow(QString(s + " text2").toLatin1()) << QString("A") << QString(passChar) << m << bool(use_setText);
|
|
1561 |
input = QString("ryyryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryryrryryryryryryryryryryryryry");
|
|
1562 |
pass.resize(input.length());
|
|
1563 |
pass.fill(passChar);
|
|
1564 |
QTest::newRow(QString(s + " text3").toLatin1()) << input << pass << m << bool(use_setText);
|
|
1565 |
input = QString("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890`~!@#$%^&*()_-+={[}]|\\:;'?/>.<,\"");
|
|
1566 |
pass.fill(passChar, input.length());
|
|
1567 |
QTest::newRow(QString(s + " text4").toLatin1()) << input << pass << m << bool(use_setText);
|
|
1568 |
input = QString("Hello") + QChar(0xa0) + "World";
|
|
1569 |
pass.resize(input.length());
|
|
1570 |
pass.fill(passChar);
|
|
1571 |
QTest::newRow(QString(s + " text with nbsp").toLatin1()) << input << pass << m << bool(use_setText);
|
|
1572 |
}
|
|
1573 |
}
|
|
1574 |
|
|
1575 |
void tst_QLineEdit::displayText()
|
|
1576 |
{
|
|
1577 |
QFETCH(QString, insertString);
|
|
1578 |
QFETCH(QString, expectedString);
|
|
1579 |
QFETCH(QLineEdit::EchoMode, mode);
|
|
1580 |
//QFETCH(bool, use_setText); Currently unused.
|
|
1581 |
|
|
1582 |
testWidget->setEchoMode(mode);
|
|
1583 |
testWidget->setText(insertString);
|
|
1584 |
QCOMPARE(testWidget->displayText(), expectedString);
|
|
1585 |
QVERIFY(testWidget->echoMode() == mode);
|
|
1586 |
}
|
|
1587 |
|
|
1588 |
void tst_QLineEdit::setEchoMode()
|
|
1589 |
{
|
|
1590 |
DEPENDS_ON("displayText");
|
|
1591 |
}
|
|
1592 |
|
|
1593 |
void tst_QLineEdit::echoMode()
|
|
1594 |
{
|
|
1595 |
DEPENDS_ON("displayText");
|
|
1596 |
}
|
|
1597 |
|
|
1598 |
void tst_QLineEdit::passwordEchoOnEdit()
|
|
1599 |
{
|
|
1600 |
QStyleOptionFrameV2 opt;
|
|
1601 |
QChar fillChar = testWidget->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, testWidget);
|
|
1602 |
|
|
1603 |
testWidget->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
|
1604 |
testWidget->setFocus();
|
|
1605 |
testWidget->raise();
|
|
1606 |
QTRY_VERIFY(testWidget->hasFocus());
|
|
1607 |
|
|
1608 |
QTest::keyPress(testWidget, '0');
|
|
1609 |
QTest::keyPress(testWidget, '1');
|
|
1610 |
QTest::keyPress(testWidget, '2');
|
|
1611 |
QTest::keyPress(testWidget, '3');
|
|
1612 |
QTest::keyPress(testWidget, '4');
|
|
1613 |
QCOMPARE(testWidget->displayText(), QString("01234"));
|
|
1614 |
testWidget->clearFocus();
|
|
1615 |
QVERIFY(!testWidget->hasFocus());
|
|
1616 |
QCOMPARE(testWidget->displayText(), QString(5, fillChar));
|
|
1617 |
testWidget->setFocus();
|
|
1618 |
QTRY_VERIFY(testWidget->hasFocus());
|
|
1619 |
|
|
1620 |
QCOMPARE(testWidget->displayText(), QString(5, fillChar));
|
|
1621 |
QTest::keyPress(testWidget, '0');
|
|
1622 |
QCOMPARE(testWidget->displayText(), QString("0"));
|
|
1623 |
|
|
1624 |
// restore clean state
|
|
1625 |
testWidget->setEchoMode(QLineEdit::Normal);
|
|
1626 |
}
|
|
1627 |
|
|
1628 |
void tst_QLineEdit::maxLength_mask_data()
|
|
1629 |
{
|
|
1630 |
QTest::addColumn<QString>("mask");
|
|
1631 |
QTest::addColumn<int>("expectedLength");
|
|
1632 |
|
|
1633 |
QTest::newRow("mask_case") << QString(">000<>00<000") << 8;
|
|
1634 |
QTest::newRow("mask_nocase") << QString("00000000") << 8;
|
|
1635 |
QTest::newRow("mask_null") << QString() << 32767;
|
|
1636 |
QTest::newRow("mask_escape") << QString("\\A\\aAA") << 4;
|
|
1637 |
}
|
|
1638 |
|
|
1639 |
void tst_QLineEdit::maxLength_mask()
|
|
1640 |
{
|
|
1641 |
QFETCH(QString, mask);
|
|
1642 |
QFETCH(int, expectedLength);
|
|
1643 |
|
|
1644 |
testWidget->setInputMask(mask);
|
|
1645 |
|
|
1646 |
QCOMPARE(testWidget->maxLength(), expectedLength);
|
|
1647 |
}
|
|
1648 |
|
|
1649 |
void tst_QLineEdit::maxLength_data()
|
|
1650 |
{
|
|
1651 |
QTest::addColumn<QString>("insertString");
|
|
1652 |
QTest::addColumn<QString>("expectedString");
|
|
1653 |
QTest::addColumn<int>("length");
|
|
1654 |
QTest::addColumn<bool>("insertBeforeSettingMaxLength");
|
|
1655 |
QTest::addColumn<bool>("use_setText");
|
|
1656 |
|
|
1657 |
QTest::newRow("keyclick before0") << QString("this is a test.") << QString("this is a test.") << 20 << bool(true) << bool(false);
|
|
1658 |
QTest::newRow("keyclick before1") << QString("this is a test.") << QString("this is a ") << 10 << bool(true) << bool(false);
|
|
1659 |
QTest::newRow("keyclick after0") << QString("this is a test.") << QString("this is a test.") << 20 << bool(false) << bool(false);
|
|
1660 |
QTest::newRow("keyclick after1") << QString("this is a test.") << QString("this is a ") << 10 << bool(false) << bool(false);
|
|
1661 |
QTest::newRow("settext before0") << QString("this is a test.") << QString("this is a test.") << 20 << bool(true) << bool(true);
|
|
1662 |
QTest::newRow("settext before1") << QString("this is a test.") << QString("this is a ") << 10 << bool(true) << bool(true);
|
|
1663 |
QTest::newRow("settext after0") << QString("this is a test.") << QString("this is a test.") << 20 << bool(false) << bool(true);
|
|
1664 |
QTest::newRow("settext after1") << QString("this is a test.") << QString("this is a ") << 10 << bool(false) << bool(true);
|
|
1665 |
}
|
|
1666 |
|
|
1667 |
void tst_QLineEdit::maxLength()
|
|
1668 |
{
|
|
1669 |
QFETCH(QString, insertString);
|
|
1670 |
QFETCH(QString, expectedString);
|
|
1671 |
QFETCH(int, length);
|
|
1672 |
QFETCH(bool, insertBeforeSettingMaxLength);
|
|
1673 |
QFETCH(bool, use_setText);
|
|
1674 |
|
|
1675 |
// in some cases we set the maxLength _before_ entering the text.
|
|
1676 |
if (!insertBeforeSettingMaxLength)
|
|
1677 |
testWidget->setMaxLength(length);
|
|
1678 |
|
|
1679 |
// I expect MaxLength to work BOTH with entering live characters AND with setting the text.
|
|
1680 |
if (use_setText) {
|
|
1681 |
// Enter insertString using setText.
|
|
1682 |
testWidget->setText(insertString);
|
|
1683 |
} else {
|
|
1684 |
// Enter insertString as a sequence of keyClicks
|
|
1685 |
QTest::keyClicks(testWidget, insertString);
|
|
1686 |
}
|
|
1687 |
|
|
1688 |
// in all other cases we set the maxLength _after_ entering the text.
|
|
1689 |
if (insertBeforeSettingMaxLength) {
|
|
1690 |
changed_count = 0;
|
|
1691 |
testWidget->setMaxLength(length);
|
|
1692 |
|
|
1693 |
// Make sure that the textChanged is not emitted unless the text is actually changed
|
|
1694 |
if (insertString == expectedString) {
|
|
1695 |
QVERIFY(changed_count == 0);
|
|
1696 |
} else {
|
|
1697 |
QVERIFY(changed_count == 1);
|
|
1698 |
}
|
|
1699 |
}
|
|
1700 |
|
|
1701 |
// and check if we get the expected string back
|
|
1702 |
QCOMPARE(testWidget->text(), expectedString);
|
|
1703 |
}
|
|
1704 |
|
|
1705 |
void tst_QLineEdit::setMaxLength()
|
|
1706 |
{
|
|
1707 |
DEPENDS_ON("maxLength");
|
|
1708 |
}
|
|
1709 |
|
|
1710 |
void tst_QLineEdit::isReadOnly()
|
|
1711 |
{
|
|
1712 |
QVERIFY(!testWidget->isReadOnly());
|
|
1713 |
|
|
1714 |
// start with a basic text
|
|
1715 |
QTest::keyClicks(testWidget, "the quick brown fox");
|
|
1716 |
QCOMPARE(testWidget->text(), QString("the quick brown fox"));
|
|
1717 |
|
|
1718 |
// do a quick check to verify that we can indeed edit the text
|
|
1719 |
testWidget->home(false);
|
|
1720 |
testWidget->cursorForward(false, 10);
|
|
1721 |
QTest::keyClicks(testWidget, "dark ");
|
|
1722 |
QCOMPARE(testWidget->text(), QString("the quick dark brown fox"));
|
|
1723 |
|
|
1724 |
testWidget->setReadOnly(true);
|
|
1725 |
QVERIFY(testWidget->isReadOnly());
|
|
1726 |
|
|
1727 |
// verify that we cannot edit the text anymore
|
|
1728 |
testWidget->home(false);
|
|
1729 |
testWidget->cursorForward(false, 10);
|
|
1730 |
QTest::keyClick(testWidget, Qt::Key_Delete);
|
|
1731 |
QCOMPARE(testWidget->text(), QString("the quick dark brown fox"));
|
|
1732 |
testWidget->cursorForward(false, 10);
|
|
1733 |
QTest::keyClicks(testWidget, "this should not have any effect!! ");
|
|
1734 |
QCOMPARE(testWidget->text(), QString("the quick dark brown fox"));
|
|
1735 |
}
|
|
1736 |
|
|
1737 |
void tst_QLineEdit::setReadOnly()
|
|
1738 |
{
|
|
1739 |
DEPENDS_ON("isReadOnly");
|
|
1740 |
}
|
|
1741 |
|
|
1742 |
static void figureOutProperKey(Qt::Key &key, Qt::KeyboardModifiers &pressState)
|
|
1743 |
{
|
|
1744 |
#ifdef Q_WS_MAC
|
|
1745 |
static bool tst_lineedit_randomized = false;
|
|
1746 |
// Mac has 3 different ways of accomplishing this (same for moving to the back)
|
|
1747 |
// So I guess we should just randomly do this for now. Which may get people mad, but if
|
|
1748 |
// we fail at one point, it's just a matter of setting roll to the correct value
|
|
1749 |
// instead of random.
|
|
1750 |
|
|
1751 |
if (!tst_lineedit_randomized) {
|
|
1752 |
tst_lineedit_randomized = true;
|
|
1753 |
::srandom(ulong(time(0)));
|
|
1754 |
}
|
|
1755 |
long roll = ::random() % 3;
|
|
1756 |
switch (roll) {
|
|
1757 |
case 0:
|
|
1758 |
key = key == Qt::Key_Home ? Qt::Key_Up : Qt::Key_Down;
|
|
1759 |
break;
|
|
1760 |
case 1:
|
|
1761 |
case 2:
|
|
1762 |
key = key == Qt::Key_Home ? Qt::Key_Left : Qt::Key_Right;
|
|
1763 |
pressState |= (roll == 1) ? Qt::ControlModifier : Qt::MetaModifier;
|
|
1764 |
break;
|
|
1765 |
}
|
|
1766 |
#else
|
|
1767 |
// Naively kill the warning.
|
|
1768 |
key = key;
|
|
1769 |
pressState = pressState;
|
|
1770 |
#endif
|
|
1771 |
}
|
|
1772 |
|
|
1773 |
// Platform specific move. Home and End do nothing on the Mac,
|
|
1774 |
// so do something a bit smarter than tons of #ifdefs
|
|
1775 |
void tst_QLineEdit::psKeyClick(QWidget *target, Qt::Key key, Qt::KeyboardModifiers pressState)
|
|
1776 |
{
|
|
1777 |
figureOutProperKey(key, pressState);
|
|
1778 |
QTest::keyClick(target, key, pressState);
|
|
1779 |
}
|
|
1780 |
|
|
1781 |
void tst_QLineEdit::psKeyClick(QTestEventList &keys, Qt::Key key, Qt::KeyboardModifiers pressState)
|
|
1782 |
{
|
|
1783 |
figureOutProperKey(key, pressState);
|
|
1784 |
keys.addKeyClick(key, pressState);
|
|
1785 |
}
|
|
1786 |
|
|
1787 |
void tst_QLineEdit::cursorPosition()
|
|
1788 |
{
|
|
1789 |
QVERIFY(testWidget->cursorPosition() == 0);
|
|
1790 |
|
|
1791 |
// start with a basic text
|
|
1792 |
QTest::keyClicks(testWidget, "The");
|
|
1793 |
QCOMPARE(testWidget->cursorPosition(), 3);
|
|
1794 |
QTest::keyClicks(testWidget, " quick");
|
|
1795 |
QCOMPARE(testWidget->cursorPosition(), 9);
|
|
1796 |
QTest::keyClicks(testWidget, " brown fox jumps over the lazy dog");
|
|
1797 |
QCOMPARE(testWidget->cursorPosition(), 43);
|
|
1798 |
|
|
1799 |
// The text we have now is:
|
|
1800 |
// 1 2 3 4 5
|
|
1801 |
// 012345678901234567890123456789012345678901234567890
|
|
1802 |
// The quick brown fox jumps over the lazy dog
|
|
1803 |
|
|
1804 |
// next we will check some of the cursor movement functions
|
|
1805 |
testWidget->end(false);
|
|
1806 |
QCOMPARE(testWidget->cursorPosition() , 43);
|
|
1807 |
testWidget->cursorForward(false, -1);
|
|
1808 |
QCOMPARE(testWidget->cursorPosition() , 42);
|
|
1809 |
testWidget->cursorBackward(false, 1);
|
|
1810 |
QCOMPARE(testWidget->cursorPosition() , 41);
|
|
1811 |
testWidget->home(false);
|
|
1812 |
QCOMPARE(testWidget->cursorPosition() , 0);
|
|
1813 |
testWidget->cursorForward(false, 1);
|
|
1814 |
QCOMPARE(testWidget->cursorPosition() , 1);
|
|
1815 |
testWidget->cursorForward(false, 9);
|
|
1816 |
QCOMPARE(testWidget->cursorPosition() , 10);
|
|
1817 |
testWidget->cursorWordForward(false); // 'fox'
|
|
1818 |
QCOMPARE(testWidget->cursorPosition(), 16);
|
|
1819 |
testWidget->cursorWordForward(false); // 'jumps'
|
|
1820 |
QCOMPARE(testWidget->cursorPosition(), 20);
|
|
1821 |
testWidget->cursorWordBackward(false); // 'fox'
|
|
1822 |
QCOMPARE(testWidget->cursorPosition(), 16);
|
|
1823 |
testWidget->cursorWordBackward(false); // 'brown'
|
|
1824 |
testWidget->cursorWordBackward(false); // 'quick'
|
|
1825 |
testWidget->cursorWordBackward(false); // 'The'
|
|
1826 |
QCOMPARE(testWidget->cursorPosition(), 0);
|
|
1827 |
testWidget->cursorWordBackward(false); // 'The'
|
|
1828 |
QCOMPARE(testWidget->cursorPosition(), 0);
|
|
1829 |
|
|
1830 |
// Cursor position should be 0 here!
|
|
1831 |
int i;
|
|
1832 |
for (i=0; i<5; i++)
|
|
1833 |
QTest::keyClick(testWidget, Qt::Key_Right);
|
|
1834 |
QCOMPARE(testWidget->cursorPosition(), 5);
|
|
1835 |
psKeyClick(testWidget, Qt::Key_End);
|
|
1836 |
QCOMPARE(testWidget->cursorPosition(), 43);
|
|
1837 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
1838 |
QCOMPARE(testWidget->cursorPosition(), 42);
|
|
1839 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
1840 |
QCOMPARE(testWidget->cursorPosition(), 41);
|
|
1841 |
psKeyClick(testWidget, Qt::Key_Home);
|
|
1842 |
QCOMPARE(testWidget->cursorPosition(), 0);
|
|
1843 |
|
|
1844 |
// cursorposition when maxlength is set
|
|
1845 |
int maxLength = 9;
|
|
1846 |
testWidget->clear();
|
|
1847 |
testWidget->setMaxLength(maxLength);
|
|
1848 |
QCOMPARE(testWidget->cursorPosition() , 0);
|
|
1849 |
QTest::keyClicks(testWidget, "123ABC123");
|
|
1850 |
QCOMPARE(testWidget->cursorPosition() , maxLength);
|
|
1851 |
psKeyClick(testWidget, Qt::Key_Home);
|
|
1852 |
QCOMPARE(testWidget->cursorPosition() , 0);
|
|
1853 |
psKeyClick(testWidget, Qt::Key_End);
|
|
1854 |
QCOMPARE(testWidget->cursorPosition() , maxLength);
|
|
1855 |
}
|
|
1856 |
|
|
1857 |
/* // tested in cursorPosition
|
|
1858 |
void tst_QLineEdit::cursorLeft()
|
|
1859 |
void tst_QLineEdit::cursorRight()
|
|
1860 |
void tst_QLineEdit::cursorForward()
|
|
1861 |
void tst_QLineEdit::cursorBackward()
|
|
1862 |
void tst_QLineEdit::cursorWordForward()
|
|
1863 |
void tst_QLineEdit::cursorWordBackward()
|
|
1864 |
void tst_QLineEdit::home()
|
|
1865 |
void tst_QLineEdit::end()
|
|
1866 |
*/
|
|
1867 |
|
|
1868 |
void tst_QLineEdit::cursorPositionChanged_data()
|
|
1869 |
{
|
|
1870 |
QTest::addColumn<QTestEventList>("input");
|
|
1871 |
QTest::addColumn<int>("lastPos");
|
|
1872 |
QTest::addColumn<int>("newPos");
|
|
1873 |
|
|
1874 |
QTestEventList keys;
|
|
1875 |
keys.addKeyClick(Qt::Key_A);
|
|
1876 |
QTest::newRow("a") << keys << 0 << 1;
|
|
1877 |
keys.clear();
|
|
1878 |
|
|
1879 |
keys.addKeyClick(Qt::Key_A);
|
|
1880 |
keys.addKeyClick(Qt::Key_B);
|
|
1881 |
keys.addKeyClick(Qt::Key_C);
|
|
1882 |
psKeyClick(keys, Qt::Key_Home);
|
|
1883 |
QTest::newRow("abc<home>") << keys << 3 << 0;
|
|
1884 |
keys.clear();
|
|
1885 |
|
|
1886 |
keys.addKeyClick(Qt::Key_A);
|
|
1887 |
keys.addKeyClick(Qt::Key_B);
|
|
1888 |
keys.addKeyClick(Qt::Key_C);
|
|
1889 |
keys.addKeyClick(Qt::Key_Left);
|
|
1890 |
QTest::newRow("abc<left>") << keys << 3 << 2;
|
|
1891 |
keys.clear();
|
|
1892 |
|
|
1893 |
keys.addKeyClick(Qt::Key_A);
|
|
1894 |
keys.addKeyClick(Qt::Key_B);
|
|
1895 |
keys.addKeyClick(Qt::Key_C);
|
|
1896 |
keys.addKeyClick(Qt::Key_Right);
|
|
1897 |
QTest::newRow("abc<right>") << keys << 2 << 3;
|
|
1898 |
keys.clear();
|
|
1899 |
|
|
1900 |
keys.addKeyClick(Qt::Key_A);
|
|
1901 |
keys.addKeyClick(Qt::Key_B);
|
|
1902 |
keys.addKeyClick(Qt::Key_C);
|
|
1903 |
psKeyClick(keys, Qt::Key_Home);
|
|
1904 |
keys.addKeyClick(Qt::Key_Right);
|
|
1905 |
QTest::newRow("abc<home><right>") << keys << 0 << 1;
|
|
1906 |
keys.clear();
|
|
1907 |
|
|
1908 |
keys.addKeyClick(Qt::Key_A);
|
|
1909 |
keys.addKeyClick(Qt::Key_B);
|
|
1910 |
keys.addKeyClick(Qt::Key_C);
|
|
1911 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
1912 |
QTest::newRow("abc<backspace>") << keys << 3 << 2;
|
|
1913 |
keys.clear();
|
|
1914 |
|
|
1915 |
keys.addKeyClick(Qt::Key_A);
|
|
1916 |
keys.addKeyClick(Qt::Key_B);
|
|
1917 |
keys.addKeyClick(Qt::Key_C);
|
|
1918 |
keys.addKeyClick(Qt::Key_Delete);
|
|
1919 |
QTest::newRow("abc<delete>") << keys << 2 << 3;
|
|
1920 |
keys.clear();
|
|
1921 |
|
|
1922 |
keys.addKeyClick(Qt::Key_A);
|
|
1923 |
keys.addKeyClick(Qt::Key_B);
|
|
1924 |
keys.addKeyClick(Qt::Key_C);
|
|
1925 |
keys.addKeyClick(Qt::Key_Left);
|
|
1926 |
keys.addKeyClick(Qt::Key_Delete);
|
|
1927 |
QTest::newRow("abc<left><delete>") << keys << 3 << 2;
|
|
1928 |
keys.clear();
|
|
1929 |
|
|
1930 |
keys.addKeyClick(Qt::Key_A);
|
|
1931 |
keys.addKeyClick(Qt::Key_B);
|
|
1932 |
keys.addKeyClick(Qt::Key_C);
|
|
1933 |
psKeyClick(keys, Qt::Key_Home);
|
|
1934 |
psKeyClick(keys, Qt::Key_End);
|
|
1935 |
QTest::newRow("abc<home><end>") << keys << 0 << 3;
|
|
1936 |
keys.clear();
|
|
1937 |
|
|
1938 |
keys.addKeyClick(Qt::Key_A);
|
|
1939 |
keys.addKeyClick(Qt::Key_B);
|
|
1940 |
keys.addKeyClick(Qt::Key_C);
|
|
1941 |
keys.addKeyClick(Qt::Key_Space);
|
|
1942 |
keys.addKeyClick(Qt::Key_D);
|
|
1943 |
keys.addKeyClick(Qt::Key_E);
|
|
1944 |
keys.addKeyClick(Qt::Key_F);
|
|
1945 |
keys.addKeyClick(Qt::Key_Home);
|
|
1946 |
keys.addKeyClick(Qt::Key_Right, Qt::ControlModifier);
|
|
1947 |
QTest::newRow("abc efg<home><ctrl-right>") << keys
|
|
1948 |
#ifndef Q_WS_MAC
|
|
1949 |
<< 0 << 4;
|
|
1950 |
#else
|
|
1951 |
<< 6 << 7;
|
|
1952 |
#endif
|
|
1953 |
keys.clear();
|
|
1954 |
|
|
1955 |
#ifdef Q_WS_MAC
|
|
1956 |
keys.addKeyClick(Qt::Key_A);
|
|
1957 |
keys.addKeyClick(Qt::Key_B);
|
|
1958 |
keys.addKeyClick(Qt::Key_C);
|
|
1959 |
keys.addKeyClick(Qt::Key_Space);
|
|
1960 |
keys.addKeyClick(Qt::Key_D);
|
|
1961 |
keys.addKeyClick(Qt::Key_E);
|
|
1962 |
keys.addKeyClick(Qt::Key_F);
|
|
1963 |
keys.addKeyClick(Qt::Key_Up);
|
|
1964 |
keys.addKeyClick(Qt::Key_Right, Qt::AltModifier);
|
|
1965 |
QTest::newRow("mac equivalent abc efg<up><option-right>") << keys << 0 << 4;
|
|
1966 |
keys.clear();
|
|
1967 |
#endif
|
|
1968 |
|
|
1969 |
keys.addKeyClick(Qt::Key_A);
|
|
1970 |
keys.addKeyClick(Qt::Key_B);
|
|
1971 |
keys.addKeyClick(Qt::Key_C);
|
|
1972 |
keys.addKeyClick(Qt::Key_Space);
|
|
1973 |
keys.addKeyClick(Qt::Key_D);
|
|
1974 |
keys.addKeyClick(Qt::Key_E);
|
|
1975 |
keys.addKeyClick(Qt::Key_F);
|
|
1976 |
keys.addKeyClick(Qt::Key_Left, Qt::ControlModifier);
|
|
1977 |
QTest::newRow("abc efg<ctrl-left>") << keys << 7
|
|
1978 |
#ifndef Q_WS_MAC
|
|
1979 |
<< 4;
|
|
1980 |
#else
|
|
1981 |
<< 0;
|
|
1982 |
#endif
|
|
1983 |
keys.clear();
|
|
1984 |
#ifdef Q_WS_MAC
|
|
1985 |
keys.addKeyClick(Qt::Key_A);
|
|
1986 |
keys.addKeyClick(Qt::Key_B);
|
|
1987 |
keys.addKeyClick(Qt::Key_C);
|
|
1988 |
keys.addKeyClick(Qt::Key_Space);
|
|
1989 |
keys.addKeyClick(Qt::Key_D);
|
|
1990 |
keys.addKeyClick(Qt::Key_E);
|
|
1991 |
keys.addKeyClick(Qt::Key_F);
|
|
1992 |
keys.addKeyClick(Qt::Key_Left, Qt::AltModifier);
|
|
1993 |
QTest::newRow("mac equivalent abc efg<option-left>") << keys << 7 << 4;
|
|
1994 |
keys.clear();
|
|
1995 |
#endif
|
|
1996 |
}
|
|
1997 |
|
|
1998 |
|
|
1999 |
void tst_QLineEdit::cursorPositionChanged()
|
|
2000 |
{
|
|
2001 |
QFETCH(QTestEventList, input);
|
|
2002 |
QFETCH(int, lastPos);
|
|
2003 |
QFETCH(int, newPos);
|
|
2004 |
|
|
2005 |
lastCursorPos = 0;
|
|
2006 |
newCursorPos = 0;
|
|
2007 |
input.simulate(testWidget);
|
|
2008 |
QCOMPARE(lastCursorPos, lastPos);
|
|
2009 |
QCOMPARE(newCursorPos, newPos);
|
|
2010 |
}
|
|
2011 |
|
|
2012 |
void tst_QLineEdit::selectedText()
|
|
2013 |
{
|
|
2014 |
QString testString = "Abc defg hijklmno, p 'qrst' uvw xyz";
|
|
2015 |
|
|
2016 |
// start with a basic text
|
|
2017 |
testWidget->setText(testString);
|
|
2018 |
selection_count = 0;
|
|
2019 |
|
|
2020 |
// The text we have now is:
|
|
2021 |
// 1 2 3 4 5
|
|
2022 |
// 012345678901234567890123456789012345678901234567890
|
|
2023 |
// Abc defg hijklmno, p 'qrst' uvw xyz
|
|
2024 |
|
|
2025 |
testWidget->home(false);
|
|
2026 |
QVERIFY(!testWidget->hasSelectedText());
|
|
2027 |
QCOMPARE(testWidget->selectedText(), QString());
|
|
2028 |
|
|
2029 |
// play a bit with the cursorForward, cursorBackward(), etc
|
|
2030 |
testWidget->cursorForward(true, 9);
|
|
2031 |
QVERIFY(testWidget->hasSelectedText());
|
|
2032 |
QCOMPARE(testWidget->selectedText(), QString("Abc defg "));
|
|
2033 |
QVERIFY(selection_count == 1);
|
|
2034 |
|
|
2035 |
// reset selection
|
|
2036 |
testWidget->home(false);
|
|
2037 |
QVERIFY(!testWidget->hasSelectedText());
|
|
2038 |
QCOMPARE(testWidget->selectedText(), QString());
|
|
2039 |
selection_count = 0;
|
|
2040 |
}
|
|
2041 |
|
|
2042 |
/* // tested in selectedText
|
|
2043 |
void tst_QLineEdit::backspace()
|
|
2044 |
void tst_QLineEdit::del()
|
|
2045 |
void tst_QLineEdit::selectionChanged()
|
|
2046 |
void tst_QLineEdit::selectAll()
|
|
2047 |
void tst_QLineEdit::deselect()
|
|
2048 |
*/
|
|
2049 |
|
|
2050 |
void tst_QLineEdit::onSelectionChanged()
|
|
2051 |
{
|
|
2052 |
selection_count++;
|
|
2053 |
}
|
|
2054 |
|
|
2055 |
void tst_QLineEdit::hasSelectedText()
|
|
2056 |
{
|
|
2057 |
DEPENDS_ON("selectedText");
|
|
2058 |
}
|
|
2059 |
|
|
2060 |
void tst_QLineEdit::deleteSelectedText()
|
|
2061 |
{
|
|
2062 |
const QString text = QString::fromLatin1("bar");
|
|
2063 |
QLineEdit edit( text );
|
|
2064 |
QCOMPARE(edit.text(), text);
|
|
2065 |
|
|
2066 |
edit.selectAll();
|
|
2067 |
|
|
2068 |
QTest::keyClick(&edit, Qt::Key_Delete, 0);
|
|
2069 |
QVERIFY(edit.text().isEmpty());
|
|
2070 |
|
|
2071 |
edit.setText(text);
|
|
2072 |
edit.selectAll();
|
|
2073 |
|
|
2074 |
QMenu *menu = edit.createStandardContextMenu();
|
|
2075 |
for (int i = 0; i < menu->actions().count(); ++i) {
|
|
2076 |
QAction *current = menu->actions().at(i);
|
|
2077 |
if (current->text() == QLineEdit::tr("Delete")) {
|
|
2078 |
current->trigger(); //this will delete the whole text selected
|
|
2079 |
QVERIFY(edit.text().isEmpty());
|
|
2080 |
}
|
|
2081 |
}
|
|
2082 |
|
|
2083 |
}
|
|
2084 |
|
|
2085 |
|
|
2086 |
void tst_QLineEdit::textChangedAndTextEdited()
|
|
2087 |
{
|
|
2088 |
changed_count = 0;
|
|
2089 |
edited_count = 0;
|
|
2090 |
|
|
2091 |
QTest::keyClick(testWidget, Qt::Key_A);
|
|
2092 |
QCOMPARE(changed_count, 1);
|
|
2093 |
QVERIFY(edited_count == changed_count);
|
|
2094 |
QTest::keyClick(testWidget, 'b');
|
|
2095 |
QCOMPARE(changed_count, 2);
|
|
2096 |
QVERIFY(edited_count == changed_count);
|
|
2097 |
QTest::keyClick(testWidget, 'c');
|
|
2098 |
QCOMPARE(changed_count, 3);
|
|
2099 |
QVERIFY(edited_count == changed_count);
|
|
2100 |
QTest::keyClick(testWidget, ' ');
|
|
2101 |
QCOMPARE(changed_count, 4);
|
|
2102 |
QVERIFY(edited_count == changed_count);
|
|
2103 |
QTest::keyClick(testWidget, 'd');
|
|
2104 |
QCOMPARE(changed_count, 5);
|
|
2105 |
QVERIFY(edited_count == changed_count);
|
|
2106 |
|
|
2107 |
changed_count = 0;
|
|
2108 |
edited_count = 0;
|
|
2109 |
changed_string = QString::null;
|
|
2110 |
|
|
2111 |
testWidget->setText("foo");
|
|
2112 |
QCOMPARE(changed_count, 1);
|
|
2113 |
QCOMPARE(edited_count, 0);
|
|
2114 |
QCOMPARE(changed_string, QString("foo"));
|
|
2115 |
|
|
2116 |
changed_count = 0;
|
|
2117 |
edited_count = 0;
|
|
2118 |
changed_string = QString::null;
|
|
2119 |
|
|
2120 |
testWidget->setText("");
|
|
2121 |
QCOMPARE(changed_count, 1);
|
|
2122 |
QCOMPARE(edited_count, 0);
|
|
2123 |
QVERIFY(changed_string.isEmpty());
|
|
2124 |
QVERIFY(!changed_string.isNull());
|
|
2125 |
}
|
|
2126 |
|
|
2127 |
void tst_QLineEdit::onTextChanged(const QString &text)
|
|
2128 |
{
|
|
2129 |
changed_count++;
|
|
2130 |
changed_string = text;
|
|
2131 |
}
|
|
2132 |
|
|
2133 |
void tst_QLineEdit::onTextEdited(const QString &/*text*/)
|
|
2134 |
{
|
|
2135 |
edited_count++;
|
|
2136 |
}
|
|
2137 |
|
|
2138 |
|
|
2139 |
void tst_QLineEdit::onCursorPositionChanged(int oldPos, int newPos)
|
|
2140 |
{
|
|
2141 |
lastCursorPos = oldPos;
|
|
2142 |
newCursorPos = newPos;
|
|
2143 |
}
|
|
2144 |
|
|
2145 |
void tst_QLineEdit::returnPressed()
|
|
2146 |
{
|
|
2147 |
return_count = 0;
|
|
2148 |
|
|
2149 |
QTest::keyClick(testWidget, Qt::Key_Return);
|
|
2150 |
QVERIFY(return_count == 1);
|
|
2151 |
return_count = 0;
|
|
2152 |
|
|
2153 |
QTest::keyClick(testWidget, 'A');
|
|
2154 |
QVERIFY(return_count == 0);
|
|
2155 |
QTest::keyClick(testWidget, 'b');
|
|
2156 |
QVERIFY(return_count == 0);
|
|
2157 |
QTest::keyClick(testWidget, 'c');
|
|
2158 |
QVERIFY(return_count == 0);
|
|
2159 |
QTest::keyClick(testWidget, ' ');
|
|
2160 |
QVERIFY(return_count == 0);
|
|
2161 |
QTest::keyClick(testWidget, 'd');
|
|
2162 |
QVERIFY(return_count == 0);
|
|
2163 |
psKeyClick(testWidget, Qt::Key_Home);
|
|
2164 |
QVERIFY(return_count == 0);
|
|
2165 |
psKeyClick(testWidget, Qt::Key_End);
|
|
2166 |
QVERIFY(return_count == 0);
|
|
2167 |
QTest::keyClick(testWidget, Qt::Key_Escape);
|
|
2168 |
QVERIFY(return_count == 0);
|
|
2169 |
QTest::keyClick(testWidget, Qt::Key_Return);
|
|
2170 |
QVERIFY(return_count == 1);
|
|
2171 |
}
|
|
2172 |
|
|
2173 |
// int validator that fixes all !isNumber to '0'
|
|
2174 |
class QIntFixValidator : public QIntValidator {
|
|
2175 |
public:
|
|
2176 |
QIntFixValidator(int min, int max, QObject *parent) : QIntValidator(min, max, parent) {}
|
|
2177 |
void fixup (QString &input) const {
|
|
2178 |
for (int i=0; i<input.length(); ++i)
|
|
2179 |
if (!input.at(i).isNumber()) {
|
|
2180 |
input[(int)i] = QChar('0');
|
|
2181 |
}
|
|
2182 |
}
|
|
2183 |
};
|
|
2184 |
|
|
2185 |
void tst_QLineEdit::returnPressed_maskvalidator_data() {
|
|
2186 |
QTest::addColumn<QString>("inputMask");
|
|
2187 |
QTest::addColumn<bool>("hasValidator");
|
|
2188 |
QTest::addColumn<QTestEventList>("input");
|
|
2189 |
QTest::addColumn<QString>("expectedText");
|
|
2190 |
QTest::addColumn<bool>("returnPressed");
|
|
2191 |
|
|
2192 |
{
|
|
2193 |
QTestEventList keys;
|
|
2194 |
keys.addKeyClick(Qt::Key_Home);
|
|
2195 |
keys.addKeyClick(Qt::Key_1);
|
|
2196 |
keys.addKeyClick(Qt::Key_2);
|
|
2197 |
keys.addKeyClick(Qt::Key_3);
|
|
2198 |
keys.addKeyClick(Qt::Key_Return);
|
|
2199 |
QTest::newRow("no mask, no validator, input '123<cr>'")
|
|
2200 |
<< QString()
|
|
2201 |
<< false
|
|
2202 |
<< keys
|
|
2203 |
<< QString("123")
|
|
2204 |
<< true;
|
|
2205 |
}
|
|
2206 |
{
|
|
2207 |
QTestEventList keys;
|
|
2208 |
keys.addKeyClick(Qt::Key_Home);
|
|
2209 |
keys.addKeyClick(Qt::Key_1);
|
|
2210 |
keys.addKeyClick(Qt::Key_2);
|
|
2211 |
keys.addKeyClick(Qt::Key_Return);
|
|
2212 |
QTest::newRow("mask '999', no validator, input '12<cr>'")
|
|
2213 |
<< QString("999")
|
|
2214 |
<< false
|
|
2215 |
<< keys
|
|
2216 |
<< QString("12")
|
|
2217 |
<< false;
|
|
2218 |
}
|
|
2219 |
{
|
|
2220 |
QTestEventList keys;
|
|
2221 |
keys.addKeyClick(Qt::Key_Home);
|
|
2222 |
keys.addKeyClick(Qt::Key_1);
|
|
2223 |
keys.addKeyClick(Qt::Key_2);
|
|
2224 |
keys.addKeyClick(Qt::Key_3);
|
|
2225 |
keys.addKeyClick(Qt::Key_Return);
|
|
2226 |
QTest::newRow("mask '999', no validator, input '123<cr>'")
|
|
2227 |
<< QString("999")
|
|
2228 |
<< false
|
|
2229 |
<< keys
|
|
2230 |
<< QString("123")
|
|
2231 |
<< true;
|
|
2232 |
}
|
|
2233 |
{
|
|
2234 |
QTestEventList keys;
|
|
2235 |
keys.addKeyClick(Qt::Key_Home);
|
|
2236 |
keys.addKeyClick(Qt::Key_1);
|
|
2237 |
keys.addKeyClick(Qt::Key_2);
|
|
2238 |
keys.addKeyClick(Qt::Key_3);
|
|
2239 |
keys.addKeyClick(Qt::Key_Return);
|
|
2240 |
QTest::newRow("no mask, intfix validator(0,999), input '123<cr>'")
|
|
2241 |
<< QString()
|
|
2242 |
<< true
|
|
2243 |
<< keys
|
|
2244 |
<< QString("123")
|
|
2245 |
<< true;
|
|
2246 |
}
|
|
2247 |
{
|
|
2248 |
QTestEventList keys;
|
|
2249 |
keys.addKeyClick(Qt::Key_Home);
|
|
2250 |
keys.addKeyClick(Qt::Key_7);
|
|
2251 |
keys.addKeyClick(Qt::Key_7);
|
|
2252 |
keys.addKeyClick(Qt::Key_7);
|
|
2253 |
keys.addKeyClick(Qt::Key_7);
|
|
2254 |
keys.addKeyClick(Qt::Key_Return);
|
|
2255 |
QTest::newRow("no mask, intfix validator(0,999), input '7777<cr>'")
|
|
2256 |
<< QString()
|
|
2257 |
<< true
|
|
2258 |
<< keys
|
|
2259 |
<< QString("777")
|
|
2260 |
<< true;
|
|
2261 |
}
|
|
2262 |
{
|
|
2263 |
QTestEventList keys;
|
|
2264 |
keys.addKeyClick(Qt::Key_Home);
|
|
2265 |
keys.addKeyClick(Qt::Key_1);
|
|
2266 |
keys.addKeyClick(Qt::Key_2);
|
|
2267 |
keys.addKeyClick(Qt::Key_Return);
|
|
2268 |
QTest::newRow("mask '999', intfix validator(0,999), input '12<cr>'")
|
|
2269 |
<< QString("999")
|
|
2270 |
<< true
|
|
2271 |
<< keys
|
|
2272 |
<< QString("12")
|
|
2273 |
<< false;
|
|
2274 |
}
|
|
2275 |
{
|
|
2276 |
QTestEventList keys;
|
|
2277 |
keys.addKeyClick(Qt::Key_Home);
|
|
2278 |
keys.addKeyClick(Qt::Key_Return);
|
|
2279 |
QTest::newRow("mask '999', intfix validator(0,999), input '<cr>'")
|
|
2280 |
<< QString("999")
|
|
2281 |
<< true
|
|
2282 |
<< keys
|
|
2283 |
<< QString("000")
|
|
2284 |
<< true;
|
|
2285 |
}
|
|
2286 |
}
|
|
2287 |
|
|
2288 |
void tst_QLineEdit::returnPressed_maskvalidator()
|
|
2289 |
{
|
|
2290 |
QFETCH(QString, inputMask);
|
|
2291 |
QFETCH(bool, hasValidator);
|
|
2292 |
QFETCH(QTestEventList, input);
|
|
2293 |
QFETCH(QString, expectedText);
|
|
2294 |
QFETCH(bool, returnPressed);
|
|
2295 |
|
|
2296 |
QEXPECT_FAIL("mask '999', intfix validator(0,999), input '12<cr>'", "QIntValidator has changed behaviour. Does not accept spaces. Task 43082.", Abort);
|
|
2297 |
|
|
2298 |
testWidget->setInputMask(inputMask);
|
|
2299 |
if (hasValidator)
|
|
2300 |
testWidget->setValidator(new QIntFixValidator(0, 999, testWidget));
|
|
2301 |
|
|
2302 |
return_count = 0;
|
|
2303 |
input.simulate(testWidget);
|
|
2304 |
|
|
2305 |
QCOMPARE(testWidget->text(), expectedText);
|
|
2306 |
QCOMPARE(return_count , returnPressed ? 1 : 0);
|
|
2307 |
}
|
|
2308 |
|
|
2309 |
void tst_QLineEdit::onReturnPressed()
|
|
2310 |
{
|
|
2311 |
return_count++;
|
|
2312 |
}
|
|
2313 |
|
|
2314 |
void tst_QLineEdit::setValidator()
|
|
2315 |
{
|
|
2316 |
// Verify that we can set and re-set a validator.
|
|
2317 |
QVERIFY(!testWidget->validator());
|
|
2318 |
|
|
2319 |
QIntValidator iv1(0);
|
|
2320 |
testWidget->setValidator(&iv1);
|
|
2321 |
QCOMPARE(testWidget->validator(), static_cast<const QValidator*>(&iv1));
|
|
2322 |
|
|
2323 |
testWidget->setValidator(0);
|
|
2324 |
QVERIFY(testWidget->validator() == 0);
|
|
2325 |
|
|
2326 |
QIntValidator iv2(0, 99, 0);
|
|
2327 |
testWidget->setValidator(&iv2);
|
|
2328 |
QCOMPARE(testWidget->validator(), static_cast<const QValidator *>(&iv2));
|
|
2329 |
|
|
2330 |
testWidget->setValidator(0);
|
|
2331 |
QVERIFY(testWidget->validator() == 0);
|
|
2332 |
}
|
|
2333 |
|
|
2334 |
void tst_QLineEdit::validator()
|
|
2335 |
{
|
|
2336 |
DEPENDS_ON("setValidator");
|
|
2337 |
}
|
|
2338 |
|
|
2339 |
void tst_QLineEdit::clearValidator()
|
|
2340 |
{
|
|
2341 |
DEPENDS_ON("setValidator");
|
|
2342 |
}
|
|
2343 |
|
|
2344 |
void tst_QLineEdit::setValidator_QIntValidator_data()
|
|
2345 |
{
|
|
2346 |
QTest::addColumn<int>("mini");
|
|
2347 |
QTest::addColumn<int>("maxi");
|
|
2348 |
QTest::addColumn<QString>("input");
|
|
2349 |
QTest::addColumn<QString>("expectedText");
|
|
2350 |
QTest::addColumn<bool>("useKeys");
|
|
2351 |
QTest::addColumn<bool>("is_valid");
|
|
2352 |
|
|
2353 |
for (int i=0; i<2; i++) {
|
|
2354 |
bool useKeys = false;
|
|
2355 |
QString inputMode = "insert ";
|
|
2356 |
if (i!=0) {
|
|
2357 |
inputMode = "useKeys ";
|
|
2358 |
useKeys = true;
|
|
2359 |
}
|
|
2360 |
|
|
2361 |
// valid data
|
|
2362 |
QTest::newRow(QString(inputMode + "range [0,9] valid '1'").toLatin1())
|
|
2363 |
<< 0
|
|
2364 |
<< 9
|
|
2365 |
<< QString("1")
|
|
2366 |
<< QString("1")
|
|
2367 |
<< bool(useKeys)
|
|
2368 |
<< bool(true);
|
|
2369 |
|
|
2370 |
QTest::newRow(QString(inputMode + "range [3,7] valid '3'").toLatin1())
|
|
2371 |
<< 3
|
|
2372 |
<< 7
|
|
2373 |
<< QString("3")
|
|
2374 |
<< QString("3")
|
|
2375 |
<< bool(useKeys)
|
|
2376 |
<< bool(true);
|
|
2377 |
|
|
2378 |
QTest::newRow(QString(inputMode + "range [3,7] valid '7'").toLatin1())
|
|
2379 |
<< 3
|
|
2380 |
<< 7
|
|
2381 |
<< QString("7")
|
|
2382 |
<< QString("7")
|
|
2383 |
<< bool(useKeys)
|
|
2384 |
<< bool(true);
|
|
2385 |
|
|
2386 |
QTest::newRow(QString(inputMode + "range [0,100] valid '9'").toLatin1())
|
|
2387 |
<< 0
|
|
2388 |
<< 100
|
|
2389 |
<< QString("9")
|
|
2390 |
<< QString("9")
|
|
2391 |
<< bool(useKeys)
|
|
2392 |
<< bool(true);
|
|
2393 |
|
|
2394 |
QTest::newRow(QString(inputMode + "range [0,100] valid '12'").toLatin1())
|
|
2395 |
<< 0
|
|
2396 |
<< 100
|
|
2397 |
<< QString("12")
|
|
2398 |
<< QString("12")
|
|
2399 |
<< bool(useKeys)
|
|
2400 |
<< bool(true);
|
|
2401 |
|
|
2402 |
QTest::newRow(QString(inputMode + "range [-100,100] valid '-12'").toLatin1())
|
|
2403 |
<< -100
|
|
2404 |
<< 100
|
|
2405 |
<< QString("-12")
|
|
2406 |
<< QString("-12")
|
|
2407 |
<< bool(useKeys)
|
|
2408 |
<< bool(true);
|
|
2409 |
|
|
2410 |
// invalid data
|
|
2411 |
// characters not allowed in QIntValidator
|
|
2412 |
QTest::newRow(QString(inputMode + "range [0,9] inv 'a-a'").toLatin1())
|
|
2413 |
<< 0
|
|
2414 |
<< 9
|
|
2415 |
<< QString("a")
|
|
2416 |
<< QString("")
|
|
2417 |
<< bool(useKeys)
|
|
2418 |
<< bool(false);
|
|
2419 |
|
|
2420 |
QTest::newRow(QString(inputMode + "range [0,9] inv 'A'").toLatin1())
|
|
2421 |
<< 0
|
|
2422 |
<< 9
|
|
2423 |
<< QString("A")
|
|
2424 |
<< QString("")
|
|
2425 |
<< bool(useKeys)
|
|
2426 |
<< bool(false);
|
|
2427 |
// minus sign only allowed with a range on the negative side
|
|
2428 |
QTest::newRow(QString(inputMode + "range [0,100] inv '-'").toLatin1())
|
|
2429 |
<< 0
|
|
2430 |
<< 100
|
|
2431 |
<< QString("-")
|
|
2432 |
<< QString("")
|
|
2433 |
<< bool(useKeys)
|
|
2434 |
<< bool(false);
|
|
2435 |
QTest::newRow(QString(inputMode + "range [0,100] int '153'").toLatin1())
|
|
2436 |
<< 0
|
|
2437 |
<< 100
|
|
2438 |
<< QString("153")
|
|
2439 |
<< QString(useKeys ? "15" : "")
|
|
2440 |
<< bool(useKeys)
|
|
2441 |
<< bool(useKeys ? true : false);
|
|
2442 |
QTest::newRow(QString(inputMode + "range [-100,100] int '-153'").toLatin1())
|
|
2443 |
<< -100
|
|
2444 |
<< 100
|
|
2445 |
<< QString("-153")
|
|
2446 |
<< QString(useKeys ? "-15" : "")
|
|
2447 |
<< bool(useKeys)
|
|
2448 |
<< bool(useKeys ? true : false);
|
|
2449 |
QTest::newRow(QString(inputMode + "range [3,7] int '2'").toLatin1())
|
|
2450 |
<< 3
|
|
2451 |
<< 7
|
|
2452 |
<< QString("2")
|
|
2453 |
<< QString("2")
|
|
2454 |
<< bool(useKeys)
|
|
2455 |
<< bool(false);
|
|
2456 |
|
|
2457 |
QTest::newRow(QString(inputMode + "range [3,7] int '8'").toLatin1())
|
|
2458 |
<< 3
|
|
2459 |
<< 7
|
|
2460 |
<< QString("8")
|
|
2461 |
<< QString("")
|
|
2462 |
<< bool(useKeys)
|
|
2463 |
<< bool(false);
|
|
2464 |
}
|
|
2465 |
}
|
|
2466 |
|
|
2467 |
void tst_QLineEdit::setValidator_QIntValidator()
|
|
2468 |
{
|
|
2469 |
QFETCH(int, mini);
|
|
2470 |
QFETCH(int, maxi);
|
|
2471 |
QFETCH(QString, input);
|
|
2472 |
QFETCH(QString, expectedText);
|
|
2473 |
QFETCH(bool, useKeys);
|
|
2474 |
QFETCH(bool, is_valid);
|
|
2475 |
|
|
2476 |
QIntValidator intValidator(mini, maxi, 0);
|
|
2477 |
testWidget->setValidator(&intValidator);
|
|
2478 |
QVERIFY(testWidget->text().isEmpty());
|
|
2479 |
//qDebug("1 input: '" + input + "' Exp: '" + expectedText + "'");
|
|
2480 |
|
|
2481 |
// tests valid input
|
|
2482 |
if (!useKeys) {
|
|
2483 |
testWidget->insert(input);
|
|
2484 |
} else {
|
|
2485 |
QTest::keyClicks(testWidget, input);
|
|
2486 |
return_count = 0;
|
|
2487 |
QTest::keyClick(testWidget, Qt::Key_Return);
|
|
2488 |
QCOMPARE(return_count, int(is_valid)); // assuming that is_valid = true equals 1
|
|
2489 |
}
|
|
2490 |
//qDebug("2 input: '" + input + "' Exp: '" + expectedText + "'");
|
|
2491 |
// QCOMPARE(testWidget->displayText(), expectedText);
|
|
2492 |
QCOMPARE(testWidget->text(), expectedText);
|
|
2493 |
}
|
|
2494 |
|
|
2495 |
#define NO_PIXMAP_TESTS
|
|
2496 |
|
|
2497 |
void tst_QLineEdit::frame_data()
|
|
2498 |
{
|
|
2499 |
#ifndef NO_PIXMAP_TESTS
|
|
2500 |
#if defined Q_WS_WIN
|
|
2501 |
QTest::addColumn<QPixmap>("noFrame");
|
|
2502 |
QTest::addColumn<QPixmap>("useFrame");
|
|
2503 |
|
|
2504 |
QTest::newRow("win");
|
|
2505 |
//#else
|
|
2506 |
// QTest::newRow("x11");
|
|
2507 |
#endif
|
|
2508 |
#endif
|
|
2509 |
}
|
|
2510 |
|
|
2511 |
void tst_QLineEdit::frame()
|
|
2512 |
{
|
|
2513 |
testWidget->setFrame(false);
|
|
2514 |
// verify that the editor is shown without a frame
|
|
2515 |
#ifndef NO_PIXMAP_TESTS
|
|
2516 |
#if defined Q_WS_WIN
|
|
2517 |
QTEST(testWidget, "noFrame");
|
|
2518 |
#endif
|
|
2519 |
#endif
|
|
2520 |
QVERIFY(!testWidget->hasFrame());
|
|
2521 |
|
|
2522 |
testWidget->setFrame(true);
|
|
2523 |
// verify that the editor is shown with a frame
|
|
2524 |
#ifndef NO_PIXMAP_TESTS
|
|
2525 |
#if defined Q_WS_WIN
|
|
2526 |
QTEST(testWidget, "useFrame");
|
|
2527 |
#endif
|
|
2528 |
#endif
|
|
2529 |
QVERIFY(testWidget->hasFrame());
|
|
2530 |
}
|
|
2531 |
|
|
2532 |
void tst_QLineEdit::alignment()
|
|
2533 |
{
|
|
2534 |
DEPENDS_ON("setAlignment");
|
|
2535 |
}
|
|
2536 |
|
|
2537 |
void tst_QLineEdit::setAlignment_data()
|
|
2538 |
{
|
|
2539 |
#ifndef NO_PIXMAP_TESTS
|
|
2540 |
#if defined Q_WS_WIN
|
|
2541 |
QTest::addColumn<QPixmap>("left");
|
|
2542 |
QTest::addColumn<QPixmap>("right");
|
|
2543 |
QTest::addColumn<QPixmap>("hcenter");
|
|
2544 |
QTest::addColumn<QPixmap>("auto");
|
|
2545 |
|
|
2546 |
QTest::newRow("win");
|
|
2547 |
//#else
|
|
2548 |
// QTest::newRow("x11");
|
|
2549 |
#endif
|
|
2550 |
#endif
|
|
2551 |
}
|
|
2552 |
|
|
2553 |
void tst_QLineEdit::setAlignment()
|
|
2554 |
{
|
|
2555 |
testWidget->setText("left");
|
|
2556 |
testWidget->setAlignment(Qt::AlignLeft);
|
|
2557 |
#ifndef NO_PIXMAP_TESTS
|
|
2558 |
#if defined Q_WS_WIN
|
|
2559 |
QTEST(testWidget, "left");
|
|
2560 |
#endif
|
|
2561 |
#endif
|
|
2562 |
QVERIFY(testWidget->alignment() == Qt::AlignLeft);
|
|
2563 |
|
|
2564 |
#ifdef QT3_SUPPORT
|
|
2565 |
testWidget->setText("auto");
|
|
2566 |
testWidget->setAlignment(Qt::AlignAuto);
|
|
2567 |
#ifndef NO_PIXMAP_TESTS
|
|
2568 |
#if defined Q_WS_WIN
|
|
2569 |
QTEST(testWidget, "auto");
|
|
2570 |
#endif
|
|
2571 |
#endif
|
|
2572 |
#endif
|
|
2573 |
|
|
2574 |
testWidget->setText("hcenter");
|
|
2575 |
testWidget->setAlignment(Qt::AlignHCenter);
|
|
2576 |
#ifndef NO_PIXMAP_TESTS
|
|
2577 |
#if defined Q_WS_WIN
|
|
2578 |
QTEST(testWidget, "hcenter");
|
|
2579 |
#endif
|
|
2580 |
#endif
|
|
2581 |
QVERIFY(testWidget->alignment() == Qt::AlignHCenter);
|
|
2582 |
|
|
2583 |
#ifdef QT3_SUPPORT
|
|
2584 |
testWidget->setText("auto");
|
|
2585 |
testWidget->setAlignment(Qt::AlignAuto);
|
|
2586 |
#ifndef NO_PIXMAP_TESTS
|
|
2587 |
#if defined Q_WS_WIN
|
|
2588 |
QTEST(testWidget, "auto");
|
|
2589 |
#endif
|
|
2590 |
#endif
|
|
2591 |
#endif
|
|
2592 |
|
|
2593 |
testWidget->setText("right");
|
|
2594 |
testWidget->setAlignment(Qt::AlignRight);
|
|
2595 |
#ifndef NO_PIXMAP_TESTS
|
|
2596 |
#if defined Q_WS_WIN
|
|
2597 |
QTEST(testWidget, "right");
|
|
2598 |
#endif
|
|
2599 |
#endif
|
|
2600 |
QVERIFY(testWidget->alignment() == Qt::AlignRight);
|
|
2601 |
|
|
2602 |
#ifdef QT3_SUPPORT
|
|
2603 |
testWidget->setText("auto");
|
|
2604 |
testWidget->setAlignment(Qt::AlignAuto);
|
|
2605 |
#ifndef NO_PIXMAP_TESTS
|
|
2606 |
#if defined Q_WS_WIN
|
|
2607 |
QTEST(testWidget, "auto");
|
|
2608 |
#endif
|
|
2609 |
#endif
|
|
2610 |
QVERIFY(testWidget->alignment() == Qt::AlignAuto);
|
|
2611 |
#endif
|
|
2612 |
|
|
2613 |
testWidget->setAlignment(Qt::AlignTop);
|
|
2614 |
QVERIFY(testWidget->alignment() == Qt::AlignTop);
|
|
2615 |
|
|
2616 |
testWidget->setAlignment(Qt::AlignBottom);
|
|
2617 |
QVERIFY(testWidget->alignment() == Qt::AlignBottom);
|
|
2618 |
|
|
2619 |
testWidget->setAlignment(Qt::AlignCenter);
|
|
2620 |
QVERIFY(testWidget->alignment() == Qt::AlignCenter);
|
|
2621 |
}
|
|
2622 |
|
|
2623 |
void tst_QLineEdit::isModified()
|
|
2624 |
{
|
|
2625 |
QVERIFY(!testWidget->isModified());
|
|
2626 |
testWidget->setText("bla");
|
|
2627 |
QVERIFY(!testWidget->isModified());
|
|
2628 |
|
|
2629 |
psKeyClick(testWidget, Qt::Key_Home);
|
|
2630 |
QVERIFY(!testWidget->isModified());
|
|
2631 |
QTest::keyClick(testWidget, Qt::Key_Right);
|
|
2632 |
QVERIFY(!testWidget->isModified());
|
|
2633 |
QTest::keyClick(testWidget, Qt::Key_Right);
|
|
2634 |
QVERIFY(!testWidget->isModified());
|
|
2635 |
QTest::keyClick(testWidget, Qt::Key_Right);
|
|
2636 |
QVERIFY(!testWidget->isModified());
|
|
2637 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
2638 |
QVERIFY(!testWidget->isModified());
|
|
2639 |
psKeyClick(testWidget, Qt::Key_End);
|
|
2640 |
QVERIFY(!testWidget->isModified());
|
|
2641 |
|
|
2642 |
QTest::keyClicks(testWidget, "T");
|
|
2643 |
QVERIFY(testWidget->isModified());
|
|
2644 |
QTest::keyClicks(testWidget, "his is a string");
|
|
2645 |
QVERIFY(testWidget->isModified());
|
|
2646 |
|
|
2647 |
testWidget->setText("");
|
|
2648 |
QVERIFY(!testWidget->isModified());
|
|
2649 |
testWidget->setText("foo");
|
|
2650 |
QVERIFY(!testWidget->isModified());
|
|
2651 |
}
|
|
2652 |
|
|
2653 |
/*
|
|
2654 |
Obsolete function but as long as we provide it, it needs to work.
|
|
2655 |
*/
|
|
2656 |
|
|
2657 |
void tst_QLineEdit::edited()
|
|
2658 |
{
|
|
2659 |
QVERIFY(!testWidget->isModified());
|
|
2660 |
testWidget->setText("bla");
|
|
2661 |
QVERIFY(!testWidget->isModified());
|
|
2662 |
|
|
2663 |
psKeyClick(testWidget, Qt::Key_Home);
|
|
2664 |
QVERIFY(!testWidget->isModified());
|
|
2665 |
QTest::keyClick(testWidget, Qt::Key_Right);
|
|
2666 |
QVERIFY(!testWidget->isModified());
|
|
2667 |
QTest::keyClick(testWidget, Qt::Key_Right);
|
|
2668 |
QVERIFY(!testWidget->isModified());
|
|
2669 |
QTest::keyClick(testWidget, Qt::Key_Right);
|
|
2670 |
QVERIFY(!testWidget->isModified());
|
|
2671 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
2672 |
QVERIFY(!testWidget->isModified());
|
|
2673 |
psKeyClick(testWidget, Qt::Key_End);
|
|
2674 |
QVERIFY(!testWidget->isModified());
|
|
2675 |
|
|
2676 |
QTest::keyClicks(testWidget, "T");
|
|
2677 |
QVERIFY(testWidget->isModified());
|
|
2678 |
QTest::keyClicks(testWidget, "his is a string");
|
|
2679 |
QVERIFY(testWidget->isModified());
|
|
2680 |
|
|
2681 |
testWidget->setModified(false);
|
|
2682 |
QVERIFY(!testWidget->isModified());
|
|
2683 |
|
|
2684 |
testWidget->setModified(true);
|
|
2685 |
QVERIFY(testWidget->isModified());
|
|
2686 |
}
|
|
2687 |
|
|
2688 |
/*
|
|
2689 |
Obsolete function but as long as we provide it, it needs to work.
|
|
2690 |
*/
|
|
2691 |
|
|
2692 |
void tst_QLineEdit::setEdited()
|
|
2693 |
{
|
|
2694 |
DEPENDS_ON("edited");
|
|
2695 |
}
|
|
2696 |
|
|
2697 |
void tst_QLineEdit::insert()
|
|
2698 |
{
|
|
2699 |
testWidget->insert("This");
|
|
2700 |
testWidget->insert(" is");
|
|
2701 |
testWidget->insert(" a");
|
|
2702 |
testWidget->insert(" test");
|
|
2703 |
|
|
2704 |
QCOMPARE(testWidget->text(), QString("This is a test"));
|
|
2705 |
|
|
2706 |
testWidget->cursorWordBackward(false);
|
|
2707 |
testWidget->cursorBackward(false, 1);
|
|
2708 |
testWidget->insert(" nice");
|
|
2709 |
QCOMPARE(testWidget->text(), QString("This is a nice test"));
|
|
2710 |
|
|
2711 |
testWidget->setCursorPosition(-1);
|
|
2712 |
testWidget->insert("No Crash! ");
|
|
2713 |
QCOMPARE(testWidget->text(), QString("No Crash! This is a nice test"));
|
|
2714 |
}
|
|
2715 |
|
|
2716 |
void tst_QLineEdit::setSelection_data()
|
|
2717 |
{
|
|
2718 |
QTest::addColumn<QString>("text");
|
|
2719 |
QTest::addColumn<int>("start");
|
|
2720 |
QTest::addColumn<int>("length");
|
|
2721 |
QTest::addColumn<int>("expectedCursor");
|
|
2722 |
QTest::addColumn<QString>("expectedText");
|
|
2723 |
QTest::addColumn<bool>("expectedHasSelectedText");
|
|
2724 |
|
|
2725 |
QString text = "Abc defg hijklmno, p 'qrst' uvw xyz";
|
|
2726 |
int start, length, pos;
|
|
2727 |
|
|
2728 |
start = 0; length = 1; pos = 1;
|
|
2729 |
QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
|
|
2730 |
<< text << start << length << pos << QString("A") << true;
|
|
2731 |
|
|
2732 |
start = 0; length = 2; pos = 2;
|
|
2733 |
QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
|
|
2734 |
<< text << start << length << pos << QString("Ab") << true;
|
|
2735 |
|
|
2736 |
start = 0; length = 4; pos = 4;
|
|
2737 |
QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
|
|
2738 |
<< text << start << length << pos << QString("Abc ") << true;
|
|
2739 |
|
|
2740 |
start = -1; length = 0; pos = text.length();
|
|
2741 |
QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
|
|
2742 |
<< text << start << length << pos << QString() << false;
|
|
2743 |
|
|
2744 |
start = 34; length = 1; pos = 35;
|
|
2745 |
QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
|
|
2746 |
<< text << start << length << pos << QString("z") << true;
|
|
2747 |
|
|
2748 |
start = 34; length = 2; pos = 35;
|
|
2749 |
QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
|
|
2750 |
<< text << start << length << pos << QString("z") << true;
|
|
2751 |
|
|
2752 |
start = 34; length = -1; pos = 33;
|
|
2753 |
QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
|
|
2754 |
<< text << start << length << pos << QString("y") << true;
|
|
2755 |
|
|
2756 |
start = 1; length = -2; pos = 0;
|
|
2757 |
QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
|
|
2758 |
<< text << start << length << pos << QString("A") << true;
|
|
2759 |
|
|
2760 |
start = -1; length = -1; pos = text.length();
|
|
2761 |
QTest::newRow(QString("selection start: %1 length: %2").arg(start).arg(length).toLatin1())
|
|
2762 |
<< text << start << length << pos << QString() << false;
|
|
2763 |
}
|
|
2764 |
|
|
2765 |
|
|
2766 |
void tst_QLineEdit::setSelection()
|
|
2767 |
{
|
|
2768 |
QFETCH(QString, text);
|
|
2769 |
QFETCH(int, start);
|
|
2770 |
QFETCH(int, length);
|
|
2771 |
QFETCH(int, expectedCursor);
|
|
2772 |
QFETCH(QString, expectedText);
|
|
2773 |
QFETCH(bool, expectedHasSelectedText);
|
|
2774 |
|
|
2775 |
testWidget->setText(text);
|
|
2776 |
testWidget->setSelection(start, length);
|
|
2777 |
QCOMPARE(testWidget->hasSelectedText(), expectedHasSelectedText);
|
|
2778 |
QCOMPARE(testWidget->selectedText(), expectedText);
|
|
2779 |
if (expectedCursor >= 0)
|
|
2780 |
QCOMPARE(testWidget->cursorPosition(), expectedCursor);
|
|
2781 |
}
|
|
2782 |
|
|
2783 |
#ifndef QT_NO_CLIPBOARD
|
|
2784 |
void tst_QLineEdit::cut()
|
|
2785 |
{
|
|
2786 |
#ifdef Q_WS_MAC
|
|
2787 |
{
|
|
2788 |
PasteboardRef pasteboard;
|
|
2789 |
OSStatus status = PasteboardCreate(0, &pasteboard);
|
|
2790 |
if (status == noErr)
|
|
2791 |
CFRelease(pasteboard);
|
|
2792 |
else
|
|
2793 |
QSKIP("Autotests run from cron and pasteboard don't get along quite ATM", SkipAll);
|
|
2794 |
}
|
|
2795 |
#endif
|
|
2796 |
// test newlines in cut'n'paste
|
|
2797 |
testWidget->setText("A\nB\nC\n");
|
|
2798 |
testWidget->setSelection(0, 6);
|
|
2799 |
testWidget->cut();
|
|
2800 |
psKeyClick(testWidget, Qt::Key_Home);
|
|
2801 |
testWidget->paste();
|
|
2802 |
QCOMPARE(testWidget->text(), QString("A\nB\nC\n"));
|
|
2803 |
// 1 2 3 4
|
|
2804 |
// 01234567890123456789012345678901234567890
|
|
2805 |
testWidget->setText("Abc defg hijklmno");
|
|
2806 |
|
|
2807 |
testWidget->setSelection(0, 3);
|
|
2808 |
testWidget->cut();
|
|
2809 |
QCOMPARE(testWidget->text(), QString(" defg hijklmno"));
|
|
2810 |
|
|
2811 |
psKeyClick(testWidget, Qt::Key_End);
|
|
2812 |
testWidget->paste();
|
|
2813 |
QCOMPARE(testWidget->text(), QString(" defg hijklmnoAbc"));
|
|
2814 |
|
|
2815 |
psKeyClick(testWidget, Qt::Key_Home);
|
|
2816 |
testWidget->del();
|
|
2817 |
QCOMPARE(testWidget->text(), QString("defg hijklmnoAbc"));
|
|
2818 |
|
|
2819 |
testWidget->setSelection(0, 4);
|
|
2820 |
testWidget->copy();
|
|
2821 |
psKeyClick(testWidget, Qt::Key_End);
|
|
2822 |
testWidget->paste();
|
|
2823 |
QCOMPARE(testWidget->text(), QString("defg hijklmnoAbcdefg"));
|
|
2824 |
|
|
2825 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
2826 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
2827 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
2828 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
2829 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
2830 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
2831 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
2832 |
QTest::keyClick(testWidget, ' ');
|
|
2833 |
QCOMPARE(testWidget->text(), QString("defg hijklmno Abcdefg"));
|
|
2834 |
|
|
2835 |
testWidget->setSelection(0, 5);
|
|
2836 |
testWidget->del();
|
|
2837 |
QCOMPARE(testWidget->text(), QString("hijklmno Abcdefg"));
|
|
2838 |
|
|
2839 |
testWidget->end(false);
|
|
2840 |
QTest::keyClick(testWidget, ' ');
|
|
2841 |
testWidget->paste();
|
|
2842 |
QCOMPARE(testWidget->text(), QString("hijklmno Abcdefg defg"));
|
|
2843 |
|
|
2844 |
testWidget->home(false);
|
|
2845 |
testWidget->cursorWordForward(true);
|
|
2846 |
testWidget->cut();
|
|
2847 |
testWidget->end(false);
|
|
2848 |
QTest::keyClick(testWidget, ' ');
|
|
2849 |
testWidget->paste();
|
|
2850 |
testWidget->cursorBackward(true, 1);
|
|
2851 |
testWidget->cut();
|
|
2852 |
QCOMPARE(testWidget->text(), QString("Abcdefg defg hijklmno"));
|
|
2853 |
}
|
|
2854 |
|
|
2855 |
void tst_QLineEdit::copy()
|
|
2856 |
{
|
|
2857 |
DEPENDS_ON("cut");
|
|
2858 |
}
|
|
2859 |
|
|
2860 |
void tst_QLineEdit::paste()
|
|
2861 |
{
|
|
2862 |
DEPENDS_ON("cut");
|
|
2863 |
}
|
|
2864 |
#endif
|
|
2865 |
class InputMaskValidator : public QValidator
|
|
2866 |
{
|
|
2867 |
public:
|
|
2868 |
InputMaskValidator(QObject *parent, const char *name = 0) : QValidator(parent) { setObjectName(name); }
|
|
2869 |
State validate(QString &text, int &pos) const
|
|
2870 |
{
|
|
2871 |
InputMaskValidator *that = (InputMaskValidator *)this;
|
|
2872 |
that->validateText = text;
|
|
2873 |
that->validatePos = pos;
|
|
2874 |
return Acceptable;
|
|
2875 |
}
|
|
2876 |
QString validateText;
|
|
2877 |
int validatePos;
|
|
2878 |
};
|
|
2879 |
|
|
2880 |
void tst_QLineEdit::inputMaskAndValidator_data()
|
|
2881 |
{
|
|
2882 |
QTest::addColumn<QString>("inputMask");
|
|
2883 |
QTest::addColumn<QTestEventList>("keys");
|
|
2884 |
QTest::addColumn<QString>("validateText");
|
|
2885 |
QTest::addColumn<int>("validatePos");
|
|
2886 |
|
|
2887 |
QTestEventList inputKeys;
|
|
2888 |
inputKeys.addKeyClick(Qt::Key_1);
|
|
2889 |
inputKeys.addKeyClick(Qt::Key_2);
|
|
2890 |
|
|
2891 |
QTest::newRow("task28291") << "000;_" << inputKeys << "12_" << 2;
|
|
2892 |
}
|
|
2893 |
|
|
2894 |
void tst_QLineEdit::inputMaskAndValidator()
|
|
2895 |
{
|
|
2896 |
QFETCH(QString, inputMask);
|
|
2897 |
QFETCH(QTestEventList, keys);
|
|
2898 |
QFETCH(QString, validateText);
|
|
2899 |
QFETCH(int, validatePos);
|
|
2900 |
|
|
2901 |
InputMaskValidator imv(testWidget);
|
|
2902 |
testWidget->setValidator(&imv);
|
|
2903 |
|
|
2904 |
testWidget->setInputMask(inputMask);
|
|
2905 |
keys.simulate(testWidget);
|
|
2906 |
|
|
2907 |
QCOMPARE(imv.validateText, validateText);
|
|
2908 |
QCOMPARE(imv.validatePos, validatePos);
|
|
2909 |
}
|
|
2910 |
|
|
2911 |
void tst_QLineEdit::maxLengthAndInputMask()
|
|
2912 |
{
|
|
2913 |
// Really a test for #30447
|
|
2914 |
QVERIFY(testWidget->inputMask().isNull());
|
|
2915 |
testWidget->setMaxLength(10);
|
|
2916 |
QVERIFY(testWidget->maxLength() == 10);
|
|
2917 |
testWidget->setInputMask(QString::null);
|
|
2918 |
QVERIFY(testWidget->inputMask().isNull());
|
|
2919 |
QVERIFY(testWidget->maxLength() == 10);
|
|
2920 |
}
|
|
2921 |
|
|
2922 |
|
|
2923 |
class LineEdit : public QLineEdit
|
|
2924 |
{
|
|
2925 |
public:
|
|
2926 |
LineEdit() { state = Other; }
|
|
2927 |
|
|
2928 |
void keyPressEvent(QKeyEvent *e)
|
|
2929 |
{
|
|
2930 |
QLineEdit::keyPressEvent(e);
|
|
2931 |
if (e->key() == Qt::Key_Enter) {
|
|
2932 |
state = e->isAccepted() ? Accepted : Ignored;
|
|
2933 |
} else {
|
|
2934 |
state = Other;
|
|
2935 |
}
|
|
2936 |
|
|
2937 |
}
|
|
2938 |
enum State {
|
|
2939 |
Accepted,
|
|
2940 |
Ignored,
|
|
2941 |
Other
|
|
2942 |
};
|
|
2943 |
|
|
2944 |
State state;
|
|
2945 |
};
|
|
2946 |
|
|
2947 |
Q_DECLARE_METATYPE(LineEdit::State);
|
|
2948 |
void tst_QLineEdit::returnPressedKeyEvent()
|
|
2949 |
{
|
|
2950 |
LineEdit lineedit;
|
|
2951 |
lineedit.show();
|
|
2952 |
QCOMPARE((int)lineedit.state, (int)LineEdit::Other);
|
|
2953 |
QTest::keyClick(&lineedit, Qt::Key_Enter);
|
|
2954 |
QCOMPARE((int)lineedit.state, (int)LineEdit::Ignored);
|
|
2955 |
connect(&lineedit, SIGNAL(returnPressed()), this, SLOT(onReturnPressed()));
|
|
2956 |
QTest::keyClick(&lineedit, Qt::Key_Enter);
|
|
2957 |
QCOMPARE((int)lineedit.state, (int)LineEdit::Ignored);
|
|
2958 |
disconnect(&lineedit, SIGNAL(returnPressed()), this, SLOT(onReturnPressed()));
|
|
2959 |
QTest::keyClick(&lineedit, Qt::Key_Enter);
|
|
2960 |
QCOMPARE((int)lineedit.state, (int)LineEdit::Ignored);
|
|
2961 |
QTest::keyClick(&lineedit, Qt::Key_1);
|
|
2962 |
QCOMPARE((int)lineedit.state, (int)LineEdit::Other);
|
|
2963 |
}
|
|
2964 |
|
|
2965 |
void tst_QLineEdit::keepSelectionOnTabFocusIn()
|
|
2966 |
{
|
|
2967 |
testWidget->setText("hello world");
|
|
2968 |
{
|
|
2969 |
QFocusEvent e(QEvent::FocusIn, Qt::TabFocusReason);
|
|
2970 |
QApplication::sendEvent(testWidget, &e);
|
|
2971 |
}
|
|
2972 |
QCOMPARE(testWidget->selectedText(), QString("hello world"));
|
|
2973 |
testWidget->setSelection(0, 5);
|
|
2974 |
QCOMPARE(testWidget->selectedText(), QString("hello"));
|
|
2975 |
{
|
|
2976 |
QFocusEvent e(QEvent::FocusIn, Qt::TabFocusReason);
|
|
2977 |
QApplication::sendEvent(testWidget, &e);
|
|
2978 |
}
|
|
2979 |
QCOMPARE(testWidget->selectedText(), QString("hello"));
|
|
2980 |
}
|
|
2981 |
|
|
2982 |
void tst_QLineEdit::readOnlyStyleOption()
|
|
2983 |
{
|
|
2984 |
bool wasReadOnly = testWidget->isReadOnly();
|
|
2985 |
QStyle *oldStyle = testWidget->style();
|
|
2986 |
|
|
2987 |
StyleOptionTestStyle myStyle;
|
|
2988 |
testWidget->setStyle(&myStyle);
|
|
2989 |
|
|
2990 |
myStyle.setReadOnly(true);
|
|
2991 |
testWidget->setReadOnly(true);
|
|
2992 |
testWidget->repaint();
|
|
2993 |
qApp->processEvents();
|
|
2994 |
|
|
2995 |
testWidget->setReadOnly(false);
|
|
2996 |
myStyle.setReadOnly(false);
|
|
2997 |
testWidget->repaint();
|
|
2998 |
qApp->processEvents();
|
|
2999 |
|
|
3000 |
testWidget->setReadOnly(wasReadOnly);
|
|
3001 |
testWidget->setStyle(oldStyle);
|
|
3002 |
}
|
|
3003 |
|
|
3004 |
void tst_QLineEdit::validateOnFocusOut()
|
|
3005 |
{
|
|
3006 |
QSignalSpy editingFinishedSpy(testWidget, SIGNAL(editingFinished()));
|
|
3007 |
testWidget->setValidator(new QIntValidator(100, 999, 0));
|
|
3008 |
QTest::keyPress(testWidget, '1');
|
|
3009 |
QTest::keyPress(testWidget, '0');
|
|
3010 |
QCOMPARE(testWidget->text(), QString("10"));
|
|
3011 |
testWidget->clearFocus();
|
|
3012 |
QCOMPARE(editingFinishedSpy.count(), 0);
|
|
3013 |
|
|
3014 |
testWidget->setFocus();
|
|
3015 |
testWidget->activateWindow();
|
|
3016 |
QTRY_VERIFY(testWidget->hasFocus());
|
|
3017 |
|
|
3018 |
QTest::keyPress(testWidget, '0');
|
|
3019 |
QTRY_COMPARE(testWidget->text(), QString("100"));
|
|
3020 |
|
|
3021 |
testWidget->clearFocus();
|
|
3022 |
QCOMPARE(editingFinishedSpy.count(), 1);
|
|
3023 |
}
|
|
3024 |
|
|
3025 |
void tst_QLineEdit::editInvalidText()
|
|
3026 |
{
|
|
3027 |
testWidget->clear();
|
|
3028 |
testWidget->setValidator(new QIntValidator(0, 120, 0));
|
|
3029 |
testWidget->setText("1234");
|
|
3030 |
|
|
3031 |
QVERIFY(!testWidget->hasAcceptableInput());
|
|
3032 |
QTest::keyPress(testWidget, Qt::Key_Backspace);
|
|
3033 |
QTest::keyPress(testWidget, Qt::Key_Backspace);
|
|
3034 |
QTest::keyPress(testWidget, Qt::Key_A);
|
|
3035 |
QTest::keyPress(testWidget, Qt::Key_B);
|
|
3036 |
QTest::keyPress(testWidget, Qt::Key_C);
|
|
3037 |
QTest::keyPress(testWidget, Qt::Key_1);
|
|
3038 |
QVERIFY(testWidget->hasAcceptableInput());
|
|
3039 |
QCOMPARE(testWidget->text(), QString("12"));
|
|
3040 |
testWidget->cursorBackward(false);
|
|
3041 |
testWidget->cursorBackward(true, 2);
|
|
3042 |
QTest::keyPress(testWidget, Qt::Key_Delete);
|
|
3043 |
QVERIFY(testWidget->hasAcceptableInput());
|
|
3044 |
QCOMPARE(testWidget->text(), QString("2"));
|
|
3045 |
QTest::keyPress(testWidget, Qt::Key_1);
|
|
3046 |
QVERIFY(testWidget->hasAcceptableInput());
|
|
3047 |
QCOMPARE(testWidget->text(), QString("12"));
|
|
3048 |
|
|
3049 |
testWidget->setValidator(0);
|
|
3050 |
}
|
|
3051 |
|
|
3052 |
void tst_QLineEdit::charWithAltOrCtrlModifier()
|
|
3053 |
{
|
|
3054 |
testWidget->clear();
|
|
3055 |
QCOMPARE(testWidget->text(), QString(""));
|
|
3056 |
QTest::keyPress(testWidget, Qt::Key_Plus);
|
|
3057 |
QCOMPARE(testWidget->text(), QString("+"));
|
|
3058 |
QTest::keyPress(testWidget, Qt::Key_Plus, Qt::ControlModifier);
|
|
3059 |
QCOMPARE(testWidget->text(), QString("++"));
|
|
3060 |
QTest::keyPress(testWidget, Qt::Key_Plus, Qt::AltModifier);
|
|
3061 |
QCOMPARE(testWidget->text(), QString("+++"));
|
|
3062 |
QTest::keyPress(testWidget, Qt::Key_Plus, Qt::AltModifier | Qt::ControlModifier);
|
|
3063 |
QCOMPARE(testWidget->text(), QString("++++"));
|
|
3064 |
}
|
|
3065 |
|
|
3066 |
void tst_QLineEdit::leftKeyOnSelectedText()
|
|
3067 |
{
|
|
3068 |
testWidget->clear();
|
|
3069 |
testWidget->setText("0123");
|
|
3070 |
testWidget->setCursorPosition(4);
|
|
3071 |
QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
|
|
3072 |
QCOMPARE(testWidget->cursorPosition(), 3);
|
|
3073 |
QCOMPARE(testWidget->selectedText(), QString("3"));
|
|
3074 |
QTest::keyClick(testWidget, Qt::Key_Left, Qt::ShiftModifier);
|
|
3075 |
QCOMPARE(testWidget->cursorPosition(), 2);
|
|
3076 |
QCOMPARE(testWidget->selectedText(), QString("23"));
|
|
3077 |
QTest::keyClick(testWidget, Qt::Key_Left);
|
|
3078 |
#ifdef Q_OS_WIN
|
|
3079 |
QCOMPARE(testWidget->cursorPosition(), 1);
|
|
3080 |
#else
|
|
3081 |
// X11 used to behave like window prior to 4.2. Changes caused by QKeySequence
|
|
3082 |
// resulted in an inadvertant change in behavior
|
|
3083 |
QCOMPARE(testWidget->cursorPosition(), 2);
|
|
3084 |
#endif
|
|
3085 |
}
|
|
3086 |
|
|
3087 |
void tst_QLineEdit::inlineCompletion()
|
|
3088 |
{
|
|
3089 |
testWidget->clear();
|
|
3090 |
QStandardItemModel *model = new QStandardItemModel;
|
|
3091 |
QStandardItem *root = model->invisibleRootItem();
|
|
3092 |
QStandardItem *items[5];
|
|
3093 |
for (int i = 0; i < 5; i++) {
|
|
3094 |
items[i] = new QStandardItem(QString("item%1").arg(i));
|
|
3095 |
if ((i+2)%2 == 0) { // disable 0,2,4
|
|
3096 |
items[i]->setFlags(items[i]->flags() & ~Qt::ItemIsEnabled);
|
|
3097 |
}
|
|
3098 |
root->appendRow(items[i]);
|
|
3099 |
}
|
|
3100 |
QCompleter *completer = new QCompleter(model);
|
|
3101 |
completer->setCompletionMode(QCompleter::InlineCompletion);
|
|
3102 |
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
|
3103 |
testWidget->setFocus();
|
|
3104 |
QTRY_COMPARE(qApp->activeWindow(), (QWidget*)testWidget);
|
|
3105 |
testWidget->setCompleter(completer);
|
|
3106 |
|
|
3107 |
// sanity
|
|
3108 |
QTest::keyClick(testWidget, Qt::Key_X);
|
|
3109 |
QCOMPARE(testWidget->selectedText(), QString());
|
|
3110 |
QCOMPARE(testWidget->text(), QString("x"));
|
|
3111 |
QTest::keyClick(testWidget, Qt::Key_Down, Qt::ControlModifier);
|
|
3112 |
QCOMPARE(testWidget->selectedText(), QString());
|
|
3113 |
QCOMPARE(testWidget->text(), QString("x"));
|
|
3114 |
QTest::keyClick(testWidget, Qt::Key_Up, Qt::ControlModifier);
|
|
3115 |
QCOMPARE(testWidget->selectedText(), QString());
|
|
3116 |
QCOMPARE(testWidget->text(), QString("x"));
|
|
3117 |
|
|
3118 |
testWidget->clear();
|
|
3119 |
QTest::keyClick(testWidget, Qt::Key_I);
|
|
3120 |
QCOMPARE(testWidget->selectedText(), QString("tem1"));
|
|
3121 |
|
|
3122 |
Qt::KeyboardModifiers keyboardModifiers = Qt::ControlModifier;
|
|
3123 |
#ifdef Q_WS_MAC
|
|
3124 |
keyboardModifiers |= Qt::AltModifier;
|
|
3125 |
#endif
|
|
3126 |
QTest::keyClick(testWidget, Qt::Key_Down, keyboardModifiers);
|
|
3127 |
QCOMPARE(testWidget->selectedText(), QString("tem3"));
|
|
3128 |
|
|
3129 |
// wraps around (Default)
|
|
3130 |
QTest::keyClick(testWidget, Qt::Key_Down, keyboardModifiers);
|
|
3131 |
QCOMPARE(testWidget->selectedText(), QString("tem1"));
|
|
3132 |
|
|
3133 |
QTest::keyClick(testWidget, Qt::Key_Up, keyboardModifiers);
|
|
3134 |
QCOMPARE(testWidget->selectedText(), QString("tem3"));
|
|
3135 |
|
|
3136 |
// should not wrap
|
|
3137 |
completer->setWrapAround(false);
|
|
3138 |
QTest::keyClick(testWidget, Qt::Key_Down, keyboardModifiers);
|
|
3139 |
QCOMPARE(testWidget->selectedText(), QString("tem3"));
|
|
3140 |
QTest::keyClick(testWidget, Qt::Key_Up, keyboardModifiers); // item1
|
|
3141 |
QTest::keyClick(testWidget, Qt::Key_Up, keyboardModifiers); // item1
|
|
3142 |
QCOMPARE(testWidget->selectedText(), QString("tem1"));
|
|
3143 |
|
|
3144 |
// trivia :)
|
|
3145 |
root->appendRow(new QStandardItem("item11"));
|
|
3146 |
root->appendRow(new QStandardItem("item12"));
|
|
3147 |
testWidget->clear();
|
|
3148 |
QTest::keyClick(testWidget, Qt::Key_I);
|
|
3149 |
QCOMPARE(testWidget->selectedText(), QString("tem1"));
|
|
3150 |
QTest::keyClick(testWidget, Qt::Key_Delete);
|
|
3151 |
QCOMPARE(testWidget->selectedText(), QString());
|
|
3152 |
QTest::keyClick(testWidget, Qt::Key_Down, keyboardModifiers);
|
|
3153 |
QCOMPARE(testWidget->selectedText(), QString("tem1")); // neato
|
|
3154 |
testWidget->setText("item1");
|
|
3155 |
testWidget->setSelection(1, 2);
|
|
3156 |
QTest::keyClick(testWidget, Qt::Key_Down, keyboardModifiers);
|
|
3157 |
testWidget->end(false);
|
|
3158 |
QCOMPARE(testWidget->text(), QString("item1")); // no effect for selection in "middle"
|
|
3159 |
QTest::keyClick(testWidget, Qt::Key_Down, keyboardModifiers); // item1
|
|
3160 |
QTest::keyClick(testWidget, Qt::Key_Down, keyboardModifiers); // item11
|
|
3161 |
QCOMPARE(testWidget->text(), QString("item11"));
|
|
3162 |
|
|
3163 |
delete model;
|
|
3164 |
delete completer;
|
|
3165 |
}
|
|
3166 |
|
|
3167 |
void tst_QLineEdit::noTextEditedOnClear()
|
|
3168 |
{
|
|
3169 |
testWidget->setText("Test");
|
|
3170 |
QSignalSpy textEditedSpy(testWidget, SIGNAL(textEdited(const QString &)));
|
|
3171 |
testWidget->clear();
|
|
3172 |
QCOMPARE(textEditedSpy.count(), 0);
|
|
3173 |
}
|
|
3174 |
|
|
3175 |
void tst_QLineEdit::textMargin_data()
|
|
3176 |
{
|
|
3177 |
QTest::addColumn<int>("left");
|
|
3178 |
QTest::addColumn<int>("top");
|
|
3179 |
QTest::addColumn<int>("right");
|
|
3180 |
QTest::addColumn<int>("bottom");
|
|
3181 |
|
|
3182 |
QTest::addColumn<QPoint>("mousePressPos");
|
|
3183 |
QTest::addColumn<int>("cursorPosition");
|
|
3184 |
|
|
3185 |
QLineEdit testWidget;
|
|
3186 |
QFontMetrics metrics(testWidget.font());
|
|
3187 |
const QString s = QLatin1String("MMM MMM MMM");
|
|
3188 |
|
|
3189 |
// Different styles generate different offsets, so
|
|
3190 |
// calculate the width rather than hardcode it.
|
|
3191 |
const int pixelWidthOfM = metrics.width(s, 1);
|
|
3192 |
const int pixelWidthOfMMM_MM = metrics.width(s, 6);
|
|
3193 |
|
|
3194 |
QTest::newRow("default-0") << 0 << 0 << 0 << 0 << QPoint(pixelWidthOfMMM_MM, 0) << 6;
|
|
3195 |
QTest::newRow("default-1") << 0 << 0 << 0 << 0 << QPoint(1, 1) << 0;
|
|
3196 |
QTest::newRow("default-2") << -1 << 0 << -1 << 0 << QPoint(pixelWidthOfMMM_MM, 0) << 6;
|
|
3197 |
QTest::newRow("default-3") << 0 << 0 << 0 << 0 << QPoint(pixelWidthOfM, 1) << 1;
|
|
3198 |
|
|
3199 |
QTest::newRow("hor-0") << 10 << 0 << 10 << 0 << QPoint(1, 1) << 0;
|
|
3200 |
QTest::newRow("hor-1") << 10 << 0 << 10 << 0 << QPoint(10, 1) << 0;
|
|
3201 |
QTest::newRow("hor-2") << 20 << 0 << 10 << 0 << QPoint(20, 1) << 0;
|
|
3202 |
|
|
3203 |
if (!qApp->style()->inherits("QMacStyle")) { //MacStyle doesn't support verticals margins.
|
|
3204 |
QTest::newRow("default-2-ver") << -1 << -1 << -1 << -1 << QPoint(pixelWidthOfMMM_MM, 0) << 6;
|
|
3205 |
QTest::newRow("ver") << 0 << 10 << 0 << 10 << QPoint(1, 1) << 0;
|
|
3206 |
}
|
|
3207 |
}
|
|
3208 |
|
|
3209 |
void tst_QLineEdit::textMargin()
|
|
3210 |
{
|
|
3211 |
QFETCH(int, left);
|
|
3212 |
QFETCH(int, top);
|
|
3213 |
QFETCH(int, right);
|
|
3214 |
QFETCH(int, bottom);
|
|
3215 |
QFETCH(QPoint, mousePressPos);
|
|
3216 |
QFETCH(int, cursorPosition);
|
|
3217 |
|
|
3218 |
// Put the line edit into a toplevel window to avoid
|
|
3219 |
// resizing by the window system.
|
|
3220 |
QWidget tlw;
|
|
3221 |
QLineEdit testWidget(&tlw);
|
|
3222 |
testWidget.setGeometry(100, 100, 100, 30);
|
|
3223 |
testWidget.setText("MMM MMM MMM");
|
|
3224 |
testWidget.setCursorPosition(6);
|
|
3225 |
|
|
3226 |
QSize sizeHint = testWidget.sizeHint();
|
|
3227 |
testWidget.setTextMargins(left, top, right, bottom);
|
|
3228 |
sizeHint.setWidth(sizeHint.width() + left + right);
|
|
3229 |
sizeHint.setHeight(sizeHint.height() + top +bottom);
|
|
3230 |
QCOMPARE(testWidget.sizeHint(), sizeHint);
|
|
3231 |
testWidget.setFrame(false);
|
|
3232 |
tlw.show();
|
|
3233 |
|
|
3234 |
int l;
|
|
3235 |
int t;
|
|
3236 |
int r;
|
|
3237 |
int b;
|
|
3238 |
testWidget.getTextMargins(&l, &t, &r, &b);
|
|
3239 |
QCOMPARE(left, l);
|
|
3240 |
QCOMPARE(top, t);
|
|
3241 |
QCOMPARE(right, r);
|
|
3242 |
QCOMPARE(bottom, b);
|
|
3243 |
|
|
3244 |
QTest::mouseClick(&testWidget, Qt::LeftButton, 0, mousePressPos);
|
|
3245 |
QTRY_COMPARE(testWidget.cursorPosition(), cursorPosition);
|
|
3246 |
}
|
|
3247 |
|
|
3248 |
void tst_QLineEdit::cursor()
|
|
3249 |
{
|
|
3250 |
#ifdef QT_NO_CURSOR
|
|
3251 |
QSKIP("Qt compiled without cursor support", SkipAll);
|
|
3252 |
#else
|
|
3253 |
testWidget->setReadOnly(false);
|
|
3254 |
QCOMPARE(testWidget->cursor().shape(), Qt::IBeamCursor);
|
|
3255 |
testWidget->setReadOnly(true);
|
|
3256 |
QCOMPARE(testWidget->cursor().shape(), Qt::ArrowCursor);
|
|
3257 |
testWidget->setReadOnly(false);
|
|
3258 |
QCOMPARE(testWidget->cursor().shape(), Qt::IBeamCursor);
|
|
3259 |
#endif
|
|
3260 |
}
|
|
3261 |
|
|
3262 |
class task180999_Widget : public QWidget
|
|
3263 |
{
|
|
3264 |
public:
|
|
3265 |
task180999_Widget(QWidget *parent = 0) : QWidget(parent)
|
|
3266 |
{
|
|
3267 |
QHBoxLayout *layout = new QHBoxLayout(this);
|
|
3268 |
lineEdit1.setText("some text 1 ...");
|
|
3269 |
lineEdit2.setText("some text 2 ...");
|
|
3270 |
layout->addWidget(&lineEdit1);
|
|
3271 |
layout->addWidget(&lineEdit2);
|
|
3272 |
}
|
|
3273 |
|
|
3274 |
QLineEdit lineEdit1;
|
|
3275 |
QLineEdit lineEdit2;
|
|
3276 |
};
|
|
3277 |
|
|
3278 |
void tst_QLineEdit::task180999_focus()
|
|
3279 |
{
|
|
3280 |
task180999_Widget widget;
|
|
3281 |
|
|
3282 |
widget.lineEdit1.setFocus();
|
|
3283 |
widget.show();
|
|
3284 |
|
|
3285 |
widget.lineEdit2.setFocus();
|
|
3286 |
widget.lineEdit2.selectAll();
|
|
3287 |
widget.hide();
|
|
3288 |
|
|
3289 |
widget.lineEdit1.setFocus();
|
|
3290 |
widget.show();
|
|
3291 |
QTest::qWait(200);
|
|
3292 |
widget.activateWindow();
|
|
3293 |
|
|
3294 |
QTRY_VERIFY(!widget.lineEdit2.hasSelectedText());
|
|
3295 |
}
|
|
3296 |
|
|
3297 |
void tst_QLineEdit::task174640_editingFinished()
|
|
3298 |
{
|
|
3299 |
QWidget mw;
|
|
3300 |
QVBoxLayout *layout = new QVBoxLayout(&mw);
|
|
3301 |
QLineEdit *le1 = new QLineEdit(&mw);
|
|
3302 |
QLineEdit *le2 = new QLineEdit(&mw);
|
|
3303 |
layout->addWidget(le1);
|
|
3304 |
layout->addWidget(le2);
|
|
3305 |
|
|
3306 |
mw.show();
|
|
3307 |
QApplication::setActiveWindow(&mw);
|
|
3308 |
mw.activateWindow();
|
|
3309 |
QTest::qWaitForWindowShown(&mw);
|
|
3310 |
|
|
3311 |
QSignalSpy editingFinishedSpy(le1, SIGNAL(editingFinished()));
|
|
3312 |
|
|
3313 |
le1->setFocus();
|
|
3314 |
QTest::qWait(20);
|
|
3315 |
QTRY_VERIFY(le1->hasFocus());
|
|
3316 |
QCOMPARE(editingFinishedSpy.count(), 0);
|
|
3317 |
|
|
3318 |
le2->setFocus();
|
|
3319 |
QTest::qWait(20);
|
|
3320 |
QTRY_VERIFY(le2->hasFocus());
|
|
3321 |
QCOMPARE(editingFinishedSpy.count(), 1);
|
|
3322 |
editingFinishedSpy.clear();
|
|
3323 |
|
|
3324 |
le1->setFocus();
|
|
3325 |
QTest::qWait(20);
|
|
3326 |
QTRY_VERIFY(le1->hasFocus());
|
|
3327 |
|
|
3328 |
QMenu *testMenu1 = new QMenu(le1);
|
|
3329 |
testMenu1->addAction("foo");
|
|
3330 |
testMenu1->addAction("bar");
|
|
3331 |
testMenu1->show();
|
|
3332 |
QTest::qWaitForWindowShown(testMenu1);
|
|
3333 |
QTest::qWait(20);
|
|
3334 |
mw.activateWindow();
|
|
3335 |
|
|
3336 |
delete testMenu1;
|
|
3337 |
QCOMPARE(editingFinishedSpy.count(), 0);
|
|
3338 |
QTRY_VERIFY(le1->hasFocus());
|
|
3339 |
|
|
3340 |
QMenu *testMenu2 = new QMenu(le2);
|
|
3341 |
testMenu2->addAction("foo2");
|
|
3342 |
testMenu2->addAction("bar2");
|
|
3343 |
testMenu2->show();
|
|
3344 |
QTest::qWaitForWindowShown(testMenu2);
|
|
3345 |
QTest::qWait(20);
|
|
3346 |
mw.activateWindow();
|
|
3347 |
delete testMenu2;
|
|
3348 |
QCOMPARE(editingFinishedSpy.count(), 1);
|
|
3349 |
}
|
|
3350 |
|
|
3351 |
#ifndef QT_NO_COMPLETER
|
|
3352 |
class task198789_Widget : public QWidget
|
|
3353 |
{
|
|
3354 |
Q_OBJECT
|
|
3355 |
public:
|
|
3356 |
task198789_Widget(QWidget *parent = 0) : QWidget(parent)
|
|
3357 |
{
|
|
3358 |
QStringList wordList;
|
|
3359 |
wordList << "alpha" << "omega" << "omicron" << "zeta";
|
|
3360 |
|
|
3361 |
lineEdit = new QLineEdit(this);
|
|
3362 |
completer = new QCompleter(wordList, this);
|
|
3363 |
lineEdit->setCompleter(completer);
|
|
3364 |
|
|
3365 |
connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
|
|
3366 |
}
|
|
3367 |
|
|
3368 |
QLineEdit *lineEdit;
|
|
3369 |
QCompleter *completer;
|
|
3370 |
QString currentCompletion;
|
|
3371 |
|
|
3372 |
private slots:
|
|
3373 |
void textChanged(const QString &)
|
|
3374 |
{
|
|
3375 |
currentCompletion = completer->currentCompletion();
|
|
3376 |
}
|
|
3377 |
};
|
|
3378 |
|
|
3379 |
void tst_QLineEdit::task198789_currentCompletion()
|
|
3380 |
{
|
|
3381 |
task198789_Widget widget;
|
|
3382 |
widget.show();
|
|
3383 |
qApp->processEvents();
|
|
3384 |
QTest::keyPress(widget.lineEdit, 'o');
|
|
3385 |
QTest::keyPress(widget.lineEdit, 'm');
|
|
3386 |
QTest::keyPress(widget.lineEdit, 'i');
|
|
3387 |
QCOMPARE(widget.currentCompletion, QLatin1String("omicron"));
|
|
3388 |
}
|
|
3389 |
|
|
3390 |
void tst_QLineEdit::task210502_caseInsensitiveInlineCompletion()
|
|
3391 |
{
|
|
3392 |
QString completion("ABCD");
|
|
3393 |
QStringList completions;
|
|
3394 |
completions << completion;
|
|
3395 |
QLineEdit lineEdit;
|
|
3396 |
QCompleter completer(completions);
|
|
3397 |
completer.setCaseSensitivity(Qt::CaseInsensitive);
|
|
3398 |
completer.setCompletionMode(QCompleter::InlineCompletion);
|
|
3399 |
lineEdit.setCompleter(&completer);
|
|
3400 |
lineEdit.show();
|
|
3401 |
#ifdef Q_WS_X11
|
|
3402 |
// to be safe and avoid failing setFocus with window managers
|
|
3403 |
qt_x11_wait_for_window_manager(&lineEdit);
|
|
3404 |
#endif
|
|
3405 |
lineEdit.setFocus();
|
|
3406 |
QTRY_VERIFY(lineEdit.hasFocus());
|
|
3407 |
QTest::keyPress(&lineEdit, 'a');
|
|
3408 |
QTest::keyPress(&lineEdit, Qt::Key_Return);
|
|
3409 |
QCOMPARE(lineEdit.text(), completion);
|
|
3410 |
}
|
|
3411 |
|
|
3412 |
#endif // QT_NO_COMPLETER
|
|
3413 |
|
|
3414 |
|
|
3415 |
void tst_QLineEdit::task229938_dontEmitChangedWhenTextIsNotChanged()
|
|
3416 |
{
|
|
3417 |
QLineEdit lineEdit;
|
|
3418 |
lineEdit.setMaxLength(5);
|
|
3419 |
lineEdit.show();
|
|
3420 |
#ifdef Q_WS_X11
|
|
3421 |
// to be safe and avoid failing setFocus with window managers
|
|
3422 |
qt_x11_wait_for_window_manager(&lineEdit);
|
|
3423 |
#endif
|
|
3424 |
lineEdit.setFocus();
|
|
3425 |
QSignalSpy changedSpy(&lineEdit, SIGNAL(textChanged(QString)));
|
|
3426 |
QTest::qWait(200);
|
|
3427 |
QTest::keyPress(&lineEdit, 'a');
|
|
3428 |
QTest::keyPress(&lineEdit, 'b');
|
|
3429 |
QTest::keyPress(&lineEdit, 'c');
|
|
3430 |
QTest::keyPress(&lineEdit, 'd');
|
|
3431 |
QTest::keyPress(&lineEdit, 'e');
|
|
3432 |
QTest::keyPress(&lineEdit, 'f');
|
|
3433 |
QCOMPARE(changedSpy.count(), 5);
|
|
3434 |
}
|
|
3435 |
|
|
3436 |
void tst_QLineEdit::task233101_cursorPosAfterInputMethod_data()
|
|
3437 |
{
|
|
3438 |
QTest::addColumn<int>("maxLength");
|
|
3439 |
QTest::addColumn<int>("cursorPos");
|
|
3440 |
QTest::addColumn<int>("replacementStart");
|
|
3441 |
QTest::addColumn<int>("replacementLength");
|
|
3442 |
QTest::addColumn<QString>("commitString");
|
|
3443 |
|
|
3444 |
QTest::newRow("") << 4 << 4 << 0 << 0 << QString("");
|
|
3445 |
QTest::newRow("") << 4 << 4 << 0 << 0 << QString("x");
|
|
3446 |
QTest::newRow("") << 4 << 4 << 0 << 0 << QString("xxxxxxxxxxxxxxxx");
|
|
3447 |
QTest::newRow("") << 4 << 3 << 0 << 0 << QString("");
|
|
3448 |
QTest::newRow("") << 4 << 3 << 0 << 0 << QString("x");
|
|
3449 |
QTest::newRow("") << 4 << 3 << 0 << 0 << QString("xxxxxxxxxxxxxxxx");
|
|
3450 |
QTest::newRow("") << 4 << 0 << 0 << 0 << QString("");
|
|
3451 |
QTest::newRow("") << 4 << 0 << 0 << 0 << QString("x");
|
|
3452 |
QTest::newRow("") << 4 << 0 << 0 << 0 << QString("xxxxxxxxxxxxxxxx");
|
|
3453 |
|
|
3454 |
QTest::newRow("") << 4 << 4 << -4 << 4 << QString("");
|
|
3455 |
QTest::newRow("") << 4 << 4 << -4 << 4 << QString("x");
|
|
3456 |
QTest::newRow("") << 4 << 4 << -4 << 4 << QString("xxxxxxxxxxxxxxxx");
|
|
3457 |
QTest::newRow("") << 4 << 3 << -3 << 4 << QString("");
|
|
3458 |
QTest::newRow("") << 4 << 3 << -3 << 4 << QString("x");
|
|
3459 |
QTest::newRow("") << 4 << 3 << -3 << 4 << QString("xxxxxxxxxxxxxxxx");
|
|
3460 |
QTest::newRow("") << 4 << 0 << 0 << 4 << QString("");
|
|
3461 |
QTest::newRow("") << 4 << 0 << 0 << 4 << QString("x");
|
|
3462 |
QTest::newRow("") << 4 << 0 << 0 << 4 << QString("xxxxxxxxxxxxxxxx");
|
|
3463 |
|
|
3464 |
QTest::newRow("") << 4 << 4 << -4 << 0 << QString("");
|
|
3465 |
QTest::newRow("") << 4 << 4 << -4 << 0 << QString("x");
|
|
3466 |
QTest::newRow("") << 4 << 4 << -4 << 0 << QString("xxxxxxxxxxxxxxxx");
|
|
3467 |
QTest::newRow("") << 4 << 3 << -3 << 0 << QString("");
|
|
3468 |
QTest::newRow("") << 4 << 3 << -3 << 0 << QString("x");
|
|
3469 |
QTest::newRow("") << 4 << 3 << -3 << 0 << QString("xxxxxxxxxxxxxxxx");
|
|
3470 |
}
|
|
3471 |
|
|
3472 |
void tst_QLineEdit::task233101_cursorPosAfterInputMethod()
|
|
3473 |
{
|
|
3474 |
QFETCH(int, maxLength);
|
|
3475 |
QFETCH(int, cursorPos);
|
|
3476 |
QFETCH(int, replacementStart);
|
|
3477 |
QFETCH(int, replacementLength);
|
|
3478 |
QFETCH(QString, commitString);
|
|
3479 |
|
|
3480 |
QLineEdit lineEdit;
|
|
3481 |
lineEdit.setMaxLength(maxLength);
|
|
3482 |
lineEdit.insert(QString().fill(QLatin1Char('a'), cursorPos));
|
|
3483 |
QCOMPARE(lineEdit.cursorPosition(), cursorPos);
|
|
3484 |
|
|
3485 |
QInputMethodEvent event;
|
|
3486 |
event.setCommitString(QLatin1String("x"), replacementStart, replacementLength);
|
|
3487 |
qApp->sendEvent(&lineEdit, &event);
|
|
3488 |
QVERIFY(lineEdit.cursorPosition() >= 0);
|
|
3489 |
QVERIFY(lineEdit.cursorPosition() <= lineEdit.text().size());
|
|
3490 |
QVERIFY(lineEdit.text().size() <= lineEdit.maxLength());
|
|
3491 |
}
|
|
3492 |
|
|
3493 |
void tst_QLineEdit::task241436_passwordEchoOnEditRestoreEchoMode()
|
|
3494 |
{
|
|
3495 |
QStyleOptionFrameV2 opt;
|
|
3496 |
QChar fillChar = testWidget->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, testWidget);
|
|
3497 |
|
|
3498 |
testWidget->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
|
3499 |
testWidget->setFocus();
|
|
3500 |
QApplication::setActiveWindow(testWidget);
|
|
3501 |
QTRY_VERIFY(testWidget->hasFocus());
|
|
3502 |
|
|
3503 |
QTest::keyPress(testWidget, '0');
|
|
3504 |
QCOMPARE(testWidget->displayText(), QString("0"));
|
|
3505 |
testWidget->setEchoMode(QLineEdit::Normal);
|
|
3506 |
testWidget->clearFocus();
|
|
3507 |
QCOMPARE(testWidget->displayText(), QString("0"));
|
|
3508 |
|
|
3509 |
testWidget->activateWindow();
|
|
3510 |
testWidget->setFocus();
|
|
3511 |
testWidget->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
|
3512 |
QTest::keyPress(testWidget, '0');
|
|
3513 |
QCOMPARE(testWidget->displayText(), QString("0"));
|
|
3514 |
testWidget->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
|
3515 |
QCOMPARE(testWidget->displayText(), QString("0"));
|
|
3516 |
testWidget->clearFocus();
|
|
3517 |
QCOMPARE(testWidget->displayText(), QString(fillChar));
|
|
3518 |
|
|
3519 |
// restore clean state
|
|
3520 |
testWidget->setEchoMode(QLineEdit::Normal);
|
|
3521 |
}
|
|
3522 |
|
|
3523 |
void tst_QLineEdit::task248948_redoRemovedSelection()
|
|
3524 |
{
|
|
3525 |
testWidget->setText("a");
|
|
3526 |
testWidget->selectAll();
|
|
3527 |
QTest::keyPress(testWidget, Qt::Key_Delete);
|
|
3528 |
testWidget->undo();
|
|
3529 |
testWidget->redo();
|
|
3530 |
QTest::keyPress(testWidget, 'a');
|
|
3531 |
QTest::keyPress(testWidget, 'b');
|
|
3532 |
QCOMPARE(testWidget->text(), QLatin1String("ab"));
|
|
3533 |
}
|
|
3534 |
|
|
3535 |
QTEST_MAIN(tst_QLineEdit)
|
|
3536 |
#include "tst_qlineedit.moc"
|