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