os/graphics/windowing/windowserver/test/tman/TMAN.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/TMAN.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,490 @@
     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 +// Manual window server tests
    1.18 +// Note: Wherever possible tests should be put into the TAUTO automatic test
    1.19 +// code test should only go here when manual operation is essential
    1.20 +// 
    1.21 +//
    1.22 +
    1.23 +#include <e32std.h>
    1.24 +#include "W32STD.H"
    1.25 +#include <e32svr.h>
    1.26 +#include "TMAN.H"
    1.27 +
    1.28 +#define LOG_TESTS
    1.29 +
    1.30 +class ErrorDialog : public CTDialog
    1.31 +	{
    1.32 +public:
    1.33 +	ErrorDialog(CTestBase *aTest);
    1.34 +	void ButtonPressL(TInt aButton);
    1.35 +private:
    1.36 +	CTestBase *iTest;
    1.37 +	};
    1.38 +
    1.39 +class TestWindowGroup : public CTWindowGroup
    1.40 +	{
    1.41 +public:
    1.42 +	TestWindowGroup(CTClient *aClient);
    1.43 +	void ConstructL();
    1.44 +	void KeyL(const TKeyEvent &aKey,const TTime &aTime);
    1.45 +	void KeyDownL(const TKeyEvent &aKey,const TTime &aTime);
    1.46 +	void KeyUpL(const TKeyEvent &aKey,const TTime &aTime);
    1.47 +	};
    1.48 +
    1.49 +class CTManScheduler : public CActiveScheduler
    1.50 +	{
    1.51 +public:
    1.52 +	void SetClient(TestClient *aClient);
    1.53 +	void Error(TInt anError) const;
    1.54 +private:
    1.55 +	void doErrorL(TInt anError) const;
    1.56 +private:
    1.57 +	TestClient *iClient;
    1.58 +	};
    1.59 +
    1.60 +typedef CTestBase *(*CTestBaseCreate)();
    1.61 +
    1.62 +GLREF_C CTestBase *CreateScreenModeTest();
    1.63 +GLREF_C CTestBase *CreateScaleTest();
    1.64 +GLREF_C CTestBase *CreateTextTest();
    1.65 +GLREF_C CTestBase *CreateDummyTest();
    1.66 +GLREF_C CTestBase *CreateMultiConTest();
    1.67 +GLREF_C CTestBase *CreateMultiCaptureKeyTest();
    1.68 +GLREF_C CTestBase *CreateHotKeyTest();
    1.69 +GLREF_C CTestBase *CreatePointerTest();
    1.70 +GLREF_C CTestBase *CreatePointerCaptureTest();
    1.71 +GLREF_C CTestBase *CreatePointerBufferTest();
    1.72 +GLREF_C CTestBase *CreateModifiersChangedTest();
    1.73 +GLREF_C CTestBase *CreatePointerKeyTest();
    1.74 +GLREF_C CTestBase *CreatePasswordTest();
    1.75 +GLREF_C CTestBase *CreatePointerCursorTest();
    1.76 +GLREF_C CTestBase *CreateScreenModeTimes();
    1.77 +
    1.78 +// Tests that have not been converted to tauto yet
    1.79 +CTestBaseCreate CreateTestClass[]={
    1.80 +	CreateScreenModeTimes,
    1.81 +	CreatePointerCursorTest,
    1.82 +	CreatePointerTest,			//Mostly converted
    1.83 +	CreatePointerKeyTest,		//Mostly converted
    1.84 +	CreateModifiersChangedTest,		//Partially Conerted
    1.85 +	CreatePointerBufferTest,
    1.86 +	CreateTextTest,
    1.87 +	CreateScaleTest,
    1.88 +	CreateDummyTest,
    1.89 +	};
    1.90 +
    1.91 +LogWindow *LogWin;
    1.92 +
    1.93 +void TManPanic(TInt aPanic)
    1.94 +	{
    1.95 +	User::Panic(_L("Auto"),aPanic);
    1.96 +	}
    1.97 +
    1.98 +//
    1.99 +// Log window, logs testing //
   1.100 +//
   1.101 +
   1.102 +LogWindow::LogWindow() : CTWin()
   1.103 +	{
   1.104 +	}
   1.105 +
   1.106 +void LogWindow::ConstructL(CTWinBase &parent)
   1.107 +	{
   1.108 +	CTWin::ConstructL(parent);
   1.109 +	iTitleHeight=iFont->HeightInPixels()+4;
   1.110 +	}
   1.111 +
   1.112 +void LogWindow::Draw()
   1.113 +	{
   1.114 +	iGc->SetPenColor(TRgb::Gray16(8));
   1.115 +	iGc->SetPenColor(TRgb::Gray16(0));
   1.116 +	DrawBorder();
   1.117 +	iGc->DrawLine(TPoint(0,iTitleHeight),TPoint(iSize.iWidth,iTitleHeight));
   1.118 +	iGc->DrawText(iTestTitle, TPoint((iSize.iWidth-iFont->TextWidthInPixels(iTestTitle))/2,iFont->AscentInPixels()+2));
   1.119 +	}
   1.120 +
   1.121 +void LogWindow::LogTest(TDesC &aTitle,TInt aNum)
   1.122 +	{
   1.123 +	iTestTitle.Format(TRefByValue<const TDesC>(_L("Test %d,%S")),aNum,&aTitle);
   1.124 +	iWin.Invalidate();
   1.125 +	Client()->iWs.Flush();
   1.126 +	}
   1.127 +
   1.128 +//
   1.129 +// Test window, simple window used to do test graphics in //
   1.130 +//
   1.131 +TestWindow::TestWindow() : CTWin()
   1.132 +	{
   1.133 +	}
   1.134 +
   1.135 +void TestWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
   1.136 +	{
   1.137 +	iBorderWin=new(ELeave) BorderWindow();
   1.138 +	iBorderWin->SetUpL(pos,size,parent,aGc);
   1.139 +	CTWin::ConstructExtLD(*iBorderWin,TPoint(2,2),TSize(size.iWidth-4,size.iHeight-4));
   1.140 +	Activate();
   1.141 +	AssignGC(aGc);
   1.142 +	}
   1.143 +
   1.144 +void TestWindow::Draw()
   1.145 +	{
   1.146 +	iGc->Clear();
   1.147 +	}
   1.148 +
   1.149 +//
   1.150 +BorderWindow::BorderWindow() : CTWin()
   1.151 +	{
   1.152 +	}
   1.153 +
   1.154 +void BorderWindow::ConstructL(CTWinBase &parent)
   1.155 +	{
   1.156 +	CTWin::ConstructL(parent);
   1.157 +	}
   1.158 +
   1.159 +void BorderWindow::Draw()
   1.160 +	{
   1.161 +	iGc->SetBrushColor(TRgb::Gray16(0));
   1.162 +	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.163 +	iGc->SetPenStyle(CGraphicsContext::ENullPen);
   1.164 +	iGc->DrawRect(TRect(Size()));
   1.165 +	}
   1.166 +
   1.167 +//
   1.168 +
   1.169 +TestWindowGroup::TestWindowGroup(CTClient *aClient) : CTWindowGroup(aClient)
   1.170 +	{
   1.171 +	}
   1.172 +
   1.173 +void TestWindowGroup::ConstructL()
   1.174 +	{
   1.175 +	CTWindowGroup::ConstructL();
   1.176 +	GroupWin()->EnableScreenChangeEvents();
   1.177 +	}
   1.178 +
   1.179 +void TestWindowGroup::KeyDownL(const TKeyEvent &aKey,const TTime &aTime)
   1.180 +	{
   1.181 +	if (iCurWin)
   1.182 +		iCurWin->KeyDownL(aKey,aTime);
   1.183 +	}
   1.184 +
   1.185 +void TestWindowGroup::KeyUpL(const TKeyEvent &aKey,const TTime &aTime)
   1.186 +	{
   1.187 +	if (iCurWin)
   1.188 +		iCurWin->KeyUpL(aKey,aTime);
   1.189 +	}
   1.190 +
   1.191 +void TestWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &aTime)
   1.192 +	{
   1.193 +	if (aKey.iModifiers&EModifierFunc)
   1.194 +		{
   1.195 +		switch(aKey.iCode)
   1.196 +			{
   1.197 +			case 'f':
   1.198 +				((TestClient *)Client())->Driver()->iTest->TriggerFail();
   1.199 +				break;
   1.200 +			}
   1.201 +		}
   1.202 +	else if (iCurWin)
   1.203 +		iCurWin->WinKeyL(aKey,aTime);
   1.204 +	}
   1.205 +
   1.206 +//
   1.207 +
   1.208 +TestClient::TestClient()
   1.209 +	{
   1.210 +	}
   1.211 +
   1.212 +void TestClient::ConstructL()
   1.213 +	{
   1.214 +	CTClient::ConstructL();
   1.215 +
   1.216 +	iGroup=new(ELeave) TestWindowGroup(this);
   1.217 +	iGroup->ConstructL();
   1.218 +
   1.219 +	TSize screenSize=iGroup->Size();
   1.220 +	TInt winWidth=(screenSize.iWidth/3)-10;
   1.221 +	TInt winHeight=screenSize.iHeight-10;
   1.222 +	LogWin=new(ELeave) LogWindow();
   1.223 +	LogWin->SetUpL(TPoint(5+winWidth*2,5),TSize(winWidth,winHeight),iGroup,*iGc);
   1.224 +	iDriver=new(ELeave) TestDriver(this);
   1.225 +	}
   1.226 +
   1.227 +TestClient::~TestClient()
   1.228 +	{
   1.229 +	delete iDriver;
   1.230 +	}
   1.231 +
   1.232 +TestDriver *TestClient::Driver()
   1.233 +	{
   1.234 +	return(iDriver);
   1.235 +	}
   1.236 +
   1.237 +//
   1.238 +// Error dialog //
   1.239 +//
   1.240 +
   1.241 +ErrorDialog::ErrorDialog(CTestBase *aTest) : CTDialog(), iTest(aTest)
   1.242 +	{}
   1.243 +
   1.244 +void ErrorDialog::ButtonPressL(TInt aButton)
   1.245 +	{
   1.246 +	switch(aButton)
   1.247 +		{
   1.248 +		case 0:
   1.249 +			{
   1.250 +			CTestBase *test=iTest;
   1.251 +			CTDialog::Delete(this);
   1.252 +			if (test)
   1.253 +				test->Driver()->DestroyTest();
   1.254 +			CActiveScheduler::Stop();
   1.255 +			User::Leave(0);		// Signals RunL not to do another request
   1.256 +			}
   1.257 +			break;
   1.258 +		case 1:
   1.259 +			CTestBase *test=iTest;
   1.260 +			CTDialog::Delete(this);
   1.261 +			if (test)
   1.262 +				{
   1.263 +				test->Driver()->TestComplete();
   1.264 +				test->Driver()->DestroyTest();
   1.265 +				}
   1.266 +			break;
   1.267 +		}
   1.268 +	}
   1.269 +
   1.270 +//
   1.271 +// TestDriver, drives the test code //
   1.272 +//
   1.273 +
   1.274 +TestDriver::TestDriver(TestClient *aClient) : CActive(-10), iClient(aClient)
   1.275 +	{
   1.276 +	CActiveScheduler::Add(this);
   1.277 +	Request();
   1.278 +	}
   1.279 +
   1.280 +TestClient *TestDriver::Client()
   1.281 +	{
   1.282 +	return(iClient);
   1.283 +	}
   1.284 +
   1.285 +TestDriver::~TestDriver()
   1.286 +	{
   1.287 +	Cancel();
   1.288 +	DestroyTest();
   1.289 +	}
   1.290 +
   1.291 +void TestDriver::DoCancel()
   1.292 +	{
   1.293 +	TRequestStatus *pStat= &iStatus;
   1.294 +	RThread().RequestComplete(pStat,KErrCancel);
   1.295 +	}
   1.296 +
   1.297 +void TestDriver::Request()
   1.298 +	{
   1.299 +	TRequestStatus *pStat= &iStatus;
   1.300 +	RThread().RequestComplete(pStat,KErrNone);
   1.301 +	SetActive();
   1.302 +	}
   1.303 +
   1.304 +void TestDriver::RunL()
   1.305 +	{
   1.306 +	iTest=(*CreateTestClass[iTestNum])();
   1.307 +	iTest->StartTest(iTestNum,this);
   1.308 +	iTest->ConstructL();
   1.309 +	}
   1.310 +
   1.311 +void TestDriver::TestComplete()
   1.312 +	{
   1.313 +	iTestNum++;
   1.314 +	if (iTestNum==sizeof(CreateTestClass)/sizeof(CreateTestClass[0]))
   1.315 +		{
   1.316 +		DisplayDialog(_L("Tests complete"),_L(""),_L(""));
   1.317 +		CActiveScheduler::Stop();
   1.318 +		}
   1.319 +	else
   1.320 +		Request();
   1.321 +	}
   1.322 +
   1.323 +void TestDriver::DestroyTest()
   1.324 +	{
   1.325 +	delete iTest;
   1.326 +	iTest=NULL;
   1.327 +	}
   1.328 +
   1.329 +// CTestBase //
   1.330 +
   1.331 +CTestBase::CTestBase(const TDesC &aTitle) : CActive(-10)
   1.332 +	{
   1.333 +	CActiveScheduler::Add(this);
   1.334 +	iTitle.Copy(aTitle);
   1.335 +	}
   1.336 +
   1.337 +CTestBase::~CTestBase()
   1.338 +	{
   1.339 +	User::Free(iBuf1);
   1.340 +	User::Free(iBuf2);
   1.341 +	Cancel();
   1.342 +	}
   1.343 +
   1.344 +void CTestBase::DoCancel()
   1.345 +	{
   1.346 +	TRequestStatus *pStat= &iStatus;
   1.347 +	RThread().RequestComplete(pStat,KErrCancel);
   1.348 +	}
   1.349 +
   1.350 +void CTestBase::Request()
   1.351 +	{
   1.352 +	TRequestStatus *pStat= &iStatus;
   1.353 +	RThread().RequestComplete(pStat,KErrNone);
   1.354 +	SetActive();
   1.355 +	}
   1.356 +
   1.357 +void CTestBase::TriggerFail()
   1.358 +	{
   1.359 +	iFail=ETrue;
   1.360 +	}
   1.361 +
   1.362 +TestClient *CTestBase::Client()
   1.363 +	{
   1.364 +	return(iDriver->Client());
   1.365 +	}
   1.366 +
   1.367 +void CTestBase::LogLeave(TInt aErr)
   1.368 +	{
   1.369 +#if defined(LOG_TESTS)
   1.370 +	TLogMessageText buf;
   1.371 +	_LIT(KLeave,"MAN Left with error code %d in sub-test %d: ");
   1.372 +	buf.AppendFormat(KLeave,aErr,iSubTestNum);
   1.373 +	buf.Append(iSubTitle);
   1.374 +	Client()->LogMessage(buf);
   1.375 +#else
   1.376 +	aErr=KErrNone;		//To stop a warning
   1.377 +#endif
   1.378 +	}
   1.379 +
   1.380 +void CTestBase::RunL()
   1.381 +	{
   1.382 +	TInt ret=EInvalid;
   1.383 +	TRAPD(err,ret=DoTestL());
   1.384 +	if (err!=KErrNone)
   1.385 +		{
   1.386 +		LogLeave(err);
   1.387 +		if (err!=ETestFailed)
   1.388 +			{
   1.389 +			User::Leave(err);
   1.390 +			}
   1.391 +		}
   1.392 +	else if (ret==EFinished)
   1.393 +		{
   1.394 +		iDriver->TestComplete();
   1.395 +		iDriver->DestroyTest();
   1.396 +		}
   1.397 +	else if (ret==ENext)
   1.398 +		Request();
   1.399 +	}
   1.400 +
   1.401 +void CTestBase::StartTest(TInt aNum, TestDriver *aDriver)
   1.402 +	{
   1.403 +	iDriver=aDriver;
   1.404 +	iTestNum=aNum;
   1.405 +	LogWin->LogTest(iTitle,aNum);
   1.406 +#if defined(LOG_TESTS)
   1.407 +	TLogMessageText buf;
   1.408 +	_LIT(ManNewTest,"MAN New Test %d: ");
   1.409 +	buf.AppendFormat(ManNewTest,aNum);
   1.410 +	buf.Append(iTitle);
   1.411 +	Client()->LogMessage(buf);
   1.412 +#endif
   1.413 +	Request();
   1.414 +	}
   1.415 +
   1.416 +void CTestBase::LogSubTest(const TDesC &aSubTitle,TInt aNum)
   1.417 +	{
   1.418 +	iSubTestNum=aNum;
   1.419 +	iSubTitle=aSubTitle;
   1.420 +#if defined(LOG_TESTS)
   1.421 +	TLogMessageText buf;
   1.422 +	_LIT(ManSubTest,"MAN SubTest %d: ");
   1.423 +	buf.AppendFormat(ManSubTest,iSubTestNum);
   1.424 +	buf.Append(iSubTitle);
   1.425 +	Client()->LogMessage(buf);
   1.426 +#endif
   1.427 +	}
   1.428 +
   1.429 +void CTestBase::AbortL()
   1.430 +	{
   1.431 +	TestDriver *driver=iDriver;			
   1.432 +	iDriver->DestroyTest();
   1.433 +	driver->TestComplete();
   1.434 +	User::Leave(ETestFailed);
   1.435 +	}
   1.436 +
   1.437 +void CTestBase::TestL(TInt aCondition)
   1.438 +	{
   1.439 +	if (!aCondition || iFail)
   1.440 +		{
   1.441 +		iFail=EFalse;
   1.442 +  		ErrorDialog *dialog=new ErrorDialog(this);
   1.443 +		if (dialog)
   1.444 +			{
   1.445 +			dialog->SetTitle(_L("Test failed"));
   1.446 +			dialog->SetNumButtons(2);
   1.447 +			dialog->SetButtonText(0,_L("Abort all tests"));
   1.448 +			dialog->SetButtonText(1,_L("Continue other tests"));
   1.449 +			dialog->ConstructLD(*Client()->iGroup,*Client()->iGc);
   1.450 +			dialog->Display();
   1.451 +			}
   1.452 +		User::Leave(ETestFailed);
   1.453 +		}
   1.454 +	}
   1.455 +
   1.456 +void CTManScheduler::SetClient(TestClient *aClient)
   1.457 +	{
   1.458 +	iClient=aClient;
   1.459 +	}
   1.460 +
   1.461 +void CTManScheduler::Error(TInt aError) const
   1.462 +	{
   1.463 +	TRAP_IGNORE(doErrorL(aError));
   1.464 +	CActiveScheduler::Stop();
   1.465 +	}
   1.466 +
   1.467 +void CTManScheduler::doErrorL(TInt aError) const
   1.468 +	{
   1.469 +	CTDialog *dialog=new(ELeave) CTDialog();
   1.470 +	if (dialog)
   1.471 +		{
   1.472 +		TWindowTitle title;
   1.473 +		title.Format(TRefByValue<const TDesC>(_L("Error %d")),aError);
   1.474 +		dialog->SetTitle(title);
   1.475 +		dialog->SetNumButtons(1);
   1.476 +		dialog->SetButtonText(0,_L("Abort tests"));
   1.477 +		dialog->ConstructLD(*iClient->iGroup,*iClient->iGc);
   1.478 +		dialog->Display();
   1.479 +		}
   1.480 +	}
   1.481 +
   1.482 +//
   1.483 +
   1.484 +GLDEF_C CTClient *CreateClientL()
   1.485 +	{
   1.486 +	return(new(ELeave) TestClient());
   1.487 +	}
   1.488 +
   1.489 +
   1.490 +GLDEF_C TInt E32Main()
   1.491 +{
   1.492 +return(TestLibStartUp(CreateClientL));
   1.493 +}