author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 17 Sep 2010 08:34:18 +0300 | |
changeset 36 | ef0373b55136 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
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 |
||
45 |
||
46 |
#include "qlabel.h" |
|
47 |
#include <qapplication.h> |
|
48 |
#include <qboxlayout.h> |
|
49 |
#include <qlabel.h> |
|
50 |
#include <qlineedit.h> |
|
51 |
#include <qmovie.h> |
|
52 |
#include <qpicture.h> |
|
53 |
#include <qmessagebox.h> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
54 |
#include <private/qlabel_p.h> |
0 | 55 |
|
56 |
//TESTED_CLASS= |
|
57 |
//TESTED_FILES= |
|
58 |
#if defined(Q_OS_SYMBIAN) |
|
59 |
# define SRCDIR "" |
|
60 |
#endif |
|
61 |
||
62 |
#include "../../shared/util.h" |
|
63 |
||
64 |
class Widget : public QWidget |
|
65 |
{ |
|
66 |
public: |
|
67 |
Widget() { } |
|
68 |
||
69 |
QList<QEvent::Type> events; |
|
70 |
||
71 |
protected: |
|
72 |
bool event(QEvent *ev) { |
|
73 |
events.append(ev->type()); |
|
74 |
return QWidget::event(ev); |
|
75 |
} |
|
76 |
||
77 |
}; |
|
78 |
||
79 |
class tst_QLabel : public QObject |
|
80 |
{ |
|
81 |
Q_OBJECT |
|
82 |
||
83 |
public: |
|
84 |
tst_QLabel(); |
|
85 |
virtual ~tst_QLabel(); |
|
86 |
||
87 |
||
88 |
public slots: |
|
89 |
void initTestCase(); |
|
90 |
void cleanupTestCase(); |
|
91 |
void init(); |
|
92 |
void cleanup(); |
|
93 |
private slots: |
|
94 |
void getSetCheck(); |
|
95 |
void text(); |
|
96 |
void setText_data(); |
|
97 |
void setText(); |
|
98 |
void textFormat(); |
|
99 |
void setTextFormat(); |
|
100 |
void buddy(); |
|
101 |
void setBuddy(); |
|
102 |
void setFont(); |
|
103 |
void setNum(); |
|
104 |
void clear(); |
|
105 |
void wordWrap(); |
|
106 |
void eventPropagation_data(); |
|
107 |
void eventPropagation(); |
|
108 |
void focusPolicy(); |
|
109 |
||
110 |
void task190318_sizes(); |
|
111 |
||
112 |
void sizeHint(); |
|
113 |
||
114 |
void task226479_movieResize(); |
|
115 |
void emptyPixmap(); |
|
116 |
||
117 |
void unicodeText_data(); |
|
118 |
void unicodeText(); |
|
119 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
void mnemonic_data(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
void mnemonic(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
122 |
void selection(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
123 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
124 |
#ifndef QT_NO_CONTEXTMENU |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
125 |
void taskQTBUG_7902_contextMenuCrash(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
126 |
#endif |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
|
0 | 128 |
private: |
129 |
QLabel *testWidget; |
|
130 |
QPointer<Widget> test_box; |
|
131 |
QPointer<QLabel> test_label; |
|
132 |
QLineEdit *test_edit; |
|
133 |
}; |
|
134 |
||
135 |
// Testing get/set functions |
|
136 |
void tst_QLabel::getSetCheck() |
|
137 |
{ |
|
138 |
QLabel obj1; |
|
139 |
// bool QLabel::wordWrap() |
|
140 |
// void QLabel::setWordWrap(bool) |
|
141 |
obj1.setWordWrap(false); |
|
142 |
QCOMPARE(false, obj1.wordWrap()); |
|
143 |
obj1.setWordWrap(true); |
|
144 |
QCOMPARE(true, obj1.wordWrap()); |
|
145 |
||
146 |
// QWidget * QLabel::buddy() |
|
147 |
// void QLabel::setBuddy(QWidget *) |
|
148 |
QWidget *var2 = new QWidget(); |
|
149 |
obj1.setBuddy(var2); |
|
150 |
QCOMPARE(var2, obj1.buddy()); |
|
151 |
obj1.setBuddy((QWidget *)0); |
|
152 |
QCOMPARE((QWidget *)0, obj1.buddy()); |
|
153 |
delete var2; |
|
154 |
||
155 |
// QMovie * QLabel::movie() |
|
156 |
// void QLabel::setMovie(QMovie *) |
|
157 |
QMovie *var3 = new QMovie; |
|
158 |
obj1.setMovie(var3); |
|
159 |
QCOMPARE(var3, obj1.movie()); |
|
160 |
obj1.setMovie((QMovie *)0); |
|
161 |
QCOMPARE((QMovie *)0, obj1.movie()); |
|
162 |
delete var3; |
|
163 |
} |
|
164 |
||
165 |
||
166 |
tst_QLabel::tst_QLabel(): test_box(0) |
|
167 |
{ |
|
168 |
} |
|
169 |
||
170 |
tst_QLabel::~tst_QLabel() |
|
171 |
{ |
|
172 |
} |
|
173 |
||
174 |
void tst_QLabel::initTestCase() |
|
175 |
{ |
|
176 |
// Create the test class |
|
177 |
testWidget = new QLabel(0); |
|
178 |
testWidget->resize( 200, 200 ); |
|
179 |
testWidget->show(); |
|
180 |
} |
|
181 |
||
182 |
void tst_QLabel::cleanupTestCase() |
|
183 |
{ |
|
184 |
delete testWidget; |
|
185 |
testWidget = 0; |
|
186 |
if (test_box) |
|
187 |
delete test_box; |
|
188 |
} |
|
189 |
||
190 |
void tst_QLabel::init() |
|
191 |
{ |
|
192 |
testWidget->setTextFormat( Qt::AutoText ); |
|
193 |
testWidget->setBuddy( 0 ); |
|
194 |
testWidget->setIndent( 0 ); |
|
195 |
testWidget->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); |
|
196 |
testWidget->setScaledContents( FALSE ); |
|
197 |
} |
|
198 |
||
199 |
void tst_QLabel::cleanup() |
|
200 |
{ |
|
201 |
if (QTest::currentTestFunction() == QLatin1String("setBuddy")) { |
|
202 |
testWidget->show(); |
|
203 |
||
204 |
delete test_box; // this should delete tst_labl and test_edit as well. |
|
205 |
} |
|
206 |
} |
|
207 |
||
208 |
void tst_QLabel::buddy() |
|
209 |
{ |
|
210 |
DEPENDS_ON( "setBuddy" ); |
|
211 |
} |
|
212 |
||
213 |
void tst_QLabel::setBuddy() |
|
214 |
{ |
|
215 |
#ifdef Q_WS_MAC |
|
216 |
QSKIP("Set buddy doesn't make much sense on Mac OS X", SkipAll); |
|
217 |
#endif |
|
218 |
testWidget->hide(); |
|
219 |
||
220 |
test_box = new Widget; |
|
221 |
test_label= new QLabel( test_box ); |
|
222 |
test_label->setText( "&Test with a buddy" ); |
|
223 |
test_edit = new QLineEdit( test_box ); |
|
224 |
QVBoxLayout *layout = new QVBoxLayout(test_box); |
|
225 |
layout->addWidget(test_label); |
|
226 |
layout->addWidget(test_edit); |
|
227 |
test_box->show(); |
|
228 |
qApp->setActiveWindow(test_box); |
|
229 |
QVERIFY(test_box->isActiveWindow()); |
|
230 |
||
231 |
test_label->setBuddy( test_edit ); |
|
232 |
test_label->setFocus(); |
|
233 |
QVERIFY( !test_edit->hasFocus() ); |
|
234 |
QTest::keyClick( test_box, 't', Qt::AltModifier ); |
|
235 |
QVERIFY( test_edit->hasFocus() ); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
delete test_box; |
0 | 237 |
} |
238 |
||
239 |
void tst_QLabel::text() |
|
240 |
{ |
|
241 |
DEPENDS_ON( "setText" ); |
|
242 |
} |
|
243 |
||
244 |
void tst_QLabel::setText_data() |
|
245 |
{ |
|
246 |
QTest::addColumn<QString>("txt"); |
|
247 |
QTest::addColumn<QString>("font"); |
|
248 |
||
249 |
QString prefix = ""; |
|
250 |
#ifdef Q_OS_WIN32 |
|
251 |
prefix = "win32_"; |
|
252 |
#endif |
|
253 |
||
254 |
QTest::newRow( QString(prefix + "data0").toLatin1() ) << QString("This is a single line") << QString("Helvetica"); |
|
255 |
QTest::newRow( QString(prefix + "data1").toLatin1() ) << QString("This is the first line\nThis is the second line") << QString("Courier"); |
|
256 |
QTest::newRow( QString(prefix + "data2").toLatin1() ) << QString("This is the first line\nThis is the second line\nThis is the third line") << QString("Helvetica"); |
|
257 |
QTest::newRow( QString(prefix + "data3").toLatin1() ) << QString("This is <b>bold</b> richtext") << QString("Courier"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
QTest::newRow( QString(prefix + "data4").toLatin1() ) << QString("I Have a &shortcut") << QString("Helvetica"); |
0 | 259 |
} |
260 |
||
261 |
void tst_QLabel::setText() |
|
262 |
{ |
|
263 |
QFETCH( QString, txt ); |
|
264 |
QFETCH( QString, font ); |
|
265 |
QFont f( font, 8 ); |
|
266 |
testWidget->setFont( f ); |
|
267 |
testWidget->setText( txt ); |
|
268 |
QCOMPARE( testWidget->text(), txt ); |
|
269 |
} |
|
270 |
||
271 |
||
272 |
void tst_QLabel::textFormat() |
|
273 |
{ |
|
274 |
DEPENDS_ON( "setTextFormat" ); |
|
275 |
} |
|
276 |
||
277 |
void tst_QLabel::setTextFormat() |
|
278 |
{ |
|
279 |
// lets' start with the simple stuff... |
|
280 |
testWidget->setTextFormat( Qt::PlainText ); |
|
281 |
QVERIFY( testWidget->textFormat() == Qt::PlainText ); |
|
282 |
||
283 |
testWidget->setTextFormat( Qt::RichText ); |
|
284 |
QVERIFY( testWidget->textFormat() == Qt::RichText ); |
|
285 |
||
286 |
testWidget->setTextFormat( Qt::LogText ); |
|
287 |
QVERIFY( testWidget->textFormat() == Qt::LogText ); |
|
288 |
||
289 |
testWidget->setTextFormat( Qt::AutoText ); |
|
290 |
QVERIFY( testWidget->textFormat() == Qt::AutoText ); |
|
291 |
} |
|
292 |
||
293 |
||
294 |
void tst_QLabel::setFont() |
|
295 |
{ |
|
296 |
DEPENDS_ON( "setText" ); |
|
297 |
} |
|
298 |
||
299 |
void tst_QLabel::setNum() |
|
300 |
{ |
|
301 |
testWidget->setText( "This is a text" ); |
|
302 |
testWidget->setNum( 12 ); |
|
303 |
QCOMPARE( testWidget->text(), QString("12") ); |
|
304 |
testWidget->setNum( 12.345 ); |
|
305 |
QCOMPARE( testWidget->text(), QString("12.345") ); |
|
306 |
} |
|
307 |
||
308 |
void tst_QLabel::clear() |
|
309 |
{ |
|
310 |
const QString TEXT = "blah blah"; |
|
311 |
testWidget->setText(TEXT); |
|
312 |
QCOMPARE(testWidget->text(), TEXT); |
|
313 |
testWidget->clear(); |
|
314 |
QVERIFY(testWidget->text().isEmpty()); |
|
315 |
} |
|
316 |
||
317 |
void tst_QLabel::wordWrap() |
|
318 |
{ |
|
319 |
QLabel label; |
|
320 |
||
321 |
QVERIFY(!label.wordWrap()); |
|
322 |
||
323 |
label.setText("Plain Text"); |
|
324 |
QVERIFY(!label.wordWrap()); |
|
325 |
||
326 |
label.setText("<b>rich text</b>"); |
|
327 |
QVERIFY(!label.wordWrap()); |
|
328 |
||
329 |
label.setWordWrap(false); |
|
330 |
label.setText("<b>rich text</b>"); |
|
331 |
QVERIFY(!label.wordWrap()); |
|
332 |
} |
|
333 |
||
334 |
void tst_QLabel::eventPropagation_data() |
|
335 |
{ |
|
336 |
QTest::addColumn<QString>("text"); |
|
337 |
QTest::addColumn<int>("textInteractionFlags"); |
|
338 |
QTest::addColumn<int>("focusPolicy"); |
|
339 |
QTest::addColumn<bool>("propagation"); |
|
340 |
||
341 |
QTest::newRow("plain text1") << QString("plain text") << int(Qt::LinksAccessibleByMouse) << int(Qt::NoFocus) << true; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
342 |
QTest::newRow("plain text2") << QString("plain text") << (int)Qt::TextSelectableByKeyboard << (int)Qt::ClickFocus << true; |
0 | 343 |
QTest::newRow("plain text3") << QString("plain text") << (int)Qt::TextSelectableByMouse << (int)Qt::ClickFocus << false; |
344 |
QTest::newRow("plain text4") << QString("plain text") << (int)Qt::NoTextInteraction << (int)Qt::NoFocus << true; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
345 |
QTest::newRow("rich text1") << QString("<b>rich text</b>") << (int)Qt::LinksAccessibleByMouse << (int)Qt::NoFocus << true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
346 |
QTest::newRow("rich text2") << QString("<b>rich text</b>") << (int)Qt::TextSelectableByKeyboard << (int)Qt::ClickFocus << true; |
0 | 347 |
QTest::newRow("rich text3") << QString("<b>rich text</b>") << (int)Qt::TextSelectableByMouse << (int)Qt::ClickFocus << false; |
348 |
QTest::newRow("rich text4") << QString("<b>rich text</b>") << (int)Qt::NoTextInteraction << (int)Qt::NoFocus << true; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
349 |
QTest::newRow("rich text4") << QString("<b>rich text</b>") << (int)Qt::LinksAccessibleByKeyboard << (int)Qt::StrongFocus << true; |
0 | 350 |
|
351 |
if (!test_box) |
|
352 |
test_box = new Widget; |
|
353 |
if (!test_label) |
|
354 |
test_label = new QLabel(test_box); |
|
355 |
} |
|
356 |
||
357 |
void tst_QLabel::eventPropagation() |
|
358 |
{ |
|
359 |
QFETCH(QString, text); |
|
360 |
QFETCH(int, textInteractionFlags); |
|
361 |
QFETCH(int, focusPolicy); |
|
362 |
QFETCH(bool, propagation); |
|
363 |
||
364 |
// plain text (accepts mouse event _only_ when label selectable by mouse) |
|
365 |
test_label->setText(text); |
|
366 |
test_box->events.clear(); |
|
367 |
test_label->setTextInteractionFlags(Qt::TextInteractionFlags(textInteractionFlags)); |
|
368 |
QVERIFY(int(test_label->focusPolicy()) == focusPolicy); |
|
369 |
QTest::mousePress(test_label, Qt::LeftButton); |
|
370 |
QVERIFY(test_box->events.contains(QEvent::MouseButtonPress) == propagation); // should have propagated! |
|
371 |
} |
|
372 |
||
373 |
void tst_QLabel::focusPolicy() |
|
374 |
{ |
|
375 |
delete test_label; |
|
376 |
test_label = new QLabel; |
|
377 |
QCOMPARE(test_label->focusPolicy(), Qt::NoFocus); // default |
|
378 |
test_label->setFocusPolicy(Qt::StrongFocus); |
|
379 |
test_label->setText("Whatever"); // setting text should not change the focus policy |
|
380 |
QCOMPARE(test_label->focusPolicy(), Qt::StrongFocus); |
|
381 |
test_label->setTextInteractionFlags(Qt::TextSelectableByKeyboard); // this should |
|
382 |
QCOMPARE(test_label->focusPolicy(), Qt::ClickFocus); |
|
383 |
test_label->setFocusPolicy(Qt::StrongFocus); |
|
384 |
test_label->setText("Whatever"); // setting text should not change the focus policy |
|
385 |
QCOMPARE(test_label->focusPolicy(), Qt::StrongFocus); |
|
386 |
test_label->setTextInteractionFlags(Qt::NoTextInteraction); |
|
387 |
QCOMPARE(test_label->focusPolicy(), Qt::NoFocus); |
|
388 |
test_label->setFocusPolicy(Qt::StrongFocus); |
|
389 |
test_label->setTextInteractionFlags(Qt::NoTextInteraction); |
|
390 |
QCOMPARE(test_label->focusPolicy(), Qt::StrongFocus); // is not touched since value didn't change |
|
391 |
delete test_label; |
|
392 |
} |
|
393 |
||
394 |
void tst_QLabel::task190318_sizes() |
|
395 |
{ |
|
396 |
QLabel label(" "); |
|
397 |
QSize ms(500,600); |
|
398 |
label.setMinimumSize(ms); |
|
399 |
QCOMPARE(label.minimumSize(), ms); |
|
400 |
QCOMPARE(label.sizeHint(), ms); |
|
401 |
QCOMPARE(label.minimumSizeHint(), ms); |
|
402 |
} |
|
403 |
||
404 |
void tst_QLabel::sizeHint() |
|
405 |
{ |
|
406 |
QLabel label(QLatin1String("Test")); |
|
407 |
label.setIndent(0); |
|
408 |
label.setMargin(0); |
|
409 |
label.setContentsMargins(0, 0, 0, 0); |
|
410 |
label.setAlignment(Qt::AlignVCenter); |
|
411 |
int h = label.sizeHint().height(); |
|
412 |
||
413 |
QLabel l1(QLatin1String("Test")); |
|
414 |
l1.setIndent(0); |
|
415 |
l1.setMargin(0); |
|
416 |
l1.setContentsMargins(0, 0, 0, 0); |
|
417 |
l1.setAlignment(Qt::AlignVCenter); |
|
418 |
l1.setTextInteractionFlags(Qt::TextSelectableByMouse); // will now use qtextcontrol |
|
419 |
int h1 = l1.sizeHint().height(); |
|
420 |
QCOMPARE(h1, h); |
|
421 |
||
422 |
} |
|
423 |
||
424 |
void tst_QLabel::task226479_movieResize() |
|
425 |
{ |
|
426 |
class Label : public QLabel { |
|
427 |
protected: |
|
428 |
void paintEvent(QPaintEvent *e) |
|
429 |
{ |
|
430 |
paintedRegion += e->region(); |
|
431 |
QLabel::paintEvent(e); |
|
432 |
} |
|
433 |
||
434 |
public: |
|
435 |
QRegion paintedRegion; |
|
436 |
}; |
|
437 |
||
438 |
Label label; |
|
439 |
label.resize(350,350); |
|
440 |
label.show(); |
|
441 |
QMovie *movie = new QMovie( &label ); |
|
442 |
label.setMovie(movie); |
|
443 |
QTest::qWaitForWindowShown(&label); |
|
444 |
movie->setFileName(SRCDIR "red.png"); |
|
445 |
movie->start(); |
|
446 |
QTest::qWait(50); |
|
447 |
movie->stop(); |
|
448 |
label.paintedRegion = QRegion(); |
|
449 |
movie->setFileName(SRCDIR "green.png"); |
|
450 |
movie->start(); |
|
451 |
QTest::qWait(50); |
|
452 |
||
453 |
QTRY_COMPARE(label.paintedRegion , QRegion(label.rect()) ); |
|
454 |
} |
|
455 |
||
456 |
void tst_QLabel::emptyPixmap() |
|
457 |
{ |
|
458 |
//task 197919 |
|
459 |
QLabel label1, label2, label3, label4; |
|
460 |
label2.setPixmap(QPixmap("/tmp/idonotexist")); |
|
461 |
QMovie movie; |
|
462 |
label3.setMovie(&movie); |
|
463 |
label4.setPicture(QPicture()); |
|
464 |
QCOMPARE(label1.sizeHint(), label2.sizeHint()); |
|
465 |
QCOMPARE(label1.sizeHint(), label3.sizeHint()); |
|
466 |
QCOMPARE(label1.sizeHint(), label4.sizeHint()); |
|
467 |
} |
|
468 |
||
469 |
/** |
|
470 |
Test for QTBUG-4848 - unicode data corrupting QLabel display |
|
471 |
*/ |
|
472 |
void tst_QLabel::unicodeText_data() |
|
473 |
{ |
|
474 |
QTest::addColumn<QString>("text"); |
|
475 |
QTest::addColumn<QString>("languageName"); |
|
476 |
||
477 |
/* |
|
478 |
The "glass" phrase in Thai was the initial report for bug QTBUG-4848, was |
|
479 |
originally found on http://www.columbia.edu/kermit/utf8.html. |
|
480 |
||
481 |
The phrase is from an internet tradition regarding a striking phrase |
|
482 |
that is translated into many different languages. The utf8 strings |
|
483 |
below were generated by using http://translate.google.com. |
|
484 |
||
485 |
The glass phrase in Thai contains the ้ว character which manifests bug |
|
486 |
QTBUG-4848 |
|
487 |
||
488 |
The last long phrase is an excerpt from Churchills "on the beaches" |
|
489 |
speech, also translated using http://translate.google.com. |
|
490 |
*/ |
|
491 |
||
492 |
QTest::newRow("english") << QString::fromUtf8("I can eat glass and it doesn't hurt me.") << QString("english"); |
|
493 |
QTest::newRow("thai") << QString::fromUtf8("ฉันจะกินแก้วและไม่เจ็บฉัน") << QString("thai"); |
|
494 |
QTest::newRow("chinese") << QString::fromUtf8("我可以吃玻璃,并没有伤害我。") << QString("chinese"); |
|
495 |
QTest::newRow("arabic") << QString::fromUtf8("أستطيع أكل الزجاج ، وأنه لا يؤذيني.") << QString("arabic"); |
|
496 |
QTest::newRow("russian") << QString::fromUtf8("Я могу есть стекло, и не больно.") << QString("russian"); |
|
497 |
QTest::newRow("korean") << QString::fromUtf8("유리를 먹을 수있는, 그리고 그게 날 다치게하지 않습니다.") << QString("korean"); |
|
498 |
QTest::newRow("greek") << QString::fromUtf8("Μπορώ να φάτε γυαλί και δεν μου κάνει κακό.") << QString("greek"); |
|
499 |
QTest::newRow("german") << QString::fromUtf8("Ich kann Glas essen und es macht mich nicht heiß.") << QString("german"); |
|
500 |
||
501 |
QTest::newRow("thai_long") << QString::fromUtf8("เราจะต่อสู้ในทะเลและมหาสมุทร. เราจะต่อสู้ด้วยความมั่นใจเติบโตและความเจริญเติบโตในอากาศเราจะปกป้องเกาะของเราค่าใช้จ่ายใดๆอาจ." |
|
502 |
"เราจะต่อสู้บนชายหาดเราจะต่อสู้ในบริเวณเชื่อมโยงไปถึงเราจะต่อสู้ในช่องและในถนนที่เราจะต่อสู้ในภูเขานั้นเราจะไม่ยอม.") |
|
503 |
<< QString("thai_long"); |
|
504 |
} |
|
505 |
||
506 |
void tst_QLabel::unicodeText() |
|
507 |
{ |
|
508 |
const QString testDataPath("testdata/unicodeText"); |
|
509 |
QFETCH(QString, text); |
|
510 |
QFETCH(QString, languageName); |
|
511 |
QFrame frame; |
|
512 |
QVBoxLayout *layout = new QVBoxLayout(); |
|
513 |
QLabel *label = new QLabel(text, &frame); |
|
514 |
layout->addWidget(label); |
|
515 |
layout->setMargin(8); |
|
516 |
frame.setLayout(layout); |
|
517 |
frame.show(); |
|
518 |
QTest::qWaitForWindowShown(&frame); |
|
519 |
QVERIFY(frame.isVisible()); // was successfully sized and shown |
|
520 |
testWidget->show(); |
|
521 |
} |
|
522 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
523 |
void tst_QLabel::mnemonic_data() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
524 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
525 |
QTest::addColumn<QString>("text"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
526 |
QTest::addColumn<QString>("expectedDocText"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
527 |
QTest::addColumn<QString>("expectedShortcutCursor"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
528 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
529 |
QTest::newRow("1") << QString("Normal") << QString("Normal") << QString(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
530 |
QTest::newRow("2") << QString("&Simple") << QString("Simple") << QString("S"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
531 |
QTest::newRow("3") << QString("Also &simple") << QString("Also simple") << QString("s"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
532 |
QTest::newRow("4") << QString("&&With &Double &&") << QString("&With Double &") << QString("D"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
533 |
QTest::newRow("5") << QString("Hep&&Hop") << QString("Hep&Hop") << QString(""); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
534 |
QTest::newRow("6") << QString("Hep&&&Hop") << QString("Hep&Hop") << QString("H"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
535 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
536 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
537 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
538 |
void tst_QLabel::mnemonic() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
539 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
540 |
// this test that the mnemonics appears correctly when the label has a text control. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
541 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
542 |
QFETCH(QString, text); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
543 |
QFETCH(QString, expectedDocText); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
544 |
QFETCH(QString, expectedShortcutCursor); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
545 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
546 |
QWidget w; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
547 |
QHBoxLayout *hbox = new QHBoxLayout; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
548 |
QLabel *lab = new QLabel(text); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
549 |
//lab->setText("plop &plop"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
550 |
QLineEdit *lineedit = new QLineEdit; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
551 |
lab->setBuddy(lineedit); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
552 |
lab->setTextInteractionFlags(Qt::TextSelectableByMouse); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
553 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
554 |
hbox->addWidget(lab); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
555 |
hbox->addWidget(lineedit); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
556 |
hbox->addWidget(new QLineEdit); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
557 |
w.setLayout(hbox); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
558 |
w.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
559 |
QTest::qWaitForWindowShown(&w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
QLabelPrivate *d = static_cast<QLabelPrivate *>(QObjectPrivate::get(lab)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
562 |
QVERIFY(d->control); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
563 |
QCOMPARE(d->control->document()->toPlainText(), expectedDocText); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
564 |
QCOMPARE(d->shortcutCursor.selectedText(), expectedShortcutCursor); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
565 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
566 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
567 |
void tst_QLabel::selection() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
568 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
569 |
QLabel label; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
570 |
label.setText("Hello world"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
571 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
572 |
label.setTextInteractionFlags(Qt::TextSelectableByMouse); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
573 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
574 |
QVERIFY(!label.hasSelectedText()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
575 |
QCOMPARE(label.selectedText(), QString()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
576 |
QCOMPARE(label.selectionStart(), -1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
577 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
578 |
label.setSelection(0, 4); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
579 |
QVERIFY(label.hasSelectedText()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
580 |
QCOMPARE(label.selectedText(), QString::fromLatin1("Hell")); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
581 |
QCOMPARE(label.selectionStart(), 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
582 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
583 |
label.setSelection(6, 5); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
584 |
QVERIFY(label.hasSelectedText()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
585 |
QCOMPARE(label.selectedText(), QString::fromLatin1("world")); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
586 |
QCOMPARE(label.selectionStart(), 6); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
587 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
588 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
589 |
#ifndef QT_NO_CONTEXTMENU |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
590 |
void tst_QLabel::taskQTBUG_7902_contextMenuCrash() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
591 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
592 |
QLabel *w = new QLabel("Test or crash?"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
593 |
w->setTextInteractionFlags(Qt::TextSelectableByMouse); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
594 |
w->show(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
595 |
QTest::qWaitForWindowShown(w); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
596 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
597 |
QTimer ti; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
598 |
w->connect(&ti, SIGNAL(timeout()), w, SLOT(deleteLater())); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
599 |
ti.start(300); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
600 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
601 |
QContextMenuEvent *cme = new QContextMenuEvent(QContextMenuEvent::Mouse, w->rect().center()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
602 |
qApp->postEvent(w, cme); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
603 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
604 |
QTest::qWait(350); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
605 |
// No crash, it's allright. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
606 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
607 |
#endif |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
608 |
|
0 | 609 |
QTEST_MAIN(tst_QLabel) |
610 |
#include "tst_qlabel.moc" |