1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 
43 #include <QtTest/QtTest>
44 #include <qapplication.h>
45 #include <q3accel.h>
46 #include <qtextedit.h>
47 #include <qmainwindow.h>
48 #include <qstatusbar.h>
49 #include <qstring.h>
50 
51 class AccelForm;
52 QT_FORWARD_DECLARE_CLASS(QTextEdit)
53 QT_FORWARD_DECLARE_CLASS(QMainWindow)
54 
55 //TESTED_CLASS=
56 //TESTED_FILES=
57 
58 class tst_Q3Accel : public QObject
59 {
60     Q_OBJECT
61 public:
62     tst_Q3Accel();
63     virtual ~tst_Q3Accel();
64 
65 
66 public slots:
accelTrig1()67     void accelTrig1() { currentResult = Accel1Triggered; }
accelTrig2()68     void accelTrig2() { currentResult = Accel2Triggered; }
ambig1()69     void ambig1() { currentResult = Ambiguous; ambigResult = Accel1Triggered; }
ambig2()70     void ambig2() { currentResult = Ambiguous; ambigResult = Accel2Triggered; }
statusMessage(const QString & message)71     void statusMessage( const QString& message ) { sbText = message; }
72 
73 public slots:
74     void initTestCase();
75 private slots:
76     void number_data();
77     void number();
78     void text_data();
79     void text();
80     void disabledItems();
81     void ambiguousItems();
82     void unicodeCompare();
83     void unicodeCompose();
84 
85 protected:
86     static int toButtons( int key );
87     void defElements();
88     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 );
89     void testElement();
90 
91     enum Action {
92         SetupAccel,
93         TestAccel,
94         ClearAll
95     } currentAction;
96 
97     enum Widget {
98         NoWidget,
99         Accel1,
100         Accel2
101     };
102 
103     enum Result {
104         NoResult,
105         Accel1Triggered,
106         Accel2Triggered,
107         Ambiguous
108     } currentResult;
109 
110     QMainWindow *mainW;
111     Q3Accel *accel1;
112     Q3Accel *accel2;
113     QTextEdit *edit;
114     QString sbText;
115     Result ambigResult;
116 };
117 
118 // copied from qkeysequence.cpp
119 const QString MacCtrl = QString(QChar(0x2318));
120 const QString MacMeta = QString(QChar(0x2303));
121 const QString MacAlt = QString(QChar(0x2325));
122 const QString MacShift = QString(QChar(0x21E7));
123 
tst_Q3Accel()124 tst_Q3Accel::tst_Q3Accel(): mainW( 0 )
125 {
126 }
127 
~tst_Q3Accel()128 tst_Q3Accel::~tst_Q3Accel()
129 {
130     delete mainW;
131 }
132 
initTestCase()133 void tst_Q3Accel::initTestCase()
134 {
135     currentResult = NoResult;
136     mainW = new QMainWindow(0);
137     mainW->setObjectName("main window");
138     mainW->setFixedSize( 100, 100 );
139     accel1 = new Q3Accel(mainW, "test_accel1" );
140     accel2 = new Q3Accel(mainW, "test_accel2" );
141     edit   = new QTextEdit(mainW);
142     edit->setObjectName("test_edit");
143     connect( accel1, SIGNAL(activated(int)), this, SLOT(accelTrig1()) );
144     connect( accel2, SIGNAL(activated(int)), this, SLOT(accelTrig2()) );
145     connect( accel1, SIGNAL(activatedAmbiguously(int)), this, SLOT(ambig1()) );
146     connect( accel2, SIGNAL(activatedAmbiguously(int)), this, SLOT(ambig2()) );
147     mainW->setCentralWidget( edit );
148     connect( mainW->statusBar(), SIGNAL(messageChanged(const QString&)),
149              this, SLOT(statusMessage(const QString&)) );
150     qApp->setMainWidget( mainW );
151     mainW->show();
152 }
153 
toButtons(int key)154 int tst_Q3Accel::toButtons( int key )
155 {
156     int result = 0;
157     if ( key & Qt::SHIFT )
158         result |= Qt::ShiftModifier;
159     if ( key & Qt::CTRL )
160         result |= Qt::ControlModifier;
161     if ( key & Qt::META )
162         result |= Qt::MetaModifier;
163     if ( key & Qt::ALT )
164         result |= Qt::AltModifier;
165     return result;
166 }
167 
defElements()168 void tst_Q3Accel::defElements()
169 {
170     QTest::addColumn<int>("theAction");
171     QTest::addColumn<int>("theTestWidget");
172     QTest::addColumn<QString>("theString");
173     QTest::addColumn<int>("the1Key");
174     QTest::addColumn<int>("the1Char");
175     QTest::addColumn<int>("the2Key");
176     QTest::addColumn<int>("the2Char");
177     QTest::addColumn<int>("the3Key");
178     QTest::addColumn<int>("the3Char");
179     QTest::addColumn<int>("the4Key");
180     QTest::addColumn<int>("the4Char");
181     QTest::addColumn<int>("theResult");
182 }
183 
number()184 void tst_Q3Accel::number()
185 {
186     testElement();
187 }
text()188 void tst_Q3Accel::text()
189 {
190     testElement();
191 }
192 // ------------------------------------------------------------------
193 // Number Elements --------------------------------------------------
194 // ------------------------------------------------------------------
number_data()195 void tst_Q3Accel::number_data()
196 {
197     defElements();
198 
199     // Clear all
200     QTest::newRow( "N00 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
201 
202     //===========================================
203     // [Shift + key] on non-shift accels testing
204     //===========================================
205 
206     /* Testing Single Sequences
207        Shift + Qt::Key_M    on  Qt::Key_M
208                Qt::Key_M    on  Qt::Key_M
209        Shift + Qt::Key_Plus on  Qt::Key_Pluss
210                Qt::Key_Plus on  Qt::Key_Pluss
211     */
212     QTest::newRow( "N001 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
213         << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
214     QTest::newRow( "N001:Shift + M - [M]" ) << int(TestAccel) << int(NoWidget) << QString("")
215         << int(Qt::SHIFT) + int(Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
216     QTest::newRow( "N001:M - [M]" ) << int(TestAccel) << int(NoWidget) << QString("")
217         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
218 
219     QTest::newRow( "N001 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("")
220         << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
221     QTest::newRow( "N001:Shift + + [+]" ) << int(TestAccel) << int(NoWidget) << QString("")
222         << int(Qt::SHIFT) + int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
223     QTest::newRow( "N001:+ [+]" ) << int(TestAccel) << int(NoWidget) << QString("")
224         << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
225 
226     QTest::newRow( "N001 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
227 
228     /* Testing Single Sequences
229        Shift + Qt::Key_M    on  Shift + Qt::Key_M
230                Qt::Key_M    on  Shift + Qt::Key_M
231        Shift + Qt::Key_Plus on  Shift + Qt::Key_Pluss
232                Qt::Key_Plus on  Shift + Qt::Key_Pluss
233     */
234     QTest::newRow( "N002 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
235         << int(Qt::SHIFT) + int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
236     QTest::newRow( "N002:Shift + M - [Shift + M]" ) << int(TestAccel) << int(NoWidget) << QString("")
237         << int(Qt::SHIFT) + int(Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
238     QTest::newRow( "N002:M - [Shift + M]" ) << int(TestAccel) << int(NoWidget) << QString("")
239         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
240 
241     QTest::newRow( "N002 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("")
242         << int(Qt::SHIFT) + int(Qt::Key_Plus) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
243     QTest::newRow( "N002:Shift + + [Shift + +]" ) << int(TestAccel) << int(NoWidget) << QString("")
244         << int(Qt::SHIFT) + int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
245     QTest::newRow( "N002:+ [Shift + +]" ) << int(TestAccel) << int(NoWidget) << QString("")
246         << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
247 
248     QTest::newRow( "N002 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
249 
250     /* Testing Single Sequences
251        Shift + Qt::Key_F1   on  Qt::Key_F1
252                Qt::Key_F1   on  Qt::Key_F1
253     */
254     QTest::newRow( "N003 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
255         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
256     QTest::newRow( "N003:Shift + F1 - [F1]" ) << int(TestAccel) << int(NoWidget) << QString("")
257         << int(Qt::SHIFT) + int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
258     QTest::newRow( "N003:F1 - [F1]" ) << int(TestAccel) << int(NoWidget) << QString("")
259         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
260 
261     QTest::newRow( "N003 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
262 
263     /* Testing Single Sequences
264        Shift + Qt::Key_F1   on  Shift + Qt::Key_F1
265                Qt::Key_F1   on  Shift + Qt::Key_F1
266     */
267     QTest::newRow( "N004 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
268         << int(Qt::SHIFT) + int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
269     QTest::newRow( "N004:Shift + F1 - [Shift + F1]" ) << int(TestAccel) << int(NoWidget) << QString("")
270         << int(Qt::SHIFT) + int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
271     QTest::newRow( "N004:F1 - [Shift + F1]" ) << int(TestAccel) << int(NoWidget) << QString("")
272         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
273 
274     QTest::newRow( "N004 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
275 
276     /* Testing Single Sequences
277                Qt::Key_BackTab  on  Qt::Key_Tab
278        Shift + Qt::Key_Tab      on  Qt::Key_Tab
279                Qt::Key_Tab      on  Qt::Key_Tab
280     */
281     QTest::newRow( "N005 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
282         << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
283     QTest::newRow( "N005:BackTab - [Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
284         << int(Qt::Key_BackTab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
285     QTest::newRow( "N005:Shift + Tab - [Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
286         << int(Qt::SHIFT) + Qt::Key_Tab << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
287     QTest::newRow( "N005:Tab - [Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
288         << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
289 
290     QTest::newRow( "N005 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
291 
292     /* Testing Single Sequences
293                Qt::Key_BackTab  on  Shift + Qt::Key_Tab
294        Shift + Qt::Key_Tab      on  Shift + Qt::Key_Tab
295                Qt::Key_Tab      on  Shift + Qt::Key_Tab
296     */
297     QTest::newRow( "N006 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
298         << int(Qt::SHIFT) + int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
299     QTest::newRow( "N006:BackTab - [Shift + Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
300         << int(Qt::SHIFT) + int(Qt::Key_BackTab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
301     QTest::newRow( "N006:Shift + Tab - [Shift + Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
302         << int(Qt::SHIFT) + int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
303     QTest::newRow( "N006:Tab - [Shift + Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
304         << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
305 
306     QTest::newRow( "N006 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
307 
308 
309     //===========================================
310     // [Shift + key] and [key] on accels with
311     // and without modifiers
312     //===========================================
313 
314     /* Testing Single Sequences
315        Qt::Key_F1
316        Shift + Qt::Key_F1
317     */
318     QTest::newRow( "N007 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
319         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
320     QTest::newRow( "N007 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("")
321         << int(Qt::SHIFT) + int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
322     QTest::newRow( "N007:F1" ) << int(TestAccel) << int(NoWidget) << QString("")
323         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
324     QTest::newRow( "N007:Shift + F1" ) << int(TestAccel) << int(NoWidget) << QString("")
325         << int(Qt::SHIFT) + int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
326 
327     QTest::newRow( "N007 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
328 
329     /* Testing Single Sequences
330        Qt::Key_M
331        Shift + Qt::Key_M
332        Ctrl  + Qt::Key_M
333        Alt   + Qt::Key_M
334     */
335     QTest::newRow( "N01 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
336         << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
337     QTest::newRow( "N02 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("")
338         << int(Qt::SHIFT) + int(Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
339     QTest::newRow( "N03 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
340         << int(Qt::CTRL) + int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
341     QTest::newRow( "N04 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("")
342         << int(Qt::ALT) + int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
343 
344 
345     QTest::newRow( "N:Qt::Key_M" ) << int(TestAccel) << int(NoWidget) << QString("")
346         << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
347     QTest::newRow( "N:Shift + Qt::Key_M" ) << int(TestAccel) << int(NoWidget) << QString("")
348         << int(Qt::SHIFT) + int(Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
349     QTest::newRow( "N:Ctrl + Qt::Key_M" ) << int(TestAccel) << int(NoWidget) << QString("")
350         << int(Qt::CTRL) + int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
351     QTest::newRow( "N:Alt + Qt::Key_M" ) << int(TestAccel) << int(NoWidget) << QString("")
352         << int(Qt::ALT) + int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
353 
354     /* Testing Single Sequence Ambiguity
355        Qt::Key_M on accel2
356     */
357     QTest::newRow( "N05 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("")
358         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
359     QTest::newRow( "N:int(Qt::Key_M) on int(Accel2)" ) << int(TestAccel) << int(NoWidget) << QString("")
360         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << int(Ambiguous);
361 
362     /* Testing Single Specialkeys
363        int(Qt::Key_aring)
364        int(Qt::Key_Aring)
365        UNICODE_ACCEL + int(Qt::Key_K)
366     */
367     QTest::newRow( "N06 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
368         << int(Qt::Key_aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
369     QTest::newRow( "N08 - sA2" ) << int(SetupAccel) << int(Accel1) << QString("")
370         << int(Qt::UNICODE_ACCEL) + int(Qt::Key_K) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
371 
372     QTest::newRow( "N:int(Qt::Key_aring)" ) << int(TestAccel) << int(NoWidget) << QString("")
373         << int(Qt::Key_aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
374     QTest::newRow( "N:int(Qt::Key_aring) - Text Form" ) << int(TestAccel) << int(NoWidget) << QString("")
375         << int(Qt::Key_unknown) << 0xE5 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
376     QTest::newRow( "N:int(Qt::Key_Aring) - Text Form" ) << int(TestAccel) << int(NoWidget) << QString("")
377         << int(Qt::Key_unknown) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
378     QTest::newRow( "N:UNICODE_ACCEL + int(Qt::Key_K)" ) << int(TestAccel) << int(NoWidget) << QString("")
379         << int(Qt::UNICODE_ACCEL) + int(Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
380 
381     // Clear all
382     QTest::newRow( "N09 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
383 
384     /* Testing Multiple Sequences
385        int(Qt::Key_M)
386        int(Qt::Key_I), int(Qt::Key_M)
387        Shift+int(Qt::Key_I), int(Qt::Key_M)
388     */
389     QTest::newRow( "N10 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
390         << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
391     QTest::newRow( "N11 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("")
392         << int(Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << int(NoResult);
393     QTest::newRow( "N12 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("")
394         << int(Qt::SHIFT) + int(Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << int(NoResult);
395 
396     QTest::newRow( "N:int(Qt::Key_M) (2)" ) << int(TestAccel) << int(NoWidget) << QString("")
397         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
398     QTest::newRow( "N:int(Qt::Key_I), int(Qt::Key_M)" ) << int(TestAccel) << int(NoWidget) << QString("")
399         << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << int(Accel2Triggered);
400     QTest::newRow( "N:Shift+int(Qt::Key_I), int(Qt::Key_M)" ) << int(TestAccel) << int(NoWidget) << QString("")
401         << int(Qt::SHIFT) + int(Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << int(Accel1Triggered);
402 }
403 
404 // ------------------------------------------------------------------
405 // Text Elements ----------------------------------------------------
406 // ------------------------------------------------------------------
text_data()407 void tst_Q3Accel::text_data()
408 {
409     defElements();
410     // Clear all
411     QTest::newRow( "T00 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
412 
413     //===========================================
414     // [Shift + key] on non-shift accels testing
415     //===========================================
416 
417     /* Testing Single Sequences
418        Shift + int(Qt::Key_M)    on  int(Qt::Key_M)
419                int(Qt::Key_M)    on  int(Qt::Key_M)
420        Shift + int(Qt::Key_Plus) on  Qt::Key_Pluss
421                int(Qt::Key_Plus) on  Qt::Key_Pluss
422     */
423     QTest::newRow( "T001 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("M")
424         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
425     QTest::newRow( "T001:Shift + M - [M]" ) << int(TestAccel) << int(NoWidget) << QString("")
426         << int(Qt::SHIFT) + int(Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
427     QTest::newRow( "T001:M - [M]" ) << int(TestAccel) << int(NoWidget) << QString("")
428         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
429 
430     QTest::newRow( "T001 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("+")
431         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
432     QTest::newRow( "T001:Shift + + [+]" ) << int(TestAccel) << int(NoWidget) << QString("")
433         << int(Qt::SHIFT) + int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
434     QTest::newRow( "T001:+ [+]" ) << int(TestAccel) << int(NoWidget) << QString("")
435         << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
436 
437     QTest::newRow( "T001 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
438 
439     /* Testing Single Sequences
440        Shift + int(Qt::Key_M)    on  Shift + int(Qt::Key_M)
441                int(Qt::Key_M)    on  Shift + int(Qt::Key_M)
442        Shift + int(Qt::Key_Plus) on  Shift + Qt::Key_Pluss
443                int(Qt::Key_Plus) on  Shift + Qt::Key_Pluss
444        Shift + Ctrl + int(Qt::Key_Plus) on  Ctrl + Qt::Key_Pluss
445                Ctrl + int(Qt::Key_Plus) on  Ctrl + Qt::Key_Pluss
446     */
447     QTest::newRow( "T002 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("Shift+M")
448         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
449     QTest::newRow( "T002:Shift + M - [Shift + M]" ) << int(TestAccel) << int(NoWidget) << QString("")
450         << int(Qt::SHIFT) + int(Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
451     QTest::newRow( "T002:M - [Shift + M]" ) << int(TestAccel) << int(NoWidget) << QString("")
452         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
453 
454     QTest::newRow( "T002 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("Shift++")
455         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
456     QTest::newRow( "T002:Shift + + [Shift + +]" ) << int(TestAccel) << int(NoWidget) << QString("")
457         << int(Qt::SHIFT) + int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
458     QTest::newRow( "T002:+ [Shift + +]" ) << int(TestAccel) << int(NoWidget) << QString("")
459         << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
460 
461     QTest::newRow( "T002 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
462 
463     /* Testing Single Sequences
464        Shift + Ctrl + int(Qt::Key_Plus) on  Ctrl + int(Qt::Key_Plus)
465                Ctrl + int(Qt::Key_Plus) on  Ctrl + int(Qt::Key_Plus)
466                       int(Qt::Key_Plus) on  Ctrl + int(Qt::Key_Plus)
467     */
468     QTest::newRow( "T002b - sA1" ) << int(SetupAccel) << int(Accel1) << QString("Ctrl++")
469         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
470     QTest::newRow( "T002b:Shift + Ctrl + + [Ctrl + +]" ) << int(TestAccel) << int(NoWidget) << QString("")
471         << int(Qt::SHIFT) + int(Qt::CTRL) + int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
472     QTest::newRow( "T002b:Ctrl + [Ctrl + +]" ) << int(TestAccel) << int(NoWidget) << QString("")
473         << int(Qt::CTRL) + int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
474     QTest::newRow( "T002b: + [Ctrl + +]" ) << int(TestAccel) << int(NoWidget) << QString("")
475         << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
476 
477     /* Testing Single Sequences
478        Shift + int(Qt::Key_F1)   on  int(Qt::Key_F1)
479                int(Qt::Key_F1)   on  int(Qt::Key_F1)
480     */
481     QTest::newRow( "T003 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("F1")
482         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
483     QTest::newRow( "T003:Shift + F1 - [F1]" ) << int(TestAccel) << int(NoWidget) << QString("")
484         << int(Qt::SHIFT) + int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
485     QTest::newRow( "T003:F1 - [F1]" ) << int(TestAccel) << int(NoWidget) << QString("")
486         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
487 
488     QTest::newRow( "T003 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
489 
490     /* Testing Single Sequences
491        Shift + int(Qt::Key_F1)   on  Shift + int(Qt::Key_F1)
492                int(Qt::Key_F1)   on  Shift + int(Qt::Key_F1)
493     */
494     QTest::newRow( "T004 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("Shift+F1")
495         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
496     QTest::newRow( "T004:Shift + F1 - [Shift + F1]" ) << int(TestAccel) << int(NoWidget) << QString("")
497         << int(Qt::SHIFT) + int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
498     QTest::newRow( "T004:F1 - [Shift + F1]" ) << int(TestAccel) << int(NoWidget) << QString("")
499         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
500 
501     QTest::newRow( "T004 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
502 
503     /* Testing Single Sequences
504                int(Qt::Key_BackTab)  on  int(Qt::Key_Tab)
505        Shift + int(Qt::Key_Tab)      on  int(Qt::Key_Tab)
506                int(Qt::Key_Tab)      on  int(Qt::Key_Tab)
507     */
508     QTest::newRow( "T005 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("Tab")
509         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
510     QTest::newRow( "T005:BackTab - [Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
511         << int(Qt::Key_BackTab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
512     QTest::newRow( "T005:Shift + Tab - [Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
513         << int(Qt::SHIFT) + int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
514     QTest::newRow( "T005:Tab - [Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
515         << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
516 
517     QTest::newRow( "N005 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
518 
519     /* Testing Single Sequences
520                int(Qt::Key_BackTab)  on  Shift + int(Qt::Key_Tab)
521        Shift + int(Qt::Key_Tab)      on  Shift + int(Qt::Key_Tab)
522                int(Qt::Key_Tab)      on  Shift + int(Qt::Key_Tab)
523     */
524     QTest::newRow( "T006 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("Shift+Tab")
525         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
526     QTest::newRow( "T006:BackTab - [Shift + Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
527         << int(Qt::SHIFT) + int(Qt::Key_BackTab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
528     QTest::newRow( "T006:Shift + Tab - [Shift + Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
529         << int(Qt::SHIFT) + int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
530     QTest::newRow( "T006:Tab - [Shift + Tab]" ) << int(TestAccel) << int(NoWidget) << QString("")
531         << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
532 
533     QTest::newRow( "T006 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
534 
535     //===========================================
536     // [Shift + key] and [key] on accels with
537     // and without modifiers
538     //===========================================
539 
540     /* Testing Single Sequences
541        int(Qt::Key_F1)
542        Shift + int(Qt::Key_F1)
543     */
544     QTest::newRow( "T007 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("F1")
545         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
546     QTest::newRow( "T007 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("Shift+F1")
547         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
548     QTest::newRow( "T007:F1" ) << int(TestAccel) << int(NoWidget) << QString("")
549         << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
550     QTest::newRow( "T007:Shift + F1" ) << int(TestAccel) << int(NoWidget) << QString("")
551         << int(Qt::SHIFT) + int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
552 
553     QTest::newRow( "T005 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
554 
555     /* Testing Single Sequences
556        int(Qt::Key_M)
557        Shift + int(Qt::Key_M)
558        Ctrl  + int(Qt::Key_M)
559        Alt   + int(Qt::Key_M)
560     */
561     QTest::newRow( "T01 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("M")
562         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
563     QTest::newRow( "T02 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("Shift+M")
564         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
565     QTest::newRow( "T03 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("Ctrl+M")
566         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
567     QTest::newRow( "T04 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("Alt+M")
568         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
569 
570 
571     QTest::newRow( "T:int(Qt::Key_M)" ) << int(TestAccel) << int(NoWidget) << QString("")
572         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
573     QTest::newRow( "T:Shift + int(Qt::Key_M)" ) << int(TestAccel) << int(NoWidget) << QString("")
574         << int(Qt::SHIFT) + int(Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
575     QTest::newRow( "T:Ctrl + int(Qt::Key_M)" ) << int(TestAccel) << int(NoWidget) << QString("")
576         << int(Qt::CTRL) + int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
577     QTest::newRow( "T:Alt + int(Qt::Key_M)" ) << int(TestAccel) << int(NoWidget) << QString("")
578         << int(Qt::ALT) + int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel2Triggered);
579 
580     /* Testing Single Sequence Ambiguity
581        int(Qt::Key_M) on accel2
582     */
583     QTest::newRow( "T05 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("M")
584         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
585     QTest::newRow( "T:int(Qt::Key_M) on int(Accel2)" ) << int(TestAccel) << int(NoWidget) << QString("")
586         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << int(Ambiguous);
587 
588     /* Testing Single Specialkeys
589        int(Qt::Key_aring)
590        int(Qt::Key_Aring)
591        UNICODE_ACCEL + int(Qt::Key_K)
592     */
593     /* see comments above on the #ifdef'ery */
594     QTest::newRow( "T06 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("\x0E5")
595         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
596     QTest::newRow( "T08 - sA2" ) << int(SetupAccel) << int(Accel1) << QString("K")
597         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
598 
599     QTest::newRow( "T:int(Qt::Key_aring)" ) << int(TestAccel) << int(NoWidget) << QString("")
600         << int(Qt::Key_aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
601     QTest::newRow( "T:int(Qt::Key_aring) - Text Form" ) << int(TestAccel) << int(NoWidget) << QString("")
602         << int(Qt::Key_unknown) << 0xE5 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
603     QTest::newRow( "T:int(Qt::Key_Aring) - Text Form" ) << int(TestAccel) << int(NoWidget) << QString("")
604         << int(Qt::Key_unknown) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
605     QTest::newRow( "T:UNICODE_ACCEL + int(Qt::Key_K)" ) << int(TestAccel) << int(NoWidget) << QString("")
606         << int(Qt::UNICODE_ACCEL) + int(Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
607 
608     // Clear all
609     QTest::newRow( "T09 - clear" ) << int(ClearAll) <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
610 
611     /* Testing Multiple Sequences
612        int(Qt::Key_M)
613        int(Qt::Key_I), int(Qt::Key_M)
614        Shift+int(Qt::Key_I), int(Qt::Key_M)
615     */
616     QTest::newRow( "T10 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("M")
617         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
618     QTest::newRow( "T11 - sA2" ) << int(SetupAccel) << int(Accel2) << QString("I, M")
619         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
620     QTest::newRow( "T12 - sA1" ) << int(SetupAccel) << int(Accel1) << QString("Shift+I, M")
621         << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << int(NoResult);
622 
623     QTest::newRow( "T:int(Qt::Key_M) (2)" ) << int(TestAccel) << int(NoWidget) << QString("")
624         << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << int(Accel1Triggered);
625     QTest::newRow( "T:int(Qt::Key_I), int(Qt::Key_M)" ) << int(TestAccel) << int(NoWidget) << QString("")
626         << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << int(Accel2Triggered);
627     QTest::newRow( "T:Shift+int(Qt::Key_I), int(Qt::Key_M)" ) << int(TestAccel) << int(NoWidget) << QString("")
628         << int(Qt::SHIFT) + int(Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << int(Accel1Triggered);
629 }
630 
631 // ------------------------------------------------------------------
632 // Disabled Elements ------------------------------------------------
633 // ------------------------------------------------------------------
disabledItems()634 void tst_Q3Accel::disabledItems()
635 {
636     accel1->setEnabled( TRUE );
637     accel2->setEnabled( TRUE );
638 
639     /* Testing Disabled Accel
640        Qt::Key_M          on A1
641        Shift + Qt::Key_M  on A1
642        Qt::Key_M          on A2 (disabled)
643        Shift + Qt::Key_M  on A2 (disabled)
644     */
645     accel1->clear();
646     accel2->clear();
647     accel1->insertItem( QKeySequence("M") );
648     accel1->insertItem( QKeySequence("Shift+M") );
649     accel2->insertItem( QKeySequence("M") );
650     accel2->insertItem( QKeySequence("Shift+M") );
651     accel2->setEnabled( FALSE );
652     currentResult = NoResult;
653     sendKeyEvents( Qt::Key_M, 'm' );
654     QCOMPARE( currentResult, Accel1Triggered );
655     currentResult = NoResult;
656     sendKeyEvents( Qt::SHIFT+Qt::Key_M, 'M' );
657     QCOMPARE( currentResult, Accel1Triggered );
658     accel2->setEnabled( TRUE ); //PS!
659 
660     /* Testing Disabled Accel
661        Qt::Key_M          on A1
662        Shift + Qt::Key_M  on A1 (disabled)
663        Qt::Key_M          on A2 (disabled)
664        Shift + Qt::Key_M  on A2
665     */
666     accel1->clear();
667     accel2->clear();
668     accel1->insertItem( QKeySequence("M") );
669     int i1 = accel1->insertItem( QKeySequence("Shift+M") );
670     int i2 = accel2->insertItem( QKeySequence("M") );
671     accel2->insertItem( QKeySequence("Shift+M") );
672     accel1->setItemEnabled( i1, FALSE );
673     accel2->setItemEnabled( i2, FALSE );
674     currentResult = NoResult;
675     sendKeyEvents( Qt::Key_M, 'm' );
676     QCOMPARE( currentResult, Accel1Triggered );
677     currentResult = NoResult;
678     sendKeyEvents( Qt::SHIFT+Qt::Key_M, 'M' );
679     QCOMPARE( currentResult, Accel2Triggered );
680 
681     /* Testing Disabled Accel Items
682        Qt::Key_F5          on A1
683        Shift + Qt::Key_F5  on A2 (disabled)
684     */
685     accel1->clear();
686     accel2->clear();
687     i1 = accel1->insertItem( QKeySequence("F5") );
688     i2 = accel2->insertItem( QKeySequence("Shift+F5") );
689     accel1->setItemEnabled( i1, TRUE );
690     accel2->setItemEnabled( i2, FALSE );
691     currentResult = NoResult;
692     sendKeyEvents( Qt::Key_F5, 0 );
693     QCOMPARE( currentResult, Accel1Triggered );
694     currentResult = NoResult;
695     sendKeyEvents( Qt::SHIFT+Qt::Key_F5, 0 );
696     QCOMPARE( currentResult, NoResult );
697 
698     /* Testing Disabled Accel
699        Qt::Key_F5          on A1
700        Shift + Qt::Key_F5  on A2 (disabled)
701     */
702     accel1->clear();
703     accel2->clear();
704     i1 = accel1->insertItem( QKeySequence("F5") );
705     i2 = accel2->insertItem( QKeySequence("Shift+F5") );
706     accel1->setEnabled( TRUE );
707     accel2->setEnabled( FALSE );
708     currentResult = NoResult;
709     sendKeyEvents( Qt::Key_F5, 0 );
710     QCOMPARE( currentResult, Accel1Triggered );
711     currentResult = NoResult;
712     sendKeyEvents( Qt::SHIFT+Qt::Key_F5, 0 );
713     QCOMPARE( currentResult, NoResult );
714 
715 
716 
717     /* Testing Disabled Accel, and the corresponding statusbar feedback
718        Ctrl + Qt::Key_K, Ctrl + Qt::Key_L on A1
719        Ctrl + Qt::Key_K, Ctrl + Qt::Key_M on A2 (disabled)
720     */
721     accel1->clear();
722     accel2->clear();
723     i1 = accel1->insertItem( QKeySequence("Ctrl+K, Ctrl+L") );
724     i2 = accel2->insertItem( QKeySequence("Ctrl+K, Ctrl+M") );
725     accel1->setItemEnabled( i1, TRUE );
726     accel2->setItemEnabled( i2, FALSE );
727     currentResult = NoResult;
728     sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 );
729     sendKeyEvents( Qt::CTRL+Qt::Key_Q, 0 );
730     QCOMPARE( currentResult, NoResult );
731 #ifndef Q_WS_MAC
732     QCOMPARE( sbText, QString("Ctrl+K, Ctrl+Q not defined") );
733 #else
734     QCOMPARE(sbText, MacCtrl + "K, " + MacCtrl + "Q not defined");
735 #endif
736     currentResult = NoResult;
737     sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 );
738     sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 );
739     QCOMPARE( currentResult, NoResult );
740     QCOMPARE(sbText, QString());
741     currentResult = NoResult;
742     sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 );
743     sendKeyEvents( Qt::CTRL+Qt::Key_L, 0 );
744     QCOMPARE( currentResult, Accel1Triggered );
745     QCOMPARE(sbText, QString());
746 
747     accel1->setEnabled( TRUE );
748     accel2->setEnabled( TRUE );
749 }
750 
751 // ------------------------------------------------------------------
752 // Ambiguous Elements -----------------------------------------------
753 // ------------------------------------------------------------------
ambiguousItems()754 void tst_Q3Accel::ambiguousItems()
755 {
756     accel1->setEnabled( TRUE );
757     accel2->setEnabled( TRUE );
758 
759     /* Testing Disabled Accel
760        Qt::Key_M  on A1
761        Qt::Key_M  on A2
762     */
763     accel1->clear();
764     accel2->clear();
765     accel1->insertItem( QKeySequence("M") );
766     accel2->insertItem( QKeySequence("M") );
767     currentResult = NoResult;
768     sendKeyEvents( Qt::Key_M, 'm' );
769     QCOMPARE( currentResult, Ambiguous );
770     QCOMPARE( ambigResult, Accel1Triggered );
771     currentResult = NoResult;
772     sendKeyEvents( Qt::Key_M, 'm' );
773     QCOMPARE( currentResult, Ambiguous );
774     QCOMPARE( ambigResult, Accel2Triggered );
775     currentResult = NoResult;
776     sendKeyEvents( Qt::Key_M, 'm' );
777     QCOMPARE( currentResult, Ambiguous );
778     QCOMPARE( ambigResult, Accel1Triggered );
779 
780     accel1->setEnabled( TRUE );
781     accel2->setEnabled( TRUE );
782 }
783 
784 // ------------------------------------------------------------------
785 // Unicode and non-unicode Elements ---------------------------------
786 // ------------------------------------------------------------------
unicodeCompare()787 void tst_Q3Accel::unicodeCompare()
788 {
789     accel1->setEnabled( TRUE );
790     accel2->setEnabled( TRUE );
791 
792     QKeySequence ks1("Ctrl+M");
793     QKeySequence ks2( Qt::CTRL+Qt::Key_M );
794     accel1->clear();
795     accel2->clear();
796     accel1->insertItem( ks1 );
797     accel2->insertItem( ks2 );
798     currentResult = NoResult;
799     sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 );
800     QCOMPARE( currentResult, Ambiguous );
801     // They _are_ ambiguous, so the QKeySequence operator==
802     // should indicate the same
803     QVERIFY( ks1 == ks2 );
804     QVERIFY( !(ks1 != ks2) );
805 }
806 
807 // ------------------------------------------------------------------
808 // Unicode composed keys using keypad, and number accels ------------
809 // ------------------------------------------------------------------
unicodeCompose()810 void tst_Q3Accel::unicodeCompose()
811 {
812     accel1->setEnabled( TRUE );
813     accel2->setEnabled( TRUE );
814 
815 #if 0
816 //#if QT_VERSION >= 0x30200
817     accel1->clear();
818     accel2->clear();
819     accel1->insertItem( META+Qt::Key_9 );
820     edit->setFocus();
821     currentResult = NoResult;
822 
823     // Turn on unicode composing, and
824     // compose a smileyface. ( 9786 = 0x263A )
825     QApplication::setMetaComposedUnicode();
826     QChar ch1( '9' );
827     QChar ch2( '7' );
828     QChar ch3( '8' );
829     QChar ch4( '6' );
830     QString s1( ch1 );
831     QString s2( ch2 );
832     QString s3( ch3 );
833     QString s4( ch4 );
834     QKeyEvent k1a( QEvent::AccelOverride, Qt::Key_9, ch1.row() ? 0 : ch1.cell(), Qt::MetaModifier + Qt::KeypadModifier, s1 );
835     QKeyEvent k1p( QEvent::KeyPress, Qt::Key_9, ch1.row() ? 0 : ch1.cell(), Qt::MetaModifier + Qt::KeypadModifier, s1 );
836     QKeyEvent k1r( QEvent::KeyRelease, Qt::Key_9, ch1.row() ? 0 : ch1.cell(), Qt::MetaModifier + Qt::KeypadModifier, s1 );
837     QKeyEvent k2a( QEvent::AccelOverride, Qt::Key_7, ch2.row() ? 0 : ch2.cell(), Qt::MetaModifier + Qt::KeypadModifier, s2 );
838     QKeyEvent k2p( QEvent::KeyPress, Qt::Key_7, ch2.row() ? 0 : ch2.cell(), Qt::MetaModifier + Qt::KeypadModifier, s2 );
839     QKeyEvent k2r( QEvent::KeyRelease, Qt::Key_7, ch2.row() ? 0 : ch2.cell(), Qt::MetaModifier + Qt::KeypadModifier, s2 );
840     QKeyEvent k3a( QEvent::AccelOverride, Qt::Key_8, ch3.row() ? 0 : ch3.cell(), Qt::MetaModifier + Qt::KeypadModifier, s3 );
841     QKeyEvent k3p( QEvent::KeyPress, Qt::Key_8, ch3.row() ? 0 : ch3.cell(), Qt::MetaModifier + Qt::KeypadModifier, s3 );
842     QKeyEvent k3r( QEvent::KeyRelease, Qt::Key_8, ch3.row() ? 0 : ch3.cell(), Qt::MetaModifier + Qt::KeypadModifier, s3 );
843     QKeyEvent k4a( QEvent::AccelOverride, Qt::Key_6, ch4.row() ? 0 : ch4.cell(), Qt::MetaModifier + Qt::KeypadModifier, s4 );
844     QKeyEvent k4p( QEvent::KeyPress, Qt::Key_6, ch4.row() ? 0 : ch4.cell(), Qt::MetaModifier + Qt::KeypadModifier, s4 );
845     QKeyEvent k4r( QEvent::KeyRelease, Qt::Key_6, ch4.row() ? 0 : ch4.cell(), Qt::MetaModifier + Qt::KeypadModifier, s4 );
846     QKeyEvent k5r( QEvent::KeyRelease, Qt::Key_Meta, 0, 0, "" );
847     QApplication::sendEvent( edit, &k1a );
848     QApplication::sendEvent( edit, &k1p );
849     QApplication::sendEvent( edit, &k1r );
850     QCOMPARE( currentResult, NoResult );
851 
852     QApplication::sendEvent( edit, &k2a );
853     QApplication::sendEvent( edit, &k2p );
854     QApplication::sendEvent( edit, &k2r );
855     QCOMPARE( currentResult, NoResult );
856 
857     QApplication::sendEvent( edit, &k3a );
858     QApplication::sendEvent( edit, &k3p );
859     QApplication::sendEvent( edit, &k3r );
860     QCOMPARE( currentResult, NoResult );
861 
862     QApplication::sendEvent( edit, &k4a );
863     QApplication::sendEvent( edit, &k4p );
864     QApplication::sendEvent( edit, &k4r );
865     QCOMPARE( currentResult, NoResult );
866 
867     QApplication::sendEvent( edit, &k5r );
868     // Unicode character is fully composed, and
869     // shouldn't have triggered any accels
870     QCOMPARE( currentResult, NoResult );
871 
872     // Verify that the unicode character indeed
873     // is composed
874     QVERIFY( edit->text().length() == 1 );
875     QCOMPARE( (int)edit->text()[0].unicode(), 9786 );
876 
877     sendKeyEvents( META+Qt::Key_9, 0 );
878     QCOMPARE( currentResult, Accel1Triggered );
879 #else
880     QSKIP( "Unicode composing non-existent in Qt 3.y.z", SkipAll);
881 #endif
882 }
883 
884 // ------------------------------------------------------------------
885 // Element Testing  -------------------------------------------------
886 // ------------------------------------------------------------------
testElement()887 void tst_Q3Accel::testElement()
888 {
889 #if 0
890     currentResult = NoResult;
891     QFETCH( int, theAction );
892     QFETCH( int, theTestWidget );
893     QFETCH( QString, theString );
894     QFETCH( int, the1Key );
895     QFETCH( int, the1Char );
896     QFETCH( int, the2Key );
897     QFETCH( int, the2Char );
898     QFETCH( int, the3Key );
899     QFETCH( int, the3Char );
900     QFETCH( int, the4Key );
901     QFETCH( int, the4Char );
902     QFETCH( int, theResult );
903 
904     Q3Accel *ac = 0;
905     switch( theTestWidget ) {
906     case Accel1:
907         ac = accel1;
908         break;
909     case Accel2:
910         ac = accel2;
911         break;
912     case NoWidget:
913     default:
914         ac = 0;
915     }
916 
917     if ( theAction == ClearAll ) {
918         // Clear all current accelerators
919         accel1->clear();
920         accel2->clear();
921         QCOMPARE( TRUE, TRUE );
922     } else if ( theAction == SetupAccel ) {
923         // Set up accelerator for next test
924         QKeySequence ks;
925         if ( QString(theString).isEmpty() ) {
926             ks =  QKeySequence( the1Key, the2Key, the3Key, the4Key );
927         } else {
928             ks = QKeySequence( theString );
929         }
930         ac->insertItem( ks );
931         QCOMPARE( TRUE, TRUE );
932     } else {
933         // Send keyevents
934         sendKeyEvents( the1Key, the1Char,
935                        the2Key, the2Char,
936                        the3Key, the3Char,
937                        the4Key, the4Char );
938         // Verify the result
939         QCOMPARE( currentResult, theResult );
940     }
941 #endif
942 }
943 
sendKeyEvents(int k1,QChar c1,int k2,QChar c2,int k3,QChar c3,int k4,QChar c4)944 void tst_Q3Accel::sendKeyEvents( int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4 )
945 {
946     int b1 = toButtons( k1 );
947     int b2 = toButtons( k2 );
948     int b3 = toButtons( k3 );
949     int b4 = toButtons( k4 );
950     k1 &= ~Qt::MODIFIER_MASK;
951     k2 &= ~Qt::MODIFIER_MASK;
952     k3 &= ~Qt::MODIFIER_MASK;
953     k4 &= ~Qt::MODIFIER_MASK;
954     QKeyEvent ke( QEvent::Accel, k1, (Qt::KeyboardModifiers)b1, QString(c1) );
955     QApplication::sendEvent( mainW, &ke );
956     if ( k2 ) {
957         QKeyEvent ke( QEvent::Accel, k2, k2, b2, QString(c2) );
958         QApplication::sendEvent( mainW, &ke );
959     }
960     if ( k3 ) {
961         QKeyEvent ke( QEvent::Accel, k3, k3, b3, QString(c3) );
962         QApplication::sendEvent( mainW, &ke );
963     }
964     if ( k4 ) {
965         QKeyEvent ke( QEvent::Accel, k4, k4, b4, QString(c4) );
966         QApplication::sendEvent( mainW, &ke );
967     }
968 }
969 
970 QTEST_MAIN(tst_Q3Accel)
971 #include "tst_q3accel.moc"
972