os/kernelhwsrv/kerneltest/e32test/window/t_keys.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\window\t_keys.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <e32hal.h>
sl@0
    20
#include <e32twin.h>
sl@0
    21
#include <e32svr.h>
sl@0
    22
sl@0
    23
const TBool KEY_UP=ETrue;
sl@0
    24
const TBool KEY_DOWN=EFalse;
sl@0
    25
const TBool EXPECT_NO_KEY_PRESS=EFalse;
sl@0
    26
const TBool EXPECT_KEY_PRESS=ETrue;
sl@0
    27
sl@0
    28
LOCAL_D RTest test(_L("T_KEYS"));
sl@0
    29
LOCAL_D CKeyTranslator *KeyTranslator;
sl@0
    30
LOCAL_D CCaptureKeys *CaptureKeys;
sl@0
    31
sl@0
    32
LOCAL_C TBool testType()
sl@0
    33
//
sl@0
    34
// Determine whether the Func key sets Alt or Func modifier
sl@0
    35
//
sl@0
    36
    {
sl@0
    37
	TKeyData keyData;
sl@0
    38
    TBool ret;
sl@0
    39
    KeyTranslator->TranslateKey(EStdKeyLeftFunc,EFalse,*CaptureKeys,keyData);
sl@0
    40
    ret=(keyData.iModifiers==(EModifierLeftFunc|EModifierFunc));
sl@0
    41
    KeyTranslator->TranslateKey(EStdKeyLeftFunc,ETrue,*CaptureKeys,keyData);
sl@0
    42
    return(ret);
sl@0
    43
    }
sl@0
    44
sl@0
    45
LOCAL_C void testConv(const TDesC& aDes,TBool aKeyup,TBool aRet,TUint aScanCode,TUint aKeyCode,TInt aModifiers)
sl@0
    46
	{
sl@0
    47
	TKeyData keyData;
sl@0
    48
    TBool ret=KeyTranslator->TranslateKey(aScanCode, aKeyup,*CaptureKeys,keyData);
sl@0
    49
	test.Next(aDes);
sl@0
    50
	test(ret==aRet);
sl@0
    51
	test((keyData.iKeyCode==aKeyCode));
sl@0
    52
	test((keyData.iModifiers==aModifiers));
sl@0
    53
	}
sl@0
    54
sl@0
    55
LOCAL_C void testCtrl(TInt aKeyCode)
sl@0
    56
//
sl@0
    57
// Test that prssing Ctrl-xyz returns ascii code xyz
sl@0
    58
//
sl@0
    59
    {
sl@0
    60
sl@0
    61
    TBuf<16> down;
sl@0
    62
    TBuf<16> up;
sl@0
    63
sl@0
    64
    TInt val[4];
sl@0
    65
    TInt ii=0;
sl@0
    66
	TInt key=aKeyCode;
sl@0
    67
sl@0
    68
    while(key)
sl@0
    69
        {
sl@0
    70
        val[ii++]=key%10;
sl@0
    71
        key/=10;
sl@0
    72
        }
sl@0
    73
sl@0
    74
	testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
sl@0
    75
sl@0
    76
	TUint downModifiers=EModifierCtrl|EModifierLeftCtrl|EModifierPureKeycode;
sl@0
    77
	TUint upModifiers=EModifierCtrl|EModifierLeftCtrl|EModifierKeyUp;
sl@0
    78
sl@0
    79
    while(ii--)
sl@0
    80
        {
sl@0
    81
        down.Format(_L("%d down"),val[ii]);
sl@0
    82
        up.Format(_L("%d up"),val[ii]);
sl@0
    83
    	testConv(down,KEY_DOWN,EXPECT_NO_KEY_PRESS,val[ii]+'0',0,downModifiers);
sl@0
    84
    	testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,val[ii]+'0',0,upModifiers);
sl@0
    85
		downModifiers&=~(EModifierPureKeycode);
sl@0
    86
        }
sl@0
    87
sl@0
    88
	testConv(_L("Left control up"),KEY_UP,EXPECT_KEY_PRESS,EStdKeyLeftCtrl,aKeyCode,EModifierKeyUp|EModifierSpecial);
sl@0
    89
    }
sl@0
    90
sl@0
    91
