os/graphics/windowing/windowserver/test/tauto/TWSGRAPHS.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// This test step contains a series of tests cases to validate the correct behaviour of PREQ1246 implementation.
sl@0
    15
// In order to create these test cases, basic implementations of the objects involved in this PREQ will be created,
sl@0
    16
// .i.e. CWsGraphic-derived objects (generically named CWsGraphicTest) and CWsGraphicDrawer-derived objects
sl@0
    17
// (generically named CWsGraphicDrawerTest).
sl@0
    18
// Actual construction is performed by a UI-specific entity such as a theme manager. The test code shall replace
sl@0
    19
// that theme manager functionality, in terms of being the test code who owns a collection of CWsGraphicTest
sl@0
    20
// objects.
sl@0
    21
// 
sl@0
    22
//
sl@0
    23
sl@0
    24
/**
sl@0
    25
 @file
sl@0
    26
 @test
sl@0
    27
 @internalComponent - Internal Symbian test code
sl@0
    28
*/
sl@0
    29
sl@0
    30
#include "TWSGRAPHS.H"
sl@0
    31
#include "../inc/WSGRAPHICDRAWERARRAY.H"
sl@0
    32
#include "../../nga/graphicdrawer/panics.h"
sl@0
    33
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
sl@0
    34
#include "wsbufferdrawer.h"
sl@0
    35
#endif
sl@0
    36
sl@0
    37
_LIT(KTestExe, "TWSGRAPHICTEST.exe");
sl@0
    38
_LIT(KSpace, " ");
sl@0
    39
sl@0
    40
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
    41
const TInt KCustomTextCursorId = TTextCursor::ETypeLastBasic + 57; // 57 is arbitrary
sl@0
    42
#endif
sl@0
    43
sl@0
    44
CCrWin* CCrWin::NewL(TInt aScreenId, TBool aDraw)
sl@0
    45
	{
sl@0
    46
	CCrWin* win = new(ELeave) CCrWin;
sl@0
    47
	CleanupStack::PushL(win);
sl@0
    48
	win->ConstructL(aScreenId, aDraw);
sl@0
    49
	CleanupStack::Pop(win);
sl@0
    50
	return win;
sl@0
    51
	}
sl@0
    52
sl@0
    53
CCrWin::~CCrWin()
sl@0
    54
	{
sl@0
    55
	iWin.Close();
sl@0
    56
	iGroup.Close();
sl@0
    57
	delete iGc;
sl@0
    58
	delete iScr;
sl@0
    59
	iWs.Close();
sl@0
    60
	}
sl@0
    61
sl@0
    62
void CCrWin::ConstructL(TInt aScreenId, TBool aDraw)
sl@0
    63
	{
sl@0
    64
	User::LeaveIfError(iWs.Connect());
sl@0
    65
	iScr = new(ELeave) CWsScreenDevice(iWs);
sl@0
    66
	User::LeaveIfError(iScr->Construct(aScreenId));
sl@0
    67
	User::LeaveIfError(iScr->CreateContext(iGc));
sl@0
    68
	iGroup = RWindowGroup(iWs);
sl@0
    69
	User::LeaveIfError(iGroup.Construct(0xbadbabe,ETrue));
sl@0
    70
	iGroup.SetOrdinalPosition(0,100);
sl@0
    71
	iWin = RWindow(iWs);
sl@0
    72
	User::LeaveIfError(iWin.Construct(iGroup,0xbadcafe));
sl@0
    73
	iWin.SetRequiredDisplayMode(EColor64K);
sl@0
    74
	iWin.Activate();
sl@0
    75
	iWs.Flush();
sl@0
    76
	if (aDraw)
sl@0
    77
	Draw();
sl@0
    78
	}
sl@0
    79
sl@0
    80
void CCrWin::Draw()
sl@0
    81
	{
sl@0
    82
	iWin.BeginRedraw();
sl@0
    83
	iGc->Activate(iWin);
sl@0
    84
	iGc->SetBrushColor(KRgbRed);
sl@0
    85
	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
    86
	TRect rect(iScr->SizeInPixels());
sl@0
    87
	iGc->DrawRect(rect);
sl@0
    88
	iGc->SetBrushColor(KRgbBlue);
sl@0
    89
	iGc->DrawEllipse(TRect(rect.iTl.iX,rect.iTl.iY,rect.iBr.iX/2,rect.iBr.iY));
sl@0
    90
	iGc->DrawEllipse(TRect(rect.iBr.iX/2,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY));
sl@0
    91
	iGc->Deactivate();
sl@0
    92
	iWin.EndRedraw();
sl@0
    93
	iWs.Flush();
sl@0
    94
	}
sl@0
    95
sl@0
    96
sl@0
    97
void CCrWin::DrawFirstHalf()
sl@0
    98
	{
sl@0
    99
	iWin.BeginRedraw();
sl@0
   100
	iGc->Activate(iWin);
sl@0
   101
	iGc->SetBrushColor(KRgbRed);
sl@0
   102
	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   103
	TRect rect(TPoint(0,0),TSize(iScr->SizeInPixels().iWidth/2,iScr->SizeInPixels().iHeight));
sl@0
   104
	iGc->DrawRect(rect);
sl@0
   105
	iWs.Flush();	
sl@0
   106
	}
sl@0
   107
sl@0
   108
void CCrWin::DrawSecondHalf()
sl@0
   109
	{
sl@0
   110
	TRect rect(TPoint(iScr->SizeInPixels().iWidth/2,0),TSize(iScr->SizeInPixels().iWidth/2,iScr->SizeInPixels().iHeight));
sl@0
   111
	iGc->DrawRect(rect);
sl@0
   112
	iGc->Deactivate();
sl@0
   113
	iWin.EndRedraw();	
sl@0
   114
	iWs.Flush();		
sl@0
   115
	}
sl@0
   116
sl@0
   117
/** 
sl@0
   118
The objective of this function is, two animations should run independently
sl@0
   119
with respective frame rate in the given time interval.
sl@0
   120
The time delay allows to draw animations freely and the plug-in
sl@0
   121
calculates number of times DoDraw() function called during this interval.
sl@0
   122
sl@0
   123
@param TInt Wsgrphic test plug-in id.
sl@0
   124
*/
sl@0
   125
void CCrWin::DrawGraphic(TInt aWsId)
sl@0
   126
	{
sl@0
   127
	// draw the animation in two positions
sl@0
   128
	const TSize screenSize = iScr->SizeInPixels();	
sl@0
   129
	const TRect position(0,0,screenSize.iWidth/2,screenSize.iHeight);
sl@0
   130
	const TRect position2((screenSize.iWidth/2)+1,0,screenSize.iWidth,screenSize.iHeight);
sl@0
   131
	//PeterI if CWsGraphic animation areas overlap then when one redraws the other will as well.
sl@0
   132
	//2 separate positions are needed otherwise the framerates will be identical.
sl@0
   133
	
sl@0
   134
	iWin.BeginRedraw();
sl@0
   135
	iGc->Activate(iWin);
sl@0
   136
	const TUint8 animid1=0;
sl@0
   137
	const TUint8 fps1=20;
sl@0
   138
	TBuf8<2> animData1;
sl@0
   139
	animData1.Append(animid1);   //animId1
sl@0
   140
	animData1.Append(fps1); //20fps
sl@0
   141
	iGc->DrawWsGraphic(aWsId,position,animData1);
sl@0
   142
	iWs.Flush();
sl@0
   143
	User::After(200000);
sl@0
   144
	const TUint8 animid2=1;
sl@0
   145
	const TUint8 fps2=60;
sl@0
   146
	TBuf8<2> animData2;
sl@0
   147
	animData2.Append(animid2);   //animId2
sl@0
   148
	animData2.Append(fps2); //60fps
sl@0
   149
	iGc->DrawWsGraphic(aWsId,position2,animData2);
sl@0
   150
	iWs.Flush();
sl@0
   151
	User::After(200000);
sl@0
   152
	iGc->Deactivate();
sl@0
   153
	iWin.EndRedraw();
sl@0
   154
	iWs.Flush();
sl@0
   155
	}
sl@0
   156
sl@0
   157
/**
sl@0
   158
 * Set a standard text cursor on this window.
sl@0
   159
 * @see RWindowGroup::SetTextCursor()
sl@0
   160
 */
sl@0
   161
void CCrWin::SetTextCursor(const TPoint &aPos, const TTextCursor &aCursor)
sl@0
   162
	{
sl@0
   163
	iGroup.SetTextCursor(iWin, aPos, aCursor);
sl@0
   164
	}
sl@0
   165
sl@0
   166
/**
sl@0
   167
 * Cancel a text cursor from this window.
sl@0
   168
 * @see RWindowGroup::CancelTextCursor()
sl@0
   169
 */
sl@0
   170
void CCrWin::CancelTextCursor()
sl@0
   171
	{
sl@0
   172
	iGroup.CancelTextCursor();
sl@0
   173
	}
sl@0
   174
sl@0
   175
CCrAlphaWin* CCrAlphaWin::NewL(TInt aScreenId)
sl@0
   176
	{
sl@0
   177
	CCrAlphaWin* win = new(ELeave) CCrAlphaWin;
sl@0
   178
	CleanupStack::PushL(win);
sl@0
   179
	win->ConstructL(aScreenId);
sl@0
   180
	CleanupStack::Pop(win);
sl@0
   181
	return win;
sl@0
   182
	}
sl@0
   183
sl@0
   184
CCrAlphaWin::~CCrAlphaWin()
sl@0
   185
	{
sl@0
   186
	iWin.Close();
sl@0
   187
	iGroup.Close();
sl@0
   188
	delete iScr;
sl@0
   189
	iWs.Close();
sl@0
   190
	}
sl@0
   191
sl@0
   192
void CCrAlphaWin::ConstructL(TInt aScreenId)
sl@0
   193
	{
sl@0
   194
	User::LeaveIfError(iWs.Connect());
sl@0
   195
	iScr = new(ELeave) CWsScreenDevice(iWs);
sl@0
   196
	User::LeaveIfError(iScr->Construct(aScreenId));
sl@0
   197
	iGroup = RWindowGroup(iWs);
sl@0
   198
	User::LeaveIfError(iGroup.Construct(0xbadc0de,ETrue));
sl@0
   199
	iGroup.SetOrdinalPosition(0,100);
sl@0
   200
	iWin = RWindow(iWs);
sl@0
   201
	User::LeaveIfError(iWin.Construct(iGroup,0xbadbeef));
sl@0
   202
	iWin.SetRequiredDisplayMode(EColor64K);
sl@0
   203
	iWin.SetTransparencyAlphaChannel();
sl@0
   204
	iWin.SetBackgroundColor(TRgb(0xff,0xff,0,0x80));
sl@0
   205
	iWin.Activate();
sl@0
   206
	iWs.Flush();
sl@0
   207
	}
sl@0
   208
sl@0
   209
sl@0
   210
//
sl@0
   211
//  CTWsGraphs
sl@0
   212
//
sl@0
   213
sl@0
   214
CTWsGraphs::CTWsGraphs(CTestStep* aStep):
sl@0
   215
	CTWsGraphicsBase(aStep)
sl@0
   216
	{
sl@0
   217
	}
sl@0
   218
sl@0
   219
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   220
LOCAL_D void DeleteSpriteMember(TAny* aSpriteMember)
sl@0
   221
	{
sl@0
   222
	TSpriteMember* member=reinterpret_cast<TSpriteMember*>(aSpriteMember);
sl@0
   223
	delete member->iBitmap;
sl@0
   224
	member->iBitmap=NULL;
sl@0
   225
	delete member->iMaskBitmap;
sl@0
   226
	member->iMaskBitmap=NULL;
sl@0
   227
	}
sl@0
   228
#endif
sl@0
   229
sl@0
   230
CTWsGraphs::~CTWsGraphs()
sl@0
   231
	{
sl@0
   232
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   233
	DeleteSpriteMember(&iSpriteMemberArray[0]);
sl@0
   234
	iSpriteMemberArray.Close();
sl@0
   235
#endif
sl@0
   236
	delete iGdCoverage;
sl@0
   237
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   238
	delete iAfter;
sl@0
   239
	delete iBefore;
sl@0
   240
	delete iBackCopy;
sl@0
   241
	delete iFrontCopy;
sl@0
   242
#endif
sl@0
   243
	delete iListen;
sl@0
   244
	delete iNotify2;
sl@0
   245
	delete iNotify1;
sl@0
   246
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   247
	delete iRedir;
sl@0
   248
#endif
sl@0
   249
	}
sl@0
   250
sl@0
   251
void CTWsGraphs::ConstructL()
sl@0
   252
	{
sl@0
   253
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   254
	iRedir = CWsRedir::NewL(iTest->iScreenNumber,ETrue);
sl@0
   255
	iRedir->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
sl@0
   256
#endif
sl@0
   257
	iNotify1 = CWsNotify::NewL(EFalse);
sl@0
   258
	iNotify2 = CWsNotify::NewL(ETrue);
sl@0
   259
	iListen = CWsListen::NewL(ETrue);
sl@0
   260
	iListen->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
sl@0
   261
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   262
	iFrontCopy = new(ELeave) CFbsBitmap;
sl@0
   263
	iBackCopy = new(ELeave) CFbsBitmap;
sl@0
   264
	iBefore = new(ELeave) CFbsBitmap;
sl@0
   265
	User::LeaveIfError(iBefore->Create(TheClient->iScreen->SizeInPixels(), EColor64K));
sl@0
   266
	iAfter = new(ELeave) CFbsBitmap;
sl@0
   267
	User::LeaveIfError(iAfter->Create(TheClient->iScreen->SizeInPixels(), EColor64K));
sl@0
   268
#endif
sl@0
   269
	iGdCoverage = CWsGdCoverage::NewL();
sl@0
   270
	iGdCoverage->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
sl@0
   271
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   272
	TSpriteMember spriteMember;
sl@0
   273
	spriteMember.iBitmap = NULL;
sl@0
   274
	spriteMember.iMaskBitmap = NULL;
sl@0
   275
	spriteMember.iInvertMask =EFalse;
sl@0
   276
	spriteMember.iDrawMode = CGraphicsContext::EDrawModePEN;
sl@0
   277
	spriteMember.iOffset = TPoint();
sl@0
   278
	spriteMember.iInterval = TTimeIntervalMicroSeconds32(0);
sl@0
   279
	CleanupStack::PushL(TCleanupItem(DeleteSpriteMember, &spriteMember));
sl@0
   280
	spriteMember.iBitmap = new (ELeave) CFbsBitmap;
sl@0
   281
	User::LeaveIfError(spriteMember.iBitmap->Load(TEST_BITMAP_NAME, EMbmWsautotestBmp1));
sl@0
   282
	spriteMember.iMaskBitmap = new (ELeave) CFbsBitmap;
sl@0
   283
	User::LeaveIfError(spriteMember.iMaskBitmap->Load(TEST_BITMAP_NAME, EMbmWsautotestBmp1mask));
sl@0
   284
	User::LeaveIfError(iSpriteMemberArray.Append(spriteMember));
sl@0
   285
	CleanupStack::Pop(&spriteMember);
sl@0
   286
#endif
sl@0
   287
	}
sl@0
   288
sl@0
   289
void CTWsGraphs::LaunchNewProcess(const TDesC& aExecutable)
sl@0
   290
	{
sl@0
   291
	TBuf<128> args;
sl@0
   292
 	args.Append(KSpace);
sl@0
   293
	args.AppendNum(iTest->iScreenNumber);
sl@0
   294
	RProcess pr;
sl@0
   295
	TInt err = pr.Create(aExecutable,args);
sl@0
   296
	if (err == KErrNone)
sl@0
   297
		{
sl@0
   298
		TRequestStatus status;
sl@0
   299
		pr.Logon(status);
sl@0
   300
		pr.Resume();
sl@0
   301
		User::WaitForRequest(status);
sl@0
   302
		err = pr.ExitReason();
sl@0
   303
		pr.Close();
sl@0
   304
		if (err != KErrNone)
sl@0
   305
			{
sl@0
   306
			_LIT(KLog,"%S returned error: %d. Check RDebug output.");
sl@0
   307
			LOG_MESSAGE3(KLog, &aExecutable, err);
sl@0
   308
			}
sl@0
   309
		}
sl@0
   310
	else
sl@0
   311
		{
sl@0
   312
		_LIT(KLog,"Can't create the process (%S), err=%d");
sl@0
   313
		LOG_MESSAGE3(KLog, &aExecutable, err);
sl@0
   314
		}
sl@0
   315
	TEST(err == KErrNone);
sl@0
   316
	// Restore main test group to foreground.
sl@0
   317
	TheClient->iGroup->GroupWin()->SetOrdinalPosition(0);
sl@0
   318
	}
sl@0
   319
sl@0
   320
TInt CTWsGraphs::PluginCallBack(TAny* /*aArg*/)
sl@0
   321
	{
sl@0
   322
	return (TInt)EWait;
sl@0
   323
	}
sl@0
   324
sl@0
   325
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   326
sl@0
   327
/**
sl@0
   328
 @SYMTestCaseID				GRAPHICS-WSERV-0371
sl@0
   329
 @SYMREQ					GT247-CR0714
sl@0
   330
 @SYMTestCaseDesc			Test interface extension
sl@0
   331
 @SYMTestPriority			High
sl@0
   332
 @SYMTestStatus				Implemented
sl@0
   333
 @SYMTestActions			Retrieves object interfaces from Content Rendering Plugin (plugin).
sl@0
   334
							Actions step:
sl@0
   335
							-Create plugin
sl@0
   336
							-Query interfaces obtained from plugin side
sl@0
   337
 @SYMTestExpectedResults	Supported interfaces should return non null
sl@0
   338
*/
sl@0
   339
TestState CTWsGraphs::TestInterfaceExtensionL()
sl@0
   340
	{
sl@0
   341
	if (iSubState==0)
sl@0
   342
		{
sl@0
   343
		_LIT(KTestInterfaceExtension, "TestInterfaceExtension");
sl@0
   344
		INFO_PRINTF1(KTestInterfaceExtension);
sl@0
   345
sl@0
   346
		++iSubState;
sl@0
   347
		Mem::FillZ(&iRedirInfo, sizeof(TRedirectorInfo));
sl@0
   348
		iRedir->QueryPlugin(iRedirInfo);
sl@0
   349
		return EWait;
sl@0
   350
		}
sl@0
   351
	TEST(iRedirInfo.iScreenConfigInterface!=NULL);
sl@0
   352
	TEST(iRedirInfo.iFrontBufferInterface!=NULL);
sl@0
   353
	TEST(iRedirInfo.iScreenBitmapHandle!=0);
sl@0
   354
	iFrontCopy->Duplicate(iRedirInfo.iScreenBitmapHandle);
sl@0
   355
sl@0
   356
	if (TransparencySupportedL()!=KErrNotSupported)
sl@0
   357
		{
sl@0
   358
		TEST(iRedirInfo.iBackBufferInterface!=NULL);
sl@0
   359
		TEST(iRedirInfo.iFlickerBitmapHandle!=0);
sl@0
   360
		iBackCopy->Duplicate(iRedirInfo.iFlickerBitmapHandle);
sl@0
   361
		}
sl@0
   362
sl@0
   363
	++(iTest->iState);
sl@0
   364
	iSubState = 0;
sl@0
   365
	return ENext;
sl@0
   366
	}
