os/graphics/graphicsdeviceinterface/bitgdi/tbit/TDefect2.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.
     1 // Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <random.h>
    17 #include <s32file.h>
    18 #include <e32math.h>
    19 #include <s32mem.h>
    20 #include <graphics/gdi/gdiconsts.h>
    21 #include <e32cmn.h>
    22 #include "BITPANIC.H"
    23 #include "TDefect2.h"
    24 #include "fbsmessage.h"
    25 
    26 //===================================================================
    27 //In order to test multiple screens creation process on the Emulator, 
    28 //you have to extend your epoc.ini file with the following lines
    29 //_NewScreen_
    30 //ScreenWidth 640
    31 //ScreenHeight 480
    32 //===================================================================
    33 
    34 //
    35 //
    36 //Globals
    37 LOCAL_D RFs		FServSession;
    38 
    39 //
    40 //
    41 //Test file names
    42 _LIT(KArchiveFileName, "C:\\FbsBitGcArchive.dat");
    43 
    44 //
    45 //
    46 //Create/Destroy test environment global functions
    47 
    48 //Delete "aFullName" file.
    49 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
    50 	{
    51 	RFs fsSession;
    52 	TInt err = fsSession.Connect();
    53 	if(err == KErrNone)
    54 		{
    55 		TEntry entry;
    56 		if(fsSession.Entry(aFullName, entry) == KErrNone)
    57 			{
    58 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
    59 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
    60 			if(err != KErrNone) 
    61 				{
    62 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
    63 				}
    64 			err = fsSession.Delete(aFullName);
    65 			if(err != KErrNone) 
    66 				{
    67 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
    68 				}
    69 			}
    70 		fsSession.Close();
    71 		}
    72 	else
    73 		{
    74 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
    75 		}
    76 	}
    77 
    78 //
    79 CTDefect2::CTDefect2(CTestStep* aStep):
    80 	CTGraphicsBase(aStep),
    81 	iScrDev(NULL),
    82 	iGc(NULL),
    83 	iSize(0, 0),
    84 	iCurrentMode(ENone),
    85 	iBitmap(NULL),
    86 	iBmpDevice(NULL)
    87 	{
    88 	}
    89 
    90 CTDefect2::~CTDefect2()
    91 	{
    92 	DestroyFont();
    93 	DeleteBitmap();
    94 	DeleteGraphicsContext();
    95 	DeleteBitmapDevice();
    96 	DeleteScreenDevice();
    97 	}
    98 
    99 void CTDefect2::ConstructL()
   100 	{
   101 	User::LeaveIfError(::FServSession.Connect());
   102 	}
   103 
   104 void CTDefect2::RunTestCaseL(TInt aCurTestCase)
   105 	{
   106 	((CTDefect2Step*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   107 	_LIT(KTest1,"SubTest %d: DEF039237");
   108 	_LIT(KTest2,"SubTest %d: DEF039331");
   109 	_LIT(KTest3,"SubTest %d: DEF039650");
   110 	_LIT(KTest4,"SubTest %d: CFbsBitmap::GetPixel() performance");
   111 	_LIT(KTest5,"SubTest %d: Rotate/Move text");
   112 	_LIT(KTest6,"SubTest %d: SwapWidthAndHeight");
   113 	_LIT(KTest8,"SubTest %d: Clear with non-zero origin");
   114 	_LIT(KTest9,"SubTest %d: DEF115395: DrawBitmap & DrawBitmapMasked with a sourceRect out of the Bitmap bounds");
   115 	_LIT(KTest10,"SubTest %d: INC119063: General test CopyRect rewrite for low color depth (8,4,2, pixels per byte)");
   116 	_LIT(KTest11,"SubTest %d: INC120917: Dirty Mask Bitmap not remapped in BitBltMasked");
   117 	_LIT(KTest12,"SubTest %d: Zero-sized brush pattern bitmaps");
   118 	_LIT(KTest13,"SubTest %d: CopyRect with non-trivial alpha");
   119 	_LIT(KTest14,"SubTest %d: INC119063: CopyRect reading past end of bitmap data at unallocated pages");
   120 	_LIT(KTest15,"SubTest %d: INC128813 : CFbsBitGc::InternalizeL handle duplicate fail testing");
   121 	_LIT(KTest16,"SubTest %d: DEF132331 : CFbsScreenDevice PixelsToTwips conversions faulty with large inputs");
   122 	_LIT(KTest17,"SubTest %d: DEF137103: CFbsBitmapDevice::SetBits() should check bitmap size");
   123 	switch(aCurTestCase)
   124 		{
   125 	case 1:
   126 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0066"));
   127 		INFO_PRINTF2(KTest1,aCurTestCase);
   128 		DEF039237L();
   129 		break;
   130 	case 2:
   131 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0067"));
   132 		INFO_PRINTF2(KTest2,aCurTestCase);
   133 		DEF039331L();
   134 		break;
   135 	case 3:
   136 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0068"));
   137 		INFO_PRINTF2(KTest3,aCurTestCase);
   138 		DEF039650L();
   139 		break;
   140 	case 4:
   141 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0069"));
   142 		INFO_PRINTF2(KTest4,aCurTestCase);
   143 		GetPixelPerformance1L();
   144 		break;
   145 	case 5:
   146 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0070"));
   147 		INFO_PRINTF2(KTest5,aCurTestCase);
   148 		RotateMoveTextL();
   149 		break;
   150 	case 6:
   151 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0071"));
   152 		INFO_PRINTF2(KTest6,aCurTestCase);
   153 		SwapWidthAndHeightL();
   154 		break;
   155 	case 7:
   156 		// Test case moved to tmultiscreens.cpp
   157 		break;
   158 	case 8:
   159 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0073"));
   160 		INFO_PRINTF2(KTest8,aCurTestCase);
   161 		NonZeroOriginClearL();
   162 		break;
   163 	case 9:
   164 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0097"));
   165 		INFO_PRINTF2(KTest9,aCurTestCase);
   166 		DEF115395L();
   167 		break;
   168 	case 10:
   169 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0099"));
   170 		INFO_PRINTF2(KTest10,aCurTestCase);
   171 		ExerciseCopyRect();
   172 		break;
   173 	case 11:
   174 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0101"));
   175 		INFO_PRINTF2(KTest11,aCurTestCase);
   176 		TestDirtyMaskBitmapL();
   177 		break;
   178 	case 12:
   179 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0108"));
   180 		INFO_PRINTF2(KTest12,aCurTestCase);
   181 		ZeroSizedPatternBrushL();
   182 		break;
   183 	case 13:
   184 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0113"));
   185 		INFO_PRINTF2(KTest13,aCurTestCase);
   186 		CopyRectAlphaL();
   187 		break;
   188 	case 14: 	
   189 		//Note: This test generates panic windows... you may need to put your test before it.
   190 		//They will be closed at the end of the test set, but they may get in the way of your next test, sorry.
   191 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0098"));
   192 		INFO_PRINTF2(KTest14,aCurTestCase);
   193 		CopyRectReadOutsideBitmap();
   194 		break;
   195 	case 15:
   196 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0110"));
   197 		INFO_PRINTF2(KTest15,aCurTestCase);
   198 		CFbsBitGcInternalizeLFailL();
   199 		break;
   200 	case 16:
   201 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0111"));
   202 		INFO_PRINTF2(KTest16,aCurTestCase);
   203 		PixelsToTwipsConversionCheck();
   204 		break;
   205 	case 17:
   206 		((CTDefect2Step*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0112"));
   207 		INFO_PRINTF2(KTest17,aCurTestCase);
   208 		TestSetBitsL();
   209 		break;
   210 
   211     case 18:
   212         INFO_PRINTF1(_L("PDEF141192: test CFbsBitGc::DrawBitmapMasked()"));
   213         INFO_PRINTF1(_L("Test Red Channel"));
   214         TestMaskForSelectedValuesL(0);
   215         INFO_PRINTF1(_L("Test Green Channel"));
   216         TestMaskForSelectedValuesL(1);
   217         INFO_PRINTF1(_L("Test Blue Channel"));
   218         TestMaskForSelectedValuesL(2);
   219         break;
   220         
   221 	//Insert tests here
   222 
   223 	case 19:
   224 		((CTDefect2Step*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   225 		((CTDefect2Step*)iStep)->CloseTMSGraphicsStep();
   226 		TestComplete();
   227 		break;
   228 		}
   229 	((CTDefect2Step*)iStep)->RecordTestResultL();
   230 	}
   231 
   232 /**
   233  * @SYMTestCaseID GRAPHICS-BITGDI-0101
   234  *
   235  * @SYMDEF INC120917
   236  *
   237  * @SYMTestCaseDesc If mask bitmap has been dirtied (by resize/compress) 
   238  * 						then bitbltmasked should not read old memory contents
   239  *
   240  * @SYMTestPriority Normal
   241  *
   242  * @SYMTestStatus Implemented
   243  *
   244  * @SYMTestActions Create image and mask bitmap with  pattern and blit them for reference
   245  * 					create duplicate handle 
   246  * 					resize the mask on duplicate
   247  * 					verify that blit produces same result for same area on larger mask 
   248  * 					and change pattern
   249  * 					blit using duplicate handle and source
   250  * 					blit using original handle and source
   251  * 						in defect scenario these results are different (original same as reference)
   252  * 						in fix scenario they should be same (different to reference)
   253  * 					revalidate original handle reblit and verify now correct
   254  * 
   255  * 					repeat above steps: 
   256  * 					(this proves duplicate change causes original flag, not just duplication)
   257  * 					resize the mask on duplicate
   258  * 					verify that blit produces same result for same area on larger mask 
   259  * 					and change pattern
   260  * 					blit using duplicate handle and source
   261  * 					blit using original handle and source
   262  * 						in defect scenario these results are different (original same as reference)
   263  * 						in fix scenario they should be same (different to reference)
   264  * 					revalidate original handle reblit and verify now correct
   265  */	
   266 void  CTDefect2::TestDirtyMaskBitmapL()
   267 	{
   268 	const TInt 	KWidth=120;
   269 	const TInt	KHeight=50;
   270 	const TInt	KBigger=50;
   271 	enum
   272 		{
   273 		EStepBefore=0,
   274 		EStepVerifyDupGrow,
   275 		EStepDupDiffAfterRefill,
   276 		EStepOriginalDiffAfterRefill,
   277 		EStepOriginalDiffAfterRefillAndGetAddress,
   278 		EStepDupDiffAfterRefill2,
   279 		EStepOriginalDiffAfterRefill2,
   280 		ENumSteps
   281 		};
   282 	TInt pushcount=0;
   283 	//set up the target
   284 	CFbsBitmap* targetBmp=new(ELeave) CFbsBitmap();
   285 	CleanupStack::PushL(targetBmp);pushcount++;	
   286 	User::LeaveIfError(targetBmp->Create(TSize(KWidth,KHeight*ENumSteps), EColor16MU));	
   287 	CFbsBitmapDevice* bmpDevice=CFbsBitmapDevice::NewL(targetBmp);
   288 	CleanupStack::PushL(bmpDevice);pushcount++;	
   289 	CBitmapContext* bmpContext;
   290 	User::LeaveIfError(bmpDevice->CreateBitmapContext(bmpContext));
   291 	CleanupStack::PushL(bmpContext);pushcount++;		
   292 	bmpContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
   293 	bmpContext->SetBrushColor(KRgbRed);	
   294 	bmpContext->Clear();
   295 	
   296 	//set up source and mask
   297 	CFbsBitmap* sourceBmp=new(ELeave) CFbsBitmap();
   298 	CleanupStack::PushL(sourceBmp);pushcount++;		
   299 	User::LeaveIfError(sourceBmp->Create(TSize(KWidth,KHeight), EColor16MU));
   300 	TUint32* sourceData=sourceBmp->DataAddress();
   301 	TInt 	 sourceLength=(sourceBmp->DataStride()>>2)*KHeight;
   302 	CFbsBitmap* maskBmp=new(ELeave) CFbsBitmap();
   303 	CleanupStack::PushL(maskBmp);pushcount++;		
   304 	User::LeaveIfError(maskBmp->Create(TSize(KWidth,KHeight), EGray2));
   305 	TUint32* maskDataStart=maskBmp->DataAddress();
   306 	TInt 	 maskLength=(maskBmp->DataStride()>>2)*KHeight;
   307 
   308 	TUint32* targetData=targetBmp->DataAddress();
   309 	TInt targetCopySize=((targetBmp->DataStride()+3)>>2)*KHeight;
   310 
   311 	TUint32 blueint=KRgbBlue.Color16MU();
   312 	for (TInt fillIndex=0;fillIndex<sourceLength;fillIndex++)
   313 		{
   314 		sourceData[fillIndex]=blueint;
   315 		}
   316 	TInt maskPattern=0x12345678;
   317 	for (TInt fillIndex=0;fillIndex<maskLength;fillIndex++)
   318 		{
   319 		maskDataStart[fillIndex]=maskPattern;
   320 		}
   321 	
   322 	//Initial result of blit operation
   323 	bmpContext->BitBltMasked(TPoint(0,KHeight*EStepBefore),sourceBmp,TSize(KWidth,KHeight),maskBmp,EFalse);
   324 	
   325 	//duplicate the mask handle
   326 	CFbsBitmap* maskBmpDup=new(ELeave) CFbsBitmap();
   327 	CleanupStack::PushL(maskBmpDup);pushcount++;	
   328 	maskBmpDup->Duplicate(maskBmp->Handle());
   329 	TUint32* maskDataDup=maskBmpDup->DataAddress();
   330 	TEST(maskDataDup==maskDataStart);	//not expected to fail
   331 	//resize duplicate handle bigger
   332 	maskBmpDup->Resize(TSize(KWidth+KBigger,KHeight));
   333 	maskDataDup=maskBmpDup->DataAddress();
   334 	TEST(maskDataDup!=maskDataStart);	//not expected to fail
   335 	
   336 	//At this point the duplicate handle is referencing a different address to the original handle.
   337 	//With the defect in place this remains uncorrected, 
   338 	//and is demonstrated by comparing the output contents of blitting using each of the handles. 
   339 	
   340 	//verify that the resizing of the mask preserved the original mask data, so the resize has no effect on small area blit
   341 	bmpContext->BitBltMasked(TPoint(0,KHeight*EStepVerifyDupGrow),sourceBmp,TSize(KWidth,KHeight),maskBmpDup,EFalse);
   342 	
   343 	//If this cmp fails: blit or resize is not working properly on the duplicate handle - not caused by this defect (very unexpected)
   344 	TEST(0==Mem::Compare((TUint8*)(targetData),targetCopySize*4,(TUint8*)(targetData+targetCopySize*EStepVerifyDupGrow),targetCopySize*4));
   345 	
   346 	//Change the mask using the address in the duplicate handle
   347 	//As we want to fill the whole mask with a known pattern we need to recalculate the mask size.
   348 	TInt newMaskLength=(maskBmpDup->DataStride()>>2)*KHeight;
   349 	maskPattern=0xAAAAAAAA;
   350 	for (TInt fillIndex=0;fillIndex<newMaskLength;fillIndex++)
   351 		{	
   352 		maskDataDup[fillIndex]=maskPattern;
   353 		}
   354 	
   355 	//compare the results of blitting using this new mask using each of the two handles to the same mask
   356 	bmpContext->BitBltMasked(TPoint(0,KHeight*EStepDupDiffAfterRefill),sourceBmp,TSize(KWidth,KHeight),maskBmpDup,EFalse);
   357 	//This blit should not crash, even if the defect is present because the previous sized bitmap should not be released until all references have been updated.
   358 
   359 	bmpContext->BitBltMasked(TPoint(0,KHeight*EStepOriginalDiffAfterRefill),sourceBmp,TSize(KWidth,KHeight),maskBmp,EFalse);
   360 
   361 	//If this cmp fails: data change had no effect for duplicate handle (very unexpected)
   362 	TEST(0!=Mem::Compare((TUint8*)(targetData),targetCopySize*4,(TUint8*)(targetData+targetCopySize*EStepDupDiffAfterRefill),targetCopySize*4));
   363 	
   364 	//Check that the result of both blits is the same.
   365 	//If this cmp fails: defect is demonstrated. This is the main defect demonstration test.
   366 	TEST(0==Mem::Compare((TUint8*)(targetData+targetCopySize*EStepDupDiffAfterRefill),targetCopySize*4,(TUint8*)(targetData+targetCopySize*EStepOriginalDiffAfterRefill),targetCopySize*4));
   367 	
   368 	//This revalidates the original handle, hiding the defect
   369 	TUint32* maskDataRevalid=maskBmp->DataAddress();
   370 	TEST(maskDataDup==maskDataRevalid);
   371 	
   372 	//This blit should not crash as the original handle has now been revalidated to point to allocated data. 
   373 	bmpContext->BitBltMasked(TPoint(0,KHeight*EStepOriginalDiffAfterRefillAndGetAddress),sourceBmp,TSize(KWidth,KHeight),maskBmp,EFalse);
   374 	//If this cmp fails: original was not revalidated by DataAddress - content is not same as duplicate
   375 	TEST(0==Mem::Compare((TUint8*)(targetData+targetCopySize*EStepDupDiffAfterRefill),targetCopySize*4,(TUint8*)(targetData+targetCopySize*EStepOriginalDiffAfterRefillAndGetAddress),targetCopySize*4));
   376 
   377 	//Extra testing... do we handle situation where the duplicated handle is changed more than once?
   378 
   379 	//Basically repeats the test sequence above.
   380 	
   381 	//Repeat the resize even bigger using duplicate handle
   382 	//resize duplicate handle bigger
   383 	maskBmpDup->Resize(TSize(KWidth+KBigger,KHeight+KBigger));
   384 	maskDataDup=maskBmpDup->DataAddress();
   385 	TEST(maskDataDup!=maskDataRevalid);
   386 	
   387 	//Change the mask using the address in the duplicate handle
   388 	//As we want to fill the whole mask with a known pattern we need to recalculate the mask size.
   389 	newMaskLength=(maskBmpDup->DataStride()>>2)*(KHeight+KBigger);
   390 	maskPattern=0x55555555;
   391 	for (TInt fillIndex=0;fillIndex<newMaskLength;fillIndex++)
   392 		{	
   393 		maskDataDup[fillIndex]=maskPattern;
   394 		}
   395 	
   396 	//compare the results of blitting using this new mask using each of the two handles to the same mask
   397 	
   398 	bmpContext->BitBltMasked(TPoint(0,KHeight*EStepDupDiffAfterRefill2),sourceBmp,TSize(KWidth,KHeight),maskBmpDup,EFalse);
   399 	//This blit should not crash, even if the defect is present because the previous sized bitmap should not be released until all references have been updated.
   400 	//If it does crash then this demonstrates the defect in that the original address is being used in error and has been freed and paged out
   401 	bmpContext->BitBltMasked(TPoint(0,KHeight*EStepOriginalDiffAfterRefill2),sourceBmp,TSize(KWidth,KHeight),maskBmp,EFalse);
   402 
   403 	//If this cmp fails: data change  had no effect for duplicate handle (very unexpected)
   404 	TEST(0!=Mem::Compare((TUint8*)(targetData+targetCopySize*EStepDupDiffAfterRefill),targetCopySize*4,(TUint8*)(targetData+targetCopySize*EStepDupDiffAfterRefill2),targetCopySize*4));
   405 
   406 	//Check that the result of both blits is the same.
   407 	//If this cmp fails: defect is demonstrated. This is the main defect demonstration test.
   408 	TEST(0==Mem::Compare((TUint8*)(targetData+targetCopySize*EStepDupDiffAfterRefill2),targetCopySize*4,(TUint8*)(targetData+targetCopySize*EStepOriginalDiffAfterRefill2),targetCopySize*4));
   409 	
   410 	
   411 	CleanupStack::PopAndDestroy(pushcount,targetBmp);
   412 	}
   413 
   414  /**
   415   * @SYMTestCaseID GRAPHICS-BITGDI-0097
   416   *
   417   * @SYMDEF DEF115395
   418   *
   419   * @SYMTestCaseDesc Robustness in the CFbsBitGc::DrawBitmap & CFbsBitGc::DrawBitmapMasked functions:
   420   * when a sourceRect is used to capture only a part of the bitmap,
   421   * we have to make sure that the sourceRect is not out of border of the image!
   422   * (if it's the case, we just draw nothing)
   423   *
   424   * @SYMTestPriority Normal
   425   *
   426   * @SYMTestStatus Implemented
   427   *
   428   * @SYMTestActions We create a 8x8 KRgbRed Bitmap and 8x8 Mask (color TRgb(30, 30, 30))
   429   * We try the 2 functions CFbsBitGc::DrawBitmap and CFbsBitGc::DrawBitmapMasked
   430   * with a out of bounds source rectangle on a white output image.
   431   * The output should stay all white.                
   432   *
   433   */  
   434 void CTDefect2::DEF115395L()
   435 	{
   436 	const TSize size=TSize(8, 8);
   437 	const TPoint origin=TPoint(0, 0);
   438 	const TPoint vector=TPoint(2, 2);
   439 	const TRect destRect=TRect(origin, size);
   440 	const TRect srcRect=TRect(origin-vector, size);
   441 	const TBool invertMask=EFalse;
   442 	const TRgb maskColor=TRgb(30, 30, 30);
   443 	TBool succeed=ETrue;
   444 
   445 	// Bitmap creation
   446 	CFbsBitmap* myBmp=new(ELeave) CFbsBitmap();
   447 	CleanupStack::PushL(myBmp);
   448 	User::LeaveIfError(myBmp->Create(size, EColor16MU));
   449 	CFbsBitmapDevice* bmpDevice=CFbsBitmapDevice::NewL(myBmp);
   450 	CleanupStack::PushL(bmpDevice);
   451 	CBitmapContext* bmpContext;
   452 	User::LeaveIfError(bmpDevice->CreateBitmapContext(bmpContext));
   453 	CleanupStack::PushL(bmpContext);
   454 	bmpContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
   455 	bmpContext->SetBrushColor(KRgbRed);
   456 	bmpContext->Clear();
   457 	CleanupStack::PopAndDestroy(2, bmpDevice); // bmpContext, bmpDevice
   458 
   459 	// Mask creation
   460 	CFbsBitmap* myMaskBmp=new(ELeave) CFbsBitmap();
   461 	CleanupStack::PushL(myMaskBmp);
   462 	User::LeaveIfError(myMaskBmp->Create(size, EGray256));
   463 	bmpDevice = CFbsBitmapDevice::NewL(myMaskBmp);
   464 	CleanupStack::PushL(bmpDevice);     
   465 	User::LeaveIfError(bmpDevice->CreateBitmapContext(bmpContext));
   466 	CleanupStack::PushL(bmpContext);
   467 	bmpContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
   468 	bmpContext->SetBrushColor(maskColor);
   469 	bmpContext->Clear();
   470 	CleanupStack::PopAndDestroy(2, bmpDevice); // bmpContext, bmpDevice
   471 
   472 	// Output Image
   473 	CFbsBitmap* outputImg=new(ELeave) CFbsBitmap();
   474 	CleanupStack::PushL(outputImg);
   475 	User::LeaveIfError(outputImg->Create(size, EColor16MU));
   476 	bmpDevice = CFbsBitmapDevice::NewL(outputImg);
   477 	CleanupStack::PushL(bmpDevice);
   478 	User::LeaveIfError(bmpDevice->CreateBitmapContext(bmpContext));
   479 	CleanupStack::PushL(bmpContext);
   480 	bmpContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
   481 	bmpContext->SetBrushColor(KRgbWhite);
   482 	bmpContext->Clear();
   483 
   484 	bmpContext->DrawBitmapMasked(destRect, myBmp, srcRect, myMaskBmp, invertMask);   
   485 	TRgb pixelColor;
   486 	TInt ii,jj;
   487 	for (ii=0;ii<=size.iWidth;ii++)
   488 		{
   489 		for (jj=0;jj<=size.iHeight;jj++)
   490 			{
   491 			outputImg->GetPixel(pixelColor, TPoint(ii,jj));
   492 			if (pixelColor!=KRgbWhite)
   493 				{
   494 				succeed=EFalse;
   495 				break;
   496 				}
   497 			}
   498 		if (!succeed)
   499 			{
   500 			break;
   501 			}
   502 		}
   503 
   504 	bmpContext->Clear();
   505 	bmpContext->DrawBitmap(destRect, myBmp, srcRect);
   506 	for (ii=0;ii<=size.iWidth;ii++)
   507 		{
   508 		for (jj=0;jj<=size.iHeight;jj++)
   509 			{
   510 			outputImg->GetPixel(pixelColor, TPoint(ii,jj));
   511 			if (pixelColor!=KRgbWhite)
   512 				{
   513 				succeed=EFalse;
   514 				break;
   515 				}
   516 			}
   517 		if (!succeed)
   518 			{
   519 			break;
   520 			}
   521 		}
   522 
   523 	TEST(succeed);
   524 	CleanupStack::PopAndDestroy(5);
   525 }
   526 
   527 /**  
   528    @SYMDEF PDEF141192, INC140310         
   529 
   530    @SYMTestCaseDesc Test that the alpha merge method CFbsBitGc::DrawBitmapMasked() works accurately.
   531                     
   532    @SYMTestPriority normal
   533 
   534    @SYMTestStatus Implemented
   535 
   536    @SYMTestActions Create an alpha capable bitmap and throw sample values at the merge function
   537  
   538    @SYMTestExpectedResults
   539    1a)     The merge resultant alpha values do not wrap through 256
   540    1b)     The merge resultant alpha values closely match an equivalent floating-point calculation
   541    2a)     The merge resultant colours do not wrap through 256
   542    2b)     The merge resultant colours do not exceed the resultant alpha if premultiplied output is expected
   543    2c)     The merge resultant colours closely match an equivalent floating-point calculation
   544    2d)     The other resultant colour values are not affected (stay black) 
   545    
   546    @param  aChannelControl which channel is controlled  (0=red, 1= green, 2=blue)
   547    
   548    The input tested format is EColor64K, but could easily be changesd to test other formats.
   549    The input mask is EGray256. If optimised internally, this could be changed to EGray16.
   550    The tested output format is EColor16MAP. This should not be changed. 
   551    
   552    This test is an optimised version of CTDefect2::TestMaskForAllCombinationL(TInt aChannelControl)
   553 */
   554 void CTDefect2::TestMaskForSelectedValuesL(TInt aChannelControl)
   555      {
   556      const TSize size=TSize(1, 1);
   557  
   558      // Bitmap creation
   559      CFbsBitmap* srcBmp=new(ELeave) CFbsBitmap();
   560      CleanupStack::PushL(srcBmp); 
   561      User::LeaveIfError(srcBmp->Create(size, EColor64K)); 
   562      CFbsBitmapDevice* sourceBmpDevice=CFbsBitmapDevice::NewL(srcBmp);
   563      CleanupStack::PushL(sourceBmpDevice);
   564      CBitmapContext* sourceBmpContext;
   565      User::LeaveIfError(sourceBmpDevice->CreateBitmapContext(sourceBmpContext));
   566      CleanupStack::PushL(sourceBmpContext);    
   567      sourceBmpContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
   568      sourceBmpContext->Clear();
   569      CleanupStack::PopAndDestroy(2, sourceBmpDevice); // sourceBmpContext, sourceBmpDevice
   570      
   571      // Mask creation
   572      CFbsBitmap* maskBmp=new(ELeave) CFbsBitmap();
   573      CleanupStack::PushL(maskBmp); 
   574      User::LeaveIfError(maskBmp->Create(size, EGray256)); 
   575      CFbsBitmapDevice* maskBmpDevice=CFbsBitmapDevice::NewL(maskBmp);
   576      CleanupStack::PushL(maskBmpDevice);
   577      CBitmapContext* maskBmpContext;
   578      User::LeaveIfError(maskBmpDevice->CreateBitmapContext(maskBmpContext));
   579      CleanupStack::PushL(maskBmpContext);    
   580      maskBmpContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
   581      maskBmpContext->Clear();
   582      CleanupStack::PopAndDestroy(2, maskBmpDevice); // maskBmpContext, maskBmpDevice
   583           
   584      // Target Bitmap
   585      CFbsBitmap* targetBmp=new(ELeave) CFbsBitmap();
   586      CleanupStack::PushL(targetBmp); 
   587      User::LeaveIfError(targetBmp->Create(size, EColor16MAP)); 
   588      CFbsBitmapDevice* targetBmpDevice=CFbsBitmapDevice::NewL(targetBmp);
   589      CleanupStack::PushL(targetBmpDevice);
   590      CBitmapContext* targetBmpContext;
   591      User::LeaveIfError(targetBmpDevice->CreateBitmapContext(targetBmpContext));
   592      CleanupStack::PushL(targetBmpContext);    
   593      targetBmpContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
   594      targetBmpContext->Clear();
   595      
   596      TSize screenSize = targetBmpDevice->SizeInPixels();
   597      
   598       TInt channelMask; 
   599       TInt channelMul;
   600 
   601       if (aChannelControl<1)
   602           {
   603           channelMask=0xFF0000;   
   604           }
   605       else
   606           {
   607           if(aChannelControl==1)
   608               {
   609               channelMask=0x00FF00;   
   610               }
   611           else
   612               {
   613               channelMask=0x0000FF;   
   614               }
   615           }
   616       channelMul=channelMask&0x01010101;
   617       TInt previousTargetMask = -1;
   618       const TInt otherMask=0xFFFFFF^channelMask;
   619          
   620       for (TInt targetMask=0;targetMask<256;targetMask++)
   621          {
   622          //bkgrdChannel is background channel input value. 
   623          for (TInt targetChannel=0;targetChannel<=targetMask;targetChannel++) 
   624              {
   625              if(targetChannel>(targetMask-10)) // Optimise the loop to test values specific for this defect
   626                  {
   627                  TInt failsPerPass=10;
   628 
   629                  //srcMask is the source mask/alpha
   630                  for (TInt srcMask=0;srcMask<256;srcMask++)
   631                      {  
   632                      if((srcMask<=10)||(srcMask>=250)) // Optimise the loop to test values specific for this defect
   633                          {
   634                          TReal step;
   635                          if (aChannelControl == 1)
   636                              {
   637                              step = 255.0/63;  // Only for blue channel for EColor64K source colour
   638                              }
   639                          else
   640                              {
   641                              step = 255.0/31;                     
   642                              }
   643                          TReal srcChannelReal = 0.0;
   644                          for (TInt srcChannel=0;srcChannel<256;srcChannel=(TInt)srcChannelReal)
   645                              {
   646                              if (targetMask != previousTargetMask)
   647                                  {
   648                                  //uncomment it to print log for each targetMask loop
   649                                  //INFO_PRINTF2(_L("Processing source colours for targetMask=%i"),targetMask);
   650                                  previousTargetMask = targetMask;
   651                                  }
   652                              srcChannelReal += step;
   653                             
   654                              //test blending of one-pixel bitmap
   655                              DoMaskTestL(srcChannel, srcMask, targetMask, targetChannel, aChannelControl, srcBmp, maskBmp, targetBmp, targetBmpContext);
   656 
   657                              TBuf8<4> readBuffer;
   658                              TUint* readPixel = (TUint*)readBuffer.Ptr();
   659                              targetBmp->GetScanLine(readBuffer, TPoint(0, 0), 1, EColor16MAP); 
   660                              
   661                              //channelPixelValue is the channel pixel value as generated from the library code under test
   662                              TUint channelPixelValue=((*readPixel)&channelMask)/channelMul;
   663                              //alphaPixelValue is the alpha pixel value as generated from the library code under test
   664                              TUint alphaPixelValue = (*readPixel)>>24; 
   665                              
   666                              //check if channelPixelValue and alphaPixelValue match the expected ones
   667                              CheckValues(alphaPixelValue, channelPixelValue, failsPerPass, targetMask, targetChannel, srcMask, srcChannel, otherMask, readPixel);
   668                              } 
   669                          }
   670                      }
   671                      if (failsPerPass<0) 
   672                          {       //note that this count may be out by 1... 
   673                          INFO_PRINTF2(_L("Additional %i errors not reported in this pass."),-failsPerPass); 
   674                          }                                    
   675                  }
   676              }
   677          }         
   678      CleanupStack::PopAndDestroy(5);      
   679      }
   680 
   681 void CTDefect2::CheckValues(TUint aAlphaPixelValue, TUint aChannelPixelValue, TInt& aFailsPerPass, TInt aTargetMask, TInt aTargetChannel, TInt aSrcMask, TInt aSrcChannel, TInt aOtherMask, TUint* aReadPixel)
   682    {
   683    const TReal KGross=1.95;
   684    TReal srcMultiplier;
   685    TReal alphaOutputValue;
   686    //source multiplier factor for alpha that can then be used to optimise non-multiplied input calculations.
   687    srcMultiplier=aSrcMask/255.0;
   688    //destination/background multiplier factor for alpha that can then be used to optimise non-multiplied input calculations.
   689    TReal destMultiplier=(aTargetMask/255.0)*(1.0-srcMultiplier);
   690    //alphaOutputValue is a floating-point calculation of the alpha output value using 255.0 as the scaling factor.
   691    alphaOutputValue=(srcMultiplier+destMultiplier)*255.0;
   692 
   693    //alphaDiff is the difference in alpha between pixel and float calcuation, i.e. the error. This can be less than 1 level of brightness, i.e. insignificant.
   694    TReal alphaDiff=0.0;                             
   695    alphaDiff=alphaOutputValue-aAlphaPixelValue;
   696    if (alphaDiff>KGross || alphaDiff<-KGross)
   697        {
   698        if (--aFailsPerPass>0)
   699            {
   700            LogColourEvent(aTargetMask,aTargetChannel,aSrcMask,-1,alphaOutputValue,aAlphaPixelValue,alphaDiff,_L("Big Alpha error: expected %f, got %f"),ETrue);                                     
   701            }                             
   702        }      
   703    //channelOutputValue is a floating-point calculation of the channel output value using 255.0 as the scaling factor.
   704    TReal channelOutputValue=aSrcChannel*srcMultiplier; 
   705    channelOutputValue+=aTargetChannel*(1.0-srcMultiplier);  
   706    
   707    if (aChannelPixelValue>aAlphaPixelValue)
   708        {
   709        if (--aFailsPerPass>0)  
   710            {
   711            LogColourEvent(aTargetMask,aTargetChannel,aSrcMask,aSrcChannel,aAlphaPixelValue,channelOutputValue,aChannelPixelValue,_L("Output multiplied colour exceeds alpha %f: expected %f got %f"),EFalse);                             
   712            INFO_PRINTF1(_L("channelPixelValue>alphaPixelValue"));                                 
   713            }               
   714        }  
   715 
   716    if((aOtherMask&(*aReadPixel))!=0)
   717        {
   718        if (--aFailsPerPass>0)  
   719            {
   720            LogColourEvent(aTargetMask,aTargetChannel,aSrcMask,aSrcChannel,aAlphaPixelValue,channelOutputValue,aChannelPixelValue,_L("Other colours damaged - NOT Zero"),EFalse);                             
   721            }               
   722        }  
   723        
   724    //channelDiff is the difference in channel between pixel and float calcuation, i.e. the error. This can be less than 1 level of brightness, i.e. insignificant.
   725     TReal channelDiff=channelOutputValue-aChannelPixelValue;
   726 
   727     if (channelDiff>KGross || channelDiff<-KGross)
   728         {
   729         if (--aFailsPerPass>0)
   730             {
   731             LogColourEvent(aTargetMask,aTargetChannel,aSrcMask,aSrcChannel,channelOutputValue,aChannelPixelValue,channelDiff,_L("Big Colour error: expected %f, got %f"),EFalse);      
   732             }                          
   733         }                                   
   734    }
   735 
   736 /**
   737 Test of Blending function DrawBitmapMasked(). 
   738 @param aSrcChannel source channel 
   739 @param aSrcMask source mask
   740 @param aTargetMask target mask
   741 @param aTargetChannel target channel
   742 @param aChannelControl which channel is controlled  (0=red, 1= green, 2=blue)
   743 @param aSrcBmp source bitmap
   744 @param aMaskBmp mask bitmap
   745 @param aTargetBmp target bitmap
   746 @param aTargetBmpContext gc for target bitmap 
   747 **/ 
   748 void CTDefect2::DoMaskTestL(TInt aSrcChannel, TInt aSrcMask, TInt aTargetMask, TInt aTargetChannel, TInt aChannelControl, 
   749        CFbsBitmap* aSrcBmp, CFbsBitmap* aMaskBmp, CFbsBitmap* aTargetBmp, CBitmapContext* aTargetBmpContext)
   750    {
   751    const TSize size=TSize(1, 1);
   752    const TRect destRect=TRect(size);  
   753    const TRect srcRect=TRect(size);
   754 
   755    const TInt scanLineLengthEColor16MAP = CFbsBitmap::ScanLineLength(1, EColor16MAP);
   756    HBufC8* targetBuffer = HBufC8::NewL(scanLineLengthEColor16MAP);
   757    CleanupStack::PushL(targetBuffer);
   758    TPtr8 targetDes = targetBuffer->Des();
   759    targetDes.SetLength(scanLineLengthEColor16MAP);
   760    TUint32* targetP = (TUint32*)targetDes.Ptr();
   761    TRgb targetColour(0, 0);
   762    if (aChannelControl<1)
   763        {
   764        targetColour.SetRed(aTargetChannel);                  
   765        }
   766    else
   767        {
   768        if (aChannelControl==1)
   769            {
   770            targetColour.SetGreen(aTargetChannel);                                        
   771            }
   772        else
   773            {
   774            targetColour.SetBlue(aTargetChannel);                                        
   775            }
   776        }
   777    targetColour.SetAlpha(aTargetMask);
   778    *targetP = targetColour.Internal();
   779    aTargetBmp->SetScanLine(targetDes, 0);
   780    
   781    const TInt scanLineLengthEGray256 = CFbsBitmap::ScanLineLength(1, EGray256);
   782    HBufC8* maskBuffer = HBufC8::NewL(scanLineLengthEGray256);
   783    CleanupStack::PushL(maskBuffer);
   784    TPtr8 maskDes = maskBuffer->Des();
   785    maskDes.SetLength(scanLineLengthEGray256);
   786    TUint8* maskP = (TUint8*)maskDes.Ptr();
   787    *maskP = aSrcMask;
   788    aMaskBmp->SetScanLine(maskDes, 0);
   789 
   790    const TInt scanLineLengthEColor64K = CFbsBitmap::ScanLineLength(1, EColor64K);
   791    HBufC8* srcBuffer = HBufC8::NewL(scanLineLengthEColor64K);
   792    CleanupStack::PushL(srcBuffer);
   793    TPtr8 srcDes = srcBuffer->Des();
   794    srcDes.SetLength(scanLineLengthEColor64K);
   795    TUint16* srcP = (TUint16*)srcDes.Ptr();
   796    TRgb srcColour(0);
   797    if (aChannelControl<1)
   798        {
   799        srcColour.SetRed(aSrcChannel);
   800        }
   801    else
   802        {
   803        if (aChannelControl==1)
   804            {
   805            srcColour.SetGreen(aSrcChannel);
   806            }
   807        else
   808            {
   809            srcColour.SetBlue(aSrcChannel);
   810            }
   811        }
   812    
   813    *srcP = srcColour.Color64K();
   814    aSrcBmp->SetScanLine(srcDes, 0);
   815    aTargetBmpContext->DrawBitmapMasked(destRect, aSrcBmp, srcRect, aMaskBmp, EFalse);
   816    
   817    CleanupStack::PopAndDestroy(3);                                        
   818    }
   819 
   820 /**  
   821   @SYMDEF PDEF141192, INC140310         
   822 
   823   @SYMTestCaseDesc Test that the alpha merge method CFbsBitGc::DrawBitmapMasked() works accurately.
   824                    
   825   @SYMTestPriority normal
   826 
   827   @SYMTestStatus Implemented
   828 
   829   @SYMTestActions Create an alpha capable bitmap and throw sample values at the merge function
   830 
   831   @SYMTestExpectedResults
   832   1a)     The merge resultant alpha values do not wrap through 256
   833   1b)     The merge resultant alpha values closely match an equivalent floating-point calculation
   834   2a)     The merge resultant colours do not wrap through 256
   835   2b)     The merge resultant colours do not exceed the resultant alpha if premultiplied output is expected
   836   2c)     The merge resultant colours closely match an equivalent floating-point calculation
   837   2d)     The other resultant colour values are not affected (stay black) 
   838   @param  aChannelControl which channel is controlled  (0=red, 1= green, 2=blue)
   839   
   840    The input tested format is EColor64K, but could easily be changesd to test other formats.
   841    The input mask is EGray256. If optimised internally, this could be changed to EGray16.
   842    The tested output format is EColor16MAP. This should not be changed. 
   843 
   844    This test takes up to 40 minutes to run per channel control. Therefore, it is only kept for local reference, not scheduled for ONB. 
   845    An optimised version CTDefect2::TestMaskForSelectedValuesL(TInt aChannelControl) is run instead for selected combinations of channel and mask values. 
   846 */
   847 void CTDefect2::TestMaskForAllCombinationL(TInt aChannelControl)
   848    {
   849    const TSize size=TSize(1, 1);
   850 
   851    // Bitmap creation
   852    CFbsBitmap* srcBmp=new(ELeave) CFbsBitmap();
   853    CleanupStack::PushL(srcBmp); 
   854    User::LeaveIfError(srcBmp->Create(size, EColor64K)); 
   855    CFbsBitmapDevice* sourceBmpDevice=CFbsBitmapDevice::NewL(srcBmp);
   856    CleanupStack::PushL(sourceBmpDevice);
   857    CBitmapContext* sourceBmpContext;
   858    User::LeaveIfError(sourceBmpDevice->CreateBitmapContext(sourceBmpContext));
   859    CleanupStack::PushL(sourceBmpContext);    
   860    sourceBmpContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
   861    sourceBmpContext->Clear();
   862    CleanupStack::PopAndDestroy(2, sourceBmpDevice); // sourceBmpContext, sourceBmpDevice
   863    
   864    // Mask creation
   865    CFbsBitmap* maskBmp=new(ELeave) CFbsBitmap();
   866    CleanupStack::PushL(maskBmp); 
   867    User::LeaveIfError(maskBmp->Create(size, EGray256)); 
   868    CFbsBitmapDevice* maskBmpDevice=CFbsBitmapDevice::NewL(maskBmp);
   869    CleanupStack::PushL(maskBmpDevice);
   870    CBitmapContext* maskBmpContext;
   871    User::LeaveIfError(maskBmpDevice->CreateBitmapContext(maskBmpContext));
   872    CleanupStack::PushL(maskBmpContext);    
   873    maskBmpContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
   874    maskBmpContext->Clear();
   875    CleanupStack::PopAndDestroy(2, maskBmpDevice); // maskBmpContext, maskBmpDevice
   876         
   877    // Target Bitmap
   878    CFbsBitmap* targetBmp=new(ELeave) CFbsBitmap();
   879    CleanupStack::PushL(targetBmp); 
   880    User::LeaveIfError(targetBmp->Create(size, EColor16MAP)); 
   881    CFbsBitmapDevice* targetBmpDevice=CFbsBitmapDevice::NewL(targetBmp);
   882    CleanupStack::PushL(targetBmpDevice);
   883    CBitmapContext* targetBmpContext;
   884    User::LeaveIfError(targetBmpDevice->CreateBitmapContext(targetBmpContext));
   885    CleanupStack::PushL(targetBmpContext);    
   886    targetBmpContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
   887    targetBmpContext->Clear();
   888    
   889    TSize screenSize = targetBmpDevice->SizeInPixels();
   890    
   891     TInt channelMask; 
   892     TInt channelMul;
   893 
   894     if (aChannelControl<1)
   895         {
   896         channelMask=0xFF0000;   
   897         }
   898     else
   899         {
   900         if(aChannelControl==1)
   901             {
   902             channelMask=0x00FF00;   
   903             }
   904         else
   905             {
   906             channelMask=0x0000FF;   
   907             }
   908         }
   909     channelMul=channelMask&0x01010101;
   910     TInt previousTargetMask = -1;
   911     const TInt otherMask=0xFFFFFF^channelMask;
   912        
   913     for (TInt targetMask=0;targetMask<256;targetMask++)
   914        {
   915        //bkgrdChannel is background channel input value. 
   916        for (TInt targetChannel=0;targetChannel<=targetMask;targetChannel++) 
   917            {
   918            TInt failsPerPass=10;
   919 
   920             //srcMask is the source mask/alpha
   921            for (TInt srcMask=0;srcMask<256;srcMask++)
   922                {  
   923                TReal step;
   924                if (aChannelControl == 1)
   925                    {
   926                    step = 255.0/63; // Only for blue channel for EColor64K source colour
   927                    }
   928                else
   929                    {
   930                    step = 255.0/31;                     
   931                    }
   932                TReal srcChannelReal = 0.0;
   933 
   934                for (TInt srcChannel=0;srcChannel<256;srcChannel=(TInt)srcChannelReal)
   935                    {
   936                    if (targetMask != previousTargetMask)
   937                        {
   938                        INFO_PRINTF2(_L("Processing source colours for targetMask=%i"),targetMask);
   939                        previousTargetMask = targetMask;
   940                        }
   941                    srcChannelReal += step;
   942                    
   943                    //test blending of one-pixel bitmap
   944                    DoMaskTestL(srcChannel, srcMask, targetMask, targetChannel, aChannelControl, srcBmp, maskBmp, targetBmp, targetBmpContext);
   945                    
   946                    TBuf8<4> readBuffer;
   947                    TUint* readPixel = (TUint*)readBuffer.Ptr();
   948                    targetBmp->GetScanLine(readBuffer, TPoint(0, 0), 1, EColor16MAP);                
   949 
   950                    //channelPixelValue is the channel pixel value as generated from the library code under test
   951                    TUint channelPixelValue=((*readPixel)&channelMask)/channelMul;
   952                    //alphaPixelValue is the alpha pixel value as generated from the library code under test
   953                    TUint alphaPixelValue = (*readPixel)>>24; 
   954                    
   955                    //check if channelPixelValue and alphaPixelValue match the expected ones
   956                    CheckValues(alphaPixelValue, channelPixelValue, failsPerPass, targetMask, targetChannel, srcMask, srcChannel, otherMask, readPixel);
   957                     
   958                if (failsPerPass<0) 
   959                    {       //note that this count may be out by 1... 
   960                    INFO_PRINTF2(_L("Additional %i errors not reported in this pass."),-failsPerPass); 
   961                    }                  
   962                } 
   963            } 
   964            }
   965        }         
   966    CleanupStack::PopAndDestroy(5);      
   967    }
   968 
   969 /**
   970 This function is used to write to the log file
   971 @param  aNonPreMulDestPixColor non pre multiplied destination pixel colour
   972 @param  aPreMulSrcPixelColor pre multiplied source pixel colour
   973 @param  aNonPreMulSrcPixelColor non pre multiplied source pixel colour
   974 @param  aVal1 it contains the value of the first variable of the message to be displayed
   975 @param  aVal2 it contains the value of the second variable of the message to be displayed
   976 @param  aVal3 it contains the value of the third variable of the message to be displayed
   977 @param  aMsg it contains the message to be printed to the log file
   978 @param  aErr if true then the test case fails, if false test passes. log is printed in both the case. TEST does not abort, just reports test case failure
   979 */
   980 void CTDefect2::LogColourEvent(TInt aPreMulDestPixColor,TInt aNonPreMulDestPixColor,TInt aPreMulSrcPixelColor,TInt aNonPreMulSrcPixelColor,TReal aVal1,TReal aVal2,TReal aVal3,TRefByValue<const TDesC> aMsg,TBool aErr)
   981    {
   982    TEST(aErr==EFalse); // if aErr=True, then the previous test step failed.
   983    INFO_PRINTF4(aMsg,aVal1,aVal2,aVal3);
   984    if (aNonPreMulSrcPixelColor<0)
   985        {
   986        INFO_PRINTF4(_L("Processing source colours for MDest=%i, CDest=%i, MSrc=%i"),aPreMulDestPixColor,aNonPreMulDestPixColor,aPreMulSrcPixelColor);
   987        }
   988    else
   989        {
   990        INFO_PRINTF5(_L("Processing colour set MDest=%i, CDest=%i, MSrc=%i, CSrc=%i"),aPreMulDestPixColor,aNonPreMulDestPixColor,aPreMulSrcPixelColor,aNonPreMulSrcPixelColor);
   991        }
   992    }
   993 
   994 class TFunctionThread
   995 	{
   996 protected:
   997 	TFunctionThread():iExitHow(ENotStarted)	
   998 		{}
   999 	TInt LaunchThreadFunction(const TDesC& aName);
  1000 private:
  1001 	static TInt TheThreadFunction(TAny*);
  1002 	virtual TInt	ThreadFunctionL()=0;
  1003 public:
  1004 	enum {
  1005 		ENotStarted,
  1006 		ERunning,	//should never see this
  1007 		EReturn,
  1008 		ELeave,
  1009 		EPanic,
  1010 		ETerminate,
  1011 		};
  1012 	TInt	iExitHow;
  1013 	TInt	iExitCode;	//Currently don't store the panic category string.
  1014 	};
  1015 
  1016 TInt TFunctionThread::LaunchThreadFunction(const TDesC& aName)
  1017 	{
  1018 	RThread thrd;
  1019 	TRequestStatus stat;
  1020 	enum { //8kb to 2mb
  1021 		KMinHeapSize=0x2000,
  1022 		KMaxHeapSize=0x200000
  1023 		};
  1024 	TInt created=thrd.Create(aName,TheThreadFunction,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,this);
  1025 	if (created<KErrNone)
  1026 		{
  1027 		iExitCode=created;
  1028 		return created;
  1029 		}
  1030 	thrd.SetPriority(EPriorityMuchMore);
  1031 	thrd.Logon(stat);
  1032 	User::SetJustInTime(EFalse);
  1033 	thrd.Resume();
  1034 	User::WaitForRequest(stat);
  1035 	if ( iExitHow!=ENotStarted || iExitHow==ERunning )
  1036 		{
  1037 		iExitCode=thrd.ExitReason();
  1038 		switch (thrd.ExitType())
  1039 			{
  1040 			case EExitKill:			iExitHow=EReturn;		break;
  1041 			case EExitPanic:		iExitHow=EPanic;		break;
  1042 			case EExitTerminate:	iExitHow=ETerminate;	break;
  1043 			default:
  1044 				ASSERT(EFalse);
  1045 			}
  1046 		}
  1047 	thrd.Close();
  1048 	User::SetJustInTime(ETrue);
  1049 	return KErrNone;
  1050 	}
  1051 
  1052 TInt TFunctionThread::TheThreadFunction(TAny* aThis)
  1053 	{
  1054 	TFunctionThread* thisThis=(TFunctionThread*)aThis;
  1055 	if (thisThis==NULL)
  1056 		{
  1057 		User::Panic(_L("NoThis"),0x1);
  1058 		}
  1059 	TInt leaveErr = RFbsSession::Connect();
  1060 	if (leaveErr != KErrNone)
  1061 		{
  1062 		thisThis->iExitHow = ELeave;
  1063 		thisThis->iExitCode = leaveErr;
  1064 		return leaveErr;
  1065 		}
  1066 	thisThis->iExitHow=thisThis->ERunning;
  1067 	CTrapCleanup* cleanup = CTrapCleanup::New();
  1068 	TInt returnErr=KErrNone;
  1069 	TRAP(leaveErr, returnErr = thisThis->ThreadFunctionL());
  1070 	if (leaveErr)
  1071 		{
  1072 		thisThis->iExitHow=ELeave;
  1073 		thisThis->iExitCode=leaveErr;
  1074 		delete cleanup;
  1075 		RFbsSession::Disconnect();
  1076 		return leaveErr;
  1077 		}
  1078 	else
  1079 		{
  1080 		thisThis->iExitHow=EReturn;
  1081 		thisThis->iExitCode=returnErr;
  1082 		delete cleanup;
  1083 		RFbsSession::Disconnect();
  1084 		return returnErr;
  1085 		}
  1086 	}
  1087 
  1088 /** This thread verifies whether a range of memory is accessible 
  1089   The range is read sequentially until it panics, or the range is completed.
  1090   It is useful to input a range of addresses where some are valid and some fail 
  1091   in order to demonstrate an edge against which an algorithm that performs illegal reads can subsequently be tested.
  1092   The FailOffset() returned index indicates the offset from the start at which the memory access caused a panic. 
  1093  **/
  1094 class TTestMemThread:public TFunctionThread
  1095 	{
  1096 public:
  1097 	TTestMemThread(TUint32* aStartAddress,TUint32* aEndAddress);
  1098 	TInt FailOffset();
  1099 private:
  1100 	virtual TInt	ThreadFunctionL();
  1101 private:
  1102 	TUint32* iStartAddress;
  1103 	TUint32* iEndAddress;
  1104 	volatile TUint32* iLastAddressTried;
  1105 	volatile TUint32  iCopyValueHere;
  1106 	
  1107 	};
  1108 
  1109 TTestMemThread::TTestMemThread(TUint32* aStartAddress,TUint32* aEndAddress):
  1110 	iStartAddress(aStartAddress),
  1111 	iEndAddress(aEndAddress),
  1112 	iLastAddressTried(NULL)
  1113 	{
  1114 	ASSERT(aStartAddress);
  1115 	ASSERT(aEndAddress);
  1116 	LaunchThreadFunction(_L("MemTest"));
  1117 	}
  1118 
  1119 /**
  1120  *	Returns the number of successful memory reads before a panic occurred
  1121  * 	Or various error codes if the test didn't run or didn't panic.
  1122  * 
  1123  **/
  1124 TInt TTestMemThread::FailOffset()
  1125 	{
  1126 	if (iExitHow==EReturn)
  1127 		{
  1128 		return KErrCompletion;
  1129 		}
  1130 	else
  1131 		{
  1132 		if (iExitHow==EPanic)
  1133 			{
  1134 			if (iLastAddressTried)
  1135 				{
  1136 				TInt retval=iLastAddressTried-iStartAddress;
  1137 				if (iEndAddress-iStartAddress<0)
  1138 					{
  1139 					retval=-retval;
  1140 					}
  1141 				if (retval<0)
  1142 					{
  1143 					return KErrCorrupt;
  1144 					}
  1145 				else
  1146 					{
  1147 					return retval;
  1148 					}
  1149 				}
  1150 			else
  1151 				{
  1152 				return KErrNotFound;
  1153 				}
  1154 			}
  1155 		else
  1156 			{
  1157 			return -iExitHow*100; 
  1158 			}
  1159 		}
  1160 	}
  1161 /*
  1162  * This thread function allows a test to verify that a particular address range 
  1163  * is actually inaccessable.
  1164  * I.e. that attempting to read from the given address range causes a panic.
  1165  */
  1166 TInt TTestMemThread::ThreadFunctionL()
  1167 	{
  1168 	if (iStartAddress && iEndAddress)
  1169 		{
  1170 		TInt delta=1;
  1171 		if (iStartAddress>iEndAddress)
  1172 			{
  1173 			delta=-1;
  1174 			}
  1175 		for (TUint32 volatile* tryAddress=iStartAddress;tryAddress!=iEndAddress;tryAddress+=delta)
  1176 			{
  1177 			iLastAddressTried=tryAddress;
  1178 			iCopyValueHere=*tryAddress;
  1179 			}
  1180 		return 0;
  1181 		}
  1182 	return KErrArgument;
  1183 	}
  1184 
  1185 /** This thread verifies the function of CopyRect
  1186   A series of operations are performed on the given bitmap.
  1187   If the operation panics the launcher is able to retrieve the parameters that caused the panic and report
  1188   The FailOffset() returned index indicates the offset from the start at which the memory access caused a panic. 
  1189  **/
  1190 class TTestCopyRectThread:public TFunctionThread
  1191 	{
  1192 public:
  1193 	TTestCopyRectThread(CFbsBitGc* aBitmapContext,TInt aStartX,TInt aStopX,TInt aY1,TInt aY2,TPoint aOffset);
  1194 private:
  1195 	virtual TInt	ThreadFunctionL();
  1196 private:
  1197 	CFbsBitGc* iBitmapContext;
  1198 	TInt iStartX;
  1199 	TInt iStopX;
  1200 	TInt iY1;
  1201 	TInt iY2;
  1202 	TPoint iOffset;
  1203 public:
  1204 	volatile TInt iCurrX;
  1205 	volatile TInt iCurrWidth;
  1206 	
  1207 	};
  1208 
  1209 TTestCopyRectThread::TTestCopyRectThread(CFbsBitGc* aBitmapContext,TInt aStartX,TInt aStopX,TInt aY1,TInt aY2,TPoint aOffset):
  1210 	iBitmapContext(aBitmapContext),
  1211 	iStartX(aStartX),
  1212 	iStopX(aStopX),
  1213 	iY1(aY1),
  1214 	iY2(aY2),
  1215 	iOffset(aOffset)
  1216 	{
  1217 	LaunchThreadFunction(_L("CopyRectTest"));
  1218 	}
  1219 TInt	TTestCopyRectThread::ThreadFunctionL()
  1220 	{
  1221 	for (iCurrX=iStartX;iCurrX<iStopX;iCurrX++)
  1222 		{
  1223 		for (iCurrWidth=iStopX-iCurrX;iCurrWidth>0;iCurrWidth--)
  1224 			{
  1225 			iBitmapContext->CopyRect(iOffset,TRect(iCurrX,iY1,iCurrX+iCurrWidth,iY2));
  1226 		    }
  1227 		}
  1228 	return KErrNone;
  1229 }
  1230 
  1231 class CTestExecuteLogger;
  1232 
  1233 struct WrapCTestExecuteLogger
  1234 	{
  1235 	WrapCTestExecuteLogger():	iLogger(NULL)	{}
  1236 	WrapCTestExecuteLogger(CTestExecuteLogger&aLogger):	iLogger(&aLogger)	{}
  1237 	WrapCTestExecuteLogger(CTestExecuteLogger*aLogger):	iLogger(aLogger)	{}
  1238 	
  1239 	operator int()	{return (iLogger!=NULL);}
  1240 	CTestExecuteLogger& operator()() { return *iLogger;	}
  1241 
  1242 	CTestExecuteLogger* iLogger;
  1243 	
  1244 	};
  1245 static const TInt KCopyTestHeight=20;
  1246 static const TInt KCopyTestWidth=256;	//should be some multiple of 32...
  1247 /** Compares the pixels in the source rectangle and its copy.
  1248  * 	The copy is at an offset from the source.
  1249  * 	The compare is not complete as this was found to be too slow.
  1250  *  Instead only a few pixels on the left and right edges are compared.
  1251  * 
  1252  **/
  1253 TBool CmpBitmapRectL(CFbsBitmap& aTestBitmap,TRect aSource,TPoint aTrgOffset,WrapCTestExecuteLogger Logger=NULL,TBool aExpectedPass=EFalse)
  1254 	{
  1255 	//Comparing all the pixels in a large rectangle using GetPixel() is too slow. 
  1256 	//So now, only a few pixels on the edges of the rectangle are compared, 
  1257 	//and the ones in between are skipped.
  1258 	//Using any faster method to get the pixels is dubious 
  1259 	//as it it may ultimately use GetLine, which is the method under test...
  1260 	const TInt processSize=6;
  1261 	TBool returnState=ETrue;
  1262 	TUint16 printcompareresultbuffers[KCopyTestHeight][2][processSize*2+1]={{{0}}};
  1263 	TInt resultRow=KCopyTestHeight-aSource.Height();
  1264 	TInt skipMiddleStart=aSource.iTl.iX+processSize;
  1265 	TInt skipMiddleEnd=aSource.iBr.iX-processSize-1;
  1266 	if (skipMiddleStart>=skipMiddleEnd)
  1267 		{
  1268 		skipMiddleStart+=processSize+processSize;	//make skip irrelivent
  1269 		}
  1270 	//verify inputs valid 
  1271 	TRect bitmapRect=aTestBitmap.SizeInPixels();
  1272 	TRect sourceRectIntersect=aSource;
  1273 	TRect targetRect=aSource;
  1274 	targetRect.Move(aTrgOffset);
  1275 	TRect targetRectIntersect=targetRect;
  1276 	targetRectIntersect.Intersection(bitmapRect);
  1277 	sourceRectIntersect.Intersection(bitmapRect);
  1278 	ASSERT(sourceRectIntersect==aSource);
  1279 	ASSERT(targetRectIntersect==targetRect);
  1280 	
  1281 	for (TInt sy=aSource.iTl.iY;sy<aSource.iBr.iY;sy++)
  1282 		{
  1283 		TInt resultCol=0;
  1284 		for (TInt sx=aSource.iTl.iX;sx<aSource.iBr.iX;sx++)
  1285 			{
  1286 			if (sx==skipMiddleStart)
  1287 				{
  1288 				sx=skipMiddleEnd;
  1289 				}
  1290 			else
  1291 				{
  1292 				TRgb sourceColor;
  1293 				aTestBitmap.GetPixel(sourceColor,TPoint(sx,sy));
  1294 				TRgb targetColor;
  1295 				aTestBitmap.GetPixel(targetColor,TPoint(sx,sy)+aTrgOffset);
  1296 				if (sourceColor!=targetColor)
  1297 					{
  1298 					if (Logger)
  1299 						{
  1300 						returnState=EFalse;
  1301 						}
  1302 					else
  1303 						{
  1304 						return EFalse;
  1305 						}
  1306 					}
  1307 				if (Logger&&resultRow>=0)
  1308 					{
  1309 					printcompareresultbuffers[resultRow][0][resultCol]=L'@'+sourceColor.Color16(); 
  1310 					printcompareresultbuffers[resultRow][1][resultCol]=L'@'+targetColor.Color16(); 
  1311 					}
  1312 				}
  1313 				
  1314 			}
  1315 		resultRow++;
  1316 		}
  1317 	if (Logger && returnState!=aExpectedPass)
  1318 		{
  1319 		INFO_PRINTF4(_L("Case: srcx=%i targx=%i width=%i result compare has failed! Content dump follows: [src] [trg] "),
  1320 				aSource.iTl.iX,targetRect.iTl.iX,aSource.Width());
  1321 		for (TInt row=(KCopyTestHeight-aSource.Height()>0)?KCopyTestHeight-aSource.Height():0;row<KCopyTestHeight;row++)
  1322 			{
  1323 			INFO_PRINTF5(_L("Row: %2i %s  %s (%s)"),
  1324 					row,printcompareresultbuffers[row][0],printcompareresultbuffers[row][1],
  1325 					Mem::Compare(printcompareresultbuffers[row][0],processSize*2,printcompareresultbuffers[row][1],processSize*2)
  1326 						?L"differ":L"same"
  1327 						);
  1328 			
  1329 			}
  1330 		}
  1331 	return returnState;
  1332 	}
  1333 
  1334 /**
  1335  * @SYMTestCaseID GRAPHICS-BITGDI-0099
  1336  *
  1337  * @SYMDEF INC119063, pdef120353
  1338  *
  1339  * @SYMTestCaseDesc CopyRect could read bytes past the end of the source bitmap
  1340  * 					This is a general test of the rewrite of CopyRect
  1341  *					Note that this test says well within the boundaries of the bitmap,
  1342  * 					and does not test the exception condition detected in the defect.
  1343  * @SYMTestPriority Normal
  1344  *
  1345  * @SYMTestStatus Implemented
  1346  *
  1347  * @SYMTestActions 
  1348  * 				Repeat the test for 4 affected bitmap resolutions: Gray2, Gray4, Gray16, Color16
  1349  * 				Allocate a bitmap big enough to process the test
  1350  * 				Repeat:
  1351  * 					Fill the whole image with random data
  1352  * 					Pixel compare the source rectangle wiith the target rectangle
  1353  * 						- they should NOT be identical - very unlucky!
  1354  * 					Pixel compare the left and right edge pixels outside the copy rect
  1355  * 						- these should not be all identical - very unlucky!
  1356  * 					Copyrect a region from the bottom half to the top half (not to edges)
  1357  * 					Pixel compare the source rectangle wiith the target rectangle
  1358  * 						- they should be identical - copy was successful
  1359  * 					Pixel compare the left and right edge pixels outside the copy rect
  1360  * 						- these should not be all identical - or too much was copied
  1361  * 				Repeat for values of target x 0 to 32
  1362  * 				Repeat for values of source x 0 to 32
  1363  * 				Repeat for values of source/target width 1 to 96
  1364  * 				Guess: 4x32x32x96 tests=400000 iterations
  1365 */	
  1366 void CTDefect2::ExerciseCopyRect()
  1367 	{
  1368 	for (TInt mode=1;mode<EColorLast;mode++)
  1369 		{
  1370 		CFbsBitmap testBitmap;
  1371 
  1372 		//The exact dimensions of this bitmap are not important...
  1373 		//The width should ensure that the range of tests work (max 32+32+96=160 pixels)
  1374 		//The height should be enough to ensure there is enough variability in the random data
  1375 		//Note that the smallest data used in a uniqueness test is a 1-pixel-width column half the height of the image. 
  1376 		//The whole height will be used if this is changed.
  1377 		if (testBitmap.Create(TSize(KCopyTestWidth,KCopyTestHeight*2),TDisplayMode(mode))<KErrNone)
  1378 			{
  1379 			continue;	//some mode numbers are bad!
  1380 			}
  1381 		
  1382 		
  1383 		SEpocBitmapHeader header1 = testBitmap.Header();
  1384 		//We could run this test for other modes, but the defect and fix only applies to low bit depths
  1385 		if (header1.iBitsPerPixel>4)
  1386 		{
  1387 		continue;	
  1388 		}
  1389 		INFO_PRINTF3(_L("Bitmap color depth: %i bits. Color flag: %i"),header1.iBitsPerPixel,header1.iColor);
  1390    
  1391  
  1392 		TUint32* bitmapData=testBitmap.DataAddress();
  1393 		TUint32* pastBitmapData=bitmapData+((header1.iBitmapSize-header1.iStructSize)>>2);
  1394 
  1395 		TInt splitHeight=header1.iSizeInPixels.iHeight/2;
  1396    
  1397 		CFbsBitGc* bitmapContext = NULL;
  1398 		CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(&testBitmap);
  1399 		CleanupStack::PushL(bitmapDevice);
  1400 		User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext));
  1401 		CleanupStack::PushL(bitmapContext);
  1402 		TInt skippedCases=0;
  1403 		TInt totalCases=0;
  1404 		//These counts have been tweaked based on knowledge of the algorithm.
  1405 		//The target position is shifted in bits by up to 1 word (32 bits)
  1406 		//Bigger changes than this just change the target pointer and modulo the shift.
  1407 		//[I don't think that the target position influences the result, but it might]
  1408 		//The source position is shifted in bits by up to 1 word (32 bits)
  1409 		//Bigger changes than this just change the source pointer and modulo the shift.
  1410 		//The copy width is made up of a copy words element and a remainder bytes element.
  1411 		//The difference in shift element between source and target is used to shift the 
  1412 		//source to a temporary buffer.
  1413 		//So the copy width element is also influenced by the source position and target position.
  1414 		//Testing 96 possible bit widths should exercise it for zero and non-zero word counts adequately.
  1415 		const TInt
  1416 			KTargXMin=32,
  1417 			KTargXMax=32+32/header1.iBitsPerPixel,
  1418 			KSrcXMin=32,
  1419 			KSrcXMax=32+32/header1.iBitsPerPixel,
  1420 			KWidthMin=1,
  1421 			KWidthMax=96/header1.iBitsPerPixel;
  1422 		for (TInt targx=KTargXMin;targx<KTargXMax;targx++)
  1423 			{	
  1424 			for (TInt srcx=KSrcXMin;srcx<KSrcXMax;srcx++)
  1425 				{
  1426 				for (TInt width=KWidthMin;width<KWidthMax;width++)
  1427 					{
  1428 					totalCases++;
  1429 					TInt offsetx=targx-srcx;
  1430 					//fill the buffer with random data
  1431 					TInt64 randomSeed=MAKE_TINT64(0xdeadbeef,0xbaadf00d);
  1432 					Math::Rand(randomSeed);
  1433 					TInt maxRetries=3;
  1434 					TInt rndCount=0;
  1435 					while (--maxRetries>=0)
  1436 						{
  1437 						for (TUint32* fillData=bitmapData;fillData!=pastBitmapData;fillData++)
  1438 							{
  1439 							rndCount++;
  1440 							//Rand only sets 31 bits of the integer - no negative values - no top bit set! 
  1441 							//This solution wastes some of the seed, but it should still produce valid results. 
  1442 							TInt rnd=Math::Rand(randomSeed)^(Math::Rand(randomSeed)<<8);
  1443 							*fillData=rnd;
  1444 							}
  1445 						TInt colOffSrc=0;
  1446 						TInt colOffTrg=0;
  1447 						//verify that the data is different inside the copy area and outside each copy area
  1448 						if (TInt failCode=	CmpBitmapRectL(testBitmap,TRect(srcx,splitHeight,srcx+width,splitHeight*2),TPoint(offsetx,-splitHeight))
  1449 							+	2*CmpBitmapRectL(testBitmap,TRect(srcx-1,splitHeight,srcx,splitHeight*2),TPoint(offsetx,-splitHeight))
  1450 							+ 	4*CmpBitmapRectL(testBitmap,TRect(srcx+width,splitHeight,srcx+width+1,splitHeight*2),TPoint(offsetx,-splitHeight))
  1451 							)
  1452 						   {
  1453 						   //OK.. need to find another pair of bits where the source and target columns are non-identical
  1454 						   INFO_PRINTF5(_L("First random data failed... (code %i) Trying alternale columns: srcx=%i targx=%i width=%i"),failCode,srcx,targx,width);
  1455 						   for (TInt tryOffSrc=0;tryOffSrc+srcx<KCopyTestWidth-(KWidthMax+1) && (colOffSrc==0&&colOffTrg==0);tryOffSrc+=32)
  1456 							   for (TInt tryOffTrg=0;tryOffTrg+targx<KCopyTestWidth-(KWidthMax+1) && (colOffSrc==0&&colOffTrg==0);tryOffTrg+=32)
  1457 								   {
  1458 								   TInt offsetx=(tryOffTrg+targx)-(tryOffSrc+srcx);
  1459 								   TInt trysrcx=tryOffSrc+srcx;
  1460 								   if (	CmpBitmapRectL(testBitmap,TRect(trysrcx,splitHeight,trysrcx+width,splitHeight*2),TPoint(offsetx,-splitHeight))
  1461 									|	CmpBitmapRectL(testBitmap,TRect(trysrcx-1,splitHeight,trysrcx,splitHeight*2),TPoint(offsetx,-splitHeight))
  1462 									|	CmpBitmapRectL(testBitmap,TRect(trysrcx+width,splitHeight,trysrcx+width+1,splitHeight*2),TPoint(offsetx,-splitHeight))
  1463 									)
  1464 									   {
  1465 									   }
  1466 								   else
  1467 									   {
  1468 									   colOffSrc=tryOffSrc;
  1469 									   colOffTrg=tryOffTrg;
  1470 									   }
  1471 								   }
  1472 						   if (colOffSrc||colOffTrg)
  1473 							   {
  1474 							   offsetx=(colOffTrg+targx)-(colOffSrc+srcx);
  1475 							   INFO_PRINTF4(_L("Found a safe equivalent column:  srcx=%i targx=%i width=%i"),colOffSrc+srcx,colOffTrg+targx,width);
  1476 							   }
  1477 						   else
  1478 							   {
  1479 							   INFO_PRINTF4(_L("Didn't find a safe column! Trying next random numbers"),srcx,targx,width);
  1480 							   continue;	//Try next random number...
  1481 							   }
  1482 						   }
  1483 						TInt trysrcx=colOffSrc+srcx;
  1484 						//Copy the region in question
  1485 						bitmapContext->CopyRect(TPoint(offsetx,-splitHeight), TRect(trysrcx,splitHeight,trysrcx+width,splitHeight*2));
  1486 						//verify the copied region is an exact match
  1487 						TBool copySame=CmpBitmapRectL(testBitmap,TRect(trysrcx,splitHeight,trysrcx+width,splitHeight*2),TPoint(offsetx,-splitHeight));
  1488 						//verify the area outside has not been copied
  1489 						TBool leftSame=CmpBitmapRectL(testBitmap,TRect(trysrcx-1,splitHeight,trysrcx,splitHeight*2),TPoint(offsetx,-splitHeight));
  1490 						TBool rightSame=CmpBitmapRectL(testBitmap,TRect(trysrcx+width,splitHeight,trysrcx+width+1,splitHeight*2),TPoint(offsetx,-splitHeight));
  1491 						if (!copySame||leftSame||rightSame)
  1492 							{
  1493 							INFO_PRINTF4(_L("Case: srcx=%i targx=%i width=%i result compare has failed!"),srcx,targx,width);
  1494 							if (!copySame)
  1495 								{
  1496 								INFO_PRINTF1(_L("Copied data is not same as source data!"));
  1497 								}
  1498 							if (leftSame)
  1499 								{
  1500 								INFO_PRINTF1(_L("Data to left of copy is now same as source data!"));
  1501 								}
  1502 							if (rightSame)
  1503 								{
  1504 								INFO_PRINTF1(_L("Data to right of copy is now same as source data!"));
  1505 								}
  1506 							TEST(EFalse);
  1507 							}
  1508 						break;	//out of "try next random number" loop
  1509 						}
  1510 					if (maxRetries<0)
  1511 						{
  1512 						INFO_PRINTF4(_L("Case skipped TOO MANY TIMES because random data not unique: srcx=%i targx=%i width=%i."),srcx,targx,width);
  1513 						skippedCases++;
  1514 						}
  1515 					}
  1516 				}
  1517 			}
  1518 		CleanupStack::PopAndDestroy(bitmapContext);
  1519 	   	CleanupStack::PopAndDestroy(bitmapDevice);
  1520 	   	
  1521 	   	testBitmap.Reset();
  1522 		if (skippedCases)
  1523 			{
  1524 			INFO_PRINTF3(_L("%i / %i cases skipped because random picture data not unique enough! 10%% will cause test fail."),skippedCases,totalCases );
  1525 			TEST(skippedCases*10<totalCases);
  1526 			}
  1527 		}
  1528 	}
  1529 /**
  1530  * @SYMTestCaseID GRAPHICS-BITGDI-0098
  1531  *
  1532  * @SYMDEF INC119063, PDEF120353
  1533  *
  1534  * @SYMTestCaseDesc CopyRect could previously read bytes past the end of the source bitmap
  1535  * 					This would exception if the page is not mapped.
  1536  * 					This particular image size allocation reproduces this exception.
  1537  * 					Any changes to the allocation mechanism may mean the crash condition is not reproducable.
  1538  * 					It is likely that it is changes to the allocator that have caused this defect to occur
  1539  * 					in the first place.
  1540  *
  1541  * @SYMTestPriority Normal
  1542  *
  1543  * @SYMTestStatus Implemented
  1544  *
  1545  * @SYMTestActions Create 768x1280 1 bit image, (also 384x1280x2bit and 192x1280x4bit ?)
  1546  * 			In a seperate thread try to read past the end of the data.
  1547  * 			If this panics then the test is valid.
  1548  * 			Now, make a number of copyrect calls 
  1549  * 			that attempt to read data from near the end of the last scanline				   
  1550  *			Expected result: these reads should not exception.
  1551  * 			Enhancement to improve reproducability:
  1552  * 			Occasionally, the "next location" is addressable when the test is run in the overnight script
  1553  * 			To address this, the test will recurse and repeat, forcing the image allocation to a different address if this occurs
  1554 */	
  1555 TBool CTDefect2::CopyRectReadOutsideBitmap(TInt aSingleMode /*=0*/,TInt aRetriesLeft /*=5*/)
  1556 	{
  1557 	TBool testShouldUltimatelyFail=EFalse;
  1558 	TInt startMode=aSingleMode?aSingleMode:1;
  1559 	TInt stopMode=aSingleMode?aSingleMode+1:EColorLast;
  1560 	for (TInt mode=startMode;mode<stopMode;mode++)
  1561 		{
  1562 		CFbsBitmap testBitmap;
  1563 		enum
  1564 			{
  1565 			EMonoPixelsWidth=768,
  1566 			EMonoBytesWidth=96,
  1567 			EMonoHeight=1280
  1568 			};
  1569 		TInt guessPixels=EMonoPixelsWidth;
  1570 		TInt guessBytes=CFbsBitmap::ScanLineLength(guessPixels,TDisplayMode(mode));
  1571 		if (guessBytes<=0 || reinterpret_cast<TDisplayMode&>(mode)==ERgb)
  1572 			{
  1573 			continue;	//mode number not good.
  1574 			}
  1575 		//want to generate a length of 768/8=96 bytes per scanline to repro the defect...
  1576 		while (guessBytes<EMonoBytesWidth)
  1577 			{
  1578 			if (guessBytes<=EMonoBytesWidth/2)
  1579 				{
  1580 				guessPixels*=2;
  1581 				}
  1582 			else
  1583 				{
  1584 				guessPixels++;
  1585 				}
  1586 			guessBytes=CFbsBitmap::ScanLineLength(guessPixels,TDisplayMode(mode));
  1587 			}
  1588 		while (guessBytes>EMonoBytesWidth)
  1589 			{
  1590 			if (guessBytes>=EMonoBytesWidth*2)
  1591 				{
  1592 				guessPixels>>=1;
  1593 				}
  1594 			else
  1595 				{
  1596 				guessPixels--;
  1597 				}
  1598 			guessBytes=CFbsBitmap::ScanLineLength(guessPixels,TDisplayMode(mode));
  1599 			}
  1600 		
  1601 		if (testBitmap.Create(TSize(guessPixels,EMonoHeight),TDisplayMode(mode))<KErrNone)
  1602 			{
  1603 			_LIT(KFail,"Failed to create bitmap for color depth: %S");
  1604 			INFO_PRINTF2(KFail,&ColorModeName(mode));
  1605 			if (aSingleMode)
  1606 				{
  1607 				testShouldUltimatelyFail=ETrue;
  1608 				}
  1609 			continue;	//some mode numbers are bad!
  1610 			}
  1611 
  1612 		SEpocBitmapHeader header1 = testBitmap.Header();
  1613 
  1614 		TUint32* bitmapData=testBitmap.DataAddress();
  1615 		TUint32* pastBitmapData=bitmapData+((header1.iBitmapSize-header1.iStructSize)>>2);
  1616 
  1617 		//The defect and fix only applies to low bit depths, but it is quick enough to run it for all color depths
  1618 		if (aSingleMode)
  1619 			{
  1620 			User::After(1000000);	//Pause is in microseconds! //A small pause to try to get the bad operation completed
  1621 			INFO_PRINTF3(_L("Retry Bitmap: Address 0x%08x, past 0x%08x"),
  1622 					bitmapData,pastBitmapData		);
  1623 			
  1624 			}
  1625 		else
  1626 			{
  1627 			INFO_PRINTF7(_L("Bitmap: color depth: %i bits. Color mode= %i. Width=%i Height=%i Address 0x%08x, past 0x%08x"),
  1628 					header1.iBitsPerPixel,header1.iColor,
  1629 					header1.iSizeInPixels.iWidth,header1.iSizeInPixels.iHeight,
  1630 					bitmapData,pastBitmapData		);
  1631 			}
  1632 		TBool canGenerateDefectScenario=EFalse;
  1633 
  1634 		
  1635 		//So now we hope that we have created a test bitmap on the bottom of a memory page,
  1636 		//as per the defect, but at different color depths as well.
  1637 		//Any number of factors could change the way this block is allocated and disguise the defect.
  1638 		//Equally, the next block of memory may be already mapped, and again the defect will not occurr.
  1639 		//There is no way to influence the result, so the next ting to do is to verify that an exception will occur.
  1640 		//Could assert that the address matches a 4K page, but I need to check if the page is mapped anyway!	
  1641 		TTestMemThread memThread(pastBitmapData-2,pastBitmapData+2);
  1642 		TInt failAt=memThread.FailOffset();
  1643 		if (failAt<0)
  1644 			{
  1645 			INFO_PRINTF2(_L("                 Scenario invalid - error code generated by test thread! %i"),failAt);
  1646 			}
  1647 		else if (failAt<=1)
  1648 			{
  1649 			INFO_PRINTF1(_L("                 Scenario invalid - didn't manage to read a safe location near the end of the bitmap!"));
  1650 			}
  1651 		else if (failAt>2)
  1652 			{
  1653 			INFO_PRINTF1(_L("                   Scenario invalid - managed to read right past the test location!"));
  1654 			}
  1655 		else
  1656 			{
  1657 			INFO_PRINTF1(_L("              Verified that end address is bad memory"));
  1658 			canGenerateDefectScenario=ETrue;
  1659 			}
  1660 		if (!canGenerateDefectScenario)
  1661 			{
  1662 			if (!aRetriesLeft || !CopyRectReadOutsideBitmap(mode,aRetriesLeft-1))	//repeat attempt with nested bitmap alocation to new address
  1663 				{
  1664 				//if this doesn't work out then the memory allocator is not like it was when the defect was raised!
  1665 				//so the test is no longer any good.
  1666 				//Can't return "Inconclusive" as other tests in the test set may reset the state.
  1667 				INFO_PRINTF2(_L("Error!!: Couldn't generate the defect scenario for the end address at 0x%08x."),(TInt)pastBitmapData);
  1668 				testShouldUltimatelyFail=ETrue;
  1669 				}
  1670 			}
  1671 		else
  1672 			{
  1673 			//These writes should succeed if the end of the bitmap is where it should be:
  1674 			//these colour values will be transferred in the copied data in the subsequent test
  1675 			//The test does not explicitly look for these patterns, 
  1676 			//but they are useful to identify in the copied data if manually debugging.
  1677 			pastBitmapData[-2]=0xBAADF00D;
  1678 			pastBitmapData[-1]=0xdeadbeef;
  1679 
  1680 			CFbsBitGc* bitmapContext = NULL;
  1681 			CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(&testBitmap);
  1682 			CleanupStack::PushL(bitmapDevice);
  1683 			User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext));
  1684 			CleanupStack::PushL(bitmapContext);
  1685 			//for the last scanline, try to copy various permutations of the last few pixels
  1686 			//note that there is no check to see if the "right" contents are copied, only that it doesn't abort.
  1687 			//In fact most of the bitmap is uninitialised...
  1688 			TTestCopyRectThread copythread(bitmapContext,guessPixels-64,guessPixels,EMonoHeight-5,EMonoHeight,TPoint(-5,-5));
  1689 			if (copythread.iExitHow!=copythread.EReturn)
  1690 				{
  1691 				testShouldUltimatelyFail=ETrue;
  1692 				INFO_PRINTF7(_L("Error: (probably panic) when using CopyRect(TPoint(%i,%i),TRect(%i,%i,%i,%i)"),
  1693 						-5,-5,
  1694 						copythread.iCurrX,EMonoHeight-5, copythread.iCurrX+copythread.iCurrWidth,EMonoHeight);
  1695 				_LIT(KLog,"Thread Exit Reason %d, expected %d");
  1696 				INFO_PRINTF3(KLog,copythread.iExitHow,copythread.EReturn);
  1697 				}
  1698 
  1699 			CleanupStack::PopAndDestroy(bitmapContext);
  1700 			CleanupStack::PopAndDestroy(bitmapDevice);
  1701 
  1702 			//For the purposes of verification, check that the memory location is still considered a valid scenario.
  1703 			//Again , the test is repeated nested if the scenario has become invalid
  1704 			TTestMemThread memThread2(pastBitmapData-2,pastBitmapData+2);
  1705 			TInt failAt=memThread2.FailOffset();
  1706 			canGenerateDefectScenario=EFalse;
  1707 			if (failAt<0)
  1708 				{
  1709 				INFO_PRINTF2(_L("                 After Test: Scenario invalid - error code generated by test thread! %i"),failAt);
  1710 				INFO_PRINTF1(_L("Warning: This may mean that bad copys may not have been detected??"));
  1711 				}
  1712 			else if (failAt<=1)
  1713 				{
  1714 				INFO_PRINTF1(_L("                 After Test: Scenario invalid - didn't manage to read a safe location near the end of the bitmap!"));
  1715 				INFO_PRINTF1(_L("Warning: This may mean that bad copys may not have been detected??"));
  1716 				}
  1717 			else if (failAt>2)
  1718 				{
  1719 				INFO_PRINTF1(_L("                  After Test: Scenario invalid - managed to read right past the test location!"));
  1720 				INFO_PRINTF1(_L("Warning: This may mean that bad copys may not have been detected??"));
  1721 				}
  1722 			else
  1723 				{
  1724 				INFO_PRINTF1(_L("              After Test: Verified that end address is still bad memory"));
  1725 				canGenerateDefectScenario=ETrue;
  1726 				}
  1727 			if (!canGenerateDefectScenario)
  1728 				{
  1729 				if (!aRetriesLeft || !CopyRectReadOutsideBitmap(mode,aRetriesLeft-1))	//repeat attempt with nested bitmap alocation to new address
  1730 					{
  1731 					//if this doesn't work out then the memory allocator is not like it was when the defect was raised!
  1732 					//so the test is no longer any good.
  1733 					//Can't return "Inconclusive" as other tests in the test set may reset the state.
  1734 					INFO_PRINTF2(_L("Warning!!: Couldn't maintain the defect scenario for the end address at 0x%08x after retries."),(TInt)pastBitmapData);
  1735 					INFO_PRINTF1(_L("Test may have read from end of bitmap after it was made accessible."));
  1736 					//Ultimately, this refuses to stabilise on ONB scenario, so I won't have this retry of the test fail.
  1737 					}
  1738 				}
  1739 				
  1740 			}
  1741 	   	testBitmap.Reset();
  1742 		}
  1743 	if (!aSingleMode)
  1744 		{
  1745 		TEST(!testShouldUltimatelyFail);
  1746 		}
  1747 	return (!testShouldUltimatelyFail);
  1748 	}
  1749 
  1750 /**
  1751   @SYMTestCaseID GRAPHICS-BITGDI-0066
  1752  
  1753   @SYMDEF DEF039237            
  1754 
  1755   @SYMTestCaseDesc Memory leak in CFbsScreenDevice (occurs on Lubbock, but not WINS)
  1756    
  1757   @SYMTestPriority normal
  1758 
  1759   @SYMTestStatus Implemented
  1760 
  1761   @SYMTestActions Creates a screen device in each colour mode 
  1762  
  1763   @SYMTestExpectedResults Test should perform graphics operations succesfully. 
  1764 */
  1765 void CTDefect2::DEF039237L()
  1766 	{
  1767 	__UHEAP_MARK;
  1768 	const TInt KNumDisplayModes = 11;
  1769 	const TDisplayMode KDisplayMode[KNumDisplayModes] =
  1770 		{ EGray2, EGray4, EGray16, EGray256, EColor16, EColor256,
  1771 		  EColor4K, EColor64K, EColor16M, EColor16MA, EColor16MAP };
  1772 
  1773 	CFbsScreenDevice* device = NULL;
  1774 	TInt err = KErrNotSupported;
  1775 	TInt index;
  1776 
  1777 	for (index=0; index<KNumDisplayModes && err==KErrNotSupported; ++index)
  1778 		{
  1779 		ASSERT(device==NULL);
  1780 		TRAP(err,device = CFbsScreenDevice::NewL(KNullDesC,KDisplayMode[index]));
  1781 		}
  1782 	--index;
  1783 	if (device)
  1784 		{
  1785 		_LIT(KLog,"Created device with color depth %S");
  1786 		INFO_PRINTF2(KLog,&ColorModeName(KDisplayMode[index]));
  1787 		}
  1788 	else
  1789 		{
  1790 		_LIT(KLog,"Failed to create screen device, last color depth tried %S gave return value %d");
  1791 		INFO_PRINTF3(KLog,&ColorModeName(KDisplayMode[index]),err);
  1792 		}
  1793 
  1794 	User::LeaveIfError(err);
  1795 	ASSERT(device);
  1796 
  1797 	delete device;
  1798 	__UHEAP_MARKEND; 
  1799 	}
  1800 
  1801 /**
  1802   @SYMTestCaseID GRAPHICS-BITGDI-0067
  1803  
  1804   @SYMDEF DEF039331         
  1805 
  1806   @SYMTestCaseDesc bitgdi fails to deal correctly with screen orientation changes 
  1807     				
  1808   @SYMTestPriority normal
  1809 
  1810   @SYMTestStatus Implemented
  1811 
  1812   @SYMTestActions 
  1813   					DEF039604 - CFbsBitGc::InternalizeL/ExternalizeL - comments, version number
  1814    					Default region externalization/internalization related code was removed, so
  1815 					I want to check that everything is OK calling 
  1816 					CFbsBitGc::ExternalizeL()/CFbsBitGc::InternalizeL().
  1817 					The test may also fail in the future if somebody changes CFbsBitGc data members
  1818 					and fail to update ExternalizeL/InternalizeL methods.		 
  1819  
  1820   @SYMTestExpectedResults Test should perform graphics operations succesfully. 
  1821 */
  1822 void CTDefect2::DEF039331L()
  1823 	{
  1824 	CreateScrDevAndContextL();
  1825 
  1826 	//Make sure that the archive file does not exist.
  1827 	FServSession.Delete(KArchiveFileName);
  1828 
  1829 	RFileWriteStream wrStream;
  1830 	::CleanupClosePushL(wrStream);
  1831 	User::LeaveIfError(wrStream.Create(FServSession, KArchiveFileName, EFileWrite | EFileRead));
  1832 
  1833 	iGc->ExternalizeL(wrStream);
  1834 	wrStream.CommitL();
  1835 	CleanupStack::PopAndDestroy();//wrStream
  1836 
  1837 	RFileReadStream rdStream;
  1838 	::CleanupClosePushL(rdStream);
  1839 	User::LeaveIfError(rdStream.Open(FServSession, KArchiveFileName, EFileRead));
  1840 	iGc->InternalizeL(rdStream);
  1841 	CleanupStack::PopAndDestroy();//rdStream
  1842 	}
  1843 
  1844 /**
  1845   @SYMTestCaseID GRAPHICS-BITGDI-0068
  1846  
  1847   @SYMDEF DEF039650             
  1848 
  1849   @SYMTestCaseDesc CFbsDevice::RectCompare says don't match when they do
  1850    
  1851   @SYMTestPriority normal
  1852 
  1853   @SYMTestStatus Implemented
  1854 
  1855   @SYMTestActions Creates a bitmap, calls scanlinedata then checks that the scanline returns the correct amount of data
  1856  
  1857   @SYMTestExpectedResults Test should return correct number of bytes
  1858 */
  1859 //DEF039650 - . 
  1860 void CTDefect2::DEF039650L()
  1861 	{
  1862 	enum {KHeight = 1};//Bitmaps height - in pixels
  1863 	TDisplayMode testMode[] =  {EGray2, EGray4, EGray16, EColor16, EColor4K, EColor64K, EColor16M, EColor16MU, EColor256};//tested display modes
  1864 	const TInt pixelPerByte[] ={8,      4,      2,       2,        0,        0,         0,         0,          1};
  1865 	const TInt bytePerPixel[] ={0,      0,      0,       0,        2,        2,         3,         4,          0};
  1866 	const TInt bitmapWidth[] = {22,     7,      11,      11,       3,        3,         1,         1,          10};//bitmaps width
  1867 	const TUint8 KTestVal1 = 0xA3;//test value
  1868 	const TUint8 KTestVal2 = 0xF7;//test value
  1869 	TUint8 scanLineData[100];//100 should be enough for all possible modes which are tested
  1870 	for(TInt ii=0;ii<TInt(sizeof(testMode)/sizeof(testMode[0]));ii++)
  1871 		{
  1872 		TSize size(bitmapWidth[ii], KHeight);//bitmap size - in pixels
  1873 		CreateBitmapL(size, testMode[ii]);
  1874 		//Initialize the bitmap scanline
  1875 		TInt scanLineLen = 0;
  1876 		if(pixelPerByte[ii])
  1877 			{
  1878 			scanLineLen = bitmapWidth[ii] / pixelPerByte[ii] + (bitmapWidth[ii] % pixelPerByte[ii] ? 1 : 0);
  1879 			}
  1880 		else
  1881 			{
  1882 			scanLineLen = bitmapWidth[ii] * bytePerPixel[ii];
  1883 			}
  1884 		const TInt KAddBytes = 10;
  1885 		Mem::Fill(scanLineData, scanLineLen, KTestVal1);
  1886 		TPtr8 p(scanLineData, scanLineLen, scanLineLen + KAddBytes);
  1887 		iBitmap->SetScanLine(p, 0);
  1888 		//Create bitmap device (KWidth, KHeight) size
  1889 		DeleteBitmapDevice();
  1890 		iBmpDevice = CFbsBitmapDevice::NewL(iBitmap);
  1891 		//Fill the scanLineData with control values
  1892 		Mem::Fill(scanLineData, sizeof(scanLineData), KTestVal2);
  1893 		//GetScanLine test - check the KAddBytes bytes
  1894 		iBmpDevice->GetScanLine(p, TPoint(), bitmapWidth[ii], testMode[ii]);
  1895 		for(TInt jj=0;jj<KAddBytes;jj++)
  1896 			{
  1897 			TEST(scanLineData[scanLineLen+jj] == KTestVal2);
  1898 			}
  1899 		}//end of - for(TInt ii=0;ii<TInt(sizeof(testMode)/sizeof(testMode[0]));ii++)
  1900 	}
  1901 
  1902 /**
  1903   @SYMTestCaseID GRAPHICS-BITGDI-0069
  1904  
  1905   @SYMDEF             
  1906 
  1907   @SYMTestCaseDesc Tests the performance of getting and setting pixels in different display modes
  1908    
  1909   @SYMTestPriority normal
  1910 
  1911   @SYMTestStatus Implemented
  1912 
  1913   @SYMTestActions draws a number opf pixels to a bitmap then reads them back. Time is recorded
  1914  
  1915   @SYMTestExpectedResults Test should perform graphics operations succesfully. 
  1916 */
  1917 void CTDefect2::GetPixelPerformance1L()
  1918 	{
  1919 	TDisplayMode mode[] = {EColor16MA, EColor16MAP, EColor256, EColor4K, EColor16M, EColor16MU, EColor64K, 
  1920 						   EGray256, EGray16, EGray4, EGray2, EColor16};
  1921 	_LIT(KLog,"Mode %S. Uncompressed bitmap. Time=%d");
  1922 	for(TInt ii=0;ii<TInt(sizeof(mode)/sizeof(mode[0]));ii++)
  1923 		{
  1924 		//Create bitmap
  1925 		enum {KWidth = 600, KHeight = 400};
  1926 		TSize size(KWidth, KHeight);
  1927 		CreateBitmapL(size, mode[ii]);
  1928 		TEST(!iBitmap->IsCompressedInRAM());
  1929 		//Fill bitmap
  1930 		TBitmapUtil bmpUtil(iBitmap);
  1931 		TTime now;
  1932 		now.UniversalTime();
  1933 		TInt64 seed = now.Int64();
  1934 		bmpUtil.Begin(TPoint(0, 0));
  1935 		for(TInt j1=0;j1<KWidth;j1++)
  1936 			{
  1937 			for(TInt j2=0;j2<KHeight;j2++)
  1938 				{
  1939 				bmpUtil.SetPos(TPoint(j1, j2));
  1940 				bmpUtil.SetPixel(Math::Rand(seed));
  1941 				}
  1942 			}
  1943 		bmpUtil.End();
  1944 		//Performance test
  1945 		TUint time = User::TickCount();
  1946 		TPoint pt;
  1947 		TRgb color(0);
  1948 		for(TInt jj=0;jj<size.iWidth;jj++)
  1949 			{
  1950 			for(TInt kk=0;kk<size.iHeight;kk++)
  1951 				{
  1952 				pt.iX = jj;
  1953 				pt.iY = kk;
  1954 				iBitmap->GetPixel(color, pt);
  1955 				}
  1956 			}
  1957 		time = User::TickCount() - time;
  1958 		INFO_PRINTF3(KLog,&ColorModeName(mode[ii]),time);
  1959 		//Destroy bitmap
  1960 		DeleteBitmap();
  1961 		}//end of - for(TInt ii=0;ii<TInt(sizeof(mode)/sizeof(mode[0]));ii++)
  1962 	}
  1963 
  1964 /**
  1965   @SYMTestCaseID GRAPHICS-BITGDI-0070
  1966  
  1967   @SYMDEF             
  1968 
  1969   @SYMTestCaseDesc Draws text to the screen device in different orientations
  1970    
  1971   @SYMTestPriority normal
  1972 
  1973   @SYMTestStatus Implemented
  1974 
  1975   @SYMTestActions Creates a screen device and gc, changes the gc orientation then draws some text to it 
  1976  
  1977   @SYMTestExpectedResults Test should perform graphics operations succesfully. 
  1978 */
  1979 void CTDefect2::RotateMoveTextL()
  1980 	{
  1981 	TInt err=CreateScrDevAndContext(EColor64K);
  1982 	if (err!=KErrNone)
  1983 		err=CreateScrDevAndContext(EColor256);
  1984 	if (err!=KErrNone)
  1985 		err=CreateScrDevAndContext(EColor16MA);
  1986 	if (err!=KErrNone)
  1987 		err=CreateScrDevAndContext(EColor16MAP);
  1988 	TEST(err==KErrNone);
  1989 	DoRotateMoveTextL();
  1990 	}
  1991 
  1992 void CTDefect2::DoRotateMoveTextL()
  1993 	{
  1994 	__ASSERT_ALWAYS(iScrDev, User::Invariant());
  1995 	__ASSERT_ALWAYS(iGc, User::Invariant());
  1996 	
  1997 	CreateFontL();
  1998 
  1999 	const CFbsBitGc::TGraphicsOrientation KOrientation[] = 
  2000 		{
  2001 		CFbsBitGc::EGraphicsOrientationNormal,
  2002 		CFbsBitGc::EGraphicsOrientationRotated90,
  2003 		CFbsBitGc::EGraphicsOrientationRotated180,
  2004 		CFbsBitGc::EGraphicsOrientationRotated270
  2005 		};
  2006 
  2007 	for(TInt ii=0;ii<TInt(sizeof(KOrientation)/sizeof(KOrientation[0]));++ii)
  2008 		{
  2009 		if(!iGc->SetOrientation(KOrientation[ii]))
  2010 			{
  2011 			continue;
  2012 			}
  2013 		_LIT(KRotation,"===EOrientation%S===");
  2014 		INFO_PRINTF2(KRotation,&RotationName(KOrientation[ii]));
  2015 
  2016 		TSize size = iScrDev->SizeInPixels();
  2017 		RDebug::Print(_L("Size: %d, %d\r\n"), size.iWidth, size.iHeight);
  2018 		for(TInt x=-40;x<(size.iWidth+30);x+=27)
  2019 			{
  2020 			for(TInt y=-40;y<(size.iHeight+30);y+=23)
  2021 				{
  2022 				iGc->Clear();
  2023 				iGc->SetPenStyle(CGraphicsContext::ESolidPen);
  2024 				iGc->SetPenColor(TRgb(0x00, 0x00, 0x00));
  2025 				iGc->SetPenSize(TSize(1, 1));
  2026 				
  2027 				iGc->DrawText(_L("Test text"), TPoint(x, y));
  2028 				
  2029 				iScrDev->Update();
  2030 				}
  2031 			}
  2032 		}
  2033 	iGc->SetOrientation(CFbsBitGc::EGraphicsOrientationNormal);
  2034 	}
  2035 
  2036 /**
  2037   @SYMTestCaseID GRAPHICS-BITGDI-0071
  2038  
  2039   @SYMDEF             
  2040 
  2041   @SYMTestCaseDesc Swaps width and height of a bitmap
  2042    
  2043   @SYMTestPriority normal
  2044 
  2045   @SYMTestStatus Implemented
  2046 
  2047   @SYMTestActions Test to swap the width and height of a bitmap
  2048  
  2049   @SYMTestExpectedResults Test should perform graphics operations succesfully. 
  2050 */
  2051 void CTDefect2::SwapWidthAndHeightL()
  2052 	{
  2053 	TDisplayMode testMode[] =  {EColor4K, EColor64K, EColor16M, EColor16MU,
  2054 								EColor256, EColor16MA, EColor16MAP, EColor16, EGray16, EGray4, EGray2};//tested display modes
  2055 	_LIT(KLog,"Mode %S");
  2056 	for(TInt ii=0;ii<TInt(sizeof(testMode)/sizeof(testMode[0]));ii++)
  2057 		{
  2058 		INFO_PRINTF2(KLog,&ColorModeName(testMode[ii]));
  2059 		TSize size(40, 12);//bitmap size - in pixels
  2060 		CreateBitmapL(size, testMode[ii]);//iBitmap - created
  2061 		//Create bitmap device
  2062 		DeleteBitmapDevice();
  2063 		iBmpDevice = CFbsBitmapDevice::NewL(iBitmap);
  2064 		TInt err = iBmpDevice->SwapWidthAndHeight();
  2065 		TEST(err == KErrNone);
  2066 		}//end of - for(TInt ii=0;ii<TInt(sizeof(testMode)/sizeof(testMode[0]));ii++)
  2067 	}
  2068 
  2069 
  2070 void CTDefect2::CreateScrDevAndContextL()
  2071 	{
  2072 	DeleteGraphicsContext();
  2073 	DeleteScreenDevice();
  2074 	TDisplayMode mode[] = {EColor256, EColor4K, EColor16M, EColor16MU, EColor64K,
  2075 						   EGray256, EGray16, EGray4, EGray2, EColor16, EColor16MA, EColor16MAP};
  2076 	TInt ii;
  2077 	TInt err = KErrNotSupported;
  2078 	for(ii=0;(ii<TInt(sizeof(mode)/sizeof(mode[0]))) && (err == KErrNotSupported);++ii)
  2079 		{
  2080 		err = CreateScrDevAndContext(mode[ii]);
  2081 		}
  2082 	TEST(err == KErrNone);
  2083 	}
  2084 
  2085 TInt CTDefect2::CreateScrDevAndContext(TInt aScreenNo, TDisplayMode aDisplayMode)
  2086 	{
  2087 	DeleteGraphicsContext();
  2088 	DeleteScreenDevice();
  2089 	TRAPD(err, iScrDev = CFbsScreenDevice::NewL(aScreenNo, aDisplayMode));
  2090 	if ( !iScrDev )
  2091 		{
  2092 		TESTE( err == KErrNotSupported, err );
  2093 		return err;
  2094 		}
  2095 	TEST(err == KErrNone);
  2096 	TEST(iScrDev->ScreenNo() == aScreenNo);
  2097 	err = iScrDev->CreateContext((CGraphicsContext*&)iGc);
  2098 	if ( !iGc )
  2099 		{
  2100 		return err;
  2101 		}
  2102 	TEST(err == KErrNone);
  2103 	iGc->SetUserDisplayMode(aDisplayMode);
  2104 	iScrDev->ChangeScreenDevice(NULL);
  2105 	iScrDev->SetAutoUpdate(EFalse);
  2106 	iSize = iScrDev->SizeInPixels();
  2107 	iCurrentMode = aDisplayMode;
  2108 	return err;
  2109 	}
  2110 
  2111 TInt CTDefect2::CreateScrDevAndContext(TDisplayMode aDisplayMode)
  2112 	{
  2113 	return CreateScrDevAndContext(KDefaultScreenNo,aDisplayMode);
  2114 	}
  2115 
  2116 void CTDefect2::DeleteScreenDevice()
  2117 	{
  2118 	delete iScrDev;
  2119 	iScrDev = NULL;
  2120 	}
  2121 
  2122 void CTDefect2::DeleteGraphicsContext()
  2123 	{
  2124 	delete iGc;
  2125 	iGc = NULL;
  2126 	}
  2127 
  2128 void CTDefect2::CreateBitmapL(const TSize& aSize, TDisplayMode aMode)
  2129 	{
  2130 	DeleteBitmap();
  2131 	iBitmap = new (ELeave) CFbsBitmap;
  2132 	User::LeaveIfError(iBitmap->Create(aSize, aMode));
  2133 	}
  2134 
  2135 void CTDefect2::DeleteBitmap()
  2136 	{
  2137 	if(iBitmap)
  2138 		{
  2139 		iBitmap->Reset();
  2140 		}
  2141 	delete iBitmap;
  2142 	iBitmap = NULL;
  2143 	}
  2144 
  2145 void CTDefect2::DeleteBitmapDevice()
  2146 	{
  2147 	delete iBmpDevice;
  2148 	iBmpDevice = NULL;
  2149 	}
  2150 
  2151 void CTDefect2::CreateFontL()
  2152 	{
  2153 	CFbsFont* font = NULL;
  2154 	TFontSpec fs(_L("Swiss"), 12);
  2155 	User::LeaveIfError(iScrDev->GetNearestFontToDesignHeightInPixels(font, fs));
  2156 	iGc->UseFont(font);
  2157 	}
  2158 
  2159 void CTDefect2::DestroyFont()
  2160 	{
  2161 	if(iGc)
  2162 		{
  2163 		iGc->DiscardFont();
  2164 		}
  2165 	}
  2166 
  2167 /**
  2168   @SYMTestCaseID GRAPHICS-BITGDI-0073
  2169  
  2170   @SYMDEF             
  2171 
  2172   @SYMTestCaseDesc Clear with non-zero origin
  2173    
  2174   @SYMTestPriority High
  2175 
  2176   @SYMTestStatus Implemented
  2177 
  2178   @SYMTestActions Creates a gc, setes its origin off (0,0) then clears it
  2179  
  2180   @SYMTestExpectedResults Test should perform graphics operations succesfully. 
  2181 */
  2182 void CTDefect2::NonZeroOriginClearL()
  2183 	{
  2184 	TInt err=CreateScrDevAndContext(EColor64K);
  2185 	if (err==KErrNotSupported)
  2186 		err=CreateScrDevAndContext(EColor16MA);
  2187 	if (err==KErrNotSupported)
  2188 		err=CreateScrDevAndContext(EColor16MAP);
  2189 	if (err!=KErrNone)
  2190 		{
  2191 		_LIT(KLog,"Failed to create screen device, err=%d");
  2192 		INFO_PRINTF2(KLog,err);
  2193 		}
  2194 	TRgb setColor(TRgb::Color64K(13897));
  2195 	iGc->SetBrushColor(setColor);
  2196 	iGc->SetOrigin(TPoint(100,100));
  2197 	iGc->Clear();
  2198 	iScrDev->Update();
  2199 
  2200 	//Check samples of the screen that it is the right color
  2201 	TSize size=iScrDev->SizeInPixels();
  2202 	TInt x;
  2203 	TInt y;
  2204 
  2205 	for (x=0;x<size.iWidth;x+=10)
  2206 		{
  2207 		for (y=0;y<size.iHeight;y+=10)
  2208 			{
  2209 			TRgb gotColor;
  2210 			iScrDev->GetPixel(gotColor, TPoint(x,y));
  2211 			TEST(gotColor==setColor);
  2212 			}
  2213 		}
  2214 	}
  2215 
  2216 /** 
  2217 @SYMTestCaseID		GRAPHICS-BITGDI-0108 
  2218 
  2219 @SYMDEF				PDEF127874      
  2220 
  2221 @SYMTestCaseDesc	Use pattern brush bitmaps with zero widths or zero height or both 
  2222 
  2223 @SYMTestPriority	High 
  2224 
  2225 @SYMTestStatus		Implemented 
  2226 
  2227 @SYMTestActions		Creates 3 bitmaps: 
  2228 					One with zero width, one with zero height, one width zero width and height. 
  2229 					Each bitmap should automatically be cleared to white. 
  2230 					Clear the screen to black. 
  2231 					Set the GC to use patterned brush. 
  2232 					In turn, set the brush pattern to be one of the bitmap and draw a rectangle.                     
  2233 @SYMTestExpectedResults Each rectangle drawn should remain black as each pattern brush should not be used.   
  2234 */ 
  2235 void CTDefect2::ZeroSizedPatternBrushL() 
  2236 	{ 
  2237 	// Create a source bitmap with zero width 
  2238 	CFbsBitmap* bmp1 = new (ELeave) CFbsBitmap(); 
  2239 	CleanupStack::PushL(bmp1); 
  2240 	User::LeaveIfError(bmp1->Create(TSize(0,1), EColor16MU)); 
  2241 
  2242 	// Create a source bitmap with zero height 
  2243 	CFbsBitmap* bmp2 = new(ELeave) CFbsBitmap(); 
  2244 	CleanupStack::PushL(bmp2); 
  2245 	User::LeaveIfError(bmp2->Create(TSize(1,0), EColor16MU)); 
  2246 
  2247 	// Create a source bitmap with zero width and height 
  2248 	CFbsBitmap* bmp3 = new (ELeave) CFbsBitmap(); 
  2249 	CleanupStack::PushL(bmp3); 
  2250 	User::LeaveIfError(bmp3->Create(TSize(0,0), EColor16MU)); 
  2251 
  2252 	//Create a screen device & gc 
  2253 	CreateScrDevAndContextL(); 
  2254 
  2255 	TRgb clearColor = KRgbBlack; 
  2256 	iGc->SetBrushColor(clearColor); 
  2257 	iGc->Clear(); 
  2258 	iScrDev->Update(); 
  2259 	iGc->SetPenStyle(CGraphicsContext::ENullPen); 
  2260 	iGc->SetBrushStyle(CGraphicsContext::EPatternedBrush); 
  2261 	TSize drawRectSize(10,3); 
  2262 	// Draw a rectangle using each bitmap as a brush pattern 
  2263 	// Each rectangle does not overlap 
  2264 	iGc->UseBrushPattern(bmp1); 
  2265 	iGc->DrawRect(TRect(TPoint(0,0),drawRectSize)); 
  2266 
  2267 	iGc->UseBrushPattern(bmp2); 
  2268 	iGc->DrawRect(TRect(TPoint(0,4),drawRectSize)); 
  2269 
  2270 	iGc->UseBrushPattern(bmp3); 
  2271 	iGc->DrawRect(TRect(TPoint(0,8),drawRectSize)); 
  2272 
  2273 	iScrDev->Update(); 
  2274 	// Bitmaps should be cleared to white when created, so if they are drawn 
  2275 	// will show up different to cleared screen. 
  2276 	for(TInt y=0; y<12; ++y) 
  2277 		{ 
  2278 		for(TInt x=0; x<10; ++x) 
  2279 			{ 
  2280 			TRgb pixelColor; 
  2281 			iScrDev->GetPixel(pixelColor,TPoint(x,y)); 
  2282 			TEST(pixelColor==clearColor); 
  2283 			} 
  2284 		} 
  2285 	CleanupStack::PopAndDestroy(3, bmp1); 
  2286 	DeleteGraphicsContext(); 
  2287 	DeleteScreenDevice(); 
  2288 	}
  2289 
  2290 /**
  2291 @SYMTestCaseID GRAPHICS-BITGDI-0110
  2292 
  2293 @SYMDEF INC128813,PDEF129382
  2294 
  2295 @SYMTestCaseDesc Test CFbsBitGc::InternalizeL() when the font duplicate called from 
  2296 CFbsBitGc::Internalize:() fails.
  2297  
  2298 @SYMTestPriority Normal
  2299 
  2300 @SYMTestStatus Implemented (udeb/ debug versions only)
  2301 
  2302 @SYMTestActions Create and externalize a the CFbsBitGc*.
  2303  				Then send a message to the font and bitmap server to force 
  2304  				CFbsBitGcFont::Duplicate() calls to fail.
  2305  				Internalize the CFbsBitGc*()
  2306  				Then send a message to the font and bitmap server to allow
  2307  				CFbsBitGcFont::Duplicate() calls to succeed.
  2308  				If the test runs to completion without any panics, then it has passed.
  2309 */
  2310 void CTDefect2::CFbsBitGcInternalizeLFailL()
  2311 	{
  2312 	// this code is based on test CTDefect2::DEF039331L();
  2313 #ifndef _DEBUG
  2314 	INFO_PRINTF1(_L("Cannot run CFbsBitGcInternalizeLFailL test because test needs udeb for fbserv"));
  2315 	return;
  2316 	
  2317 #else
  2318 	CreateScrDevAndContextL();
  2319 
  2320 	//Make sure that the archive file does not exist.
  2321 	FServSession.Delete(KArchiveFileName);
  2322 
  2323 	CBufFlat* flatBuf = CBufFlat::NewL(256);
  2324 	CleanupStack::PushL(flatBuf);
  2325 	RBufWriteStream wrStream(*flatBuf);
  2326 	::CleanupClosePushL(wrStream);
  2327 	
  2328 	CreateFontL();
  2329 	
  2330 	iGc->ExternalizeL(wrStream);
  2331 	wrStream.CommitL();
  2332 	CleanupStack::PopAndDestroy();//wrStream
  2333 
  2334 	RBufReadStream rdStream(*flatBuf);
  2335 	::CleanupClosePushL(rdStream);
  2336 
  2337 	RFbsSession::GetSession()->SendCommand(static_cast<TInt>(EFbsMessSetDuplicateFail),1);
  2338 
  2339 	TInt ret=KErrNone;
  2340 	TRAP(ret, (void)(iGc->InternalizeL(rdStream)));
  2341 	INFO_PRINTF2(_L("CFbsBitGcInternalizeLFailL test returned %d: should have an error code"),ret);
  2342 
  2343 	RFbsSession::GetSession()->SendCommand(static_cast<TInt>(EFbsMessSetDuplicateFail),0);
  2344 
  2345 	//Without the fix there is a Kern-Exec3 panic.
  2346 	TEST (ETrue);
  2347 	CleanupStack::PopAndDestroy(2,flatBuf);
  2348 #endif
  2349 	}
  2350 
  2351 /** 
  2352 @SYMTestCaseID		GRAPHICS-BITGDI-0111 
  2353 
  2354 @SYMDEF				DEF132331
  2355 
  2356 @SYMTestCaseDesc	Compare output from CFbsScreenDevice::HorizontalPixelsToTwips() and 
  2357 					VerticalPixelsToTwips() with the same methods in CWsScreenDevice with
  2358 					large input numbers. 
  2359 
  2360 @SYMTestPriority	Normal 
  2361 
  2362 @SYMTestStatus		Implemented 
  2363 
  2364 @SYMTestActions		Creates an instance of CWsScreenDevice (instance of CFbsScreenDevice already prepared for
  2365 					other tests).  Call the pixels to twips and twips to pixels conversion methods on each with same 
  2366 					number.  Compare the resulting output.                       
  2367 @SYMTestExpectedResults Outputs should be within a small tolerance.   
  2368 */ 
  2369 void CTDefect2::PixelsToTwipsConversionCheck() 
  2370 	{ 
  2371 	const TInt 	KHorizontalTestPixels=64000000;
  2372 	const TInt	KVerticalTestPixels=24000000;
  2373 	const TReal32	KTolerance=0.10; // Percent difference permitted
  2374 	TInt cFbsScreenDeviceResult = 1;
  2375 	TInt cWsScreenDeviceResult = 1;
  2376 	TReal32 percentDifference = 0.0;
  2377 	CreateScrDevAndContextL();
  2378 	TBool testResult = EFalse;
  2379 
  2380 	RWsSession wsSession;
  2381 	if (KErrNone == wsSession.Connect())
  2382 		{
  2383 		CWsScreenDevice* wsScrDev = new (ELeave) CWsScreenDevice(wsSession);
  2384 		wsScrDev->Construct(0);
  2385 		
  2386 		// first compare results of the two class's HorizontalPixelsToTwips and pass 
  2387 		// the test if they are within tolerance
  2388 		cFbsScreenDeviceResult = iScrDev->HorizontalPixelsToTwips(KHorizontalTestPixels);
  2389 		cWsScreenDeviceResult = wsScrDev->HorizontalPixelsToTwips(KHorizontalTestPixels);
  2390 		percentDifference = Abs((TReal32)(cFbsScreenDeviceResult - cWsScreenDeviceResult)/cFbsScreenDeviceResult*100.0);
  2391 		testResult = (percentDifference < KTolerance);
  2392 		if ( !testResult )
  2393 			{
  2394 			_LIT(KHorizPixelsToTwipsDesc, "%d horizontal pixels converted to twips by screen device: FBS=%d, WS=%d");
  2395 			WARN_PRINTF4(KHorizPixelsToTwipsDesc, KHorizontalTestPixels, cFbsScreenDeviceResult, cWsScreenDeviceResult);
  2396 			}
  2397 		TEST( testResult );
  2398 		
  2399 		// convert the CWsScreenDevice result back again using each class's HorizontalTwipsToPixels
  2400 		// and pass the test if these results are within tolerance
  2401 		TInt numTwipsToTest = cWsScreenDeviceResult;
  2402 		cFbsScreenDeviceResult = iScrDev->HorizontalTwipsToPixels(numTwipsToTest);
  2403 		cWsScreenDeviceResult = wsScrDev->HorizontalTwipsToPixels(numTwipsToTest);
  2404 		percentDifference = Abs((TReal32)(cFbsScreenDeviceResult - cWsScreenDeviceResult)/cFbsScreenDeviceResult*100.0);
  2405         testResult = (percentDifference < KTolerance);
  2406         if ( !testResult )
  2407 			{
  2408 			_LIT(KHorizTwipsToPixelsDesc, "%d horizontal twips converted to pixels by screen device: FBS=%d, WS=%d");
  2409 			WARN_PRINTF4(KHorizTwipsToPixelsDesc, numTwipsToTest, cFbsScreenDeviceResult, cWsScreenDeviceResult);
  2410             }
  2411         TEST( testResult );
  2412 
  2413 		// next compare results of the two class's VerticalPixelsToTwips and pass the test
  2414 		// if they are within tolerance
  2415 		cFbsScreenDeviceResult = iScrDev->VerticalPixelsToTwips(KVerticalTestPixels);
  2416 		cWsScreenDeviceResult= wsScrDev->VerticalPixelsToTwips(KVerticalTestPixels);
  2417 		percentDifference = Abs((TReal32)(cFbsScreenDeviceResult - cWsScreenDeviceResult)/cFbsScreenDeviceResult*100.0);
  2418         testResult = (percentDifference < KTolerance);
  2419         if ( !testResult )
  2420             {
  2421             _LIT(KVertPixelsToTwipsDesc, "%d vertical pixels converted to twips by screen device: FBS=%d, WS=%d");
  2422             WARN_PRINTF4(KVertPixelsToTwipsDesc, KVerticalTestPixels, cFbsScreenDeviceResult, cWsScreenDeviceResult);
  2423             }
  2424         TEST( testResult );
  2425 		
  2426 		// convert the CWsScreenDevice result back again using each class's VerticalTwipsToPixels
  2427 		// and pass the test if these results are within tolerance
  2428 		numTwipsToTest = cWsScreenDeviceResult;
  2429 		cFbsScreenDeviceResult = iScrDev->VerticalTwipsToPixels(numTwipsToTest);
  2430 		cWsScreenDeviceResult = wsScrDev->VerticalTwipsToPixels(numTwipsToTest);
  2431 		percentDifference = Abs((TReal32)(cFbsScreenDeviceResult - cWsScreenDeviceResult)/cFbsScreenDeviceResult*100.0);
  2432         testResult = (percentDifference < KTolerance);
  2433         if ( !testResult )
  2434             {
  2435             _LIT(KVertTwipsToPixelsDesc, "%d vertical twips converted to pixels by screen device: FBS=%d, WS=%d");
  2436             WARN_PRINTF4(KVertTwipsToPixelsDesc, numTwipsToTest, cFbsScreenDeviceResult, cWsScreenDeviceResult);
  2437             }
  2438         TEST( testResult );
  2439 		
  2440 		delete wsScrDev;
  2441 		wsSession.Close();
  2442 		}
  2443 	else
  2444 		{
  2445 		iStep->SetTestStepResult(EFail);
  2446 		_LIT(KMessage,"ERROR: Test Failed");
  2447 		Logger().LogExtra((TText8*)__FILE__, __LINE__, ESevrErr,KMessage);
  2448 		}
  2449 	}
  2450 
  2451 /**
  2452 @SYMTestCaseID GRAPHICS-BITGDI-0113
  2453 
  2454 @SYMDEF PDEF138111 
  2455 
  2456 @SYMTestCaseDesc Test CFbsBitGc::CopyRect() with non-trivial alpha channel
  2457  
  2458 @SYMTestPriority Normal
  2459 
  2460 @SYMTestStatus Implemented
  2461 
  2462 @SYMTestActions Create a 128 by 128 pixel bitmap with display mode EColor16MA. 
  2463 				Fill the upper half of the bitmap with semi-transparent gray. 
  2464 				Call CFbsBitGc::CopyRect() to copy the upper half to the lower half.
  2465  				Sample one pixel from both the upper and lower half of the bitmap.
  2466 
  2467 @SYMTestExpectedResults The two pixels should be the same. Without the fix the lower part
  2468 						would show a lighter shade of the gray.
  2469 */
  2470 void CTDefect2::CopyRectAlphaL()
  2471 	{
  2472 	TSize size = TSize(128, 128);
  2473 	
  2474 	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
  2475 	CleanupStack::PushL(bitmap);
  2476 	User::LeaveIfError(bitmap->Create(size, EColor16MA));
  2477 	
  2478 	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
  2479 	CleanupStack::PushL(bitmapDevice);	
  2480 	
  2481 	CFbsBitGc* bitmapContext = NULL;
  2482 	User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext));
  2483 	CleanupStack::PushL(bitmapContext);
  2484 	
  2485 	bitmap->BeginDataAccess();
  2486 	Mem::Fill(bitmap->DataAddress(), 128 * 4 * 64, 0x80);
  2487 	bitmap->EndDataAccess();
  2488 	bitmapContext->CopyRect(TPoint(0, 64), TRect(0, 0, 128, 64));
  2489 	
  2490 	//sample a pixel from the lower part of the bitmap and it should be the same as the upper half 
  2491 	TRgb pixelColorUpper;
  2492 	bitmap->GetPixel(pixelColorUpper, TPoint(2, 3));
  2493 	TRgb pixelColorLower;
  2494 	bitmap->GetPixel(pixelColorLower, TPoint(80, 90));
  2495 	TEST(pixelColorUpper == pixelColorLower);
  2496 	
  2497 	CleanupStack::PopAndDestroy(3, bitmap);
  2498 	}
  2499 
  2500 //
  2501 
  2502 class TTestSetBitsThread: public TFunctionThread
  2503 	{
  2504 public:
  2505 	TTestSetBitsThread(TDisplayMode aDisplayMode, TBool aVerticalResize, TBool aScaling);
  2506 private:
  2507 	virtual TInt ThreadFunctionL();
  2508 private:
  2509 	TDisplayMode iDisplayMode;
  2510 	TBool iVerticalResize;
  2511 	TBool iScaling;
  2512 	};
  2513 
  2514 TTestSetBitsThread::TTestSetBitsThread(TDisplayMode aDisplayMode, TBool aVerticalResize, TBool aScaling)
  2515 	: iDisplayMode(aDisplayMode), iVerticalResize(aVerticalResize), iScaling(aScaling)
  2516 	{
  2517 	TBuf<32> threadName;
  2518 	threadName.Format(_L("TestSetBits-%d-%d-%d"), TInt(aDisplayMode), TInt(aVerticalResize), TInt(aScaling));
  2519 	LaunchThreadFunction(threadName);
  2520 	}
  2521 
  2522 TInt TTestSetBitsThread::ThreadFunctionL()
  2523 	{
  2524 	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
  2525 	CleanupStack::PushL(bmp);
  2526 	User::LeaveIfError(bmp->Create(TSize(256, 256), iDisplayMode));
  2527 	CFbsBitmapDevice* bmpDev = CFbsBitmapDevice::NewL(bmp);
  2528 	CleanupStack::PushL(bmpDev);
  2529 	if (iScaling)
  2530 		{
  2531 		User::LeaveIfError(bmpDev->SetScalingFactor(TPoint(0, 0), 2, 2, 1, 1));
  2532 		}
  2533 	if (iVerticalResize)
  2534 		{
  2535 		User::LeaveIfError(bmp->Resize(TSize(256, 128)));
  2536 		}
  2537 	else
  2538 		{
  2539 		User::LeaveIfError(bmp->Resize(TSize(128, 256)));
  2540 		}
  2541 	bmpDev->DrawingBegin();
  2542 	bmpDev->DrawingEnd();
  2543 	CleanupStack::PopAndDestroy(2);
  2544 	return 0;
  2545 	}
  2546 
  2547 /**
  2548 @SYMTestCaseID GRAPHICS-BITGDI-0112
  2549 
  2550 @SYMDEF PDEF138375
  2551 
  2552 @SYMTestCaseDesc Makes sure that CFbsBitmapDevice::SetBits() checks that the bitmap size is consistent.
  2553 
  2554 @SYMTestPriority Normal
  2555 
  2556 @SYMTestStatus Implemented
  2557 
  2558 @SYMTestActions 1. Creates a bitmap and an associated bitmap device.
  2559 				2. Resizes the bitmap directly.
  2560 				3. Calls DrawingBegin()/DrawingEnd() on the bitmap device.
  2561 
  2562 @SYMTestExpectedResults The call to DrawingBegin() should panic in debug builds.
  2563 */
  2564 void CTDefect2::TestSetBitsL()
  2565 	{
  2566 #ifdef _DEBUG
  2567 	for (TBool verticalResize = 0; verticalResize <= 1; ++verticalResize)
  2568 		{
  2569 		for (TBool scaling = 0; scaling <= 1; ++scaling)
  2570 			{
  2571 			TTestSetBitsThread testThread1(EGray2, verticalResize, scaling);
  2572 			TEST(testThread1.iExitHow == TFunctionThread::EPanic);
  2573 			TEST(testThread1.iExitCode == EBitgdiPanicInvalidBitmap);
  2574 
  2575 			TTestSetBitsThread testThread2(EGray4, verticalResize, scaling);
  2576 			TEST(testThread2.iExitHow == TFunctionThread::EPanic);
  2577 			TEST(testThread2.iExitCode == EBitgdiPanicInvalidBitmap);
  2578 
  2579 			TTestSetBitsThread testThread3(EGray16, verticalResize, scaling);
  2580 			TEST(testThread3.iExitHow == TFunctionThread::EPanic);
  2581 			TEST(testThread3.iExitCode == EBitgdiPanicInvalidBitmap);
  2582 
  2583 			TTestSetBitsThread testThread4(EColor16, verticalResize, scaling);
  2584 			TEST(testThread4.iExitHow == TFunctionThread::EPanic);
  2585 			TEST(testThread4.iExitCode == EBitgdiPanicInvalidBitmap);
  2586 
  2587 			TTestSetBitsThread testThread5(EGray256, verticalResize, scaling);
  2588 			TEST(testThread5.iExitHow == TFunctionThread::EPanic);
  2589 			TEST(testThread5.iExitCode == EBitgdiPanicInvalidBitmap);
  2590 
  2591 			TTestSetBitsThread testThread6(EColor256, verticalResize, scaling);
  2592 			TEST(testThread6.iExitHow == TFunctionThread::EPanic);
  2593 			TEST(testThread6.iExitCode == EBitgdiPanicInvalidBitmap);
  2594 
  2595 			TTestSetBitsThread testThread7(EColor4K, verticalResize, scaling);
  2596 			TEST(testThread7.iExitHow == TFunctionThread::EPanic);
  2597 			TEST(testThread7.iExitCode == EBitgdiPanicInvalidBitmap);
  2598 
  2599 			TTestSetBitsThread testThread8(EColor64K, verticalResize, scaling);
  2600 			TEST(testThread8.iExitHow == TFunctionThread::EPanic);
  2601 			TEST(testThread8.iExitCode == EBitgdiPanicInvalidBitmap);
  2602 
  2603 			TTestSetBitsThread testThread9(EColor16M, verticalResize, scaling);
  2604 			TEST(testThread9.iExitHow == TFunctionThread::EPanic);
  2605 			TEST(testThread9.iExitCode == EBitgdiPanicInvalidBitmap);
  2606 
  2607 			TTestSetBitsThread testThread10(EColor16MU, verticalResize, scaling);
  2608 			TEST(testThread10.iExitHow == TFunctionThread::EPanic);
  2609 			TEST(testThread10.iExitCode == EBitgdiPanicInvalidBitmap);
  2610 
  2611 			TTestSetBitsThread testThread11(EColor16MA, verticalResize, scaling);
  2612 			TEST(testThread11.iExitHow == TFunctionThread::EPanic);
  2613 			TEST(testThread11.iExitCode == EBitgdiPanicInvalidBitmap);
  2614 
  2615 			TTestSetBitsThread testThread12(EColor16MAP, verticalResize, scaling);
  2616 			TEST(testThread12.iExitHow == TFunctionThread::EPanic);
  2617 			TEST(testThread12.iExitCode == EBitgdiPanicInvalidBitmap);
  2618 			}
  2619 		}
  2620 #else
  2621 	WARN_PRINTF1(_L("Test skipped because it needs udeb build"));
  2622 #endif
  2623 	}
  2624 
  2625 //--------------
  2626 __CONSTRUCT_STEP__(Defect2)
  2627 
  2628 void CTDefect2Step::TestSetupL()
  2629 	{
  2630 	}
  2631 	
  2632 void CTDefect2Step::TestClose()
  2633 	{
  2634 	::DeleteDataFile(KArchiveFileName);
  2635 	}