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