os/graphics/windowing/windowserver/test/tauto/TPntKey.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/TPntKey.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,385 @@
     1.4 +// Copyright (c) 1996-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 +// Converted from TMan test code (TMPNTKEY.CPP) May 2001
    1.18 +// Test Pointer move/drag buffer
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 + @test
    1.25 + @internalComponent - Internal Symbian test code
    1.26 +*/
    1.27 +
    1.28 +#include "TPNTKEY.H"
    1.29 +
    1.30 +#define LOGGING on	//Uncomment this line to get more logging
    1.31 +
    1.32 +TInt CTPntKeyWindow::iTestScanCodes[ENumPntKeyTests]={'A','B',0,'C',EStdKeyEnter,'Y'};
    1.33 +TUint CTPntKeyWindow::iTestCodes[ENumPntKeyTests]={'a','B',0,'c',EKeyEnter,'y'};
    1.34 +TUint CTPntKeyWindow::iTestModifiers[ENumPntKeyTests]={0,EModifierShift,0,0,0,0};
    1.35 +
    1.36 +CTPntKeyWindow::CTPntKeyWindow(CTPntKey *aTest) : iTest(aTest)
    1.37 +	{}
    1.38 +
    1.39 +CTPntKeyWindow::~CTPntKeyWindow()
    1.40 +	{
    1.41 +	}
    1.42 +
    1.43 +void CTPntKeyWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent)
    1.44 +	{
    1.45 +	ConstructExtLD(*parent,pos,size);
    1.46 +	iWin.SetPointerGrab(ETrue);
    1.47 +	iKey1=TRect(size.iWidth*1/16,size.iHeight/2,size.iWidth*5/16,size.iHeight);
    1.48 +	iKey2=TRect(size.iWidth*6/16,size.iHeight/2,size.iWidth*10/16,size.iHeight);
    1.49 +	iKey3=TRect(size.iWidth*11/16,size.iHeight/2,size.iWidth*15/16,size.iHeight);
    1.50 +	iWin.AddKeyRect(iKey1,'A',EFalse);
    1.51 +	iWin.AddKeyRect(iKey2,'B',EFalse);
    1.52 +	AssignGC(*Client()->iGc);
    1.53 +	BaseWin()->EnableOnEvents();
    1.54 +	Activate();
    1.55 +	}
    1.56 +
    1.57 +void CTPntKeyWindow::Error(TInt aWhere)
    1.58 +	{
    1.59 +	iTest->Failed(aWhere);
    1.60 +	}
    1.61 +
    1.62 +void CTPntKeyWindow::NextKey()
    1.63 +	{
    1.64 +	if (++iKeyCount!=ENumPntKeyTests)
    1.65 +		{
    1.66 +	#if defined(LOGGING)
    1.67 +		_LIT(KLog,"Next Key  KeyCount=%d");
    1.68 +		iTest->LOG_MESSAGE2(KLog,iKeyCount);
    1.69 +	#endif
    1.70 +		if (iKeyCount==2)
    1.71 +			iWin.RemoveAllKeyRects();
    1.72 +		else if (iKeyCount==3)
    1.73 +			iWin.AddKeyRect(iKey3,'C',EFalse);
    1.74 +		else if (iKeyCount==4)
    1.75 +			{
    1.76 +	#if !defined(__WINS__)
    1.77 +			if (iTest->NoDigitiser())
    1.78 +				{
    1.79 +				return;
    1.80 +				}
    1.81 +	#endif
    1.82 +			iWin.RemoveAllKeyRects();
    1.83 +			iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Z',EFalse);
    1.84 +			}
    1.85 +		else if (iKeyCount==5)
    1.86 +			{
    1.87 +			iWin.RemoveAllKeyRects();
    1.88 +			Client()->iWs.Flush();
    1.89 +			User::After(500000);	// Wait half a second
    1.90 +			iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Y',ETrue);
    1.91 +			}
    1.92 +		Invalidate();
    1.93 +		}
    1.94 +	SendEvent();
    1.95 +	}
    1.96 +
    1.97 +void CTPntKeyWindow::SendEvent()
    1.98 +	{
    1.99 +	TheClient->WaitForRedrawsToFinish();
   1.100 +#if defined(LOGGING)
   1.101 +	_LIT(KLog,"SendEvent  KeyCount=%d");
   1.102 +	iTest->LOG_MESSAGE2(KLog,iKeyCount);
   1.103 +#endif
   1.104 +	switch(iKeyCount)
   1.105 +		{
   1.106 +		case 0:
   1.107 +			SimulatePointerDownUp(iKey1);
   1.108 +			break;
   1.109 +		case 1:
   1.110 +			iTest->TestBase()->SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftShift);
   1.111 +			SimulatePointerDownUp(iKey2);
   1.112 +			iTest->TestBase()->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftShift);
   1.113 +			break;
   1.114 +		case 2:
   1.115 +		case 5:
   1.116 +			{
   1.117 +			TPoint pos=Position();
   1.118 +			TSize size=Size();
   1.119 +			iTest->TestBase()->SimulatePointerDownUp(pos.iX+size.iWidth/2,pos.iY+size.iHeight/4);
   1.120 +			}
   1.121 +			break;
   1.122 +		case 3:
   1.123 +			SimulatePointerDownUp(iKey3);
   1.124 +			break;
   1.125 +		case 4:
   1.126 +			iTest->TestBase()->SimulateKeyDownUp(EStdKeyEnter);
   1.127 +			break;
   1.128 +		}
   1.129 +	}
   1.130 +
   1.131 +void CTPntKeyWindow::SimulatePointerDownUp(const TRect& aRect)
   1.132 +	{
   1.133 +	iTest->TestBase()->SimulatePointerDownUp((aRect.iTl.iX+aRect.iBr.iX)/2,(aRect.iTl.iY+aRect.iBr.iY)/2);
   1.134 +	}
   1.135 +
   1.136 +void CTPntKeyWindow::Test(TInt aCheck)
   1.137 +	{
   1.138 +	if (!aCheck)
   1.139 +		Error(3);
   1.140 +	}
   1.141 +
   1.142 +void CTPntKeyWindow::KeyUpL(const TKeyEvent &aKey,const TTime&)
   1.143 +	{
   1.144 +	if (aKey.iScanCode==iTestScanCodes[iKeyCount])
   1.145 +		NextKey();
   1.146 +	}
   1.147 +
   1.148 +void CTPntKeyWindow::KeyDownL(const TKeyEvent &aKey,const TTime &)
   1.149 +	{
   1.150 +#if defined(LOGGING)
   1.151 +	_LIT(KLog,"KeyDownL  ScanCode=%d '%c' (%d)  KeyCount=%d");
   1.152 +	iTest->LOG_MESSAGE5(KLog,aKey.iScanCode,aKey.iScanCode,iTestScanCodes[iKeyCount],iKeyCount);
   1.153 +#endif
   1.154 +	if (aKey.iScanCode!=EStdKeyLeftFunc && aKey.iScanCode!=EStdKeyRightFunc && 
   1.155 +		 aKey.iScanCode!=EStdKeyLeftAlt && aKey.iScanCode!=EStdKeyRightAlt &&
   1.156 +		 aKey.iScanCode!=EStdKeyLeftCtrl && aKey.iScanCode!=EStdKeyRightCtrl &&
   1.157 +		 aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift && 
   1.158 +		 aKey.iScanCode!=EStdKeyOff &&
   1.159 +		 aKey.iScanCode!=EStdKeyEscape)
   1.160 +		Test(aKey.iScanCode==iTestScanCodes[iKeyCount]);
   1.161 +	}
   1.162 +
   1.163 +void CTPntKeyWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
   1.164 +	{
   1.165 +	if (aKey.iCode!=EKeyEscape)
   1.166 +		{
   1.167 +#if defined(LOGGING)
   1.168 +		_LIT(KLog1,"WinKeyL1  ScanCode=%d (%d)  Code=%d '%c' (%d)");
   1.169 +		_LIT(KLog2,"WinKeyL2  ScanCode=%d  Modifiers=0x%x (0x%x) KeyCount=%d");
   1.170 +		iTest->LOG_MESSAGE6(KLog1,aKey.iScanCode,iTestScanCodes[iKeyCount],aKey.iCode,aKey.iCode,iTestCodes[iKeyCount]);
   1.171 +		iTest->LOG_MESSAGE5(KLog2,aKey.iScanCode,aKey.iModifiers&EModifierMask,iTestModifiers[iKeyCount]&EModifierMask,iKeyCount);
   1.172 +#endif
   1.173 +		Test(aKey.iScanCode==iTestScanCodes[iKeyCount]);
   1.174 +		Test(aKey.iCode==iTestCodes[iKeyCount]);
   1.175 +		Test((aKey.iModifiers&EModifierMask)==(iTestModifiers[iKeyCount]&EModifierMask));
   1.176 +		}
   1.177 +	}
   1.178 +
   1.179 +void CTPntKeyWindow::SwitchOn(const TTime &)
   1.180 +	{
   1.181 +#if defined(LOGGING)
   1.182 +	_LIT(KLog,"SwitchOn  KeyCount=%d");
   1.183 +	iTest->LOG_MESSAGE2(KLog,iKeyCount);
   1.184 +#endif
   1.185 +	if (iKeyCount==4)
   1.186 +		NextKey();
   1.187 + 	else if (iKeyCount!=5)
   1.188 +		Error(2);
   1.189 +	}
   1.190 +
   1.191 +void CTPntKeyWindow::PointerL(const TPointerEvent &aPointer,const TTime &)
   1.192 +	{
   1.193 +#if defined(LOGGING)
   1.194 +	_LIT(KLog,"Pointer Event  Type=%d  Pos=(%d,%d)  PPos=(%d,%d)  KeyCount=%d");
   1.195 +	iTest->LOG_MESSAGE7(KLog,aPointer.iType,aPointer.iPosition.iX,aPointer.iPosition.iY
   1.196 +						,aPointer.iParentPosition.iX,aPointer.iParentPosition.iY,iKeyCount);
   1.197 +#endif
   1.198 +	if (aPointer.iType==TPointerEvent::EButton1Down)
   1.199 +		{
   1.200 +		if (iKeyCount!=2)
   1.201 +			Error(1);
   1.202 +		else
   1.203 +			NextKey();
   1.204 +		}
   1.205 +	}
   1.206 +
   1.207 +void CTPntKeyWindow::DrawButton(const TRect &aRect, const TDesC &aText)
   1.208 +	{
   1.209 +	iGc->DrawRect(aRect);
   1.210 +	iGc->DrawText(aText, TPoint((aRect.iBr.iX+aRect.iTl.iX)/2,(aRect.iBr.iY+aRect.iTl.iY)/2));
   1.211 +	}
   1.212 +
   1.213 +void CTPntKeyWindow::Draw()
   1.214 +	{
   1.215 +	iGc->SetBrushColor(TRgb::Gray4(0));
   1.216 +	iGc->SetPenColor(TRgb::Gray4(3));
   1.217 +	iGc->Clear();
   1.218 +	DrawButton(iKey1,_L("A"));
   1.219 +	DrawButton(iKey2,_L("B"));
   1.220 +	DrawButton(iKey3,_L("C"));
   1.221 +	switch(iKeyCount)
   1.222 +		{
   1.223 +		case 0:
   1.224 +			iGc->DrawText(_L("Click on 'A'"), TPoint(10,20));
   1.225 +			break;
   1.226 +		case 1:
   1.227 +			iGc->DrawText(_L("Shift-Click on 'B'"), TPoint(10,20));
   1.228 +			break;
   1.229 +		case 2:
   1.230 +			iGc->DrawText(_L("Click anywhere in this window"), TPoint(10,20));
   1.231 +			break;
   1.232 +		case 3:
   1.233 +			iGc->DrawText(_L("Click on 'C'"), TPoint(10,20));
   1.234 +			break;
   1.235 +		case 4:
   1.236 +#if defined(__WINS__)	// Can't emulate touching dig when switched off under WINS
   1.237 +			iGc->DrawText(_L("Switch off and on (or press Enter)"), TPoint(10,20));
   1.238 +#else
   1.239 +			iGc->DrawText(_L("Switch off, then touch the screen to switch on"), TPoint(10,20));
   1.240 +#endif
   1.241 +			break;
   1.242 +		case 5:
   1.243 +#if defined(__WINS__)	// Can't emulate touching dig when switched off under WINS
   1.244 +			iGc->DrawText(_L("Touch anywhere in the window"), TPoint(10,20));
   1.245 +#else
   1.246 +			iGc->DrawText(_L("Switch off and touch the screen to switch on again"), TPoint(10,20));
   1.247 +#endif
   1.248 +			break;
   1.249 +		}
   1.250 +	}
   1.251 +
   1.252 +CTPntKey::CTPntKey(CTestStep* aStep):
   1.253 +	CTWsGraphicsBase(aStep)
   1.254 +	{
   1.255 +	}
   1.256 +
   1.257 +CTPntKey::~CTPntKey()
   1.258 +	{
   1.259 +	HAL::Set(HALData::EPenDisplayOn,iOldPointerState);
   1.260 +	CTWin::Delete(iWin);
   1.261 +	Client()->ResetFocus();
   1.262 +	delete iTimeOut;
   1.263 +	}
   1.264 +
   1.265 +TInt CTPntKey::TimeOut(TAny* aTest)		//static
   1.266 +	{
   1.267 +	static_cast<CTPntKey*>(aTest)->TimeOut();
   1.268 +	return(KErrNone);
   1.269 +	}
   1.270 +
   1.271 +void CTPntKey::TimeOut()
   1.272 +	{
   1.273 +	TLogMessageText buf;
   1.274 +	_LIT(KPntKeyTimeOut,"TIMEOUT: Pointer Key, %d, %S");
   1.275 +	buf.AppendFormat(KPntKeyTimeOut,iState,&TestBase()->iSubTitle);
   1.276 +	TheClient->LogMessage(buf);
   1.277 +	Failed(4);
   1.278 +	}
   1.279 +
   1.280 +void CTPntKey::Failed(TInt aWhere)
   1.281 +	{
   1.282 +	_LIT(KLog,"Failed at %d");
   1.283 +	LOG_MESSAGE2(KLog,aWhere);
   1.284 +	if (!iFailed)
   1.285 +		{
   1.286 +		iFailed=ETrue;
   1.287 +		Client()->iGroup->ClearCurrentWindow();
   1.288 +		}
   1.289 +	}
   1.290 +
   1.291 +void CTPntKey::ConstructL()
   1.292 +	{
   1.293 +	TInt mods=TheClient->iWs.GetModifierState();
   1.294 +	if (mods&EModifierCapsLock)
   1.295 +		iTest->SimulateKeyDownUp(EStdKeyCapsLock);
   1.296 +	//Make sure all the keys we test are in the up state
   1.297 +	iTest->SimulateKeyDownUp(EStdKeyLeftShift);
   1.298 +	iTest->SimulateKeyDownUp(EStdKeyRightShift);
   1.299 +	iTest->SimulateKeyDownUp(EStdKeyLeftFunc);
   1.300 +	iTest->SimulateKeyDownUp(EStdKeyLeftCtrl);
   1.301 +	iTest->SimulateKeyDownUp(EStdKeyRightCtrl);
   1.302 +	mods=TheClient->iWs.GetModifierState();
   1.303 +	_LIT(KLog,"Initial Modifiers state 0x%x (ideally should be zero)");
   1.304 +	LOG_MESSAGE2(KLog,mods);
   1.305 +	TheClient->iScreen->SetScreenMode(0);		//May sure we are in the right screen size mode
   1.306 +	TheClient->iScreen->SetAppScreenMode(0);
   1.307 +	TheClient->iWs.SetPointerCursorArea(TestBase()->iNormalPointerCursorArea);
   1.308 +	CTPntKeyWindow *win=new(ELeave) CTPntKeyWindow(this);
   1.309 +	win->SetUpLD(TPoint(20,20),Client()->iScreen->SizeInPixels()-TSize(40,40),Client()->iGroup);
   1.310 +	iWin=win;
   1.311 +	Client()->iGroup->SetCurrentWindow(iWin);
   1.312 +	iNoDigitiser=EFalse;
   1.313 +	TInt err=HAL::Get(HALData::EPenDisplayOn,iOldPointerState);
   1.314 +	if (err==KErrNotSupported)
   1.315 +		{
   1.316 +		iNoDigitiser=ETrue;
   1.317 +		}
   1.318 +	else if (err==KErrNone)
   1.319 +		{
   1.320 +		err=HAL::Set(HALData::EPenDisplayOn,ETrue);
   1.321 +		if (err==KErrNotSupported)
   1.322 +			iNoDigitiser=(!iOldPointerState);
   1.323 +		}
   1.324 +	else
   1.325 +		{
   1.326 +		TEST(EFalse);
   1.327 +		}
   1.328 +	TheClient->WaitForRedrawsToFinish();	//Make sure all pending events have been delt with (redraw events are lowest priority)
   1.329 +	iTimeOut=new(ELeave) CTimeOut();
   1.330 +	iTimeOut->ConstructL();
   1.331 +	iTimeOut->Start(KTimeOutAfter,TCallBack(CTPntKey::TimeOut,this));
   1.332 +	}
   1.333 +
   1.334 +void CTPntKey::RunTestCaseL(TInt /*aCurTestCase*/)
   1.335 +	{
   1.336 +	_LIT(KTestName,"Key set 1");
   1.337 +	TEST(!iFailed);
   1.338 +	if (iFailed)
   1.339 +		{
   1.340 +		_LIT(KLog,"Test Failed  Substate=%d  KeyCount=%d");
   1.341 +		LOG_MESSAGE3(KLog,iTest->iState,iWin->KeyCount());
   1.342 +		}
   1.343 +	((CTPntKeyStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   1.344 +	switch(++iTest->iState)
   1.345 +		{
   1.346 +/**
   1.347 +@SYMTestCaseID		GRAPHICS-WSERV-0200
   1.348 +
   1.349 +@SYMDEF             DEF081259
   1.350 +
   1.351 +@SYMTestCaseDesc    Test Pointer move/drag buffer
   1.352 +
   1.353 +@SYMTestPriority    High
   1.354 +
   1.355 +@SYMTestStatus      Implemented
   1.356 +
   1.357 +@SYMTestActions     Exercise the pointer move/drag buffer and check
   1.358 +					that it functions correctly
   1.359 +
   1.360 +@SYMTestExpectedResults The buffer functions correctly
   1.361 +*/
   1.362 +		case 1:
   1.363 +			((CTPntKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0200"));
   1.364 +			iTest->LogSubTest(KTestName);
   1.365 +			if (TestBase()->ConfigurationSupportsPointerEventTesting())
   1.366 +			    {
   1.367 +			    iWin->SendEvent();
   1.368 +			    TheClient->Flush();
   1.369 +			    }
   1.370 +			else
   1.371 +			    {
   1.372 +			    INFO_PRINTF1(_L("Test skipped because config does not support pointer event testing"));
   1.373 +			    }
   1.374 +			break;
   1.375 +		case 2:
   1.376 +			((CTPntKeyStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.377 +			((CTPntKeyStep*)iStep)->CloseTMSGraphicsStep();
   1.378 +			if (TestBase()->ConfigurationSupportsPointerEventTesting())
   1.379 +			    {
   1.380 +                iTimeOut->Cancel();
   1.381 +			    }
   1.382 +			TestComplete();
   1.383 +			break;
   1.384 +		}
   1.385 +	((CTPntKeyStep*)iStep)->RecordTestResultL();
   1.386 +	}
   1.387 +	
   1.388 +__WS_CONSTRUCT_STEP__(PntKey)