fbs/fontandbitmapserver/tfbs/textendedbitmap.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2008-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  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code
       
    20 */
       
    21 
       
    22 #include "textendedbitmapcommon.h"
       
    23 #include "textendedbitmap.h"
       
    24 #include "examplerasterizer.h"
       
    25 #include <graphics/fbsrasterizerclearcache.h>
       
    26 #include <s32mem.h>
       
    27 
       
    28 const TUint8 KRepeatTestData[] = "(This pattern is 32 bytes long!)";
       
    29 const TInt KRepeatTestDataSize = 32;
       
    30 const TInt KLargeDataSize = 0x8000 * KRepeatTestDataSize;
       
    31 
       
    32 CTExtendedBitmap::CTExtendedBitmap(CTestStep* aStep):
       
    33 	CTFbsBase(aStep, ETrue)
       
    34 	{
       
    35 	}
       
    36 
       
    37 CTExtendedBitmap::~CTExtendedBitmap()
       
    38 	{
       
    39 	((CTExtendedBitmapStep*)iStep)->CloseTMSGraphicsStep();
       
    40 	User::Free(iLargeData);
       
    41 	}
       
    42 
       
    43 void CTExtendedBitmap::ConstructL()
       
    44 	{	
       
    45 	TRAPD(err, iLargeData = static_cast<TUint8*>(User::AllocL(KLargeDataSize)));
       
    46 	if (err != KErrNone)
       
    47 		{
       
    48 		INFO_PRINTF3(_L("Error allocating large data buffer (size %d) in CTExtendedBitmap::ConstructL(), %d"), KLargeDataSize, err);
       
    49 		User::Leave(err);
       
    50 		}
       
    51 	for (TInt i = 0; i < KLargeDataSize; i += KRepeatTestDataSize)
       
    52 		{
       
    53 		Mem::Copy(PtrAdd(iLargeData, i), KRepeatTestData, KRepeatTestDataSize);
       
    54 		}
       
    55 	
       
    56 	// Save a pointer to the example rasterizer's MFbsRasterizerClearCache interface
       
    57 	if (CFbsRasterizer* rasterizer = CFbsBitmap::Rasterizer())
       
    58 		{		
       
    59 		err = rasterizer->GetInterface(TUid::Uid(KUidFbsRasterizerClearCache), (TAny*&)iRasterizerClearCache);
       
    60 		if (err != KErrNone) 
       
    61 			{
       
    62 			WARN_PRINTF1(_L("Failed to get a MFbsRasterizerClearCache interface for the current rasterizer, tests will panic during OOM testing due to the rasterizer cache not being cleared"));
       
    63 			}
       
    64 		}
       
    65 	}
       
    66 
       
    67 void CTExtendedBitmap::RunFbsTestL(TInt aCurTestCase)
       
    68     {    
       
    69     ((CTExtendedBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
       
    70 	switch(aCurTestCase)
       
    71 		{
       
    72 	case 1:
       
    73 		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0001"));
       
    74 		CreateExtendedBitmapL();
       
    75 		break;
       
    76 	case 2:
       
    77 		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0002"));
       
    78 		CreateLargeExtendedBitmapL();
       
    79 		break;
       
    80 	case 3:
       
    81 		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0003"));
       
    82 		CreateUsingInitializerL();
       
    83 		break;
       
    84 	case 4:
       
    85 		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0004"));
       
    86 		ScanLineL(EFalse);
       
    87 		break;
       
    88 	case 5:
       
    89 		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0004"));
       
    90 		ScanLineL(ETrue);
       
    91 		break;
       
    92 	case 6:
       
    93 		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0040"));
       
    94 		TestGetPixelL(EFalse);
       
    95 		break;
       
    96 	case 7:
       
    97 		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0040"));
       
    98 		TestGetPixelL(ETrue);
       
    99 		break;
       
   100 	case 8:
       
   101 		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0042"));
       
   102 		TestGetVerticalScanLineL(EFalse);
       
   103 		break;
       
   104 	case 9:
       
   105 		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0042"));
       
   106 		TestGetVerticalScanLineL(ETrue);
       
   107 
       
   108 		// Fall through as last test case
       
   109 	default:
       
   110 		SetLastTestCase();		
       
   111 		break;
       
   112 		}
       
   113 	((CTExtendedBitmapStep*)iStep)->RecordTestResultL();
       
   114     }
       
   115 
       
   116 
       
   117 /**
       
   118 	@SYMTestCaseID
       
   119 	GRAPHICS-FBSERV-EXTENDEDBITMAP-0001
       
   120 
       
   121 	@SYMTestCaseDesc
       
   122 	Create an extended bitmap and retrieve data
       
   123 
       
   124 	@SYMPREQ 
       
   125 	PREQ2096
       
   126 	
       
   127 	@SYMREQ
       
   128 	REQ10847
       
   129 	REQ10849
       
   130 	REQ10850
       
   131 	REQ10851
       
   132 	REQ10852
       
   133 	REQ10853
       
   134 	REQ10854
       
   135 	REQ10855
       
   136 
       
   137 	@SYMTestPriority  
       
   138 	High
       
   139 	
       
   140 	@SYMTestStatus 
       
   141 	Implemented
       
   142 	
       
   143 	@SYMTestActions
       
   144 	Creates an extended bitmap using test data and test Uid;
       
   145 	Retrieves and validates the data size, data and Uid.
       
   146 		
       
   147 	@SYMTestExpectedResults
       
   148 	Extended bitmap created and information correctly retrieved.
       
   149 */
       
   150 void CTExtendedBitmap::CreateExtendedBitmapL()
       
   151 	{
       
   152 	INFO_PRINTF1(_L("Create an extended bitmap"));
       
   153 
       
   154 	const TUint8 KTestData[]		= "Extended bitmap test data 123456";
       
   155 	const TInt KTestDataSize		= sizeof(KTestData);
       
   156 	const TSize KSizeInPixels 		= TSize(50,50);
       
   157 	const TDisplayMode KDisplayMode	= EColor64K;
       
   158 
       
   159 	CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
       
   160 	CleanupStack::PushL(bmp);
       
   161 	TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidTestExtendedBitmap, KTestData, KTestDataSize);
       
   162 	TESTNOERRORL(res);
       
   163 
       
   164 	bmp->BeginDataAccess();
       
   165 	
       
   166 	TInt returnedDataSize = bmp->DataSize();
       
   167 	TESTEQUALL(KTestDataSize, returnedDataSize);
       
   168 	INFO_PRINTF3(_L("Test data size on creation: %i. Test data size returned: %i"), KTestDataSize, returnedDataSize);
       
   169 	
       
   170 	const TUint8* returnedDataAddress = reinterpret_cast<TUint8*>(bmp->DataAddress());
       
   171 	res = Mem::Compare(returnedDataAddress,returnedDataSize, KTestData, KTestDataSize);
       
   172 	TESTEQUALL(0, res);
       
   173 	
       
   174 	TUid returnedUid = bmp->ExtendedBitmapType();
       
   175 	TESTEQUALL(KUidTestExtendedBitmap, returnedUid);
       
   176 
       
   177 	bmp->EndDataAccess(ETrue);
       
   178 	
       
   179 	CleanupStack::PopAndDestroy(bmp);
       
   180 	}
       
   181 
       
   182 
       
   183 /**
       
   184 	@SYMTestCaseID
       
   185 	GRAPHICS-FBSERV-EXTENDEDBITMAP-0002
       
   186 
       
   187 	@SYMTestCaseDesc
       
   188 	Create an extended bitmap with data sized 1MB
       
   189 
       
   190 	@SYMPREQ 
       
   191 	PREQ2096
       
   192 	
       
   193 	@SYMREQ
       
   194 	REQ10847
       
   195 	REQ10863
       
   196 
       
   197 	@SYMTestPriority  
       
   198 	High
       
   199 	
       
   200 	@SYMTestStatus 
       
   201 	Implemented
       
   202 	
       
   203 	@SYMTestActions
       
   204 	Create an extended bitmap with a buffer that is 1MB.
       
   205 		
       
   206 	@SYMTestExpectedResults
       
   207 	No errors or panics should occur.
       
   208 */
       
   209 void CTExtendedBitmap::CreateLargeExtendedBitmapL()
       
   210 	{
       
   211 	INFO_PRINTF1(_L("Create an extended bitmap with data size 1MB"));	
       
   212 	
       
   213 	const TSize KSizeInPixels = TSize(50,50);
       
   214 	const TDisplayMode KDisplayMode	= EColor64K;	
       
   215 	
       
   216 	CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
       
   217 	CleanupStack::PushL(bmp);
       
   218 	TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidTestExtendedBitmap, iLargeData, KLargeDataSize);
       
   219 	TESTNOERRORL(res);
       
   220 
       
   221 	bmp->BeginDataAccess();
       
   222 	
       
   223 	TInt returnedDataSize = bmp->DataSize();
       
   224 	TESTEQUALL(KLargeDataSize, returnedDataSize);
       
   225 	INFO_PRINTF3(_L("Test data size on creation: %i. Test data size returned: %i"), KLargeDataSize, returnedDataSize);
       
   226 	
       
   227 	const TUint8* returnedDataAddress = reinterpret_cast<TUint8*>(bmp->DataAddress());
       
   228 	res = Mem::Compare(returnedDataAddress, returnedDataSize, iLargeData, KLargeDataSize);
       
   229 	TESTEQUALL(0, res);
       
   230 	
       
   231 	TUid returnedUid = bmp->ExtendedBitmapType();
       
   232 	TESTEQUALL(KUidTestExtendedBitmap, returnedUid);
       
   233 
       
   234 	bmp->EndDataAccess(ETrue);
       
   235 	
       
   236 	CleanupStack::PopAndDestroy(bmp);
       
   237 	}
       
   238 
       
   239 
       
   240 /**
       
   241 	@SYMTestCaseID
       
   242 	GRAPHICS-FBSERV-EXTENDEDBITMAP-0003
       
   243 
       
   244 	@SYMTestCaseDesc
       
   245 	Create an extended bitmap using an MFbsExtendedBitmapInitializer
       
   246 
       
   247 	@SYMPREQ 
       
   248 	PREQ2096
       
   249 	
       
   250 	@SYMREQ
       
   251 
       
   252 	@SYMTestPriority  
       
   253 	High
       
   254 	
       
   255 	@SYMTestStatus 
       
   256 	Implemented
       
   257 	
       
   258 	@SYMTestActions
       
   259 	Create an extended bitmap using an MFbsExtendedBitmapInitializer, with a buffer that is 1MB.
       
   260 		
       
   261 	@SYMTestExpectedResults
       
   262 	Extended bitmap created and information correctly retrieved. 
       
   263 */
       
   264 void CTExtendedBitmap::CreateUsingInitializerL()
       
   265 	{
       
   266 	INFO_PRINTF1(_L("Create an extended bitmap using an MFbsExtendedBitmapInitializer"));	
       
   267 	
       
   268 	const TSize KSizeInPixels = TSize(50,50);
       
   269 	const TDisplayMode KDisplayMode	= EColor64K;	
       
   270 	
       
   271 	CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
       
   272 	CleanupStack::PushL(bmp);
       
   273 	CTestExtendedBitmapInitializer* initializer = new(ELeave) CTestExtendedBitmapInitializer(iLargeData, KLargeDataSize);
       
   274 	CleanupStack::PushL(initializer);
       
   275 	TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidTestExtendedBitmap, KLargeDataSize, *initializer);
       
   276 	CleanupStack::PopAndDestroy(initializer);
       
   277 	TESTNOERRORL(res);
       
   278 	
       
   279 	bmp->BeginDataAccess();
       
   280 	
       
   281 	TInt returnedDataSize = bmp->DataSize();
       
   282 	TESTEQUALL(KLargeDataSize, returnedDataSize);
       
   283 	INFO_PRINTF3(_L("Test data size on creation: %i. Test data size returned: %i"), KLargeDataSize, returnedDataSize);
       
   284 	
       
   285 	const TUint8* returnedDataAddress = reinterpret_cast<TUint8*>(bmp->DataAddress());
       
   286 	res = Mem::Compare(returnedDataAddress, returnedDataSize, iLargeData, KLargeDataSize);
       
   287 	TESTEQUALL(0, res);
       
   288 	
       
   289 	TUid returnedUid = bmp->ExtendedBitmapType();
       
   290 	TESTEQUALL(KUidTestExtendedBitmap, returnedUid);
       
   291 
       
   292 	bmp->EndDataAccess(ETrue);
       
   293 	
       
   294 	CleanupStack::PopAndDestroy(bmp);
       
   295 	}
       
   296 
       
   297 /**
       
   298 	@SYMTestCaseID
       
   299 	GRAPHICS-FBSERV-EXTENDEDBITMAP-0004
       
   300 
       
   301 	@SYMTestCaseDesc
       
   302 	Create an extended bitmap and retrieve scanline
       
   303 
       
   304 	@SYMPREQ 
       
   305 	PREQ2096
       
   306 	
       
   307 	@SYMREQ
       
   308 	REQ10847
       
   309 
       
   310 	@SYMTestPriority  
       
   311 	High
       
   312 	
       
   313 	@SYMTestStatus 
       
   314 	Implemented
       
   315 	
       
   316 	@SYMTestActions
       
   317 	Creates an extended bitmap using data compatible with the
       
   318 	example rasterizer.
       
   319 	If (aUseDuplicateBitmap == ETrue) use CFbsBitmap::Duplicate()
       
   320 	to create a duplicate of the extended bitmap just created and 
       
   321 	complete the test using the duplicate extended bitmap. 
       
   322 	Get a scanline using CFbsBitmap::GetScanLine() and check if
       
   323 	it is correct, depending on the presence of the rasterizer.
       
   324 		
       
   325 	@SYMTestExpectedResults
       
   326 	Extended bitmap created and scanline correctly retrieved.
       
   327 */
       
   328 void CTExtendedBitmap::ScanLineL(TBool aUseDuplicateBitmap)
       
   329 	{
       
   330 	INFO_PRINTF1(_L("Get a scanline from an extended bitmap"));	
       
   331 
       
   332 	const TRgb KColors[] 	= {TRgb(0,0,0), TRgb(255,0,0), TRgb(255,255,0)};
       
   333 	// Small size needed for this test O(x^2 * y) iterations run every time
       
   334 	const TSize KSizeInPixels 		= TSize(8,5); 
       
   335 	const TDisplayMode KDisplayMode	= EColor64K;
       
   336 	const TUint8 horizontalStripes = 1;
       
   337 
       
   338 	// Check to see if we have an example bitmap rasterizer available for this test run	
       
   339 	iRasterizerAvailable = (CFbsBitmap::Rasterizer() != NULL);
       
   340 	if (iRasterizerAvailable)
       
   341 		{
       
   342 		INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));	
       
   343 		}
       
   344 	else
       
   345 		{
       
   346 		INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
       
   347 		}
       
   348 	
       
   349 	CleanupStack::PushL(TCleanupItem(ClearRasterizerCache, iRasterizerClearCache));
       
   350 
       
   351 	TInt dataSize = sizeof(KColors)+sizeof(horizontalStripes); // estimate the data size
       
   352 	TUint8* data = new(ELeave) TUint8[dataSize];
       
   353 	CleanupStack::PushL(data);	
       
   354 	
       
   355 	// Write the colours to be used in the extended bitmap to the data
       
   356 	RMemWriteStream ws;
       
   357 	ws.Open(data, dataSize);
       
   358 	CleanupClosePushL(ws);
       
   359 	ws << KColors[0] << KColors[1] << KColors[2] << horizontalStripes;
       
   360 	dataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
       
   361 	CleanupStack::PopAndDestroy(1, &ws);
       
   362 	
       
   363 	// Create the extended bitmap to be used a a brush
       
   364 	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
       
   365 	CleanupStack::PushL(bmp);
       
   366 	TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
       
   367 	TESTNOERRORL(res);
       
   368 		
       
   369 	if (aUseDuplicateBitmap)
       
   370 		{
       
   371 		INFO_PRINTF1(_L("Testing using a duplicated extended bitmap"));
       
   372 		CFbsBitmap* duplicateBmp = new(ELeave) CFbsBitmap;
       
   373 		CleanupStack::PushL(duplicateBmp);
       
   374 		res = duplicateBmp->Duplicate(bmp->Handle());
       
   375 		TESTNOERRORL(res);
       
   376 		bmp = duplicateBmp;
       
   377 		}
       
   378 
       
   379 	TInt byteWidth = CFbsBitmap::ScanLineLength(KSizeInPixels.iWidth, KDisplayMode);
       
   380 	TUint8* buffer = new(ELeave) TUint8[byteWidth + 1];
       
   381 	CleanupArrayDeletePushL(buffer);
       
   382 
       
   383 	const TUint8 KCheckValue = 0x69; // Pixel value used as guard at the end of the buffer used
       
   384 	buffer[byteWidth] = KCheckValue; 
       
   385 	TPtr8 scanLine(buffer,byteWidth,byteWidth);
       
   386 
       
   387 	TInt x, y;
       
   388 	TInt firstStripe, lastStripe;
       
   389 	TInt* s;
       
   390 	if(horizontalStripes)
       
   391 		{
       
   392 		firstStripe = KSizeInPixels.iHeight/3;
       
   393 		lastStripe = KSizeInPixels.iHeight - firstStripe;
       
   394 		s = &y;
       
   395 		}
       
   396 	else
       
   397 		{
       
   398 		firstStripe = KSizeInPixels.iWidth/3;
       
   399 		lastStripe = KSizeInPixels.iWidth - firstStripe;
       
   400 		s = &x;
       
   401 		}
       
   402 
       
   403 	for(y = 0; y < KSizeInPixels.iHeight; ++y)
       
   404 		{
       
   405 		for(TInt length = 1; length <= KSizeInPixels.iWidth; ++length)
       
   406 			{
       
   407 			for(TInt pos = KSizeInPixels.iWidth - length; pos >= 0; --pos)
       
   408 				{
       
   409 				bmp->GetScanLine(scanLine, TPoint(pos,y), length, KDisplayMode);
       
   410 				for(x = pos + length - 1; x >= pos; --x)
       
   411 					{
       
   412 					TRgb bufferColor = ExtractRgb(buffer, x-pos, KDisplayMode);
       
   413 					
       
   414 					if(!iRasterizerAvailable)
       
   415 						{
       
   416 						TESTCOLOREQUALL(bufferColor, KRgbWhite);
       
   417 						}
       
   418 					else if (*s < firstStripe)
       
   419 						{
       
   420 						// First stripe
       
   421 						TESTCOLOREQUALL(bufferColor, KColors[0]);
       
   422 						}
       
   423 					else if (*s >= lastStripe)
       
   424 						{
       
   425 						// Last stripe
       
   426 						TESTCOLOREQUALL(bufferColor, KColors[2]);
       
   427 						}
       
   428 					else
       
   429 						{
       
   430 						// Middle stripe
       
   431 						TESTCOLOREQUALL(bufferColor, KColors[1]);
       
   432 						}							
       
   433 					}
       
   434 				}
       
   435 			}
       
   436 		}
       
   437 	
       
   438 	// Check that the guard byte is still intact now that the tests have been run
       
   439 	TEST(buffer[byteWidth] == KCheckValue); 
       
   440 	
       
   441 	if (aUseDuplicateBitmap)
       
   442 		{
       
   443 		CleanupStack::PopAndDestroy(1);
       
   444 		}
       
   445 	CleanupStack::PopAndDestroy(4);
       
   446 	}
       
   447 
       
   448 
       
   449 /**
       
   450 	@SYMTestCaseID
       
   451 	GRAPHICS-FBSERV-EXTENDEDBITMAP-0040
       
   452 
       
   453 	@SYMTestCaseDesc
       
   454 	Create an extended bitmap and retrieve pixels
       
   455 
       
   456 	@SYMPREQ 
       
   457 	CR1804
       
   458 	
       
   459 	@SYMREQ
       
   460 	REQ10858
       
   461 
       
   462 	@SYMTestPriority  
       
   463 	High
       
   464 	
       
   465 	@SYMTestStatus 
       
   466 	Implemented
       
   467 	
       
   468 	@SYMTestActions
       
   469 	Creates an extended bitmap using data compatible with the
       
   470 	example rasterizer.
       
   471 	If (aUseDuplicateBitmap == ETrue) use CFbsBitmap::Duplicate()
       
   472 	to create a duplicate of the extended bitmap just created and 
       
   473 	complete the test using the duplicate extended bitmap. 
       
   474 	Get pixel values using CFbsBitmap::GetPixel() and check if
       
   475 	they are correct, depending on the presence of the rasterizer.
       
   476 		
       
   477 	@SYMTestExpectedResults
       
   478 	Extended bitmap created and pixels correctly retrieved.
       
   479 */
       
   480 void CTExtendedBitmap::TestGetPixelL(TBool aUseDuplicateBitmap)
       
   481 	{
       
   482 	INFO_PRINTF1(_L("Get pixel values from an extended bitmap"));	
       
   483 
       
   484 	const TRgb KColors[] 	= {TRgb(0,0,0), TRgb(255,0,0), TRgb(255,255,0)};
       
   485 	const TSize KSizeInPixels 		= TSize(8,5); 
       
   486 	const TDisplayMode KDisplayMode	= EColor64K;
       
   487 	const TUint8 KHorizontalStripes = 1;
       
   488 
       
   489 	// Check to see if we have an example bitmap rasterizer available for this test run	
       
   490 	iRasterizerAvailable = (CFbsBitmap::Rasterizer() != NULL);
       
   491 	if (iRasterizerAvailable)
       
   492 		{
       
   493 		INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));	
       
   494 		}
       
   495 	else
       
   496 		{
       
   497 		INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
       
   498 		}
       
   499 	
       
   500 	CleanupStack::PushL(TCleanupItem(ClearRasterizerCache, iRasterizerClearCache));
       
   501 
       
   502 	TInt dataSize = sizeof(KColors)+sizeof(KHorizontalStripes); // estimate the data size
       
   503 	TUint8* data = new(ELeave) TUint8[dataSize];
       
   504 	CleanupStack::PushL(data);	
       
   505 	
       
   506 	// Write the colours to be used in the extended bitmap to the data
       
   507 	RMemWriteStream ws;
       
   508 	ws.Open(data, dataSize);
       
   509 	CleanupClosePushL(ws);
       
   510 	ws << KColors[0] << KColors[1] << KColors[2] << KHorizontalStripes;
       
   511 	dataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
       
   512 	CleanupStack::PopAndDestroy(1, &ws);
       
   513 	
       
   514 	// Create the extended bitmap
       
   515 	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
       
   516 	CleanupStack::PushL(bmp);
       
   517 	TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
       
   518 	TESTNOERRORL(res);
       
   519 		
       
   520 	if (aUseDuplicateBitmap)
       
   521 		{
       
   522 		INFO_PRINTF1(_L("Testing using a duplicated extended bitmap"));
       
   523 		CFbsBitmap* duplicateBmp = new(ELeave) CFbsBitmap;
       
   524 		CleanupStack::PushL(duplicateBmp);
       
   525 		res = duplicateBmp->Duplicate(bmp->Handle());
       
   526 		TESTNOERRORL(res);
       
   527 		bmp = duplicateBmp;
       
   528 		}
       
   529 
       
   530 	TInt firstStripe = KSizeInPixels.iHeight/3;
       
   531 	TInt lastStripe = KSizeInPixels.iHeight - firstStripe;
       
   532 	TRgb color;
       
   533 	for(TInt y = 0; y < KSizeInPixels.iHeight; ++y)
       
   534 		{
       
   535 		for(TInt x = 0; x < KSizeInPixels.iWidth; ++x)
       
   536 			{
       
   537 			bmp->GetPixel(color, TPoint(x,y));
       
   538 
       
   539 			if(!iRasterizerAvailable)
       
   540 				{
       
   541 				TESTCOLOREQUALL(color, KRgbWhite);
       
   542 				}
       
   543 			else if (y < firstStripe)
       
   544 				{
       
   545 				// First stripe
       
   546 				TESTCOLOREQUALL(color, KColors[0]);
       
   547 				}
       
   548 			else if (y >= lastStripe)
       
   549 				{
       
   550 				// Last stripe
       
   551 				TESTCOLOREQUALL(color, KColors[2]);
       
   552 				}
       
   553 			else
       
   554 				{
       
   555 				// Middle stripe
       
   556 				TESTCOLOREQUALL(color, KColors[1]);
       
   557 				}							
       
   558 			}
       
   559 		}
       
   560 	
       
   561 	if (aUseDuplicateBitmap)
       
   562 		{
       
   563 		CleanupStack::PopAndDestroy(1);
       
   564 		}
       
   565 	CleanupStack::PopAndDestroy(3);
       
   566 	}
       
   567 
       
   568 
       
   569 
       
   570 /**
       
   571 @SYMTestCaseID
       
   572 	GRAPHICS-FBSERV-EXTENDEDBITMAP-0042
       
   573 
       
   574 @SYMTestCaseDesc
       
   575 	Create an extended bitmap and retrieve vertical scanline
       
   576 
       
   577 @SYMPREQ 
       
   578 	DEF141346
       
   579 	
       
   580 @SYMTestPriority  
       
   581 	High
       
   582 
       
   583 @SYMTestStatus 
       
   584 	Implemented
       
   585 
       
   586 @SYMTestActions
       
   587 	Create an extended bitmap using data compatible with the
       
   588 	example rasterizer.
       
   589 	If (aUseDuplicateBitmap == ETrue) use CFbsBitmap::Duplicate()
       
   590 	to create a duplicate of the extended bitmap just created and 
       
   591 	complete the test using the duplicate extended bitmap. 
       
   592 	Get a vertical scanline using CFbsBitmap::GetVerticalScanLine() and check
       
   593 	if it is correct, depending on the presence of the rasterizer.
       
   594 
       
   595 @SYMTestExpectedResults
       
   596 	Extended bitmap created and scanline correctly retrieved.
       
   597 */
       
   598 void CTExtendedBitmap::TestGetVerticalScanLineL(TBool aUseDuplicateBitmap)
       
   599 	{
       
   600 	INFO_PRINTF1(_L("Get a vertical scanline from an extended bitmap"));	
       
   601 
       
   602 		const TRgb KColors[] 	= {TRgb(0,0,0), TRgb(255,0,0), TRgb(255,255,0)};
       
   603 		const TSize KSizeInPixels 		= TSize(5,8); 
       
   604 		const TDisplayMode KDisplayMode	= EColor64K;
       
   605 		const TUint8 KHorizontalStripes = 1;
       
   606 
       
   607 		// Check to see if we have an example bitmap rasterizer available for this test run	
       
   608 		iRasterizerAvailable = (CFbsBitmap::Rasterizer() != NULL);
       
   609 		if (iRasterizerAvailable)
       
   610 			{
       
   611 			INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));	
       
   612 			}
       
   613 		else
       
   614 			{
       
   615 			INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
       
   616 			}
       
   617 		
       
   618 		CleanupStack::PushL(TCleanupItem(ClearRasterizerCache, iRasterizerClearCache));
       
   619 
       
   620 		TInt dataSize = sizeof(KColors)+sizeof(KHorizontalStripes); // estimate the data size
       
   621 		TUint8* data = new(ELeave) TUint8[dataSize];
       
   622 		CleanupStack::PushL(data);	
       
   623 		
       
   624 		// Write the colours to be used in the extended bitmap to the data
       
   625 		RMemWriteStream ws;
       
   626 		ws.Open(data, dataSize);
       
   627 		CleanupClosePushL(ws);
       
   628 		ws << KColors[0] << KColors[1] << KColors[2] << KHorizontalStripes;
       
   629 		dataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
       
   630 		CleanupStack::PopAndDestroy(1, &ws);
       
   631 		
       
   632 		// Create the extended bitmap
       
   633 		CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
       
   634 		CleanupStack::PushL(bmp);
       
   635 		TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
       
   636 		TESTNOERRORL(res);
       
   637 			
       
   638 		if (aUseDuplicateBitmap)
       
   639 			{
       
   640 			INFO_PRINTF1(_L("Testing using a duplicated extended bitmap"));
       
   641 			CFbsBitmap* duplicateBmp = new(ELeave) CFbsBitmap;
       
   642 			CleanupStack::PushL(duplicateBmp);
       
   643 			res = duplicateBmp->Duplicate(bmp->Handle());
       
   644 			TESTNOERRORL(res);
       
   645 			bmp = duplicateBmp;
       
   646 			}
       
   647 
       
   648 		TInt byteWidth = CFbsBitmap::ScanLineLength(KSizeInPixels.iHeight, KDisplayMode);
       
   649 		TUint8* buffer = new(ELeave) TUint8[byteWidth + 1];
       
   650 		CleanupArrayDeletePushL(buffer);
       
   651 
       
   652 		const TUint8 KCheckValue = 0x69; // Pixel value used as guard at the end of the buffer used
       
   653 		buffer[byteWidth] = KCheckValue; 
       
   654 		TPtr8 scanLine(buffer,byteWidth,byteWidth);
       
   655 
       
   656 		TInt firstStripe = KSizeInPixels.iHeight/3;
       
   657 		TInt lastStripe = KSizeInPixels.iHeight - firstStripe;
       
   658 		TRgb color;
       
   659 		for(TInt x = 0; x < KSizeInPixels.iWidth; ++x)
       
   660 			{
       
   661 			bmp->GetVerticalScanLine(scanLine, x, KDisplayMode);
       
   662 			for(TInt y = 0; y < KSizeInPixels.iHeight; ++y)
       
   663 				{
       
   664 				TRgb bufferColor = ExtractRgb(buffer, y, KDisplayMode);
       
   665 				if(!iRasterizerAvailable)
       
   666 					{
       
   667 					TESTCOLOREQUALL(bufferColor, KRgbWhite);
       
   668 					}
       
   669 				else if (y < firstStripe)
       
   670 					{
       
   671 					// First stripe
       
   672 					TESTCOLOREQUALL(bufferColor, KColors[0]);
       
   673 					}
       
   674 				else if (y >= lastStripe)
       
   675 					{
       
   676 					// Last stripe
       
   677 					TESTCOLOREQUALL(bufferColor, KColors[2]);
       
   678 					}
       
   679 				else
       
   680 					{
       
   681 					// Middle stripe
       
   682 					TESTCOLOREQUALL(bufferColor, KColors[1]);
       
   683 					}							
       
   684 				}
       
   685 			}
       
   686 
       
   687 		// Check that the guard byte is still intact now that the tests have been run
       
   688 		TEST(buffer[byteWidth] == KCheckValue); 
       
   689 
       
   690 		if (aUseDuplicateBitmap)
       
   691 			{
       
   692 			CleanupStack::PopAndDestroy(1);
       
   693 			}
       
   694 		CleanupStack::PopAndDestroy(4);
       
   695 	}
       
   696 
       
   697 //--------------
       
   698 __CONSTRUCT_STEP__(ExtendedBitmap)
       
   699 
       
   700 /** Method to be used with a TCleanupItem for clearing the extended bitmap rasterizer cache
       
   701 from the cleanup stack. Calls the MExampleRasterizerClearCache::ClearCache() method on the
       
   702 passed CFbsRasterizer object if the MExampleRasterizerClearCache extension interface is available
       
   703 for that object.
       
   704 @param aPtr A pointer to the current CFbsRasterizer object, or NULL if no rasterizer
       
   705 object is available.
       
   706  */
       
   707 void CTExtendedBitmap::ClearRasterizerCache(TAny* aPtr)
       
   708 	{	
       
   709 	if (aPtr)
       
   710 		{
       
   711 		static_cast<MFbsRasterizerClearCache*>(aPtr)->ClearCache();
       
   712 		}
       
   713 	}
       
   714