sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\window\t_keys.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: const TBool KEY_UP=ETrue; sl@0: const TBool KEY_DOWN=EFalse; sl@0: const TBool EXPECT_NO_KEY_PRESS=EFalse; sl@0: const TBool EXPECT_KEY_PRESS=ETrue; sl@0: sl@0: LOCAL_D RTest test(_L("T_KEYS")); sl@0: LOCAL_D CKeyTranslator *KeyTranslator; sl@0: LOCAL_D CCaptureKeys *CaptureKeys; sl@0: sl@0: LOCAL_C TBool testType() sl@0: // sl@0: // Determine whether the Func key sets Alt or Func modifier sl@0: // sl@0: { sl@0: TKeyData keyData; sl@0: TBool ret; sl@0: KeyTranslator->TranslateKey(EStdKeyLeftFunc,EFalse,*CaptureKeys,keyData); sl@0: ret=(keyData.iModifiers==(EModifierLeftFunc|EModifierFunc)); sl@0: KeyTranslator->TranslateKey(EStdKeyLeftFunc,ETrue,*CaptureKeys,keyData); sl@0: return(ret); sl@0: } sl@0: sl@0: LOCAL_C void testConv(const TDesC& aDes,TBool aKeyup,TBool aRet,TUint aScanCode,TUint aKeyCode,TInt aModifiers) sl@0: { sl@0: TKeyData keyData; sl@0: TBool ret=KeyTranslator->TranslateKey(aScanCode, aKeyup,*CaptureKeys,keyData); sl@0: test.Next(aDes); sl@0: test(ret==aRet); sl@0: test((keyData.iKeyCode==aKeyCode)); sl@0: test((keyData.iModifiers==aModifiers)); sl@0: } sl@0: sl@0: LOCAL_C void testCtrl(TInt aKeyCode) sl@0: // sl@0: // Test that prssing Ctrl-xyz returns ascii code xyz sl@0: // sl@0: { sl@0: sl@0: TBuf<16> down; sl@0: TBuf<16> up; sl@0: sl@0: TInt val[4]; sl@0: TInt ii=0; sl@0: TInt key=aKeyCode; sl@0: sl@0: while(key) sl@0: { sl@0: val[ii++]=key%10; sl@0: key/=10; sl@0: } sl@0: sl@0: testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl); sl@0: sl@0: TUint downModifiers=EModifierCtrl|EModifierLeftCtrl|EModifierPureKeycode; sl@0: TUint upModifiers=EModifierCtrl|EModifierLeftCtrl|EModifierKeyUp; sl@0: sl@0: while(ii--) sl@0: { sl@0: down.Format(_L("%d down"),val[ii]); sl@0: up.Format(_L("%d up"),val[ii]); sl@0: testConv(down,KEY_DOWN,EXPECT_NO_KEY_PRESS,val[ii]+'0',0,downModifiers); sl@0: testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,val[ii]+'0',0,upModifiers); sl@0: downModifiers&=~(EModifierPureKeycode); sl@0: } sl@0: sl@0: testConv(_L("Left control up"),KEY_UP,EXPECT_KEY_PRESS,EStdKeyLeftCtrl,aKeyCode,EModifierKeyUp|EModifierSpecial); sl@0: } sl@0: sl@0: /* sl@0: LOCAL_C void testAccents(TInt aNum,TInt aLetter,TInt aKeycode) sl@0: // sl@0: // Check accents by pressing Ctrl-n followed by a letter sl@0: // sl@0: { sl@0: sl@0: TBuf<16> down; sl@0: TBuf<16> up; sl@0: // sl@0: // Press the Ctrl key sl@0: // sl@0: testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl); sl@0: // sl@0: // While it's down, press the given number key... sl@0: // sl@0: down.Format(_L("%c down"),aNum); sl@0: testConv(down,KEY_DOWN,EXPECT_NO_KEY_PRESS,aNum,0,EModifierCtrl|EModifierLeftCtrl|EModifierPureKeycode); sl@0: // sl@0: // Release the number and Ctrl keys sl@0: // sl@0: up.Format(_L("%c up"),aNum); sl@0: testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,aNum,0,EModifierCtrl|EModifierLeftCtrl|EModifierKeyUp); sl@0: testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp); sl@0: // sl@0: // Press the letter key and check an accent is returned... sl@0: // sl@0: down.Format(_L("%c down"),aLetter); sl@0: up.Format(_L("%c up"),aLetter); sl@0: testConv(down,KEY_DOWN,EXPECT_KEY_PRESS,aLetter,aKeycode,EModifierSpecial); sl@0: testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,aLetter,0,EModifierKeyUp); sl@0: } sl@0: */ sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: // sl@0: // Test the keyboard translator sl@0: // sl@0: { sl@0: sl@0: test.Start(_L("Keyboard translator tests")); sl@0: sl@0: KeyTranslator=CKeyTranslator::New(); sl@0: CaptureKeys=new CCaptureKeys(); sl@0: sl@0: CaptureKeys->Construct(); sl@0: sl@0: TUint scancode=EStdKeyLeftArrow; sl@0: // sl@0: // Test that the special keys pass through and anything after sl@0: // or before raises an error sl@0: // sl@0: testConv(_L("First Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0); sl@0: testConv(_L("First Special key up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Last Sepcial key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount-1,ESpecialKeyBase+ESpecialKeyCount-1,0); sl@0: testConv(_L("Last Special key up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount-1,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Key before Special range down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,ESpecialKeyBase-1,0,0); sl@0: testConv(_L("Key before Special range up"),KEY_UP,EXPECT_NO_KEY_PRESS,0,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Key after Special range down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount,0,0); sl@0: testConv(_L("Key after Sepcial range up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount,0,EModifierKeyUp); sl@0: // sl@0: // Test a range of keys... sl@0: // sl@0: for(scancode='A';scancode<='Z';scancode++) sl@0: { sl@0: TBuf<16> buf; sl@0: sl@0: buf.Format(_L("Testing key %c"),scancode); sl@0: testConv(buf,KEY_DOWN,EXPECT_KEY_PRESS,scancode,'a'+scancode-'A',EModifierAutorepeatable); sl@0: testConv(buf,KEY_UP,EXPECT_NO_KEY_PRESS,scancode,0,EModifierKeyUp); sl@0: } sl@0: // sl@0: // Test shift and control modifiers sl@0: // sl@0: testConv(_L("Left shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierShift|EModifierLeftShift); sl@0: testConv(_L("Left shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Right shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierShift|EModifierRightShift); sl@0: testConv(_L("Right shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Left shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierShift|EModifierLeftShift); sl@0: testConv(_L("Right shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierShift|EModifierRightShift|EModifierLeftShift); sl@0: testConv(_L("Left shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierKeyUp|EModifierShift|EModifierRightShift); sl@0: testConv(_L("Right shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl); sl@0: testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp|EModifierPureKeycode); sl@0: sl@0: testConv(_L("Right control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierCtrl|EModifierRightCtrl); sl@0: testConv(_L("Right control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierKeyUp|EModifierPureKeycode); sl@0: sl@0: testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl); sl@0: testConv(_L("Right control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierCtrl|EModifierRightCtrl|EModifierLeftCtrl); sl@0: testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp|EModifierCtrl|EModifierRightCtrl|EModifierPureKeycode); sl@0: testConv(_L("Right control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierKeyUp|EModifierPureKeycode); sl@0: // sl@0: // Test function and alt keys - these are swapped on some platforms sl@0: // sl@0: if(testType()) sl@0: { sl@0: testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierFunc|EModifierLeftFunc); sl@0: testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierFunc|EModifierRightFunc); sl@0: testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierFunc|EModifierLeftFunc); sl@0: testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierFunc|EModifierRightFunc|EModifierLeftFunc); sl@0: testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp|EModifierFunc|EModifierRightFunc); sl@0: testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierAlt|EModifierLeftAlt); sl@0: testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierAlt|EModifierRightAlt); sl@0: testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierAlt|EModifierLeftAlt); sl@0: testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierAlt|EModifierRightAlt|EModifierLeftAlt); sl@0: testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp|EModifierAlt|EModifierRightAlt); sl@0: testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp); sl@0: } sl@0: else sl@0: { sl@0: testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierFunc|EModifierLeftFunc); sl@0: testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierFunc|EModifierRightFunc); sl@0: testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierFunc|EModifierLeftFunc); sl@0: testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierFunc|EModifierRightFunc|EModifierLeftFunc); sl@0: testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp|EModifierFunc|EModifierRightFunc); sl@0: testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierAlt|EModifierLeftAlt); sl@0: testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierAlt|EModifierRightAlt); sl@0: testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp); sl@0: sl@0: testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierAlt|EModifierLeftAlt); sl@0: testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierAlt|EModifierRightAlt|EModifierLeftAlt); sl@0: testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp|EModifierAlt|EModifierRightAlt); sl@0: testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp); sl@0: } sl@0: // sl@0: // Test control entering of ascii codes sl@0: // sl@0: testCtrl(123); sl@0: testCtrl(217); sl@0: testCtrl(53); sl@0: testCtrl(37); sl@0: sl@0: /* These accent tests are dependent upon the keyboard mapping being used. They need enhancing sl@0: so that they adjust according to the platform on which they are being run sl@0: sl@0: // sl@0: // Test that pressing Ctrl-1 followed by 'e' gives accents sl@0: // sl@0: testAccents('1','E',0xe6); sl@0: testAccents('2','E',0xea); sl@0: testAccents('3','E',0xe8); sl@0: testAccents('4','E',0xe9); sl@0: testAccents('5','A',0xe3); sl@0: testAccents('6','E',0xea); sl@0: sl@0: */ sl@0: test.End(); sl@0: return(KErrNone); sl@0: } sl@0: