Update contrib.
1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\window\t_keys.cpp
23 const TBool KEY_UP=ETrue;
24 const TBool KEY_DOWN=EFalse;
25 const TBool EXPECT_NO_KEY_PRESS=EFalse;
26 const TBool EXPECT_KEY_PRESS=ETrue;
28 LOCAL_D RTest test(_L("T_KEYS"));
29 LOCAL_D CKeyTranslator *KeyTranslator;
30 LOCAL_D CCaptureKeys *CaptureKeys;
32 LOCAL_C TBool testType()
34 // Determine whether the Func key sets Alt or Func modifier
39 KeyTranslator->TranslateKey(EStdKeyLeftFunc,EFalse,*CaptureKeys,keyData);
40 ret=(keyData.iModifiers==(EModifierLeftFunc|EModifierFunc));
41 KeyTranslator->TranslateKey(EStdKeyLeftFunc,ETrue,*CaptureKeys,keyData);
45 LOCAL_C void testConv(const TDesC& aDes,TBool aKeyup,TBool aRet,TUint aScanCode,TUint aKeyCode,TInt aModifiers)
48 TBool ret=KeyTranslator->TranslateKey(aScanCode, aKeyup,*CaptureKeys,keyData);
51 test((keyData.iKeyCode==aKeyCode));
52 test((keyData.iModifiers==aModifiers));
55 LOCAL_C void testCtrl(TInt aKeyCode)
57 // Test that prssing Ctrl-xyz returns ascii code xyz
74 testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
76 TUint downModifiers=EModifierCtrl|EModifierLeftCtrl|EModifierPureKeycode;
77 TUint upModifiers=EModifierCtrl|EModifierLeftCtrl|EModifierKeyUp;
81 down.Format(_L("%d down"),val[ii]);
82 up.Format(_L("%d up"),val[ii]);
83 testConv(down,KEY_DOWN,EXPECT_NO_KEY_PRESS,val[ii]+'0',0,downModifiers);
84 testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,val[ii]+'0',0,upModifiers);
85 downModifiers&=~(EModifierPureKeycode);
88 testConv(_L("Left control up"),KEY_UP,EXPECT_KEY_PRESS,EStdKeyLeftCtrl,aKeyCode,EModifierKeyUp|EModifierSpecial);
92 LOCAL_C void testAccents(TInt aNum,TInt aLetter,TInt aKeycode)
94 // Check accents by pressing Ctrl-n followed by a letter
101 // Press the Ctrl key
103 testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
105 // While it's down, press the given number key...
107 down.Format(_L("%c down"),aNum);
108 testConv(down,KEY_DOWN,EXPECT_NO_KEY_PRESS,aNum,0,EModifierCtrl|EModifierLeftCtrl|EModifierPureKeycode);
110 // Release the number and Ctrl keys
112 up.Format(_L("%c up"),aNum);
113 testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,aNum,0,EModifierCtrl|EModifierLeftCtrl|EModifierKeyUp);
114 testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp);
116 // Press the letter key and check an accent is returned...
118 down.Format(_L("%c down"),aLetter);
119 up.Format(_L("%c up"),aLetter);
120 testConv(down,KEY_DOWN,EXPECT_KEY_PRESS,aLetter,aKeycode,EModifierSpecial);
121 testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,aLetter,0,EModifierKeyUp);
125 GLDEF_C TInt E32Main()
127 // Test the keyboard translator
131 test.Start(_L("Keyboard translator tests"));
133 KeyTranslator=CKeyTranslator::New();
134 CaptureKeys=new CCaptureKeys();
136 CaptureKeys->Construct();
138 TUint scancode=EStdKeyLeftArrow;
140 // Test that the special keys pass through and anything after
141 // or before raises an error
143 testConv(_L("First Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0);
144 testConv(_L("First Special key up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase,0,EModifierKeyUp);
146 testConv(_L("Last Sepcial key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount-1,ESpecialKeyBase+ESpecialKeyCount-1,0);
147 testConv(_L("Last Special key up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount-1,0,EModifierKeyUp);
149 testConv(_L("Key before Special range down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,ESpecialKeyBase-1,0,0);
150 testConv(_L("Key before Special range up"),KEY_UP,EXPECT_NO_KEY_PRESS,0,0,EModifierKeyUp);
152 testConv(_L("Key after Special range down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount,0,0);
153 testConv(_L("Key after Sepcial range up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount,0,EModifierKeyUp);
155 // Test a range of keys...
157 for(scancode='A';scancode<='Z';scancode++)
161 buf.Format(_L("Testing key %c"),scancode);
162 testConv(buf,KEY_DOWN,EXPECT_KEY_PRESS,scancode,'a'+scancode-'A',EModifierAutorepeatable);
163 testConv(buf,KEY_UP,EXPECT_NO_KEY_PRESS,scancode,0,EModifierKeyUp);
166 // Test shift and control modifiers
168 testConv(_L("Left shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierShift|EModifierLeftShift);
169 testConv(_L("Left shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierKeyUp);
171 testConv(_L("Right shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierShift|EModifierRightShift);
172 testConv(_L("Right shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierKeyUp);
174 testConv(_L("Left shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierShift|EModifierLeftShift);
175 testConv(_L("Right shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierShift|EModifierRightShift|EModifierLeftShift);
176 testConv(_L("Left shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierKeyUp|EModifierShift|EModifierRightShift);
177 testConv(_L("Right shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierKeyUp);
179 testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
180 testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp|EModifierPureKeycode);
182 testConv(_L("Right control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierCtrl|EModifierRightCtrl);
183 testConv(_L("Right control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierKeyUp|EModifierPureKeycode);
185 testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
186 testConv(_L("Right control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierCtrl|EModifierRightCtrl|EModifierLeftCtrl);
187 testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp|EModifierCtrl|EModifierRightCtrl|EModifierPureKeycode);
188 testConv(_L("Right control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierKeyUp|EModifierPureKeycode);
190 // Test function and alt keys - these are swapped on some platforms
194 testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierFunc|EModifierLeftFunc);
195 testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp);
197 testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierFunc|EModifierRightFunc);
198 testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
200 testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierFunc|EModifierLeftFunc);
201 testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierFunc|EModifierRightFunc|EModifierLeftFunc);
202 testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp|EModifierFunc|EModifierRightFunc);
203 testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
205 testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierAlt|EModifierLeftAlt);
206 testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp);
208 testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierAlt|EModifierRightAlt);
209 testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
211 testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierAlt|EModifierLeftAlt);
212 testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierAlt|EModifierRightAlt|EModifierLeftAlt);
213 testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp|EModifierAlt|EModifierRightAlt);
214 testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
218 testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierFunc|EModifierLeftFunc);
219 testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp);
221 testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierFunc|EModifierRightFunc);
222 testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
224 testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierFunc|EModifierLeftFunc);
225 testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierFunc|EModifierRightFunc|EModifierLeftFunc);
226 testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp|EModifierFunc|EModifierRightFunc);
227 testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
229 testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierAlt|EModifierLeftAlt);
230 testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp);
232 testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierAlt|EModifierRightAlt);
233 testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
235 testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierAlt|EModifierLeftAlt);
236 testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierAlt|EModifierRightAlt|EModifierLeftAlt);
237 testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp|EModifierAlt|EModifierRightAlt);
238 testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
241 // Test control entering of ascii codes
248 /* These accent tests are dependent upon the keyboard mapping being used. They need enhancing
249 so that they adjust according to the platform on which they are being run
252 // Test that pressing Ctrl-1 followed by 'e' gives accents
254 testAccents('1','E',0xe6);
255 testAccents('2','E',0xea);
256 testAccents('3','E',0xe8);
257 testAccents('4','E',0xe9);
258 testAccents('5','A',0xe3);
259 testAccents('6','E',0xea);