97c749e5ba78e9eb9903495d18e616fb4553f716
[profile/ivi/qtbase.git] / tests / auto / gui / kernel / qshortcut / tst_qshortcut.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42
43 #include <QtTest/QtTest>
44 #include <qapplication.h>
45 #include <qtextedit.h>
46 #include <qpushbutton.h>
47 #include <qmainwindow.h>
48 #include <qstatusbar.h>
49 #include <qboxlayout.h>
50 #include <qdebug.h>
51 #include <qstring.h>
52 #include <qshortcut.h>
53
54 class AccelForm;
55 QT_BEGIN_NAMESPACE
56 class QMainWindow;
57 class QTextEdit;
58 QT_END_NAMESPACE
59
60 class tst_QShortcut : public QObject
61 {
62     Q_OBJECT
63 public:
64     tst_QShortcut();
65     virtual ~tst_QShortcut();
66
67
68     enum Action {
69         SetupAccel,
70         TestAccel,
71         ClearAll
72     } currentAction;
73
74     enum Widget {
75         NoWidget,
76         TriggerSlot1,
77         TriggerSlot2,
78         TriggerSlot3,
79         TriggerSlot4,
80         TriggerSlot5,
81         TriggerSlot6,
82         TriggerSlot7
83     };
84
85     enum Result {
86         NoResult,
87         Slot1Triggered,
88         Slot2Triggered,
89         Slot3Triggered,
90         Slot4Triggered,
91         Slot5Triggered,
92         Slot6Triggered,
93         Slot7Triggered,
94         Ambiguous
95     } currentResult;
96
97 public slots:
98     void slotTrig1() { currentResult = Slot1Triggered; }
99     void slotTrig2() { currentResult = Slot2Triggered; }
100     void slotTrig3() { currentResult = Slot3Triggered; }
101     void slotTrig4() { currentResult = Slot4Triggered; }
102     void slotTrig5() { currentResult = Slot5Triggered; }
103     void slotTrig6() { currentResult = Slot6Triggered; }
104     void slotTrig7() { currentResult = Slot7Triggered; }
105     void ambigSlot1() { currentResult = Ambiguous; ambigResult = Slot1Triggered; }
106     void ambigSlot2() { currentResult = Ambiguous; ambigResult = Slot2Triggered; }
107     void ambigSlot3() { currentResult = Ambiguous; ambigResult = Slot3Triggered; }
108     void ambigSlot4() { currentResult = Ambiguous; ambigResult = Slot4Triggered; }
109     void ambigSlot5() { currentResult = Ambiguous; ambigResult = Slot5Triggered; }
110     void ambigSlot6() { currentResult = Ambiguous; ambigResult = Slot6Triggered; }
111     void ambigSlot7() { currentResult = Ambiguous; ambigResult = Slot7Triggered; }
112     void statusMessage( const QString& message ) { sbText = message; }
113     void shortcutDestroyed(QObject* obj);
114
115 public slots:
116     void initTestCase();
117     void cleanupTestCase();
118
119 private slots:
120     void number_data();
121     void number();
122     void text_data();
123     void text();
124     void disabledItems();
125     void ambiguousItems();
126     void ambiguousRotation();
127     void keypressConsumption();
128     void unicodeCompare();
129     void context();
130
131 protected:
132     static Qt::KeyboardModifiers toButtons( int key );
133     void defElements();
134
135     void clearAllShortcuts();
136     QShortcut *setupShortcut(int testWidget, const QKeySequence &ks);
137     QShortcut *setupShortcut(int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0);
138
139     QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0);
140     QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QKeySequence &ks, Qt::ShortcutContext context = Qt::WindowShortcut);
141
142     void sendKeyEvents(QWidget *w, int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0);
143     void sendKeyEvents(int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0);
144
145     void testElement();
146
147     QMainWindow *mainW;
148     QList<QShortcut*> shortcuts;
149     QTextEdit *edit;
150     QString sbText;
151     Result ambigResult;
152 };
153
154 QT_BEGIN_NAMESPACE
155 template<> struct QMetaTypeId<tst_QShortcut::Widget> : public QMetaTypeId<int>
156 { static inline int qt_metatype_id() { return QMetaType::Int; } };
157 template<> struct QMetaTypeId<tst_QShortcut::Result> : public QMetaTypeId<int>
158 { static inline int qt_metatype_id() { return QMetaType::Int; } };
159 template<> struct QMetaTypeId<tst_QShortcut::Action> : public QMetaTypeId<int>
160 { static inline int qt_metatype_id() { return QMetaType::Int; } };
161 QT_END_NAMESPACE
162
163 class TestEdit : public QTextEdit
164 {
165     Q_OBJECT
166 public:
167     TestEdit(QWidget *parent, const char *name)
168         : QTextEdit(parent)
169     {
170         setObjectName(name);
171     }
172
173 protected:
174     bool event(QEvent *e) {
175         // Make testedit allow any Ctrl+Key as shortcut
176         if (e->type() == QEvent::ShortcutOverride) {
177             QKeyEvent *ke = static_cast<QKeyEvent*>(e);
178             if (ke->modifiers() == Qt::ControlModifier
179                 && ke->key() > Qt::Key_Any
180                 && ke->key() < Qt::Key_ydiaeresis) {
181                 ke->ignore();
182                 return true;
183             }
184         }
185
186         // If keypress not processed as normal, check for
187         // Ctrl+Key event, and input custom string for
188         // result comparison.
189         if (e->type() == QEvent::KeyPress) {
190             QKeyEvent *ke = static_cast<QKeyEvent*>(e);
191             if (ke->modifiers() && ke->key() > Qt::Key_Any
192                 && ke->key() < Qt::Key_ydiaeresis) {
193                 if (ke->modifiers() == Qt::ControlModifier)
194                     insertPlainText(QString("<Ctrl+%1>").arg(char(ke->key())));
195                 else if (ke->modifiers() == Qt::AltModifier)
196                     insertPlainText(QString("<Alt+%1>").arg(char(ke->key())));
197                 else if (ke->modifiers() == Qt::ShiftModifier)
198                     insertPlainText(QString("<Shift+%1>").arg(char(ke->key())));
199                 return true;
200             }
201         }
202         return QTextEdit::event(e);
203     }
204 };
205
206 tst_QShortcut::tst_QShortcut(): mainW( 0 )
207 {
208 }
209
210 tst_QShortcut::~tst_QShortcut()
211 {
212     clearAllShortcuts();
213 }
214
215 void tst_QShortcut::initTestCase()
216 {
217     currentResult = NoResult;
218     mainW = new QMainWindow(0);
219     mainW->setWindowFlags(Qt::X11BypassWindowManagerHint);
220     edit  = new TestEdit(mainW, "test_edit");
221     mainW->setFixedSize( 100, 100 );
222     mainW->setCentralWidget( edit );
223     mainW->show();
224 #ifdef Q_WS_X11
225     qt_x11_wait_for_window_manager(mainW);
226 #endif
227     mainW->activateWindow();
228     QTest::qWait(100);
229     connect( mainW->statusBar(), SIGNAL(messageChanged(const QString&)),
230              this, SLOT(statusMessage(const QString&)) );
231 }
232
233 void tst_QShortcut::cleanupTestCase()
234 {
235     delete mainW;
236 }
237
238 Qt::KeyboardModifiers tst_QShortcut::toButtons( int key )
239 {
240     Qt::KeyboardModifiers result = Qt::NoModifier;
241     if ( key & Qt::SHIFT )
242         result |= Qt::ShiftModifier;
243     if ( key & Qt::CTRL )
244         result |= Qt::ControlModifier;
245    if ( key & Qt::META )
246         result |= Qt::MetaModifier;
247    if ( key & Qt::ALT )
248         result |= Qt::AltModifier;
249     return result;
250 }
251
252 void tst_QShortcut::defElements()
253 {
254     QTest::addColumn<int>("action");
255     QTest::addColumn<int>("testWidget");
256     QTest::addColumn<QString>("txt");
257     QTest::addColumn<int>("k1");
258     QTest::addColumn<int>("c1");
259     QTest::addColumn<int>("k2");
260     QTest::addColumn<int>("c2");
261     QTest::addColumn<int>("k3");
262     QTest::addColumn<int>("c3");
263     QTest::addColumn<int>("k4");
264     QTest::addColumn<int>("c4");
265     QTest::addColumn<int>("result");
266 }
267
268 void tst_QShortcut::number()
269 {
270     // We expect a failure on these tests, until QtTestKeyboard is
271     // fixed to do real platform dependent keyboard simulations
272     if (QTest::currentDataTag() == QString("N006a:Shift+Tab - [BackTab]")
273         || QTest::currentDataTag() == QString("N006b:Shift+Tab - [Shift+BackTab]"))
274         QEXPECT_FAIL("", "FLAW IN QTESTKEYBOARD: Keyboard events not passed through "
275                         "platform dependent key handling code", Continue);
276     testElement();
277 }
278 void tst_QShortcut::text()
279 {
280     testElement();
281 }
282 // ------------------------------------------------------------------
283 // Number Elements --------------------------------------------------
284 // ------------------------------------------------------------------
285 void tst_QShortcut::number_data()
286 {
287     defElements();
288
289     // Clear all
290     QTest::newRow("N00 - clear") << ClearAll <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
291
292     //===========================================
293     // [Shift + key] on non-shift shortcuts testing
294     //===========================================
295
296     /* Testing Single Sequences
297        Shift + Qt::Key_M    on  Qt::Key_M
298                Qt::Key_M    on  Qt::Key_M
299        Shift + Qt::Key_Plus on  Qt::Key_Pluss
300                Qt::Key_Plus on  Qt::Key_Pluss
301     */
302     QTest::newRow("N001 - slot1")                   << SetupAccel << TriggerSlot1 << QString("")    << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
303     //commented out because the behaviour changed, those tests should be updated
304     //QTest::newRow("N001:Shift + M - [M]")         << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
305     QTest::newRow("N001:M - [M]")                   << TestAccel << NoWidget << QString("")         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
306     QTest::newRow("N001 - slot2")                   << SetupAccel << TriggerSlot2 << QString("")    << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
307     //commented out because the behaviour changed, those tests should be updated
308     //QTest::newRow("N001:Shift++ [+]")     << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
309     QTest::newRow("N001:+ [+]")             << TestAccel << NoWidget << QString("")         << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
310     QTest::newRow("N001 - clear")                   << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
311
312     /* Testing Single Sequences
313        Shift + Qt::Key_M    on  Shift + Qt::Key_M
314                Qt::Key_M    on  Shift + Qt::Key_M
315        Shift + Qt::Key_Plus on  Shift + Qt::Key_Pluss
316                Qt::Key_Plus on  Shift + Qt::Key_Pluss
317     */
318     QTest::newRow("N002 - slot1")                   << SetupAccel << TriggerSlot1 << QString("")    << int(Qt::SHIFT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
319     QTest::newRow("N002:Shift+M - [Shift+M]")  << TestAccel << NoWidget << QString("")      << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
320     QTest::newRow("N002:M - [Shift+M]")     << TestAccel << NoWidget << QString("")         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
321     QTest::newRow("N002 - slot2")                   << SetupAccel << TriggerSlot2 << QString("")    << int(Qt::SHIFT + Qt::Key_Plus) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
322     QTest::newRow("N002:Shift++ [Shift++]")    << TestAccel << NoWidget << QString("")      << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
323     QTest::newRow("N002:+ [Shift++]")       << TestAccel << NoWidget << QString("")         << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
324     QTest::newRow("N002 - clear")                   << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
325
326     /* Testing Single Sequences
327        Shift + Qt::Key_F1   on  Qt::Key_F1
328                Qt::Key_F1   on  Qt::Key_F1
329     */
330     QTest::newRow("N003 - slot1")                   << SetupAccel << TriggerSlot1 << QString("")    << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
331     //commented out because the behaviour changed, those tests should be updated
332     //QTest::newRow("N003:Shift+F1 - [F1]")         << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
333     QTest::newRow("N003:F1 - [F1]")         << TestAccel << NoWidget << QString("")         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
334     QTest::newRow("N003 - clear")                   << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
335     /* Testing Single Sequences
336        Shift + Qt::Key_F1   on  Shift + Qt::Key_F1
337                Qt::Key_F1   on  Shift + Qt::Key_F1
338     */
339
340     QTest::newRow("N004 - slot1")                   << SetupAccel << TriggerSlot1 << QString("")    << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
341     QTest::newRow("N004:Shift+F1 - [Shift+F1]")<< TestAccel << NoWidget << QString("")      << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
342     QTest::newRow("N004:F1 - [Shift+F1]")           << TestAccel << NoWidget << QString("")         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
343     QTest::newRow("N004 - clear")                   << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
344
345     /* Testing Single Sequences
346                Qt::Key_Tab      on  Qt::Key_Tab
347        Shift + Qt::Key_Tab      on  Qt::Key_Tab
348                Qt::Key_Backtab  on  Qt::Key_Tab
349        Shift + Qt::Key_Backtab  on  Qt::Key_Tab
350     */
351     QTest::newRow("N005a - slot1")                         << SetupAccel << TriggerSlot1 << QString("")<< int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
352     QTest::newRow("N005a:Tab - [Tab]")             << TestAccel << NoWidget << QString("")     << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
353     //commented out because the behaviour changed, those tests should be updated
354     //QTest::newRow("N005a:Shift+Tab - [Tab]")          << TestAccel << NoWidget << QString("")     << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
355     // (Shift+)BackTab != Tab, but Shift+BackTab == Shift+Tab
356     QTest::newRow("N005a:Backtab - [Tab]")                 << TestAccel << NoWidget << QString("")     << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
357     QTest::newRow("N005a:Shift+Backtab - [Tab]")      << TestAccel << NoWidget << QString("")     << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
358     QTest::newRow("N005a - clear")                         << ClearAll << 0 << QString("")             << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
359
360     /* Testing Single Sequences
361                Qt::Key_Tab      on  Shift + Qt::Key_Tab
362        Shift + Qt::Key_Tab      on  Shift + Qt::Key_Tab
363                Qt::Key_Backtab  on  Shift + Qt::Key_Tab
364        Shift + Qt::Key_Backtab  on  Shift + Qt::Key_Tab
365     */
366     QTest::newRow("N005b - slot1")                         << SetupAccel << TriggerSlot1 << QString("")<< int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
367     QTest::newRow("N005b:Tab - [Shift+Tab]")          << TestAccel << NoWidget << QString("")     << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
368     QTest::newRow("N005b:Shift+Tab - [Shift+Tab]")    << TestAccel << NoWidget << QString("")     << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
369     QTest::newRow("N005b:BackTab - [Shift+Tab]")      << TestAccel << NoWidget << QString("")     << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
370     QTest::newRow("N005b:Shift+BackTab - [Shift+Tab]")<< TestAccel << NoWidget << QString("")     << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
371     QTest::newRow("N005b - clear")                         << ClearAll << 0 << QString("")             << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
372
373     /* Testing Single Sequences
374                Qt::Key_Tab      on  Qt::Key_Backtab
375        Shift + Qt::Key_Tab      on  Qt::Key_Backtab
376                Qt::Key_Backtab  on  Qt::Key_Backtab
377        Shift + Qt::Key_Backtab  on  Qt::Key_Backtab
378     */
379     QTest::newRow("N006a - slot1")                         << SetupAccel << TriggerSlot1 << QString("")<< int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
380     QTest::newRow("N006a:Tab - [BackTab]")                 << TestAccel << NoWidget << QString("")     << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
381     // This should work, since platform dependent code will transform the
382     // Shift+Tab into a Shift+BackTab, which should trigger the shortcut
383     QTest::newRow("N006a:Shift+Tab - [BackTab]")      << TestAccel << NoWidget << QString("")     << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL
384     QTest::newRow("N006a:BackTab - [BackTab]")        << TestAccel << NoWidget << QString("")     << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
385     //commented out because the behaviour changed, those tests should be updated
386     //QTest::newRow("N006a:Shift+BackTab - [BackTab]")  << TestAccel << NoWidget << QString("")     << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
387     QTest::newRow("N006a - clear")                         << ClearAll << 0 << QString("")             << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
388
389     /* Testing Single Sequences
390                Qt::Key_Tab      on  Shift + Qt::Key_Backtab
391        Shift + Qt::Key_Tab      on  Shift + Qt::Key_Backtab
392                Qt::Key_Backtab  on  Shift + Qt::Key_Backtab
393        Shift + Qt::Key_Backtab  on  Shift + Qt::Key_Backtab
394     */
395     QTest::newRow("N006b - slot1")                         << SetupAccel << TriggerSlot1 << QString("")<< int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
396     QTest::newRow("N006b:Tab - [Shift+BackTab]")      << TestAccel << NoWidget << QString("")     << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
397     QTest::newRow("N006b:Shift+Tab - [Shift+BackTab]")<< TestAccel << NoWidget << QString("")     << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
398     QTest::newRow("N006b:BackTab - [Shift+BackTab]")  << TestAccel << NoWidget << QString("")     << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
399     QTest::newRow("N006b:Shift+BackTab - [Shift+BackTab]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL
400     QTest::newRow("N006b - clear")                         << ClearAll << 0 << QString("")             << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
401
402     //===========================================
403     // [Shift + key] and [key] on shortcuts with
404     // and without modifiers
405     //===========================================
406
407     /* Testing Single Sequences
408        Qt::Key_F1
409        Shift + Qt::Key_F1
410     */
411     QTest::newRow("N007 - slot1")                   << SetupAccel << TriggerSlot1 << QString("")    << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
412     QTest::newRow("N007 - slot2")                   << SetupAccel << TriggerSlot2 << QString("")    << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
413     QTest::newRow("N007:F1")                << TestAccel << NoWidget << QString("")         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
414     QTest::newRow("N007:Shift + F1")        << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
415     QTest::newRow("N007 - clear")                   << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
416
417     /* Testing Single Sequences
418        Qt::Key_M
419        Shift + Qt::Key_M
420        Ctrl  + Qt::Key_M
421        Alt   + Qt::Key_M
422     */
423     QTest::newRow("N01 - slot1")                    << SetupAccel << TriggerSlot1 << QString("")    << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
424     QTest::newRow("N02 - slot2")                    << SetupAccel << TriggerSlot2 << QString("")    << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
425     QTest::newRow("N03 - slot1")                    << SetupAccel << TriggerSlot1 << QString("")    << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
426     QTest::newRow("N04 - slot2")                    << SetupAccel << TriggerSlot2 << QString("")    << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
427     QTest::newRow("N:Qt::Key_M")                    << TestAccel << NoWidget << QString("")         << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
428     QTest::newRow("N:Shift+Qt::Key_M")              << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
429     QTest::newRow("N:Ctrl+Qt::Key_M")               << TestAccel << NoWidget << QString("")         << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
430     QTest::newRow("N:Alt+Qt::Key_M")                << TestAccel << NoWidget << QString("")         << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
431
432     /* Testing Single Sequence Ambiguity
433        Qt::Key_M on shortcut2
434     */
435     QTest::newRow("N05 - slot2")                    << SetupAccel << TriggerSlot2 << QString("")    << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
436     QTest::newRow("N:Qt::Key_M on slot")            << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous;
437     QTest::newRow("N05 - clear")                    << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
438
439     /* Testing Single Specialkeys
440        Qt::Key_aring
441        Qt::Key_Aring
442        Qt::UNICODE_ACCEL + Qt::Key_K
443     */
444     QTest::newRow("N06 - slot1")                    << SetupAccel << TriggerSlot1 << QString("")    << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
445     QTest::newRow("N07 - slot2")                    << SetupAccel << TriggerSlot2 << QString("")    << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
446     QTest::newRow("N08 - slot2")                    << SetupAccel << TriggerSlot1 << QString("")    << int(Qt::UNICODE_ACCEL + Qt::Key_K) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
447
448     QTest::newRow("N:Qt::Key_aring")                << TestAccel << NoWidget << QString("")         << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
449     QTest::newRow("N:Qt::Key_Aring")                << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
450     QTest::newRow("N:Qt::Key_aring - Text Form")   << TestAccel << NoWidget << QString("")          << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
451     QTest::newRow("N:Qt::Key_Aring - Text Form")   << TestAccel << NoWidget << QString("")          << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
452     QTest::newRow("N:Qt::UNICODE_ACCEL + Qt::Key_K")   << TestAccel << NoWidget << QString("")      << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
453     QTest::newRow("N09 - clear")                    << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
454
455     /* Testing Multiple Sequences
456        Qt::Key_M
457        Qt::Key_I, Qt::Key_M
458        Shift+Qt::Key_I, Qt::Key_M
459     */
460     QTest::newRow("N10 - slot1")                    << SetupAccel << TriggerSlot1 << QString("")    << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
461     QTest::newRow("N11 - slot2")                    << SetupAccel << TriggerSlot2 << QString("")    << int(Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult;
462     QTest::newRow("N12 - slot1")                    << SetupAccel << TriggerSlot1 << QString("")    << int(Qt::SHIFT + Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult;
463
464     QTest::newRow("N:Qt::Key_M (2)")                << TestAccel << NoWidget << QString("")         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
465     QTest::newRow("N:Qt::Key_I, Qt::Key_M")         << TestAccel << NoWidget << QString("")         << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered;
466     QTest::newRow("N:Shift+Qt::Key_I, Qt::Key_M")           << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered;
467     QTest::newRow("N13 - clear")                    << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
468 }
469
470 // ------------------------------------------------------------------
471 // Text Elements ----------------------------------------------------
472 // ------------------------------------------------------------------
473 void tst_QShortcut::text_data()
474 {
475     defElements();
476     // Clear all
477     QTest::newRow("T00 - clear") << ClearAll <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
478
479     //===========================================
480     // [Shift + key] on non-shift shortcuts testing
481     //===========================================
482
483     /* Testing Single Sequences
484        Shift + Qt::Key_M    on  Qt::Key_M
485                Qt::Key_M    on  Qt::Key_M
486        Shift + Qt::Key_Plus on  Qt::Key_Pluss
487                Qt::Key_Plus on  Qt::Key_Pluss
488     */
489     QTest::newRow("T001 - slot1")                   << SetupAccel << TriggerSlot1 << QString("M")   << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
490     //commented out because the behaviour changed, those tests should be updated
491     //QTest::newRow("T001:Shift+M - [M]")           << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
492     QTest::newRow("T001:M - [M]")                   << TestAccel << NoWidget << QString("")         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
493     QTest::newRow("T001 - slot2")                   << SetupAccel << TriggerSlot2 << QString("+")   << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
494     //commented out because the behaviour changed, those tests should be updated
495     //QTest::newRow("T001:Shift++ [+]")     << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
496     QTest::newRow("T001:+ [+]")             << TestAccel << NoWidget << QString("")         << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
497     QTest::newRow("T001 - clear")                   << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
498
499     /* Testing Single Sequences
500        Shift + Qt::Key_M    on  Shift + Qt::Key_M
501                Qt::Key_M    on  Shift + Qt::Key_M
502        Shift + Qt::Key_Plus on  Shift + Qt::Key_Pluss
503                Qt::Key_Plus on  Shift + Qt::Key_Pluss
504        Shift + Ctrl + Qt::Key_Plus on  Ctrl + Qt::Key_Pluss
505                Ctrl + Qt::Key_Plus on  Ctrl + Qt::Key_Pluss
506     */
507     QTest::newRow("T002 - slot1")                   << SetupAccel << TriggerSlot1 << QString("Shift+M")   << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
508     QTest::newRow("T002:Shift+M - [Shift+M]")  << TestAccel << NoWidget << QString("")      << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
509     QTest::newRow("T002:M - [Shift+M]")     << TestAccel << NoWidget << QString("")         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
510     QTest::newRow("T002 - slot2")                   << SetupAccel << TriggerSlot2 << QString("Shift++")   << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
511     QTest::newRow("T002:Shift++ [Shift++]")    << TestAccel << NoWidget << QString("")      << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
512     QTest::newRow("T002:+ [Shift++]")       << TestAccel << NoWidget << QString("")         << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
513     QTest::newRow("T002 - clear")                   << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
514
515     /* Testing Single Sequences
516        Shift + Ctrl + Qt::Key_Plus on  Ctrl + Qt::Key_Plus
517                Ctrl + Qt::Key_Plus on  Ctrl + Qt::Key_Plus
518                       Qt::Key_Plus on  Ctrl + Qt::Key_Plus
519     */
520     QTest::newRow("T002b - slot1")                  << SetupAccel << TriggerSlot1 << QString("Ctrl++")    << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
521     //commented out because the behaviour changed, those tests should be updated
522     //QTest::newRow("T002b:Shift+Ctrl++ [Ctrl++]")<< TestAccel << NoWidget << QString("")           << int(Qt::SHIFT + Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
523     QTest::newRow("T002b:Ctrl++ [Ctrl++]")          << TestAccel << NoWidget << QString("")         << int(Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
524     QTest::newRow("T002b:+ [Ctrl++]")       << TestAccel << NoWidget << QString("")         << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
525     QTest::newRow("T002b - clear")                  << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
526
527     /* Testing Single Sequences
528        Shift + Qt::Key_F1   on  Qt::Key_F1
529                Qt::Key_F1   on  Qt::Key_F1
530     */
531     QTest::newRow("T003 - slot1")                   << SetupAccel << TriggerSlot1 << QString("F1")  << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
532     //commented out because the behaviour changed, those tests should be updated
533     //QTest::newRow("T003:Shift+F1 - [F1]")         << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
534     QTest::newRow("T003:F1 - [F1]")         << TestAccel << NoWidget << QString("")         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
535     QTest::newRow("T003 - clear")                   << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
536
537     /* Testing Single Sequences
538        Shift + Qt::Key_F1   on  Shift + Qt::Key_F1
539                Qt::Key_F1   on  Shift + Qt::Key_F1
540     */
541     QTest::newRow("T004 - slot1")                   << SetupAccel << TriggerSlot1 << QString("Shift+F1")  << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
542     QTest::newRow("T004:Shift+F1 - [Shift+F1]")<< TestAccel << NoWidget << QString("")      << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
543     QTest::newRow("T004:F1 - [Shift+F1]")           << TestAccel << NoWidget << QString("")         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
544     QTest::newRow("T004 - clear")                   << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
545
546     //===========================================
547     // [Shift + key] and [key] on shortcuts with
548     // and without modifiers
549     //===========================================
550
551     /* Testing Single Sequences
552        Qt::Key_F1
553        Shift + Qt::Key_F1
554     */
555     QTest::newRow("T007 - slot1")                   << SetupAccel << TriggerSlot1 << QString("F1")  << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
556     QTest::newRow("T007 - slot2")                   << SetupAccel << TriggerSlot2 << QString("Shift+F1")  << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
557     QTest::newRow("T007:F1")                << TestAccel << NoWidget << QString("")         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
558     QTest::newRow("T007:Shift + F1")        << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
559     QTest::newRow("T007 - clear")                   << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
560
561     /* Testing Single Sequences
562        Qt::Key_M
563        Shift + Qt::Key_M
564        Ctrl  + Qt::Key_M
565        Alt   + Qt::Key_M
566     */
567     QTest::newRow("T01 - slot1")                    << SetupAccel << TriggerSlot1 << QString("M")         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
568     QTest::newRow("T02 - slot2")                    << SetupAccel << TriggerSlot2 << QString("Shift+M")   << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
569     QTest::newRow("T03 - slot1")                    << SetupAccel << TriggerSlot1 << QString("Ctrl+M")    << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
570     QTest::newRow("T04 - slot2")                    << SetupAccel << TriggerSlot2 << QString("Alt+M")     << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
571
572     QTest::newRow("T:Qt::Key_M")                    << TestAccel << NoWidget << QString("")         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
573     QTest::newRow("T:Shift + Qt::Key_M")            << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
574     QTest::newRow("T:Ctrl + Qt::Key_M")     << TestAccel << NoWidget << QString("")         << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
575     QTest::newRow("T:Alt + Qt::Key_M")              << TestAccel << NoWidget << QString("")         << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
576
577     /* Testing Single Sequence Ambiguity
578        Qt::Key_M on shortcut2
579     */
580     QTest::newRow("T05 - slot2")                    << SetupAccel << TriggerSlot2 << QString("M")   << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
581     QTest::newRow("T:Qt::Key_M on TriggerSlot2")            << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous;
582     QTest::newRow("T06 - clear")                    << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
583
584     /* Testing Single Specialkeys
585        Qt::Key_aring
586        Qt::Key_Aring
587        Qt::UNICODE_ACCEL + Qt::Key_K
588     */
589     /* see comments above on the #ifdef'ery */
590     QTest::newRow("T06 - slot1")                    << SetupAccel << TriggerSlot1 << QString("\x0C5")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
591     QTest::newRow("T07 - slot2")                    << SetupAccel << TriggerSlot2 << QString("Shift+\x0C5")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
592     QTest::newRow("T08 - slot2")                    << SetupAccel << TriggerSlot1 << QString("K")   << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
593     QTest::newRow("T:Qt::Key_aring")                << TestAccel << NoWidget << QString("")         << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
594     QTest::newRow("T:Qt::Key_Aring")                << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
595     QTest::newRow("T:Qt::Key_aring - Text Form")   << TestAccel << NoWidget << QString("")          << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
596     QTest::newRow("T:Qt::Key_Aring - Text Form")   << TestAccel << NoWidget << QString("")          << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
597     QTest::newRow("T:Qt::UNICODE_ACCEL + Qt::Key_K")   << TestAccel << NoWidget << QString("")      << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
598     QTest::newRow("T09 - clear")                    << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
599
600     /* Testing Multiple Sequences
601        Qt::Key_M
602        Qt::Key_I, Qt::Key_M
603        Shift+Qt::Key_I, Qt::Key_M
604     */
605     QTest::newRow("T10 - slot1")                    << SetupAccel << TriggerSlot1 << QString("M")   << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
606     QTest::newRow("T11 - slot2")                    << SetupAccel << TriggerSlot2 << QString("I, M")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
607     QTest::newRow("T12 - slot1")                    << SetupAccel << TriggerSlot1 << QString("Shift+I, M")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
608     QTest::newRow("T:Qt::Key_M (2)")                << TestAccel << NoWidget << QString("")         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
609     QTest::newRow("T:Qt::Key_I, Qt::Key_M")         << TestAccel << NoWidget << QString("")         << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered;
610     QTest::newRow("T:Shift+Qt::Key_I, Qt::Key_M")           << TestAccel << NoWidget << QString("")         << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered;
611     QTest::newRow("T13 - clear")                    << ClearAll << 0 << QString("")                 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
612 }
613
614 // ------------------------------------------------------------------
615 // Disabled Elements ------------------------------------------------
616 // ------------------------------------------------------------------
617 void tst_QShortcut::disabledItems()
618 {
619     clearAllShortcuts();
620     mainW->activateWindow();
621     qApp->syncX();
622     QTest::qWait(100);
623
624     /* Testing Disabled Shortcuts
625        Qt::Key_M          on slot1
626        Shift + Qt::Key_M  on slot1
627        Qt::Key_M          on slot2 (disabled)
628        Shift + Qt::Key_M  on slot2 (disabled)
629     */
630
631     // Setup two identical shortcuts on different pushbuttons
632     QPushButton pb1(mainW);
633     QPushButton pb2(mainW);
634     pb1.setObjectName("pushbutton-1");
635     pb2.setObjectName("pushbutton-2");
636     pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger
637     pb2.show();
638
639     QShortcut *cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M");
640     QShortcut *cut2 = setupShortcut(&pb1, "shortcut2-pb1", TriggerSlot1, "Shift+M");
641     QShortcut *cut3 = setupShortcut(&pb2, "shortcut3-pb2", TriggerSlot2, "M");
642     QShortcut *cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+M");
643
644     cut3->setEnabled(false);
645     cut4->setEnabled(false);
646
647     currentResult = NoResult;
648     sendKeyEvents(Qt::Key_M, 'm');
649     QCOMPARE(currentResult, Slot1Triggered);
650
651     currentResult = NoResult;
652     sendKeyEvents(Qt::SHIFT+Qt::Key_M, 'M');
653     QCOMPARE(currentResult, Slot1Triggered);
654
655     cut2->setEnabled(false);
656     cut4->setEnabled(true);
657
658     /* Testing Disabled Shortcuts
659        Qt::Key_M          on slot1
660        Shift + Qt::Key_M  on slot1 (disabled)
661        Qt::Key_M          on slot2 (disabled)
662        Shift + Qt::Key_M  on slot2
663     */
664     currentResult = NoResult;
665     sendKeyEvents( Qt::Key_M, 'm' );
666     QCOMPARE( currentResult, Slot1Triggered );
667
668     currentResult = NoResult;
669     sendKeyEvents( Qt::SHIFT+Qt::Key_M, 'M' );
670     QCOMPARE( currentResult, Slot2Triggered );
671
672
673     /* Testing Disabled Accel
674        Qt::Key_F5          on slot1
675        Shift + Qt::Key_F5  on slot2 (disabled)
676     */
677     clearAllShortcuts();
678     cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "F5");
679     cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+F5");
680
681     cut1->setKey(QKeySequence("F5"));
682     cut4->setKey(QKeySequence("Shift+F5"));
683
684     cut1->setEnabled(true);
685     cut4->setEnabled(false);
686
687     currentResult = NoResult;
688     sendKeyEvents( Qt::Key_F5, 0 );
689     QCOMPARE( currentResult, Slot1Triggered );
690
691     currentResult = NoResult;
692     sendKeyEvents( Qt::SHIFT+Qt::Key_F5, 0 );
693     QCOMPARE( currentResult, NoResult );
694
695 #if 0
696     qFatal("Not testing statusbar text feedback yet, since not implemented");
697     /* Testing Disabled Accel, and the corresponding statusbar feedback
698        Ctrl + Qt::Key_K, Ctrl + Qt::Key_L on slot1
699        Ctrl + Qt::Key_K, Ctrl + Qt::Key_M on slot2 (disabled)
700     */
701     cut1->setKey(QKeySequence("Ctrl+K, Ctrl+L"));
702     cut4->setKey(QKeySequence("Ctrl+K, Ctrl+M"));
703
704     cut1->setEnabled(true);
705     cut4->setEnabled(false);
706
707     currentResult = NoResult;
708     sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 );
709     sendKeyEvents( Qt::CTRL+Qt::Key_Q, 0 );
710     QCOMPARE( currentResult, NoResult );
711     if (over_330)
712         QCOMPARE( sbText, QString("Ctrl+K, Ctrl+Q not defined") );
713
714     currentResult = NoResult;
715     sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 );
716     sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 );
717     QCOMPARE( currentResult, NoResult );
718     if (over_330)
719         QCOMPARE( sbText, QString::null );
720
721     currentResult = NoResult;
722     sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 );
723     sendKeyEvents( Qt::CTRL+Qt::Key_L, 0 );
724     QCOMPARE( currentResult, Slot1Triggered );
725     if (over_330)
726         QCOMPARE( sbText, QString::null );
727 #endif
728     clearAllShortcuts();
729     cut1 = 0;
730     cut4 = 0;
731 }
732 // ------------------------------------------------------------------
733 // Ambiguous Elements -----------------------------------------------
734 // ------------------------------------------------------------------
735 void tst_QShortcut::ambiguousRotation()
736 {
737     clearAllShortcuts();
738     /* Testing Shortcut rotation scheme
739        Ctrl + Qt::Key_A   on slot1 (disabled)
740        Ctrl + Qt::Key_A   on slot2 (disabled)
741        Ctrl + Qt::Key_A   on slot3
742        Ctrl + Qt::Key_A   on slot4
743        Ctrl + Qt::Key_A   on slot5 (disabled)
744        Ctrl + Qt::Key_A   on slot6
745        Ctrl + Qt::Key_A   on slot7 (disabled)
746     */
747     QShortcut *cut1 = setupShortcut(TriggerSlot1, "Ctrl+A");
748     QShortcut *cut2 = setupShortcut(TriggerSlot2, "Ctrl+A");
749     QShortcut *cut3 = setupShortcut(TriggerSlot3, "Ctrl+A");
750     QShortcut *cut4 = setupShortcut(TriggerSlot4, "Ctrl+A");
751     QShortcut *cut5 = setupShortcut(TriggerSlot5, "Ctrl+A");
752     QShortcut *cut6 = setupShortcut(TriggerSlot6, "Ctrl+A");
753     QShortcut *cut7 = setupShortcut(TriggerSlot7, "Ctrl+A");
754
755     cut1->setEnabled(false);
756     cut2->setEnabled(false);
757     cut5->setEnabled(false);
758     cut7->setEnabled(false);
759
760     // Test proper rotation
761     //   Start on first
762     //   Go to last
763     //   Go back to first
764     //   Continue...
765     currentResult = NoResult;
766     ambigResult = NoResult;
767     sendKeyEvents(Qt::CTRL+Qt::Key_A);
768     QCOMPARE(currentResult, Ambiguous);
769     QCOMPARE(ambigResult, Slot3Triggered);
770
771     currentResult = NoResult;
772     ambigResult = NoResult;
773     sendKeyEvents(Qt::CTRL+Qt::Key_A);
774     QCOMPARE(currentResult, Ambiguous);
775     QCOMPARE(ambigResult, Slot4Triggered);
776
777     currentResult = NoResult;
778     ambigResult = NoResult;
779     sendKeyEvents(Qt::CTRL+Qt::Key_A);
780     QCOMPARE(currentResult, Ambiguous);
781     QCOMPARE(ambigResult, Slot6Triggered);
782
783     currentResult = NoResult;
784     ambigResult = NoResult;
785     sendKeyEvents(Qt::CTRL+Qt::Key_A);
786     QCOMPARE(currentResult, Ambiguous);
787     QCOMPARE(ambigResult, Slot3Triggered);
788
789     currentResult = NoResult;
790     ambigResult = NoResult;
791     sendKeyEvents(Qt::CTRL+Qt::Key_A);
792     QCOMPARE(currentResult, Ambiguous);
793     QCOMPARE(ambigResult, Slot4Triggered);
794
795     currentResult = NoResult;
796     ambigResult = NoResult;
797     sendKeyEvents(Qt::CTRL+Qt::Key_A);
798     QCOMPARE(currentResult, Ambiguous);
799     QCOMPARE(ambigResult, Slot6Triggered);
800
801     /* Testing Shortcut rotation scheme
802        Ctrl + Qt::Key_A   on slot1
803        Ctrl + Qt::Key_A   on slot2
804        Ctrl + Qt::Key_A   on slot3 (disabled)
805        Ctrl + Qt::Key_A   on slot4 (disabled)
806        Ctrl + Qt::Key_A   on slot5
807        Ctrl + Qt::Key_A   on slot6 (disabled)
808        Ctrl + Qt::Key_A   on slot7
809     */
810
811     cut1->setEnabled(true);
812     cut2->setEnabled(true);
813     cut5->setEnabled(true);
814     cut7->setEnabled(true);
815
816     cut3->setEnabled(false);
817     cut4->setEnabled(false);
818     cut6->setEnabled(false);
819
820     currentResult = NoResult;
821     ambigResult = NoResult;
822     sendKeyEvents(Qt::CTRL+Qt::Key_A);
823     QCOMPARE(currentResult, Ambiguous);
824     QCOMPARE(ambigResult, Slot1Triggered);
825
826     currentResult = NoResult;
827     ambigResult = NoResult;
828     sendKeyEvents(Qt::CTRL+Qt::Key_A);
829     QCOMPARE(currentResult, Ambiguous);
830     QCOMPARE(ambigResult, Slot2Triggered);
831
832     currentResult = NoResult;
833     ambigResult = NoResult;
834     sendKeyEvents(Qt::CTRL+Qt::Key_A);
835     QCOMPARE(currentResult, Ambiguous);
836     QCOMPARE(ambigResult, Slot5Triggered);
837
838     currentResult = NoResult;
839     ambigResult = NoResult;
840     sendKeyEvents(Qt::CTRL+Qt::Key_A);
841     QCOMPARE(currentResult, Ambiguous);
842     QCOMPARE(ambigResult, Slot7Triggered);
843
844     currentResult = NoResult;
845     ambigResult = NoResult;
846     sendKeyEvents(Qt::CTRL+Qt::Key_A);
847     QCOMPARE(currentResult, Ambiguous);
848     QCOMPARE(ambigResult, Slot1Triggered);
849
850     currentResult = NoResult;
851     ambigResult = NoResult;
852     sendKeyEvents(Qt::CTRL+Qt::Key_A);
853     QCOMPARE(currentResult, Ambiguous);
854     QCOMPARE(ambigResult, Slot2Triggered);
855
856     currentResult = NoResult;
857     ambigResult = NoResult;
858     sendKeyEvents(Qt::CTRL+Qt::Key_A);
859     QCOMPARE(currentResult, Ambiguous);
860     QCOMPARE(ambigResult, Slot5Triggered);
861
862     currentResult = NoResult;
863     ambigResult = NoResult;
864     sendKeyEvents(Qt::CTRL+Qt::Key_A);
865     QCOMPARE(currentResult, Ambiguous);
866     QCOMPARE(ambigResult, Slot7Triggered);
867
868     clearAllShortcuts();
869     cut1 = 0; cut2 = 0;
870     cut3 = 0; cut4 = 0;
871     cut5 = 0; cut6 = 0;
872     cut7 = 0;
873 }
874
875 void tst_QShortcut::ambiguousItems()
876 {
877     clearAllShortcuts();
878     /* Testing Ambiguous Shortcuts
879        Qt::Key_M  on Pushbutton 1
880        Qt::Key_M  on Pushbutton 2
881     */
882
883     // Setup two identical shortcuts on different pushbuttons
884     QPushButton pb1(mainW);
885     QPushButton pb2(mainW);
886     pb1.setObjectName("pushbutton-1");
887     pb2.setObjectName("pushbutton-2");
888     pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger
889     pb2.show();
890
891     setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M");
892     setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, "M");
893
894     currentResult = NoResult;
895     sendKeyEvents( Qt::Key_M, 'm' );
896     QCOMPARE( currentResult, Ambiguous );
897     QCOMPARE( ambigResult, Slot1Triggered );
898
899     currentResult = NoResult;
900     sendKeyEvents( Qt::Key_M, 'm' );
901     QCOMPARE( currentResult, Ambiguous );
902     QCOMPARE( ambigResult, Slot2Triggered );
903
904     currentResult = NoResult;
905     sendKeyEvents( Qt::Key_M, 'm' );
906     QCOMPARE( currentResult, Ambiguous );
907     QCOMPARE( ambigResult, Slot1Triggered );
908
909     clearAllShortcuts();
910 }
911
912
913 // ------------------------------------------------------------------
914 // Unicode and non-unicode Elements ---------------------------------
915 // ------------------------------------------------------------------
916 void tst_QShortcut::unicodeCompare()
917 {
918     clearAllShortcuts();
919     /* Testing Unicode/non-Unicode Shortcuts
920        Qt::Key_M  on Pushbutton 1
921        Qt::Key_M  on Pushbutton 2
922     */
923     QPushButton pb1(mainW);
924     QPushButton pb2(mainW);
925     pb1.setObjectName("pushbutton-1");
926     pb2.setObjectName("pushbutton-2");
927     pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger
928     pb2.show();
929
930     QKeySequence ks1("Ctrl+M");     // Unicode
931     QKeySequence ks2(Qt::CTRL+Qt::Key_M);   // non-Unicode
932     setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, ks1);
933     setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, ks2);
934
935     currentResult = NoResult;
936     sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 );
937     QCOMPARE( currentResult, Ambiguous );
938     // They _are_ ambiguous, so the QKeySequence operator==
939     // should indicate the same
940     QVERIFY( ks1 == ks2 );
941     QVERIFY( !(ks1 != ks2) );
942
943     clearAllShortcuts();
944 }
945
946 // ------------------------------------------------------------------
947 // Keypress consumption verification --------------------------------
948 // ------------------------------------------------------------------
949 void tst_QShortcut::keypressConsumption()
950 {
951     clearAllShortcuts();
952     edit->clear();
953     QCOMPARE(edit->toPlainText().size(), 0);
954
955     QShortcut *cut1 = setupShortcut(edit, "shortcut1-line", TriggerSlot1, "Ctrl+I, A");
956     QShortcut *cut2 = setupShortcut(edit, "shortcut1-line", TriggerSlot2, "Ctrl+I, B");
957
958     currentResult = NoResult;
959     ambigResult = NoResult;
960     sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0);   // Send key to edit
961     QCOMPARE( currentResult, NoResult );
962     QCOMPARE( ambigResult, NoResult );
963     QCOMPARE(edit->toPlainText(), QString(""));
964
965     // Make sure next keypress is eaten (failing multiple keysequence)
966     sendKeyEvents(edit, Qt::Key_C, 'c');         // Send key to edit
967     QCOMPARE( currentResult, NoResult );
968     QCOMPARE( ambigResult, NoResult );
969     QCOMPARE(edit->toPlainText(), QString(""));
970
971     // Next keypress should be normal
972     sendKeyEvents(edit, Qt::Key_C, 'c');         // Send key to edit
973     QCOMPARE( currentResult, NoResult );
974     QCOMPARE( ambigResult, NoResult );
975     QCOMPARE(edit->toPlainText(), QString("c"));
976
977     currentResult = NoResult;
978     ambigResult = NoResult;
979     edit->clear();
980     QCOMPARE(edit->toPlainText().size(), 0);
981
982     cut1->setEnabled(false);
983     cut2->setEnabled(false);
984
985     // Make sure keypresses is passed on, since all multiple keysequences
986     // with Ctrl+I are disabled
987     sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0);   // Send key to edit
988     QCOMPARE( currentResult, NoResult );
989     QCOMPARE( ambigResult, NoResult );
990     QVERIFY(edit->toPlainText().endsWith("<Ctrl+I>"));
991
992     sendKeyEvents(edit, Qt::Key_A, 'a');         // Send key to edit
993     QCOMPARE( currentResult, NoResult );
994     QCOMPARE( ambigResult, NoResult );
995     QVERIFY(edit->toPlainText().endsWith("<Ctrl+I>a"));
996
997     clearAllShortcuts();
998 }
999
1000 // ------------------------------------------------------------------
1001 // Context Validation -----------------------------------------------
1002 // ------------------------------------------------------------------
1003 void tst_QShortcut::context()
1004 {
1005     clearAllShortcuts();
1006
1007     QWidget myBox;
1008     TestEdit *other1 = new TestEdit(&myBox, "test_edit_other1");
1009     TestEdit *other2 = new TestEdit(&myBox, "test_edit_other2");
1010     QHBoxLayout *layout = new QHBoxLayout(&myBox);
1011     layout->addWidget(other1);
1012     layout->addWidget(other2);
1013     myBox.show();
1014 #ifdef Q_WS_X11
1015     qt_x11_wait_for_window_manager(&myBox);
1016 #endif
1017
1018     setupShortcut(other1, "ActiveWindow", TriggerSlot1, QKeySequence("Alt+1"), Qt::WindowShortcut);
1019     setupShortcut(other2, "Focus",        TriggerSlot2, QKeySequence("Alt+2"), Qt::WidgetShortcut);
1020     setupShortcut(edit,   "Application",  TriggerSlot3, QKeySequence("Alt+3"), Qt::ApplicationShortcut);
1021
1022     currentResult = NoResult;
1023     ambigResult = NoResult;
1024     edit->clear();
1025     other1->clear();
1026     other2->clear();
1027
1028     // edit doesn't have focus, so ActiveWindow context should work
1029     // ..but Focus context shouldn't..
1030     // Changing focus to edit should make focus context work
1031     // Application context should always work
1032
1033
1034     // Focus on 'other1' edit, so Active Window context should trigger
1035     other1->activateWindow(); // <---
1036     QApplication::setActiveWindow(other1);
1037     QCOMPARE(qApp->activeWindow(), other1->window());
1038     QCOMPARE(qApp->focusWidget(), (QWidget *)other1);
1039
1040     currentResult = NoResult;
1041     ambigResult = NoResult;
1042     edit->clear();
1043     other1->clear();
1044     other2->clear();
1045
1046     QCOMPARE(qApp->focusWidget(), (QWidget *)other1);
1047     sendKeyEvents(other1, Qt::ALT+Qt::Key_1);
1048     QCOMPARE(currentResult, Slot1Triggered);
1049     QCOMPARE(ambigResult, NoResult);
1050     QCOMPARE(edit->toPlainText(), QString(""));
1051     QCOMPARE(other1->toPlainText(), QString(""));
1052     QCOMPARE(other2->toPlainText(), QString(""));
1053
1054     // ..but not Focus context on 'other2'..
1055     currentResult = NoResult;
1056     ambigResult = NoResult;
1057     edit->clear();
1058     other1->clear();
1059     other2->clear();
1060
1061     sendKeyEvents(other1, Qt::ALT+Qt::Key_2);
1062     QCOMPARE(currentResult, NoResult);
1063     QCOMPARE(ambigResult, NoResult);
1064     QCOMPARE(edit->toPlainText(), QString(""));
1065     QCOMPARE(other1->toPlainText(), QString("<Alt+2>"));
1066     QCOMPARE(other2->toPlainText(), QString(""));
1067
1068     // ..however, application global context on 'edit' should..
1069     currentResult = NoResult;
1070     ambigResult = NoResult;
1071     edit->clear();
1072     other1->clear();
1073     other2->clear();
1074
1075     sendKeyEvents(other1, Qt::ALT+Qt::Key_3);
1076     QCOMPARE(currentResult, Slot3Triggered);
1077     QCOMPARE(ambigResult, NoResult);
1078     QCOMPARE(edit->toPlainText(), QString(""));
1079     QCOMPARE(other1->toPlainText(), QString(""));
1080     QCOMPARE(other2->toPlainText(), QString(""));
1081
1082     // Changing focus to 'other2' should make the Focus context there work
1083     other2->activateWindow();
1084     other2->setFocus(); // ###
1085     qApp->syncX();
1086 #ifdef Q_WS_X11
1087     qt_x11_wait_for_window_manager(other2);
1088 #endif
1089     QTest::qWait(100);
1090     QCOMPARE(qApp->activeWindow(), other2->window());
1091     QCOMPARE(qApp->focusWidget(), (QWidget *)other2);
1092
1093     currentResult = NoResult;
1094     ambigResult = NoResult;
1095     edit->clear();
1096     other1->clear();
1097     other2->clear();
1098
1099     sendKeyEvents(other2, Qt::ALT+Qt::Key_2);
1100     QCOMPARE(currentResult, Slot2Triggered);
1101     QCOMPARE(ambigResult, NoResult);
1102     QCOMPARE(edit->toPlainText(), QString(""));
1103     QCOMPARE(other1->toPlainText(), QString(""));
1104     QCOMPARE(other2->toPlainText(), QString(""));
1105
1106     clearAllShortcuts();
1107     delete other1;
1108     delete other2;
1109     edit->activateWindow();
1110     qApp->syncX();
1111 #ifdef Q_WS_X11
1112     qt_x11_wait_for_window_manager(edit);
1113 #endif
1114     QTest::qWait(100);
1115 }
1116
1117 // ------------------------------------------------------------------
1118 // Element Testing helper functions ---------------------------------
1119 // ------------------------------------------------------------------
1120 void tst_QShortcut::clearAllShortcuts()
1121 {
1122     QList<QShortcut *> shortcutsCpy = shortcuts;
1123     qDeleteAll(shortcutsCpy);
1124     shortcuts.clear();
1125 }
1126
1127 QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QKeySequence &ks)
1128 {
1129     return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, ks);
1130 }
1131
1132 QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QString &txt, int k1, int k2, int k3, int k4)
1133 {
1134     return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget,
1135                          (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt)));
1136 }
1137
1138 QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1, int k2, int k3, int k4)
1139 {
1140     return setupShortcut(parent, name, testWidget,
1141                          (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt)));
1142 }
1143
1144 QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget,
1145                                         const QKeySequence &ks, Qt::ShortcutContext context)
1146 {
1147     // Set up shortcut for next test
1148     QShortcut *cut = new QShortcut(QKeySequence(), parent, 0, 0, context);
1149     cut->setObjectName(name);
1150     cut->setKey(ks);
1151
1152     const char *normal = 0;
1153     const char *ambig  = 0;
1154     switch(testWidget)
1155     {
1156     case TriggerSlot1:
1157         normal = SLOT(slotTrig1());
1158         ambig  = SLOT(ambigSlot1());
1159         break;
1160     case TriggerSlot2:
1161         normal = SLOT(slotTrig2());
1162         ambig  = SLOT(ambigSlot2());
1163         break;
1164     case TriggerSlot3:
1165         normal = SLOT(slotTrig3());
1166         ambig  = SLOT(ambigSlot3());
1167         break;
1168     case TriggerSlot4:
1169         normal = SLOT(slotTrig4());
1170         ambig  = SLOT(ambigSlot4());
1171         break;
1172     case TriggerSlot5:
1173         normal = SLOT(slotTrig5());
1174         ambig  = SLOT(ambigSlot5());
1175         break;
1176     case TriggerSlot6:
1177         normal = SLOT(slotTrig6());
1178         ambig  = SLOT(ambigSlot6());
1179         break;
1180     case TriggerSlot7:
1181         normal = SLOT(slotTrig7());
1182         ambig  = SLOT(ambigSlot7());
1183         break;
1184     }
1185     connect(cut, SIGNAL(activated()), this, normal);
1186     connect(cut, SIGNAL(activatedAmbiguously()), this, ambig);
1187     connect(cut, SIGNAL(destroyed(QObject*)), this, SLOT(shortcutDestroyed(QObject*)));
1188     shortcuts.append(cut);
1189     return cut;
1190 }
1191
1192 void tst_QShortcut::shortcutDestroyed(QObject* obj)
1193 {
1194     shortcuts.removeAll(static_cast<QShortcut *>(obj));
1195 }
1196
1197 void tst_QShortcut::sendKeyEvents(int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4)
1198 {
1199     sendKeyEvents(mainW, k1, c1, k2, c2, k3, c3, k4, c4);
1200 }
1201
1202 void tst_QShortcut::sendKeyEvents(QWidget *w, int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4)
1203 {
1204     Qt::KeyboardModifiers b1 = toButtons( k1 );
1205     Qt::KeyboardModifiers b2 = toButtons( k2 );
1206     Qt::KeyboardModifiers b3 = toButtons( k3 );
1207     Qt::KeyboardModifiers b4 = toButtons( k4 );
1208     k1 &= ~Qt::MODIFIER_MASK;
1209     k2 &= ~Qt::MODIFIER_MASK;
1210     k3 &= ~Qt::MODIFIER_MASK;
1211     k4 &= ~Qt::MODIFIER_MASK;
1212
1213
1214     if (k1 || c1.toAscii()) {
1215         QString c(c1.unicode() == QChar::Null ? QString() : QString(c1));
1216         QTest::sendKeyEvent(QTest::Press, w, static_cast<Qt::Key>(k1), c, b1);
1217         QTest::sendKeyEvent(QTest::Release, w, static_cast<Qt::Key>(k1), c, b1);
1218     }
1219
1220     if (k2 || c2.toAscii()) {
1221         QString c(c2.unicode() == QChar::Null ? QString() : QString(c2));
1222         QTest::sendKeyEvent(QTest::Press, w, static_cast<Qt::Key>(k2), c, b2);
1223         QTest::sendKeyEvent(QTest::Release, w, static_cast<Qt::Key>(k2), c, b2);
1224     }
1225
1226     if (k3 || c3.toAscii()) {
1227         QString c(c3.unicode() == QChar::Null ? QString() : QString(c3));
1228         QTest::sendKeyEvent(QTest::Press, w, static_cast<Qt::Key>(k3), c, b3);
1229         QTest::sendKeyEvent(QTest::Release, w, static_cast<Qt::Key>(k3), c, b3);
1230     }
1231
1232     if (k4 || c4.toAscii()) {
1233         QString c(c4.unicode() == QChar::Null ? QString() : QString(c4));
1234         QTest::sendKeyEvent(QTest::Press, w, static_cast<Qt::Key>(k4), c, b4);
1235         QTest::sendKeyEvent(QTest::Release, w, static_cast<Qt::Key>(k4), c, b4);
1236     }
1237 }
1238
1239 void tst_QShortcut::testElement()
1240 {
1241     currentResult = NoResult;
1242     QFETCH(int, action);
1243     QFETCH(int, testWidget);
1244     QFETCH(QString, txt);
1245     QFETCH(int, k1);
1246     QFETCH(int, c1);
1247     QFETCH(int, k2);
1248     QFETCH(int, c2);
1249     QFETCH(int, k3);
1250     QFETCH(int, c3);
1251     QFETCH(int, k4);
1252     QFETCH(int, c4);
1253     QFETCH(int, result);
1254
1255     if (action == ClearAll) {
1256         clearAllShortcuts();
1257     } else if (action == SetupAccel) {
1258         setupShortcut(testWidget, txt, k1, k2, k3, k4);
1259     } else {
1260         sendKeyEvents(k1, c1, k2, c2, k3, c3, k4, c4);
1261         QCOMPARE(int(currentResult), result);
1262     }
1263 }
1264
1265 QTEST_MAIN(tst_QShortcut)
1266 #include "tst_qshortcut.moc"