os/graphics/windowing/windowserver/test/tauto/TOOMDRAW.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/TOOMDRAW.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,244 @@
     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 out of memory redraws
    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 "TOOMDRAW.H"
    1.28 +
    1.29 +void DrawTestScreen(CWindowGc *aGc, const TSize &aSize)
    1.30 +	{
    1.31 +	aGc->SetPenSize(TSize(10,10));
    1.32 +	aGc->SetBrushStyle(CGraphicsContext::EVerticalHatchBrush);
    1.33 +	aGc->DrawRect(TRect(aSize));
    1.34 +	}
    1.35 +
    1.36 +CTestWin::CTestWin()
    1.37 +	{
    1.38 +	}
    1.39 +
    1.40 +void CTestWin::Draw()
    1.41 +	{
    1.42 +#if defined(FULLLOGGING)
    1.43 +	_LIT(KLog,"Drawing Test Win:%d  %d,%d");
    1.44 +	TLogMessageText buf;
    1.45 +	buf.Format(KLog,Size().iWidth>320?1:0,Size().iWidth,Size().iHeight);
    1.46 +	TheClient->LogMessage(buf);
    1.47 +#endif
    1.48 +	DrawTestScreen(iGc,Size());
    1.49 +	}
    1.50 +
    1.51 +CBaseTestWin::CBaseTestWin() : CTBackedUpWin(EGray4)
    1.52 +	{}
    1.53 +
    1.54 +void CBaseTestWin::Resized(const TSize &aNewSize)
    1.55 +	{
    1.56 +	TheGc->Activate(*DrawableWin());
    1.57 +	DrawTestScreen(TheGc,aNewSize);
    1.58 +	TheGc->Deactivate();
    1.59 +	}
    1.60 +
    1.61 +CToomDraw::CToomDraw(CTestStep* aStep):
    1.62 +	CTWsGraphicsBase(aStep)
    1.63 +	{
    1.64 +	}
    1.65 +
    1.66 +CToomDraw::~CToomDraw()
    1.67 +	{
    1.68 +	TheClient->iWs.HeapSetFail(RHeap::ENone,0);		//In case the test crashes and it hasn't been reset
    1.69 +	DeleteWindows();
    1.70 +	}
    1.71 +
    1.72 +void CToomDraw::DeleteWindows()
    1.73 +	{
    1.74 +	delete iTestWin;
    1.75 +	iTestWin=NULL;
    1.76 +	delete iBaseWin;
    1.77 +	iBaseWin=NULL;
    1.78 +	delete iBackWin;
    1.79 +	iBackWin=NULL;
    1.80 +	delete iBlankWin;
    1.81 +	iBlankWin=NULL;
    1.82 +	}
    1.83 +
    1.84 +void CToomDraw::ConstructL()
    1.85 +	{
    1.86 +	iScrSize=TheClient->iScreen->SizeInPixels();
    1.87 +	iBlankWin=new(ELeave) CTBlankWindow;
    1.88 +	iBlankWin->ConstructL(*TheClient->iGroup);
    1.89 +	iBlankWin->SetColor(TRgb::Gray4(2));		//Grey
    1.90 +	iBlankWin->Activate();
    1.91 +	iBackWin=new(ELeave) CTestWin();
    1.92 +	iBackWin->SetUpL(TPoint(0,iScrSize.iHeight/4), TSize(iScrSize.iWidth,iScrSize.iHeight/2), TheClient->iGroup, *TheClient->iGc);
    1.93 +	iBaseWin=new(ELeave) CBaseTestWin();
    1.94 +	iBaseWin->SetUpL(TPoint(iScrSize.iWidth*2/3,0), TSize(iScrSize.iWidth/3,iScrSize.iHeight), TheClient->iGroup, *TheClient->iGc);
    1.95 +	}
    1.96 +
    1.97 +void CToomDraw::CreateTestWinL()
    1.98 +	{
    1.99 +	iTestWin=new(ELeave) CTestWin();
   1.100 +	iTestWin->ConstructL(*TheClient->iGroup);
   1.101 +	iTestWin->SetExtL(TPoint(0,0), TSize(iScrSize.iWidth/3,iScrSize.iHeight));
   1.102 +	iTestWin->AssignGC(*TheClient->iGc);
   1.103 +	iTestWin->BaseWin()->SetShadowHeight(2);
   1.104 +	}
   1.105 +
   1.106 +void CToomDraw::TriggerOomDrawsL(TInt aCount)
   1.107 +	{
   1.108 +	if(iTestWin)
   1.109 +		{
   1.110 +		iTestWin->SetExtL(TPoint(),iScrSize);		
   1.111 +		}
   1.112 +	delete iTestWin;
   1.113 +	iTestWin=NULL;
   1.114 +	CreateTestWinL();
   1.115 +	TheClient->iWs.HeapSetFail(RHeap::EDeterministic,aCount);
   1.116 +	iTestWin->Activate();
   1.117 +	TheClient->iWs.Finish();
   1.118 +	}
   1.119 +
   1.120 +TBool CToomDraw::CheckWindowsL()
   1.121 +	{
   1.122 +	TLogMessageText buf;
   1.123 +	TBool pass = DoCheckRect(iTestWin,iBaseWin);
   1.124 +	if (pass)
   1.125 +		{
   1.126 +		TEST(ETrue);		//Adds one to test count
   1.127 +	#if defined(FULLLOGGING)
   1.128 +		_LIT(KLog,"OOM Draw Test Pass, State=%d");
   1.129 +		buf.Format(KLog,iState);
   1.130 +	#endif
   1.131 +		iRetryCount=0;
   1.132 +		}
   1.133 +	else
   1.134 +		{
   1.135 +		if (iRetryCount==4)
   1.136 +			{
   1.137 +			if ((iTest->RedrawStoreTypeL()==EPartialRedraw_PreserveStoredCmds ||
   1.138 +			iTest->RedrawStoreTypeL()==EPartialRedraw_FullRedrawSupport) && (iState==19 || iState==30) ||
   1.139 +			((iState>=2 && iState<=6) && (iTest->RedrawStoreTypeL()==EPartialRedraw_None || iTest->RedrawStoreTypeL()==EPartialRedraw_FullRedrawSupport)))
   1.140 +				{
   1.141 +			#if defined(FULLLOGGING)
   1.142 +				_LIT(KLog,"OOM Draw Test Known F a i l, State=%d");
   1.143 +				buf.Format(KLog,iState);
   1.144 +			#endif
   1.145 +				pass=ETrue;
   1.146 +				}
   1.147 +			else
   1.148 +				{
   1.149 +				if (iFailAt==0)
   1.150 +					iFailAt=iState;
   1.151 +				++iFails; //mark this test as failed
   1.152 +			#if defined(LOGGING)
   1.153 +				_LIT(KLog,"OOM Draw Test FAIL, State=%d  <------- FAIL");
   1.154 +				buf.Format(KLog,iState);
   1.155 +			#endif
   1.156 +				++iState; //and advance to next test
   1.157 +				}
   1.158 +			iRetryCount=0;
   1.159 +			}
   1.160 +		else
   1.161 +			{
   1.162 +		#if defined(FULLLOGGING)
   1.163 +			_LIT(KLog,"OOM Draw Test F a i l, State=%d retrying");
   1.164 +			buf.Format(KLog,iState);
   1.165 +		#endif
   1.166 +			if (++iRetryCount%2==0)
   1.167 +				iBackWin->DrawNow();
   1.168 +			}
   1.169 +		}
   1.170 +	if (buf.Length()>0)
   1.171 +		TheClient->LogMessage(buf);
   1.172 +	return pass;
   1.173 +	}
   1.174 +
   1.175 +void CToomDraw::RunTestCaseL(TInt aCurTestCase)
   1.176 +	{
   1.177 +	TBool testFinished = false;
   1.178 +	((CToomDrawStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   1.179 +	switch(aCurTestCase)
   1.180 +		{
   1.181 +/**
   1.182 +@SYMTestCaseID		GRAPHICS-WSERV-0110
   1.183 +
   1.184 +@SYMDEF             DEF081259
   1.185 +
   1.186 +@SYMTestCaseDesc    Test trying to draw when out of memory
   1.187 +
   1.188 +@SYMTestPriority    High
   1.189 +
   1.190 +@SYMTestStatus      Implemented
   1.191 +
   1.192 +@SYMTestActions     Set out of memory and try drawing
   1.193 +
   1.194 +@SYMTestExpectedResults Out of memory drawing is handle correctly
   1.195 +*/
   1.196 +	case 1:
   1.197 +		((CToomDrawStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0110"));
   1.198 +		while (!testFinished)
   1.199 +			{
   1.200 +		if (iDoCheck)
   1.201 +			{
   1.202 +			TheClient->iWs.HeapSetFail(RHeap::ENone,0);
   1.203 +			TheClient->WaitForRedrawsToFinish();
   1.204 +			if (CheckWindowsL())
   1.205 +				{
   1.206 +				++iState;
   1.207 +				if (iState==EMaxOOMState)
   1.208 +					DeleteWindows();
   1.209 +				}
   1.210 +			iDoCheck=EFalse;
   1.211 +			TheClient->iWs.Finish();
   1.212 +			}
   1.213 +		else
   1.214 +			{
   1.215 +			if (iState==EMaxOOMState)
   1.216 +				{
   1.217 +				if (iFails>0)
   1.218 +					{
   1.219 +			#if defined(LOGING)
   1.220 +					_LIT(KLog,"OOM Draw Test Failed, First Fail At %d, Number of Fails %d");
   1.221 +					TLogMessageText buf;
   1.222 +					buf.Format(KLog,iFailAt,iFails);
   1.223 +					TheClient->LogMessage(buf);
   1.224 +			#endif
   1.225 +					TEST(iFails==0);
   1.226 +					}
   1.227 +				User::After(500000);	// Let the rest of the world catch up after OOM death
   1.228 +				testFinished = true;
   1.229 +				}
   1.230 +			else if (iState < 3 && iTest->IsFullRomL())
   1.231 +				testFinished = true;
   1.232 +			else
   1.233 +				TriggerOomDrawsL(iState);
   1.234 +			iDoCheck=ETrue;
   1.235 +			}
   1.236 +			}
   1.237 +		break;
   1.238 +	case 2:
   1.239 +		((CToomDrawStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.240 +		((CToomDrawStep*)iStep)->CloseTMSGraphicsStep();
   1.241 +		TestComplete();
   1.242 +		break;
   1.243 +		}
   1.244 +	((CToomDrawStep*)iStep)->RecordTestResultL();
   1.245 +	}
   1.246 +
   1.247 +__WS_CONSTRUCT_STEP__(oomDraw)