os/graphics/windowing/windowserver/test/tman/TMCAPKEY.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-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 "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
// Test capture key
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <e32svr.h>
sl@0
    20
#include <e32keys.h>
sl@0
    21
#include "W32STD.H"
sl@0
    22
#include "../tlib/testbase.h"
sl@0
    23
#include "TMAN.H"
sl@0
    24
sl@0
    25
enum TTestMode
sl@0
    26
	{
sl@0
    27
	EModeNormalCapture,
sl@0
    28
	EModeWaitingForFirstDown,
sl@0
    29
	EModeKeyUpsAndDowns,
sl@0
    30
	EModeAbortKeys,
sl@0
    31
	};
sl@0
    32
enum TCapKeyRetValues
sl@0
    33
	{
sl@0
    34
	ECapKeyOkay,
sl@0
    35
	ECapKeyRetry,
sl@0
    36
	ECapKeyFail,
sl@0
    37
	};
sl@0
    38
sl@0
    39
struct SCapKeyParams
sl@0
    40
	{
sl@0
    41
	TInt connIndex;		// Connection that should capture this key
sl@0
    42
	TUint keyCode;
sl@0
    43
	TUint modifier_mask;
sl@0
    44
	TUint modifiers;
sl@0
    45
	};
sl@0
    46
sl@0
    47
struct SCapKeyTestParams
sl@0
    48
	{
sl@0
    49
	TText *txt;			// Text message telling user what to do
sl@0
    50
	TInt connIndex;		// Connection that receive the key press
sl@0
    51
	TUint keyCode;		// Expected key code
sl@0
    52
	TUint modifier_mask;// Modifiers mask for expected modifiers
sl@0
    53
	TUint modifiers;	// Expected modifiers
sl@0
    54
	};
sl@0
    55
sl@0
    56
struct SAbortKeyTests
sl@0
    57
	{
sl@0
    58
	TUint keyCode;		// Expected key code
sl@0
    59
	TUint modifier_mask;// Modifiers mask for expected modifiers
sl@0
    60
	TUint modifiers;	// Expected modifiers
sl@0
    61
	};
sl@0
    62
sl@0
    63
LOCAL_D SCapKeyParams capKeys[]={
sl@0
    64
	{1,19,EModifierFunc|EModifierCtrl,EModifierFunc|EModifierCtrl},
sl@0
    65
	{2,'b',EModifierFunc|EModifierCtrl,EModifierFunc},
sl@0
    66
	{2,'n',EModifierFunc|EModifierCtrl,EModifierFunc},
sl@0
    67
	{0,3,EModifierFunc|EModifierCtrl,EModifierFunc|EModifierCtrl},
sl@0
    68
	{2,'q',0,0},
sl@0
    69
	{2,'w',0,0},
sl@0
    70
	};
sl@0
    71
	
sl@0
    72
LOCAL_D SCapKeyParams capUpAndDownKeys[]={
sl@0
    73
	{2,EStdKeySpace,EModifierFunc|EModifierCtrl|EModifierShift,0},
sl@0
    74
	{2,EStdKeyEnter,EModifierFunc|EModifierCtrl|EModifierShift,EModifierShift},
sl@0
    75
	};
sl@0
    76
	
sl@0
    77
