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 |
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 <private/qapplication_p.h> |
|
45 |
#include <qkeysequence.h> |
|
46 |
#include <private/qkeysequence_p.h> |
|
47 |
#include <QTranslator> |
|
48 |
#include <QLibraryInfo> |
|
49 |
||
50 |
//TESTED_CLASS= |
|
51 |
//TESTED_FILES= |
|
52 |
||
53 |
#ifdef Q_WS_MAC |
|
54 |
#include <Carbon/Carbon.h> |
|
55 |
struct MacSpecialKey { |
|
56 |
int key; |
|
57 |
ushort macSymbol; |
|
58 |
}; |
|
59 |
||
60 |
static const int NumEntries = 21; |
|
61 |
static const MacSpecialKey entries[NumEntries] = { |
|
62 |
{ Qt::Key_Escape, 0x238B }, |
|
63 |
{ Qt::Key_Tab, 0x21E5 }, |
|
64 |
{ Qt::Key_Backtab, 0x21E4 }, |
|
65 |
{ Qt::Key_Backspace, 0x232B }, |
|
66 |
{ Qt::Key_Return, 0x21B5 }, |
|
67 |
{ Qt::Key_Enter, 0x21B5 }, |
|
68 |
{ Qt::Key_Delete, 0x2326 }, |
|
69 |
{ Qt::Key_Home, 0x2196 }, |
|
70 |
{ Qt::Key_End, 0x2198 }, |
|
71 |
{ Qt::Key_Left, 0x2190 }, |
|
72 |
{ Qt::Key_Up, 0x2191 }, |
|
73 |
{ Qt::Key_Right, 0x2192 }, |
|
74 |
{ Qt::Key_Down, 0x2193 }, |
|
75 |
{ Qt::Key_PageUp, 0x21DE }, |
|
76 |
{ Qt::Key_PageDown, 0x21DF }, |
|
77 |
{ Qt::Key_Shift, kShiftUnicode }, |
|
78 |
{ Qt::Key_Control, kCommandUnicode }, |
|
79 |
{ Qt::Key_Meta, kControlUnicode }, |
|
80 |
{ Qt::Key_Alt, kOptionUnicode }, |
|
81 |
{ Qt::Key_CapsLock, 0x21EA }, |
|
82 |
}; |
|
83 |
||
84 |
static bool operator<(const MacSpecialKey &entry, int key) |
|
85 |
{ |
|
86 |
return entry.key < key; |
|
87 |
} |
|
88 |
||
89 |
static bool operator<(int key, const MacSpecialKey &entry) |
|
90 |
{ |
|
91 |
return key < entry.key; |
|
92 |
} |
|
93 |
||
94 |
static const MacSpecialKey * const MacSpecialKeyEntriesEnd = entries + NumEntries; |
|
95 |
||
96 |
static QChar macSymbolForQtKey(int key) |
|
97 |
{ |
|
98 |
const MacSpecialKey *i = qBinaryFind(entries, MacSpecialKeyEntriesEnd, key); |
|
99 |
if (i == MacSpecialKeyEntriesEnd) |
|
100 |
return QChar(); |
|
101 |
return QChar(i->macSymbol); |
|
102 |
} |
|
103 |
||
104 |
#endif |
|
105 |
||
106 |
class tst_QKeySequence : public QObject |
|
107 |
{ |
|
108 |
Q_OBJECT |
|
109 |
||
110 |
public: |
|
111 |
tst_QKeySequence(); |
|
112 |
virtual ~tst_QKeySequence(); |
|
113 |
||
114 |
private slots: |
|
115 |
void operatorQString_data(); |
|
116 |
void operatorQString(); |
|
117 |
void compareConstructors_data(); |
|
118 |
void compareConstructors(); |
|
119 |
void symetricConstructors_data(); |
|
120 |
void symetricConstructors(); |
|
121 |
void checkMultipleNames(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
void mnemonic_data(); |
0 | 123 |
void mnemonic(); |
124 |
void toString_data(); |
|
125 |
void toString(); |
|
126 |
void streamOperators_data(); |
|
127 |
void streamOperators(); |
|
128 |
void fromString_data(); |
|
129 |
void fromString(); |
|
130 |
void ensureSorted(); |
|
131 |
void standardKeys_data(); |
|
132 |
void standardKeys(); |
|
133 |
void keyBindings(); |
|
134 |
void translated_data(); |
|
135 |
void translated(); |
|
136 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
|
0 | 138 |
void initTestCase(); |
139 |
private: |
|
140 |
QTranslator *ourTranslator; |
|
141 |
QTranslator *qtTranslator; |
|
142 |
#ifdef Q_WS_MAC |
|
143 |
static const QString MacCtrl; |
|
144 |
static const QString MacMeta; |
|
145 |
static const QString MacAlt; |
|
146 |
static const QString MacShift; |
|
147 |
#endif |
|
148 |
||
149 |
||
150 |
}; |
|
151 |
||
152 |
#ifdef Q_WS_MAC |
|
153 |
const QString tst_QKeySequence::MacCtrl = QString(QChar(0x2318)); |
|
154 |
const QString tst_QKeySequence::MacMeta = QString(QChar(0x2303)); |
|
155 |
const QString tst_QKeySequence::MacAlt = QString(QChar(0x2325)); |
|
156 |
const QString tst_QKeySequence::MacShift = QString(QChar(0x21E7)); |
|
157 |
#endif |
|
158 |
||
159 |
tst_QKeySequence::tst_QKeySequence() |
|
160 |
{ |
|
161 |
} |
|
162 |
||
163 |
tst_QKeySequence::~tst_QKeySequence() |
|
164 |
{ |
|
165 |
||
166 |
} |
|
167 |
||
168 |
void tst_QKeySequence::initTestCase() |
|
169 |
{ |
|
170 |
ourTranslator = new QTranslator(this); |
|
171 |
ourTranslator->load(":/keys_de"); |
|
172 |
qtTranslator = new QTranslator(this); |
|
173 |
qtTranslator->load(":/qt_de"); |
|
174 |
} |
|
175 |
||
176 |
void tst_QKeySequence::operatorQString_data() |
|
177 |
{ |
|
178 |
QTest::addColumn<int>("modifiers"); |
|
179 |
QTest::addColumn<int>("keycode"); |
|
180 |
QTest::addColumn<QString>("keystring"); |
|
181 |
||
182 |
QTest::newRow( "No modifier" ) << 0 << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "\x0c5" ); |
|
183 |
||
184 |
#ifndef Q_WS_MAC |
|
185 |
QTest::newRow( "Ctrl+Left" ) << int(Qt::CTRL) << int(Qt::Key_Left) << QString( "Ctrl+Left" ); |
|
186 |
QTest::newRow( "Ctrl+," ) << int(Qt::CTRL) << int(Qt::Key_Comma) << QString( "Ctrl+," ); |
|
187 |
QTest::newRow( "Alt+Left" ) << int(Qt::ALT) << int(Qt::Key_Left) << QString( "Alt+Left" ); |
|
188 |
QTest::newRow( "Alt+Shift+Left" ) << int(Qt::ALT | Qt::SHIFT) << int(Qt::Key_Left) << QString( "Alt+Shift+Left" ); |
|
189 |
QTest::newRow( "Ctrl" ) << int(Qt::CTRL) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Ctrl+\x0c5" ); |
|
190 |
QTest::newRow( "Alt" ) << int(Qt::ALT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Alt+\x0c5" ); |
|
191 |
QTest::newRow( "Shift" ) << int(Qt::SHIFT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Shift+\x0c5" ); |
|
192 |
QTest::newRow( "Meta" ) << int(Qt::META) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Meta+\x0c5" ); |
|
193 |
#else |
|
194 |
QTest::newRow( "Ctrl+Left" ) << int(Qt::CTRL) << int(Qt::Key_Left) << MacCtrl + macSymbolForQtKey(Qt::Key_Left); |
|
195 |
QTest::newRow( "Ctrl+," ) << int(Qt::CTRL) << int(Qt::Key_Comma) << MacCtrl + ","; |
|
196 |
QTest::newRow( "Alt+Left" ) << int(Qt::ALT) << int(Qt::Key_Left) << MacAlt + macSymbolForQtKey(Qt::Key_Left); |
|
197 |
QTest::newRow( "Alt+Shift+Left" ) << int(Qt::ALT | Qt::SHIFT) << int(Qt::Key_Left) << MacAlt + MacShift + macSymbolForQtKey(Qt::Key_Left); |
|
198 |
QTest::newRow( "Ctrl" ) << int(Qt::CTRL) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacCtrl + "\x0c5"; |
|
199 |
QTest::newRow( "Alt" ) << int(Qt::ALT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacAlt + "\x0c5"; |
|
200 |
QTest::newRow( "Shift" ) << int(Qt::SHIFT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacShift + "\x0c5"; |
|
201 |
QTest::newRow( "Meta" ) << int(Qt::META) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacMeta + "\x0c5"; |
|
202 |
#endif |
|
203 |
} |
|
204 |
||
205 |
void tst_QKeySequence::symetricConstructors_data() |
|
206 |
{ |
|
207 |
QTest::addColumn<int>("modifiers"); |
|
208 |
QTest::addColumn<int>("keycode"); |
|
209 |
||
210 |
QTest::newRow( "No modifier" ) << 0 << int(Qt::Key_Aring | Qt::UNICODE_ACCEL); |
|
211 |
QTest::newRow( "Ctrl" ) << int(Qt::CTRL) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL); |
|
212 |
QTest::newRow( "Alt" ) << int(Qt::ALT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL); |
|
213 |
QTest::newRow( "Shift" ) << int(Qt::SHIFT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL); |
|
214 |
QTest::newRow( "Meta" ) << int(Qt::META) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL); |
|
215 |
} |
|
216 |
||
217 |
void tst_QKeySequence::compareConstructors_data() |
|
218 |
{ |
|
219 |
operatorQString_data(); |
|
220 |
} |
|
221 |
||
222 |
// operator QString() |
|
223 |
void tst_QKeySequence::operatorQString() |
|
224 |
{ |
|
225 |
QKeySequence seq; |
|
226 |
QFETCH( int, modifiers ); |
|
227 |
QFETCH( int, keycode ); |
|
228 |
QFETCH( QString, keystring ); |
|
229 |
||
230 |
seq = QKeySequence( modifiers | keycode ); |
|
231 |
||
232 |
QCOMPARE( (QString)seq, keystring ); |
|
233 |
} |
|
234 |
||
235 |
// this verifies that the constructors can handle the same strings in and out |
|
236 |
void tst_QKeySequence::symetricConstructors() |
|
237 |
{ |
|
238 |
QFETCH( int, modifiers ); |
|
239 |
QFETCH( int, keycode ); |
|
240 |
||
241 |
QKeySequence seq1( modifiers | keycode ); |
|
242 |
QKeySequence seq2( (QString)seq1 ); |
|
243 |
||
244 |
QVERIFY( seq1 == seq2 ); |
|
245 |
} |
|
246 |
||
247 |
/* Compares QKeySequence constructurs with int or QString arguments |
|
248 |
We don't do this for 3.0 since it doesn't support unicode accelerators */ |
|
249 |
void tst_QKeySequence::compareConstructors() |
|
250 |
{ |
|
251 |
QFETCH( int, modifiers ); |
|
252 |
QFETCH( int, keycode ); |
|
253 |
QFETCH( QString, keystring ); |
|
254 |
||
255 |
QKeySequence qstringSeq( keystring ); |
|
256 |
QKeySequence intSeq( modifiers | keycode ); |
|
257 |
||
258 |
QVERIFY( qstringSeq == intSeq ); |
|
259 |
} |
|
260 |
||
261 |
void tst_QKeySequence::checkMultipleNames() |
|
262 |
{ |
|
263 |
QKeySequence oldK( "Ctrl+Page Up" ); |
|
264 |
QKeySequence newK( "Ctrl+PgUp" ); |
|
265 |
QVERIFY( oldK == newK ); |
|
266 |
} |
|
267 |
||
268 |
/* |
|
269 |
* We must ensure that the keyBindings data is allways sorted |
|
270 |
* so that we can safely perform binary searches. |
|
271 |
*/ |
|
272 |
void tst_QKeySequence::ensureSorted() |
|
273 |
{ |
|
274 |
//### accessing static members from private classes does not work on msvc at the moment |
|
275 |
#if defined(QT_BUILD_INTERNAL) && !defined(Q_WS_WIN) |
|
276 |
uint N = QKeySequencePrivate::numberOfKeyBindings; |
|
277 |
uint val = QKeySequencePrivate::keyBindings[0].shortcut; |
|
278 |
for ( uint i = 1 ; i < N ; ++i) { |
|
279 |
uint nextval = QKeySequencePrivate::keyBindings[i].shortcut; |
|
280 |
if (nextval < val) |
|
281 |
qDebug() << "Data not sorted at index " << i; |
|
282 |
QVERIFY(nextval >= val); |
|
283 |
val = nextval; |
|
284 |
} |
|
285 |
#endif |
|
286 |
} |
|
287 |
||
288 |
void tst_QKeySequence::standardKeys_data() |
|
289 |
{ |
|
290 |
QTest::addColumn<int>("standardKey"); |
|
291 |
QTest::addColumn<QString>("expected"); |
|
292 |
QTest::newRow("unknownkey") << (int)QKeySequence::UnknownKey<< QString(""); |
|
293 |
QTest::newRow("copy") << (int)QKeySequence::Copy << QString("CTRL+C"); |
|
294 |
QTest::newRow("cut") << (int)QKeySequence::Cut << QString("CTRL+X"); |
|
295 |
QTest::newRow("paste") << (int)QKeySequence::Paste << QString("CTRL+V"); |
|
296 |
QTest::newRow("delete") << (int)QKeySequence::Delete<< QString("DEL"); |
|
297 |
QTest::newRow("open") << (int)QKeySequence::Open << QString("CTRL+O"); |
|
298 |
QTest::newRow("find") << (int)QKeySequence::Find<< QString("CTRL+F"); |
|
299 |
#ifdef Q_WS_WIN |
|
300 |
QTest::newRow("addTab") << (int)QKeySequence::AddTab<< QString("CTRL+T"); |
|
301 |
QTest::newRow("findNext") << (int)QKeySequence::FindNext<< QString("F3"); |
|
302 |
QTest::newRow("findPrevious") << (int)QKeySequence::FindPrevious << QString("SHIFT+F3"); |
|
303 |
QTest::newRow("close") << (int)QKeySequence::Close<< QString("CTRL+F4"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
304 |
QTest::newRow("replace") << (int)QKeySequence::Replace<< QString("CTRL+H"); |
0 | 305 |
#endif |
306 |
QTest::newRow("bold") << (int)QKeySequence::Bold << QString("CTRL+B"); |
|
307 |
QTest::newRow("italic") << (int)QKeySequence::Italic << QString("CTRL+I"); |
|
308 |
QTest::newRow("underline") << (int)QKeySequence::Underline << QString("CTRL+U"); |
|
309 |
QTest::newRow("selectall") << (int)QKeySequence::SelectAll << QString("CTRL+A"); |
|
310 |
QTest::newRow("print") << (int)QKeySequence::Print << QString("CTRL+P"); |
|
311 |
QTest::newRow("movenextchar") << (int)QKeySequence::MoveToNextChar<< QString("RIGHT"); |
|
312 |
QTest::newRow("zoomIn") << (int)QKeySequence::ZoomIn<< QString("CTRL++"); |
|
313 |
QTest::newRow("zoomOut") << (int)QKeySequence::ZoomOut<< QString("CTRL+-"); |
|
314 |
QTest::newRow("whatsthis") << (int)QKeySequence::WhatsThis<< QString("SHIFT+F1"); |
|
315 |
||
316 |
#if defined(Q_WS_MAC) |
|
317 |
QTest::newRow("help") << (int)QKeySequence::HelpContents<< QString("Ctrl+?"); |
|
318 |
QTest::newRow("nextChild") << (int)QKeySequence::NextChild << QString("CTRL+}"); |
|
319 |
QTest::newRow("previousChild") << (int)QKeySequence::PreviousChild << QString("CTRL+{"); |
|
320 |
QTest::newRow("MoveToEndOfBlock") << (int)QKeySequence::MoveToEndOfBlock << QString("ALT+DOWN"); |
|
321 |
QTest::newRow("forward") << (int)QKeySequence::Forward << QString("CTRL+]"); |
|
322 |
QTest::newRow("backward") << (int)QKeySequence::Back << QString("CTRL+["); |
|
323 |
QTest::newRow("SelectEndOfDocument") << (int)QKeySequence::SelectEndOfDocument<< QString("CTRL+SHIFT+DOWN"); //mac only |
|
324 |
#elif defined(Q_WS_S60) |
|
325 |
QTest::newRow("help") << (int)QKeySequence::HelpContents<< QString("F2"); |
|
326 |
QTest::newRow("SelectEndOfDocument") << (int)QKeySequence::SelectEndOfDocument<< QString("CTRL+SHIFT+END"); //mac only |
|
327 |
#else |
|
328 |
QTest::newRow("help") << (int)QKeySequence::HelpContents<< QString("F1"); |
|
329 |
QTest::newRow("nextChild") << (int)QKeySequence::NextChild<< QString("CTRL+Tab"); |
|
330 |
QTest::newRow("previousChild") << (int)QKeySequence::PreviousChild<< QString("CTRL+SHIFT+BACKTAB"); |
|
331 |
QTest::newRow("forward") << (int)QKeySequence::Forward << QString("ALT+RIGHT"); |
|
332 |
QTest::newRow("backward") << (int)QKeySequence::Back << QString("ALT+LEFT"); |
|
333 |
QTest::newRow("MoveToEndOfBlock") << (int)QKeySequence::MoveToEndOfBlock<< QString(""); //mac only |
|
334 |
QTest::newRow("SelectEndOfDocument") << (int)QKeySequence::SelectEndOfDocument<< QString("CTRL+SHIFT+END"); //mac only |
|
335 |
#endif |
|
336 |
} |
|
337 |
||
338 |
void tst_QKeySequence::standardKeys() |
|
339 |
{ |
|
340 |
QFETCH(int, standardKey); |
|
341 |
QFETCH(QString, expected); |
|
342 |
QKeySequence ks((QKeySequence::StandardKey)standardKey); |
|
343 |
QKeySequence ks2(expected); |
|
344 |
QVERIFY(ks == ks2); |
|
345 |
} |
|
346 |
||
347 |
void tst_QKeySequence::keyBindings() |
|
348 |
{ |
|
349 |
QList<QKeySequence> bindings = QKeySequence::keyBindings(QKeySequence::Copy); |
|
350 |
QList<QKeySequence> expected; |
|
351 |
#if defined(Q_WS_MAC) || defined (Q_WS_S60) |
|
352 |
expected << QKeySequence("CTRL+C"); |
|
353 |
#elif defined Q_WS_X11 |
|
354 |
expected << QKeySequence("CTRL+C") << QKeySequence("F16") << QKeySequence("CTRL+INSERT"); |
|
355 |
#else |
|
356 |
expected << QKeySequence("CTRL+C") << QKeySequence("CTRL+INSERT"); |
|
357 |
#endif |
|
358 |
QVERIFY(bindings == expected); |
|
359 |
} |
|
360 |
||
361 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
362 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
363 |
void tst_QKeySequence::mnemonic_data() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
364 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
QTest::addColumn<QString>("string"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
366 |
QTest::addColumn<QString>("key"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
367 |
QTest::addColumn<bool>("warning"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
QTest::newRow("1") << QString::fromLatin1("&bonjour") << QString::fromLatin1("ALT+B") << false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
370 |
QTest::newRow("2") << QString::fromLatin1("&&bonjour") << QString() << false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
371 |
QTest::newRow("3") << QString::fromLatin1("&&bon&jour") << QString::fromLatin1("ALT+J") << false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
372 |
QTest::newRow("4") << QString::fromLatin1("&&bon&jo&ur") << QString::fromLatin1("ALT+J") << true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
373 |
QTest::newRow("5") << QString::fromLatin1("b&on&&jour") << QString::fromLatin1("ALT+O") << false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
374 |
QTest::newRow("6") << QString::fromLatin1("bonjour") << QString() << false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
375 |
QTest::newRow("7") << QString::fromLatin1("&&&bonjour") << QString::fromLatin1("ALT+B") << false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
376 |
QTest::newRow("8") << QString::fromLatin1("bonjour&&&") << QString() << false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
377 |
QTest::newRow("9") << QString::fromLatin1("bo&&nj&o&&u&r") << QString::fromLatin1("ALT+O") << true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
378 |
QTest::newRow("10") << QString::fromLatin1("BON&JOUR") << QString::fromLatin1("ALT+J") << false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
379 |
QTest::newRow("11") << QString::fromUtf8("bonjour") << QString() << false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
380 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
|
0 | 382 |
void tst_QKeySequence::mnemonic() |
383 |
{ |
|
384 |
#ifdef Q_WS_MAC |
|
385 |
QSKIP("mnemonics are not used on Mac OS X", SkipAll); |
|
386 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
QFETCH(QString, string); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
QFETCH(QString, key); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
QFETCH(bool, warning); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
#ifndef QT_NO_DEBUG |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
if (warning) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
QString str = QString::fromLatin1("QKeySequence::mnemonic: \"%1\" contains multiple occurences of '&'").arg(string); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
QTest::ignoreMessage(QtWarningMsg, qPrintable(str)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
// qWarning(qPrintable(str)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
QKeySequence seq = QKeySequence::mnemonic(string); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
QKeySequence res = QKeySequence(key); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
QCOMPARE(seq, res); |
0 | 402 |
} |
403 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
|
0 | 406 |
void tst_QKeySequence::toString_data() |
407 |
{ |
|
408 |
QTest::addColumn<QString>("strSequence"); |
|
409 |
QTest::addColumn<QString>("neutralString"); |
|
410 |
QTest::addColumn<QString>("platformString"); |
|
411 |
||
412 |
||
413 |
#ifndef Q_WS_MAC |
|
414 |
QTest::newRow("Ctrl+Left") << QString("Ctrl+Left") << QString("Ctrl+Left") << QString("Ctrl+Left"); |
|
415 |
QTest::newRow("Alt+Left") << QString("Alt+Left") << QString("Alt+Left") << QString("Alt+Left"); |
|
416 |
QTest::newRow("Alt+Shift+Left") << QString("Alt+Shift+Left") << QString("Alt+Shift+Left") << QString("Alt+Shift+Left"); |
|
417 |
QTest::newRow("Ctrl") << QString("Ctrl+\x0c5") << QString("Ctrl+\x0c5") << QString("Ctrl+\x0c5"); |
|
418 |
QTest::newRow("Alt") << QString("Alt+\x0c5") << QString("Alt+\x0c5") << QString("Alt+\x0c5"); |
|
419 |
QTest::newRow("Shift") << QString("Shift+\x0c5") << QString("Shift+\x0c5") << QString("Shift+\x0c5"); |
|
420 |
QTest::newRow("Meta") << QString("Meta+\x0c5") << QString("Meta+\x0c5") << QString("Meta+\x0c5"); |
|
421 |
QTest::newRow("Ctrl+Plus") << QString("Ctrl++") << QString("Ctrl++") << QString("Ctrl++"); |
|
422 |
QTest::newRow("Ctrl+,") << QString("Ctrl+,") << QString("Ctrl+,") << QString("Ctrl+,"); |
|
423 |
QTest::newRow("Ctrl+,,Ctrl+,") << QString("Ctrl+,,Ctrl+,") << QString("Ctrl+,, Ctrl+,") << QString("Ctrl+,, Ctrl+,"); |
|
424 |
QTest::newRow("MultiKey") << QString("Alt+X, Ctrl+Y, Z") << QString("Alt+X, Ctrl+Y, Z") |
|
425 |
<< QString("Alt+X, Ctrl+Y, Z"); |
|
426 |
||
427 |
QTest::newRow("Invalid") << QString("Ctrly") << QString("") << QString(""); |
|
428 |
#else |
|
429 |
/* |
|
430 |
QTest::newRow("Ctrl+Left") << MacCtrl + "Left" << QString("Ctrl+Left") << MacCtrl + macSymbolForQtKey(Qt::Key_Left); |
|
431 |
QTest::newRow("Alt+Left") << MacAlt + "Left" << QString("Alt+Left") << MacAlt + macSymbolForQtKey(Qt::Key_Left); |
|
432 |
QTest::newRow("Alt+Shift+Left") << MacAlt + MacShift + "Left" << QString("Alt+Shift+Left") |
|
433 |
<< MacAlt + MacShift + macSymbolForQtKey(Qt::Key_Left); |
|
434 |
*/ |
|
435 |
QTest::newRow("Ctrl+Right,Left") << MacCtrl + "Right, Left" << QString("Ctrl+Right, Left") << MacCtrl + macSymbolForQtKey(Qt::Key_Right) + QString(", ") + macSymbolForQtKey(Qt::Key_Left); |
|
436 |
QTest::newRow("Ctrl") << MacCtrl + "\x0c5" << QString("Ctrl+\x0c5") << MacCtrl + "\x0c5"; |
|
437 |
QTest::newRow("Alt") << MacAlt + "\x0c5" << QString("Alt+\x0c5") << MacAlt + "\x0c5"; |
|
438 |
QTest::newRow("Shift") << MacShift + "\x0c5" << QString("Shift+\x0c5") << MacShift + "\x0c5"; |
|
439 |
QTest::newRow("Meta") << MacMeta + "\x0c5" << QString("Meta+\x0c5") << MacMeta + "\x0c5"; |
|
440 |
QTest::newRow("Ctrl+Plus") << MacCtrl + "+" << QString("Ctrl++") << MacCtrl + "+"; |
|
441 |
QTest::newRow("Ctrl+,") << MacCtrl + "," << QString("Ctrl+,") << MacCtrl + ","; |
|
442 |
QTest::newRow("Ctrl+,,Ctrl+,") << MacCtrl + ",, " + MacCtrl + "," << QString("Ctrl+,, Ctrl+,") << MacCtrl + ",, " + MacCtrl + ","; |
|
443 |
QTest::newRow("MultiKey") << MacAlt + "X, " + MacCtrl + "Y, Z" << QString("Alt+X, Ctrl+Y, Z") |
|
444 |
<< MacAlt + "X, " + MacCtrl + "Y, Z"; |
|
445 |
QTest::newRow("Invalid") << QString("Ctrly") << QString("") << QString(""); |
|
446 |
#endif |
|
447 |
} |
|
448 |
||
449 |
void tst_QKeySequence::toString() |
|
450 |
{ |
|
451 |
QFETCH(QString, strSequence); |
|
452 |
QFETCH(QString, neutralString); |
|
453 |
QFETCH(QString, platformString); |
|
454 |
||
455 |
QKeySequence ks1(strSequence); |
|
456 |
||
457 |
QCOMPARE(ks1.toString(QKeySequence::NativeText), platformString); |
|
458 |
QCOMPARE(ks1.toString(QKeySequence::PortableText), neutralString); |
|
459 |
||
460 |
} |
|
461 |
||
462 |
void tst_QKeySequence::streamOperators_data() |
|
463 |
{ |
|
464 |
operatorQString_data(); |
|
465 |
} |
|
466 |
||
467 |
void tst_QKeySequence::streamOperators() |
|
468 |
{ |
|
469 |
QFETCH( int, modifiers ); |
|
470 |
QFETCH( int, keycode ); |
|
471 |
||
472 |
QByteArray data; |
|
473 |
QKeySequence refK( modifiers | keycode ); |
|
474 |
QKeySequence orgK( "Ctrl+A" ); |
|
475 |
QKeySequence copyOrgK = orgK; |
|
476 |
QVERIFY( copyOrgK == orgK ); |
|
477 |
||
478 |
QDataStream in(&data, QIODevice::WriteOnly); |
|
479 |
in << refK; |
|
480 |
QDataStream out(&data, QIODevice::ReadOnly); |
|
481 |
out >> orgK; |
|
482 |
||
483 |
QVERIFY( orgK == refK ); |
|
484 |
||
485 |
// check if detached |
|
486 |
QVERIFY( orgK != copyOrgK ); |
|
487 |
} |
|
488 |
||
489 |
void tst_QKeySequence::fromString_data() |
|
490 |
{ |
|
491 |
toString_data(); |
|
492 |
} |
|
493 |
||
494 |
void tst_QKeySequence::fromString() |
|
495 |
{ |
|
496 |
QFETCH(QString, strSequence); |
|
497 |
QFETCH(QString, neutralString); |
|
498 |
QFETCH(QString, platformString); |
|
499 |
||
500 |
QKeySequence ks1(strSequence); |
|
501 |
QKeySequence ks2 = QKeySequence::fromString(ks1.toString()); |
|
502 |
QKeySequence ks3 = QKeySequence::fromString(neutralString, QKeySequence::PortableText); |
|
503 |
QKeySequence ks4 = QKeySequence::fromString(platformString, QKeySequence::NativeText); |
|
504 |
||
505 |
||
506 |
// assume the transitive property exists here. |
|
507 |
QCOMPARE(ks2, ks1); |
|
508 |
QCOMPARE(ks3, ks1); |
|
509 |
QCOMPARE(ks4, ks1); |
|
510 |
} |
|
511 |
||
512 |
void tst_QKeySequence::translated_data() |
|
513 |
{ |
|
514 |
qApp->installTranslator(ourTranslator); |
|
515 |
qApp->installTranslator(qtTranslator); |
|
516 |
||
517 |
QTest::addColumn<QString>("transKey"); |
|
518 |
QTest::addColumn<QString>("compKey"); |
|
519 |
||
520 |
QTest::newRow("Shift++") << QString(tr("Shift++")) << QString("Umschalt++"); |
|
521 |
QTest::newRow("Ctrl++") << QString(tr("Ctrl++")) << QString("Strg++"); |
|
522 |
QTest::newRow("Alt++") << QString(tr("Alt++")) << QString("Alt++"); |
|
523 |
QTest::newRow("Meta++") << QString(tr("Meta++")) << QString("Meta++"); |
|
524 |
||
525 |
QTest::newRow("Shift+,, Shift++") << QString(tr("Shift+,, Shift++")) << QString("Umschalt+,, Umschalt++"); |
|
526 |
QTest::newRow("Shift+,, Ctrl++") << QString(tr("Shift+,, Ctrl++")) << QString("Umschalt+,, Strg++"); |
|
527 |
QTest::newRow("Shift+,, Alt++") << QString(tr("Shift+,, Alt++")) << QString("Umschalt+,, Alt++"); |
|
528 |
QTest::newRow("Shift+,, Meta++") << QString(tr("Shift+,, Meta++")) << QString("Umschalt+,, Meta++"); |
|
529 |
||
530 |
QTest::newRow("Ctrl+,, Shift++") << QString(tr("Ctrl+,, Shift++")) << QString("Strg+,, Umschalt++"); |
|
531 |
QTest::newRow("Ctrl+,, Ctrl++") << QString(tr("Ctrl+,, Ctrl++")) << QString("Strg+,, Strg++"); |
|
532 |
QTest::newRow("Ctrl+,, Alt++") << QString(tr("Ctrl+,, Alt++")) << QString("Strg+,, Alt++"); |
|
533 |
QTest::newRow("Ctrl+,, Meta++") << QString(tr("Ctrl+,, Meta++")) << QString("Strg+,, Meta++"); |
|
534 |
||
535 |
qApp->removeTranslator(ourTranslator); |
|
536 |
qApp->removeTranslator(qtTranslator); |
|
537 |
} |
|
538 |
||
539 |
void tst_QKeySequence::translated() |
|
540 |
{ |
|
541 |
QFETCH(QString, transKey); |
|
542 |
QFETCH(QString, compKey); |
|
543 |
#ifdef Q_WS_MAC |
|
544 |
QSKIP("No need to translate modifiers on Mac OS X", SkipAll); |
|
545 |
#elif defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
|
546 |
QSKIP("No need to translate modifiers on WinCE or Symbian", SkipAll); |
|
547 |
#endif |
|
548 |
||
549 |
qApp->installTranslator(ourTranslator); |
|
550 |
qApp->installTranslator(qtTranslator); |
|
551 |
||
552 |
QKeySequence ks1(transKey); |
|
553 |
QCOMPARE(ks1.toString(QKeySequence::NativeText), compKey); |
|
554 |
||
555 |
qApp->removeTranslator(ourTranslator); |
|
556 |
qApp->removeTranslator(qtTranslator); |
|
557 |
} |
|
558 |
||
559 |
||
560 |
QTEST_MAIN(tst_QKeySequence) |
|
561 |
#include "tst_qkeysequence.moc" |