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