LOCAL_D SCapKeyTestParams capKeyTests[]={
sl@0
    78
	{(TText *)_S("Press q"),2,'q',EModifierFunc|EModifierCtrl|EModifierShift,0},
sl@0
    79
	//{(TText *)_S("Press <Alt>q"),2,'q',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
sl@0
    80
	{(TText *)_S("Press <Alt>w"),2,'w',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
sl@0
    81
	{(TText *)_S("Press a"),0,'a',0},
sl@0
    82
	//{(TText *)_S("Press <Ctrl><Alt>a"),1,1,EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc|EModifierCtrl},
sl@0
    83
	{(TText *)_S("Press <Ctrl><Alt>s"),1,19,EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc|EModifierCtrl},
sl@0
    84
	//{(TText *)_S("Press <Alt>b"),2,'b',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
sl@0
    85
	{(TText *)_S("Press <Alt>n"),2,'n',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
sl@0
    86
	{(TText *)_S("Press <Ctrl><Alt>b"),0,2,EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc|EModifierCtrl},
sl@0
    87
	//{(TText *)_S("Press <Alt>c"),0,'c',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
sl@0
    88
	{(TText *)_S("Press <Alt>d"),0,'d',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
sl@0
    89
	{(TText *)_S("Press <Ctrl><Alt>c"),0,3,EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc|EModifierCtrl},
sl@0
    90
//
sl@0
    91
// Capture ups and downs
sl@0
    92
//
sl@0
    93
	{(TText *)_S("Press <Space>"),2,EStdKeySpace,EModifierFunc|EModifierCtrl|EModifierShift,0},
sl@0
    94
	{(TText *)_S("Press <Enter>"),0,EStdKeyEnter,EModifierShift,0},
sl@0
    95
	{(TText *)_S("Press <Shift><Space>"),0,EStdKeySpace,EModifierFunc|EModifierCtrl|EModifierShift,EModifierShift},
sl@0
    96
	{(TText *)_S("Press <Shift><Enter>"),2,EStdKeyEnter,EModifierShift,EModifierShift},
sl@0
    97
//
sl@0
    98
// Priority keys
sl@0
    99
//
sl@0
   100
	{(TText *)_S("Press <Ctrl>c"),0,0,0,0},
sl@0
   101
	{(TText *)_S("Press <Ctrl>d"),0,0,0,0},
sl@0
   102
	{(TText *)_S("Press z"),0,0,0,0},
sl@0
   103
	};
sl@0
   104
sl@0
   105
LOCAL_D SAbortKeyTests abortKeyTests[]={
sl@0
   106
	{3,EModifierCtrl,EModifierCtrl},
sl@0
   107
	{4,EModifierCtrl,EModifierCtrl},
sl@0
   108
	{'z',EModifierFunc|EModifierCtrl|EModifierShift,0}
sl@0
   109
	};
sl@0
   110
sl@0
   111
struct SErrorCapKey
sl@0
   112
	{
sl@0
   113
	TInt keyCode;
sl@0
   114
	TUint modifier_mask;
sl@0
   115
	TUint modifiers;
sl@0
   116
	};
sl@0
   117
sl@0
   118
LOCAL_D SErrorCapKey errorKeys[]={
sl@0
   119
	{'a',EModifierFunc|EModifierShift,EModifierFunc|EModifierCtrl},
sl@0
   120
	{'1',0,EModifierFunc},
sl@0
   121
	{3,EModifierCtrl,EModifierCtrl|EModifierShift},
sl@0
   122
	};
sl@0
   123
sl@0
   124
const TInt numCapKeys=sizeof(capKeys)/sizeof(capKeys[0]);
sl@0
   125
const TInt numTests=sizeof(capKeyTests)/sizeof(capKeyTests[0]);
sl@0
   126
const TInt numErrorKeys=sizeof(errorKeys)/sizeof(errorKeys[0]);
sl@0
   127
const TInt numAbortKeyTests=sizeof(abortKeyTests)/sizeof(abortKeyTests[0]);
sl@0
   128
const TInt numUpDownKeys=sizeof(capUpAndDownKeys)/sizeof(capUpAndDownKeys[0]);
sl@0
   129
const TInt numUpDownKeyTests=4;
sl@0
   130
const TInt numCapKeyTests=numTests-numAbortKeyTests-numUpDownKeyTests;
sl@0
   131
sl@0
   132
LOCAL_D TInt capKeyHandle[numCapKeys];
sl@0
   133
LOCAL_D TInt capUpDownKeyHandle[numUpDownKeys];
sl@0
   134
sl@0
   135
class CCKWindow;
sl@0
   136
class TCaptureKeyTest;
sl@0
   137
class CCKAbortConnection;
sl@0
   138
sl@0
   139
class CCKConnectionBase : public CTClient
sl@0
   140
	{
sl@0
   141
public:
sl@0
   142
	CCKConnectionBase(TCaptureKeyTest *aTest);
sl@0
   143
	void ConstructL();
sl@0
   144
protected:
sl@0
   145
	TCaptureKeyTest *iTest;
sl@0
   146
	};
sl@0
   147
sl@0
   148
class CCKConnection : public CCKConnectionBase
sl@0
   149
	{
sl@0
   150
public:
sl@0
   151
	CCKConnection(TCaptureKeyTest *aTest, TInt aConnIndex);
sl@0
   152
	~CCKConnection();
sl@0
   153
	void ConstructL();
sl@0
   154
	void CheckKeyL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey);
sl@0
   155
	void SubStateChanged();
sl@0
   156
	void KeyTestL(TInt aBool);
sl@0
   157
	void KeyL(const TKeyEvent &aKey,const TTime &aTime);
sl@0
   158
	void CheckUpDownL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey);
sl@0
   159
	void CheckUpDownL(const TKeyEvent &aKey);
sl@0
   160
	inline TInt Index() {return iConnIndex;}
sl@0
   161
protected:
sl@0
   162
	TInt iConnIndex;
sl@0
   163
	CCKWindow *iWin;
sl@0
   164
	};
sl@0
   165
sl@0
   166
class CAbortHandler : public CTEventBase
sl@0
   167
	{
sl@0
   168
public:
sl@0
   169
	CAbortHandler(RWsSession *aWs, CCKAbortConnection *aConnection);
sl@0
   170
	~CAbortHandler();
sl@0
   171
	void Request();
sl@0
   172
protected:
sl@0
   173
	void DoCancel();
sl@0
   174
	void doRunL();
sl@0
   175
protected:
sl@0
   176
	CCKAbortConnection *iConnection;
sl@0
   177
	};
sl@0
   178
sl@0
   179
class CCKAbortConnection : public CCKConnectionBase
sl@0
   180
	{
sl@0
   181
public:
sl@0
   182
	CCKAbortConnection(TCaptureKeyTest *aTest);
sl@0
   183
	~CCKAbortConnection();
sl@0
   184
	void ConstructL();
sl@0
   185
	void ReceivedAbortEventL(TInt aHandle, TKeyEvent *aKey);
sl@0
   186
	void Foreground();
sl@0
   187
protected:
sl@0
   188
	CAbortHandler *iAbortHandler;
sl@0
   189
	TInt iAbortKeyIndex;
sl@0
   190
	};
sl@0
   191
sl@0
   192
class CCKWindow : public CTWin
sl@0
   193
	{
sl@0
   194
public:
sl@0
   195
	CCKWindow(TCaptureKeyTest *aTest, TInt aConnIndex);
sl@0
   196
	void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
sl@0
   197
	void Draw();
sl@0
   198
protected:
sl@0
   199
	TInt iConnIndex;
sl@0
   200
	TCaptureKeyTest *iTest;
sl@0
   201
	TRgb iBack;
sl@0
   202
	};
sl@0
   203
sl@0
   204
class CCKWindowGroup : public CTWindowGroup
sl@0
   205
	{
sl@0
   206
public:
sl@0
   207
	CCKWindowGroup(CTClient *aClient, TCaptureKeyTest *aTest);
sl@0
   208
	void KeyL(const TKeyEvent &aKey,const TTime &aTime);
sl@0
   209
	void KeyDownL(const TKeyEvent &aKey,const TTime &);
sl@0
   210
	void KeyUpL(const TKeyEvent &aKey,const TTime &);
sl@0
   211
	void CheckUpDown(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey);
sl@0
   212
private:
sl@0
   213
	TCaptureKeyTest *iTest;
sl@0
   214
	};
sl@0
   215
sl@0
   216
class TCaptureKeyTest : public CTestBase
sl@0
   217
	{
sl@0
   218
public:
sl@0
   219
	TCaptureKeyTest();
sl@0
   220
	~TCaptureKeyTest();
sl@0
   221
	TestState DoTestL();
sl@0
   222
	void ConstructL();
sl@0
   223
	void EndCaptureKeyTest();
sl@0
   224
	TInt SubState() const;
sl@0
   225
	void IncSubState();
sl@0
   226
	void BadParamsL();
sl@0
   227
	void CapKeyPurgingL();
sl@0
   228
	void SetUpPriorityKeyTest();
sl@0
   229
	void TestComplete();
sl@0
   230
	void CaptureUpsAndDownsTest();
sl@0
   231
	TTestMode Mode();
sl@0
   232
	void SetMode(TTestMode aMode);
sl@0
   233
private:
sl@0
   234
	CCKConnection *iConn1;
sl@0
   235
	CCKConnection *iConn2;
sl@0
   236
	CCKConnection *iConn3;
sl@0
   237
	CCKAbortConnection *iAbortConn;
sl@0
   238
	TSize iWinSize;
sl@0
   239
	TInt iState;
sl@0
   240
	TInt iSubState;
sl@0
   241
	TTestMode iMode;
sl@0
   242
	};
sl@0
   243
sl@0
   244
GLDEF_C CTestBase *CreateMultiCaptureKeyTest()
sl@0
   245
	{
sl@0
   246
	return(new(ELeave) TCaptureKeyTest());
sl@0
   247
	}
sl@0
   248
sl@0
   249
//
sl@0
   250
// CAbortHandler
sl@0
   251
sl@0
   252
CAbortHandler::CAbortHandler(RWsSession *aWs, CCKAbortConnection *aConnection) : CTEventBase(aWs, 10), iConnection(aConnection)
sl@0
   253
	{
sl@0
   254
	}
sl@0
   255
sl@0
   256
CAbortHandler::~CAbortHandler()
sl@0
   257
	{
sl@0
   258
	Cancel();
sl@0
   259
	}
sl@0
   260
sl@0
   261
void CAbortHandler::Request()
sl@0
   262
	{
sl@0
   263
	iWs->PriorityKeyReady(&iStatus);
sl@0
   264
	SetActive();
sl@0
   265
	}
sl@0
   266
sl@0
   267
void CAbortHandler::DoCancel()
sl@0
   268
	{
sl@0
   269
	iWs->PriorityKeyReadyCancel();
sl@0
   270
	}
sl@0
   271
sl@0
   272
void CAbortHandler::doRunL()
sl@0
   273
	{
sl@0
   274
	TWsPriorityKeyEvent abortEvent;
sl@0
   275
	iWs->GetPriorityKey(abortEvent);
sl@0
   276
	iConnection->ReceivedAbortEventL(abortEvent.Handle(),abortEvent.Key());
sl@0
   277
	}
sl@0
   278
sl@0
   279
//
sl@0
   280
// CCKConnection
sl@0
   281
sl@0
   282
CCKConnectionBase::CCKConnectionBase(TCaptureKeyTest *aTest) : iTest(aTest)
sl@0
   283
	{
sl@0
   284
	}
sl@0
   285
sl@0
   286
void CCKConnectionBase::ConstructL()
sl@0
   287
	{
sl@0
   288
	CTClient::ConstructL();
sl@0
   289
	iGroup=new(ELeave) CCKWindowGroup(this, iTest);
sl@0
   290
	iGroup->ConstructL();
sl@0
   291
	}
sl@0
   292
sl@0
   293
CCKConnection::CCKConnection(TCaptureKeyTest *aTest, TInt aConnIndex) : CCKConnectionBase(aTest), iConnIndex(aConnIndex)
sl@0
   294
	{
sl@0
   295
	}
sl@0
   296
sl@0
   297
CCKConnection::~CCKConnection()
sl@0
   298
	{
sl@0
   299
	for(TInt index=0;index<numCapKeys;index++)
sl@0
   300
		if (capKeys[index].connIndex==iConnIndex)
sl@0
   301
			iGroup->GroupWin()->CancelCaptureKey(capKeyHandle[index]);
sl@0
   302
	for(TInt index2=0;index2<numUpDownKeys;index2++)
sl@0
   303
		if (capUpAndDownKeys[index2].connIndex==iConnIndex)
sl@0
   304
			iGroup->GroupWin()->CancelCaptureKeyUpAndDowns(capUpDownKeyHandle[index2]);
sl@0
   305
	CTWin::Delete(iWin);
sl@0
   306
	}
sl@0
   307
sl@0
   308
void CCKConnection::SubStateChanged()
sl@0
   309
	{
sl@0
   310
	iWin->Invalidate();
sl@0
   311
	iWs.Flush();
sl@0
   312
	}
sl@0
   313
sl@0
   314
void CCKConnection::ConstructL()
sl@0
   315
	{
sl@0
   316
	CCKConnectionBase::ConstructL();
sl@0
   317
	for(TInt index=0;index<numCapKeys;index++)
sl@0
   318
		if (capKeys[index].connIndex==iConnIndex)
sl@0
   319
			capKeyHandle[index]=User::LeaveIfError(iGroup->GroupWin()->CaptureKey(capKeys[index].keyCode,capKeys[index].modifier_mask,capKeys[index].modifiers));
sl@0
   320
	for(TInt index2=0;index2<numUpDownKeys;index2++)
sl@0
   321
		if (capUpAndDownKeys[index2].connIndex==iConnIndex)
sl@0
   322
			capUpDownKeyHandle[index2]=User::LeaveIfError(iGroup->GroupWin()->CaptureKeyUpAndDowns(capUpAndDownKeys[index2].keyCode,
sl@0
   323
								capUpAndDownKeys[index2].modifier_mask,capUpAndDownKeys[index2].modifiers));
sl@0
   324
	TSize screenSize=iGroup->Size();
sl@0
   325
	TInt winWidth=screenSize.iWidth/2;
sl@0
   326
	TInt winHeight=screenSize.iHeight-10;
sl@0
   327
	iGroup->GroupWin()->AutoForeground(EFalse);		// Don't allow clicking to cause foreground, might mess up test
sl@0
   328
	CCKWindow *win=new(ELeave) CCKWindow(iTest, iConnIndex);
sl@0
   329
	win->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc);
sl@0
   330
	iWin=win;
sl@0
   331
	}
