os/graphics/windowing/windowserver/test/tauto/TOOMDRAW.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Test out of memory redraws
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @test
    21  @internalComponent - Internal Symbian test code
    22 */
    23 
    24 #include "TOOMDRAW.H"
    25 
    26 void DrawTestScreen(CWindowGc *aGc, const TSize &aSize)
    27 	{
    28 	aGc->SetPenSize(TSize(10,10));
    29 	aGc->SetBrushStyle(CGraphicsContext::EVerticalHatchBrush);
    30 	aGc->DrawRect(TRect(aSize));
    31 	}
    32 
    33 CTestWin::CTestWin()
    34 	{
    35 	}
    36 
    37 void CTestWin::Draw()
    38 	{
    39 #if defined(FULLLOGGING)
    40 	_LIT(KLog,"Drawing Test Win:%d  %d,%d");
    41 	TLogMessageText buf;
    42 	buf.Format(KLog,Size().iWidth>320?1:0,Size().iWidth,Size().iHeight);
    43 	TheClient->LogMessage(buf);
    44 #endif
    45 	DrawTestScreen(iGc,Size());
    46 	}
    47 
    48 CBaseTestWin::CBaseTestWin() : CTBackedUpWin(EGray4)
    49 	{}
    50 
    51 void CBaseTestWin::Resized(const TSize &aNewSize)
    52 	{
    53 	TheGc->Activate(*DrawableWin());
    54 	DrawTestScreen(TheGc,aNewSize);
    55 	TheGc->Deactivate();
    56 	}
    57 
    58 CToomDraw::CToomDraw(CTestStep* aStep):
    59 	CTWsGraphicsBase(aStep)
    60 	{
    61 	}
    62 
    63 CToomDraw::~CToomDraw()
    64 	{
    65 	TheClient->iWs.HeapSetFail(RHeap::ENone,0);		//In case the test crashes and it hasn't been reset
    66 	DeleteWindows();
    67 	}
    68 
    69 void CToomDraw::DeleteWindows()
    70 	{
    71 	delete iTestWin;
    72 	iTestWin=NULL;
    73 	delete iBaseWin;
    74 	iBaseWin=NULL;
    75 	delete iBackWin;
    76 	iBackWin=NULL;
    77 	delete iBlankWin;
    78 	iBlankWin=NULL;
    79 	}
    80 
    81 void CToomDraw::ConstructL()
    82 	{
    83 	iScrSize=TheClient->iScreen->SizeInPixels();
    84 	iBlankWin=new(ELeave) CTBlankWindow;
    85 	iBlankWin->ConstructL(*TheClient->iGroup);
    86 	iBlankWin->SetColor(TRgb::Gray4(2));		//Grey
    87 	iBlankWin->Activate();
    88 	iBackWin=new(ELeave) CTestWin();
    89 	iBackWin->SetUpL(TPoint(0,iScrSize.iHeight/4), TSize(iScrSize.iWidth,iScrSize.iHeight/2), TheClient->iGroup, *TheClient->iGc);
    90 	iBaseWin=new(ELeave) CBaseTestWin();
    91 	iBaseWin->SetUpL(TPoint(iScrSize.iWidth*2/3,0), TSize(iScrSize.iWidth/3,iScrSize.iHeight), TheClient->iGroup, *TheClient->iGc);
    92 	}
    93 
    94 void CToomDraw::CreateTestWinL()
    95 	{
    96 	iTestWin=new(ELeave) CTestWin();
    97 	iTestWin->ConstructL(*TheClient->iGroup);
    98 	iTestWin->SetExtL(TPoint(0,0), TSize(iScrSize.iWidth/3,iScrSize.iHeight));
    99 	iTestWin->AssignGC(*TheClient->iGc);
   100 	iTestWin->BaseWin()->SetShadowHeight(2);
   101 	}
   102 
   103 void CToomDraw::TriggerOomDrawsL(TInt aCount)
   104 	{
   105 	if(iTestWin)
   106 		{
   107 		iTestWin->SetExtL(TPoint(),iScrSize);		
   108 		}
   109 	delete iTestWin;
   110 	iTestWin=NULL;
   111 	CreateTestWinL();
   112 	TheClient->iWs.HeapSetFail(RHeap::EDeterministic,aCount);
   113 	iTestWin->Activate();
   114 	TheClient->iWs.Finish();
   115 	}
   116 
   117 TBool CToomDraw::CheckWindowsL()
   118 	{
   119 	TLogMessageText buf;
   120 	TBool pass = DoCheckRect(iTestWin,iBaseWin);
   121 	if (pass)
   122 		{
   123 		TEST(ETrue);		//Adds one to test count
   124 	#if defined(FULLLOGGING)
   125 		_LIT(KLog,"OOM Draw Test Pass, State=%d");
   126 		buf.Format(KLog,iState);
   127 	#endif
   128 		iRetryCount=0;
   129 		}
   130 	else
   131 		{
   132 		if (iRetryCount==4)
   133 			{
   134 			if ((iTest->RedrawStoreTypeL()==EPartialRedraw_PreserveStoredCmds ||
   135 			iTest->RedrawStoreTypeL()==EPartialRedraw_FullRedrawSupport) && (iState==19 || iState==30) ||
   136 			((iState>=2 && iState<=6) && (iTest->RedrawStoreTypeL()==EPartialRedraw_None || iTest->RedrawStoreTypeL()==EPartialRedraw_FullRedrawSupport)))
   137 				{
   138 			#if defined(FULLLOGGING)
   139 				_LIT(KLog,"OOM Draw Test Known F a i l, State=%d");
   140 				buf.Format(KLog,iState);
   141 			#endif
   142 				pass=ETrue;
   143 				}
   144 			else
   145 				{
   146 				if (iFailAt==0)
   147 					iFailAt=iState;
   148 				++iFails; //mark this test as failed
   149 			#if defined(LOGGING)
   150 				_LIT(KLog,"OOM Draw Test FAIL, State=%d  <------- FAIL");
   151 				buf.Format(KLog,iState);
   152 			#endif
   153 				++iState; //and advance to next test
   154 				}
   155 			iRetryCount=0;
   156 			}
   157 		else
   158 			{
   159 		#if defined(FULLLOGGING)
   160 			_LIT(KLog,"OOM Draw Test F a i l, State=%d retrying");
   161 			buf.Format(KLog,iState);
   162 		#endif
   163 			if (++iRetryCount%2==0)
   164 				iBackWin->DrawNow();
   165 			}
   166 		}
   167 	if (buf.Length()>0)
   168 		TheClient->LogMessage(buf);
   169 	return pass;
   170 	}
   171 
   172 void CToomDraw::RunTestCaseL(TInt aCurTestCase)
   173 	{
   174 	TBool testFinished = false;
   175 	((CToomDrawStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   176 	switch(aCurTestCase)
   177 		{
   178 /**
   179 @SYMTestCaseID		GRAPHICS-WSERV-0110
   180 
   181 @SYMDEF             DEF081259
   182 
   183 @SYMTestCaseDesc    Test trying to draw when out of memory
   184 
   185 @SYMTestPriority    High
   186 
   187 @SYMTestStatus      Implemented
   188 
   189 @SYMTestActions     Set out of memory and try drawing
   190 
   191 @SYMTestExpectedResults Out of memory drawing is handle correctly
   192 */
   193 	case 1:
   194 		((CToomDrawStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0110"));
   195 		while (!testFinished)
   196 			{
   197 		if (iDoCheck)
   198 			{
   199 			TheClient->iWs.HeapSetFail(RHeap::ENone,0);
   200 			TheClient->WaitForRedrawsToFinish();
   201 			if (CheckWindowsL())
   202 				{
   203 				++iState;
   204 				if (iState==EMaxOOMState)
   205 					DeleteWindows();
   206 				}
   207 			iDoCheck=EFalse;
   208 			TheClient->iWs.Finish();
   209 			}
   210 		else
   211 			{
   212 			if (iState==EMaxOOMState)
   213 				{
   214 				if (iFails>0)
   215 					{
   216 			#if defined(LOGING)
   217 					_LIT(KLog,"OOM Draw Test Failed, First Fail At %d, Number of Fails %d");
   218 					TLogMessageText buf;
   219 					buf.Format(KLog,iFailAt,iFails);
   220 					TheClient->LogMessage(buf);
   221 			#endif
   222 					TEST(iFails==0);
   223 					}
   224 				User::After(500000);	// Let the rest of the world catch up after OOM death
   225 				testFinished = true;
   226 				}
   227 			else if (iState < 3 && iTest->IsFullRomL())
   228 				testFinished = true;
   229 			else
   230 				TriggerOomDrawsL(iState);
   231 			iDoCheck=ETrue;
   232 			}
   233 			}
   234 		break;
   235 	case 2:
   236 		((CToomDrawStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   237 		((CToomDrawStep*)iStep)->CloseTMSGraphicsStep();
   238 		TestComplete();
   239 		break;
   240 		}
   241 	((CToomDrawStep*)iStep)->RecordTestResultL();
   242 	}
   243 
   244 __WS_CONSTRUCT_STEP__(oomDraw)