sl@0
   367
sl@0
   368
#endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   369
sl@0
   370
void CTWsGraphs::CreateWindowL(TBool aDraw)
sl@0
   371
	{
sl@0
   372
	iWin = CCrWin::NewL(iTest->iScreenNumber, aDraw);
sl@0
   373
	}
sl@0
   374
sl@0
   375
void CTWsGraphs::DestroyWindowL()
sl@0
   376
	{
sl@0
   377
	delete iWin;
sl@0
   378
	iWin = NULL;
sl@0
   379
	}
sl@0
   380
sl@0
   381
void CTWsGraphs::CreateAlphaWindowL()
sl@0
   382
	{
sl@0
   383
	iAlpha = CCrAlphaWin::NewL(iTest->iScreenNumber);
sl@0
   384
	}
sl@0
   385
sl@0
   386
void CTWsGraphs::DestroyAlphaWindowL()
sl@0
   387
	{
sl@0
   388
	delete iAlpha;
sl@0
   389
	iAlpha = NULL;
sl@0
   390
	}
sl@0
   391
sl@0
   392
TBool CTWsGraphs::CompareBitmapArea16Bpp(CFbsBitmap* aBmp1, const TPoint& aPos1, CFbsBitmap* aBmp2, const TPoint& aPos2, const TSize& aSize)
sl@0
   393
	{
sl@0
   394
	const TDisplayMode dispmode = aBmp1->DisplayMode();
sl@0
   395
	if (dispmode!=aBmp2->DisplayMode())
sl@0
   396
		return EFalse;
sl@0
   397
	const TInt stride1 = aBmp1->DataStride();
sl@0
   398
	const TInt stride2 = aBmp2->DataStride();
sl@0
   399
	const TInt linebytes = aSize.iWidth * 2;
sl@0
   400
	const TInt pixelbytes = 2;
sl@0
   401
	aBmp1->LockHeap();
sl@0
   402
	const TUint8* p1 = ((const TUint8*)aBmp1->DataAddress())+aPos1.iY*stride1+aPos1.iX*pixelbytes;
sl@0
   403
	const TUint8* p2 = ((const TUint8*)aBmp2->DataAddress())+aPos2.iY*stride2+aPos2.iX*pixelbytes;
sl@0
   404
	for (TInt y=0; y<aSize.iHeight; ++y)
sl@0
   405
		{
sl@0
   406
		if (Mem::Compare(p1+y*stride1,linebytes,p2+y*stride2,linebytes)!=0)
sl@0
   407
			{
sl@0
   408
			aBmp1->UnlockHeap();
sl@0
   409
			return EFalse;
sl@0
   410
			}
sl@0
   411
		}
sl@0
   412
	aBmp1->UnlockHeap();
sl@0
   413
	return ETrue;
sl@0
   414
	}
sl@0
   415
sl@0
   416
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   417
TestState CTWsGraphs::TestScreenRedirectionL()
sl@0
   418
	{
sl@0
   419
	if (iSubState==0)
sl@0
   420
		{
sl@0
   421
		_LIT(KTestScreenRedirection, "TestScreenRedirection");
sl@0
   422
		INFO_PRINTF1(KTestScreenRedirection);
sl@0
   423
sl@0
   424
		++iSubState;
sl@0
   425
		/**
sl@0
   426
		 @SYMTestCaseID				GRAPHICS-WSERV-0372
sl@0
   427
		 @SYMREQ					GT247-CR0714
sl@0
   428
		 @SYMTestCaseDesc			Redirect wserv screen drawing to custom graphics context
sl@0
   429
		 @SYMTestPriority			High
sl@0
   430
		 @SYMTestStatus				Implemented
sl@0
   431
		 @SYMTestActions			Redirects wserv screen drawing to bitmap context owned by plugin.
sl@0
   432
									Actions step:
sl@0
   433
									-Draw opaque window.
sl@0
   434
									-Save screen content to a bitmap
sl@0
   435
									-Instruct plugin to redirect wserv screen drawing to a bitmap device
sl@0
   436
									-Draw the same window again
sl@0
   437
									-Retrieve plugin bitmap and compare against  the saved bitmap
sl@0
   438
		 @SYMTestExpectedResults	Bitmap content match
sl@0
   439
		*/
sl@0
   440
		CreateWindowL();		
sl@0
   441
		TheClient->iScreen->CopyScreenToBitmap(iBefore);
sl@0
   442
		DestroyWindowL();
sl@0
   443
		iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue);
sl@0
   444
		return EWait;
sl@0
   445
		}
sl@0
   446
sl@0
   447
	if (iSubState==1)
sl@0
   448
		{
sl@0
   449
		++iSubState;
sl@0
   450
		CreateWindowL();
sl@0
   451
		TSize sz = iBefore->SizeInPixels();
sl@0
   452
		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
sl@0
   453
		iBefore->LockHeap();
sl@0
   454
		TEST(Mem::Compare((const TUint8*)iFrontCopy->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
sl@0
   455
		iBefore->UnlockHeap();
sl@0
   456
sl@0
   457
		Mem::FillZ(&iRedirInfo, sizeof(TRedirectorInfo));			
sl@0
   458
		iRedir->QueryPlugin(iRedirInfo);
sl@0
   459
		return EWait;
sl@0
   460
		}
sl@0
   461
sl@0
   462
	if (iSubState==2)
sl@0
   463
		{
sl@0
   464
		++iSubState;
sl@0
   465
		/**
sl@0
   466
		 @SYMTestCaseID				GRAPHICS-WSERV-0047
sl@0
   467
		 @SYMTestCaseDesc			Screen update event
sl@0
   468
		 @SYMTestPriority			Medium
sl@0
   469
		 @SYMTestStatus				Implemented
sl@0
   470
		 @SYMTestActions			Check plugin receive screen update event during redirection
sl@0
   471
		 @SYMTestExpectedResults	Counter is non-zero
sl@0
   472
		*/
sl@0
   473
		TEST(iRedirInfo.iUpdateCounter>0);
sl@0
   474
sl@0
   475
		DestroyWindowL();
sl@0
   476
		/**
sl@0
   477
		 @SYMTestCaseID				GRAPHICS-WSERV-0373
sl@0
   478
		 @SYMREQ					GT247-CR0714
sl@0
   479
		 @SYMTestCaseDesc			Stop wserv screen drawing redirection
sl@0
   480
		 @SYMTestPriority			High
sl@0
   481
		 @SYMTestStatus				Implemented
sl@0
   482
		 @SYMTestActions			Stop wserv screen drawing redirection.
sl@0
   483
									Actions step:
sl@0
   484
									-Instruct plugin to stop wserv screen drawing redirection
sl@0
   485
									-Draw the same window again
sl@0
   486
									-Save screen content to another bitmap
sl@0
   487
									-Compare the saved bitmap against newly saved bitmap
sl@0
   488
		 @SYMTestExpectedResults	Bitmap content match
sl@0
   489
		*/
sl@0
   490
		iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse);
sl@0
   491
		return EWait;
sl@0
   492
		}
sl@0
   493
sl@0
   494
	if (iSubState==3)
sl@0
   495
		{
sl@0
   496
		++iSubState;
sl@0
   497
		CreateWindowL();
sl@0
   498
		TheClient->iScreen->CopyScreenToBitmap(iAfter);
sl@0
   499
		TSize sz = iBefore->SizeInPixels();	
sl@0
   500
		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K	
sl@0
   501
		iAfter->LockHeap();
sl@0
   502
		TEST(Mem::Compare((const TUint8*)iAfter->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
sl@0
   503
		iAfter->UnlockHeap();
sl@0
   504
		DestroyWindowL();
sl@0
   505
sl@0
   506
		Mem::FillZ(&iRedirInfo, sizeof(TRedirectorInfo));			
sl@0
   507
		iRedir->QueryPlugin(iRedirInfo);
sl@0
   508
		return EWait;
sl@0
   509
		}
sl@0
   510
sl@0
   511
	/**
sl@0
   512
	 @SYMTestCaseID				GRAPHICS-WSERV-0374
sl@0
   513
	 @SYMTestCaseDesc			Screen update event
sl@0
   514
	 @SYMTestPriority			Medium
sl@0
   515
	 @SYMTestStatus				Implemented
sl@0
   516
	 @SYMTestActions			Check plugin receive no screen update event when redirection is terminated
sl@0
   517
	 @SYMTestExpectedResults	Counter is zero
sl@0
   518
	*/
sl@0
   519
	TEST(iRedirInfo.iUpdateCounter==0);
sl@0
   520
sl@0
   521
	++(iTest->iState);
sl@0
   522
	iSubState = 0;
sl@0
   523
sl@0
   524
	return ENext;
sl@0
   525
	}
sl@0
   526
sl@0
   527
TestState CTWsGraphs::TestTextCursorUnderRedirectionL(TTestCursorType aCursorType)
sl@0
   528
	{
sl@0
   529
	/**
sl@0
   530
	 @SYMTestCaseID				GRAPHICS-WSERV-0363
sl@0
   531
	 @SYMTestCaseDesc			Text Cursor when drawing redirected
sl@0
   532
	 @SYMTestPriority			Medium
sl@0
   533
	 @SYMTestStatus				Implemented
sl@0
   534
	 @SYMTestActions			Action steps:
sl@0
   535
	 							- Draw the text cursor in the left side of the screen
sl@0
   536
	 							- Re-direct the Front Buffer
sl@0
   537
	 							- Move the text cursor to the right side of the screen
sl@0
   538
	 							- Pause 0.5 seconds because this amount of time is needed
sl@0
   539
								  to change from the flash ON phase to the flash OFF phase
sl@0
   540
	 							- Stop re-directing
sl@0
   541
	 							- See if when we exit re-direction in a different place in
sl@0
   542
	 							  the phase of the text cursor flashing, whether we get
sl@0
   543
	 							  non-text cursor drawing artefacts in the old location
sl@0
   544
	 							  where the text cursor used to be
sl@0
   545
	 @SYMTestExpectedResults	Left side of the screen does not show a Text Cursor
sl@0
   546
	 */
sl@0
   547
	
sl@0
   548
	ASSERT(aCursorType == ETestStandardTextCursor || aCursorType == ETestCustomTextCursor);
sl@0
   549
	
sl@0
   550
	// Cursor Flash Period is 1 second (comprising two phases; ON and OFF)
sl@0
   551
	const TInt KCursorFlashPeriod = 1000000;
sl@0
   552
	const TInt KWaitForNextFlashPhase = KCursorFlashPeriod / 2;
sl@0
   553
	
sl@0
   554
	// Size of the cursor; it may be either a standard or custom text cursor
sl@0
   555
	TSize cursorSize = (aCursorType == ETestStandardTextCursor) ? TSize(15, 20) : TSize(80, 80);
sl@0
   556
		
sl@0
   557
	// Original Text Cursor position in the left part of the screen
sl@0
   558
	const TPoint originalCursorPos(45, 40);
sl@0
   559
	
sl@0
   560
	// New Text Cursor position in the right half of the screen
sl@0
   561
	const TPoint newCursorPos((TheClient->iScreen->SizeInPixels().iWidth/2) + 45, 40);
sl@0
   562
	
sl@0
   563
	// Clean area of the screen which never had a text cursor
sl@0
   564
	const TPoint cleanReferencePos(45, 40 + 80);
sl@0
   565
	
sl@0
   566
	/* Initial setup to get a window with a standard flashing text cursor */
sl@0
   567
	if (iSubState == 0)
sl@0
   568
		{
sl@0
   569
		++iSubState;			
sl@0
   570
		CreateWindowL(ETrue);
sl@0
   571
		
sl@0
   572
		if (aCursorType == ETestStandardTextCursor)
sl@0
   573
			{
sl@0
   574
			_LIT(KTestTextCursorUnderRedirection, "TestTextCursorUnderRedirection(Standard Cursor)");
sl@0
   575
			INFO_PRINTF1(KTestTextCursorUnderRedirection);	
sl@0
   576
			iTextCursor.iType=TTextCursor::ETypeRectangle;
sl@0
   577
			iTextCursor.iHeight=cursorSize.iHeight;
sl@0
   578
			iTextCursor.iAscent=0;
sl@0
   579
			iTextCursor.iWidth=cursorSize.iWidth;
sl@0
   580
			iTextCursor.iFlags=0; 			// means flash the cursor
sl@0
   581
			iTextCursor.iColor=KRgbGreen;
sl@0
   582
			iWin->SetTextCursor(originalCursorPos, iTextCursor);
sl@0
   583
			}
sl@0
   584
		else if (aCursorType == ETestCustomTextCursor)
sl@0
   585
			{
sl@0
   586
			_LIT(KTestTextCursorUnderRedirection, "TestTextCursorUnderRedirection(Custom Cursor)");
sl@0
   587
			INFO_PRINTF1(KTestTextCursorUnderRedirection);	
sl@0
   588
sl@0
   589
			TInt err = TheClient->iWs.SetCustomTextCursor(
sl@0
   590
					KCustomTextCursorId,
sl@0
   591
					iSpriteMemberArray.Array(),
sl@0
   592
					ESpriteFlash,
sl@0
   593
					RWsSession::ECustomTextCursorAlignTop
sl@0
   594
					);
sl@0
   595
			iTextCursor.iType=KCustomTextCursorId;
sl@0
   596
			iTextCursor.iHeight=cursorSize.iHeight;
sl@0
   597
			iTextCursor.iAscent=0;
sl@0
   598
			iTextCursor.iWidth=cursorSize.iWidth;
sl@0
   599
			iTextCursor.iFlags=TTextCursor::EFlagClipHorizontal; // means flash the cursor and clip the sprite
sl@0
   600
			iTextCursor.iColor=KRgbCyan;
sl@0
   601
			iWin->SetTextCursor(originalCursorPos, iTextCursor);
sl@0
   602
			}
sl@0
   603
		else
sl@0
   604
			{
sl@0
   605
			// unknown type of test being requested
sl@0
   606
			ASSERT(0);
sl@0
   607
			}
sl@0
   608
		iWin->DrawFirstHalf();	
sl@0
   609
		return EWait;
sl@0
   610
		}
sl@0
   611
	/*
sl@0
   612
	 * Re-direct drawing to another Front Buffer.  Whilst re-directed, change the
sl@0
   613
	 * position of the text cursor.  Then pause 0.5 seconds because this is how
sl@0
   614
	 * long it will take to enter the next phase in the flashing cycle.  Finally
sl@0
   615
	 * stop re-directing.  We exit the re-direction in a different point in the
sl@0
   616
	 * phase of the text cursor from when we entered it.
sl@0
   617
	 * This is key to testing for faulty behaviour.
sl@0
   618
	 */
sl@0
   619
	if (iSubState==1)
sl@0
   620
		{
sl@0
   621
		++iSubState;
sl@0
   622
		User::After(KCursorFlashPeriod * 2);  // so its easy to visually review progress
sl@0
   623
		iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue);
sl@0
   624
		iWin->SetTextCursor(newCursorPos, iTextCursor);
sl@0
   625
		User::After(KWaitForNextFlashPhase);
sl@0
   626
		iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse);
sl@0
   627
		return EWait;
sl@0
   628
		}
sl@0
   629
	/*
sl@0
   630
	 * Paint the right hand side of the screen which should now have a text cursor.
sl@0
   631
	 */
sl@0
   632
	if (iSubState==2)
sl@0
   633
		{
sl@0
   634
		++iSubState;
sl@0
   635
		iWin->DrawSecondHalf();
sl@0
   636
		return EWait;
sl@0
   637
		}
sl@0
   638
	/*
sl@0
   639
	 * Let the cursor flash a few times, as it assists manual viewing of the progress
sl@0
   640
	 * of the test.
sl@0
   641
	 */
sl@0
   642
	if (iSubState==3)
sl@0
   643
		{
sl@0
   644
		++iSubState;
sl@0
   645
		User::After(KCursorFlashPeriod * 3);
sl@0
   646
		return EWait;
sl@0
   647
		}
sl@0
   648
	/*
sl@0
   649
	 * Check to see if the text cursor did move to the right of the screen.
sl@0
   650
	 */
sl@0
   651
	if (iSubState==4)
sl@0
   652
		{
sl@0
   653
		++iSubState;
sl@0
   654
		
sl@0
   655
		/* When we do a screen comparison, we supply flag 0, which means
sl@0
   656
		 * don't include the text cursor.  We do this because we are interested
sl@0
   657
		 * in screen artefacts.
sl@0
   658
		 */
sl@0
   659
		TEST(TheClient->iScreen->RectCompare(
sl@0
   660
				TRect(originalCursorPos, cursorSize),
sl@0
   661
				TRect(cleanReferencePos, cursorSize),
sl@0
   662
				0)); // must not supply CWsScreenDevice::EIncludeTextCursor
sl@0
   663
		
sl@0
   664
		return EWait;
sl@0
   665
		}
sl@0
   666
	/* Clean up */
sl@0
   667
	if (iSubState==5)
sl@0
   668
		{
sl@0
   669
		++iSubState;
sl@0
   670
		iWin->CancelTextCursor();
sl@0
   671
		DestroyWindowL();
sl@0
   672
		}
sl@0
   673
	
sl@0
   674
	iSubState = 0;
sl@0
   675
sl@0
   676
	return ENext;
sl@0
   677
	}
sl@0
   678
sl@0
   679
/**
sl@0
   680
 @SYMTestCaseID				GRAPHICS-WSERV-0375
sl@0
   681
 @SYMREQ					GT247-CR0714
sl@0
   682
 @SYMTestCaseDesc			Redirect wserv flickerfree drawing to custom graphics context
sl@0
   683
 @SYMTestPriority			Medium
sl@0
   684
 @SYMTestStatus				Implemented
sl@0
   685
 @SYMTestActions			Redirect wserv flickerfree buffer drawing.
sl@0
   686
							Action step:
sl@0
   687
							-Draw opaque window (as background) and transparent window
sl@0
   688
							-Save screen content to a bitmap
sl@0
   689
							-Instruct plugin to redirect wserv flickerfree buffer drawing
sl@0
   690
							-Draw the same opaque window and transparent window again
sl@0
   691
							-Retrieve plugin bitmap and compare against the saved bitmap
sl@0
   692
 @SYMTestExpectedResults	Bitmap content match
sl@0
   693
*/
sl@0
   694