sl@0
   332
sl@0
   333
void CCKConnection::KeyTestL(TInt aBool)
sl@0
   334
	{
sl@0
   335
	if (!aBool)
sl@0
   336
		{
sl@0
   337
		CTDialog *dialog=new(ELeave) CTDialog();
sl@0
   338
		TInt ret=0;
sl@0
   339
		dialog->ConstructLD(*iGroup,*iGc);
sl@0
   340
		dialog->SetTitle(_L("Invalid key press"));
sl@0
   341
		dialog->SetLine1(_L("Try again?"));
sl@0
   342
		dialog->SetNumButtons(2);
sl@0
   343
		dialog->SetButtonText(0,_L("Fail"));
sl@0
   344
		dialog->SetButtonText(1,_L("Retry"));
sl@0
   345
		ret=dialog->Display();
sl@0
   346
		User::Leave(ret==1 ? ECapKeyRetry : ECapKeyFail);
sl@0
   347
		}
sl@0
   348
	}
sl@0
   349
sl@0
   350
void CCKConnection::CheckKeyL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey)
sl@0
   351
	{
sl@0
   352
	KeyTestL(aKeyTest.connIndex==iConnIndex);
sl@0
   353
	KeyTestL(aKeyTest.keyCode==aKey.iCode);
sl@0
   354
	KeyTestL(aKeyTest.modifiers==(aKey.iModifiers&aKeyTest.modifier_mask));
sl@0
   355
	}
