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