os/graphics/graphicsdeviceinterface/bitgdi/tbit/TAUTO.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 
    17 #include <hal.h>
    18 #include <e32test.h>
    19 #include <bitdraw.h>
    20 #include <graphics/gdi/gdiconsts.h>
    21 #include "TAUTO.H"
    22 #include <graphics/fbsdefs.h>
    23 
    24 
    25 TInt PanicTestThread(TAny* aOption);
    26 
    27 enum TPanicOption
    28 	{
    29 	EFirst,
    30 	EPolygonFiller,
    31 	EBitmapDevice,
    32 	EDrawBmp1,
    33 	EDrawBmp2,
    34 	EDrawBmp3,
    35 	EGcDevice1,
    36 	EGcDevice2,
    37 	EGcRegion1,
    38 	EGcRegion2,
    39 	EUseBrush1,
    40 	EUseBrush2,
    41 	EUseBrush3,
    42 	EUseFont,
    43 	EDrawText1,
    44 	EDrawText2,
    45 	EDrawText3,
    46 	ELast
    47 	};
    48 
    49 
    50 CTAuto::CTAuto(CTestStep* aStep):
    51 	CTGraphicsBase(aStep),
    52 	iScreenDevice(NULL),
    53 	iHalfScreen()
    54 	{
    55 	iTestRect[0].SetRect(21,10,22,50);
    56 	iTestRect[1].SetRect(10,21,50,22);
    57 	iTestRect[2].SetRect(11,20,90,30);
    58 	iTestRect[3].SetRect(10,71,90,80);
    59 	iTestRect[4].SetRect(20,10,31,90);
    60 	iTestRect[5].SetRect(70,10,80,91);
    61 	iTestRect[6].SetRect(10,10,90,90);
    62 	iTestRect[7].SetRect(32,32,96,96);
    63 
    64 	INFO_PRINTF1(_L(" "));
    65 	}
    66 	
    67 CTAuto::~CTAuto()
    68 	{
    69 	
    70 	}
    71 
    72 void CTAuto::RunTestCaseL(const TInt aCurTestCase)
    73 	{
    74 	((CTAutoStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    75 	switch(aCurTestCase)
    76 		{
    77 	case 1:
    78 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
    79 		TestMem(EGray2);
    80 		break;
    81 	case 2:
    82 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
    83 		TestMem(EGray4);
    84 		break;
    85 	case 3:
    86 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
    87 		TestMem(EGray16);
    88 		break;
    89 	case 4:
    90 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
    91 		TestMem(EGray256);
    92 		break;
    93 	case 5:
    94 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
    95 		TestMem(EColor16);
    96 		break;
    97 	case 6:
    98 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
    99 		TestMem(EColor256);
   100 		break;
   101 	case 7:
   102 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
   103 		TestMem(EColor4K);
   104 		break;
   105 	case 8:
   106 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
   107 		TestMem(EColor64K);
   108 		break;
   109 	case 9:
   110 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
   111 		TestMem(EColor16M);
   112 		break;
   113 	case 10:
   114 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
   115 		TestMem(EColor16MU);
   116 		break;
   117 	case 11:
   118 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   119 		TestMapL(EGray2,15);
   120 		break;
   121 	case 12:
   122 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   123 		TestMapL(EGray4,5);
   124 		break;
   125 	case 13:
   126 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   127 		TestMapL(EGray16,5);
   128 		break;
   129 	case 14:
   130 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   131 		TestMapL(EGray256,5);
   132 		break;
   133 	case 15:
   134 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   135 		TestMapL(EColor16,5);
   136 		break;
   137 	case 16:
   138 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   139 		TestMapL(EColor256,3);
   140 		break;
   141 	case 17:
   142 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   143 		TestMapL(EColor4K,5);
   144 		break;
   145 	case 18:
   146 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   147 		TestMapL(EColor64K,4);
   148 		break;
   149 	case 19:
   150 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   151 		TestMapL(EColor16M,4);
   152 		break;
   153 	case 20:
   154 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   155 		TestMapL(EColor16MU,4);
   156 		break;
   157 	case 21:
   158 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   159 		TestBmpL(EGray2);
   160 		break;
   161 	case 22:
   162 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   163 		TestBmpL(EGray4);
   164 		break;
   165 	case 23:
   166 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   167 		TestBmpL(EGray16);
   168 		break;
   169 	case 24:
   170 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   171 		TestBmpL(EGray256);
   172 		break;
   173 	case 25:
   174 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   175 		TestBmpL(EColor16);
   176 		break;
   177 	case 26:
   178 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   179 		TestBmpL(EColor256);
   180 		break;
   181 	case 27:
   182 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   183 		TestBmpL(EColor4K);
   184 		break;
   185 	case 28:
   186 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   187 		TestBmpL(EColor64K);
   188 		break;
   189 	case 29:
   190 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   191 		TestBmpL(EColor16M);
   192 		break;
   193 	case 30:
   194 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   195 		TestBmpL(EColor16MU);
   196 		break;
   197 	case 31:		
   198 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   199 		TestBmpL(EColor16MA);
   200 		break;
   201 	case 32:
   202 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
   203 		TestMem(EColor16MA);
   204 		break;
   205 	case 33:
   206 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   207 		TestMapL(EColor16MA,4);
   208 		break;
   209 	case 34:
   210 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0027"));
   211 		TestBmpL(EColor16MAP);
   212 		break;
   213 	case 35:
   214 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0025"));
   215 		TestMem(EColor16MAP);
   216 		break;
   217 	case 36:
   218 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0026"));
   219 		TestMapL(EColor16MAP,4);
   220 		break;
   221 	case 37:
   222 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0029"));
   223 		TestFadingL();
   224 		INFO_PRINTF2(_L("TestCase %d - Passed Fading Test\r\n"),aCurTestCase);		
   225 		break;
   226 	case 38:
   227 		((CTAutoStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0028"));
   228 		TestPanics();
   229 		break;
   230 	case 39: //exit 
   231 		((CTAutoStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   232 		((CTAutoStep*)iStep)->CloseTMSGraphicsStep();
   233 		TestComplete();
   234 		break;		
   235 		}
   236 	((CTAutoStep*)iStep)->RecordTestResultL();
   237 	}
   238 
   239 
   240 /**
   241   @SYMTestCaseID GRAPHICS-BITGDI-0025
   242  
   243   @SYMDEF             
   244 
   245   @SYMTestCaseDesc Tests the memory allocation cleanup after allocations fails 
   246    
   247   @SYMTestPriority High
   248 
   249   @SYMTestStatus Implemented
   250 
   251   @SYMTestActions sets memory allocation to fail then checks it is cleaned up correctly
   252  
   253   @SYMTestExpectedResults Memory should be successfully cleaned up
   254 */
   255 void CTAuto::TestMem(TDisplayMode aDispMode)
   256 	{
   257 	LowLevelDevice(aDispMode,EFalse);
   258 	BitmapDevice(aDispMode);
   259 	LowLevelDevice(aDispMode,ETrue);
   260 	ScreenDevice(aDispMode);
   261 
   262 	INFO_PRINTF2(_L("Mode %d passed memory test\r\n"),aDispMode);
   263 	}
   264 
   265 void CTAuto::ScreenDevice(TDisplayMode aDispMode)
   266 	{
   267 	CFbsScreenDevice* device = NULL;
   268 	for (TInt count = 1; ; count++)
   269 		{
   270 		__UHEAP_SETFAIL(RHeap::EDeterministic,count);
   271 		__UHEAP_MARK;
   272 		TRAPD(err,device = CFbsScreenDevice::NewL(_L("scdv"),aDispMode));
   273 		if (err == KErrNotSupported)
   274 			{
   275 			__UHEAP_MARKEND;
   276 			break;
   277 			}
   278 		else if(err == KErrNoMemory)
   279 			{
   280 			__UHEAP_MARKEND;
   281 			}
   282 		else if (err == KErrNone)
   283 			{
   284 			delete device;
   285 			__UHEAP_MARKEND;
   286 			break;
   287 			}
   288 		else
   289 			{
   290 			__UHEAP_MARKEND;
   291 			User::Panic(_L("CFbsScreenDevice test failed "),err);
   292 			}
   293 		}
   294 
   295 	__UHEAP_RESET;
   296 	}
   297 
   298 void CTAuto::BitmapDevice(TDisplayMode aDispMode)
   299 	{
   300 	CFbsBitmap bmp;
   301 	TInt ret = bmp.Create(TSize(1,1),aDispMode);
   302 	if (ret != KErrNone)
   303 		User::Panic(_L("Failed to create bitmap"),ret);
   304 
   305 	CFbsBitmapDevice* device = NULL;
   306 	for (TInt count = 1; ; count++)
   307 		{
   308 		__UHEAP_SETFAIL(RHeap::EDeterministic,count);
   309 		__UHEAP_MARK;
   310 		TRAPD(err,device = CFbsBitmapDevice::NewL(&bmp));
   311 		if(err == KErrNotSupported)
   312 			{
   313 			__UHEAP_MARKEND;
   314 			break;
   315 			}
   316 		else if(err == KErrNoMemory)
   317 			{
   318 			__UHEAP_MARKEND;
   319 			}
   320 		else if (err == KErrNone)
   321 			{
   322 			delete device;
   323 			__UHEAP_MARKEND;
   324 			break;
   325 			}
   326 		else
   327 			{
   328 			__UHEAP_MARKEND;
   329 			User::Panic(_L("CFbsBitmapDevice test failed "),err);
   330 			}
   331 		}
   332 
   333 	__UHEAP_RESET;
   334 	}
   335 
   336 void CTAuto::LowLevelDevice(TDisplayMode aDispMode,TBool aScreen)
   337 	{
   338 	TInt address = NULL;
   339 	TSize size(0,0);
   340 	TInt ret = HAL::Get(KDefaultScreenNo, HALData::EDisplayMemoryAddress,address);
   341 	if (ret == KErrNone)
   342 		ret = HAL::Get(KDefaultScreenNo, HALData::EDisplayXPixels,size.iWidth);
   343 	if (ret == KErrNone)
   344 		ret = HAL::Get(KDefaultScreenNo, HALData::EDisplayYPixels,size.iHeight);
   345 	if (ret != KErrNone)
   346 		User::Panic(_L("CFbsDrawDevice test failed "),ret);
   347 
   348 	TPckgBuf<TScreenInfoV01> s;
   349 	s().iScreenAddressValid = ETrue;
   350 	s().iScreenAddress = REINTERPRET_CAST(TAny*,address);
   351 	s().iScreenSize = size;
   352 
   353 	CFbsDrawDevice* fdd = NULL;
   354 
   355 	for(TInt count = 1; ; count++)
   356 		{
   357 		__UHEAP_SETFAIL(RHeap::EDeterministic,count);
   358 		__UHEAP_MARK;
   359 
   360 		if (aScreen)
   361 			{
   362 			TRAP(ret,fdd = CFbsDrawDevice::NewScreenDeviceL(s(),aDispMode));
   363 			}
   364 		else
   365 			{
   366 			TRAP(ret, fdd = CFbsDrawDevice::NewBitmapDeviceL(s(), aDispMode, CFbsBitmap::ScanLineLength(size.iWidth, aDispMode)));
   367 			}
   368 
   369 		if (ret == KErrNotSupported)
   370 			{
   371 			__UHEAP_MARKEND;
   372 			break;
   373 			}
   374 		else if (ret == KErrNoMemory)
   375 			{
   376 			__UHEAP_MARKEND;
   377 			}
   378 		else if (ret == KErrNone)
   379 			{
   380 			delete fdd;
   381 			__UHEAP_MARKEND;
   382 			break;
   383 			}
   384 		else
   385 			{
   386 			__UHEAP_MARKEND;
   387 			User::Panic(_L("CFbsDrawDevice test failed "),ret);
   388 			}
   389 		}
   390 
   391 	__UHEAP_RESET;
   392 	}
   393 
   394 
   395 /**
   396   @SYMTestCaseID GRAPHICS-BITGDI-0026
   397  
   398   @SYMDEF             
   399 
   400   @SYMTestCaseDesc Colour mapping testing
   401    
   402   @SYMTestPriority High
   403 
   404   @SYMTestStatus Implemented
   405 
   406   @SYMTestActions attempts to map four shades of grey to greys in a colourmap
   407  
   408   @SYMTestExpectedResults All pixels should map to the colourmap correctly
   409 */
   410 //
   411 // 
   412 //
   413 void CTAuto::TestMapL(TDisplayMode aDispMode,TInt aShadowFactor)
   414 	{
   415 	TRAPD(err,iScreenDevice = CFbsScreenDevice::NewL(_L("scdv"),aDispMode));
   416 	if (err == KErrNotSupported)
   417 		return;
   418 	User::LeaveIfError(err);
   419 
   420 	User::LeaveIfError(iScreenDevice->CreateContext(iScreenGc));
   421 	iScreenDevice->ChangeScreenDevice(NULL);
   422 
   423 	TestMapColors();
   424 	TestShadowArea(aShadowFactor);
   425 	TestFadeArea();
   426 
   427 	delete iScreenGc;
   428 	delete iScreenDevice;
   429 
   430 	INFO_PRINTF2(_L("Mode %d passed colour map test\r\n"),aDispMode);
   431 	}
   432 
   433 void CTAuto::TestMapColors()
   434 	{
   435 	TRgb colormap[4];
   436 	TRgb screencolor;
   437 	TInt x,y;
   438 
   439 	for (TInt count = 0; count < KNumRects; count++)
   440 		{
   441 		for (TInt color = 0; color < 4 && iScreenDevice->DisplayMode() != EGray2; color++)
   442 			{
   443 			Clear(TRgb::Gray4(color));
   444 			TRect r(iTestRect[count]);
   445 			colormap[0] = TRgb::Gray4(color);
   446 			colormap[1] = TRgb::Gray4(3-color);
   447 			colormap[2] = colormap[1];
   448 			colormap[3] = colormap[0];
   449 			if (iScreenDevice->DisplayMode() == EColor64K)
   450 				{
   451 				colormap[0] = TRgb::Color64K(colormap[0].Color64K());
   452 				colormap[1] = TRgb::Color64K(colormap[1].Color64K());
   453 				colormap[2] = colormap[1];
   454 				colormap[3] = colormap[0];
   455 				}
   456 			iScreenGc->MapColors(r,colormap,2);
   457 
   458 			for(y=0;y<r.iTl.iY;y++)
   459 				for(x=0;x<100;x++)
   460 					{
   461 					iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   462 					TEST(screencolor.Gray4() == color);
   463 					}
   464 			for(y=r.iTl.iY;y<r.iBr.iY;y++)
   465 				for(x=0;x<r.iTl.iX;x++)
   466 					{
   467 					iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   468 					TEST(screencolor.Gray4() == color);
   469 					}
   470 			for(y=r.iTl.iY;y<r.iBr.iY;y++)
   471 				for(x=r.iBr.iX;x<100;x++)
   472 					{
   473 					iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   474 					TEST(screencolor.Gray4() == color);
   475 					}
   476 			for(y=r.iBr.iY;y<100;y++)
   477 				for(x=0;x<100;x++)
   478 					{
   479 					iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   480 					TEST(screencolor.Gray4() == color);
   481 					}
   482 			for(y=r.iTl.iY;y<r.iBr.iY;y++)
   483 				for(x=r.iTl.iX;x<r.iBr.iX;x++)
   484 					{
   485 					iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   486 					TEST(screencolor.Gray4() == 3-color);
   487 					}
   488 			iScreenGc->MapColors(r,colormap,2);
   489 			for(y=r.iTl.iY;y<r.iBr.iY;y++)
   490 				for(x=r.iTl.iX;x<r.iBr.iX;x++)
   491 					{
   492 					iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   493 					TEST(screencolor.Gray4() == color);
   494 					}
   495 			}
   496 		}
   497 	}
   498 
   499 void CTAuto::TestShadowArea(TInt aShadowFactor)
   500 	{
   501 	TRgb screencolor;
   502 	TInt x,y;
   503 
   504 	for (TInt count = 0; count < KNumRects; count++)
   505 		{
   506 		for (TInt color = 0; color < 4; color++)
   507 			{
   508 			if (color > 0 && iScreenDevice->DisplayMode() == EGray2)
   509 				color = 3;
   510 
   511 			Clear(TRgb::Gray4(color));
   512 			TRect r(iTestRect[count]);
   513 			TRegionFix<1> reg(r);
   514 
   515 			iScreenGc->ShadowArea(&reg);
   516 
   517 			for(y=0;y<r.iTl.iY;y++)
   518 				for(x=0;x<100;x++)
   519 					{
   520 					iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   521 					TEST(screencolor.Gray4() == color);
   522 					}
   523 
   524 			for(y=r.iTl.iY;y<r.iBr.iY;y++)
   525 				for(x=0;x<r.iTl.iX;x++)
   526 					{
   527 					iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   528 					TEST(screencolor.Gray4() == color);
   529 					}
   530 
   531 			for(y=r.iTl.iY;y<r.iBr.iY;y++)
   532 				for(x=r.iBr.iX;x<100;x++)
   533 					{
   534 					iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   535 					TEST(screencolor.Gray4() == color);
   536 					}
   537 
   538 			for(y=r.iBr.iY;y<100;y++)
   539 				for(x=0;x<100;x++)
   540 					{
   541 					iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   542 					TEST(screencolor.Gray4() == color);
   543 					}
   544 
   545 			for(y=r.iTl.iY;y<r.iBr.iY;y++)
   546 				for(x=r.iTl.iX;x<r.iBr.iX;x++)
   547 					{
   548 					iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   549 					TEST(screencolor.Gray16() == Max(0,color * 5 - aShadowFactor));
   550 					}
   551 			}
   552 		}
   553 	}
   554 
   555 void CTAuto::TestFadeArea()
   556 	{
   557 	DoTestFadeArea(0,255);
   558 	DoTestFadeArea(0,127);
   559 	DoTestFadeArea(128,255);
   560 	DoTestFadeArea(64,192);
   561 	}
   562 
   563 void CTAuto::DoTestFadeArea(TUint8 aBlackMap,TUint8 aWhiteMap)
   564 	{
   565 	iScreenGc->SetFadingParameters(aBlackMap,aWhiteMap);
   566 
   567 	DoTestFadeArea(KRgbWhite,FadeColor(KRgbWhite,aBlackMap,aWhiteMap));
   568 	DoTestFadeArea(KRgbBlack,FadeColor(KRgbBlack,aBlackMap,aWhiteMap));
   569 
   570 	if (iScreenDevice->DisplayMode() == EGray2)
   571 		return; // EGray2 mode dithers so only check black & white
   572 
   573 	DoTestFadeArea(KRgbGray,FadeColor(KRgbGray,aBlackMap,aWhiteMap));
   574 	DoTestFadeArea(KRgbDarkGray,FadeColor(KRgbDarkGray,aBlackMap,aWhiteMap));
   575 
   576 	if (iScreenDevice->DisplayMode() == EGray4)
   577 		return; // EGray4 mode dithers so only check four gray scales
   578 
   579 	DoTestFadeArea(KRgbRed,FadeColor(KRgbRed,aBlackMap,aWhiteMap));
   580 	DoTestFadeArea(KRgbGreen,FadeColor(KRgbGreen,aBlackMap,aWhiteMap));
   581 	DoTestFadeArea(KRgbBlue,FadeColor(KRgbBlue,aBlackMap,aWhiteMap));
   582 	}
   583 
   584 void CTAuto::DoTestFadeArea(TRgb aColor,TRgb aFadedColor)
   585 	{
   586 	TRgb screencolor;
   587 	TInt x,y;
   588 
   589 	for (TInt count = 0; count < KNumRects; count++)
   590 		{
   591 		Clear(aColor);
   592 		aColor = MapColorToDisplayMode(aColor);
   593 
   594 		TRect r(iTestRect[count]);
   595 		TRegionFix<1> reg(r);
   596 
   597 		iScreenGc->FadeArea(&reg);
   598 
   599 		for(y=0;y<r.iTl.iY;y++)
   600 			for(x=0;x<100;x++)
   601 				{
   602 				iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   603 				TEST(screencolor == aColor);
   604 				}
   605 
   606 		for(y=r.iTl.iY;y<r.iBr.iY;y++)
   607 			for(x=0;x<r.iTl.iX;x++)
   608 				{
   609 				iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   610 				TEST(screencolor == aColor);
   611 				}
   612 
   613 		for(y=r.iTl.iY;y<r.iBr.iY;y++)
   614 			for(x=r.iBr.iX;x<100;x++)
   615 				{
   616 				iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   617 				TEST(screencolor == aColor);
   618 				}
   619 
   620 		for(y=r.iBr.iY;y<100;y++)
   621 			for(x=0;x<100;x++)
   622 				{
   623 				iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   624 				TEST(screencolor == aColor);
   625 				}
   626 
   627 		for(y=r.iTl.iY;y<r.iBr.iY;y++)
   628 			for(x=r.iTl.iX;x<r.iBr.iX;x++)
   629 				{
   630 				iScreenDevice->GetPixel(screencolor,TPoint(x,y));
   631 				TEST(screencolor == aFadedColor);
   632 				}
   633 		}
   634 	}
   635 
   636 TRgb CTAuto::FadeColor(TRgb aColor,TInt aBlackMap,TInt aWhiteMap)
   637 	{
   638 	aColor = MapColorToDisplayMode(aColor);
   639 
   640 	TInt red = ((aColor.Red() * (aWhiteMap - aBlackMap + 1)) >> 8) + aBlackMap;
   641 	TInt green = ((aColor.Green() * (aWhiteMap - aBlackMap + 1)) >> 8) + aBlackMap;
   642 	TInt blue = ((aColor.Blue() * (aWhiteMap - aBlackMap + 1)) >> 8) + aBlackMap;
   643 
   644 	aColor = TRgb(red,green,blue);
   645 
   646 	aColor = MapColorToDisplayMode(aColor);
   647 
   648 	return aColor;
   649 	}
   650 
   651 TRgb CTAuto::MapColorToDisplayMode(TRgb aColor)
   652 	{
   653 	switch (iScreenDevice->DisplayMode())
   654 		{
   655 	case EGray2:
   656 		aColor = TRgb::Gray2(aColor.Gray2());
   657 		break;
   658 	case EGray4:
   659 		aColor = TRgb::Gray4(aColor.Gray4());
   660 		break;
   661 	case EGray16:
   662 		aColor = TRgb::Gray16(aColor.Gray16());
   663 		break;
   664 	case EGray256:
   665 		aColor = TRgb::Gray256(aColor.Gray256());
   666 		break;
   667 	case EColor16:
   668 		aColor = TRgb::Color16(aColor.Color16());
   669 		break;
   670 	case EColor256:
   671 		aColor = TRgb::Color256(aColor.Color256());
   672 		break;
   673 	case EColor4K:
   674 		aColor = TRgb::Color4K(aColor.Color4K());
   675 		break;
   676 	case EColor64K:
   677 		aColor = TRgb::Color64K(aColor.Color64K());
   678 		break;
   679 	case EColor16M:
   680 		aColor = TRgb::Color16M(aColor.Color16M());
   681 		break;
   682 	case EColor16MU:
   683 		aColor = TRgb::Color16MU(aColor.Color16MU());
   684 		break;
   685 	case EColor16MA:
   686 		aColor = TRgb::Color16MA(aColor.Color16MA());
   687 		break;
   688 	case EColor16MAP:
   689 		aColor = TRgb::Color16MAP(aColor.Color16MAP());
   690 		break;
   691 	default:
   692 		User::Invariant();
   693 		break;
   694 		}
   695 
   696 	return aColor;
   697 	}
   698 
   699 void CTAuto::Clear(TRgb aColor)
   700 	{
   701 	iScreenGc->SetBrushColor(aColor);
   702 	iScreenGc->Clear();
   703 	}
   704 
   705 
   706 /**
   707   @SYMTestCaseID GRAPHICS-BITGDI-0027
   708  
   709   @SYMDEF             
   710 
   711   @SYMTestCaseDesc tests drawing a bitmap to the screen in various colour modes
   712    
   713   @SYMTestPriority High
   714 
   715   @SYMTestStatus Implemented
   716 
   717   @SYMTestActions draws to a bitmaps gc and the screens gc then compares the result on a per pixel basis
   718  
   719   @SYMTestExpectedResults bitmap and screen should be identical
   720 */
   721 //
   722 // Bitmap drawing testing
   723 //
   724 void CTAuto::TestBmpL(TDisplayMode aDispMode)
   725 	{
   726 	TRAPD(err,iScreenDevice = CFbsScreenDevice::NewL(_L("scdv"),aDispMode));
   727 	if (err == KErrNotSupported)
   728 		return;
   729 	User::LeaveIfError(err);
   730 	iScreenDevice->ChangeScreenDevice(NULL);
   731 	User::LeaveIfError(iScreenDevice->CreateContext((CGraphicsContext*&)iScreenGc));
   732 
   733 	iHalfScreen = iScreenDevice->SizeInPixels();
   734 	iHalfScreen.iWidth /= 2;
   735 
   736 	CFbsBitmap bitmap;
   737 	User::LeaveIfError(bitmap.Create(iHalfScreen,aDispMode));
   738 
   739 	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(&bitmap);
   740 	CleanupStack::PushL(bitmapDevice);
   741 	CFbsBitGc* bitmapGc = NULL;
   742 	User::LeaveIfError(bitmapDevice->CreateContext(bitmapGc));
   743 	CleanupStack::PushL(bitmapGc);
   744 
   745 	TestGc(iScreenGc,iHalfScreen);
   746 	TestGc(bitmapGc,iHalfScreen);
   747 
   748 	iScreenGc->BitBlt(TPoint(iHalfScreen.iWidth,0),&bitmap);
   749 
   750 	TRgb* left = new(ELeave) TRgb[iHalfScreen.iWidth];
   751 	TRgb* right = new(ELeave) TRgb[iHalfScreen.iWidth];
   752 
   753 	TPtr8 leftBuf(REINTERPRET_CAST(TUint8*,left),iHalfScreen.iWidth * sizeof(TRgb),iHalfScreen.iWidth * sizeof(TRgb));
   754 	TPtr8 rightBuf(REINTERPRET_CAST(TUint8*,right),iHalfScreen.iWidth * sizeof(TRgb),iHalfScreen.iWidth * sizeof(TRgb));
   755 
   756 	for (TInt row = 0; row < iHalfScreen.iHeight; row++)
   757 		{
   758 		iScreenDevice->GetScanLine(leftBuf,TPoint(0,row),iHalfScreen.iWidth,ERgb);
   759 		bitmap.GetScanLine(rightBuf,TPoint(iHalfScreen.iWidth,row),iHalfScreen.iWidth,ERgb);
   760 
   761 		TRgb* leftPtr = left;
   762 		TRgb* rightPtr = right;
   763 
   764 		for (TInt col = 0; col < iHalfScreen.iWidth; col++)
   765 			{
   766 			if (leftPtr[0] != rightPtr[0])
   767 				User::Panic(_L("Screen/bitmap mismatch!"),KErrGeneral);
   768 
   769 			leftPtr++;
   770 			rightPtr++;
   771 			}
   772 		}
   773 
   774 	delete[] left;
   775 	delete[] right;
   776 	CleanupStack::PopAndDestroy(2); // bitmapGc,bitmapDevice
   777 	delete iScreenGc;
   778 	delete iScreenDevice;
   779 
   780 	iScreenDevice = NULL;
   781 	iScreenGc = NULL;
   782 
   783 	bitmap.Reset();
   784 
   785 	INFO_PRINTF2(_L("Mode %d passed bitmap drawing test\r\n"),aDispMode);
   786 	}
   787 
   788 void CTAuto::TestGc(CFbsBitGc* aGc,const TSize& aSize)
   789 	{
   790 	aGc->SetPenStyle(CGraphicsContext::ENullPen);
   791 	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   792 	aGc->SetBrushColor(KRgbBlack);
   793 	aGc->DrawRect(TRect(TPoint(),iScreenDevice->SizeInPixels()));
   794 	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
   795 	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   796 
   797 	Colors(aGc,aSize);
   798 	Shapes(aGc,aSize);
   799 	}
   800 
   801 void CTAuto::Colors(CFbsBitGc* aGc,const TSize& aSize)
   802 	{
   803 	TInt i=0;
   804 	TInt w=aSize.iWidth;
   805 	TInt h=aSize.iHeight;
   806 	TInt xinc = w / 16;
   807 	TInt lx = 0;
   808 	TInt rx = xinc - 1;
   809 
   810 	for(i=0;i<256;i++)
   811 		{
   812 		aGc->SetPenColor(TRgb::Gray256(i));
   813 		aGc->SetBrushColor(TRgb::Gray256(i));
   814 		aGc->DrawRect(TRect(lx,i*h/256,rx,(i+1)*h/256));
   815 		}
   816 	lx += xinc;
   817 	rx += xinc;
   818 	for(i=0;i<16;i++)
   819 		{
   820 		aGc->SetPenColor(TRgb::Gray16(i));
   821 		aGc->SetBrushColor(TRgb::Gray16(i));
   822 		aGc->DrawRect(TRect(lx,i*h/16,rx,(i+1)*h/16));
   823 		}
   824 	lx += xinc;
   825 	rx += xinc;
   826 	for(i=0;i<4;i++)
   827 		{
   828 		aGc->SetPenColor(TRgb::Gray4(i));
   829 		aGc->SetBrushColor(TRgb::Gray4(i));
   830 		aGc->DrawRect(TRect(lx,i*h/4,rx,(i+1)*h/4));
   831 		}
   832 	lx += xinc;
   833 	rx += xinc;
   834 	for(i=0;i<256;i++)
   835 		{
   836 		aGc->SetPenColor(TRgb(i,0,0));
   837 		aGc->SetBrushColor(TRgb(i,0,0));
   838 		aGc->DrawRect(TRect(lx,i*h/256,rx,(i+1)*h/256));
   839 		}
   840 	lx += xinc;
   841 	rx += xinc;
   842 	for(i=0;i<256;i++)
   843 		{
   844 		aGc->SetPenColor(TRgb(0,i,0));
   845 		aGc->SetBrushColor(TRgb(0,i,0));
   846 		aGc->DrawRect(TRect(lx,i*h/256,rx,(i+1)*h/256));
   847 		}
   848 	lx += xinc;
   849 	rx += xinc;
   850 	for(i=0;i<256;i++)
   851 		{
   852 		aGc->SetPenColor(TRgb(0,0,i));
   853 		aGc->SetBrushColor(TRgb(0,0,i));
   854 		aGc->DrawRect(TRect(lx,i*h/256,rx,(i+1)*h/256));
   855 		}
   856 	lx += xinc;
   857 	rx += xinc;
   858 	for(i=0;i<256;i++)
   859 		{
   860 		aGc->SetPenColor(TRgb::Color256(i));
   861 		aGc->SetBrushColor(TRgb::Color256(i));
   862 		aGc->DrawRect(TRect(lx,i*h/256,rx,(i+1)*h/256));
   863 		}
   864 	lx += xinc;
   865 	rx += xinc;
   866 	for(i=0;i<16;i++)
   867 		{
   868 		aGc->SetPenColor(TRgb::Color16(i));
   869 		aGc->SetBrushColor(TRgb::Color16(i));
   870 		aGc->DrawRect(TRect(lx,i*h/16,rx,(i+1)*h/16));
   871 		}
   872 
   873 	}
   874 
   875 void CTAuto::Shapes(CFbsBitGc* aGc,const TSize& aSize)
   876 	{
   877 	aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
   878 	aGc->SetPenColor(KRgbWhite);
   879 
   880 	TInt w=aSize.iWidth;
   881 	TInt h=aSize.iHeight;
   882 
   883 	CArrayFixFlat<TPoint>* poly=new(ELeave) CArrayFixFlat<TPoint>(4);
   884 	TInt a=w>>1;
   885 	TInt b=a+(a>>1);
   886 	TPoint temppt(w*5/8,h/48);
   887 	poly->AppendL(temppt);
   888 	temppt.SetXY(b-1,h*11/48);
   889 	poly->AppendL(temppt);
   890 	temppt.SetXY(a+1,h*11/48);
   891 	poly->AppendL(temppt);
   892 	temppt.SetXY(w*5/8,h/48);
   893 	poly->AppendL(temppt);
   894 	aGc->DrawPolyLine(poly);
   895 	delete poly;
   896 
   897 	aGc->DrawRect(TRect(a+1,h*7/24,b,h*12/24));
   898 	aGc->DrawRoundRect(TRect(a+1,h*13/24,b,h*18/24),TSize(w/16,h/12));
   899 	aGc->DrawEllipse(TRect(a+1,h*19/24,b,h*24/24));
   900 	aGc->DrawArc(TRect(b+1,h*1/24,w-1,h*6/24),TPoint(w*15/16,h*6/24),TPoint(w*13/16,h*6/24));
   901 	aGc->DrawPie(TRect(b+1,h*7/24,w-1,h*12/24),TPoint(w*13/16,h*7/24),TPoint(w*15/16,h*7/24));
   902 	aGc->DrawEllipse(TRect(b+1,h*13/24,w-1,h*18/24));
   903 	aGc->DrawEllipse(TRect(b+1,h*20/24,w-1,h*23/24));
   904 	}
   905 
   906 
   907 /**
   908   @SYMTestCaseID GRAPHICS-BITGDI-0028
   909  
   910   @SYMDEF             
   911 
   912   @SYMTestCaseDesc Tests various graphic panics 
   913    
   914   @SYMTestPriority High
   915 
   916   @SYMTestStatus Implemented
   917 
   918   @SYMTestActions Starts a thread that causes various graphic panics depending on the chosen option
   919  
   920   @SYMTestExpectedResults The thread should panic each time for each chosen option
   921 */
   922 void CTAuto::TestPanics()
   923 	{
   924 	for (TInt opt = EFirst + 1; opt < ELast; opt++)
   925 		{
   926 		StartThread(opt);
   927 		INFO_PRINTF2(_L("Panic test %d passed\r\n"),opt);
   928 		}
   929 	}
   930 
   931 void CTAuto::StartThread(TInt aOption)
   932 	{
   933 	RThread thrd;
   934 	TRequestStatus stat;
   935 	TBuf<256> threadNameBuf;
   936 	_LIT(KThreadNameFormat, "ptt%d");
   937 	threadNameBuf.Format(KThreadNameFormat, aOption);
   938 	TInt threadCreationVal = thrd.Create(threadNameBuf,PanicTestThread,KDefaultStackSize,0x2000,0x20000,(TAny*)aOption);
   939 	TEST(threadCreationVal==KErrNone);	
   940 	thrd.SetPriority(EPriorityMuchMore);
   941 	thrd.Logon(stat);
   942 	User::SetJustInTime(EFalse);
   943 	thrd.Resume();
   944 	User::WaitForRequest(stat);
   945 	thrd.Close();
   946 	User::SetJustInTime(ETrue);
   947 	}
   948 
   949 
   950 /**
   951   @SYMTestCaseID GRAPHICS-BITGDI-0029
   952  
   953   @SYMDEF             
   954 
   955   @SYMTestCaseDesc tests fading functionality
   956    
   957   @SYMTestPriority High
   958 
   959   @SYMTestStatus Implemented
   960 
   961   @SYMTestActions 	Tests fading functionality by drawing two rectangles with different alpha values and compares the results
   962   				 					
   963   @SYMTestExpectedResults the two bitmaps should be identical after the operations
   964 */
   965 void CTAuto::TestFadingL()
   966 	{
   967 	TBool res = EFalse;
   968 	TRect rectbitmap1(0,0,100,50);
   969 	TRect rectbitmap2(25,0,75,100);
   970 	
   971 	CFbsBitmap* bitmap=new(ELeave) CFbsBitmap;
   972 	CleanupStack::PushL(bitmap);
   973 	User::LeaveIfError(bitmap->Create(TSize(100,100), EColor64K));
   974 	
   975 	CFbsBitmapDevice* device=CFbsBitmapDevice::NewL(bitmap);		
   976 	CleanupStack::PushL(device);
   977 		
   978 	CFbsBitGc* gc;
   979 	User::LeaveIfError(device->CreateContext(gc));
   980 	CleanupStack::PushL(gc);
   981 	
   982 	CFbsBitmap* bitmap2=new(ELeave) CFbsBitmap;
   983 	CleanupStack::PushL(bitmap2);
   984 	User::LeaveIfError(bitmap2->Create(TSize(100,100), EColor64K));
   985 	
   986 	CFbsBitmapDevice* device2=CFbsBitmapDevice::NewL(bitmap2);		
   987 	CleanupStack::PushL(device2);
   988 		
   989 	CFbsBitGc* gc2;
   990 	User::LeaveIfError(device2->CreateContext(gc2));
   991 	CleanupStack::PushL(gc2);
   992 
   993 	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   994 	gc->SetPenColor(TRgb(0,0,0,0));
   995 
   996 	//Draws rectangle with Alpha Value 0 when Fading is turned OFF
   997 	gc->SetBrushColor(TRgb(0,0,255,255));
   998 	gc->DrawRect(rectbitmap2);
   999 	
  1000  	//Draws rectangle with Alpha Value 255 when Fading is turned OFF
  1001 	gc->SetBrushColor(TRgb(255,0,0,0));
  1002 	gc->DrawRect(rectbitmap1);
  1003 
  1004 	gc2->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1005 	gc2->SetPenColor(TRgb(0,0,0,0));	
  1006 	
  1007 
  1008  	//Draws rectangle with Alpha Value 255 when Fading is turned OFF
  1009 	gc2->SetBrushColor(TRgb(0,0,255,255));
  1010 	gc2->DrawRect(rectbitmap2);
  1011 
  1012  	//Draws rectangle with Alpha Value 0 when Fading is turned ON
  1013  	//Fade Option Turned ON
  1014 	gc2->SetFaded(ETrue);
  1015 	gc2->SetBrushColor(TRgb(255,0,0,0));
  1016 	gc2->DrawRect(rectbitmap1);
  1017 
  1018 	TRect rect(0,0,100,100);
  1019 	res = device->RectCompare(rect,*device2,rect);
  1020 	
  1021 	CleanupStack::PopAndDestroy(6, bitmap);
  1022 	TEST(res);
  1023 	}
  1024 
  1025 TInt PanicTestThread(TAny* aOption)
  1026 	{
  1027 	CTrapCleanup::New();
  1028 	RFbsSession::Connect();
  1029 
  1030 	CFbsScreenDevice* screendevice=NULL;
  1031 	CFbsBitGc* bitgc=NULL;
  1032 	CPolygonFiller* polyfill=NULL;
  1033 	RRegion region;
  1034 	const TInt option = TInt(aOption);
  1035 	TInt ret;
  1036 
  1037 	switch (option)
  1038 		{
  1039 	case EPolygonFiller:
  1040 		polyfill=(CPolygonFiller*)User::Alloc(sizeof(CPolygonFiller));
  1041 		new(polyfill) CPolygonFiller;
  1042 		break;
  1043 	case EDrawBmp1:
  1044 	case EDrawBmp2:
  1045 	case EDrawBmp3:
  1046 	case EDrawText1:
  1047 	case EDrawText2:
  1048 	case EDrawText3:
  1049 		TRAP(ret,screendevice=CFbsScreenDevice::NewL(_L("scdv"),EColor256));
  1050 		if (ret == KErrNotSupported)
  1051 			TRAP(ret,screendevice=CFbsScreenDevice::NewL(_L("scdv"),EGray4));
  1052 		if (ret == KErrNotSupported)
  1053 			TRAP(ret,screendevice=CFbsScreenDevice::NewL(_L("scdv"),EColor4K));
  1054 		if (ret != KErrNone)
  1055 			User::Panic(_L("screendevice failed"),ret);
  1056 		screendevice->CreateContext((CGraphicsContext*&)bitgc);
  1057 		break;
  1058 	case EGcDevice1:
  1059 	case EGcDevice2:
  1060 	case EGcRegion1:
  1061 	case EGcRegion2:
  1062 	case EUseBrush1:
  1063 	case EUseBrush2:
  1064 	case EUseBrush3:
  1065 	case EUseFont:
  1066 		TRAP(ret,bitgc=CFbsBitGc::NewL());
  1067 		break;
  1068 		};
  1069 
  1070 	switch (option)
  1071 		{
  1072 	case EPolygonFiller:
  1073 		polyfill->Construct(NULL,CGraphicsContext::EAlternate);
  1074 		break;
  1075 	case EBitmapDevice:
  1076 		(void)CFbsBitmapDevice::NewL(NULL);
  1077 		break;
  1078 	case EDrawBmp1:
  1079 		bitgc->DrawBitmap(TPoint(0,0),NULL);
  1080 		break;
  1081 	case EDrawBmp2:
  1082 		bitgc->DrawBitmap(TRect(0,0,0,0),NULL);
  1083 		break;
  1084 	case EDrawBmp3:
  1085 		bitgc->DrawBitmap(TRect(0,0,0,0),NULL,TRect(0,0,0,0));
  1086 		break;
  1087 	case EGcDevice1:
  1088 		bitgc->Resized();
  1089 		break;
  1090 	case EGcDevice2:
  1091 		bitgc->MapColors(TRect(0,0,0,0),NULL,0,EFalse);
  1092 		break;
  1093 	case EGcRegion1:
  1094 		region.ForceError();
  1095 		bitgc->SetClippingRegion(&region);
  1096 		break;
  1097 	case EGcRegion2:
  1098 		region.AddRect(TRect(-1,-1,1,1));
  1099 		bitgc->SetClippingRegion(&region);
  1100 		break;
  1101 	case EUseBrush1:
  1102 		bitgc->UseBrushPattern(NULL);
  1103 		break;
  1104 	case EUseBrush2:
  1105 		bitgc->UseBrushPattern((CFbsBitmap*)bitgc);
  1106 		break;
  1107 	case EUseBrush3:
  1108 		bitgc->UseBrushPattern(0);
  1109 		break;
  1110 	case EUseFont:
  1111 		bitgc->UseFont(NULL);
  1112 		break;
  1113 	case EDrawText1:
  1114 		bitgc->DrawText(_L("abc"),TPoint(0,0));
  1115 		break;
  1116 	case EDrawText2:
  1117 		bitgc->DrawText(_L("abc"),TRect(0,0,1,1),0,0);
  1118 		break;
  1119 	case EDrawText3:
  1120 		bitgc->DrawTextVertical(_L("abc"),EFalse);
  1121 		break;
  1122 	default:
  1123 		User::Panic(_L("Default panic"),KErrGeneral);
  1124 		};
  1125 
  1126 	return KErrNone;
  1127 	}
  1128 //-------
  1129 __CONSTRUCT_STEP__(Auto)
  1130 
  1131 void CTAutoStep::TestSetupL()
  1132 	{
  1133 	FbsStartup();
  1134 	User::LeaveIfError(RFbsSession::Connect());
  1135 	}
  1136 	
  1137 void CTAutoStep::TestClose()
  1138 	{
  1139 	RFbsSession::Disconnect();
  1140 	}