sl@0
   356
sl@0
   357
void CCKConnection::CheckUpDownL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey)
sl@0
   358
	{
sl@0
   359
	KeyTestL(aKeyTest.connIndex==iConnIndex);
sl@0
   360
	KeyTestL(aKeyTest.keyCode==(TUint)aKey.iScanCode);
sl@0
   361
	KeyTestL(aKeyTest.modifiers==(aKey.iModifiers&aKeyTest.modifier_mask));
sl@0
   362
	}
sl@0
   363
sl@0
   364
void CCKConnection::KeyL(const TKeyEvent &aKey,const TTime &)
sl@0
   365
	{
sl@0
   366
	if (iTest->Mode()==EModeNormalCapture)
sl@0
   367
		{
sl@0
   368
		if (aKey.iCode==EKeyEscape)
sl@0
   369
			iTest->AbortL();
sl@0
   370
		TRAPD(ret,CheckKeyL(capKeyTests[iTest->SubState()],aKey));
sl@0
   371
		if (ret==ECapKeyOkay)
sl@0
   372
			iTest->IncSubState();
sl@0
   373
		else
sl@0
   374
			iTest->TestL(ret==ECapKeyRetry);
sl@0
   375
		}
sl@0
   376
	}
sl@0
   377
sl@0
   378