/**
sl@0
   695
 @SYMTestCaseID				GRAPHICS-WSERV-0376
sl@0
   696
 @SYMREQ					GT247-CR0714
sl@0
   697
 @SYMTestCaseDesc			Stop wserv flickerfree drawing redirection
sl@0
   698
 @SYMTestPriority			Medium
sl@0
   699
 @SYMTestStatus				Implemented
sl@0
   700
 @SYMTestActions			Stop wserv flickerfree buffer drawing redirection.
sl@0
   701
							Action step:
sl@0
   702
							-Instruct plugin to stop wserv filckerfree drawing redirection
sl@0
   703
							-Draw the same opaque and transparent window
sl@0
   704
							-Save screen content to another bitmap
sl@0
   705
							-Compare saved bitmap against newly saved bitmap
sl@0
   706
 @SYMTestExpectedResults	Bitmap content match
sl@0
   707
*/
sl@0
   708
sl@0
   709
TestState CTWsGraphs::TestFlickerRedirectionL()
sl@0
   710
	{
sl@0
   711
	if (TransparencySupportedL()==KErrNotSupported)
sl@0
   712
		{
sl@0
   713
		++(iTest->iState);
sl@0
   714
		return ENext;
sl@0
   715
		}
sl@0
   716
sl@0
   717
	// flush transparent window destruction created in TransparencySupportedL before
sl@0
   718
	// proceeding with the test
sl@0
   719
sl@0
   720
	TheClient->iWs.Flush();
sl@0
   721
sl@0
   722
	if (iSubState==0)
sl@0
   723
		{
sl@0
   724
		_LIT(KTestFlickerRedirection, "TestFlickerRedirection");
sl@0
   725
		INFO_PRINTF1(KTestFlickerRedirection);
sl@0
   726
sl@0
   727
		++iSubState;
sl@0
   728
sl@0
   729
		CreateWindowL();
sl@0
   730
		CreateAlphaWindowL();
sl@0
   731
		TheClient->iScreen->CopyScreenToBitmap(iBefore);
sl@0
   732
		DestroyAlphaWindowL();
sl@0
   733
		DestroyWindowL();
sl@0
   734
		iRedir->Redirect(CWsRedir::EBackBuffer, ETrue);
sl@0
   735
		return EWait;
sl@0
   736
		}
sl@0
   737
sl@0
   738
	if (iSubState==1)
sl@0
   739
		{
sl@0
   740
		++iSubState;
sl@0
   741
		CreateWindowL();
sl@0
   742
		CreateAlphaWindowL();
sl@0
   743
		TSize sz = iBefore->SizeInPixels();
sl@0
   744
		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
sl@0
   745
		iBefore->LockHeap();
sl@0
   746
		TInt ret=Mem::Compare((const TUint8*)iBackCopy->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes);
sl@0
   747
		TEST(ret==0);
sl@0
   748
		if (ret!=0)
sl@0
   749
			{
sl@0
   750
			_LIT(KLog,"The memory of two bitmaps doesn't match");
sl@0
   751
			LOG_MESSAGE(KLog);
sl@0
   752
			}
sl@0
   753
		iBefore->UnlockHeap();
sl@0
   754
		DestroyAlphaWindowL();
sl@0
   755
		DestroyWindowL();
sl@0
   756
		iRedir->Redirect(CWsRedir::EBackBuffer, EFalse);
sl@0
   757
		return EWait;
sl@0
   758
		}
sl@0
   759
sl@0
   760
	CreateWindowL();
sl@0
   761
	CreateAlphaWindowL();
sl@0
   762
	TheClient->iScreen->CopyScreenToBitmap(iAfter);
sl@0
   763
	TSize sz = iBefore->SizeInPixels();
sl@0
   764
	TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
sl@0
   765
	iAfter->LockHeap();
sl@0
   766
	TEST(Mem::Compare((const TUint8*)iAfter->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
sl@0
   767
	iAfter->UnlockHeap();
sl@0
   768
	DestroyAlphaWindowL();
sl@0
   769
	DestroyWindowL();
sl@0
   770
sl@0
   771
	++(iTest->iState);
sl@0
   772
	iSubState = 0;
sl@0
   773
	return ENext;
sl@0
   774
	}
sl@0
   775
sl@0
   776
#endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   777
sl@0
   778
/**
sl@0
   779
 @SYMTestCaseID				GRAPHICS-WSERV-0377
sl@0
   780
 @SYMREQ					GT247-CR0714
sl@0
   781
 @SYMTestCaseDesc			Enable event notification
sl@0
   782
 @SYMTestPriority			Medium
sl@0
   783
 @SYMTestStatus				Implemented
sl@0
   784
 @SYMTestActions			Enable plugin to register to event notification.
sl@0
   785
							Action step:
sl@0
   786
							-Instruct plugin to register event handler
sl@0
   787
							-Draw fullscreen window (plugin will receive window visibility changed event)
sl@0
   788
							-Query visibility region from plugin side
sl@0
   789
							-Compare window visible region against value obtained by plugin
sl@0
   790
 @SYMTestExpectedResults	Visible region match
sl@0
   791
*/
sl@0
   792
/**
sl@0
   793
 @SYMTestCaseID				GRAPHICS-WSERV-0378
sl@0
   794
 @SYMREQ					GT247-CR0714
sl@0
   795
 @SYMTestCaseDesc			Disable event notification
sl@0
   796
 @SYMTestPriority			Medium
sl@0
   797
 @SYMTestStatus				Implemented
sl@0
   798
 @SYMTestActions			Disable plugin to register to event notification.
sl@0
   799
							Action step:
sl@0
   800
							-Instruct plugin to unregister event handler
sl@0
   801
							-Destroy fullscreen window (plugin will not receive window visibility changed event)
sl@0
   802
							-Query visibility region from plugin side
sl@0
   803
sl@0
   804
 @SYMTestExpectedResults	Plugin does not receive events notification
sl@0
   805
*/
sl@0
   806
TestState CTWsGraphs::TestEventNotificationL()
sl@0
   807
	{
sl@0
   808
	if (iSubState==0)
sl@0
   809
		{
sl@0
   810
		_LIT(KTestEventNotification, "TestEventNotification");
sl@0
   811
		INFO_PRINTF1(KTestEventNotification);
sl@0
   812
sl@0
   813
		++iSubState;
sl@0
   814
		iListen->Enable(ETrue);
sl@0
   815
		CreateWindowL();
sl@0
   816
		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
sl@0
   817
		TheClient->iWs.Finish();
sl@0
   818
		TheClient->WaitForRedrawsToFinish();
sl@0
   819
		iListen->QueryPlugin(iListenInfo);
sl@0
   820
		return EWait;
sl@0
   821
		}
sl@0
   822
sl@0
   823
	if (iSubState==1)
sl@0
   824
		{
sl@0
   825
		++iSubState;
sl@0
   826
		iListen->Enable(EFalse);
sl@0
   827
		TEST(iListenInfo.iNumRect==1);
sl@0
   828
		TEST(iListenInfo.iRect==TRect(TPoint(0,0),TheClient->iScreen->SizeInPixels()));
sl@0
   829
		DestroyWindowL();
sl@0
   830
		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
sl@0
   831
		iListen->QueryPlugin(iListenInfo);
sl@0
   832
		iListen->Enable(EFalse);
sl@0
   833
		DestroyWindowL();
sl@0
   834
		return EWait;
sl@0
   835
		}
sl@0
   836
		
sl@0
   837
	TEST(iListenInfo.iNumRect==0);
sl@0
   838
	
sl@0
   839
	++(iTest->iState);
sl@0
   840
	iSubState = 0;
sl@0
   841
	return ENext;
sl@0
   842
	}
sl@0
   843
sl@0
   844
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   845
sl@0
   846
TestState CTWsGraphs::TestRedirectionUsingWsBackBufferL()
sl@0
   847
	{
sl@0
   848
	if (TransparencySupportedL()==KErrNotSupported)
sl@0
   849
		{
sl@0
   850
		++(iTest->iState);
sl@0
   851
		return ENext;
sl@0
   852
		}
sl@0
   853
sl@0
   854
	// flush transparent window destruction created in TransparencySupportedL before
sl@0
   855
	// proceeding with the test
sl@0
   856
sl@0
   857
	TheClient->iWs.Flush();
sl@0
   858
sl@0
   859
	if (iSubState==0)
sl@0
   860
		{
sl@0
   861
		_LIT(KTestRedirectionWsBack, "TestRedirectionUsingWsBackBuffer");
sl@0
   862
		INFO_PRINTF1(KTestRedirectionWsBack);
sl@0
   863
		
sl@0
   864
		++iSubState;
sl@0
   865
sl@0
   866
		/**
sl@0
   867
		 @SYMTestCaseID				GRAPHICS-WSERV-0379
sl@0
   868
		 @SYMTestCaseDesc			Redirect wserv flickerfree to MWsBackBuffer object
sl@0
   869
		 @SYMTestPriority			Medium
sl@0
   870
		 @SYMTestStatus				Implemented
sl@0
   871
		 @SYMTestActions			-Draw opaque window (as background) and transparent window
sl@0
   872
									-Save screen content to a bitmap
sl@0
   873
									-Instruct plugin to redirect flickerfree buffer to MWsBackBuffer object
sl@0
   874
									-Draw the same opaque window and transparent window again
sl@0
   875
									-Retrieve plugin bitmap and compare against the saved bitmap
sl@0
   876
		 @SYMTestExpectedResults	Bitmap content match
sl@0
   877
		*/
sl@0
   878
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0379"));
sl@0
   879
		CreateWindowL();
sl@0
   880
		CreateAlphaWindowL();
sl@0
   881
		TheClient->iScreen->CopyScreenToBitmap(iBefore);
sl@0
   882
		DestroyAlphaWindowL();		
sl@0
   883
		DestroyWindowL();		
sl@0
   884
		iRedir->RedirectUsingWsBackBuffer(ETrue);
sl@0
   885
		return EWait;
sl@0
   886
		}
sl@0
   887
sl@0
   888
	if (iSubState==1)
sl@0
   889
		{
sl@0
   890
		++iSubState;
sl@0
   891
		CreateWindowL();
sl@0
   892
		CreateAlphaWindowL();
sl@0
   893
		TSize sz = iBefore->SizeInPixels();
sl@0
   894
		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
sl@0
   895
		iBefore->LockHeap();
sl@0
   896
		TInt ret=Mem::Compare((const TUint8*)iBackCopy->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes);
sl@0
   897
		TEST(ret==0);
sl@0
   898
		if (ret!=0)
sl@0
   899
			{
sl@0
   900
			_LIT(KLog,"The memory of two bitmaps doesn't match");
sl@0
   901
			LOG_MESSAGE(KLog);
sl@0
   902
			}
sl@0
   903
		iBefore->UnlockHeap();
sl@0
   904
		DestroyAlphaWindowL();
sl@0
   905
		DestroyWindowL();
sl@0
   906
sl@0
   907
		/**
sl@0
   908
		 @SYMTestCaseID				GRAPHICS-WSERV-0380
sl@0
   909
		 @SYMTestCaseDesc			Restore wserv flickerfree redirection from MWsBackBuffer object
sl@0
   910
		 @SYMTestPriority			Medium
sl@0
   911
		 @SYMTestStatus				Implemented
sl@0
   912
		 @SYMTestActions			-Instruct plugin to stop wserv filckerfree drawing redirection
sl@0
   913
									-Draw the same opaque and transparent window
sl@0
   914
									-Save screen content to another bitmap
sl@0
   915
									-Compare saved bitmap against newly saved bitmap
sl@0
   916
		 @SYMTestExpectedResults	Bitmap content match
sl@0
   917
		*/
sl@0
   918
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0380"));
sl@0
   919
		iRedir->RedirectUsingWsBackBuffer(EFalse);
sl@0
   920
		return EWait;
sl@0
   921
		}
sl@0
   922
sl@0
   923
	CreateWindowL();
sl@0
   924
	CreateAlphaWindowL();
sl@0
   925
	TheClient->iScreen->CopyScreenToBitmap(iAfter);
sl@0
   926
	TSize sz = iBefore->SizeInPixels();
sl@0
   927
	TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
sl@0
   928
	iAfter->LockHeap();
sl@0
   929
	TEST(Mem::Compare((const TUint8*)iAfter->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
sl@0
   930
	iAfter->UnlockHeap();
sl@0
   931
	DestroyAlphaWindowL();
sl@0
   932
	DestroyWindowL();
sl@0
   933
/**
sl@0
   934
	@SYMTestCaseID	GRAPHICS-WSERV-0527
sl@0
   935
*/
sl@0
   936
	((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0527"));
sl@0
   937
	++(iTest->iState);
sl@0
   938
	iSubState = 0;
sl@0
   939
	return ENext;
sl@0
   940
	}
sl@0
   941
sl@0
   942
#endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
   943
sl@0
   944
//A call to do coverage through a plugin. 
sl@0
   945
//This can serve as a basis for future coverage to objects exposed by the
sl@0
   946
//plugin. For now a single simple test is implmeneted.
sl@0
   947
TestState CTWsGraphs::TestGraphicDrawerCoverage()
sl@0
   948
	{
sl@0
   949
	__ASSERT_ALWAYS(iGdCoverage->RunTest(1)==KErrNone||KErrNotReady, User::Invariant());
sl@0
   950
	return ENext;
sl@0
   951
	}
sl@0
   952
sl@0
   953
//Simplified non-functional class to create a few dummy CWsGraphicDrawer instances.
sl@0
   954
//This code is intended to test the Array class, not the Drawer.
sl@0
   955
//Note that this object is not at all functional! The only guaranteed method is Id().
sl@0
   956
//WsGraphicDrawer is declared as a friend and is actually intended to be the factory class for CWsGraphicDrawer
sl@0
   957
class WsGraphicDrawer:public CWsGraphicDrawer
sl@0
   958
	{
sl@0
   959
public:
sl@0
   960
	WsGraphicDrawer()
sl@0
   961
		{
sl@0
   962
		}
sl@0
   963
	//stub for virtual construction. Most members are ignored
sl@0
   964
	virtual void ConstructL(MWsGraphicDrawerEnvironment& ,const TGraphicDrawerId& id,MWsClient& ,const TDesC8& )
sl@0
   965
		{
sl@0
   966
		ConstructL(id);
sl@0
   967
		}
sl@0
   968
	//simplified custom construction
sl@0
   969
	void ConstructL(const TGraphicDrawerId& id)
sl@0
   970
		{
sl@0
   971
		MWsGraphicDrawerEnvironment* nullEnv=NULL;
sl@0
   972
		MWsGraphicDrawerEnvironment& aEnv=*nullEnv;
sl@0
   973
		MWsClient* nullClient=NULL;
sl@0
   974
		MWsClient& aOwner=*nullClient;
sl@0
   975
		this->BaseConstructL(aEnv,id,aOwner);
sl@0
   976
		this->iDtor_ID_Key=TUid::Null();
sl@0
   977
		
sl@0
   978
		}
sl@0
   979
	//stubs for pure virtual methods
sl@0
   980
	virtual void HandleMessage(const TDesC8& )
sl@0
   981
		{}
sl@0
   982
	virtual void DoDraw(MWsGc& ,const TRect& ,const TDesC8& ) const
sl@0
   983
		{}
sl@0
   984
	
sl@0
   985
	};
sl@0
   986
//Class to allow me to pre-allocate the CWsGraphicDrawerArray so it doesn't pop up a false-positive memory allocation!
sl@0
   987
class DummyCleanup:public TCleanupItem
sl@0
   988
	{
sl@0
   989
public:
sl@0
   990
	static void CleanUp(TAny*)		{}
sl@0
   991
	DummyCleanup(): TCleanupItem(CleanUp,this)	{}
sl@0
   992
	operator DummyCleanup*()	{	return this;	}
sl@0
   993
	
sl@0
   994
	};
sl@0
   995
sl@0
   996
//Helper function to explain test fails. Most other tests are against KErrNone
sl@0
   997
void CTWsGraphs::ReportNegativeResultfail(TInt aLine,TInt aResult,TInt aExpectedResult)
sl@0
   998
	{
sl@0
   999
	testBooleanTrue((aResult==aExpectedResult), (TText8*)__FILE__, aLine);
sl@0
  1000
	if (aResult!=aExpectedResult)
sl@0
  1001
		{
sl@0
  1002
		INFO_PRINTF3(_L("Expected return code %i, got %i"),aExpectedResult,aResult);	
sl@0
  1003
		}
sl@0
  1004
	
sl@0
  1005
	}
sl@0
  1006
	
sl@0
  1007
//This is an attempt to use wserv test's pre-existing Panic handler to perform some negative tests.
sl@0
  1008
//At present this handler appears to be broken:
sl@0
  1009
// 1) It doesn't write to the correct html log file
sl@0
  1010
// 2) It no longer writes to the WSERV.LOG file it was writing to a few versions ago
sl@0
  1011
// 3) It doesn't close the panic window so subsequent tests that check the display output fail.
sl@0
  1012
//That was a waste of effort.
sl@0
  1013
struct CTWsGraphs::WrapTestCall
sl@0
  1014
	{
sl@0
  1015
	CTWsGraphs* thisThis;
sl@0
  1016
	TUint		testCount;
sl@0
  1017
	TBool		continueTests;
sl@0
  1018
	TUint 		testFailedLine;
sl@0
  1019
	//This field was intended to allow threaded panicing tests to report other errors
sl@0
  1020
	//As I can't get threaded panicing tests to operate correctly, I have not implemented support for the field.
sl@0
  1021
	//TBuf<1024>	errorMessages;	
sl@0
  1022
		
sl@0
  1023
	WrapTestCall (	CTWsGraphs* thisThis,	TUint		testCount):
sl@0
  1024
		thisThis(thisThis),	testCount(testCount)
sl@0
  1025
		{	continueTests=false;testFailedLine=0;	}
sl@0
  1026
	};
sl@0
  1027
	
sl@0
  1028
TInt	CTWsGraphs::DoNegTestCall(TInt /*aInt*/, TAny *aPtr)
sl@0
  1029
	{
sl@0
  1030
	CTWsGraphs::WrapTestCall* aWrap=static_cast<CTWsGraphs::WrapTestCall*>(aPtr);
sl@0
  1031
	aWrap->continueTests=aWrap->thisThis->NegTestAddSwapGDArrayL(aWrap->testCount,aWrap);	
sl@0
  1032
	return 0;
sl@0
  1033
	}
sl@0
  1034
	
sl@0
  1035
TBool	CTWsGraphs::LaunchNegTestCall(TUint		aTestCount,TUint PanicCode,const TDesC &aPanicCategory)
sl@0
  1036
	{
sl@0
  1037
	WrapTestCall wt(this,aTestCount);
sl@0
  1038
	(void)PanicCode;
sl@0
  1039
	(void)aPanicCategory;
sl@0
  1040
//I have disabled the panicing tests because they don't output diagnostics 
sl@0
  1041
//and the open panic window causes subsequent screen bitmap comparrisson tests to fail.
sl@0
  1042
//	iTest->TestPanicL(DoNegTestCall,aPanicCode,3,&wt,aPanicCategory);
sl@0
  1043
	return wt.continueTests;	
sl@0
  1044
	}
sl@0
  1045
sl@0
  1046
/**
sl@0
  1047
	Loops through all the positive and negative tests associated with the  GraphicDrawerArray.
sl@0
  1048
	The aim is to perform isolated testing of these classes as some are not currently being used.
sl@0
  1049
	
sl@0
  1050
**/
sl@0
  1051
void CTWsGraphs::TestAddSwapGDArrayL()
sl@0
  1052
	{
sl@0
  1053
sl@0
  1054
sl@0
  1055
	INFO_PRINTF1(_L("Positive tests for GraphicDrawerArray"));
sl@0
  1056
	for (TInt i=0;PosTestAddSwapGDArrayL(i);i++)
sl@0
  1057
		{}
sl@0
  1058
sl@0
  1059
sl@0
  1060
sl@0
  1061
	INFO_PRINTF1(_L("Verifying that negative tests for GraphicDrawerArray don't actually panic"));
sl@0
  1062
	for (TInt i=1;NegTestAddSwapGDArrayL(i);i++)
sl@0
  1063
		{}
sl@0
  1064
	}
sl@0
  1065
/**
sl@0
  1066
	Resets and deallocates the GDA withoud deleting the objects.
sl@0
  1067
	@param 	 testArray	the array to reset
sl@0
  1068
	@return true if the array was already empty.
sl@0
  1069
**/
sl@0
  1070
static bool	ResetArray(CWsGraphicDrawerArray& testArray)
sl@0
  1071
{
sl@0
  1072
	bool rv=(testArray.IsEmpty());
sl@0
  1073
	MWsClient* nullClient=NULL;
sl@0
  1074
	testArray.RemoveAll(*nullClient);
sl@0
  1075
	testArray.ResetAndDestroy();		
sl@0
  1076
	return rv;
sl@0
  1077
}
sl@0
  1078
/**
sl@0
  1079
   @SYMTestCaseID GRAPHICS-WSERV-AddSwapGDArray-0001
sl@0
  1080
   @SYMDEF			DEF093926  
sl@0
  1081
  
sl@0
  1082
   @SYMTestCaseDesc DEF093926: Check for stability of Add and Swap unwind methods in isolation.
sl@0
  1083
   		Note that this code is testing the functionality of a class internal to CWindowServer.
sl@0
  1084
   		At present CWindowServer presents just a simple shim on this class, 
sl@0
  1085
   		but if that implementation of  CWindowServer changes than this test will be redudant.
sl@0
  1086
   
sl@0
  1087
   @SYMTestPriority High
sl@0
  1088
   
sl@0
  1089
   @SYMTestStatus Implemented
sl@0
  1090
   
sl@0
  1091
   @SYMTestActions
sl@0
  1092
	The sequence for each of these positive test sections is pretty much the same:
sl@0
  1093
	Add one record with id 1234(test for errors)
sl@0
  1094
	Add one record with id Badf00d
sl@0
  1095
	Swap with another record with id Badf00d
sl@0
  1096
	Remove 2 records
sl@0
  1097
	result=no leaks
sl@0
  1098
	
sl@0
  1099
		Add/Swap: no Cleanup item - no leaks after Remove the added items
sl@0
  1100
   	    AddTLC/SwapTLC: Cleanup item requires Commit - check for no leaks after Remove.
sl@0
  1101
   	    AddTLC/SwapTLC: Cleanup item gets executed by forced Leave  - check for no leaks after.
sl@0
  1102
		AddTLC, SwapTLC in allocation failure scenarios. Add/Swap don't allocate anything!
sl@0
  1103
		obsoleted AddLC/SwapLC to ensure correct function when forced Leave - check for no leaks after
sl@0
  1104
		obsoleted AddLC/SwapLC to ensure correct function. These will always leak in good case.
sl@0
  1105
   @SYMTestExpectedResults 
sl@0
  1106
   		no exceptions or panics within this fn. 
sl@0
  1107
   		only the old AddLC and SwapLC should leak as indicated.
sl@0
  1108
 */
sl@0
  1109
TBool CTWsGraphs::PosTestAddSwapGDArrayL(TInt testcase)
sl@0
  1110
	{
sl@0
  1111
	((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-AddSwapGDArray-0001"));
sl@0
  1112
    CWsGraphicDrawerArray testArray;
sl@0
  1113
    //Represents the memory cached in the array once it has been used even when it is then resized to zero
sl@0
  1114
#if defined(_DEBUG)
sl@0
  1115
    const TInt KArrayMemUseBaseline=1;
sl@0
  1116
#endif
sl@0
  1117
    //Use testArray.IsEmpty() to prove the array is clear when it should be!
sl@0
  1118
    TGraphicDrawerId id1234=  	{  	1234,		EFalse    	};
sl@0
  1119
    TGraphicDrawerId idBADF00D=	{  	0xBADF00D,	EFalse    	};
sl@0
  1120
    WsGraphicDrawer dg1234;		
sl@0
  1121
    dg1234.ConstructL(id1234);
sl@0
  1122
    WsGraphicDrawer dgBADF00D;	
sl@0
  1123
    dgBADF00D.ConstructL(idBADF00D);
sl@0
  1124
    WsGraphicDrawer dgBADF00D_2;
sl@0
  1125
    dgBADF00D_2.ConstructL(idBADF00D);
sl@0
  1126
    CWsGraphicDrawerArray::XRollBackBase* rollBack1;
sl@0
  1127
 	TInt errCode=KErrAbort;
sl@0
  1128
	TInt leaveCode=KErrNone;
sl@0
  1129
	DummyCleanup markerCleanup;
sl@0
  1130
	CleanupStack::PushL(markerCleanup);	 //This allows me to check the stack is clear!
sl@0
  1131
	//expected result of this fn: no exceptions or panics. 
sl@0
  1132
	//Put as much as you like in here, so long as it shouldn't fail.
sl@0
  1133
	
sl@0
  1134
	__UHEAP_MARK;
sl@0
  1135
			__UHEAP_CHECK(0);
sl@0
  1136
	TUint expectedLeakCount=0;
sl@0
  1137
	TBool returnCode=ETrue;
sl@0
  1138
	switch (testcase)
sl@0
  1139
		{
sl@0
  1140
		case 0:
sl@0
  1141
sl@0
  1142
			INFO_PRINTF1(_L("Sub test P0: AddL/Swap: no Cleanup item"));
sl@0
  1143
			TEST(testArray.IsEmpty());
sl@0
  1144
				TRAP(leaveCode,errCode=testArray.Add(&dg1234));
sl@0
  1145
			TEST(errCode==KErrNone);
sl@0
  1146
			TEST(leaveCode==KErrNone);
sl@0
  1147
			TEST(!testArray.IsEmpty());
sl@0
  1148
				TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
sl@0
  1149
			TEST(errCode==KErrNone);
sl@0
  1150
			TEST(leaveCode==KErrNone);
sl@0
  1151
				TRAP(leaveCode,errCode=testArray.Swap(&dgBADF00D_2));
sl@0
  1152
			TEST(errCode==KErrNone);
sl@0
  1153
			TEST(leaveCode==KErrNone);
sl@0
  1154
				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
sl@0
  1155
			TEST(errCode==KErrNone);
sl@0
  1156
			TEST(leaveCode==KErrNone);
sl@0
  1157
				//Note that it is the ID that matters here... dgBADF00D & dgBADF00D_2 have same id.
sl@0
  1158
				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
sl@0
  1159
			TEST(errCode==KErrNone);
sl@0
  1160
			TEST(leaveCode==KErrNone);
sl@0
  1161
			TEST(testArray.IsEmpty());
sl@0
  1162
		break;
sl@0
  1163
		//
sl@0
  1164
		case 1:
sl@0
  1165
			INFO_PRINTF1(_L("Sub test P1: AddTLC/SwapTLC: Cleanup item requires Commit."));
sl@0
  1166
			
sl@0
  1167
			rollBack1=NULL;
sl@0
  1168
			TEST(testArray.IsEmpty());
sl@0
  1169
			TRAP(leaveCode,
sl@0
  1170
				rollBack1=testArray.AddTLC(&dg1234);
sl@0
  1171
				CleanupStack::Check(rollBack1);
sl@0
  1172
				testArray.CommitP(rollBack1);	
sl@0
  1173
				)
sl@0
  1174
			TEST(rollBack1!=NULL);
sl@0
  1175
			TEST(leaveCode==KErrNone);
sl@0
  1176
			TEST(!testArray.IsEmpty());
sl@0
  1177
			rollBack1=NULL;
sl@0
  1178
			TRAP(leaveCode,
sl@0
  1179
				rollBack1=testArray.AddTLC(&dgBADF00D);
sl@0
  1180
				CleanupStack::Check(rollBack1);
sl@0
  1181
				testArray.CommitP(rollBack1);	
sl@0
  1182
				)
sl@0
  1183
			TEST(rollBack1!=NULL);
sl@0
  1184
			TEST(leaveCode==KErrNone);
sl@0
  1185
			rollBack1=NULL;
sl@0
  1186
			TRAP(leaveCode,
sl@0
  1187
				rollBack1=testArray.SwapTLC(&dgBADF00D_2);
sl@0
  1188
				CleanupStack::Check(rollBack1);
sl@0
  1189
				testArray.CommitP(rollBack1);	
sl@0
  1190
				)
sl@0
  1191
			TEST(rollBack1!=NULL);
sl@0
  1192
			TEST(leaveCode==KErrNone);
sl@0
  1193
			rollBack1=NULL;
sl@0
  1194
			TRAP(leaveCode,
sl@0
  1195
				rollBack1=testArray.RemoveTLC(dg1234.Id());
sl@0
  1196
				CleanupStack::Check(rollBack1);
sl@0
  1197
				testArray.CommitP(rollBack1);	
sl@0
  1198
				)
sl@0
  1199
			TEST(rollBack1!=NULL);
sl@0
  1200
			TEST(leaveCode==KErrNone);
sl@0
  1201
			rollBack1=NULL;
sl@0
  1202
				TRAP(leaveCode,
sl@0
  1203
				rollBack1=testArray.RemoveTLC(dgBADF00D_2.Id());			
sl@0
  1204
				CleanupStack::Check(rollBack1);
sl@0
  1205
				testArray.CommitP(rollBack1);	
sl@0
  1206
				)
sl@0
  1207
			TEST(rollBack1!=NULL);
sl@0
  1208
			TEST(leaveCode==KErrNone);
sl@0
  1209
			rollBack1=NULL;
sl@0
  1210
			TEST(testArray.IsEmpty());
sl@0
  1211
		break;
sl@0
  1212
		//
sl@0
  1213
		case 2:
sl@0
  1214
			INFO_PRINTF1(_L("Sub test P2: AddTLC/SwapTLC: Cleanup item gets executed."));
sl@0
  1215
			
sl@0
  1216
			rollBack1=NULL;
sl@0
  1217
			TEST(testArray.IsEmpty());
sl@0
  1218
			TRAP(leaveCode,
sl@0
  1219
				rollBack1=testArray.AddTLC(&dg1234);
sl@0
  1220
				User::Leave(1234);
sl@0
  1221
				);	
sl@0
  1222
			TEST(rollBack1!=NULL);
sl@0
  1223
			TEST(leaveCode==1234);
sl@0
  1224
			TEST(testArray.IsEmpty());
sl@0
  1225
			rollBack1=NULL;
sl@0
  1226
			CleanupStack::Check(markerCleanup);
sl@0
  1227
			__UHEAP_CHECK(KArrayMemUseBaseline);
sl@0
  1228
sl@0
  1229
			TRAP(leaveCode,	errCode=testArray.Add(&dgBADF00D));
sl@0
  1230
			TEST(errCode==KErrNone);
sl@0
  1231
			TEST(leaveCode==KErrNone);
sl@0
  1232
			rollBack1=NULL;
sl@0
  1233
			TRAP(leaveCode,
sl@0
  1234
				rollBack1=testArray.SwapTLC(&dgBADF00D_2);
sl@0
  1235
				User::Leave(1234);
sl@0
  1236
				);	
sl@0
  1237
			TEST(rollBack1!=NULL);
sl@0
  1238
			TEST(leaveCode==1234);
sl@0
  1239
			TEST(!testArray.IsEmpty());
sl@0
  1240
			rollBack1=NULL;
sl@0
  1241
			TRAP(leaveCode,
sl@0
  1242
				rollBack1=testArray.RemoveTLC(dgBADF00D_2.Id());
sl@0
  1243
				TEST(testArray.IsEmpty());
sl@0
  1244
				User::Leave(1234);
sl@0
  1245
				);	
sl@0
  1246
			TEST(rollBack1!=NULL);
sl@0
  1247
			TEST(leaveCode==1234);
sl@0
  1248
			TEST(!testArray.IsEmpty());
sl@0
  1249
			
sl@0
  1250
			
sl@0
  1251
				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
sl@0
  1252
			TEST(errCode==KErrNone);
sl@0
  1253
			TEST(leaveCode==KErrNone);
sl@0
  1254
			TEST(testArray.IsEmpty());
sl@0
  1255
			rollBack1=NULL;
sl@0
  1256
		break;
sl@0
  1257
		//
sl@0
  1258
		case 3:
sl@0
  1259
			INFO_PRINTF1(_L("Sub test P3: AddLC/SwapLC: Cleanup item gets executed - doesn't leak"));
sl@0
  1260
			TEST(testArray.IsEmpty());
sl@0
  1261
			TRAP(leaveCode,
sl@0
  1262
				testArray.AddLC(&dg1234);
sl@0
  1263
				User::Leave(1234);
sl@0
  1264
				);	
sl@0
  1265
			TEST(leaveCode==1234);
sl@0
  1266
			TEST(testArray.IsEmpty());
sl@0
  1267
			rollBack1=NULL;
sl@0
  1268
		__UHEAP_CHECK(KArrayMemUseBaseline);	  //because it threw it didn't leak
sl@0
  1269
			
sl@0
  1270
			//use my new method to add the object to be swapped out so no leak
sl@0
  1271
			TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
sl@0
  1272
			TEST(errCode==KErrNone);
sl@0
  1273
			TEST(leaveCode==KErrNone);
sl@0
  1274
		__UHEAP_CHECK(KArrayMemUseBaseline);	  //new method doesn't leak.
sl@0
  1275
			rollBack1=NULL;
sl@0
  1276
			TRAP(leaveCode,
sl@0
  1277
				errCode=testArray.SwapLC(&dgBADF00D_2);
sl@0
  1278
				User::Leave(1234);
sl@0
  1279
				);	
sl@0
  1280
			TEST(errCode==KErrNone);
sl@0
  1281
			TEST(leaveCode==1234);
sl@0
  1282
			TEST(!testArray.IsEmpty());
sl@0
  1283
			
sl@0
  1284
				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
sl@0
  1285
			TEST(errCode==KErrNone);
sl@0
  1286
			TEST(leaveCode==KErrNone);
sl@0
  1287
			TEST(testArray.IsEmpty());
sl@0
  1288
			rollBack1=NULL;
sl@0
  1289
		break;
sl@0
  1290
		//
sl@0
  1291
		case 4:
sl@0
  1292
	
sl@0
  1293
		//I don't really care whether the individual calls succeed or fail, 
sl@0
  1294
		//just whether it leaks overall, and that the error codes correspond to no-action
sl@0
  1295
		for (TInt faultRate=1;faultRate<5;faultRate++)
sl@0
  1296
			{
sl@0
  1297
			INFO_PRINTF2(_L("Sub test P4: Add/Swap: memory faulting %i"),faultRate);
sl@0
  1298
			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
sl@0
  1299
			TInt err1=KErrNone;
sl@0
  1300
			rollBack1=NULL;
sl@0
  1301
			TRAP(leaveCode,
sl@0
  1302
				errCode=testArray.Add(&dg1234);
sl@0
  1303
				)
sl@0
  1304
			err1=errCode;
sl@0
  1305
			__UHEAP_SETFAIL(RAllocator::ENone,0);
sl@0
  1306
			TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
sl@0
  1307
			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
sl@0
  1308
			rollBack1=NULL;
sl@0
  1309
			TRAP(leaveCode,
sl@0
  1310
				errCode=testArray.Swap(&dgBADF00D_2);
sl@0
  1311
				)
sl@0
  1312
			__UHEAP_SETFAIL(RAllocator::ENone,0);
sl@0
  1313
			//If the first Add fails then the object should not be removed
sl@0
  1314
			if (!err1)
sl@0
  1315
				{
sl@0
  1316
				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
sl@0
  1317
				TEST(errCode==KErrNone);
sl@0
  1318
				TEST(leaveCode==KErrNone);
sl@0
  1319
				}
sl@0
  1320
			//If the swap fails, then the add still needs to be removed
sl@0
  1321
			//Note that it is the ID that matters here... dgBADF00D & dgBADF00D_2 have same id.
sl@0
  1322
			TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
sl@0
  1323
			TEST(errCode==KErrNone);
sl@0
  1324
			TEST(leaveCode==KErrNone);
sl@0
  1325
			TEST(testArray.IsEmpty());
sl@0
  1326
			ResetArray(testArray);
sl@0
  1327
			CleanupStack::Check(markerCleanup);
sl@0
  1328
			__UHEAP_CHECK(0);
sl@0
  1329
			}
sl@0
  1330
		break;
sl@0
  1331
		//
sl@0
  1332
		case 5:
sl@0
  1333
				
sl@0
  1334
		//I don't really care whether the individual calls succeed or fail, 
sl@0
  1335
		//just whether it leaks overall, and that the error codes correspond to no-action
sl@0
  1336
		for (TInt faultRate=1;faultRate<5;faultRate++)
sl@0
  1337
			{
sl@0
  1338
			INFO_PRINTF2(_L("Sub test P5: AddTLC/SwapTLC: memory faulting %i"),faultRate);
sl@0
  1339
			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
sl@0
  1340
			TInt err1=KErrNone,err2=KErrNone,err3=KErrNone;
sl@0
  1341
			rollBack1=NULL;
sl@0
  1342
			TRAP(leaveCode,
sl@0
  1343
				rollBack1=testArray.AddTLC(&dg1234);
sl@0
  1344
				CleanupStack::Check(rollBack1);
sl@0
  1345
				testArray.CommitP(rollBack1);	
sl@0
  1346
				)
sl@0
  1347
			err1=leaveCode;
sl@0
  1348
			__UHEAP_SETFAIL(RAllocator::ENone,0);
sl@0
  1349
			TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
sl@0
  1350
			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
sl@0
  1351
			rollBack1=NULL;
sl@0
  1352
			TRAP(leaveCode,
sl@0
  1353
				rollBack1=testArray.SwapTLC(&dgBADF00D_2);
sl@0
  1354
				CleanupStack::Check(rollBack1);
sl@0
  1355
				testArray.CommitP(rollBack1);	
sl@0
  1356
				)
sl@0
  1357
			//If the first Add fails then the object should not be removed
sl@0
  1358
			if (!err1)
sl@0
  1359
				{
sl@0
  1360
				TRAP(leaveCode,
sl@0
  1361
					rollBack1=testArray.RemoveTLC(dg1234.Id());			
sl@0
  1362
					CleanupStack::Check(rollBack1);
sl@0
  1363
					testArray.CommitP(rollBack1);	
sl@0
  1364
					)
sl@0
  1365
				err2=leaveCode;
sl@0
  1366
				}
sl@0
  1367
			//If the swap fails, then the add still needs to be removed
sl@0
  1368
			//Note that it is the ID that matters here... dgBADF00D & dgBADF00D_2 have same id.
sl@0
  1369
			TRAP(leaveCode,
sl@0
  1370
					rollBack1=testArray.RemoveTLC(dgBADF00D_2.Id());
sl@0
  1371
					CleanupStack::Check(rollBack1);
sl@0
  1372
					testArray.CommitP(rollBack1);	
sl@0
  1373
					)
sl@0
  1374
			err3=leaveCode;
sl@0
  1375
			
sl@0
  1376
			
sl@0
  1377
			__UHEAP_SETFAIL(RAllocator::ENone,0);
sl@0
  1378
			//If the Removes failed then the object should be removed again
sl@0
  1379
			if (err2)
sl@0
  1380
				{
sl@0
  1381
				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
sl@0
  1382
				TEST(errCode==KErrNone);
sl@0
  1383
				TEST(leaveCode==KErrNone);
sl@0
  1384
				}
sl@0
  1385
			if (err3)
sl@0
  1386
				{
sl@0
  1387
				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
sl@0
  1388
				TEST(errCode==KErrNone);
sl@0
  1389
				TEST(leaveCode==KErrNone);
sl@0
  1390
				}
sl@0
  1391
			TEST(testArray.IsEmpty());
sl@0
  1392
			ResetArray(testArray);
sl@0
  1393
			CleanupStack::Check(markerCleanup);
sl@0
  1394
			__UHEAP_CHECK(0);
sl@0
  1395
			}
sl@0
  1396
				
sl@0
  1397
		break;
sl@0
  1398
		//
sl@0
  1399
		case 6:
sl@0
  1400
	//this set does leak:
sl@0
  1401
	
sl@0
  1402
		INFO_PRINTF1(_L("Sub test P6: AddLC/SwapLC: Cleanup item gets popped - unfixable leaks"));
sl@0
  1403
			TEST(testArray.IsEmpty());
sl@0
  1404
			TRAP(leaveCode,
sl@0
  1405
				testArray.AddLC(&dg1234);
sl@0
  1406
				CleanupStack::Pop();
sl@0
  1407
				);	
sl@0
  1408
			TEST(leaveCode==KErrNone);
sl@0
  1409
			TEST(!testArray.IsEmpty());
sl@0
  1410
		
sl@0
  1411
		CleanupStack::Check(markerCleanup);
sl@0
  1412
		__UHEAP_CHECK(KArrayMemUseBaseline+1);	
sl@0
  1413
			
sl@0
  1414
			TRAP(leaveCode,
sl@0
  1415
				testArray.AddLC(&dgBADF00D);
sl@0
  1416
				CleanupStack::Pop();
sl@0
  1417
				)
sl@0
  1418
			TEST(leaveCode==KErrNone);
sl@0
  1419
		CleanupStack::Check(markerCleanup);
sl@0
  1420
		__UHEAP_CHECK(KArrayMemUseBaseline+2);	
sl@0
  1421
			rollBack1=NULL;
sl@0
  1422
			TRAP(leaveCode,
sl@0
  1423
				errCode=testArray.SwapLC(&dgBADF00D_2);
sl@0
  1424
				CleanupStack::Pop();
sl@0
  1425
				);	
sl@0
  1426
			TEST(errCode==KErrNone);
sl@0
  1427
			TEST(leaveCode==KErrNone);
sl@0
  1428
			TEST(!testArray.IsEmpty());
sl@0
  1429
				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
sl@0
  1430
			TEST(errCode==KErrNone);
sl@0
  1431
			TEST(leaveCode==KErrNone);
sl@0
  1432
				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
sl@0
  1433
			TEST(errCode==KErrNone);
sl@0
  1434
			TEST(leaveCode==KErrNone);
sl@0
  1435
			TEST(testArray.IsEmpty());
sl@0
  1436
			rollBack1=NULL;
sl@0
  1437
			expectedLeakCount=3;
sl@0
  1438
		break;
sl@0
  1439
		//
sl@0
  1440
		case 7:
sl@0
  1441
			returnCode=EFalse;
sl@0
  1442
		break;
sl@0
  1443
		}
sl@0
  1444
	ResetArray(testArray);
sl@0
  1445
	CleanupStack::Check(markerCleanup);
sl@0
  1446
	__UHEAP_CHECK(expectedLeakCount);
sl@0
  1447
	__UHEAP_MARKENDC(expectedLeakCount);
sl@0
  1448
	if (expectedLeakCount!=0)
sl@0
  1449
		{	//Ensure that the leaked items are no longer associated with this debug level.
sl@0
  1450
			//Note that __DbgSetAllocFail(FALSE,RAllocator::EReset,1) resets the debug level to 0, 
sl@0
  1451
			//so levels can't be nested when using this call.
sl@0
  1452
		__UHEAP_MARK;			
sl@0
  1453
	    __UHEAP_TOTAL_RESET;	
sl@0
  1454
		INFO_PRINTF2(_L("Anticipated %i leaks declassified"),expectedLeakCount);	//can't get here if wrong
sl@0
  1455
		}
sl@0
  1456
			
sl@0
  1457
	CleanupStack::PopAndDestroy(markerCleanup);
sl@0
  1458
	((CTWsGraphsStep*)iStep)->RecordTestResultL();
sl@0
  1459
	return returnCode;
sl@0
  1460
	}
sl@0
  1461
sl@0
  1462
/**
sl@0
  1463
	@param 	failcase		index to test to perform
sl@0
  1464
	@param	aWrappedParams  represents inter-thread information when test is run on a private thread
sl@0
  1465
				if aWrappedParams is NULL then the test is running on the main thread.
sl@0
  1466
	@return true if there are higher-numbered fail cases.
sl@0
  1467
sl@0
  1468
   @SYMTestCaseID GRAPHICS-WSERV-NegAddSwapGDArray-0001
sl@0
  1469
   @SYMDEF			DEF093926  
sl@0
  1470
  
sl@0
  1471
   @SYMTestCaseDesc DEF093926: Check for stability of Add and Swap unwind methods in isolation,
sl@0
  1472
   					specifically checking that bad inputs are rejected gracefully.
sl@0
  1473
   		Note that this code is testing the functionality of a class internal to CWindowServer.
sl@0
  1474
   		At present CWindowServer presents just a simple shim on this class, 
sl@0
  1475
   		but if that implementation of  CWindowServer changes than this test will be redudant.
sl@0
  1476
   
sl@0
  1477
   @SYMTestPriority High
sl@0
  1478
   
sl@0
  1479
   @SYMTestStatus Implemented
sl@0
  1480
   
sl@0
  1481
   @SYMTestActions
sl@0
  1482
   
sl@0
  1483
		Add/Swap: no Cleanup item - no leaks after Remove the added items
sl@0
  1484
   	    AddTLC/SwapTLC: Cleanup item requires Commit - check for no leaks after Remove.
sl@0
  1485
   	    AddTLC/SwapTLC: Cleanup item gets executed by forced Leave  - check for no leaks after.
sl@0
  1486
		AddTLC, SwapTLC in allocation failure scenarios. Add/Swap don't allocate anything!
sl@0
  1487
		obsoleted AddLC/SwapLC to ensure correct function when forced Leave - check for no leaks after
sl@0
  1488
		obsoleted AddLC/SwapLC to ensure correct function. These will always leak in good case.
sl@0
  1489
	Calls NegTestAddSwapGDArrayL.	
sl@0
  1490
	case 1/2/3: Tests AddL, AddLC, AddTLC that a NULL input is rejected
sl@0
  1491
	case 4/5/6: Tests SwapL, SwapLC, SwapTLC that a NULL input is rejected
sl@0
  1492
	case 7/8/9: Tests AddL, AddLC, AddTLC that a repeat input is rejected
sl@0
  1493
	case 10/11/12: Tests SwapL, SwapLC, SwapTLC that a non-repeat input is rejected
sl@0
  1494
   @SYMTestExpectedResults 
sl@0
  1495
 */
sl@0
  1496
TBool CTWsGraphs::NegTestAddSwapGDArrayL(TInt failcase,WrapTestCall*aWrappedParams)
sl@0
  1497
	{
sl@0
  1498
	((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-NegAddSwapGDArray-0001"));
sl@0
  1499
	_LIT(KCategory,"WsGraphicDrawer");
sl@0
  1500
	if (!aWrappedParams)
sl@0
  1501
		{
sl@0
  1502
		INFO_PRINTF2(_L("NegTestAddSwapGDArrayL Negative sub test %i"),failcase);
sl@0
  1503
		};
sl@0
  1504
    CWsGraphicDrawerArray testArray;
sl@0
  1505
    TGraphicDrawerId id1234=  	{  	1234,		EFalse    	};
sl@0
  1506
    TGraphicDrawerId idBADF00D=	{  	0xBADF00D,	EFalse    	};
sl@0
  1507
    WsGraphicDrawer dg1234;		
sl@0
  1508
    dg1234.ConstructL(id1234);
sl@0
  1509
    WsGraphicDrawer dgBADF00D;	
sl@0
  1510
    dgBADF00D.ConstructL(idBADF00D);
sl@0
  1511
    WsGraphicDrawer dgBADF00D_2;
sl@0
  1512
    dgBADF00D_2.ConstructL(idBADF00D);
sl@0
  1513
    CWsGraphicDrawerArray::XRollBackBase* rollBack1=NULL;
sl@0
  1514
 	TInt errCode=KErrAbort;
sl@0
  1515
	TInt leaveCode=KErrNone;
sl@0
  1516
	TBool	returnMoreTests=ETrue;
sl@0
  1517
	DummyCleanup markerCleanup;
sl@0
  1518
	TBool mayPanic=EFalse;
sl@0
  1519
#ifdef __WINS__
sl@0
  1520
	mayPanic=ETrue;
sl@0
  1521
#endif
sl@0
  1522
sl@0
  1523
	CleanupStack::PushL(markerCleanup);	 //This allows me to check the stack is clear!
sl@0
  1524
	__UHEAP_MARK;
sl@0
  1525
	
sl@0
  1526
	switch (failcase)
sl@0
  1527
		{
sl@0
  1528
		case 1:	//NULL arg: expected result:  returns KErrArgument
sl@0
  1529
	    	TRAP(leaveCode,
sl@0
  1530
	    		errCode=testArray.Add(NULL);
sl@0
  1531
	    		)
sl@0
  1532
			TEST(leaveCode==KErrNone);
sl@0
  1533
	    	ReportNegativeResultfail(__LINE__,errCode,KErrArgument);
sl@0
  1534
	    break;
sl@0
  1535
		case 2:	//NULL arg: expected result: throws KErrArgument
sl@0
  1536
			TRAP(leaveCode,	
sl@0
  1537
				rollBack1=testArray.AddTLC(NULL);
sl@0
  1538
				TEST(EFalse);	//Should never get here!
sl@0
  1539
				)
sl@0
  1540
			TEST(rollBack1==NULL);
sl@0
  1541
	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrArgument);
sl@0
  1542
	    break;
sl@0
  1543
		case 3:	//NULL arg: expected result: debug: panic. In release doesn't return any information!
sl@0
  1544
			if (!aWrappedParams && mayPanic)
sl@0
  1545
				{
sl@0
  1546
			    LaunchNegTestCall(failcase,EWsGraphicDrawerPanicBadArgument,KCategory);
sl@0
  1547
				}
sl@0
  1548
			else
sl@0
  1549
				{
sl@0
  1550
				TRAP(leaveCode,
sl@0
  1551
					testArray.AddLC(NULL);
sl@0
  1552
					User::Leave(1234);  //Panics before here in debug. No leak if cleanup is taken.
sl@0
  1553
					);	
sl@0
  1554
				TEST(leaveCode==1234);	//Panics before here in debug
sl@0
  1555
				}
sl@0
  1556
	    break;
sl@0
  1557
		//
sl@0
  1558
		case 4:	//NULL arg: expected result: returns KErrArgument
sl@0
  1559
	    	TRAP(leaveCode,
sl@0
  1560
	    		errCode=testArray.Swap(NULL)
sl@0
  1561
	    		)
sl@0
  1562
			TEST(leaveCode==KErrNone);
sl@0
  1563
	    	ReportNegativeResultfail(__LINE__,errCode,KErrArgument);
sl@0
  1564
	    break;
sl@0
  1565
		case 5:	//expected result:  throws KErrArgument
sl@0
  1566
			TRAP(leaveCode,
sl@0
  1567
				rollBack1=testArray.SwapTLC(NULL);
sl@0
  1568
				testArray.CommitP(rollBack1);
sl@0
  1569
				)
sl@0
  1570
			TEST(rollBack1==NULL);
sl@0
  1571
	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrArgument);
sl@0
  1572
	    break;
sl@0
  1573
		case 6:	//NULL arg: expected result: debug: panic. In release doesn't return any information!
sl@0
  1574
			if (!aWrappedParams && mayPanic)
sl@0
  1575
				{
sl@0
  1576
			    LaunchNegTestCall(failcase,EWsGraphicDrawerPanicBadArgument,KCategory);
sl@0
  1577
				}
sl@0
  1578
			else
sl@0
  1579
				{
sl@0
  1580
				TRAP(leaveCode,
sl@0
  1581
					errCode=testArray.SwapLC(NULL);
sl@0
  1582
					User::Leave(1234);  //Panics before here in debug. No leak if cleanup is taken.
sl@0
  1583
					);
sl@0
  1584
				TEST(leaveCode==1234);	//Panics before here in debug
sl@0
  1585
				TEST(errCode==KErrNotFound);
sl@0
  1586
				}
sl@0
  1587
		break;
sl@0
  1588
		//
sl@0
  1589
		case 7:	//Add overwrites: expected result: returns KErrAlreadyExists
sl@0
  1590
	    	TRAP(leaveCode,
sl@0
  1591
	    		errCode=testArray.Add(&dg1234);
sl@0
  1592
	    		)
sl@0
  1593
			TEST(errCode==KErrNone);
sl@0
  1594
			TEST(leaveCode==KErrNone);
sl@0
  1595
	    	TRAP(leaveCode,
sl@0
  1596
	    		errCode=testArray.Add(&dg1234);		//oops! Already added!
sl@0
  1597
	    		)
sl@0
  1598
			TEST(leaveCode==KErrNone);
sl@0
  1599
	    	ReportNegativeResultfail(__LINE__,errCode,KErrAlreadyExists);
sl@0
  1600
	    break;
sl@0
  1601
		case 8:	//Add overwrites: expected result:  throws KErrAlreadyExists
sl@0
  1602
	    	TRAP(leaveCode,
sl@0
  1603
	    		errCode=testArray.Add(&dg1234);
sl@0
  1604
	    		)
sl@0
  1605
			TEST(errCode==KErrNone);
sl@0
  1606
			TEST(leaveCode==KErrNone);
sl@0
  1607
			TRAP(leaveCode,	
sl@0
  1608
				rollBack1=testArray.AddTLC(&dg1234);		//oops! Already added!
sl@0
  1609
				testArray.CommitP(rollBack1);
sl@0
  1610
				)
sl@0
  1611
			TEST(rollBack1==NULL);
sl@0
  1612
	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrAlreadyExists);
sl@0
  1613
	    break;
sl@0
  1614
		case 9:	//Add overwrites: expected result: debug: does not panic, but throws KErrAlreadyExists.
sl@0
  1615
	    	TRAP(leaveCode,
sl@0
  1616
	    		errCode=testArray.Add(&dg1234);
sl@0
  1617
	    		)
sl@0
  1618
			TEST(errCode==KErrNone);
sl@0
  1619
			TEST(leaveCode==KErrNone);
sl@0
  1620
			TRAP(leaveCode,
sl@0
  1621
					testArray.AddLC(&dg1234);		//oops! Already added! Should leave.
sl@0
  1622
					User::Leave(1234);  //Should leave before here! No leak if cleanup is taken.
sl@0
  1623
				);	
sl@0
  1624
	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrAlreadyExists);
sl@0
  1625
	    break;
sl@0
  1626
		//
sl@0
  1627
		case 10:	//Swap empty slot: expected result:  returns KErrNotFound
sl@0
  1628
	    	TRAP(leaveCode,
sl@0
  1629
	    		errCode=testArray.Swap(&dg1234) 		//oops! Nothing to swap with!
sl@0
  1630
	    		)
sl@0
  1631
			TEST(leaveCode==KErrNone);
sl@0
  1632
	    	ReportNegativeResultfail(__LINE__,errCode,KErrNotFound);
sl@0
  1633
	    break;
sl@0
  1634
		case 11:	//Swap empty slot: expected result: throws KErrNotFound
sl@0
  1635
			TRAP(leaveCode,
sl@0
  1636
				rollBack1=testArray.SwapTLC(&dg1234);		//oops! Nothing to swap with!
sl@0
  1637
				testArray.CommitP(rollBack1);
sl@0
  1638
				)
sl@0
  1639
			TEST(rollBack1==NULL);
sl@0
  1640
	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrNotFound);
sl@0
  1641
	    break;
sl@0
  1642
		case 12:	//Swap empty slot: expected result: debug: panic. In release doesn't return any information!
sl@0
  1643
			if (!aWrappedParams && mayPanic)
sl@0
  1644
				{
sl@0
  1645
			    LaunchNegTestCall(failcase,EWsGraphicDrawerPanicBadArgument,KCategory);
sl@0
  1646
				}
sl@0
  1647
			else
sl@0
  1648
				{
sl@0
  1649
				TRAP(leaveCode,
sl@0
  1650
					errCode=testArray.SwapLC(&dg1234);		//oops! Nothing to swap with!
sl@0
  1651
					User::Leave(1234);  //Panics before here in debug. No leak if cleanup is taken.
sl@0
  1652
					);	
sl@0
  1653
				TEST(leaveCode==1234);			//Panics before here in debug
sl@0
  1654
				TEST(errCode==KErrNotFound);	//Panics before here in debug
sl@0
  1655
				}
sl@0
  1656
	    break;
sl@0
  1657
	    
sl@0
  1658
		//
sl@0
  1659
		default:
sl@0
  1660
			returnMoreTests=EFalse;
sl@0
  1661
		}
sl@0
  1662
	ResetArray(testArray);
sl@0
  1663
	CleanupStack::Check(markerCleanup);
sl@0
  1664
	__UHEAP_CHECK(0);
sl@0
  1665
	__UHEAP_MARKENDC(0);
sl@0
  1666
    testArray.Close();
sl@0
  1667
//    CWsGraphicDrawerArray::testArrayValidator::ResetArray(&testArray);
sl@0
  1668
	CleanupStack::PopAndDestroy(markerCleanup);
sl@0
  1669
	return returnMoreTests;
sl@0
  1670
	}
sl@0
  1671
sl@0
  1672
/**
sl@0
  1673
   @SYMTestCaseID 	GRAPHICS-WSERV-LeakInService-0001
sl@0
  1674
   @SYMDEF			DEF093926  
sl@0
  1675
   @SYMTestCaseDesc Check for leaks over repeated re-assignments.
sl@0
  1676
   
sl@0
  1677
   @SYMTestPriority High
sl@0
  1678
   
sl@0
  1679
   @SYMTestStatus Implemented
sl@0
  1680
   
sl@0
  1681
   @SYMTestActions 
sl@0
  1682
   Repeatedly create the same bitmap instance
sl@0
  1683
   After a few initial wobbles in the server-side HeapCount it should not increase
sl@0
  1684
   5 calls are made without checking the level, then 5 more check the level.
sl@0
  1685
   Note that as we are testing the main server heap, 
sl@0
  1686
   other threads may interrupt and perform operations that change the memory figures.
sl@0
  1687
   
sl@0
  1688
   @SYMTestExpectedResults The CWsGraphicBitmap objects are created and no leaks are reported.
sl@0
  1689
 */	
sl@0
  1690
void CTWsGraphs::DoTestLeakInServiceL()
sl@0
  1691
	{
sl@0
  1692
		INFO_PRINTF1(_L("DoTestLeakInServiceL"));
sl@0
  1693
		const TInt prepCount=5;
sl@0
  1694
		const TInt testCount=5;
sl@0
  1695
		
sl@0
  1696
				
sl@0
  1697
		TUid uid1 = {0x10000001};
sl@0
  1698
		TUid uid2 = {0x10000002};
sl@0
  1699
		 
sl@0
  1700
		TWsGraphicId twsGraphicId1(uid1);
sl@0
  1701
		TEST(twsGraphicId1.Uid()==uid1);
sl@0
  1702
		
sl@0
  1703
		TWsGraphicId twsGraphicId2(uid2);
sl@0
  1704
		TEST(twsGraphicId2.Uid()==uid2);
sl@0
  1705
		
sl@0
  1706
		TWsGraphicId twsGraphicId3(twsGraphicId2);
sl@0
  1707
		TEST(twsGraphicId3.Uid()==uid2);
sl@0
  1708
		
sl@0
  1709
		TWsGraphicId twsGraphicId4(1);
sl@0
  1710
		twsGraphicId4.Set(uid1);
sl@0
  1711
		TEST(twsGraphicId4.Uid()==uid1);		
sl@0
  1712
sl@0
  1713
		TSize screenSize = TheClient->iScreen->SizeInPixels();
sl@0
  1714
		
sl@0
  1715
		__UHEAP_RESET;
sl@0
  1716
		__UHEAP_MARK;
sl@0
  1717
		// Create local shared CWsGraphicBitmap	
sl@0
  1718
		// Repeat operation for any sign of memory leak...	
sl@0
  1719
		CFbsBitmap bitmap2;
sl@0
  1720
		CFbsBitmap mask2;		
sl@0
  1721
		
sl@0
  1722
		bitmap2.Create(screenSize,TheClient->iScreen->DisplayMode());
sl@0
  1723
		mask2.Create(bitmap2.SizeInPixels(),TheClient->iScreen->DisplayMode());
sl@0
  1724
			
sl@0
  1725
		TInt c0=TheClient->iWs.HeapCount();
sl@0
  1726
		CWsGraphicBitmap* bTestX = CWsGraphicBitmap::NewL(twsGraphicId2.Uid(), &bitmap2,&mask2);		
sl@0
  1727
		for (TInt i=0;i<prepCount;i++)
sl@0
  1728
			{
sl@0
  1729
			//TInt c2=TheClient->iWs.HeapCount();
sl@0
  1730
			delete bTestX; 								
sl@0
  1731
			//TInt c3=TheClient->iWs.HeapCount();
sl@0
  1732
			bTestX = CWsGraphicBitmap::NewL(twsGraphicId2.Uid(), &bitmap2,&mask2);		
sl@0
  1733
			//TInt c4=TheClient->iWs.HeapCount();
sl@0
  1734
			}
sl@0
  1735
		// Give WSERV a chance to settle.
sl@0
  1736
		TheClient->iWs.Finish();
sl@0
  1737
		User::After (1000000); //1s
sl@0
  1738
		
sl@0
  1739
		TInt c1=TheClient->iWs.HeapCount();
sl@0
  1740
		TInt failures=0;
sl@0
  1741
		for (TInt i=0;i<testCount;i++)
sl@0
  1742
			{
sl@0
  1743
			TInt c2=TheClient->iWs.HeapCount();
sl@0
  1744
			delete bTestX;
sl@0
  1745
			//TInt c3=TheClient->iWs.HeapCount();
sl@0
  1746
			//The heap count doesn't go down after delete operation
sl@0
  1747
			//because the delete message is buffered by the server, because it does not have a return value.
sl@0
  1748
			//Aparrently, although CWsGraphicBitmap and TheClient terminate at the same server,
sl@0
  1749
			//and use the same general heap (I have tested this under debug),
sl@0
  1750
			//they do not share the same session, so flushing TheClient does not effect CWsGraphicBitmap
sl@0
  1751
			bTestX = CWsGraphicBitmap::NewL(twsGraphicId2.Uid(), &bitmap2,&mask2);		
sl@0
  1752
			
sl@0
  1753
			// Give WSERV a chance to settle.
sl@0
  1754
			TheClient->iWs.Finish();
sl@0
  1755
			User::After (1000000); //1s
sl@0
  1756
sl@0
  1757
			TInt c4=TheClient->iWs.HeapCount();   
sl@0
  1758
			//Can compare immediately after allocation as the server doesn't buffer the create command.
sl@0
  1759
			if (!(c2==c4))
sl@0
  1760
				{
sl@0
  1761
				if (c4 > c2) // only fail the test if the count has increased
sl@0
  1762
					{
sl@0
  1763
					failures++;
sl@0
  1764
					}
sl@0
  1765
				INFO_PRINTF2(_L("Server Heap count change accross delete/new = %i"),c4-c2);
sl@0
  1766
				}
sl@0
  1767
			}
sl@0
  1768
		// Outside of main loop to avoid client/wserv interaction during test.
sl@0
  1769
		TEST(failures==0);
sl@0
  1770
		TInt c5=TheClient->iWs.HeapCount();
sl@0
  1771
		TEST((c1-c5)/testCount==0);	   //If every call leaked.
sl@0
  1772
		if ((c1-c5)/testCount)
sl@0
  1773
			{
sl@0
  1774
			INFO_PRINTF3(_L("Server Heap count change accross %i delete/new cycles = %i"),testCount,c5-c1);
sl@0
  1775
			INFO_PRINTF3(_L("Before %i / After %i"),c1,c5);
sl@0
  1776
			}
sl@0
  1777
		
sl@0
  1778
		delete bTestX; 
sl@0
  1779
		
sl@0
  1780
		__UHEAP_CHECK(0);
sl@0
  1781
		__UHEAP_MARKEND;
sl@0
  1782
		
sl@0
  1783
	}
sl@0
  1784
/**
sl@0
  1785
 @SYMTestCaseID				GRAPHICS-WSERV-0381 
sl@0
  1786
 @SYMDEF					DEF095063
sl@0
  1787
 @SYMTestCaseDesc			Test case for INC098114 CWsGraphicDrawer::SendMessage panics window server
sl@0
  1788
 @SYMTestPriority			Medium
sl@0
  1789
 @SYMTestStatus				Implemented
sl@0
  1790
 @SYMTestActions			Enable the test flag and reproduce the defect
sl@0
  1791
							Action step:
sl@0
  1792
							-Instruct plugin to register event handler
sl@0
  1793
							-Draw fullscreen window (plugin will receive window visibility changed event)
sl@0
  1794
							-Set the test flag 
sl@0
  1795
							-Query visibility region from plugin side
sl@0
  1796
							-Instruct plugin to unregister event handler
sl@0
  1797
							-Destroy fullscreen window (plugin will not receive window visibility changed event)
sl@0
  1798
						
sl@0
  1799
 @SYMTestExpectedResults	wserv should not panic with the fix
sl@0
  1800
*/	
sl@0
  1801
sl@0
  1802
TestState CTWsGraphs::TestSuccessiveMessageL()
sl@0
  1803
	{
sl@0
  1804
	if (iSubState==0)
sl@0
  1805
		{
sl@0
  1806
		_LIT(KTestSuccessiveMessage, "TestSuccessiveMessage");
sl@0
  1807
		INFO_PRINTF1(KTestSuccessiveMessage);
sl@0
  1808
sl@0
  1809
		++iSubState;
sl@0
  1810
		iListen->Enable(ETrue);
sl@0
  1811
		CreateWindowL();
sl@0
  1812
		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
sl@0
  1813
		//Set the test flag to enable the reproduction of defect
sl@0
  1814
		iListen->SetTestFlag();
sl@0
  1815
		iListen->QueryPlugin(iListenInfo);
sl@0
  1816
		iListen->Enable(EFalse);
sl@0
  1817
		DestroyWindowL();
sl@0
  1818
		return EWait;
sl@0
  1819
		}
sl@0
  1820
sl@0
  1821
	++(iTest->iState);
sl@0
  1822
	iSubState = 0;
sl@0
  1823
	return ENext;
sl@0
  1824
	}
sl@0
  1825
sl@0
  1826
TestState CTWsGraphs::TestWindowGroupChangeL()
sl@0
  1827
	{
sl@0
  1828
	if (iSubState==0)
sl@0
  1829
		{
sl@0
  1830
		_LIT(KTestWindowGroupChange, "TestWindowGroupChange");
sl@0
  1831
		INFO_PRINTF1(KTestWindowGroupChange);
sl@0
  1832
sl@0
  1833
		++iSubState;
sl@0
  1834
		iListen->Enable(ETrue);
sl@0
  1835
		CreateWindowL();
sl@0
  1836
		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
sl@0
  1837
		iListen->QueryPlugin(iListenInfo);
sl@0
  1838
		return EWait;
sl@0
  1839
		}
sl@0
  1840
sl@0
  1841
	if (iSubState==1)
sl@0
  1842
		{
sl@0
  1843
		++iSubState;
sl@0
  1844
		iOriginalWindowGroupId = iListenInfo.iWindowGroupId;
sl@0
  1845
		iNewWin = CCrWin::NewL(iTest->iScreenNumber, ETrue);
sl@0
  1846
		iListen->QueryPlugin(iListenInfo);
sl@0
  1847
		return EWait;
sl@0
  1848
		}
sl@0
  1849
sl@0
  1850
	TEST(iListenInfo.iWindowGroupId != iOriginalWindowGroupId);
sl@0
  1851
	
sl@0
  1852
	delete iNewWin;
sl@0
  1853
	iNewWin = NULL;
sl@0
  1854
	iListen->Enable(EFalse);
sl@0
  1855
	DestroyWindowL();
sl@0
  1856
	++(iTest->iState);
sl@0
  1857
	iSubState = 0;
sl@0
  1858
	return ENext;
sl@0
  1859
	}
sl@0
  1860
sl@0
  1861
/**
sl@0
  1862
 @SYMTestCaseID				GRAPHICS-WSERV-0382
sl@0
  1863
 @SYMDEF 					INC085451
sl@0
  1864
 @SYMTestCaseDesc			Test Animation frame rate
sl@0
  1865
 @SYMTestPriority			Medium
sl@0
  1866
 @SYMTestStatus				Implemented
sl@0
  1867
 @SYMTestActions			Simulate an Animation artwork by calling DrawWsGraphic and DoDraw.
sl@0
  1868
							Action step:
sl@0
  1869
							-Calls DrawWsGraphic for two different animations with different frame rates
sl@0
  1870
							-Retrieve the frame count for two differnt frames per seconds
sl@0
  1871
							-Test the two frame rate shouldn't be same.
sl@0
  1872
sl@0
  1873
 @SYMTestExpectedResults	Animation Frame rate should be different for different frames per second
sl@0
  1874
*/
sl@0
  1875
TestState CTWsGraphs::TestFrameRateL()
sl@0
  1876
	{
sl@0
  1877
	//Check for Transparency enabled in wsini.ini
sl@0
  1878
	if (TransparencySupportedL()==KErrNotSupported)
sl@0
  1879
		{
sl@0
  1880
		++(iTest->iState);
sl@0
  1881
		return ENext;
sl@0
  1882
		}
sl@0
  1883
sl@0
  1884
	// flush transparent window destruction created in TransparencySupportedL before
sl@0
  1885
	// proceeding with the test
sl@0
  1886
	TheClient->iWs.Flush();
sl@0
  1887
sl@0
  1888
	//Here 	iSubState is 0, when this functions executes first time 
sl@0
  1889
	//		iSubState is 1 means the call is from a callback function.
sl@0
  1890
	if(iSubState == 0)
sl@0
  1891
		{
sl@0
  1892
		_LIT(KTestFrameRate, "TestFrameRate");
sl@0
  1893
		INFO_PRINTF1(KTestFrameRate);
sl@0
  1894
sl@0
  1895
		++iSubState;
sl@0
  1896
		iTestframerate = CGraphicTestFrameRate::NewL(iTest->iScreenNumber);
sl@0
  1897
sl@0
  1898
		//Set the callback function
sl@0
  1899
		iTestframerate->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
sl@0
  1900
sl@0
  1901
		//Create the window and call the graphic animation
sl@0
  1902
		CreateWindowL(EFalse);
sl@0
  1903
		iWin->DrawGraphic(iTestframerate->Id().Id());
sl@0
  1904
		return EWait;
sl@0
  1905
		}
sl@0
  1906
sl@0
  1907
	//PeterI wait a while for animations to redraw then query the plugin
sl@0
  1908
	User::After(2000000);
sl@0
  1909
	TheClient->iWs.Flush();
sl@0
  1910
	TheClient->WaitForRedrawsToFinish();
sl@0
  1911
	TheClient->iWs.Finish();
sl@0
  1912
sl@0
  1913
	//Invoke the plug-in and get the counter value
sl@0
  1914
	Mem::FillZ(&iAnimCount, sizeof(TAnimRate));
sl@0
  1915
sl@0
  1916
	iTestframerate->QueryPlugin(iAnimCount);
sl@0
  1917
	TheClient->iWs.Flush();
sl@0
  1918
	TheClient->WaitForRedrawsToFinish();
sl@0
  1919
	TheClient->iWs.Finish();
sl@0
  1920
sl@0
  1921
	//Compare and test the total frame rate for two different frame counts....
sl@0
  1922
	TEST((iAnimCount.iAnim1>0 && iAnimCount.iAnim2>0) && iAnimCount.iAnim1 !=iAnimCount.iAnim2);
sl@0
  1923
	if(iSubState == 1)
sl@0
  1924
		{
sl@0
  1925
		DestroyWindowL();
sl@0
  1926
		delete iTestframerate;
sl@0
  1927
		}
sl@0
  1928
	++(iTest->iState);
sl@0
  1929
	iSubState = 0;
sl@0
  1930
	return ENext;
sl@0
  1931
	}
sl@0
  1932
sl@0
  1933
/**
sl@0
  1934
 @SYMTestCaseID				GRAPHICS-WSERV-0438 
sl@0
  1935
 @SYMDEF					INC103472
sl@0
  1936
 @SYMTestCaseDesc			CRedrawRegion::ContainsDrawers does not look for all drawers 
sl@0
  1937
 @SYMTestPriority			Medium
sl@0
  1938
 @SYMTestStatus				Implemented
sl@0
  1939
 @SYMTestActions			Create ECom-plugins to enable the scenario, in which there is one simple and one container drawer. 
sl@0
  1940
 							In the container drawer, two other simple drawers are enabled. Each drawer draws a coloured ellipse.
sl@0
  1941
 							In this case, when the contained drawer is requested to change the colour of the ellipse, the screen will not be updated
sl@0
  1942
 							without the fix.  
sl@0
  1943
 							Action step:
sl@0
  1944
							-Create four CRP graphics.
sl@0
  1945
							-Call the simple drawer and container drawer to draw ellipses. The container drawer
sl@0
  1946
							 also enables two other simple drawers to draw ellipses in different colors.
sl@0
  1947
							-Update the color of each ellipse in turn. 
sl@0
  1948
							-Check that the screen display is as required.						
sl@0
  1949
 @SYMTestExpectedResults	The colour of each ellipse residing in the drawers is successfully updated. Those for the contained drawers wont be updated without the fix. 
sl@0
  1950
*/	
sl@0
  1951
void CTWsGraphs::TestNestedDrawerCRP()
sl@0
  1952
	{
sl@0
  1953
	_LIT(KTestContainDrawer, "Test INC103472: A Contained Drawer");
sl@0
  1954
	INFO_PRINTF1(KTestContainDrawer);
sl@0
  1955
sl@0
  1956
	RWindow window1(TheClient->iWs);
sl@0
  1957
	CleanupClosePushL(window1);
sl@0
  1958
	User::LeaveIfError(window1.Construct(*TheClient->iGroup->GroupWin(), ENullWsHandle));
sl@0
  1959
	
sl@0
  1960
	window1.EnableRedrawStore(ETrue);	// Force to enable the redraw storing
sl@0
  1961
	window1.SetRequiredDisplayMode(EColor256);	 // Do not set window size here to avoid hardware test failure
sl@0
  1962
	window1.SetBackgroundColor(KRgbDarkGreen);
sl@0
  1963
	window1.Activate();
sl@0
  1964
	
sl@0
  1965
	// A simple graphic
sl@0
  1966
	CWsSimpleGraphicBitmap* wsGraphic1 = CWsSimpleGraphicBitmap::NewL(KSimpleDrawerInterfaceId);
sl@0
  1967
	CleanupStack::PushL(wsGraphic1);
sl@0
  1968
	// A container graphic
sl@0
  1969
	CWsContainGraphicBitmap* wsGraphic2 = CWsContainGraphicBitmap::NewL(KContainDrawerInterfaceId);
sl@0
  1970
	CleanupStack::PushL(wsGraphic2);
sl@0
  1971
	// A contained graphic residing in the container graphic wsGraphic2 
sl@0
  1972
 	CWsSimpleGraphicBitmap* wsGraphic3 = CWsInvisibleGraphicBitmap1::NewL(KInvisibleDrawerInterfaceId1);
sl@0
  1973
 	CleanupStack::PushL(wsGraphic3);
sl@0
  1974
	// A contained graphic residing in the container graphic wsGraphic2
sl@0
  1975
 	CWsSimpleGraphicBitmap* wsGraphic4 = CWsInvisibleGraphicBitmap2::NewL(KInvisibleDrawerInterfaceId2);
sl@0
  1976
 	CleanupStack::PushL(wsGraphic4);
sl@0
  1977
sl@0
  1978
    window1.Invalidate();
sl@0
  1979
	window1.BeginRedraw();
sl@0
  1980
	TheClient->iGc->Activate(window1);
sl@0
  1981
	TheClient->iGc->Clear();
sl@0
  1982
	// Call CRP drawer to draw the coloured ellipses	
sl@0
  1983
	TheClient->iGc->DrawWsGraphic(wsGraphic1->Id(),TRect(TPoint(20,20),TSize(300,100)));
sl@0
  1984
	TheClient->iGc->DrawWsGraphic(wsGraphic2->Id(),TRect(TPoint(20,100),TSize(300,100)));	
sl@0
  1985
sl@0
  1986
    TheClient->iGc->Deactivate();
sl@0
  1987
	window1.EndRedraw();
sl@0
  1988
	TheClient->Flush();			   
sl@0
  1989
	
sl@0
  1990
	// Update the colour of four ellipses residing in four CRP drawers. 
sl@0
  1991
	TInt err = wsGraphic1->UpdateColor(KRgbRed);
sl@0
  1992
	TEST(KErrNone == err);
sl@0
  1993
	err = wsGraphic2->UpdateColor(KRgbDarkBlue);
sl@0
  1994
	TEST(KErrNone == err);
sl@0
  1995
	// If the fix is not inserted, the colour of the third and fourth ellipses residing in the contained drawers wont be updated
sl@0
  1996
	err = wsGraphic3->UpdateColor(KRgbDarkMagenta);
sl@0
  1997
	TEST(KErrNone == err);
sl@0
  1998
	err = wsGraphic4->UpdateColor(KRgbDarkCyan);	  //won't change the displayed color if there is a right place for flush()
sl@0
  1999
	TEST(KErrNone == err);
sl@0
  2000
	
sl@0
  2001
	TheClient->Flush();
sl@0
  2002
 	// Force some delays to wait until the color change
sl@0
  2003
    User::After(2000000);
sl@0
  2004
    // Test whether the screen content is changed as required
sl@0
  2005
    CheckResult();
sl@0
  2006
   	CleanupStack::PopAndDestroy(5,&window1);
sl@0
  2007
	}
sl@0
  2008
sl@0
  2009
// Check the screen display with the reference bitmap to ensure the color to be updated correctly
sl@0
  2010
void CTWsGraphs::CheckResult()
sl@0
  2011
	{
sl@0
  2012
    TSize size = TSize(320,200);//The maximum size of the screen content we are looking at
sl@0
  2013
sl@0
  2014
    // Create a reference bitmap
sl@0
  2015
    CFbsBitmap* bitmapRef = new(ELeave) CFbsBitmap;
sl@0
  2016
   	CleanupStack::PushL(bitmapRef);
sl@0
  2017
	User::LeaveIfError(bitmapRef->Create(size, EColor256));
sl@0
  2018
	CFbsBitGc* gc;
sl@0
  2019
	CFbsBitmapDevice* bitmapDev = CFbsBitmapDevice::NewL(bitmapRef);
sl@0
  2020
	TEST(bitmapDev!=NULL);
sl@0
  2021
   	CleanupStack::PushL(bitmapDev);
sl@0
  2022
	User::LeaveIfError(bitmapDev->CreateContext(gc));
sl@0
  2023
   	CleanupStack::PushL(gc);
sl@0
  2024
	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
  2025
	gc->SetBrushColor(KRgbDarkGreen);
sl@0
  2026
	gc->Clear(TRect(TPoint(0,0), size));//background dark green
sl@0
  2027
	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
  2028
    gc->SetBrushColor(KRgbRed);
sl@0
  2029
	gc->DrawEllipse(TRect(TPoint(20,20),TSize(300,100)));  //map to the simple drawer
sl@0
  2030
	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
  2031
	gc->SetBrushColor(KRgbDarkBlue);
sl@0
  2032
	gc->DrawEllipse(TRect(TPoint(20,100),TSize(300,100)));	//map to the container drawer
sl@0
  2033
	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
  2034
	gc->SetBrushColor(KRgbDarkMagenta);
sl@0
  2035
	gc->DrawEllipse(TRect(TPoint(100,150),TSize(50,50)));	//map to the contained drawer
sl@0
  2036
	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
  2037
 	gc->SetBrushColor(KRgbDarkCyan);
sl@0
  2038
	gc->DrawEllipse(TRect(TPoint(200,150),TSize(50,50)));	//map to the contained drawer
sl@0
  2039
    TInt bitmapHeight = bitmapRef->SizeInPixels().iHeight;
sl@0
  2040
	TInt bitmapWidth = bitmapRef->SizeInPixels().iWidth;
sl@0
  2041
  
sl@0
  2042
   	// Copy the screen content to bitmap
sl@0
  2043
	INFO_PRINTF1(_L("Capture screen content."));
sl@0
  2044
	CFbsBitmap* screenBitmap = new(ELeave) CFbsBitmap();
sl@0
  2045
	CleanupStack::PushL(screenBitmap);
sl@0
  2046
	User::LeaveIfError(screenBitmap->Create(size, TheClient->iScreen->DisplayMode()));
sl@0
  2047
	TRect rct = TRect(TPoint(0,0), size);
sl@0
  2048
	User::LeaveIfError(TheClient->iScreen->CopyScreenToBitmap(screenBitmap,rct));
sl@0
  2049
sl@0
  2050
	// Compare the displayed bitmap against the reference one
sl@0
  2051
	INFO_PRINTF1(_L("Compare the displayed bitmap against the expected one."));
sl@0
  2052
	TInt lineLength=bitmapRef->ScanLineLength(bitmapWidth, EColor256);
sl@0
  2053
	HBufC8* compareLineBuf=HBufC8::NewLC(lineLength);
sl@0
  2054
	TPtr8 compareLinePtr(compareLineBuf->Des());
sl@0
  2055
	HBufC8* screenLineBuf=HBufC8::NewLC(lineLength);
sl@0
  2056
	TPtr8 screenLinePtr(screenLineBuf->Des());
sl@0
  2057
	for (TInt index=0; index<bitmapHeight; index++)
sl@0
  2058
		{
sl@0
  2059
		bitmapRef->GetScanLine(compareLinePtr, TPoint(0,index), bitmapWidth, EColor256);
sl@0
  2060
		screenBitmap->GetScanLine(screenLinePtr, TPoint(0,index),bitmapWidth, EColor256);
sl@0
  2061
		TInt compareResult=compareLinePtr.Compare(screenLinePtr);
sl@0
  2062
		if (compareResult!=0)
sl@0
  2063
			{
sl@0
  2064
			INFO_PRINTF2(_L("Scanline compare failed: %d"),index);
sl@0
  2065
			TEST(EFalse);
sl@0
  2066
			break;
sl@0
  2067
			}
sl@0
  2068
		}
sl@0
  2069
	CleanupStack::PopAndDestroy(6,bitmapRef);  
sl@0
  2070
sl@0
  2071
	} 
sl@0
  2072
sl@0
  2073
void ResetScreenMode(TAny* aAny)
sl@0
  2074
	{
sl@0
  2075
	CWsScreenDevice* screen=static_cast<CWsScreenDevice*>(aAny);
sl@0
  2076
	screen->SetScreenMode(0);
sl@0
  2077
	screen->SetAppScreenMode(0);
sl@0
  2078
	}
sl@0
  2079
sl@0
  2080
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
  2081
sl@0
  2082
void CTWsGraphs::TestScreenModeChangeL()
sl@0
  2083
	{
sl@0
  2084
	_LIT(KLog,"Screen Doesn't match bitmap.  Size=(%d,%d) winSizeMode=%d redrawMode=%d modeIndex=%d");
sl@0
  2085
// A simple CRP graphic to draw in the test
sl@0
  2086
	CWsSimpleGraphicBitmap* wsGraphic1=CWsSimpleGraphicBitmap::NewL(KSimpleDrawerInterfaceId);
sl@0
  2087
	CleanupStack::PushL(wsGraphic1);
sl@0
  2088
	RWindow testWin(TheClient->iWs);
sl@0
  2089
	CleanupClosePushL(testWin);
sl@0
  2090
	User::LeaveIfError(testWin.Construct(*TheClient->iGroup->GroupWin(),0xbadbad));
sl@0
  2091
	testWin.SetRequiredDisplayMode(EColor64K);
sl@0
  2092
	testWin.Activate();
sl@0
  2093
// Cleanup display mode by setting back to 0 if we leave in the tests
sl@0
  2094
	CleanupStack::PushL(TCleanupItem(ResetScreenMode,TheClient->iScreen));
sl@0
  2095
	TInt numScreenModes=TheClient->iScreenModes.Count();
sl@0
  2096
	TBool match;
sl@0
  2097
sl@0
  2098
	for(TInt winSizeMode=0;winSizeMode<2;winSizeMode++)
sl@0
  2099
		{ // Two size modes, fullScreen and non-full screen
sl@0
  2100
		for(TInt redrawMode=0;redrawMode<2;redrawMode++)
sl@0
  2101
			{ // Two redraw modes to test drawing inside and outside of a redraw.
sl@0
  2102
			const TBool drawInsideRedraw=(redrawMode==0);
sl@0
  2103
			for(TInt modeIndex=0;modeIndex<numScreenModes;modeIndex++)
sl@0
  2104
				{
sl@0
  2105
				const TInt screenMode=TheClient->iScreenModes[modeIndex];
sl@0
  2106
				const TPoint origin=TheClient->iScreen->GetScreenModeScaledOrigin(screenMode);
sl@0
  2107
				if (origin.iX!=0 || origin.iY!=0)
sl@0
  2108
					continue;
sl@0
  2109
				// Enable redirection before changing screen mode as this is what we are testing
sl@0
  2110
				iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue);
sl@0
  2111
				TheClient->iScreen->SetAppScreenMode(screenMode);
sl@0
  2112
				TheClient->iScreen->SetScreenMode(screenMode);
sl@0
  2113
sl@0
  2114
				TPixelsAndRotation sizeAndRotation;
sl@0
  2115
				TheClient->iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation);
sl@0
  2116
//
sl@0
  2117
				TSize screenSize(TheClient->iScreen->SizeInPixels());
sl@0
  2118
				if(sizeAndRotation.iRotation == CFbsBitGc::EGraphicsOrientationRotated90 || 
sl@0
  2119
						sizeAndRotation.iRotation == CFbsBitGc::EGraphicsOrientationRotated270)
sl@0
  2120
					{
sl@0
  2121
					screenSize.iWidth = Min(screenSize.iWidth, 240);//to make sure we won't exceed physical screen size
sl@0
  2122
					}
sl@0
  2123
				TSize winSize(screenSize);
sl@0
  2124
				TPoint winPos;
sl@0
  2125
				if (winSizeMode==1)
sl@0
  2126
					{
sl@0
  2127
					winSize.iWidth=winSize.iWidth*2/3;
sl@0
  2128
					winSize.iHeight=winSize.iHeight*3/4;
sl@0
  2129
					winPos.iX=(screenSize.iWidth-winSize.iWidth)/4;
sl@0
  2130
					winPos.iY=(screenSize.iHeight-winSize.iHeight)*3/4;
sl@0
  2131
					}
sl@0
  2132
				testWin.SetExtent(winPos,winSize);
sl@0
  2133
				TSize halfSize(winSize.iWidth/2,winSize.iHeight);
sl@0
  2134
				TRect leftHalf(halfSize);
sl@0
  2135
				TRect rightHalf(TPoint(halfSize.iWidth,0),halfSize);
sl@0
  2136
				TRect leftEllipse(leftHalf);
sl@0
  2137
				leftEllipse.Shrink(4,4);
sl@0
  2138
				TRect rightEllipse(rightHalf);
sl@0
  2139
				rightEllipse.Shrink(4,4);
sl@0
  2140
				// Draw half the screen with redirection on, should only go to redirection test bitmap
sl@0
  2141
				// Then draw again with redirection off, this time should go to the screen
sl@0
  2142
				// The two steps are drawn with the color of the left/right rectangles swapped.
sl@0
  2143
				for(TInt drawStep=0;drawStep<2;drawStep++)
sl@0
  2144
					{
sl@0
  2145
					TRgb leftColor;
sl@0
  2146
					TRgb rightColor;
sl@0
  2147
					if (drawStep==0)
sl@0
  2148
						{
sl@0
  2149
						leftColor=KRgbGreen;
sl@0
  2150
						rightColor=KRgbRed;
sl@0
  2151
						}
sl@0
  2152
					else
sl@0
  2153
						{ // Turn re-direction off for second time around loop
sl@0
  2154
						iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse);
sl@0
  2155
						leftColor=KRgbRed;
sl@0
  2156
						rightColor=KRgbGreen;
sl@0
  2157
						}
sl@0
  2158
					testWin.Invalidate();
sl@0
  2159
					testWin.BeginRedraw();
sl@0
  2160
					if (!drawInsideRedraw)
sl@0
  2161
						testWin.EndRedraw();
sl@0
  2162
					CWindowGc* testWinGc=TheClient->iGc;
sl@0
  2163
					testWinGc->Activate(testWin);
sl@0
  2164
					testWinGc->SetBrushColor(leftColor);
sl@0
  2165
					testWinGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
  2166
					testWinGc->DrawRect(leftHalf);
sl@0
  2167
					// Call CRP drawer to draw the coloured ellipses
sl@0
  2168
					TheClient->iGc->DrawWsGraphic(wsGraphic1->Id(),leftEllipse);
sl@0
  2169
					testWinGc->SetBrushColor(rightColor);
sl@0
  2170
					testWinGc->DrawRect(rightHalf);
sl@0
  2171
					TheClient->iGc->DrawWsGraphic(wsGraphic1->Id(),rightEllipse);
sl@0
  2172
					testWinGc->Deactivate();
sl@0
  2173
					if (drawInsideRedraw)
sl@0
  2174
						testWin.EndRedraw();
sl@0
  2175
					TheClient->iWs.Flush();
sl@0
  2176
					}
sl@0
  2177
				// We now check that the left rect of the re-directed drawing matches the right half
sl@0
  2178
				// of the on-screen drawing
sl@0
  2179
				CFbsBitmap* screenCopy=new(ELeave) CFbsBitmap;
sl@0
  2180
				CleanupStack::PushL(screenCopy);
sl@0
  2181
				User::LeaveIfError(screenCopy->Create(screenSize, EColor64K));
sl@0
  2182
				TheClient->iScreen->CopyScreenToBitmap(screenCopy);
sl@0
  2183
				match=CompareBitmapArea16Bpp(iFrontCopy,winPos,screenCopy,TPoint(winPos.iX+rightHalf.iTl.iX,winPos.iY),halfSize);
sl@0
  2184
				TEST(match);
sl@0
  2185
				if (!match)
sl@0
  2186
					LOG_MESSAGE6(KLog,screenSize.iWidth,screenSize.iHeight,winSizeMode,redrawMode,modeIndex);
sl@0
  2187
				// As a double check also check the right half of the off-screen drawing matches the
sl@0
  2188
				// on-screen left half.
sl@0
  2189
				match=CompareBitmapArea16Bpp(iFrontCopy,TPoint(winPos.iX+rightHalf.iTl.iX,winPos.iY),screenCopy,winPos,halfSize);
sl@0
  2190
				TEST(match);
sl@0
  2191
				if (!match)
sl@0
  2192
					LOG_MESSAGE6(KLog,screenSize.iWidth,screenSize.iHeight,winSizeMode,redrawMode,modeIndex);
sl@0
  2193
				CleanupStack::PopAndDestroy(screenCopy);
sl@0
  2194
				}
sl@0
  2195
			}
sl@0
  2196
		}
sl@0
  2197
 	CleanupStack::PopAndDestroy(3,wsGraphic1);
sl@0
  2198
 	
sl@0
  2199
	TEST(iNotify1->iResult);
sl@0
  2200
	if(iNotify1->iResult==EFalse)
sl@0
  2201
		{
sl@0
  2202
		INFO_PRINTF1(iNotify1->iError);
sl@0
  2203
		}
sl@0
  2204
	TEST(iNotify2->iResult);
sl@0
  2205
	if(iNotify1->iResult==EFalse)
sl@0
  2206
		{
sl@0
  2207
		INFO_PRINTF1(iNotify2->iError);
sl@0
  2208
		}
sl@0
  2209
	}
sl@0
  2210
sl@0
  2211
#endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
  2212
sl@0
  2213
/**
sl@0
  2214
@SYMTestCaseID 		GRAPHICS-WSERV-0443
sl@0
  2215
sl@0
  2216
@SYMDEF     		INC109263
sl@0
  2217
sl@0
  2218
@SYMTestCaseDesc	TWindowServerEvent::NotifyDrawer can refer to a deleted array index causing a crash
sl@0
  2219
sl@0
  2220
@SYMTestPriority 	High
sl@0
  2221
sl@0
  2222
@SYMTestStatus		Implemented
sl@0
  2223
sl@0
  2224
@SYMTestActions		Cause an event that will generate the following behaviour through TWindowServerEvent::NotifyDrawer()
sl@0
  2225
		
sl@0
  2226
					The for loop performs the following:
sl@0
  2227
					0) Drawer handler 1: Remove handle 1 ; 					Drawer handler 2: Do nothing
sl@0
  2228
					1) Drawer handler 1: Remove handle 1,Add handle 1 ;		Drawer handler 2: Do nothing
sl@0
  2229
					2) Drawer handler 1: Add handle 1 ; 					Drawer handler 2: Do nothing
sl@0
  2230
					3) Drawer handler 1: Remove handle 2 ; 					Drawer handler 2: Do nothing
sl@0
  2231
					4) Drawer handler 1: Remove handle 2,Add handle 2 ; 	Drawer handler 2: Do nothing
sl@0
  2232
					5) Drawer handler 1: Add handle 2 ; 					Drawer handler 2: Do nothing
sl@0
  2233
					6) Drawer handler 1: Remove handle 1,Remove handle 2 ; 	Drawer handler 2: Do nothing
sl@0
  2234
			
sl@0
  2235
					Repeat with handlers 1 and 2 swapped
sl@0
  2236
sl@0
  2237
@SYMTestExpectedResults		Loops through TWindowServerEvent::NotifyDrawer() should complete without crashing wserv
sl@0
  2238
*/
sl@0
  2239
sl@0
  2240
void CTWsGraphs::TestNotifyRemoval()
sl@0
  2241
	{
sl@0
  2242
	_LIT(KTestEventNotification, "TestDrawerEventHandler");
sl@0
  2243
	INFO_PRINTF1(KTestEventNotification);
sl@0
  2244
	++iSubState;
sl@0
  2245
sl@0
  2246
	for (TInt ii = 0; ii<KNotifyDoNothing; ii++)
sl@0
  2247
		{
sl@0
  2248
		INFO_PRINTF2(_L("For loop %d"), ii);
sl@0
  2249
		iNotify1->SetBehaviour(ii);					//Enable this plugin and set it to an event handling method
sl@0
  2250
		iNotify2->SetBehaviour(KNotifyDoNothing);	//Add a second drawer handler which is enabled but does nothing
sl@0
  2251
		CreateWindowL();							//Change visibility activating the event handlers - Fails if wserv crashes!
sl@0
  2252
		iNotify1->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
sl@0
  2253
		iNotify2->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
sl@0
  2254
		DestroyWindowL();
sl@0
  2255
		}
sl@0
  2256
	INFO_PRINTF1(_L("Swap handlers"));
sl@0
  2257
	for (TInt ii = 0; ii<KNotifyDoNothing; ii++)
sl@0
  2258
		{
sl@0
  2259
		INFO_PRINTF2(_L("For loop %d"), ii);
sl@0
  2260
		iNotify2->SetBehaviour(KNotifyDoNothing);	//Add a first drawer handler which is enabled but does nothing
sl@0
  2261
		iNotify1->SetBehaviour(ii);					//Enable this plugin and set it to an event handling method
sl@0
  2262
		CreateWindowL();							//Change visibility activating the event handlers - Fails if wserv crashes!
sl@0
  2263
		iNotify2->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
sl@0
  2264
		iNotify1->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
sl@0
  2265
		DestroyWindowL();
sl@0
  2266
		}
sl@0
  2267
sl@0
  2268
	TEST(ETrue);		// If the test has failed WServ will have paniced.
sl@0
  2269
	}
sl@0
  2270
sl@0
  2271
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
sl@0
  2272
/**
sl@0
  2273
@SYMTestCaseID           GRAPHICS-WSERV-0491
sl@0
  2274
@SYMPREQ                 PREQ39
sl@0
  2275
@SYMTestPriority         High
sl@0
  2276
@SYMTestCaseDesc         Draw using a ECom-plugin which has direct access to the screen/OSB buffer 
sl@0
  2277
@SYMTestActions          Create the plugin
sl@0
  2278
						 Draw using the plugin
sl@0
  2279
						 Update the position of the white line to line 70 and test
sl@0
  2280
						 Update the position of the white line to line 80 and test
sl@0
  2281
@SYMTestExpectedResults  White lines are drawn on the correct positions.
sl@0
  2282
*/
sl@0
  2283
void CTWsGraphs::TestMWsUiBufferL()
sl@0
  2284
	{
sl@0
  2285
	const TInt KWhiteLinePos = 70;
sl@0
  2286
	const TRect KBlueRect(TPoint(50,50),TSize(100,100));
sl@0
  2287
		
sl@0
  2288
	// Construct and setup window to be drawn to
sl@0
  2289
	RWindow window1 = RWindow(TheClient->iWs);
sl@0
  2290
	CleanupClosePushL(window1);
sl@0
  2291
    User::LeaveIfError(window1.Construct(*TheClient->iGroup->GroupWin(),ENullWsHandle));
sl@0
  2292
    TSize winSize=TSize(TheClient->iScreen->SizeInPixels());
sl@0
  2293
    window1.SetExtent(TPoint(0,0),winSize);
sl@0
  2294
    window1.Activate();
sl@0
  2295
    
sl@0
  2296
	CWsBufferGraphic* graphic = CWsBufferGraphic::NewL();
sl@0
  2297
	CleanupStack::PushL(graphic);
sl@0
  2298
    
sl@0
  2299
	// Draw inital drawing with a Crp which is blue rect and a white line at line 0
sl@0
  2300
	TheGc->Activate(window1);
sl@0
  2301
	TheGc->Clear();
sl@0
  2302
	window1.BeginRedraw();
sl@0
  2303
	TheGc->DrawWsGraphic(graphic->Id(),KBlueRect);
sl@0
  2304
	window1.EndRedraw();
sl@0
  2305
	TheGc->Deactivate();
sl@0
  2306
	
sl@0
  2307
    TheClient->iWs.Finish();
sl@0
  2308
    User::After(2000000);
sl@0
  2309
	
sl@0
  2310
	// Update the position of the white line to line 70
sl@0
  2311
	INFO_PRINTF1(_L("Update position of white line to line 70"));
sl@0
  2312
	graphic->UpdateWhiteLinePos(KWhiteLinePos);
sl@0
  2313
	TheClient->iWs.Finish();
sl@0
  2314
	// Force some delays to wait until the line position changes
sl@0
  2315
    User::After(2000000);
sl@0
  2316
    //Test white line has been drawn and is in the correct postion
sl@0
  2317
    TBool res1 = IsWhiteLine(KWhiteLinePos);
sl@0
  2318
    TEST(res1);
sl@0
  2319
    
sl@0
  2320
	// Update the position of the white line to line 80
sl@0
  2321
    INFO_PRINTF1(_L("Update position of white line to line 80"));
sl@0
  2322
	graphic->UpdateWhiteLinePos(KWhiteLinePos+10);
sl@0
  2323
	TheClient->iWs.Finish();
sl@0
  2324
	// Force some delays to wait until the line position changes
sl@0
  2325
	User::After(2000000);
sl@0
  2326
	// Test white line has been drawn and is in the correct postion
sl@0
  2327
    TBool res2 = IsWhiteLine(KWhiteLinePos+10);
sl@0
  2328
    TEST(res2);
sl@0
  2329
   
sl@0
  2330
	graphic->Destroy();
sl@0
  2331
	CleanupStack::PopAndDestroy(2, &window1);
sl@0
  2332
	}
sl@0
  2333
sl@0
  2334
// Test whether a line is completely white
sl@0
  2335
TBool CTWsGraphs::IsWhiteLine(TInt aWhiteLinePos)
sl@0
  2336
	{
sl@0
  2337
    TRgb color;
sl@0
  2338
    TPoint pixel;
sl@0
  2339
    
sl@0
  2340
    for(TInt xPos = 0; xPos < TheClient->iScreen->SizeInPixels().iWidth; xPos++)
sl@0
  2341
    	{
sl@0
  2342
    	pixel = TPoint(xPos,aWhiteLinePos);
sl@0
  2343
    	TheClient->iScreen->GetPixel(color,pixel);
sl@0
  2344
    	if(color.Red() != 255 && color.Blue() != 255 && color.Green() != 255)
sl@0
  2345
    		{
sl@0
  2346
    		return EFalse;
sl@0
  2347
    		}
sl@0
  2348
    	}
sl@0
  2349
    return ETrue;
sl@0
  2350
	}
sl@0
  2351
#endif //TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
sl@0
  2352
sl@0
  2353
/**
sl@0
  2354
	DoTestL() method, called by the WSERV Test Framework.
sl@0
  2355
*/
sl@0
  2356
void CTWsGraphs::RunTestCaseL(TInt /*aCurTestCase*/)
sl@0
  2357
	{
sl@0
  2358
	_LIT(KTest1,"DoTestWsGraphics");
sl@0
  2359
	_LIT(KTest2,"DoTestOOMWsGraphics");
sl@0
  2360
	_LIT(KTest3,"Interface Extension");
sl@0
  2361
	_LIT(KTest4,"Screen Redirection");
sl@0
  2362
	_LIT(KTest5,"TextCursor1");
sl@0
  2363
	_LIT(KTest6,"TextCursor2");
sl@0
  2364
	_LIT(KTest7,"Flicker Redirection");
sl@0
  2365
	_LIT(KTest8,"Event Notification");
sl@0
  2366
	_LIT(KTest9,"Successive Message");
sl@0
  2367
	_LIT(KTest10,"Redirection Using WsBackBuffer");
sl@0
  2368
	_LIT(KTest11,"Group Change");
sl@0
  2369
	_LIT(KTest12,"Frame Rate");
sl@0
  2370
	_LIT(KTest13,"Leak In Service");
sl@0
  2371
	_LIT(KTest14,"Add/Swap GDArray");
sl@0
  2372
	_LIT(KTest15,"Nested Drawer CRP");
sl@0
  2373
	_LIT(KTest16,"Notify Removal");
sl@0
  2374
	_LIT(KTest17,"Screen Mode Change");
sl@0
  2375
	_LIT(KTest18,"UI Buffer");
sl@0
  2376
	_LIT(KTest19,"Graphics Drawer Coverage");
sl@0
  2377
	CFbsBitmap bitmap1;
sl@0
  2378
	CFbsBitmap mask1;
sl@0
  2379
	CWsGraphicBitmap* bTest=NULL;
sl@0
  2380
	TSize screenSize=TheClient->iScreen->SizeInPixels();
sl@0
  2381
sl@0
  2382
	bitmap1.Create(screenSize,TheClient->iScreen->DisplayMode());
sl@0
  2383
	mask1.Create(screenSize,TheClient->iScreen->DisplayMode());
sl@0
  2384
	((CTWsGraphsStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
  2385
sl@0
  2386
	switch(++iTest->iState)
sl@0
  2387
		{
sl@0
  2388
	case 1:
sl@0
  2389
/**
sl@0
  2390
	@SYMTestCaseID	GRAPHICS-WSERV-0528
sl@0
  2391
*/
sl@0
  2392
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0528"));
sl@0
  2393
		// Launch new process with PROTSERV capability to run CWSGraphics tests in
sl@0
  2394
		iTest->LogSubTest(KTest1);
sl@0
  2395
		// This process only launches succesfully when _DEBUG is defined for the build, because it depends
sl@0
  2396
		// on the existance of debug macros such as _UHEAP_MARK, _UHEAP_MARKEND, _UHEAP_FAILNEXT, ... etc
sl@0
  2397
		LaunchNewProcess(KTestExe);
sl@0
  2398
		break;
sl@0
  2399
	case 2:
sl@0
  2400
		{
sl@0
  2401
		/**
sl@0
  2402
   		@SYMTestCaseID GRAPHICS-WSERV-0017
sl@0
  2403
sl@0
  2404
		@SYMPREQ	PREQ1246
sl@0
  2405
sl@0
  2406
		@SYMDEF		DEF081259
sl@0
  2407
sl@0
  2408
		@SYMTestCaseDesc Out of memery test when creating a CWsGraphic.
sl@0
  2409
sl@0
  2410
		@SYMTestPriority High
sl@0
  2411
sl@0
  2412
		@SYMTestStatus Implemented
sl@0
  2413
sl@0
  2414
		@SYMTestActions Out of memory test when creating a CWsGraphic.
sl@0
  2415
sl@0
  2416
		@SYMTestExpectedResults Whenever an API call fails, it should leave the number
sl@0
  2417
				of allocated heap cells unchanged.
sl@0
  2418
		*/
sl@0
  2419
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0017"));
sl@0
  2420
sl@0
  2421
		iTest->LogSubTest(KTest2);
sl@0
  2422
		TInt failRate;
sl@0
  2423
		for(failRate=1;;failRate++)
sl@0
  2424
			{
sl@0
  2425
			__UHEAP_RESET;
sl@0
  2426
			__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
sl@0
  2427
			__UHEAP_MARK;
sl@0
  2428
sl@0
  2429
			TRAPD(ret,bTest=CWsGraphicBitmap::NewL(&bitmap1,&mask1));
sl@0
  2430
			TEST((ret==KErrNone || ret==KErrNoMemory));
sl@0
  2431
			if (ret!=KErrNone && ret!=KErrNoMemory)
sl@0
  2432
				{
sl@0
  2433
				_LIT(KLog,"Failed to create CWsGraphicBitmap  error=%d");
sl@0
  2434
				LOG_MESSAGE2(KLog,ret);
sl@0
  2435
				}
sl@0
  2436
			if (ret!=KErrNone)
sl@0
  2437
				{
sl@0
  2438
				__UHEAP_MARKEND;
sl@0
  2439
				}
sl@0
  2440
			else
sl@0
  2441
				{
sl@0
  2442
				TEST(bTest!=NULL);
sl@0
  2443
				if (bTest==NULL)
sl@0
  2444
					{
sl@0
  2445
					_LIT(KLog,"Object creation didn't leave but returned NULL");
sl@0
  2446
					LOG_MESSAGE(KLog);
sl@0
  2447
					}
sl@0
  2448
				delete bTest;
sl@0
  2449
				bTest=NULL;
sl@0
  2450
				__UHEAP_MARKEND;
sl@0
  2451
				TLogMessageText logMessageText;
sl@0
  2452
				_LIT(KSet,"OOM test succeds after %d allocations.");
sl@0
  2453
				logMessageText.Format(KSet,failRate);
sl@0
  2454
				LOG_MESSAGE(logMessageText);
sl@0
  2455
				break;
sl@0
  2456
				}
sl@0
  2457
			}
sl@0
  2458
		__UHEAP_RESET;
sl@0
  2459
		}
sl@0
  2460
		break;
sl@0
  2461
	case 3:
sl@0
  2462
		iTest->LogSubTest(KTest3);
sl@0
  2463
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0371"));
sl@0
  2464
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
  2465
			
sl@0
  2466
			if (TestInterfaceExtensionL()==EWait)
sl@0
  2467
				--iTest->iState;
sl@0
  2468
#endif
sl@0
  2469
		break;
sl@0
  2470
	case 4:
sl@0
  2471
		iTest->LogSubTest(KTest4);
sl@0
  2472
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0372"));
sl@0
  2473
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA			
sl@0
  2474
			if (TestScreenRedirectionL()==EWait)
sl@0
  2475
				--iTest->iState;
sl@0
  2476
#endif
sl@0
  2477
		break;
sl@0
  2478
	case 5:
sl@0
  2479
		iTest->LogSubTest(KTest5);
sl@0
  2480
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0363"));
sl@0
  2481
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA	
sl@0
  2482
			if (TestTextCursorUnderRedirectionL(ETestStandardTextCursor) == EWait)
sl@0
  2483
				--iTest->iState;
sl@0
  2484
#endif
sl@0
  2485
		break;
sl@0
  2486
	case 6:
sl@0
  2487
		iTest->LogSubTest(KTest6);
sl@0
  2488
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0363"));
sl@0
  2489
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA	
sl@0
  2490
			if (TestTextCursorUnderRedirectionL(ETestCustomTextCursor) == EWait)
sl@0
  2491
				--iTest->iState;
sl@0
  2492
#endif
sl@0
  2493
		break;
sl@0
  2494
	case 7:
sl@0
  2495
		iTest->LogSubTest(KTest7);
sl@0
  2496
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0376"));
sl@0
  2497
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA			
sl@0
  2498
			if (TestFlickerRedirectionL()==EWait)
sl@0
  2499
				--iTest->iState;
sl@0
  2500
#endif
sl@0
  2501
		break;
sl@0
  2502
	case 8:
sl@0
  2503
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0378"));
sl@0
  2504
		iTest->LogSubTest(KTest8);
sl@0
  2505
		if (TestEventNotificationL()==EWait)
sl@0
  2506
			--iTest->iState;
sl@0
  2507
		break;
sl@0
  2508
	case 9:
sl@0
  2509
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0381"));
sl@0
  2510
		iTest->LogSubTest(KTest9);
sl@0
  2511
		if (TestSuccessiveMessageL()==EWait)
sl@0
  2512
			--iTest->iState;
sl@0
  2513
		break;
sl@0
  2514
	case 10:
sl@0
  2515
		iTest->LogSubTest(KTest10);
sl@0
  2516
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0527"));
sl@0
  2517
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
  2518
		if(TestRedirectionUsingWsBackBufferL()==EWait)
sl@0
  2519
			--iTest->iState;
sl@0
  2520
#endif
sl@0
  2521
		break;
sl@0
  2522
	case 11:
sl@0
  2523
/**
sl@0
  2524
	@SYMTestCaseID	GRAPHICS-WSERV-0529
sl@0
  2525
*/
sl@0
  2526
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0529"));
sl@0
  2527
		iTest->LogSubTest(KTest11);
sl@0
  2528
		if(TestWindowGroupChangeL()==EWait)
sl@0
  2529
			--iTest->iState;
sl@0
  2530
		break;
sl@0
  2531
	case 12:
sl@0
  2532
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0382"));
sl@0
  2533
		iTest->LogSubTest(KTest12);
sl@0
  2534
		if(TestFrameRateL()==EWait)
sl@0
  2535
			--iTest->iState;
sl@0
  2536
		break;
sl@0
  2537
	case 13:
sl@0
  2538
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-LeakInService-0001"));
sl@0
  2539
		iTest->LogSubTest(KTest13);
sl@0
  2540
		DoTestLeakInServiceL();
sl@0
  2541
		break;
sl@0
  2542
	case 14:
sl@0
  2543
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-NegAddSwapGDArray-0001"));
sl@0
  2544
		iTest->LogSubTest(KTest14);
sl@0
  2545
		TestAddSwapGDArrayL();
sl@0
  2546
		break;
sl@0
  2547
	case 15:
sl@0
  2548
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0438"));
sl@0
  2549
		iTest->LogSubTest(KTest15);
sl@0
  2550
		TestNestedDrawerCRP();
sl@0
  2551
		break;
sl@0
  2552
	case 16:
sl@0
  2553
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0443"));
sl@0
  2554
		iTest->LogSubTest(KTest16);
sl@0
  2555
		TestNotifyRemoval();
sl@0
  2556
		break;
sl@0
  2557
	case 17:
sl@0
  2558
		iTest->LogSubTest(KTest17);
sl@0
  2559
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0530"));
sl@0
  2560
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
sl@0
  2561
/**
sl@0
  2562
	@SYMTestCaseID	GRAPHICS-WSERV-0530
sl@0
  2563
*/
sl@0
  2564
			
sl@0
  2565
			TestScreenModeChangeL();
sl@0
  2566
#endif
sl@0
  2567
		break;
sl@0
  2568
	case 18:
sl@0
  2569
		iTest->LogSubTest(KTest18);
sl@0
  2570
		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0491"));
sl@0
  2571
#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
sl@0
  2572
			
sl@0
  2573
			TestMWsUiBufferL();
sl@0
  2574
#endif
sl@0
  2575
			break;
sl@0
  2576
		case 19:
sl@0
  2577
			iTest->LogSubTest(KTest19);
sl@0
  2578
/**
sl@0
  2579
	@SYMTestCaseID	GRAPHICS-WSERV-0531
sl@0
  2580
*/
sl@0
  2581
			((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0531"));
sl@0
  2582
			TestGraphicDrawerCoverage();
sl@0
  2583
			break;
sl@0
  2584
		default:
sl@0
  2585
			((CTWsGraphsStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
  2586
			((CTWsGraphsStep*)iStep)->CloseTMSGraphicsStep();
sl@0
  2587
			TestComplete();
sl@0
  2588
			break;
sl@0
  2589
		}
sl@0
  2590
	((CTWsGraphsStep*)iStep)->RecordTestResultL();
sl@0
  2591
	}
sl@0
  2592
sl@0
  2593
__WS_CONSTRUCT_STEP__(WsGraphs)