/*
sl@0
    92
LOCAL_C void testAccents(TInt aNum,TInt aLetter,TInt aKeycode)
sl@0
    93
//
sl@0
    94
// Check accents by pressing Ctrl-n followed by a letter
sl@0
    95
//
sl@0
    96
	{
sl@0
    97
sl@0
    98
	TBuf<16> down;
sl@0
    99
	TBuf<16> up;
sl@0
   100
//
sl@0
   101
// Press the Ctrl key
sl@0
   102
//
sl@0
   103
	testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
sl@0
   104
//
sl@0
   105
// While it's down, press the given number key...
sl@0
   106
//
sl@0
   107
    down.Format(_L("%c down"),aNum);
sl@0
   108
   	testConv(down,KEY_DOWN,EXPECT_NO_KEY_PRESS,aNum,0,EModifierCtrl|EModifierLeftCtrl|EModifierPureKeycode);
sl@0
   109
//
sl@0
   110
// Release the number and Ctrl keys
sl@0
   111
//
sl@0
   112
    up.Format(_L("%c up"),aNum);
sl@0
   113
   	testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,aNum,0,EModifierCtrl|EModifierLeftCtrl|EModifierKeyUp);
sl@0
   114
	testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp);
sl@0
   115
//
sl@0
   116
// Press the letter key and check an accent is returned...
sl@0
   117
//
sl@0
   118
    down.Format(_L("%c down"),aLetter);
sl@0
   119
    up.Format(_L("%c up"),aLetter);
sl@0
   120
   	testConv(down,KEY_DOWN,EXPECT_KEY_PRESS,aLetter,aKeycode,EModifierSpecial);
sl@0
   121
   	testConv(up,KEY_UP,EXPECT_NO_KEY_PRESS,aLetter,0,EModifierKeyUp);
sl@0
   122
	}
sl@0
   123
*/
sl@0
   124
sl@0
   125
GLDEF_C TInt E32Main()
sl@0
   126
//
sl@0
   127
// Test the keyboard translator
sl@0
   128