void CCKConnection::CheckUpDownL(const TKeyEvent &aKey)
sl@0
   379
	{
sl@0
   380
	CheckUpDownL(capKeyTests[iTest->SubState()],aKey);
sl@0
   381
	}
sl@0
   382
sl@0
   383
CCKAbortConnection::CCKAbortConnection(TCaptureKeyTest *aTest) : CCKConnectionBase(aTest)
sl@0
   384
	{
sl@0
   385
	}
sl@0
   386
sl@0
   387
CCKAbortConnection::~CCKAbortConnection()
sl@0
   388
	{
sl@0
   389
	iGroup->GroupWin()->RemovePriorityKey(3,EModifierCtrl,EModifierCtrl);
sl@0
   390
	delete iAbortHandler;
sl@0
   391
	}
sl@0
   392
sl@0
   393
void CCKAbortConnection::ConstructL()
sl@0
   394
	{
sl@0
   395
	CCKConnectionBase::ConstructL();
sl@0
   396
	User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[0].keyCode,abortKeyTests[0].modifier_mask,abortKeyTests[0].modifiers));
sl@0
   397
	User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[1].keyCode,abortKeyTests[1].modifier_mask,abortKeyTests[1].modifiers));
sl@0
   398
	User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[2].keyCode,abortKeyTests[2].modifier_mask,abortKeyTests[2].modifiers));
