os/graphics/windowing/windowserver/test/tman/TMCAPKEY.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tman/TMCAPKEY.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,625 @@
     1.4 +// Copyright (c) 1995-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 "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 +// Test capture key
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <e32svr.h>
    1.23 +#include <e32keys.h>
    1.24 +#include "W32STD.H"
    1.25 +#include "../tlib/testbase.h"
    1.26 +#include "TMAN.H"
    1.27 +
    1.28 +enum TTestMode
    1.29 +	{
    1.30 +	EModeNormalCapture,
    1.31 +	EModeWaitingForFirstDown,
    1.32 +	EModeKeyUpsAndDowns,
    1.33 +	EModeAbortKeys,
    1.34 +	};
    1.35 +enum TCapKeyRetValues
    1.36 +	{
    1.37 +	ECapKeyOkay,
    1.38 +	ECapKeyRetry,
    1.39 +	ECapKeyFail,
    1.40 +	};
    1.41 +
    1.42 +struct SCapKeyParams
    1.43 +	{
    1.44 +	TInt connIndex;		// Connection that should capture this key
    1.45 +	TUint keyCode;
    1.46 +	TUint modifier_mask;
    1.47 +	TUint modifiers;
    1.48 +	};
    1.49 +
    1.50 +struct SCapKeyTestParams
    1.51 +	{
    1.52 +	TText *txt;			// Text message telling user what to do
    1.53 +	TInt connIndex;		// Connection that receive the key press
    1.54 +	TUint keyCode;		// Expected key code
    1.55 +	TUint modifier_mask;// Modifiers mask for expected modifiers
    1.56 +	TUint modifiers;	// Expected modifiers
    1.57 +	};
    1.58 +
    1.59 +struct SAbortKeyTests
    1.60 +	{
    1.61 +	TUint keyCode;		// Expected key code
    1.62 +	TUint modifier_mask;// Modifiers mask for expected modifiers
    1.63 +	TUint modifiers;	// Expected modifiers
    1.64 +	};
    1.65 +
    1.66 +LOCAL_D SCapKeyParams capKeys[]={
    1.67 +	{1,19,EModifierFunc|EModifierCtrl,EModifierFunc|EModifierCtrl},
    1.68 +	{2,'b',EModifierFunc|EModifierCtrl,EModifierFunc},
    1.69 +	{2,'n',EModifierFunc|EModifierCtrl,EModifierFunc},
    1.70 +	{0,3,EModifierFunc|EModifierCtrl,EModifierFunc|EModifierCtrl},
    1.71 +	{2,'q',0,0},
    1.72 +	{2,'w',0,0},
    1.73 +	};
    1.74 +	
    1.75 +LOCAL_D SCapKeyParams capUpAndDownKeys[]={
    1.76 +	{2,EStdKeySpace,EModifierFunc|EModifierCtrl|EModifierShift,0},
    1.77 +	{2,EStdKeyEnter,EModifierFunc|EModifierCtrl|EModifierShift,EModifierShift},
    1.78 +	};
    1.79 +	
    1.80 +LOCAL_D SCapKeyTestParams capKeyTests[]={
    1.81 +	{(TText *)_S("Press q"),2,'q',EModifierFunc|EModifierCtrl|EModifierShift,0},
    1.82 +	//{(TText *)_S("Press <Alt>q"),2,'q',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
    1.83 +	{(TText *)_S("Press <Alt>w"),2,'w',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
    1.84 +	{(TText *)_S("Press a"),0,'a',0},
    1.85 +	//{(TText *)_S("Press <Ctrl><Alt>a"),1,1,EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc|EModifierCtrl},
    1.86 +	{(TText *)_S("Press <Ctrl><Alt>s"),1,19,EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc|EModifierCtrl},
    1.87 +	//{(TText *)_S("Press <Alt>b"),2,'b',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
    1.88 +	{(TText *)_S("Press <Alt>n"),2,'n',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
    1.89 +	{(TText *)_S("Press <Ctrl><Alt>b"),0,2,EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc|EModifierCtrl},
    1.90 +	//{(TText *)_S("Press <Alt>c"),0,'c',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
    1.91 +	{(TText *)_S("Press <Alt>d"),0,'d',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
    1.92 +	{(TText *)_S("Press <Ctrl><Alt>c"),0,3,EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc|EModifierCtrl},
    1.93 +//
    1.94 +// Capture ups and downs
    1.95 +//
    1.96 +	{(TText *)_S("Press <Space>"),2,EStdKeySpace,EModifierFunc|EModifierCtrl|EModifierShift,0},
    1.97 +	{(TText *)_S("Press <Enter>"),0,EStdKeyEnter,EModifierShift,0},
    1.98 +	{(TText *)_S("Press <Shift><Space>"),0,EStdKeySpace,EModifierFunc|EModifierCtrl|EModifierShift,EModifierShift},
    1.99 +	{(TText *)_S("Press <Shift><Enter>"),2,EStdKeyEnter,EModifierShift,EModifierShift},
   1.100 +//
   1.101 +// Priority keys
   1.102 +//
   1.103 +	{(TText *)_S("Press <Ctrl>c"),0,0,0,0},
   1.104 +	{(TText *)_S("Press <Ctrl>d"),0,0,0,0},
   1.105 +	{(TText *)_S("Press z"),0,0,0,0},
   1.106 +	};
   1.107 +
   1.108 +LOCAL_D SAbortKeyTests abortKeyTests[]={
   1.109 +	{3,EModifierCtrl,EModifierCtrl},
   1.110 +	{4,EModifierCtrl,EModifierCtrl},
   1.111 +	{'z',EModifierFunc|EModifierCtrl|EModifierShift,0}
   1.112 +	};
   1.113 +
   1.114 +struct SErrorCapKey
   1.115 +	{
   1.116 +	TInt keyCode;
   1.117 +	TUint modifier_mask;
   1.118 +	TUint modifiers;
   1.119 +	};
   1.120 +
   1.121 +LOCAL_D SErrorCapKey errorKeys[]={
   1.122 +	{'a',EModifierFunc|EModifierShift,EModifierFunc|EModifierCtrl},
   1.123 +	{'1',0,EModifierFunc},
   1.124 +	{3,EModifierCtrl,EModifierCtrl|EModifierShift},
   1.125 +	};
   1.126 +
   1.127 +const TInt numCapKeys=sizeof(capKeys)/sizeof(capKeys[0]);
   1.128 +const TInt numTests=sizeof(capKeyTests)/sizeof(capKeyTests[0]);
   1.129 +const TInt numErrorKeys=sizeof(errorKeys)/sizeof(errorKeys[0]);
   1.130 +const TInt numAbortKeyTests=sizeof(abortKeyTests)/sizeof(abortKeyTests[0]);
   1.131 +const TInt numUpDownKeys=sizeof(capUpAndDownKeys)/sizeof(capUpAndDownKeys[0]);
   1.132 +const TInt numUpDownKeyTests=4;
   1.133 +const TInt numCapKeyTests=numTests-numAbortKeyTests-numUpDownKeyTests;
   1.134 +
   1.135 +LOCAL_D TInt capKeyHandle[numCapKeys];
   1.136 +LOCAL_D TInt capUpDownKeyHandle[numUpDownKeys];
   1.137 +
   1.138 +class CCKWindow;
   1.139 +class TCaptureKeyTest;
   1.140 +class CCKAbortConnection;
   1.141 +
   1.142 +class CCKConnectionBase : public CTClient
   1.143 +	{
   1.144 +public:
   1.145 +	CCKConnectionBase(TCaptureKeyTest *aTest);
   1.146 +	void ConstructL();
   1.147 +protected:
   1.148 +	TCaptureKeyTest *iTest;
   1.149 +	};
   1.150 +
   1.151 +class CCKConnection : public CCKConnectionBase
   1.152 +	{
   1.153 +public:
   1.154 +	CCKConnection(TCaptureKeyTest *aTest, TInt aConnIndex);
   1.155 +	~CCKConnection();
   1.156 +	void ConstructL();
   1.157 +	void CheckKeyL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey);
   1.158 +	void SubStateChanged();
   1.159 +	void KeyTestL(TInt aBool);
   1.160 +	void KeyL(const TKeyEvent &aKey,const TTime &aTime);
   1.161 +	void CheckUpDownL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey);
   1.162 +	void CheckUpDownL(const TKeyEvent &aKey);
   1.163 +	inline TInt Index() {return iConnIndex;}
   1.164 +protected:
   1.165 +	TInt iConnIndex;
   1.166 +	CCKWindow *iWin;
   1.167 +	};
   1.168 +
   1.169 +class CAbortHandler : public CTEventBase
   1.170 +	{
   1.171 +public:
   1.172 +	CAbortHandler(RWsSession *aWs, CCKAbortConnection *aConnection);
   1.173 +	~CAbortHandler();
   1.174 +	void Request();
   1.175 +protected:
   1.176 +	void DoCancel();
   1.177 +	void doRunL();
   1.178 +protected:
   1.179 +	CCKAbortConnection *iConnection;
   1.180 +	};
   1.181 +
   1.182 +class CCKAbortConnection : public CCKConnectionBase
   1.183 +	{
   1.184 +public:
   1.185 +	CCKAbortConnection(TCaptureKeyTest *aTest);
   1.186 +	~CCKAbortConnection();
   1.187 +	void ConstructL();
   1.188 +	void ReceivedAbortEventL(TInt aHandle, TKeyEvent *aKey);
   1.189 +	void Foreground();
   1.190 +protected:
   1.191 +	CAbortHandler *iAbortHandler;
   1.192 +	TInt iAbortKeyIndex;
   1.193 +	};
   1.194 +
   1.195 +class CCKWindow : public CTWin
   1.196 +	{
   1.197 +public:
   1.198 +	CCKWindow(TCaptureKeyTest *aTest, TInt aConnIndex);
   1.199 +	void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
   1.200 +	void Draw();
   1.201 +protected:
   1.202 +	TInt iConnIndex;
   1.203 +	TCaptureKeyTest *iTest;
   1.204 +	TRgb iBack;
   1.205 +	};
   1.206 +
   1.207 +class CCKWindowGroup : public CTWindowGroup
   1.208 +	{
   1.209 +public:
   1.210 +	CCKWindowGroup(CTClient *aClient, TCaptureKeyTest *aTest);
   1.211 +	void KeyL(const TKeyEvent &aKey,const TTime &aTime);
   1.212 +	void KeyDownL(const TKeyEvent &aKey,const TTime &);
   1.213 +	void KeyUpL(const TKeyEvent &aKey,const TTime &);
   1.214 +	void CheckUpDown(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey);
   1.215 +private:
   1.216 +	TCaptureKeyTest *iTest;
   1.217 +	};
   1.218 +
   1.219 +class TCaptureKeyTest : public CTestBase
   1.220 +	{
   1.221 +public:
   1.222 +	TCaptureKeyTest();
   1.223 +	~TCaptureKeyTest();
   1.224 +	TestState DoTestL();
   1.225 +	void ConstructL();
   1.226 +	void EndCaptureKeyTest();
   1.227 +	TInt SubState() const;
   1.228 +	void IncSubState();
   1.229 +	void BadParamsL();
   1.230 +	void CapKeyPurgingL();
   1.231 +	void SetUpPriorityKeyTest();
   1.232 +	void TestComplete();
   1.233 +	void CaptureUpsAndDownsTest();
   1.234 +	TTestMode Mode();
   1.235 +	void SetMode(TTestMode aMode);
   1.236 +private:
   1.237 +	CCKConnection *iConn1;
   1.238 +	CCKConnection *iConn2;
   1.239 +	CCKConnection *iConn3;
   1.240 +	CCKAbortConnection *iAbortConn;
   1.241 +	TSize iWinSize;
   1.242 +	TInt iState;
   1.243 +	TInt iSubState;
   1.244 +	TTestMode iMode;
   1.245 +	};
   1.246 +
   1.247 +GLDEF_C CTestBase *CreateMultiCaptureKeyTest()
   1.248 +	{
   1.249 +	return(new(ELeave) TCaptureKeyTest());
   1.250 +	}
   1.251 +
   1.252 +//
   1.253 +// CAbortHandler
   1.254 +
   1.255 +CAbortHandler::CAbortHandler(RWsSession *aWs, CCKAbortConnection *aConnection) : CTEventBase(aWs, 10), iConnection(aConnection)
   1.256 +	{
   1.257 +	}
   1.258 +
   1.259 +CAbortHandler::~CAbortHandler()
   1.260 +	{
   1.261 +	Cancel();
   1.262 +	}
   1.263 +
   1.264 +void CAbortHandler::Request()
   1.265 +	{
   1.266 +	iWs->PriorityKeyReady(&iStatus);
   1.267 +	SetActive();
   1.268 +	}
   1.269 +
   1.270 +void CAbortHandler::DoCancel()
   1.271 +	{
   1.272 +	iWs->PriorityKeyReadyCancel();
   1.273 +	}
   1.274 +
   1.275 +void CAbortHandler::doRunL()
   1.276 +	{
   1.277 +	TWsPriorityKeyEvent abortEvent;
   1.278 +	iWs->GetPriorityKey(abortEvent);
   1.279 +	iConnection->ReceivedAbortEventL(abortEvent.Handle(),abortEvent.Key());
   1.280 +	}
   1.281 +
   1.282 +//
   1.283 +// CCKConnection
   1.284 +
   1.285 +CCKConnectionBase::CCKConnectionBase(TCaptureKeyTest *aTest) : iTest(aTest)
   1.286 +	{
   1.287 +	}
   1.288 +
   1.289 +void CCKConnectionBase::ConstructL()
   1.290 +	{
   1.291 +	CTClient::ConstructL();
   1.292 +	iGroup=new(ELeave) CCKWindowGroup(this, iTest);
   1.293 +	iGroup->ConstructL();
   1.294 +	}
   1.295 +
   1.296 +CCKConnection::CCKConnection(TCaptureKeyTest *aTest, TInt aConnIndex) : CCKConnectionBase(aTest), iConnIndex(aConnIndex)
   1.297 +	{
   1.298 +	}
   1.299 +
   1.300 +CCKConnection::~CCKConnection()
   1.301 +	{
   1.302 +	for(TInt index=0;index<numCapKeys;index++)
   1.303 +		if (capKeys[index].connIndex==iConnIndex)
   1.304 +			iGroup->GroupWin()->CancelCaptureKey(capKeyHandle[index]);
   1.305 +	for(TInt index2=0;index2<numUpDownKeys;index2++)
   1.306 +		if (capUpAndDownKeys[index2].connIndex==iConnIndex)
   1.307 +			iGroup->GroupWin()->CancelCaptureKeyUpAndDowns(capUpDownKeyHandle[index2]);
   1.308 +	CTWin::Delete(iWin);
   1.309 +	}
   1.310 +
   1.311 +void CCKConnection::SubStateChanged()
   1.312 +	{
   1.313 +	iWin->Invalidate();
   1.314 +	iWs.Flush();
   1.315 +	}
   1.316 +
   1.317 +void CCKConnection::ConstructL()
   1.318 +	{
   1.319 +	CCKConnectionBase::ConstructL();
   1.320 +	for(TInt index=0;index<numCapKeys;index++)
   1.321 +		if (capKeys[index].connIndex==iConnIndex)
   1.322 +			capKeyHandle[index]=User::LeaveIfError(iGroup->GroupWin()->CaptureKey(capKeys[index].keyCode,capKeys[index].modifier_mask,capKeys[index].modifiers));
   1.323 +	for(TInt index2=0;index2<numUpDownKeys;index2++)
   1.324 +		if (capUpAndDownKeys[index2].connIndex==iConnIndex)
   1.325 +			capUpDownKeyHandle[index2]=User::LeaveIfError(iGroup->GroupWin()->CaptureKeyUpAndDowns(capUpAndDownKeys[index2].keyCode,
   1.326 +								capUpAndDownKeys[index2].modifier_mask,capUpAndDownKeys[index2].modifiers));
   1.327 +	TSize screenSize=iGroup->Size();
   1.328 +	TInt winWidth=screenSize.iWidth/2;
   1.329 +	TInt winHeight=screenSize.iHeight-10;
   1.330 +	iGroup->GroupWin()->AutoForeground(EFalse);		// Don't allow clicking to cause foreground, might mess up test
   1.331 +	CCKWindow *win=new(ELeave) CCKWindow(iTest, iConnIndex);
   1.332 +	win->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc);
   1.333 +	iWin=win;
   1.334 +	}
   1.335 +
   1.336 +void CCKConnection::KeyTestL(TInt aBool)
   1.337 +	{
   1.338 +	if (!aBool)
   1.339 +		{
   1.340 +		CTDialog *dialog=new(ELeave) CTDialog();
   1.341 +		TInt ret=0;
   1.342 +		dialog->ConstructLD(*iGroup,*iGc);
   1.343 +		dialog->SetTitle(_L("Invalid key press"));
   1.344 +		dialog->SetLine1(_L("Try again?"));
   1.345 +		dialog->SetNumButtons(2);
   1.346 +		dialog->SetButtonText(0,_L("Fail"));
   1.347 +		dialog->SetButtonText(1,_L("Retry"));
   1.348 +		ret=dialog->Display();
   1.349 +		User::Leave(ret==1 ? ECapKeyRetry : ECapKeyFail);
   1.350 +		}
   1.351 +	}
   1.352 +
   1.353 +void CCKConnection::CheckKeyL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey)
   1.354 +	{
   1.355 +	KeyTestL(aKeyTest.connIndex==iConnIndex);
   1.356 +	KeyTestL(aKeyTest.keyCode==aKey.iCode);
   1.357 +	KeyTestL(aKeyTest.modifiers==(aKey.iModifiers&aKeyTest.modifier_mask));
   1.358 +	}
   1.359 +
   1.360 +void CCKConnection::CheckUpDownL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey)
   1.361 +	{
   1.362 +	KeyTestL(aKeyTest.connIndex==iConnIndex);
   1.363 +	KeyTestL(aKeyTest.keyCode==(TUint)aKey.iScanCode);
   1.364 +	KeyTestL(aKeyTest.modifiers==(aKey.iModifiers&aKeyTest.modifier_mask));
   1.365 +	}
   1.366 +
   1.367 +void CCKConnection::KeyL(const TKeyEvent &aKey,const TTime &)
   1.368 +	{
   1.369 +	if (iTest->Mode()==EModeNormalCapture)
   1.370 +		{
   1.371 +		if (aKey.iCode==EKeyEscape)
   1.372 +			iTest->AbortL();
   1.373 +		TRAPD(ret,CheckKeyL(capKeyTests[iTest->SubState()],aKey));
   1.374 +		if (ret==ECapKeyOkay)
   1.375 +			iTest->IncSubState();
   1.376 +		else
   1.377 +			iTest->TestL(ret==ECapKeyRetry);
   1.378 +		}
   1.379 +	}
   1.380 +
   1.381 +void CCKConnection::CheckUpDownL(const TKeyEvent &aKey)
   1.382 +	{
   1.383 +	CheckUpDownL(capKeyTests[iTest->SubState()],aKey);
   1.384 +	}
   1.385 +
   1.386 +CCKAbortConnection::CCKAbortConnection(TCaptureKeyTest *aTest) : CCKConnectionBase(aTest)
   1.387 +	{
   1.388 +	}
   1.389 +
   1.390 +CCKAbortConnection::~CCKAbortConnection()
   1.391 +	{
   1.392 +	iGroup->GroupWin()->RemovePriorityKey(3,EModifierCtrl,EModifierCtrl);
   1.393 +	delete iAbortHandler;
   1.394 +	}
   1.395 +
   1.396 +void CCKAbortConnection::ConstructL()
   1.397 +	{
   1.398 +	CCKConnectionBase::ConstructL();
   1.399 +	User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[0].keyCode,abortKeyTests[0].modifier_mask,abortKeyTests[0].modifiers));
   1.400 +	User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[1].keyCode,abortKeyTests[1].modifier_mask,abortKeyTests[1].modifiers));
   1.401 +	User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[2].keyCode,abortKeyTests[2].modifier_mask,abortKeyTests[2].modifiers));
   1.402 +	iAbortHandler=new(ELeave) CAbortHandler(&iWs, this);
   1.403 +	iAbortHandler->Construct();
   1.404 +	iWs.Flush();
   1.405 +	}
   1.406 +
   1.407 +void CCKAbortConnection::ReceivedAbortEventL(TInt aHandle, TKeyEvent *aKey)
   1.408 +	{
   1.409 +	iTest->TestL(aHandle==(TInt)iGroup);
   1.410 +	iTest->TestL(aKey->iCode==abortKeyTests[iAbortKeyIndex].keyCode);
   1.411 +	iTest->TestL((aKey->iModifiers&abortKeyTests[iAbortKeyIndex].modifier_mask)==abortKeyTests[iAbortKeyIndex].modifiers);
   1.412 +	iAbortKeyIndex++;
   1.413 +	iTest->IncSubState();
   1.414 +	}
   1.415 +
   1.416 +void CCKAbortConnection::Foreground()
   1.417 +	{
   1.418 +	iGroup->GroupWin()->SetOrdinalPosition(0);
   1.419 +	iWs.Flush();
   1.420 +	}
   1.421 +
   1.422 +//
   1.423 +// CCKWindowGroup class //
   1.424 +//
   1.425 +
   1.426 +CCKWindowGroup::CCKWindowGroup(CTClient *aClient, TCaptureKeyTest *aTest) : CTWindowGroup(aClient), iTest(aTest)
   1.427 +	{}
   1.428 +
   1.429 +void CCKWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &time)
   1.430 +	{
   1.431 +	/*TLogMessageText buf(_S("##Recieved Key: "));
   1.432 +	buf.Append(aKey.iScanCode);
   1.433 +	buf.Append('(');
   1.434 +	buf.AppendNum(aKey.iScanCode);
   1.435 +	buf.Append(')');
   1.436 +	if (!iCurWin)
   1.437 +		{
   1.438 +		buf.Append('(');
   1.439 +		buf.AppendNum(((CCKConnection *)iClient)->Index());
   1.440 +		buf.Append(')');
   1.441 +		}
   1.442 +	iClient->iWs.LogMessage(buf);*/
   1.443 +	if (iCurWin)
   1.444 +		iCurWin->WinKeyL(aKey,time);
   1.445 +	else
   1.446 +		((CCKConnection *)iClient)->KeyL(aKey,time);
   1.447 +	}
   1.448 +
   1.449 +void CCKWindowGroup::KeyDownL(const TKeyEvent &aKey,const TTime &)
   1.450 +	{
   1.451 +	if (aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift)
   1.452 +		{
   1.453 +		if (iTest->Mode()==EModeWaitingForFirstDown)
   1.454 +			iTest->SetMode(EModeKeyUpsAndDowns);
   1.455 +		if (iTest->Mode()==EModeKeyUpsAndDowns)
   1.456 +			((CCKConnection *)iClient)->CheckUpDownL(aKey);
   1.457 +		}
   1.458 +	}
   1.459 +
   1.460 +void CCKWindowGroup::KeyUpL(const TKeyEvent &aKey,const TTime &)
   1.461 +	{
   1.462 +	if (aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift)
   1.463 +		{
   1.464 +		if (iTest->Mode()==EModeKeyUpsAndDowns)
   1.465 +			{
   1.466 +			((CCKConnection *)iClient)->CheckUpDownL(aKey);
   1.467 +			iTest->IncSubState();
   1.468 +			}
   1.469 +		}
   1.470 +	}
   1.471 +
   1.472 +//
   1.473 +// CCKWindow, class //
   1.474 +//
   1.475 +
   1.476 +CCKWindow::CCKWindow(TCaptureKeyTest *aTest, TInt aConnIndex) : CTWin(), iConnIndex(aConnIndex), iTest(aTest)
   1.477 +	{
   1.478 +	iBack=TRgb::Gray256(230);
   1.479 +	}
   1.480 +
   1.481 +void CCKWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
   1.482 +	{
   1.483 +	ConstructExtLD(*parent,pos,size);
   1.484 +	iWin.SetBackgroundColor(iBack);
   1.485 +	Activate();
   1.486 +	AssignGC(aGc);
   1.487 +	}
   1.488 +
   1.489 +void CCKWindow::Draw()
   1.490 +	{
   1.491 +	iGc->Clear();
   1.492 +	if (iConnIndex==0)
   1.493 +		iGc->DrawText(TPtrC(capKeyTests[iTest->SubState()].txt), TPoint(10,20));
   1.494 +	}
   1.495 +
   1.496 +//
   1.497 +
   1.498 +TCaptureKeyTest::TCaptureKeyTest() : CTestBase(_L("Capture Key"))
   1.499 +	{}
   1.500 +
   1.501 +TCaptureKeyTest::~TCaptureKeyTest()
   1.502 +	{
   1.503 +	delete iConn1;
   1.504 +	delete iConn2;
   1.505 +	delete iConn3;
   1.506 +	delete iAbortConn;
   1.507 +	}
   1.508 +
   1.509 +void TCaptureKeyTest::ConstructL()
   1.510 +	{
   1.511 +	iAbortConn=new(ELeave) CCKAbortConnection(this);
   1.512 +	iAbortConn->ConstructL();
   1.513 +	iConn3=new(ELeave) CCKConnection(this,2);
   1.514 +	iConn3->ConstructL();
   1.515 +	iConn2=new(ELeave) CCKConnection(this,1);
   1.516 +	iConn2->ConstructL();
   1.517 +	iConn1=new(ELeave) CCKConnection(this,0);
   1.518 +	iConn1->ConstructL();
   1.519 +	iMode=EModeNormalCapture;
   1.520 +	}
   1.521 +
   1.522 +TInt TCaptureKeyTest::SubState() const
   1.523 +	{
   1.524 +	return(iSubState);
   1.525 +	}
   1.526 +
   1.527 +void TCaptureKeyTest::IncSubState()
   1.528 +	{
   1.529 +	iSubState++;
   1.530 +	iConn1->SubStateChanged();
   1.531 +	iConn2->SubStateChanged();
   1.532 +	iConn3->SubStateChanged();
   1.533 +	switch(iMode)
   1.534 +		{
   1.535 +		case EModeNormalCapture:
   1.536 +			if (iSubState==numCapKeyTests)
   1.537 +				TestComplete();
   1.538 +			break;
   1.539 +		case EModeKeyUpsAndDowns:
   1.540 +			if (iSubState==(numCapKeyTests+numUpDownKeyTests))
   1.541 +				TestComplete();
   1.542 +			break;
   1.543 +		case EModeAbortKeys:
   1.544 +			if (iSubState==(numCapKeyTests+numUpDownKeyTests+numAbortKeyTests))
   1.545 +				TestComplete();
   1.546 +			break;
   1.547 +		default:
   1.548 +			break;
   1.549 +		}
   1.550 +	}
   1.551 +
   1.552 +void TCaptureKeyTest::CapKeyPurgingL()
   1.553 +	{
   1.554 +	TInt base=Client()->iWs.ResourceCount();
   1.555 +	RWindowGroup groupWin(Client()->iWs);
   1.556 +	User::LeaveIfError(groupWin.Construct(ENullWsHandle));
   1.557 +	TInt capHandle=User::LeaveIfError(groupWin.CaptureKey('a',EModifierFunc,EModifierFunc));
   1.558 +	User::LeaveIfError(groupWin.CaptureKey('b',EModifierFunc,EModifierFunc));
   1.559 +	TestL(Client()->iWs.ResourceCount()==(base+3));
   1.560 +	groupWin.CancelCaptureKey(capHandle);
   1.561 +	TestL(Client()->iWs.ResourceCount()==(base+2));
   1.562 +	groupWin.Close();
   1.563 +	TestL(Client()->iWs.ResourceCount()==base);		// Check it also freed the extra capture key
   1.564 +	}
   1.565 +
   1.566 +void TCaptureKeyTest::BadParamsL()
   1.567 +	{
   1.568 +	TInt resCount=Client()->iWs.ResourceCount();
   1.569 +	for(TInt index=0;index<numErrorKeys;index++)
   1.570 +		TestL(Client()->iGroup->GroupWin()->CaptureKey(errorKeys[index].keyCode,errorKeys[index].modifier_mask,errorKeys[index].modifiers)==KErrArgument);
   1.571 +	TestL(Client()->iWs.ResourceCount()==resCount);
   1.572 +	}
   1.573 +
   1.574 +void TCaptureKeyTest::TestComplete()
   1.575 +	{
   1.576 +	Request();
   1.577 +	}
   1.578 +
   1.579 +void TCaptureKeyTest::SetMode(TTestMode aMode)
   1.580 +	{
   1.581 +	iMode=aMode;
   1.582 +	}
   1.583 +
   1.584 +TTestMode TCaptureKeyTest::Mode()
   1.585 +	{
   1.586 +	return(iMode);
   1.587 +	}
   1.588 +
   1.589 +void TCaptureKeyTest::SetUpPriorityKeyTest()
   1.590 +	{
   1.591 +	iMode=EModeAbortKeys;
   1.592 +	iAbortConn->Foreground();
   1.593 +	}
   1.594 +
   1.595 +void TCaptureKeyTest::CaptureUpsAndDownsTest()
   1.596 +	{
   1.597 +	iMode=EModeWaitingForFirstDown;
   1.598 +	}
   1.599 +
   1.600 +TestState TCaptureKeyTest::DoTestL()
   1.601 +	{
   1.602 +	switch(iState)
   1.603 +		{
   1.604 +		case 0:	// Dummy one to let capture key tests run
   1.605 +			iState++;
   1.606 +			return(EContinue);
   1.607 +		case 1:
   1.608 +			LogSubTest(_L("Capture ups and downs"),1);
   1.609 +			CaptureUpsAndDownsTest();
   1.610 +			iState++;
   1.611 +			return(EContinue);
   1.612 +		case 2:
   1.613 +			LogSubTest(_L("Abort key"),1);
   1.614 +			SetUpPriorityKeyTest();
   1.615 +			iState++;
   1.616 +			return(EContinue);
   1.617 +		case 3:
   1.618 +			LogSubTest(_L("Errors"),1);
   1.619 +			BadParamsL();
   1.620 +			CapKeyPurgingL();
   1.621 +			LogSubTest(_L("CaptureKey"),1);
   1.622 +			iState++;
   1.623 +			return(ENext);
   1.624 +		default:
   1.625 +			return(EFinished);
   1.626 +		}
   1.627 +//	return(ENext);
   1.628 + 	}