1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/window/t_keys.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,265 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\window\t_keys.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32test.h>
1.22 +#include <e32hal.h>
1.23 +#include <e32twin.h>
1.24 +#include <e32svr.h>
1.25 +
1.26 +const TBool KEY_UP=ETrue;
1.27 +const TBool KEY_DOWN=EFalse;
1.28 +const TBool EXPECT_NO_KEY_PRESS=EFalse;
1.29 +const TBool EXPECT_KEY_PRESS=ETrue;
1.30 +
1.31 +LOCAL_D RTest test(_L("T_KEYS"));
1.32 +LOCAL_D CKeyTranslator *KeyTranslator;
1.33 +LOCAL_D CCaptureKeys *CaptureKeys;
1.34 +
1.35 +LOCAL_C TBool testType()
1.36 +//
1.37 +// Determine whether the Func key sets Alt or Func modifier
1.38 +//
1.39 + {
1.40 + TKeyData keyData;
1.41 + TBool ret;
1.42 + KeyTranslator->TranslateKey(EStdKeyLeftFunc,EFalse,*CaptureKeys,keyData);
1.43 + ret=(keyData.iModifiers==(EModifierLeftFunc|EModifierFunc));
1.44 + KeyTranslator->TranslateKey(EStdKeyLeftFunc,ETrue,*CaptureKeys,keyData);
1.45 + return(ret);
1.46 + }
1.47 +
1.48 +LOCAL_C void testConv(const TDesC& aDes,TBool aKeyup,TBool aRet,TUint aScanCode,TUint aKeyCode,TInt aModifiers)
1.49 + {
1.50 + TKeyData keyData;
1.51 + TBool ret=KeyTranslator->TranslateKey(aScanCode, aKeyup,*CaptureKeys,keyData);
1.52 + test.Next(aDes);
1.53 + test(ret==aRet);
1.54 + test((keyData.iKeyCode==aKeyCode));
1.55 + test((keyData.iModifiers==aModifiers));
1.56 + }
1.57 +
1.58 +LOCAL_C void testCtrl(TInt aKeyCode)
1.59 +//
1.60 +// Test that prssing Ctrl-xyz returns ascii code xyz
1.61 +//
1.62 + {
1.63 +
1.64 + TBuf<16> down;
1.65 + TBuf<16> up;
1.66 +
1.67 + TInt val[4];
1.68 + TInt ii=0;
1.69 + TInt key=aKeyCode;
1.70 +
1.71 + while(key)
1.72 + {
1.73 + val[ii++]=key%10;
1.74 + key/=10;
1.75 + }
1.76 +
1.77 + testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
1.78 +
1.79 + TUint downModifiers=EModifierCtrl|EModifierLeftCtrl|EModifierPureKeycode;
1.80 + TUint upModifiers=EModifierCtrl|EModifierLeftCtrl|EModifierKeyUp;
1.81 +
1.82 + while(ii--)
1.83 + {
1.84 + down.Format(_L("%d down"),val[ii]);
1.85 + up.Format(_L("%d up"),val[ii]);
1.86 + testConv(down,KEY_DOWN,EXPECT_NO_KEY_PRESS,val[ii]+'0',0,downModifiers);
1.87 + testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,val[ii]+'0',0,upModifiers);
1.88 + downModifiers&=~(EModifierPureKeycode);
1.89 + }
1.90 +
1.91 + testConv(_L("Left control up"),KEY_UP,EXPECT_KEY_PRESS,EStdKeyLeftCtrl,aKeyCode,EModifierKeyUp|EModifierSpecial);
1.92 + }
1.93 +
1.94 +/*
1.95 +LOCAL_C void testAccents(TInt aNum,TInt aLetter,TInt aKeycode)
1.96 +//
1.97 +// Check accents by pressing Ctrl-n followed by a letter
1.98 +//
1.99 + {
1.100 +
1.101 + TBuf<16> down;
1.102 + TBuf<16> up;
1.103 +//
1.104 +// Press the Ctrl key
1.105 +//
1.106 + testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
1.107 +//
1.108 +// While it's down, press the given number key...
1.109 +//
1.110 + down.Format(_L("%c down"),aNum);
1.111 + testConv(down,KEY_DOWN,EXPECT_NO_KEY_PRESS,aNum,0,EModifierCtrl|EModifierLeftCtrl|EModifierPureKeycode);
1.112 +//
1.113 +// Release the number and Ctrl keys
1.114 +//
1.115 + up.Format(_L("%c up"),aNum);
1.116 + testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,aNum,0,EModifierCtrl|EModifierLeftCtrl|EModifierKeyUp);
1.117 + testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp);
1.118 +//
1.119 +// Press the letter key and check an accent is returned...
1.120 +//
1.121 + down.Format(_L("%c down"),aLetter);
1.122 + up.Format(_L("%c up"),aLetter);
1.123 + testConv(down,KEY_DOWN,EXPECT_KEY_PRESS,aLetter,aKeycode,EModifierSpecial);
1.124 + testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,aLetter,0,EModifierKeyUp);
1.125 + }
1.126 +*/
1.127 +
1.128 +GLDEF_C TInt E32Main()
1.129 +//
1.130 +// Test the keyboard translator
1.131 +//
1.132 + {
1.133 +
1.134 + test.Start(_L("Keyboard translator tests"));
1.135 +
1.136 + KeyTranslator=CKeyTranslator::New();
1.137 + CaptureKeys=new CCaptureKeys();
1.138 +
1.139 + CaptureKeys->Construct();
1.140 +
1.141 + TUint scancode=EStdKeyLeftArrow;
1.142 +//
1.143 +// Test that the special keys pass through and anything after
1.144 +// or before raises an error
1.145 +//
1.146 + testConv(_L("First Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0);
1.147 + testConv(_L("First Special key up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase,0,EModifierKeyUp);
1.148 +
1.149 + testConv(_L("Last Sepcial key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount-1,ESpecialKeyBase+ESpecialKeyCount-1,0);
1.150 + testConv(_L("Last Special key up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount-1,0,EModifierKeyUp);
1.151 +
1.152 + testConv(_L("Key before Special range down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,ESpecialKeyBase-1,0,0);
1.153 + testConv(_L("Key before Special range up"),KEY_UP,EXPECT_NO_KEY_PRESS,0,0,EModifierKeyUp);
1.154 +
1.155 + testConv(_L("Key after Special range down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount,0,0);
1.156 + testConv(_L("Key after Sepcial range up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount,0,EModifierKeyUp);
1.157 +//
1.158 +// Test a range of keys...
1.159 +//
1.160 + for(scancode='A';scancode<='Z';scancode++)
1.161 + {
1.162 + TBuf<16> buf;
1.163 +
1.164 + buf.Format(_L("Testing key %c"),scancode);
1.165 + testConv(buf,KEY_DOWN,EXPECT_KEY_PRESS,scancode,'a'+scancode-'A',EModifierAutorepeatable);
1.166 + testConv(buf,KEY_UP,EXPECT_NO_KEY_PRESS,scancode,0,EModifierKeyUp);
1.167 + }
1.168 +//
1.169 +// Test shift and control modifiers
1.170 +//
1.171 + testConv(_L("Left shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierShift|EModifierLeftShift);
1.172 + testConv(_L("Left shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierKeyUp);
1.173 +
1.174 + testConv(_L("Right shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierShift|EModifierRightShift);
1.175 + testConv(_L("Right shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierKeyUp);
1.176 +
1.177 + testConv(_L("Left shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierShift|EModifierLeftShift);
1.178 + testConv(_L("Right shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierShift|EModifierRightShift|EModifierLeftShift);
1.179 + testConv(_L("Left shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierKeyUp|EModifierShift|EModifierRightShift);
1.180 + testConv(_L("Right shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierKeyUp);
1.181 +
1.182 + testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
1.183 + testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp|EModifierPureKeycode);
1.184 +
1.185 + testConv(_L("Right control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierCtrl|EModifierRightCtrl);
1.186 + testConv(_L("Right control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierKeyUp|EModifierPureKeycode);
1.187 +
1.188 + testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
1.189 + testConv(_L("Right control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierCtrl|EModifierRightCtrl|EModifierLeftCtrl);
1.190 + testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp|EModifierCtrl|EModifierRightCtrl|EModifierPureKeycode);
1.191 + testConv(_L("Right control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierKeyUp|EModifierPureKeycode);
1.192 +//
1.193 +// Test function and alt keys - these are swapped on some platforms
1.194 +//
1.195 + if(testType())
1.196 + {
1.197 + testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierFunc|EModifierLeftFunc);
1.198 + testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp);
1.199 +
1.200 + testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierFunc|EModifierRightFunc);
1.201 + testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
1.202 +
1.203 + testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierFunc|EModifierLeftFunc);
1.204 + testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierFunc|EModifierRightFunc|EModifierLeftFunc);
1.205 + testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp|EModifierFunc|EModifierRightFunc);
1.206 + testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
1.207 +
1.208 + testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierAlt|EModifierLeftAlt);
1.209 + testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp);
1.210 +
1.211 + testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierAlt|EModifierRightAlt);
1.212 + testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
1.213 +
1.214 + testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierAlt|EModifierLeftAlt);
1.215 + testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierAlt|EModifierRightAlt|EModifierLeftAlt);
1.216 + testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp|EModifierAlt|EModifierRightAlt);
1.217 + testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
1.218 + }
1.219 + else
1.220 + {
1.221 + testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierFunc|EModifierLeftFunc);
1.222 + testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp);
1.223 +
1.224 + testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierFunc|EModifierRightFunc);
1.225 + testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
1.226 +
1.227 + testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierFunc|EModifierLeftFunc);
1.228 + testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierFunc|EModifierRightFunc|EModifierLeftFunc);
1.229 + testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp|EModifierFunc|EModifierRightFunc);
1.230 + testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
1.231 +
1.232 + testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierAlt|EModifierLeftAlt);
1.233 + testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp);
1.234 +
1.235 + testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierAlt|EModifierRightAlt);
1.236 + testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
1.237 +
1.238 + testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierAlt|EModifierLeftAlt);
1.239 + testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierAlt|EModifierRightAlt|EModifierLeftAlt);
1.240 + testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp|EModifierAlt|EModifierRightAlt);
1.241 + testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
1.242 + }
1.243 +//
1.244 +// Test control entering of ascii codes
1.245 +//
1.246 + testCtrl(123);
1.247 + testCtrl(217);
1.248 + testCtrl(53);
1.249 + testCtrl(37);
1.250 +
1.251 +/* These accent tests are dependent upon the keyboard mapping being used. They need enhancing
1.252 + so that they adjust according to the platform on which they are being run
1.253 +
1.254 +//
1.255 +// Test that pressing Ctrl-1 followed by 'e' gives accents
1.256 +//
1.257 + testAccents('1','E',0xe6);
1.258 + testAccents('2','E',0xea);
1.259 + testAccents('3','E',0xe8);
1.260 + testAccents('4','E',0xe9);
1.261 + testAccents('5','A',0xe3);
1.262 + testAccents('6','E',0xea);
1.263 +
1.264 +*/
1.265 + test.End();
1.266 + return(KErrNone);
1.267 + }
1.268 +