sl@0
   399
	iAbortHandler=new(ELeave) CAbortHandler(&iWs, this);
sl@0
   400
	iAbortHandler->Construct();
sl@0
   401
	iWs.Flush();
sl@0
   402
	}
sl@0
   403
sl@0
   404
void CCKAbortConnection::ReceivedAbortEventL(TInt aHandle, TKeyEvent *aKey)
sl@0
   405
	{
sl@0
   406
	iTest->TestL(aHandle==(TInt)iGroup);
sl@0
   407
	iTest->TestL(aKey->iCode==abortKeyTests[iAbortKeyIndex].keyCode);
sl@0
   408
	iTest->TestL((aKey->iModifiers&abortKeyTests[iAbortKeyIndex].modifier_mask)==abortKeyTests[iAbortKeyIndex].modifiers);
sl@0
   409
	iAbortKeyIndex++;
sl@0
   410
	iTest->IncSubState();
sl@0
   411
	}
sl@0
   412
sl@0
   413
void CCKAbortConnection::Foreground()
sl@0
   414
	{
sl@0
   415
	iGroup->GroupWin()->SetOrdinalPosition(0);
sl@0
   416
	iWs.Flush();
sl@0
   417
	}
sl@0
   418
sl@0
   419
//
sl@0
   420
// CCKWindowGroup class //
sl@0
   421
//
sl@0
   422
sl@0
   423
CCKWindowGroup::CCKWindowGroup(CTClient *aClient, TCaptureKeyTest *aTest) : CTWindowGroup(aClient), iTest(aTest)
sl@0
   424
	{}
sl@0
   425
sl@0
   426
void CCKWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &time)
sl@0
   427
	{
sl@0
   428
	/*TLogMessageText buf(_S("##Recieved Key: "));
sl@0
   429
	buf.Append(aKey.iScanCode);
sl@0
   430
	buf.Append('(');
sl@0
   431
	buf.AppendNum(aKey.iScanCode);
sl@0
   432
	buf.Append(')');
sl@0
   433
	if (!iCurWin)
sl@0
   434
		{
sl@0
   435
		buf.Append('(');
sl@0
   436
		buf.AppendNum(((CCKConnection *)iClient)->Index());
sl@0
   437
		buf.Append(')');
sl@0
   438
		}
sl@0
   439
	iClient->iWs.LogMessage(buf);*/
sl@0
   440
	if (iCurWin)
sl@0
   441
		iCurWin->WinKeyL(aKey,time);
sl@0
   442
	else
sl@0
   443
		((CCKConnection *)iClient)->KeyL(aKey,time);
sl@0
   444
	}
sl@0
   445
sl@0
   446
void CCKWindowGroup::KeyDownL(const TKeyEvent &aKey,const TTime &)
sl@0
   447
	{
sl@0
   448
	if (aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift)
sl@0
   449
		{
sl@0
   450
		if (iTest->Mode()==EModeWaitingForFirstDown)
sl@0
   451
			iTest->SetMode(EModeKeyUpsAndDowns);
sl@0
   452
		if (iTest->Mode()==EModeKeyUpsAndDowns)
sl@0
   453
			((CCKConnection *)iClient)->CheckUpDownL(aKey);
sl@0
   454
		}
sl@0
   455
	}
