0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
#include <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();
|
|
122 |
void mnemonic();
|
|
123 |
void toString_data();
|
|
124 |
void toString();
|
|
125 |
void streamOperators_data();
|
|
126 |
void streamOperators();
|
|
127 |
void fromString_data();
|
|
128 |
void fromString();
|
|
129 |
void ensureSorted();
|
|
130 |
void standardKeys_data();
|
|
131 |
void standardKeys();
|
|
132 |
void keyBindings();
|
|
133 |
void translated_data();
|
|
134 |
void translated();
|
|
135 |
|
|
136 |
void initTestCase();
|
|
137 |
private:
|
|
138 |
QTranslator *ourTranslator;
|
|
139 |
QTranslator *qtTranslator;
|
|
140 |
#ifdef Q_WS_MAC
|
|
141 |
static const QString MacCtrl;
|
|
142 |
static const QString MacMeta;
|
|
143 |
static const QString MacAlt;
|
|
144 |
static const QString MacShift;
|
|
145 |
#endif
|
|
146 |
|
|
147 |
|
|
148 |
};
|
|
149 |
|
|
150 |
#ifdef Q_WS_MAC
|
|
151 |
const QString tst_QKeySequence::MacCtrl = QString(QChar(0x2318));
|
|
152 |
const QString tst_QKeySequence::MacMeta = QString(QChar(0x2303));
|
|
153 |
const QString tst_QKeySequence::MacAlt = QString(QChar(0x2325));
|
|
154 |
const QString tst_QKeySequence::MacShift = QString(QChar(0x21E7));
|
|
155 |
#endif
|
|
156 |
|
|
157 |
tst_QKeySequence::tst_QKeySequence()
|
|
158 |
{
|
|
159 |
}
|
|
160 |
|
|
161 |
tst_QKeySequence::~tst_QKeySequence()
|
|
162 |
{
|
|
163 |
|
|
164 |
}
|
|
165 |
|
|
166 |
void tst_QKeySequence::initTestCase()
|
|
167 |
{
|
|
168 |
ourTranslator = new QTranslator(this);
|
|
169 |
ourTranslator->load(":/keys_de");
|
|
170 |
qtTranslator = new QTranslator(this);
|
|
171 |
qtTranslator->load(":/qt_de");
|
|
172 |
}
|
|
173 |
|
|
174 |
void tst_QKeySequence::operatorQString_data()
|
|
175 |
{
|
|
176 |
QTest::addColumn<int>("modifiers");
|
|
177 |
QTest::addColumn<int>("keycode");
|
|
178 |
QTest::addColumn<QString>("keystring");
|
|
179 |
|
|
180 |
QTest::newRow( "No modifier" ) << 0 << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "\x0c5" );
|
|
181 |
|
|
182 |
#ifndef Q_WS_MAC
|
|
183 |
QTest::newRow( "Ctrl+Left" ) << int(Qt::CTRL) << int(Qt::Key_Left) << QString( "Ctrl+Left" );
|
|
184 |
QTest::newRow( "Ctrl+," ) << int(Qt::CTRL) << int(Qt::Key_Comma) << QString( "Ctrl+," );
|
|
185 |
QTest::newRow( "Alt+Left" ) << int(Qt::ALT) << int(Qt::Key_Left) << QString( "Alt+Left" );
|
|
186 |
QTest::newRow( "Alt+Shift+Left" ) << int(Qt::ALT | Qt::SHIFT) << int(Qt::Key_Left) << QString( "Alt+Shift+Left" );
|
|
187 |
QTest::newRow( "Ctrl" ) << int(Qt::CTRL) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Ctrl+\x0c5" );
|
|
188 |
QTest::newRow( "Alt" ) << int(Qt::ALT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Alt+\x0c5" );
|
|
189 |
QTest::newRow( "Shift" ) << int(Qt::SHIFT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Shift+\x0c5" );
|
|
190 |
QTest::newRow( "Meta" ) << int(Qt::META) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Meta+\x0c5" );
|
|
191 |
#else
|
|
192 |
QTest::newRow( "Ctrl+Left" ) << int(Qt::CTRL) << int(Qt::Key_Left) << MacCtrl + macSymbolForQtKey(Qt::Key_Left);
|
|
193 |
QTest::newRow( "Ctrl+," ) << int(Qt::CTRL) << int(Qt::Key_Comma) << MacCtrl + ",";
|
|
194 |
QTest::newRow( "Alt+Left" ) << int(Qt::ALT) << int(Qt::Key_Left) << MacAlt + macSymbolForQtKey(Qt::Key_Left);
|
|
195 |
QTest::newRow( "Alt+Shift+Left" ) << int(Qt::ALT | Qt::SHIFT) << int(Qt::Key_Left) << MacAlt + MacShift + macSymbolForQtKey(Qt::Key_Left);
|
|
196 |
QTest::newRow( "Ctrl" ) << int(Qt::CTRL) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacCtrl + "\x0c5";
|
|
197 |
QTest::newRow( "Alt" ) << int(Qt::ALT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacAlt + "\x0c5";
|
|
198 |
QTest::newRow( "Shift" ) << int(Qt::SHIFT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacShift + "\x0c5";
|
|
199 |
QTest::newRow( "Meta" ) << int(Qt::META) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacMeta + "\x0c5";
|
|
200 |
#endif
|
|
201 |
}
|
|
202 |
|
|
203 |
void tst_QKeySequence::symetricConstructors_data()
|
|
204 |
{
|
|
205 |
QTest::addColumn<int>("modifiers");
|
|
206 |
QTest::addColumn<int>("keycode");
|
|
207 |
|
|
208 |
QTest::newRow( "No modifier" ) << 0 << int(Qt::Key_Aring | Qt::UNICODE_ACCEL);
|
|
209 |
QTest::newRow( "Ctrl" ) << int(Qt::CTRL) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL);
|
|
210 |
QTest::newRow( "Alt" ) << int(Qt::ALT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL);
|
|
211 |
QTest::newRow( "Shift" ) << int(Qt::SHIFT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL);
|
|
212 |
QTest::newRow( "Meta" ) << int(Qt::META) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL);
|
|
213 |
}
|
|
214 |
|
|
215 |
void tst_QKeySequence::compareConstructors_data()
|
|
216 |
{
|
|
217 |
operatorQString_data();
|
|
218 |
}
|
|
219 |
|
|
220 |
// operator QString()
|
|
221 |
void tst_QKeySequence::operatorQString()
|
|
222 |
{
|
|
223 |
QKeySequence seq;
|
|
224 |
QFETCH( int, modifiers );
|
|
225 |
QFETCH( int, keycode );
|
|
226 |
QFETCH( QString, keystring );
|
|
227 |
|
|
228 |
seq = QKeySequence( modifiers | keycode );
|
|
229 |
|
|
230 |
QCOMPARE( (QString)seq, keystring );
|
|
231 |
}
|
|
232 |
|
|
233 |
// this verifies that the constructors can handle the same strings in and out
|
|
234 |
void tst_QKeySequence::symetricConstructors()
|
|
235 |
{
|
|
236 |
QFETCH( int, modifiers );
|
|
237 |
QFETCH( int, keycode );
|
|
238 |
|
|
239 |
QKeySequence seq1( modifiers | keycode );
|
|
240 |
QKeySequence seq2( (QString)seq1 );
|
|
241 |
|
|
242 |
QVERIFY( seq1 == seq2 );
|
|
243 |
}
|
|
244 |
|
|
245 |
/* Compares QKeySequence constructurs with int or QString arguments
|
|
246 |
We don't do this for 3.0 since it doesn't support unicode accelerators */
|
|
247 |
void tst_QKeySequence::compareConstructors()
|
|
248 |
{
|
|
249 |
QFETCH( int, modifiers );
|
|
250 |
QFETCH( int, keycode );
|
|
251 |
QFETCH( QString, keystring );
|
|
252 |
|
|
253 |
QKeySequence qstringSeq( keystring );
|
|
254 |
QKeySequence intSeq( modifiers | keycode );
|
|
255 |
|
|
256 |
QVERIFY( qstringSeq == intSeq );
|
|
257 |
}
|
|
258 |
|
|
259 |
void tst_QKeySequence::checkMultipleNames()
|
|
260 |
{
|
|
261 |
QKeySequence oldK( "Ctrl+Page Up" );
|
|
262 |
QKeySequence newK( "Ctrl+PgUp" );
|
|
263 |
QVERIFY( oldK == newK );
|
|
264 |
}
|
|
265 |
|
|
266 |
/*
|
|
267 |
* We must ensure that the keyBindings data is allways sorted
|
|
268 |
* so that we can safely perform binary searches.
|
|
269 |
*/
|
|
270 |
void tst_QKeySequence::ensureSorted()
|
|
271 |
{
|
|
272 |
//### accessing static members from private classes does not work on msvc at the moment
|
|
273 |
#if defined(QT_BUILD_INTERNAL) && !defined(Q_WS_WIN)
|
|
274 |
uint N = QKeySequencePrivate::numberOfKeyBindings;
|
|
275 |
uint val = QKeySequencePrivate::keyBindings[0].shortcut;
|
|
276 |
for ( uint i = 1 ; i < N ; ++i) {
|
|
277 |
uint nextval = QKeySequencePrivate::keyBindings[i].shortcut;
|
|
278 |
if (nextval < val)
|
|
279 |
qDebug() << "Data not sorted at index " << i;
|
|
280 |
QVERIFY(nextval >= val);
|
|
281 |
val = nextval;
|
|
282 |
}
|
|
283 |
#endif
|
|
284 |
}
|
|
285 |
|
|
286 |
void tst_QKeySequence::standardKeys_data()
|
|
287 |
{
|
|
288 |
QTest::addColumn<int>("standardKey");
|
|
289 |
QTest::addColumn<QString>("expected");
|
|
290 |
QTest::newRow("unknownkey") << (int)QKeySequence::UnknownKey<< QString("");
|
|
291 |
QTest::newRow("copy") << (int)QKeySequence::Copy << QString("CTRL+C");
|
|
292 |
QTest::newRow("cut") << (int)QKeySequence::Cut << QString("CTRL+X");
|
|
293 |
QTest::newRow("paste") << (int)QKeySequence::Paste << QString("CTRL+V");
|
|
294 |
QTest::newRow("delete") << (int)QKeySequence::Delete<< QString("DEL");
|
|
295 |
QTest::newRow("open") << (int)QKeySequence::Open << QString("CTRL+O");
|
|
296 |
QTest::newRow("find") << (int)QKeySequence::Find<< QString("CTRL+F");
|
|
297 |
#ifdef Q_WS_WIN
|
|
298 |
QTest::newRow("addTab") << (int)QKeySequence::AddTab<< QString("CTRL+T");
|
|
299 |
QTest::newRow("findNext") << (int)QKeySequence::FindNext<< QString("F3");
|
|
300 |
QTest::newRow("findPrevious") << (int)QKeySequence::FindPrevious << QString("SHIFT+F3");
|
|
301 |
QTest::newRow("close") << (int)QKeySequence::Close<< QString("CTRL+F4");
|
|
302 |
QTest::newRow("replace") << (int)QKeySequence::Replace<< QString("CTRL+H");
|
|
303 |
#endif
|
|
304 |
QTest::newRow("bold") << (int)QKeySequence::Bold << QString("CTRL+B");
|
|
305 |
QTest::newRow("italic") << (int)QKeySequence::Italic << QString("CTRL+I");
|
|
306 |
QTest::newRow("underline") << (int)QKeySequence::Underline << QString("CTRL+U");
|
|
307 |
QTest::newRow("selectall") << (int)QKeySequence::SelectAll << QString("CTRL+A");
|
|
308 |
QTest::newRow("print") << (int)QKeySequence::Print << QString("CTRL+P");
|
|
309 |
QTest::newRow("movenextchar") << (int)QKeySequence::MoveToNextChar<< QString("RIGHT");
|
|
310 |
QTest::newRow("zoomIn") << (int)QKeySequence::ZoomIn<< QString("CTRL++");
|
|
311 |
QTest::newRow("zoomOut") << (int)QKeySequence::ZoomOut<< QString("CTRL+-");
|
|
312 |
QTest::newRow("whatsthis") << (int)QKeySequence::WhatsThis<< QString("SHIFT+F1");
|
|
313 |
|
|
314 |
#if defined(Q_WS_MAC)
|
|
315 |
QTest::newRow("help") << (int)QKeySequence::HelpContents<< QString("Ctrl+?");
|
|
316 |
QTest::newRow("nextChild") << (int)QKeySequence::NextChild << QString("CTRL+}");
|
|
317 |
QTest::newRow("previousChild") << (int)QKeySequence::PreviousChild << QString("CTRL+{");
|
|
318 |
QTest::newRow("MoveToEndOfBlock") << (int)QKeySequence::MoveToEndOfBlock << QString("ALT+DOWN");
|
|
319 |
QTest::newRow("forward") << (int)QKeySequence::Forward << QString("CTRL+]");
|
|
320 |
QTest::newRow("backward") << (int)QKeySequence::Back << QString("CTRL+[");
|
|
321 |
QTest::newRow("SelectEndOfDocument") << (int)QKeySequence::SelectEndOfDocument<< QString("CTRL+SHIFT+DOWN"); //mac only
|
|
322 |
#elif defined(Q_WS_S60)
|
|
323 |
QTest::newRow("help") << (int)QKeySequence::HelpContents<< QString("F2");
|
|
324 |
QTest::newRow("SelectEndOfDocument") << (int)QKeySequence::SelectEndOfDocument<< QString("CTRL+SHIFT+END"); //mac only
|
|
325 |
#else
|
|
326 |
QTest::newRow("help") << (int)QKeySequence::HelpContents<< QString("F1");
|
|
327 |
QTest::newRow("nextChild") << (int)QKeySequence::NextChild<< QString("CTRL+Tab");
|
|
328 |
QTest::newRow("previousChild") << (int)QKeySequence::PreviousChild<< QString("CTRL+SHIFT+BACKTAB");
|
|
329 |
QTest::newRow("forward") << (int)QKeySequence::Forward << QString("ALT+RIGHT");
|
|
330 |
QTest::newRow("backward") << (int)QKeySequence::Back << QString("ALT+LEFT");
|
|
331 |
QTest::newRow("MoveToEndOfBlock") << (int)QKeySequence::MoveToEndOfBlock<< QString(""); //mac only
|
|
332 |
QTest::newRow("SelectEndOfDocument") << (int)QKeySequence::SelectEndOfDocument<< QString("CTRL+SHIFT+END"); //mac only
|
|
333 |
#endif
|
|
334 |
}
|
|
335 |
|
|
336 |
void tst_QKeySequence::standardKeys()
|
|
337 |
{
|
|
338 |
QFETCH(int, standardKey);
|
|
339 |
QFETCH(QString, expected);
|
|
340 |
QKeySequence ks((QKeySequence::StandardKey)standardKey);
|
|
341 |
QKeySequence ks2(expected);
|
|
342 |
QVERIFY(ks == ks2);
|
|
343 |
}
|
|
344 |
|
|
345 |
void tst_QKeySequence::keyBindings()
|
|
346 |
{
|
|
347 |
QList<QKeySequence> bindings = QKeySequence::keyBindings(QKeySequence::Copy);
|
|
348 |
QList<QKeySequence> expected;
|
|
349 |
#if defined(Q_WS_MAC) || defined (Q_WS_S60)
|
|
350 |
expected << QKeySequence("CTRL+C");
|
|
351 |
#elif defined Q_WS_X11
|
|
352 |
expected << QKeySequence("CTRL+C") << QKeySequence("F16") << QKeySequence("CTRL+INSERT");
|
|
353 |
#else
|
|
354 |
expected << QKeySequence("CTRL+C") << QKeySequence("CTRL+INSERT");
|
|
355 |
#endif
|
|
356 |
QVERIFY(bindings == expected);
|
|
357 |
}
|
|
358 |
|
|
359 |
|
|
360 |
void tst_QKeySequence::mnemonic()
|
|
361 |
{
|
|
362 |
#ifdef Q_WS_MAC
|
|
363 |
QSKIP("mnemonics are not used on Mac OS X", SkipAll);
|
|
364 |
#endif
|
|
365 |
QKeySequence k = QKeySequence::mnemonic("&Foo");
|
|
366 |
QVERIFY(k == QKeySequence("ALT+F"));
|
|
367 |
k = QKeySequence::mnemonic("&& &x");
|
|
368 |
QVERIFY(k == QKeySequence("ALT+X"));
|
|
369 |
}
|
|
370 |
|
|
371 |
void tst_QKeySequence::toString_data()
|
|
372 |
{
|
|
373 |
QTest::addColumn<QString>("strSequence");
|
|
374 |
QTest::addColumn<QString>("neutralString");
|
|
375 |
QTest::addColumn<QString>("platformString");
|
|
376 |
|
|
377 |
|
|
378 |
#ifndef Q_WS_MAC
|
|
379 |
QTest::newRow("Ctrl+Left") << QString("Ctrl+Left") << QString("Ctrl+Left") << QString("Ctrl+Left");
|
|
380 |
QTest::newRow("Alt+Left") << QString("Alt+Left") << QString("Alt+Left") << QString("Alt+Left");
|
|
381 |
QTest::newRow("Alt+Shift+Left") << QString("Alt+Shift+Left") << QString("Alt+Shift+Left") << QString("Alt+Shift+Left");
|
|
382 |
QTest::newRow("Ctrl") << QString("Ctrl+\x0c5") << QString("Ctrl+\x0c5") << QString("Ctrl+\x0c5");
|
|
383 |
QTest::newRow("Alt") << QString("Alt+\x0c5") << QString("Alt+\x0c5") << QString("Alt+\x0c5");
|
|
384 |
QTest::newRow("Shift") << QString("Shift+\x0c5") << QString("Shift+\x0c5") << QString("Shift+\x0c5");
|
|
385 |
QTest::newRow("Meta") << QString("Meta+\x0c5") << QString("Meta+\x0c5") << QString("Meta+\x0c5");
|
|
386 |
QTest::newRow("Ctrl+Plus") << QString("Ctrl++") << QString("Ctrl++") << QString("Ctrl++");
|
|
387 |
QTest::newRow("Ctrl+,") << QString("Ctrl+,") << QString("Ctrl+,") << QString("Ctrl+,");
|
|
388 |
QTest::newRow("Ctrl+,,Ctrl+,") << QString("Ctrl+,,Ctrl+,") << QString("Ctrl+,, Ctrl+,") << QString("Ctrl+,, Ctrl+,");
|
|
389 |
QTest::newRow("MultiKey") << QString("Alt+X, Ctrl+Y, Z") << QString("Alt+X, Ctrl+Y, Z")
|
|
390 |
<< QString("Alt+X, Ctrl+Y, Z");
|
|
391 |
|
|
392 |
QTest::newRow("Invalid") << QString("Ctrly") << QString("") << QString("");
|
|
393 |
#else
|
|
394 |
/*
|
|
395 |
QTest::newRow("Ctrl+Left") << MacCtrl + "Left" << QString("Ctrl+Left") << MacCtrl + macSymbolForQtKey(Qt::Key_Left);
|
|
396 |
QTest::newRow("Alt+Left") << MacAlt + "Left" << QString("Alt+Left") << MacAlt + macSymbolForQtKey(Qt::Key_Left);
|
|
397 |
QTest::newRow("Alt+Shift+Left") << MacAlt + MacShift + "Left" << QString("Alt+Shift+Left")
|
|
398 |
<< MacAlt + MacShift + macSymbolForQtKey(Qt::Key_Left);
|
|
399 |
*/
|
|
400 |
QTest::newRow("Ctrl+Right,Left") << MacCtrl + "Right, Left" << QString("Ctrl+Right, Left") << MacCtrl + macSymbolForQtKey(Qt::Key_Right) + QString(", ") + macSymbolForQtKey(Qt::Key_Left);
|
|
401 |
QTest::newRow("Ctrl") << MacCtrl + "\x0c5" << QString("Ctrl+\x0c5") << MacCtrl + "\x0c5";
|
|
402 |
QTest::newRow("Alt") << MacAlt + "\x0c5" << QString("Alt+\x0c5") << MacAlt + "\x0c5";
|
|
403 |
QTest::newRow("Shift") << MacShift + "\x0c5" << QString("Shift+\x0c5") << MacShift + "\x0c5";
|
|
404 |
QTest::newRow("Meta") << MacMeta + "\x0c5" << QString("Meta+\x0c5") << MacMeta + "\x0c5";
|
|
405 |
QTest::newRow("Ctrl+Plus") << MacCtrl + "+" << QString("Ctrl++") << MacCtrl + "+";
|
|
406 |
QTest::newRow("Ctrl+,") << MacCtrl + "," << QString("Ctrl+,") << MacCtrl + ",";
|
|
407 |
QTest::newRow("Ctrl+,,Ctrl+,") << MacCtrl + ",, " + MacCtrl + "," << QString("Ctrl+,, Ctrl+,") << MacCtrl + ",, " + MacCtrl + ",";
|
|
408 |
QTest::newRow("MultiKey") << MacAlt + "X, " + MacCtrl + "Y, Z" << QString("Alt+X, Ctrl+Y, Z")
|
|
409 |
<< MacAlt + "X, " + MacCtrl + "Y, Z";
|
|
410 |
QTest::newRow("Invalid") << QString("Ctrly") << QString("") << QString("");
|
|
411 |
#endif
|
|
412 |
}
|
|
413 |
|
|
414 |
void tst_QKeySequence::toString()
|
|
415 |
{
|
|
416 |
QFETCH(QString, strSequence);
|
|
417 |
QFETCH(QString, neutralString);
|
|
418 |
QFETCH(QString, platformString);
|
|
419 |
|
|
420 |
QKeySequence ks1(strSequence);
|
|
421 |
|
|
422 |
QCOMPARE(ks1.toString(QKeySequence::NativeText), platformString);
|
|
423 |
QCOMPARE(ks1.toString(QKeySequence::PortableText), neutralString);
|
|
424 |
|
|
425 |
}
|
|
426 |
|
|
427 |
void tst_QKeySequence::streamOperators_data()
|
|
428 |
{
|
|
429 |
operatorQString_data();
|
|
430 |
}
|
|
431 |
|
|
432 |
void tst_QKeySequence::streamOperators()
|
|
433 |
{
|
|
434 |
QFETCH( int, modifiers );
|
|
435 |
QFETCH( int, keycode );
|
|
436 |
|
|
437 |
QByteArray data;
|
|
438 |
QKeySequence refK( modifiers | keycode );
|
|
439 |
QKeySequence orgK( "Ctrl+A" );
|
|
440 |
QKeySequence copyOrgK = orgK;
|
|
441 |
QVERIFY( copyOrgK == orgK );
|
|
442 |
|
|
443 |
QDataStream in(&data, QIODevice::WriteOnly);
|
|
444 |
in << refK;
|
|
445 |
QDataStream out(&data, QIODevice::ReadOnly);
|
|
446 |
out >> orgK;
|
|
447 |
|
|
448 |
QVERIFY( orgK == refK );
|
|
449 |
|
|
450 |
// check if detached
|
|
451 |
QVERIFY( orgK != copyOrgK );
|
|
452 |
}
|
|
453 |
|
|
454 |
void tst_QKeySequence::fromString_data()
|
|
455 |
{
|
|
456 |
toString_data();
|
|
457 |
}
|
|
458 |
|
|
459 |
void tst_QKeySequence::fromString()
|
|
460 |
{
|
|
461 |
QFETCH(QString, strSequence);
|
|
462 |
QFETCH(QString, neutralString);
|
|
463 |
QFETCH(QString, platformString);
|
|
464 |
|
|
465 |
QKeySequence ks1(strSequence);
|
|
466 |
QKeySequence ks2 = QKeySequence::fromString(ks1.toString());
|
|
467 |
QKeySequence ks3 = QKeySequence::fromString(neutralString, QKeySequence::PortableText);
|
|
468 |
QKeySequence ks4 = QKeySequence::fromString(platformString, QKeySequence::NativeText);
|
|
469 |
|
|
470 |
|
|
471 |
// assume the transitive property exists here.
|
|
472 |
QCOMPARE(ks2, ks1);
|
|
473 |
QCOMPARE(ks3, ks1);
|
|
474 |
QCOMPARE(ks4, ks1);
|
|
475 |
}
|
|
476 |
|
|
477 |
void tst_QKeySequence::translated_data()
|
|
478 |
{
|
|
479 |
qApp->installTranslator(ourTranslator);
|
|
480 |
qApp->installTranslator(qtTranslator);
|
|
481 |
|
|
482 |
QTest::addColumn<QString>("transKey");
|
|
483 |
QTest::addColumn<QString>("compKey");
|
|
484 |
|
|
485 |
QTest::newRow("Shift++") << QString(tr("Shift++")) << QString("Umschalt++");
|
|
486 |
QTest::newRow("Ctrl++") << QString(tr("Ctrl++")) << QString("Strg++");
|
|
487 |
QTest::newRow("Alt++") << QString(tr("Alt++")) << QString("Alt++");
|
|
488 |
QTest::newRow("Meta++") << QString(tr("Meta++")) << QString("Meta++");
|
|
489 |
|
|
490 |
QTest::newRow("Shift+,, Shift++") << QString(tr("Shift+,, Shift++")) << QString("Umschalt+,, Umschalt++");
|
|
491 |
QTest::newRow("Shift+,, Ctrl++") << QString(tr("Shift+,, Ctrl++")) << QString("Umschalt+,, Strg++");
|
|
492 |
QTest::newRow("Shift+,, Alt++") << QString(tr("Shift+,, Alt++")) << QString("Umschalt+,, Alt++");
|
|
493 |
QTest::newRow("Shift+,, Meta++") << QString(tr("Shift+,, Meta++")) << QString("Umschalt+,, Meta++");
|
|
494 |
|
|
495 |
QTest::newRow("Ctrl+,, Shift++") << QString(tr("Ctrl+,, Shift++")) << QString("Strg+,, Umschalt++");
|
|
496 |
QTest::newRow("Ctrl+,, Ctrl++") << QString(tr("Ctrl+,, Ctrl++")) << QString("Strg+,, Strg++");
|
|
497 |
QTest::newRow("Ctrl+,, Alt++") << QString(tr("Ctrl+,, Alt++")) << QString("Strg+,, Alt++");
|
|
498 |
QTest::newRow("Ctrl+,, Meta++") << QString(tr("Ctrl+,, Meta++")) << QString("Strg+,, Meta++");
|
|
499 |
|
|
500 |
qApp->removeTranslator(ourTranslator);
|
|
501 |
qApp->removeTranslator(qtTranslator);
|
|
502 |
}
|
|
503 |
|
|
504 |
void tst_QKeySequence::translated()
|
|
505 |
{
|
|
506 |
QFETCH(QString, transKey);
|
|
507 |
QFETCH(QString, compKey);
|
|
508 |
#ifdef Q_WS_MAC
|
|
509 |
QSKIP("No need to translate modifiers on Mac OS X", SkipAll);
|
|
510 |
#elif defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
|
|
511 |
QSKIP("No need to translate modifiers on WinCE or Symbian", SkipAll);
|
|
512 |
#endif
|
|
513 |
|
|
514 |
qApp->installTranslator(ourTranslator);
|
|
515 |
qApp->installTranslator(qtTranslator);
|
|
516 |
|
|
517 |
QKeySequence ks1(transKey);
|
|
518 |
QCOMPARE(ks1.toString(QKeySequence::NativeText), compKey);
|
|
519 |
|
|
520 |
qApp->removeTranslator(ourTranslator);
|
|
521 |
qApp->removeTranslator(qtTranslator);
|
|
522 |
}
|
|
523 |
|
|
524 |
|
|
525 |
QTEST_MAIN(tst_QKeySequence)
|
|
526 |
#include "tst_qkeysequence.moc"
|