os/graphics/windowing/windowserver/test/tauto/TMULTCON.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/TMULTCON.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,478 @@
     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 +// Test multiple connections to the window server
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @test
    1.24 + @internalComponent - Internal Symbian test code
    1.25 +*/
    1.26 +
    1.27 +#include "TMULTCON.H"
    1.28 +
    1.29 +const TInt EMaxSubState=3;
    1.30 +
    1.31 +//#define LOGGING on		//Uncomment this line to get extra logging
    1.32 +
    1.33 +_LIT(ClickOnMe,"Click on me");
    1.34 +_LIT(KError,"ERROR");
    1.35 +
    1.36 +
    1.37 +CTMultiCon::CTMultiCon(CTestStep* aStep) : CTWsGraphicsBase(aStep)
    1.38 +	{
    1.39 +	}
    1.40 +
    1.41 +CTMultiCon::~CTMultiCon()
    1.42 +	{
    1.43 +	delete iConn1;
    1.44 +	delete iConn2;
    1.45 +	delete iConn3;
    1.46 +	delete iTimeOut;
    1.47 +	}
    1.48 +
    1.49 +void CTMultiCon::EndAutoForegroundTest()
    1.50 +	{
    1.51 +#if defined(LOGGING)
    1.52 +	_LIT(KLog,"EndAutoForegroundTest  SubState %d");
    1.53 +	LOG_MESSAGE2(KLog,iSubState);
    1.54 +#endif
    1.55 +	iConn1->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
    1.56 +	iConn2->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
    1.57 +	iConn3->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
    1.58 +	CActiveScheduler::Stop();
    1.59 +	}
    1.60 +
    1.61 +void CTMultiCon::ConstructL()
    1.62 +	{
    1.63 +	iTimeOut=new(ELeave) CTimeOut();
    1.64 +	iTimeOut->ConstructL();
    1.65 +	TheClient->iWs.SetPointerCursorArea(iTest->iNormalPointerCursorArea);
    1.66 +	iScreenSize=TSize(TheClient->iScreen->SizeInPixels());
    1.67 +	iConn3=new(ELeave) CMcConnectionDef(this);
    1.68 +	iConn3->ConstructL();
    1.69 +	iConn2=new(ELeave) CMcConnection(this);
    1.70 +	iConn2->ConstructL();
    1.71 +	iConn1=new(ELeave) CMcConnectionAf(this);
    1.72 +	iConn1->ConstructL();
    1.73 +	iTest->SimulateKeyDownUp(EStdKeyLeftCtrl);
    1.74 +	iTest->SimulateKeyDownUp(EStdKeyRightCtrl);
    1.75 +	TInt mods=TheClient->iWs.GetModifierState();
    1.76 +	_LIT(KLog,"Initial Modifiers state 0x%x (ideally should be zero)");
    1.77 +	LOG_MESSAGE2(KLog,mods);
    1.78 +	}
    1.79 +
    1.80 +TInt CTMultiCon::TimeOut(TAny* aTest)		//static
    1.81 +	{
    1.82 +	static_cast<CTMultiCon*>(aTest)->TimeOut();
    1.83 +	return(KErrNone);
    1.84 +	}
    1.85 +
    1.86 +void CTMultiCon::TimeOut()
    1.87 +	{
    1.88 +	TLogMessageText buf;
    1.89 +	_LIT(KMultiConTimeOut,"TIMEOUT: Multiple Conection Test, %d, %S");
    1.90 +	buf.AppendFormat(KMultiConTimeOut,iTest->iState,&iTest->iSubTitle);
    1.91 +	TheClient->LogMessage(buf);
    1.92 +	++iTimeOutCount;
    1.93 +	EndAutoForegroundTest();
    1.94 +	}
    1.95 +
    1.96 +
    1.97 +//
    1.98 +// CMcConnection //
    1.99 +//
   1.100 +
   1.101 +CMcConnectionBase::CMcConnectionBase(CTMultiCon *aTest) : iTest(aTest)
   1.102 +	{
   1.103 +	}
   1.104 +
   1.105 +CMcConnectionBase::~CMcConnectionBase()
   1.106 +	{
   1.107 +	CTWin::Delete(iWin);
   1.108 +	delete iGc;
   1.109 +	}
   1.110 +
   1.111 +void CMcConnectionBase::SubStateChanged()
   1.112 +	{
   1.113 +	iWin->Invalidate();
   1.114 +	iWs.Flush();
   1.115 +	}
   1.116 +
   1.117 +void CMcConnectionBase::ConstructL()
   1.118 +	{
   1.119 +	CTClient::SetScreenNumber(iTest->ScreenNumber());
   1.120 +	CTClient::ConstructL();
   1.121 +	User::LeaveIfError(iScreen->CreateContext(iGc));
   1.122 +	}
   1.123 +
   1.124 +CMcConnection::CMcConnection(CTMultiCon *aTest) : CMcConnectionBase(aTest)
   1.125 +	{
   1.126 +	}
   1.127 +
   1.128 +void CMcConnection::ConstructL()
   1.129 +	{
   1.130 +	CMcConnectionBase::ConstructL();
   1.131 +	iGroup=new(ELeave) CTWindowGroup(this);
   1.132 +	iGroup->ConstructL();
   1.133 +	TSize screenSize=iGroup->Size();
   1.134 +	TInt winWidth=screenSize.iWidth/3;
   1.135 +	TInt winHeight=screenSize.iHeight/2-10;
   1.136 +	iGroup->GroupWin()->AutoForeground(EFalse);
   1.137 +	CMcWindow *win=new(ELeave) CMcWindow(iTest);
   1.138 +	win->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc);
   1.139 +	iWin=win;
   1.140 +	iWs.Flush();
   1.141 +	}
   1.142 +
   1.143 +CMcConnectionAf::CMcConnectionAf(CTMultiCon *aTest) : CMcConnectionBase(aTest)
   1.144 +	{
   1.145 +	}
   1.146 +
   1.147 +void CMcConnectionAf::ConstructL()
   1.148 +	{
   1.149 +	CMcConnectionBase::ConstructL();
   1.150 +	iGroup=new(ELeave) CMcWindowGroupAf(this);
   1.151 +	iGroup->ConstructL();
   1.152 +	TSize screenSize=iGroup->Size();
   1.153 +	TInt winWidth=screenSize.iWidth/3;
   1.154 +	TInt winHeight=screenSize.iHeight/2-10;
   1.155 +	iGroup->GroupWin()->AutoForeground(ETrue);
   1.156 +	CMcWindowAf *win=new(ELeave) CMcWindowAf(iTest);
   1.157 +	win->SetUpL(TPoint(winWidth,5),TSize(winWidth,winHeight),iGroup,*iGc);
   1.158 +	iWin=win;
   1.159 +	iWs.Flush();
   1.160 +	}
   1.161 +
   1.162 +void CMcConnectionAf::KeyL(const TKeyEvent &aKey)
   1.163 +	{
   1.164 +#if defined(LOGGING)
   1.165 +	_LIT(KLog1,"KeyL  SS=%d (0)  GpWinOrdPos=%d (0)  Code=%d (32)");
   1.166 +	_LIT(KLog2," '%c'");
   1.167 +	TLogMessageText buf;
   1.168 +	buf.Format(KLog1,iTest->SubState(),iGroup->GroupWin()->OrdinalPosition(),aKey.iCode);
   1.169 +	if (aKey.iCode>0)
   1.170 +		buf.AppendFormat(KLog2,aKey.iCode);
   1.171 +	iTest->LOG_MESSAGE(buf);
   1.172 +#endif
   1.173 +	switch(aKey.iCode)
   1.174 +		{
   1.175 +		case ' ':
   1.176 +			if (iTest->SubState()==0)
   1.177 +				{
   1.178 +				iTest->TEST(iGroup->GroupWin()->OrdinalPosition()==0);
   1.179 +				iTest->IncSubState();
   1.180 +				}
   1.181 +			break;
   1.182 +		case EKeyEscape:
   1.183 +			iTest->EndAutoForegroundTest();
   1.184 +			break;
   1.185 +		}
   1.186 +	}
   1.187 +
   1.188 +CMcConnectionDef::CMcConnectionDef(CTMultiCon *aTest) : CMcConnectionBase(aTest)
   1.189 +	{
   1.190 +	}
   1.191 +
   1.192 +void CMcConnectionDef::ConstructL()
   1.193 +	{
   1.194 +	CMcConnectionBase::ConstructL();
   1.195 +	iGroup=new(ELeave) CTWindowGroup(this);
   1.196 +	iGroup->ConstructL();
   1.197 +	iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
   1.198 +	TSize screenSize=iGroup->Size();
   1.199 +	TInt winWidth=screenSize.iWidth/3-10;
   1.200 +	TInt winHeight=(screenSize.iHeight/2)-10;
   1.201 +	CMcWindowDef *win=new(ELeave) CMcWindowDef(iTest);
   1.202 +	win->SetUpL(TPoint(5+winWidth/2,screenSize.iHeight/2),TSize(winWidth,winHeight),iGroup,*iGc);
   1.203 +	iWin=win;
   1.204 +	iWs.Flush();
   1.205 +	}
   1.206 +
   1.207 +//
   1.208 +// CMcWindow, base class //
   1.209 +//
   1.210 +
   1.211 +CMcWindowBase::CMcWindowBase(CTMultiCon *aTest) : CTWin(), iTest(aTest)
   1.212 +	{
   1.213 +	}
   1.214 +
   1.215 +void CMcWindowBase::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
   1.216 +	{
   1.217 +	ConstructExtLD(*parent,pos,size);
   1.218 +	iWin.SetBackgroundColor(iBack);
   1.219 +	Activate();
   1.220 +	AssignGC(aGc);
   1.221 +	}
   1.222 +
   1.223 +//
   1.224 +// CMcWindow, window used to test multiple connections //
   1.225 +//
   1.226 +
   1.227 +CMcWindow::CMcWindow(CTMultiCon *aTest) : CMcWindowBase(aTest)
   1.228 +	{
   1.229 +	iBack=TRgb::Gray256(221);
   1.230 +	}
   1.231 +
   1.232 +void CMcWindow::PointerL(const TPointerEvent &pointer,const TTime &)
   1.233 +	{
   1.234 +#if defined(LOGGING)
   1.235 +	_LIT(KLog,"Pointer  SS=%d (1)  Type=%d (%d)  GpWinOrdPos=%d (1)");
   1.236 +	iTest->LOG_MESSAGE5(KLog,iTest->SubState(),pointer.iType,TPointerEvent::EButton1Down,Client()->iGroup->GroupWin()->OrdinalPosition());
   1.237 +#endif
   1.238 +	if (pointer.iType==TPointerEvent::EButton1Down)
   1.239 +		{
   1.240 +		switch(iTest->SubState())
   1.241 +			{
   1.242 +			case 1:
   1.243 +				iTest->TEST(Client()->iGroup->GroupWin()->OrdinalPosition()==1);
   1.244 +				iTest->IncSubState();
   1.245 +				break;
   1.246 +			}
   1.247 +		}
   1.248 +	}
   1.249 +
   1.250 +void CMcWindow::Draw()
   1.251 +	{
   1.252 +	iGc->Clear();
   1.253 +	TBuf<0x40> buf;
   1.254 +	switch(iTest->SubState())
   1.255 +		{
   1.256 +		case 1:
   1.257 +			buf.Copy(ClickOnMe);
   1.258 +			break;
   1.259 +		case 0:
   1.260 +		case 2:
   1.261 +		case 3:
   1.262 +			buf.Copy(KNullDesC);
   1.263 +			break;
   1.264 +		default:
   1.265 +			buf.Copy(KError);
   1.266 +		}
   1.267 +	iGc->DrawText(buf, TPoint(10,20));
   1.268 +	}
   1.269 +
   1.270 +//
   1.271 +// CMcWindowAf, Auto foreground version of CMcWindow //
   1.272 +//
   1.273 +
   1.274 +CMcWindowAf::CMcWindowAf(CTMultiCon *aTest) : CMcWindowBase(aTest)
   1.275 +	{
   1.276 +	iBack=TRgb::Gray256(150);
   1.277 +	}
   1.278 +
   1.279 +void CMcWindowAf::PointerL(const TPointerEvent &pointer,const TTime &)
   1.280 +	{
   1.281 +#if defined(LOGGING)
   1.282 +	_LIT(KLog,"PointerL  SS=%d (2)  Type=%d (%d)  GpWinOrdPos=%d (0)");
   1.283 +	iTest->LOG_MESSAGE5(KLog,iTest->SubState(),pointer.iType,TPointerEvent::EButton1Down,Client()->iGroup->GroupWin()->OrdinalPosition());
   1.284 +#endif
   1.285 +	if (pointer.iType==TPointerEvent::EButton1Down)
   1.286 +		{
   1.287 +		switch(iTest->SubState())
   1.288 +			{
   1.289 +			case 2:
   1.290 +				iTest->TEST(Client()->iGroup->GroupWin()->OrdinalPosition()==0);
   1.291 +				iTest->IncSubState();
   1.292 +				break;
   1.293 +			}
   1.294 +		}
   1.295 +	}
   1.296 +
   1.297 +void CMcWindowAf::Draw()
   1.298 +	{
   1.299 +	_LIT(PressSpace,"Press <Space>");
   1.300 +	iGc->Clear();
   1.301 +	TBuf<0x40> buf;
   1.302 +	switch(iTest->SubState())
   1.303 +		{
   1.304 +		case 1:
   1.305 +		case 3:
   1.306 +			break;
   1.307 +		case 0:
   1.308 +			buf.Copy(PressSpace);
   1.309 +			break;
   1.310 +		case 2:
   1.311 +			buf.Copy(ClickOnMe);
   1.312 +			break;
   1.313 +		default:
   1.314 +			buf.Copy(KError);
   1.315 +		}
   1.316 +	iGc->DrawText(buf, TPoint(10,20));
   1.317 +	}
   1.318 +
   1.319 +//
   1.320 +
   1.321 +CMcWindowGroupAf::CMcWindowGroupAf(CTClient *aClient) : CTWindowGroup(aClient)
   1.322 +	{}
   1.323 +
   1.324 +void CMcWindowGroupAf::KeyL(const TKeyEvent &aKey, const TTime &)
   1.325 +	{
   1.326 +	((CMcConnectionAf *)iClient)->KeyL(aKey);
   1.327 +	}
   1.328 +
   1.329 +//
   1.330 +// CMcWindowDef, Default auto foreground version of CMcWindow //
   1.331 +//
   1.332 +
   1.333 +CMcWindowDef::CMcWindowDef(CTMultiCon *aTest) : CMcWindowBase(aTest)
   1.334 +	{
   1.335 +	iBack=TRgb::Gray256(236);
   1.336 +	}
   1.337 +
   1.338 +void CMcWindowDef::PointerL(const TPointerEvent &pointer,const TTime &)
   1.339 +	{
   1.340 +#if defined(LOGGING)
   1.341 +	_LIT(KLog,"PointerL  SS=%d (3)  Type=%d (%d)  GpWinOrdPos=%d (0)");
   1.342 +	iTest->LOG_MESSAGE5(KLog,iTest->SubState(),pointer.iType,TPointerEvent::EButton1Down,Client()->iGroup->GroupWin()->OrdinalPosition());
   1.343 +#endif
   1.344 +	if (pointer.iType==TPointerEvent::EButton1Down)
   1.345 +		{
   1.346 +		switch(iTest->SubState())
   1.347 +			{
   1.348 +			case 3:
   1.349 +				iTest->TEST(Client()->iGroup->GroupWin()->OrdinalPosition()==0);
   1.350 +				iTest->IncSubState();
   1.351 +				break;
   1.352 +			}
   1.353 +		}
   1.354 +	}
   1.355 +
   1.356 +void CMcWindowDef::Draw()
   1.357 +	{
   1.358 +	iGc->Clear();
   1.359 +	TBuf<0x40> buf;
   1.360 +	switch(iTest->SubState())
   1.361 +		{
   1.362 +		case 0:
   1.363 +		case 1:
   1.364 +		case 2:
   1.365 +			break;
   1.366 +		case 3:
   1.367 +			buf.Copy(ClickOnMe);
   1.368 +			break;
   1.369 +		default:
   1.370 +			buf.Copy(KError);
   1.371 +		}
   1.372 +	iGc->DrawText(buf, TPoint(10,20));
   1.373 +	}
   1.374 +
   1.375 +//
   1.376 +
   1.377 +TInt CTMultiCon::SubState() const
   1.378 +	{
   1.379 +	return(iSubState);
   1.380 +	}
   1.381 +
   1.382 +void CTMultiCon::IncSubState()
   1.383 +	{
   1.384 +	if (iSubState==EMaxSubState)
   1.385 +		EndAutoForegroundTest();
   1.386 +	else
   1.387 +		{
   1.388 +		iSubState++;
   1.389 +	#if defined(LOGGING)
   1.390 +		_LIT(KLog,"New SubState %d");
   1.391 +		LOG_MESSAGE2(KLog,iSubState);
   1.392 +	#endif
   1.393 +		iConn1->SubStateChanged();
   1.394 +		iConn2->SubStateChanged();
   1.395 +		iConn3->SubStateChanged();
   1.396 +		TheClient->WaitForRedrawsToFinish();
   1.397 +		SendEvents();
   1.398 +		}
   1.399 +	}
   1.400 +
   1.401 +void CTMultiCon::SendEvents()
   1.402 +	{
   1.403 +#if defined(LOGGING)
   1.404 +	_LIT(KLog,"Sending event for substate %d");
   1.405 +	LOG_MESSAGE2(KLog,iSubState);
   1.406 +#endif
   1.407 +
   1.408 +	switch (iSubState)
   1.409 +		{
   1.410 +	case 0:
   1.411 +		iTest->SimulateKeyDownUp(EStdKeySpace);
   1.412 +		break;
   1.413 +	case 1:
   1.414 +		iTest->SimulatePointerDownUp(iScreenSize.iWidth/6+5,iScreenSize.iHeight/4);
   1.415 +		break;
   1.416 +	case 2:
   1.417 +		iTest->SimulatePointerDownUp(iScreenSize.iWidth/2,iScreenSize.iHeight/4);
   1.418 +		break;
   1.419 +	case 3:
   1.420 +		iTest->SimulatePointerDownUp(iScreenSize.iWidth/3,3*iScreenSize.iHeight/4-5);
   1.421 +		break;
   1.422 +	default:
   1.423 +		TEST(EFalse);
   1.424 +		}
   1.425 +	TheClient->iWs.Flush();
   1.426 +	}
   1.427 +
   1.428 +void CTMultiCon::RunTestCaseL(TInt /*aCurTestCase*/)
   1.429 +	{
   1.430 +	_LIT(KTestMultiCon1,"MultiCon 1");
   1.431 +	_LIT(KTimeOut,"Test Timed Out after %dsecs.  SubState=%d");
   1.432 +	((CTMultiConStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   1.433 +	
   1.434 +	if (!TestBase()->ConfigurationSupportsPointerEventTesting())
   1.435 +	    {
   1.436 +	    INFO_PRINTF1(_L("Test skipped because config does not support pointer event testing"));
   1.437 +	    TestComplete();
   1.438 +	    return;
   1.439 +	    }
   1.440 +    
   1.441 +	switch(++iTest->iState)
   1.442 +		{
   1.443 +/**
   1.444 +
   1.445 +  @SYMTestCaseID GRAPHICS-WSERV-0289
   1.446 +  
   1.447 +  @SYMDEF             DEF081259
   1.448 + 
   1.449 +  @SYMTestCaseDesc Test multiple connections to the window server
   1.450 +    
   1.451 +  @SYMTestPriority High
   1.452 + 
   1.453 +  @SYMTestStatus Implemented
   1.454 + 
   1.455 +  @SYMTestActions Make mutiple connections to the window server and check
   1.456 +  				  that the connections are made corectly
   1.457 +  
   1.458 +  @SYMTestExpectedResults The connections are made correctly
   1.459 + 
   1.460 +*/		
   1.461 +		case 1:
   1.462 +			((CTMultiConStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0289"));
   1.463 +			iTest->LogSubTest(KTestMultiCon1);
   1.464 +			iTimeOut->Start(KTimeOutAfter,TCallBack(CTMultiCon::TimeOut,this));
   1.465 +			SendEvents();
   1.466 +			CActiveScheduler::Start();
   1.467 +			iTimeOut->Cancel();
   1.468 +			TEST(iTimeOutCount==0);
   1.469 +			if (iTimeOutCount!=0)
   1.470 +				LOG_MESSAGE3(KTimeOut,KTimeOutAfter/1000000,iSubState);
   1.471 +			break;
   1.472 +		default:
   1.473 +			((CTMultiConStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.474 +			((CTMultiConStep*)iStep)->CloseTMSGraphicsStep();
   1.475 +			TestComplete();
   1.476 +			break;
   1.477 +		}
   1.478 +	((CTMultiConStep*)iStep)->RecordTestResultL();
   1.479 +	}
   1.480 +
   1.481 +__WS_CONSTRUCT_STEP__(MultiCon)