sl@0
   456
sl@0
   457
void CCKWindowGroup::KeyUpL(const TKeyEvent &aKey,const TTime &)
sl@0
   458
	{
sl@0
   459
	if (aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift)
sl@0
   460
		{
sl@0
   461
		if (iTest->Mode()==EModeKeyUpsAndDowns)
sl@0
   462
			{
sl@0
   463
			((CCKConnection *)iClient)->CheckUpDownL(aKey);
sl@0
   464
			iTest->IncSubState();
sl@0
   465
			}
sl@0
   466
		}
sl@0
   467
	}
sl@0
   468
sl@0
   469
//
sl@0
   470
// CCKWindow, class //
sl@0
   471
//
sl@0
   472
sl@0
   473
CCKWindow::CCKWindow(TCaptureKeyTest *aTest, TInt aConnIndex) : CTWin(), iConnIndex(aConnIndex), iTest(aTest)
sl@0
   474
	{
sl@0
   475
	iBack=TRgb::Gray256(230);
sl@0
   476
	}
sl@0
   477
sl@0
   478
void CCKWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
sl@0
   479
	{
sl@0
   480
	ConstructExtLD(*parent,pos,size);
sl@0
   481
	iWin.SetBackgroundColor(iBack);
sl@0
   482
	Activate();
sl@0
   483
	AssignGC(aGc);
sl@0
   484
	}
sl@0
   485
sl@0
   486
void CCKWindow::Draw()
sl@0
   487
	{
sl@0
   488
	iGc->Clear();
sl@0
   489
	if (iConnIndex==0)
sl@0
   490
		iGc->DrawText(TPtrC(capKeyTests[iTest->SubState()].txt), TPoint(10,20));
sl@0
   491
	}
sl@0
   492
sl@0
   493
//
sl@0
   494
sl@0
   495
TCaptureKeyTest::TCaptureKeyTest() : CTestBase(_L("Capture Key"))
sl@0
   496
	{}
sl@0
   497
sl@0
   498
TCaptureKeyTest::~TCaptureKeyTest()
sl@0
   499
	{
sl@0
   500
	delete iConn1;
sl@0
   501
	delete iConn2;
sl@0
   502
	delete iConn3;
sl@0
   503
	delete iAbortConn;
sl@0
   504
	}
sl@0
   505
sl@0
   506
void TCaptureKeyTest::ConstructL()
sl@0
   507
	{
sl@0
   508
	iAbortConn=new(ELeave) CCKAbortConnection(this);
sl@0
   509
	iAbortConn->ConstructL();
sl@0
   510
	iConn3=new(ELeave) CCKConnection(this,2);
sl@0
   511
	iConn3->ConstructL();
sl@0
   512
	iConn2=new(ELeave) CCKConnection(this,1);
sl@0
   513
	iConn2->ConstructL();
sl@0
   514
	iConn1=new(ELeave) CCKConnection(this,0);
sl@0
   515
	iConn1->ConstructL();
sl@0
   516
	iMode=EModeNormalCapture;
sl@0
   517
	}
sl@0
   518
sl@0
   519
TInt TCaptureKeyTest::SubState() const
sl@0
   520
	{
sl@0
   521
	return(iSubState);
sl@0
   522
	}
sl@0
   523
sl@0
   524
void TCaptureKeyTest::IncSubState()
sl@0
   525
	{
sl@0
   526
	iSubState++;
sl@0
   527
	iConn1->SubStateChanged();
sl@0
   528
	iConn2->SubStateChanged();
sl@0
   529
	iConn3->SubStateChanged();
sl@0
   530
	switch(iMode)
sl@0
   531
		{
sl@0
   532
		case EModeNormalCapture:
sl@0
   533
			if (iSubState==numCapKeyTests)
sl@0
   534
				TestComplete();
sl@0
   535
			break;
sl@0
   536
		case EModeKeyUpsAndDowns:
sl@0
   537
			if (iSubState==(numCapKeyTests+numUpDownKeyTests))
sl@0
   538
				TestComplete();
sl@0
   539
			break;
sl@0
   540
		case EModeAbortKeys:
sl@0
   541
			if (iSubState==(numCapKeyTests+numUpDownKeyTests+numAbortKeyTests))
sl@0
   542
				TestComplete();
sl@0
   543
			break;
sl@0
   544
		default:
sl@0
   545
			break;
sl@0
   546
		}
sl@0
   547
	}