//
sl@0
   129
    {
sl@0
   130
sl@0
   131
    test.Start(_L("Keyboard translator tests"));
sl@0
   132
sl@0
   133
    KeyTranslator=CKeyTranslator::New();
sl@0
   134
    CaptureKeys=new CCaptureKeys();
sl@0
   135
sl@0
   136
	CaptureKeys->Construct();
sl@0
   137
sl@0
   138
    TUint scancode=EStdKeyLeftArrow;
sl@0
   139
//
sl@0
   140
// Test that the special keys pass through and anything after
sl@0
   141
// or before raises an error
sl@0
   142
//
sl@0
   143
	testConv(_L("First Special key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase,ESpecialKeyBase,0);
sl@0
   144
	testConv(_L("First Special key up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase,0,EModifierKeyUp);
sl@0
   145
sl@0
   146
	testConv(_L("Last Sepcial key down"),KEY_DOWN,EXPECT_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount-1,ESpecialKeyBase+ESpecialKeyCount-1,0);
sl@0
   147
	testConv(_L("Last Special key up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount-1,0,EModifierKeyUp);
sl@0
   148
sl@0
   149
	testConv(_L("Key before Special range down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,ESpecialKeyBase-1,0,0);
sl@0
   150
	testConv(_L("Key before Special range up"),KEY_UP,EXPECT_NO_KEY_PRESS,0,0,EModifierKeyUp);
sl@0
   151
sl@0
   152
	testConv(_L("Key after Special range down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount,0,0);
sl@0
   153
	testConv(_L("Key after Sepcial range up"),KEY_UP,EXPECT_NO_KEY_PRESS,ESpecialKeyBase+ESpecialKeyCount,0,EModifierKeyUp);
sl@0
   154
//
sl@0
   155
// Test a range of keys...
sl@0
   156
//
sl@0
   157
	for(scancode='A';scancode<='Z';scancode++)
sl@0
   158
		{
sl@0
   159
		TBuf<16> buf;
sl@0
   160
sl@0
   161
		buf.Format(_L("Testing key %c"),scancode);
sl@0
   162
		testConv(buf,KEY_DOWN,EXPECT_KEY_PRESS,scancode,'a'+scancode-'A',EModifierAutorepeatable);
sl@0
   163
		testConv(buf,KEY_UP,EXPECT_NO_KEY_PRESS,scancode,0,EModifierKeyUp);
sl@0
   164
		}
sl@0
   165
//
sl@0
   166
// Test shift and control modifiers
sl@0
   167
//
sl@0
   168
	testConv(_L("Left shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierShift|EModifierLeftShift);
sl@0
   169
	testConv(_L("Left shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierKeyUp);
sl@0
   170
sl@0
   171
	testConv(_L("Right shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierShift|EModifierRightShift);
sl@0
   172
	testConv(_L("Right shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierKeyUp);
sl@0
   173
sl@0
   174
	testConv(_L("Left shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierShift|EModifierLeftShift);
sl@0
   175
	testConv(_L("Right shift down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierShift|EModifierRightShift|EModifierLeftShift);
sl@0
   176
	testConv(_L("Left shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftShift,0,EModifierKeyUp|EModifierShift|EModifierRightShift);
sl@0
   177
	testConv(_L("Right shift up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightShift,0,EModifierKeyUp);
sl@0
   178
sl@0
   179
	testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
sl@0
   180
	testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp|EModifierPureKeycode);
sl@0
   181
sl@0
   182
	testConv(_L("Right control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierCtrl|EModifierRightCtrl);
sl@0
   183
	testConv(_L("Right control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierKeyUp|EModifierPureKeycode);
sl@0
   184
sl@0
   185
	testConv(_L("Left control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl);
sl@0
   186
	testConv(_L("Right control down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierCtrl|EModifierRightCtrl|EModifierLeftCtrl);
sl@0
   187
	testConv(_L("Left control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftCtrl,0,EModifierKeyUp|EModifierCtrl|EModifierRightCtrl|EModifierPureKeycode);
sl@0
   188
	testConv(_L("Right control up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightCtrl,0,EModifierKeyUp|EModifierPureKeycode);
sl@0
   189
//
sl@0
   190
// Test function and alt keys - these are swapped on some platforms
sl@0
   191
//
sl@0
   192
    if(testType())
sl@0
   193
        {
sl@0
   194
    	testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierFunc|EModifierLeftFunc);
sl@0
   195
    	testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp);
sl@0
   196
sl@0
   197
    	testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierFunc|EModifierRightFunc);
sl@0
   198
    	testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
sl@0
   199
sl@0
   200
    	testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierFunc|EModifierLeftFunc);
sl@0
   201
    	testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierFunc|EModifierRightFunc|EModifierLeftFunc);
sl@0
   202
    	testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp|EModifierFunc|EModifierRightFunc);
sl@0
   203
    	testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
sl@0
   204
sl@0
   205
    	testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierAlt|EModifierLeftAlt);
sl@0
   206
    	testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp);
sl@0
   207
sl@0
   208
    	testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierAlt|EModifierRightAlt);
sl@0
   209
    	testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
sl@0
   210
sl@0
   211
    	testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierAlt|EModifierLeftAlt);
sl@0
   212
    	testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierAlt|EModifierRightAlt|EModifierLeftAlt);
sl@0
   213
    	testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp|EModifierAlt|EModifierRightAlt);
sl@0
   214
    	testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
sl@0
   215
        }
sl@0
   216
    else
sl@0
   217
        {
sl@0
   218
    	testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierFunc|EModifierLeftFunc);
sl@0
   219
    	testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp);
sl@0
   220
sl@0
   221
    	testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierFunc|EModifierRightFunc);
sl@0
   222
    	testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
sl@0
   223
sl@0
   224
    	testConv(_L("Left func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierFunc|EModifierLeftFunc);
sl@0
   225
    	testConv(_L("Right func down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierFunc|EModifierRightFunc|EModifierLeftFunc);
sl@0
   226
    	testConv(_L("Left func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftAlt,0,EModifierKeyUp|EModifierFunc|EModifierRightFunc);
sl@0
   227
	    testConv(_L("Right func up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightAlt,0,EModifierKeyUp);
sl@0
   228
sl@0
   229
    	testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierAlt|EModifierLeftAlt);
sl@0
   230
    	testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp);
sl@0
   231
sl@0
   232
    	testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierAlt|EModifierRightAlt);
sl@0
   233
    	testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
sl@0
   234
sl@0
   235
    	testConv(_L("Left alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierAlt|EModifierLeftAlt);
sl@0
   236
    	testConv(_L("Right alt down"),KEY_DOWN,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierAlt|EModifierRightAlt|EModifierLeftAlt);
sl@0
   237
    	testConv(_L("Left alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyLeftFunc,0,EModifierKeyUp|EModifierAlt|EModifierRightAlt);
sl@0
   238
    	testConv(_L("Right alt up"),KEY_UP,EXPECT_NO_KEY_PRESS,EStdKeyRightFunc,0,EModifierKeyUp);
sl@0
   239
        }
sl@0
   240
//
sl@0
   241
// Test control entering of ascii codes
sl@0
   242
//
sl@0
   243
    testCtrl(123);
sl@0
   244
    testCtrl(217);
sl@0
   245
    testCtrl(53);
sl@0
   246
    testCtrl(37);
sl@0
   247
sl@0
   248
/* These accent tests are dependent upon the keyboard mapping being used. They need enhancing
sl@0
   249
   so that they adjust according to the platform on which they are being run
sl@0
   250
sl@0
   251
//
sl@0
   252
// Test that pressing Ctrl-1 followed by 'e' gives accents
sl@0
   253
//
sl@0
   254
	testAccents('1','E',0xe6);
sl@0
   255
	testAccents('2','E',0xea);
sl@0
   256
	testAccents('3','E',0xe8);
sl@0
   257
	testAccents('4','E',0xe9);
sl@0
   258
	testAccents('5','A',0xe3);
sl@0
   259
	testAccents('6','E',0xea);
sl@0
   260
sl@0
   261
*/
sl@0
   262
	test.End();
sl@0
   263
	return(KErrNone);
sl@0
   264
    }
sl@0
   265