sl@0
   548
sl@0
   549
void TCaptureKeyTest::CapKeyPurgingL()
sl@0
   550
	{
sl@0
   551
	TInt base=Client()->iWs.ResourceCount();
sl@0
   552
	RWindowGroup groupWin(Client()->iWs);
sl@0
   553
	User::LeaveIfError(groupWin.Construct(ENullWsHandle));
sl@0
   554
	TInt capHandle=User::LeaveIfError(groupWin.CaptureKey('a',EModifierFunc,EModifierFunc));
sl@0
   555
	User::LeaveIfError(groupWin.CaptureKey('b',EModifierFunc,EModifierFunc));
sl@0
   556
	TestL(Client()->iWs.ResourceCount()==(base+3));
sl@0
   557
	groupWin.CancelCaptureKey(capHandle);
sl@0
   558
	TestL(Client()->iWs.ResourceCount()==(base+2));
sl@0
   559
	groupWin.Close();
sl@0
   560
	TestL(Client()->iWs.ResourceCount()==base);		// Check it also freed the extra capture key
sl@0
   561
	}
sl@0
   562
sl@0
   563
void TCaptureKeyTest::BadParamsL()
sl@0
   564
	{
sl@0
   565
	TInt resCount=Client()->iWs.ResourceCount();
sl@0
   566
	for(TInt index=0;index<numErrorKeys;index++)
sl@0
   567
		TestL(Client()->iGroup->GroupWin()->CaptureKey(errorKeys[index].keyCode,errorKeys[index].modifier_mask,errorKeys[index].modifiers)==KErrArgument);
sl@0
   568
	TestL(Client()->iWs.ResourceCount()==resCount);
sl@0
   569
	}
sl@0
   570
sl@0
   571
void TCaptureKeyTest::TestComplete()
sl@0
   572
	{
sl@0
   573
	Request();
sl@0
   574
	}
sl@0
   575
sl@0
   576
void TCaptureKeyTest::SetMode(TTestMode aMode)
sl@0
   577
	{
sl@0
   578
	iMode=aMode;
sl@0
   579
	}
sl@0
   580
sl@0
   581
TTestMode TCaptureKeyTest::Mode()
sl@0
   582
	{
sl@0
   583
	return(iMode);
sl@0
   584
	}
sl@0
   585
sl@0
   586
void TCaptureKeyTest::SetUpPriorityKeyTest()
sl@0
   587
	{
sl@0
   588
	iMode=EModeAbortKeys;
sl@0
   589
	iAbortConn->Foreground();
sl@0
   590
	}
sl@0
   591
sl@0
   592
void TCaptureKeyTest::CaptureUpsAndDownsTest()
sl@0
   593
	{
sl@0
   594
	iMode=EModeWaitingForFirstDown;
sl@0
   595
	}
sl@0
   596
sl@0
   597
TestState TCaptureKeyTest::DoTestL()
sl@0
   598
	{
sl@0
   599
	switch(iState)
sl@0
   600
		{
sl@0
   601
		case 0:	// Dummy one to let capture key tests run
sl@0
   602
			iState++;
sl@0
   603
			return(EContinue);
sl@0
   604
		case 1:
sl@0
   605
			LogSubTest(_L("Capture ups and downs"),1);
sl@0
   606
			CaptureUpsAndDownsTest();
sl@0
   607
			iState++;
sl@0
   608
			return(EContinue);
sl@0
   609
		case 2:
sl@0
   610
			LogSubTest(_L("Abort key"),1);
sl@0
   611
			SetUpPriorityKeyTest();
sl@0
   612
			iState++;
sl@0
   613
			return(EContinue);
sl@0
   614
		case 3:
sl@0
   615
			LogSubTest(_L("Errors"),1);
sl@0
   616
			BadParamsL();
sl@0
   617
			CapKeyPurgingL();
sl@0
   618
			LogSubTest(_L("CaptureKey"),1);
sl@0
   619
			iState++;
sl@0
   620
			return(ENext);
sl@0
   621
		default:
sl@0
   622
			return(EFinished);
sl@0
   623
		}
sl@0
   624
//	return(ENext);
sl@0
   625
 	}