os/graphics/fbs/fontandbitmapserver/tfbs/TBITMAP.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1996-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 <e32math.h>
    23 #include <s32file.h>
    24 #include <bautils.h>
    25 #include <hal.h>
    26 #include <test/tefunit.h>
    27 #include <graphics/bitmapuid.h>
    28 #include "../sfbs/UTILS.H"
    29 #include "TBitmap.h"
    30 #include "../sfbs/fbsbitmapasyncstreamer.h"
    31 #include "fbsmessage.h"
    32 
    33 // Symbian modification to help reduce unnecessary warnings 
    34 #if (__ARMCC_VERSION >= 310000)
    35 //turn off Warning:  #546-D: transfer of control bypasses initialization of variable, which is unnecessary.
    36 #pragma diag_suppress 546
    37 #endif
    38 // End of Symbian modification
    39 
    40 
    41 
    42 //
    43 //
    44 //Globals
    45 //LOCAL_D RTest	TheTest(_L("Test Bitmap"));
    46 LOCAL_D RFs		TheFs;
    47 const TUint8	KCheckValue = 0x69;//pixel value used in the tests
    48 
    49 _LIT(KBmpCompr12, "z:\\system\\data\\compr12.mbm");
    50 _LIT(KBmpCompr16, "z:\\system\\data\\compr16.mbm");
    51 _LIT(KBmpCompr24, "z:\\system\\data\\compr24.mbm");
    52 _LIT(KBmpZCompr12, "z:\\system\\data\\racompr12.mbm");
    53 _LIT(KBmpZCompr16, "z:\\system\\data\\racompr16.mbm");
    54 _LIT(KBmpZCompr24, "z:\\system\\data\\racompr24.mbm");
    55 _LIT(KBmpCCompr12, "c:\\racompr12.mbm");
    56 _LIT(KBmpCCompr16, "c:\\racompr16.mbm");
    57 _LIT(KBmpCCompr24, "c:\\racompr24.mbm");
    58 
    59 _LIT(KRc_RamInRom8, "z:\\system\\data\\rc_ram8.mbm");
    60 _LIT(KRc_RamInRom12, "z:\\system\\data\\rc_ram12.mbm");
    61 _LIT(KRc_RamInRom16, "z:\\system\\data\\rc_ram16.mbm");
    62 _LIT(KRc_RamInRom24, "z:\\system\\data\\rc_ram24.mbm");
    63 
    64 _LIT(KRc_Ram8, "c:\\rc_ram8.mbm");
    65 _LIT(KRc_Ram12, "c:\\rc_ram12.mbm");
    66 _LIT(KRc_Ram16, "c:\\rc_ram16.mbm");
    67 _LIT(KRc_Ram24, "c:\\rc_ram24.mbm");
    68 
    69 _LIT(KRamBitmapOnZ, "z:\\system\\data\\16RAM2.mbm");
    70 _LIT(KRamBitmap, "c:\\16RAM2.mbm");
    71 _LIT(KRamBitmap2, "c:\\16RAM3.mbm");
    72 
    73 _LIT(KMono_RamInRom_M1, "z:\\system\\data\\mono_m1.mbm");
    74 _LIT(KMono_RamInRom_M2, "z:\\system\\data\\mono_m2.mbm");
    75 _LIT(KMono_RamInRom_M4, "z:\\system\\data\\mono_m4.mbm");
    76 _LIT(KMono_RamInRom_M8, "z:\\system\\data\\mono_m8.mbm");
    77 _LIT(KMono_RamInRom_C4, "z:\\system\\data\\mono_c4.mbm");
    78 _LIT(KMono_RamInRom_C8, "z:\\system\\data\\mono_c8.mbm");
    79 _LIT(KMono_RamInRom_C12, "z:\\system\\data\\mono_c12.mbm");
    80 _LIT(KMono_RamInRom_C16, "z:\\system\\data\\mono_c16.mbm");
    81 _LIT(KMono_RamInRom_C24, "z:\\system\\data\\mono_c24.mbm");
    82 _LIT(KMono_RamInRom_C32, "z:\\system\\data\\mono_c32.mbm");
    83 
    84 _LIT(KMono_M1, "c:\\mono_m1.mbm");
    85 _LIT(KMono_M2, "c:\\mono_m2.mbm");
    86 _LIT(KMono_M4, "c:\\mono_m4.mbm");
    87 _LIT(KMono_M8, "c:\\mono_m8.mbm");
    88 _LIT(KMono_C4, "c:\\mono_c4.mbm");
    89 _LIT(KMono_C8, "c:\\mono_c8.mbm");
    90 _LIT(KMono_C12, "c:\\mono_c12.mbm");
    91 _LIT(KMono_C16, "c:\\mono_c16.mbm");
    92 _LIT(KMono_C24, "c:\\mono_c24.mbm");
    93 _LIT(KMono_C32, "c:\\mono_c32.mbm");
    94 
    95 _LIT(KRomBitmap,"z:\\system\\data\\tfbs.rbm");
    96 
    97 //
    98 //
    99 //Create/Destroy test environment global functions
   100 
   101 //Delete "aFullName" file.
   102 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
   103 	{
   104 	RFs fsSession;
   105 	TInt err = fsSession.Connect();
   106 	if(err == KErrNone)
   107 		{
   108 		TEntry entry;
   109 		if(fsSession.Entry(aFullName, entry) == KErrNone)
   110 			{
   111 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
   112 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
   113 			if(err != KErrNone) 
   114 				{
   115 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
   116 				}
   117 			err = fsSession.Delete(aFullName);
   118 			if(err != KErrNone) 
   119 				{
   120 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
   121 				}
   122 			}
   123 		fsSession.Close();
   124 		}
   125 	else
   126 		{
   127 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   128 		}
   129 	}
   130 
   131 //Copy test bitmaps from Z: to C: drive. RFs::Connect() had to be called already 
   132 //on "TheFs" object.
   133 LOCAL_C void CopyFilesOnC()
   134 	{
   135 	BaflUtils::CopyFile(TheFs, KTestBitmapOnZ, KTestBitmapOnC);
   136 	BaflUtils::CopyFile(TheFs, KBmpZCompr12, KBmpCCompr12);
   137 	BaflUtils::CopyFile(TheFs, KBmpZCompr16, KBmpCCompr16);
   138 	BaflUtils::CopyFile(TheFs, KBmpZCompr24, KBmpCCompr24);
   139 	BaflUtils::CopyFile(TheFs, KRc_RamInRom8, KRc_Ram8);
   140 	BaflUtils::CopyFile(TheFs, KRc_RamInRom12, KRc_Ram12);
   141 	BaflUtils::CopyFile(TheFs, KRc_RamInRom16, KRc_Ram16);
   142 	BaflUtils::CopyFile(TheFs, KRc_RamInRom24, KRc_Ram24);
   143 	BaflUtils::CopyFile(TheFs, KRamBitmapOnZ, KRamBitmap);
   144 	BaflUtils::CopyFile(TheFs, KRamBitmapOnZ, KRamBitmap2);
   145 	BaflUtils::CopyFile(TheFs, KMono_RamInRom_M1, KMono_M1);
   146 	BaflUtils::CopyFile(TheFs, KMono_RamInRom_M2, KMono_M2);
   147 	BaflUtils::CopyFile(TheFs, KMono_RamInRom_M4, KMono_M4);
   148 	BaflUtils::CopyFile(TheFs, KMono_RamInRom_M8, KMono_M8);
   149 	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C4, KMono_C4);
   150 	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C8, KMono_C8);
   151 	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C12, KMono_C12);
   152 	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C16, KMono_C16);
   153 	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C24, KMono_C24);
   154 	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C32, KMono_C32);
   155 	}
   156 
   157 //Delete data files used by the test
   158 LOCAL_C void DeleteFilesFromC()
   159 	{
   160 	DeleteDataFile(KTestBitmapOnC);
   161 	DeleteDataFile(KBmpCCompr12);
   162 	DeleteDataFile(KBmpCCompr16);
   163 	DeleteDataFile(KBmpCCompr24);
   164 	DeleteDataFile(KRc_Ram8);
   165 	DeleteDataFile(KRc_Ram12);
   166 	DeleteDataFile(KRc_Ram16);
   167 	DeleteDataFile(KRc_Ram24);
   168 	DeleteDataFile(KRamBitmap);
   169 	DeleteDataFile(KRamBitmap2);
   170 	DeleteDataFile(KMono_M1);
   171 	DeleteDataFile(KMono_M2);
   172 	DeleteDataFile(KMono_M4);
   173 	DeleteDataFile(KMono_M8);
   174 	DeleteDataFile(KMono_C4);
   175 	DeleteDataFile(KMono_C8);
   176 	DeleteDataFile(KMono_C12);
   177 	DeleteDataFile(KMono_C16);
   178 	DeleteDataFile(KMono_C24);
   179 	DeleteDataFile(KMono_C32);
   180 	}
   181 
   182 //
   183 //
   184 
   185 void CTBitmap::DeleteScanLineBuffer()
   186 	{
   187 	RFbsSession* fbs = RFbsSession::GetSession();
   188 	delete fbs->iScanLineBuffer;
   189 	fbs->iScanLineBuffer = NULL;
   190 	}
   191 
   192 CTBitmap::CTBitmap(CTestStep* aStep):
   193 	CTGraphicsBase(aStep),
   194 	iBmpHandler(NULL),
   195 	iBitmap(NULL),
   196 	iAs(NULL)
   197 	{
   198 	__ASSERT_DEBUG(CActiveScheduler::Current(), User::Invariant());
   199 	CFbsBitmap bmp;
   200 	iTestBitmapName = KTestBitmapOnZ;
   201 	TInt ret=bmp.Load(iTestBitmapName,ETfbs,NULL);
   202 	TEST2(ret, KErrNone);
   203 	bmp.Reset();
   204 
   205 	ret = iFs.Connect();
   206 	TEST2(ret, KErrNone);
   207 
   208 	// Expand session scanline buffer cache to avoid spurious alloc heavens later on
   209 	const TInt bufferSize = 1024;
   210 
   211 	ret = bmp.Create(TSize(bufferSize,1),EColor256);
   212 	TEST2(ret, KErrNone);
   213 
   214 	ret = bmp.Compress();
   215 	TEST2(ret, KErrNone);
   216 
   217 	TUint8* buffer = new TUint8[bufferSize];
   218 	TEST(buffer != NULL);
   219 
   220 	TPtr8 scanline(buffer,bufferSize,bufferSize);
   221 	bmp.GetScanLine(scanline,TPoint(0,0),bufferSize,EColor256);
   222 	delete [] buffer;
   223 	bmp.Reset();
   224 	
   225 	TUint32* romAddress = NULL;
   226 	if(!CFbsBitmap::IsFileInRom(KRomBitmap, romAddress)) //any ROM bitmap
   227 		{
   228 		INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."),
   229 				&KRomBitmap);
   230 		INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported."));
   231 		iSkipRomBitmapTests = ETrue;
   232 		}
   233 	}
   234 
   235 CTBitmap::~CTBitmap()
   236 	{
   237 	iFs.Close();
   238 	}
   239 
   240 void CTBitmap::RunTestCaseL(TInt aCurTestCase)
   241     {
   242     ((CTBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   243 	switch(aCurTestCase)
   244 		{
   245 	case 1:		
   246 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0550"));
   247 		TwoComprLines();
   248 		break;
   249 	case 2:
   250 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0517"));
   251 	// they are fast hence at the beginning
   252 		CheckScanlineL();
   253 		break;
   254 	case 3:
   255 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0534"));
   256 		Compress();
   257 		break;
   258 	case 4:
   259 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0518"));
   260 		StreamBitmap();
   261 		break;
   262 	case 5:
   263 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0519"));
   264 		StreamRectangle();
   265 		break;
   266 	case 6:
   267 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0523"));
   268 		LoadInSegments();
   269 		break;
   270 	case 7:
   271 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0524"));
   272 		SaveInSegments();
   273 		break;
   274 	case 8:
   275 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0525"));
   276 		MonoDetect();
   277 		break;
   278 	case 9:
   279 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0526"));
   280 		ChunkPileL();
   281 		break;
   282 	case 10:
   283 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0527"));
   284 		LargeBitmaps();
   285 		break;
   286 	case 12:
   287 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0528"));
   288 		HugeBitmaps();
   289 		break;
   290 	case 13:
   291 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0529"));
   292 		Resize();
   293 		break;
   294 	case 14:
   295 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0520"));
   296 		GetScanline();
   297 		break;
   298 	case 15:
   299 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0521"));
   300 		SetScanline();
   301 		break;
   302 	case 16:
   303 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0522"));
   304 		StretchScanline();
   305 		break;
   306 	case 17:
   307 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0530"));
   308 		BitmapUtil();
   309 		break;
   310 	case 18:
   311 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0531"));
   312 		InvalidBitmap();
   313 		break;
   314 	case 19:
   315 		((CTBitmapStep*)iStep)->SetTestStepID(_L(" GRAPHICS-FBSERV-0533"));
   316 		SaveAndLoadFast();
   317 		break;
   318 	case 20:
   319 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0532"));
   320 		SaveAndLoad();
   321 		break;
   322 	case 21:
   323 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0535"));
   324 		Color256BitmapUtil();
   325 		break;
   326 	case 22:
   327 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0536"));
   328 		HardwareBitmaps();
   329 		break;
   330 	case 23:
   331 		((CTBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   332 	//	BitmapTiming(); 
   333 		break;
   334 	case 24:
   335 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0537"));
   336 		INC036062L();
   337 		break;
   338 	case 25:
   339 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0538"));
   340 		PerformanceTest_INC036062L();
   341 		break;
   342 	case 26:
   343 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0539"));
   344 		INC037474L();
   345 		break;
   346 	case 27:
   347 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0540"));
   348 		DEF038286L();
   349 		break;
   350 	case 28:
   351 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0541"));
   352 		DEF038286_2L();
   353 		break;
   354 	case 29:
   355 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0542"));
   356 		MonohromeL();
   357 		break;
   358 	case 30:
   359 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0543"));
   360 		GetVerticalScanLineL();
   361 		break;
   362 	case 31:
   363 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0544"));
   364 		GetVerticalScanLinePerformanceL();
   365 		break;
   366 	case 32:
   367 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0545"));
   368 		DEF071843_16MAL();
   369 		((CTBitmapStep*)iStep)->RecordTestResultL();
   370 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0546"));	
   371 		DEF071843_16MUL();
   372 		((CTBitmapStep*)iStep)->RecordTestResultL();
   373 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0547"));
   374 		DEF071843_16ML();
   375 #ifdef _DEBUG
   376 		((CTBitmapStep*)iStep)->RecordTestResultL();
   377 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0549"));
   378 		//It uses Heap Allocation failure macro 
   379 		//which is supported only for debug mode	
   380 		DEF095361_16MAL();
   381 #endif		
   382 		break;
   383 	case 33:
   384 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0548"));
   385 		DEF074623_16MAL();
   386 		break;
   387 	case 34:
   388 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0551"));
   389 		TestPaletteCompressionL();
   390 		break;
   391 	case 35:
   392 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0552"));
   393 		TestSynchronousBackgroundPaletteCompressionL();
   394 		break;
   395 	case 36:
   396 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0553"));
   397 		TestAsynchronousBackgroundPaletteCompressionL();
   398 		break;
   399 	case 37:
   400 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0501"));
   401 		GetAllBitmapsIdsL();
   402 		break;
   403 	case 38:
   404 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0554"));
   405 		CheckBadBmp();
   406 		break; 
   407 	case 39:
   408 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0516"));
   409 		CheckSetDisplayModeL();
   410 		break; 	
   411 	case 40:
   412 /**
   413 	@SYMTestCaseID GRAPHICS-FBSERV-0619
   414 */
   415 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0619"));
   416 		MultiThreadedTestsL();
   417 		break;
   418 	case 41:
   419 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0612"));
   420 		TestBgCompressL();
   421 		break;
   422 	case 42:
   423 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0613"));
   424 		TestBgCompressInUseL();
   425 		break;
   426 	case 43:
   427 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0614"));
   428 		TestDisconnectWithBitmapL();
   429 		break;
   430 	case 44:
   431 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0617"));
   432 		TestTouchedAndVolatileL();
   433 		break;
   434 	case 45:
   435 		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0618"));
   436 		TestBitmapWhiteFillL();
   437 		break;
   438 	case 46:
   439 #ifdef _DEBUG
   440 	    ((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0661"));
   441 	    TestBitmapUtilWithUnsupportedBitmaps();
   442 #endif
   443         break;
   444 	case 47:
   445 		((CTBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   446 		((CTBitmapStep*)iStep)->CloseTMSGraphicsStep();
   447 		TestComplete();
   448 		break;
   449 	default:
   450 		((CTBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   451 		break;
   452 		}
   453 		
   454 	((CTBitmapStep*)iStep)->RecordTestResultL();
   455     }
   456    
   457 /**
   458 	@SYMTestCaseID
   459 	GRAPHICS-FBSERV-0516
   460 
   461 	@SYMTestCaseDesc
   462 	Checks that the display mode can be set 
   463 	to various modes, including EColor16MAP
   464 	
   465 	@SYMTestActions
   466 	
   467 	@SYMTestExpectedResults
   468 	Test should pass
   469 */  
   470 void CTBitmap::CheckSetDisplayModeL()
   471 	{
   472 	INFO_PRINTF1(_L("Check SetDisplayMode EColor16MAP"));
   473 
   474 	CFbsBitmap bmp;
   475 	User::LeaveIfError(bmp.Create(TSize(4,4),EColor16MA));
   476 	TInt ret=bmp.SetDisplayMode(EColor16MAP);
   477 	TEST(ret==KErrNone);
   478 	bmp.Reset();
   479 
   480 	User::LeaveIfError(bmp.Create(TSize(4,4),EColor16MU));
   481 	ret=bmp.SetDisplayMode(EColor16MAP);
   482 	TEST(ret==KErrNone);
   483 	bmp.Reset();
   484 
   485 	User::LeaveIfError(bmp.Create(TSize(4,4),EColor64K));
   486 	ret=bmp.SetDisplayMode(EColor16MAP);
   487 	TEST(ret==KErrArgument);
   488 	bmp.Reset();
   489 
   490 	User::LeaveIfError(bmp.Create(TSize(4,4),EColor16MAP));
   491 	ret=bmp.SetDisplayMode(EColor16MAP);
   492 	TEST(ret==KErrNone);
   493 
   494 	ret=bmp.SetDisplayMode(EColor16MU);
   495 	TEST(ret==KErrNone);
   496 	bmp.Reset();
   497 	
   498 	}    
   499 
   500 /**
   501 	@SYMTestCaseID
   502 	GRAPHICS-FBSERV-0517
   503 
   504 	@SYMTestCaseDesc
   505 	Compares a pixel retrieved with GetPixel and GetScanLine
   506 
   507 	@SYMTestActions
   508 	Zero fills a buffer which has an uneven length of bytes and
   509 	gets a pixel from a point which should coincide with
   510 	that of a point retrieved with scan line
   511 		
   512 	@SYMTestExpectedResults
   513 	Test should pass
   514 */
   515 void CTBitmap::CheckScanlineL()
   516 	{
   517 	INFO_PRINTF1(_L("Scanline sanity check"));
   518 
   519 	CFbsBitmap bmp;
   520 	User::LeaveIfError(bmp.Create(TSize(32,1),EGray2));
   521 
   522 	// try using a buffer that isn't a whole number of words long. 
   523 	TUint8 buffer[3];
   524 	Mem::FillZ(buffer,3);
   525 	TPtr8 scanline(buffer,3,3);
   526 	bmp.GetScanLine(scanline,TPoint(0,0),24,EGray2);
   527 
   528 	TRgb pixel(KRgbRed);
   529 	bmp.GetPixel(pixel,TPoint(0,0));
   530 
   531 	// getscanline and getpixel should agree
   532 	TEST(TRgb::Gray2(buffer[0] & 0x01) == pixel);
   533 
   534 	bmp.Reset();
   535 
   536 	
   537 	}
   538 
   539 /**
   540 	@SYMTestCaseID
   541 	GRAPHICS-FBSERV-0518
   542 
   543 	@SYMTestCaseDesc
   544 	Streams different bitmap size of different colour depth.
   545 
   546 	@SYMTestActions
   547 
   548 	
   549 	@SYMTestExpectedResults
   550 	Test should pass
   551 */
   552 void CTBitmap::StreamBitmap()
   553 	{
   554 	INFO_PRINTF1(_L("Test Bitmap Streaming"));
   555 
   556 	DoStreamBitmapSizes(EGray2);
   557 	DoStreamBitmapSizes(EGray4);
   558 	DoStreamBitmapSizes(EGray16);
   559 	DoStreamBitmapSizes(EGray256);
   560 	DoStreamBitmapSizes(EColor16);
   561 	DoStreamBitmapSizes(EColor256);
   562 	DoStreamBitmapSizes(EColor4K);
   563 	DoStreamBitmapSizes(EColor64K);
   564 	DoStreamBitmapSizes(EColor16M);
   565 	DoStreamBitmapSizes(EColor16MU);
   566 	DoStreamBitmapSizes(EColor16MAP);
   567 	}
   568 
   569 void CTBitmap::DoStreamBitmapSizes(TDisplayMode aDispMode)
   570 	{
   571 	const TSize smallStreamBitmapSize(32,10);
   572 	const TSize largeStreamBitmapSize(256,256);
   573 	const TSize oddStreamBitmapSize(31,2);
   574 
   575 	DoStreamBitmap(smallStreamBitmapSize,aDispMode,ETrue);
   576 	DoStreamBitmap(smallStreamBitmapSize,aDispMode,EFalse);
   577 	DoStreamBitmap(largeStreamBitmapSize,aDispMode,ETrue);
   578 	DoStreamBitmap(largeStreamBitmapSize,aDispMode,EFalse);
   579 	DoStreamBitmap(oddStreamBitmapSize,aDispMode,ETrue);
   580 	DoStreamBitmap(oddStreamBitmapSize,aDispMode,EFalse);
   581 	}
   582 
   583 void CTBitmap::DoStreamBitmap(const TSize& aSize,TDisplayMode aDispMode,TBool aBlank)
   584 	{
   585 	__UHEAP_MARK;
   586 
   587 	CFbsBitmapEx bmp;
   588 	TInt ret = bmp.Create(aSize,aDispMode);
   589 	TEST2(ret, KErrNone);
   590 
   591 	if (aBlank)
   592 		BlankBitmap(bmp);
   593 	else
   594 		FillBitmap(bmp);
   595 
   596 	CDirectFileStore* writestore=NULL;
   597 
   598 	TRAP(ret,writestore=CDirectFileStore::ReplaceL(iFs,KTempFilename,EFileStream|EFileWrite));
   599 	TEST2(ret, KErrNone);
   600 
   601 	TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
   602 
   603 	TRAP(ret,writestore->SetTypeL(uidtype));
   604 	TEST2(ret, KErrNone);
   605 
   606 	RStoreWriteStream writestrm;
   607 	TStreamId headerid(0);
   608 
   609 	TRAP(ret,headerid=writestrm.CreateL(*writestore));
   610 	TEST2(ret, KErrNone);
   611 
   612 	TRAP(ret,writestore->SetRootL(headerid));
   613 	TEST2(ret, KErrNone);
   614 
   615 	TRAP(ret,bmp.ExternalizeL(writestrm));
   616 	TEST2(ret, KErrNone);
   617 
   618 	writestrm.Close();
   619 	delete writestore;
   620 
   621 	CFbsBitmapEx bmpst;
   622 	CDirectFileStore* readstore=NULL;
   623 
   624 	TRAP(ret,readstore=CDirectFileStore::OpenL(iFs,KTempFilename,EFileStream|EFileRead));
   625 	TEST2(ret, KErrNone);
   626 
   627 	RStoreReadStream readstrm;
   628 	headerid=readstore->Root();
   629 
   630 	TRAP(ret,readstrm.OpenL(*readstore,headerid));
   631 	TEST2(ret, KErrNone);
   632 
   633 	TRAP(ret,bmpst.InternalizeL(readstrm));
   634 	TEST2(ret, KErrNone);
   635 
   636 	readstrm.Close();
   637 	delete readstore;
   638 
   639 	CompareBitmaps(bmp,bmpst,EColor16M);
   640 
   641 	iFs.Delete(KTempFilename);
   642 	bmp.Reset();
   643 	bmpst.Reset();
   644 	User::Heap().Check();
   645 	__UHEAP_MARKEND;
   646 	}
   647 
   648 /**
   649 	@SYMTestCaseID
   650 	GRAPHICS-FBSERV-0519
   651 
   652 	@SYMTestCaseDesc
   653 	Streams bitmap rectangles of different colour depth
   654 	to file store and reads them back again.
   655 
   656 	@SYMTestActions
   657 	Bitmap rectangles are externalized to file store and
   658 	read back again. ScanLine is used and compared to GetPixel
   659 	from the bitmap read back from file store.
   660 	
   661 	@SYMTestExpectedResults
   662 	Test should pass
   663 */
   664 void CTBitmap::StreamRectangle()
   665 	{
   666 	INFO_PRINTF1(_L("Test Rectangle Streaming"));
   667 
   668 	DoStreamRectangle(EGray2,ETrue);
   669 	DoStreamRectangle(EGray2,EFalse);
   670 	DoStreamRectangle(EGray4,ETrue);
   671 	DoStreamRectangle(EGray4,EFalse);
   672 	DoStreamRectangle(EGray16,ETrue);
   673 	DoStreamRectangle(EGray16,EFalse);
   674 	DoStreamRectangle(EGray256,ETrue);
   675 	DoStreamRectangle(EGray256,EFalse);
   676 	DoStreamRectangle(EColor16,ETrue);
   677 	DoStreamRectangle(EColor16,EFalse);
   678 	DoStreamRectangle(EColor256,ETrue);
   679 	DoStreamRectangle(EColor256,EFalse);
   680 	DoStreamRectangle(EColor4K,ETrue);
   681 	DoStreamRectangle(EColor4K,EFalse);
   682 	DoStreamRectangle(EColor64K,ETrue);
   683 	DoStreamRectangle(EColor64K,EFalse);
   684 	DoStreamRectangle(EColor16M,ETrue);
   685 	DoStreamRectangle(EColor16M,EFalse);
   686 	DoStreamRectangle(EColor16MU,ETrue);
   687 	DoStreamRectangle(EColor16MU,EFalse);
   688 	DoStreamRectangle(EColor16MAP,ETrue);
   689 	DoStreamRectangle(EColor16MAP,EFalse);
   690 	}
   691 
   692 void CTBitmap::DoStreamRectangle(TDisplayMode aDispMode,TBool aBlank)
   693 	{
   694 	__UHEAP_MARK;
   695 	CFbsBitmapEx bmp;
   696 	TInt ret = bmp.Create(TSize(160,80),aDispMode);
   697 	TEST2(ret, KErrNone);
   698 
   699 	if (aBlank)
   700 		BlankBitmap(bmp);
   701 	else
   702 		FillBitmap(bmp);
   703 
   704 	CDirectFileStore* writestore=NULL;
   705 	TRAP(ret,writestore=CDirectFileStore::ReplaceL(iFs,KTempFilename,EFileStream|EFileWrite));
   706 	TEST2(ret, KErrNone);
   707 
   708 	TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
   709 	TRAP(ret,writestore->SetTypeL(uidtype));
   710 	TEST2(ret, KErrNone);
   711 
   712 	RStoreWriteStream writestrm;
   713 	TStreamId headerid(0);
   714 	TRAP(ret,headerid=writestrm.CreateL(*writestore));
   715 	TEST2(ret, KErrNone);
   716 
   717 	TRAP(ret,writestore->SetRootL(headerid));
   718 	TEST2(ret, KErrNone);
   719 
   720 	TRAP(ret,bmp.ExternalizeRectangleL(writestrm,TRect(40,20,120,60)));
   721 	TEST2(ret, KErrNone);
   722 
   723 	writestrm.Close();
   724 	delete writestore;
   725 
   726 	CFbsBitmapEx bmpst;
   727 	CDirectFileStore* readstore=NULL;
   728 	TRAP(ret,readstore=CDirectFileStore::OpenL(iFs,KTempFilename,EFileStream|EFileRead));
   729 	TEST2(ret, KErrNone);
   730 
   731 	RStoreReadStream readstrm;
   732 	headerid=readstore->Root();
   733 	TRAP(ret,readstrm.OpenL(*readstore,headerid));
   734 	TEST2(ret, KErrNone);
   735 
   736 	TRAP(ret,bmpst.InternalizeL(readstrm));
   737 	TEST2(ret, KErrNone);
   738 
   739 	readstrm.Close();
   740 	delete readstore;
   741 
   742 	TInt scanLineLength = CFbsBitmap::ScanLineLength(80,aDispMode);
   743 	TUint8* buffer = new TUint8[scanLineLength];
   744 	TUint8* bufferst = new TUint8[scanLineLength];
   745 	Mem::FillZ(buffer,scanLineLength);
   746 	Mem::FillZ(bufferst,scanLineLength);
   747 	TPtr8 scanline(buffer,scanLineLength,scanLineLength);
   748 	TPtr8 scanlinest(bufferst,scanLineLength,scanLineLength);
   749 
   750 	for(TInt yy=0;yy<40;yy++)
   751 		{
   752 		bmp.GetScanLine(scanline,TPoint(40,yy+20),80,aDispMode);
   753 		bmpst.GetScanLine(scanlinest,TPoint(0,yy),80,aDispMode);
   754 		
   755 		if(aDispMode != EColor16MU)
   756 			{
   757 			TInt memRet = Mem::Compare(buffer,scanLineLength,bufferst,scanLineLength);
   758 			TEST(memRet == 0);
   759 			}
   760 		else
   761 			{
   762 			TInt pixelsToCompare = scanLineLength / 4;
   763 			TUint8* bufferCur = buffer;
   764 			TUint8* bufferstCur = bufferst;
   765 			
   766 			//top byte is unused, and would be more accurate to ignore it
   767 			for(TInt ii = 0; ii < pixelsToCompare; ii++)
   768 				{
   769 				TInt memRet = Mem::Compare(bufferCur,3,bufferstCur,3);
   770 				TEST(memRet == 0);
   771 				bufferCur += 4;
   772 				bufferstCur += 4;
   773 				}
   774 			}	
   775 		}
   776 	delete [] bufferst;
   777 	delete [] buffer;
   778 
   779 	iFs.Delete(KTempFilename);
   780 	bmp.Reset();
   781 	bmpst.Reset();
   782 	User::Heap().Check();
   783 	__UHEAP_MARKEND;
   784 	}
   785 
   786 /**
   787 	@SYMTestCaseID
   788 	GRAPHICS-FBSERV-0520
   789 
   790 	@SYMTestCaseDesc
   791 	Calls GetScanLine for different screen modes with
   792 	the bitmap compressed and uncompressed and checks
   793 	if the pixels are correct.
   794 
   795 	@SYMTestActions
   796 
   797 	@SYMTestExpectedResults
   798 	Test should pass
   799 */
   800 void CTBitmap::GetScanline()
   801 	{
   802 	INFO_PRINTF1(_L("Test GetScanline"));
   803 
   804 	const TSize size1(257,5);
   805 	const TSize size2(33,17);
   806 
   807 	INFO_PRINTF1(_L("EGray2"));
   808 	DoGetScanline(size1,EGray2);
   809 	DoGetScanline(size2,EGray2);
   810 	DoGetScanlineAlt(EGray2);
   811 
   812 	INFO_PRINTF1(_L(" EGray4"));
   813 	DoGetScanline(size1,EGray4);
   814 	DoGetScanline(size2,EGray4);
   815 	DoGetScanlineAlt(EGray4);
   816 
   817 	INFO_PRINTF1(_L(" EGray16"));
   818 	DoGetScanline(size1,EGray16);
   819 	DoGetScanline(size2,EGray16);
   820 	DoGetScanlineAlt(EGray16);
   821 
   822 	INFO_PRINTF1(_L(" EGray256"));
   823 	DoGetScanline(size1,EGray256);
   824 	DoGetScanline(size2,EGray256);
   825 	DoGetScanlineAlt(EGray256);
   826 
   827 	INFO_PRINTF1(_L(" EColor16"));
   828 	DoGetScanline(size1,EColor16);
   829 	DoGetScanline(size2,EColor16);
   830 	DoGetScanlineAlt(EColor16);
   831 
   832 	INFO_PRINTF1(_L(" EColor256"));
   833 	DoGetScanline(size1,EColor256);
   834 	DoGetScanline(size2,EColor256);
   835 	DoGetScanlineAlt(EColor256);
   836 
   837 	INFO_PRINTF1(_L(" EColor4K"));
   838 	DoGetScanline(size1,EColor4K);
   839 	DoGetScanline(size2,EColor4K);
   840 	DoGetScanlineAlt(EColor4K);
   841 
   842 	INFO_PRINTF1(_L(" EColor64K"));
   843 	DoGetScanline(size1,EColor64K);
   844 	DoGetScanline(size2,EColor64K);
   845 	DoGetScanlineAlt(EColor64K);
   846 
   847 	INFO_PRINTF1(_L(" EColor16M"));
   848 	DoGetScanline(size1,EColor16M);
   849 	DoGetScanline(size2,EColor16M);
   850 	DoGetScanlineAlt(EColor16M);
   851 
   852 	INFO_PRINTF1(_L(" EColor16MA"));
   853 	DoGetScanline(size1,EColor16MA);
   854 	DoGetScanline(size2,EColor16MA);
   855 	DoGetScanlineAlt(EColor16MA);
   856 
   857 	INFO_PRINTF1(_L(" EColor16MU"));
   858 	DoGetScanline(size1,EColor16MU);
   859 	DoGetScanline(size2,EColor16MU);
   860 	DoGetScanlineAlt(EColor16MU);
   861 
   862 	INFO_PRINTF1(_L(" EColor16MAP"));
   863 	DoGetScanline(size1,EColor16MAP);
   864 	DoGetScanline(size2,EColor16MAP);
   865 	DoGetScanlineAlt(EColor16MAP);
   866 
   867 	INFO_PRINTF1(_L("\n"));
   868 	}
   869 
   870 void CTBitmap::DoGetScanline(const TSize& aSize,TDisplayMode aDispMode)
   871 	{
   872 	__UHEAP_MARK;
   873 	CFbsBitmapEx bmp;
   874 	TInt ret = bmp.Create(aSize,aDispMode);
   875 	TEST2(ret, KErrNone);
   876 	FillBitmap(bmp);
   877 
   878 	DoGetScanlineCheck1(bmp, bmp, aSize, aDispMode);
   879 	DoGetScanlineCheck2(bmp, bmp, aSize, aDispMode);
   880 	DoGetScanlineCheck3(bmp, aDispMode);
   881 
   882 	ret = bmp.Create(aSize,aDispMode);
   883 	TEST2(ret, KErrNone);
   884 
   885 	StripeBitmap(bmp);
   886 	CFbsBitmapEx ref;
   887 	ret = ref.Create(aSize,aDispMode);
   888 	TEST2(ret, KErrNone);
   889 
   890 	CopyBitmap(ref, bmp);
   891 	ret = bmp.Compress();
   892 	TEST2(ret, KErrNone);
   893 
   894 	DoGetScanlineCheck1(bmp, ref, aSize, aDispMode);
   895 
   896 	ref.Reset();
   897 	bmp.Reset();
   898 	User::Heap().Check();
   899 	__UHEAP_MARKEND;
   900 	}
   901 
   902 void CTBitmap::DoGetScanlineCheck1(CFbsBitmap& aBitmap,CFbsBitmap& aReference,const TSize& aSize,TDisplayMode aDispMode)
   903 	{
   904 	TInt byteWidth = CFbsBitmap::ScanLineLength(aSize.iWidth,aDispMode);
   905 	TUint8* buffer = new TUint8[byteWidth + 1];
   906 	buffer[byteWidth] = KCheckValue;
   907 	TPtr8 scanline(buffer,byteWidth,byteWidth);
   908 
   909 	for(TInt xStart = 0; xStart <= 33; xStart++)
   910 		{
   911 		for (TInt xLength = 1; xLength <= 33; xLength++)
   912 			{
   913 			TInt xEnd = xStart + xLength;
   914 			if (xEnd <= aSize.iWidth)
   915 				{
   916 				aBitmap.GetScanLine(scanline,TPoint(xStart,0),xLength,aDispMode);
   917 				for(TInt xx = xStart; xx < xEnd; xx++)
   918 					{
   919 					TRgb color;
   920 					aReference.GetPixel(color,TPoint(xx,0));
   921 					TRgb bufferColor = ExtractRgb(buffer,xx - xStart,aDispMode);
   922 					TEST(bufferColor == color);
   923 					}
   924 				}
   925 			}
   926 		}
   927 
   928 	for(TInt yy = 0; yy < aSize.iHeight; yy++)
   929 		{
   930 		aBitmap.GetScanLine(scanline,TPoint(0,yy),aSize.iWidth,aDispMode);
   931 		for(TInt xx = 0; xx < aSize.iWidth; xx++)
   932 			{
   933 			TRgb color;
   934 			aReference.GetPixel(color,TPoint(xx,yy));
   935 			TRgb bufferColor = ExtractRgb(buffer,xx,aDispMode);
   936 			TEST(bufferColor == color);
   937 			}
   938 		}
   939 
   940 	TEST(buffer[byteWidth] == KCheckValue);
   941 	delete [] buffer;
   942 	}
   943 
   944 void CTBitmap::DoGetScanlineCheck2(CFbsBitmap& aBitmap,CFbsBitmap& aReference,const TSize& aSize,TDisplayMode aDispMode)
   945 	{
   946 	TInt byteHeight = CFbsBitmap::ScanLineLength(aSize.iHeight,ERgb);
   947 	TUint8* buffer = new TUint8[byteHeight];
   948 	TPtr8 scanline(buffer,byteHeight,byteHeight);
   949 
   950 	TInt xx;
   951 	for(xx = 0; xx < aSize.iWidth; xx++)
   952 		{
   953 		aBitmap.GetVerticalScanLine(scanline,xx,aDispMode);
   954 		for(TInt yy = 0; yy < aSize.iHeight; yy++)
   955 			{
   956 			TRgb color;
   957 			aReference.GetPixel(color,TPoint(xx,yy));
   958 			TRgb bufferColor = ExtractRgb(buffer,yy,aDispMode);
   959 			TEST(bufferColor == color);
   960 			}
   961 		}
   962 
   963 	for(xx = 0; xx < aSize.iWidth; xx++)
   964 		{
   965 		aBitmap.GetVerticalScanLine(scanline,xx,ERgb);
   966 		for(TInt yy = 0; yy < aSize.iHeight; yy++)
   967 			{
   968 			TRgb color;
   969 			aReference.GetPixel(color,TPoint(xx,yy));
   970 			TRgb bufferColor = ExtractRgb(buffer,yy,ERgb);
   971 			TEST(bufferColor == color);
   972 			}
   973 		}
   974 
   975 	delete [] buffer;
   976 	}
   977 
   978 void CTBitmap::DoGetScanlineCheck3(CFbsBitmap& aBitmap,TDisplayMode aDispMode)
   979 	{
   980 	TUint32 wordline=0xffffffff;
   981 	TPtr8 scanline((TUint8*)&wordline,4,4);
   982 	aBitmap.Create(TSize(31,1),aDispMode);
   983 	aBitmap.LockHeap();
   984 	Mem::Fill(aBitmap.DataAddress(),CFbsBitmap::ScanLineLength(31,aDispMode),0xff);
   985 	aBitmap.UnlockHeap();
   986 	aBitmap.SetScanLine(scanline,0);
   987 	TUint32 expected=0;
   988 
   989 	for(TInt zz=1;zz<31;zz++)
   990 		{
   991 		expected|=1<<(zz-1);
   992 		wordline=0;
   993 		aBitmap.GetScanLine(scanline,TPoint(0,0),zz,EGray2);
   994 		TUint32 actual=wordline&expected;
   995 		TEST(actual==expected);
   996 		}
   997 	}
   998 
   999 /* this function calls CheckScanLine with various screen modes, and with the bitmap
  1000    compressed, and not compressed
  1001  */
  1002 void CTBitmap::DoGetScanlineAlt(TDisplayMode aDispMode)
  1003 	{
  1004 	__UHEAP_MARK;
  1005 
  1006 	CFbsBitmapEx bmp;
  1007 	TInt ret = bmp.Create(TSize(256,3),aDispMode);
  1008 	TEST2(ret, KErrNone);
  1009 
  1010 	FillBitmap(bmp);
  1011 
  1012 	CheckScanLine(bmp,bmp,EGray2);
  1013 	CheckScanLine(bmp,bmp,EGray4);
  1014 	CheckScanLine(bmp,bmp,EGray16);
  1015 	CheckScanLine(bmp,bmp,EGray256);
  1016 	CheckScanLine(bmp,bmp,EColor16);
  1017 	CheckScanLine(bmp,bmp,EColor256);
  1018 	CheckScanLine(bmp,bmp,EColor4K);
  1019 	CheckScanLine(bmp,bmp,EColor64K);
  1020 	CheckScanLine(bmp,bmp,EColor16M);
  1021 	CheckScanLine(bmp,bmp,ERgb);
  1022 	CheckScanLine(bmp,bmp,EColor16MU);
  1023 	CheckScanLine(bmp,bmp,EColor16MAP);
  1024 
  1025 	CFbsBitmapEx ref;
  1026 	ret = ref.Create(bmp.SizeInPixels(),aDispMode);
  1027 	TEST2(ret, KErrNone);
  1028 	CopyBitmap(ref,bmp);
  1029 	bmp.Compress();
  1030 
  1031 	CheckScanLine(bmp,ref,EGray2);
  1032 	CheckScanLine(bmp,ref,EGray4);
  1033 	CheckScanLine(bmp,ref,EGray16);
  1034 	CheckScanLine(bmp,ref,EGray256);
  1035 	CheckScanLine(bmp,ref,EColor16);
  1036 	CheckScanLine(bmp,ref,EColor256);
  1037 	CheckScanLine(bmp,ref,EColor4K);
  1038 	CheckScanLine(bmp,ref,EColor64K);
  1039 	CheckScanLine(bmp,ref,EColor16M);
  1040 	CheckScanLine(bmp,ref,ERgb);
  1041 	CheckScanLine(bmp,ref,EColor16MU);
  1042 	CheckScanLine(bmp,ref,EColor16MAP);
  1043 
  1044 	User::Heap().Check();
  1045 	__UHEAP_MARKEND;
  1046 	}
  1047 
  1048 void CTBitmap::CheckScanLine(CFbsBitmapEx& aBitmap,CFbsBitmapEx& aReference,TDisplayMode aDispMode)
  1049 	{
  1050 	const TSize bmpSize(aBitmap.SizeInPixels());
  1051 	TInt byteWidth = CFbsBitmap::ScanLineLength(bmpSize.iWidth,aDispMode);
  1052 	TUint8* buffer = new TUint8[byteWidth + 1];
  1053 	buffer[byteWidth] = KCheckValue;
  1054 	TPtr8 scanLine(buffer,byteWidth,byteWidth);
  1055 
  1056 	aBitmap.GetScanLine(scanLine,TPoint(0,1),bmpSize.iWidth,aDispMode);
  1057 
  1058 	for(TInt xx = 0; xx < bmpSize.iWidth; xx++)
  1059 		{
  1060 		TRgb color;
  1061 		aReference.GetPixel(color,TPoint(xx,1));
  1062 		TRgb bufferColor = ExtractRgb(buffer,xx,aDispMode);
  1063 		switch (aDispMode)
  1064 			{
  1065 		case EGray2:
  1066 			if (color.Gray4() == 0 || color.Gray4() == 3) // doesn't check in great detail because dithering occurs
  1067 				TEST(bufferColor.Gray2() == color.Gray2());
  1068 			break;
  1069 		case EGray4:
  1070 			if (aBitmap.DisplayMode() != EGray16) // doesn't check EGray16 because dithering occurs
  1071 				TEST(bufferColor.Gray4() == color.Gray4());
  1072 			break;
  1073 		case EGray16:
  1074 			TEST(bufferColor.Gray16() == color.Gray16());
  1075 			break;
  1076 		case EGray256:
  1077 			TEST(bufferColor.Gray256() == color.Gray256());
  1078 			break;
  1079 		case EColor16:
  1080 			TEST(bufferColor.Color16() == color.Color16());
  1081 			break;
  1082 		case EColor256:
  1083 			TEST(bufferColor.Color256() == color.Color256());
  1084 			break;
  1085 		case EColor4K:
  1086 			TEST(bufferColor.Color4K() == color.Color4K());
  1087 			break;
  1088 		case EColor64K:
  1089 			TEST(bufferColor.Color64K() == color.Color64K());
  1090 			break;
  1091 		case EColor16M:
  1092 			TEST(bufferColor.Color16M() == color.Color16M());
  1093 			break;
  1094 		case ERgb:
  1095 			TEST(bufferColor == color);
  1096 			break;
  1097 		case EColor16MU:
  1098 			if (aReference.DisplayMode()==EColor16MAP || aReference.DisplayMode()==EColor16MA)
  1099 				color.SetAlpha(0xff);
  1100 			CompareColourLikeness(bufferColor, color);			
  1101 			break;
  1102 		case EColor16MAP:
  1103 			//Compare the TRgb values.  For an exact match to work the comparison would
  1104 			//need to be done in PMA space.
  1105 			color.SetInternal(color.Color16MAP());
  1106 			bufferColor.SetInternal(bufferColor.Color16MAP());
  1107 			CompareColourLikeness(bufferColor, color);			
  1108 			break;	
  1109 		default:
  1110 			break;
  1111 			};
  1112 		}
  1113 
  1114 	TEST(buffer[byteWidth] == KCheckValue);
  1115 	delete [] buffer;
  1116 	}
  1117 
  1118 /**
  1119 Compares two TRgbs and tests if they are similar colour.
  1120 This is required because there may be some rounding errors when converting bitmaps from one display mode to another
  1121 or due to alpha blending calculations.
  1122 
  1123 @param aSrc is the source colour
  1124 @param aDest is the destination colour
  1125 @param aDifference use this value for colour difference.  Value of 0 use KColourDifference;
  1126 */
  1127 void CTBitmap::CompareColourLikeness(const TRgb& aSrc, const TRgb& aDest, TInt aDifference)
  1128 	{
  1129 	const TInt KColourDifference = 2;	// Acceptable difference to check for
  1130 	TInt diff;
  1131 	
  1132 	if (aDifference==0)
  1133 		diff=KColourDifference;
  1134 	else
  1135 		diff=aDifference;
  1136 	
  1137 	TInt redDiff = Abs(aSrc.Red() - aDest.Red());
  1138 	TInt greenDiff = Abs(aSrc.Green() - aDest.Green());	
  1139 	TInt blueDiff = Abs(aSrc.Blue() - aDest.Blue());	
  1140 	TInt alphaDiff = Abs(aSrc.Alpha() - aDest.Alpha());	
  1141 	
  1142 	// Test each channel
  1143 	TEST(redDiff <= diff);
  1144 	TEST(greenDiff <= diff);
  1145 	TEST(blueDiff <= diff);
  1146 	TEST(alphaDiff <= diff);
  1147 	
  1148 	// the code below is useful for a breakpoint, to inspect the differences, in case of failure
  1149 /**	
  1150 	if ((redDiff > diff)||(greenDiff > diff)||(blueDiff > diff)||(alphaDiff > diff))
  1151 		TInt temp=1;
  1152 */
  1153 	}
  1154 
  1155 /**
  1156 	@SYMTestCaseID
  1157 	GRAPHICS-FBSERV-0521
  1158 
  1159 	@SYMTestCaseDesc
  1160 	Sets a scanline of random values into
  1161 	bitmaps of different color depths
  1162 
  1163 	@SYMTestActions
  1164 	
  1165 	@SYMTestExpectedResults
  1166 	Test should pass
  1167 */
  1168 void CTBitmap::SetScanline()
  1169 	{
  1170 	INFO_PRINTF1(_L("Test SetScanline"));
  1171 
  1172 	DoSetScanline(EGray2);
  1173 	DoSetScanline(EGray4);
  1174 	DoSetScanline(EGray16);
  1175 	DoSetScanline(EGray256);
  1176 	DoSetScanline(EColor16);
  1177 	DoSetScanline(EColor256);
  1178 	DoSetScanline(EColor4K);
  1179 	DoSetScanline(EColor64K);
  1180 	DoSetScanline(EColor16M);
  1181 	DoSetScanline(EColor16MU);
  1182 	DoSetScanline(EColor16MAP);
  1183 	}
  1184 
  1185 void CTBitmap::DoSetScanline(TDisplayMode aDispMode)
  1186 	{
  1187 	__UHEAP_MARK;
  1188 	CFbsBitmap bmp;
  1189 
  1190 	TInt ret = bmp.Create(TSize(256,2),aDispMode);
  1191 	TEST2(ret, KErrNone);
  1192 
  1193 	TInt scanLineLength = CFbsBitmap::ScanLineLength(256,aDispMode);
  1194 	TUint8* buffer = new TUint8[scanLineLength];
  1195 	TEST(buffer != NULL);
  1196 	TPtr8 scanline(buffer,scanLineLength,scanLineLength);
  1197 
  1198 	TUint8* bufptr = buffer;
  1199 	TInt64 seed = bmp.Handle();
  1200 	for(TInt count = 0; count < scanLineLength; count++)
  1201 		*bufptr++ = (TUint8)Math::Rand(seed);
  1202 
  1203 	bmp.SetScanLine(scanline,0);
  1204 	bmp.SetScanLine(scanline,1);
  1205 
  1206 	bmp.LockHeap();
  1207 	TUint8* data = (TUint8*)bmp.DataAddress();
  1208 	bmp.UnlockHeap();
  1209 	ret = Mem::Compare(buffer,scanLineLength,data,scanLineLength);
  1210 	TEST(ret == 0);
  1211 
  1212 	data += scanLineLength;
  1213 	ret = Mem::Compare(buffer,scanLineLength,data,scanLineLength);
  1214 	TEST(ret == 0);
  1215 
  1216 	delete [] buffer;
  1217 	bmp.Reset();
  1218 	User::Heap().Check();
  1219 	__UHEAP_MARKEND;
  1220 	}
  1221 
  1222 /**
  1223 	@SYMTestCaseID
  1224 	GRAPHICS-FBSERV-0522
  1225 
  1226 	@SYMTestCaseDesc
  1227 	Stretches a scan line to make it
  1228 	double as long for different colour depths
  1229 	tested on both small and large bitmaps.
  1230 
  1231 	@SYMTestActions
  1232 
  1233 	@SYMTestExpectedResults
  1234 	Test should pass
  1235 */
  1236 void CTBitmap::StretchScanline()
  1237 	{
  1238 	INFO_PRINTF1(_L("Test StretchScanline"));
  1239 
  1240 	const TSize smallBitmapSize(226,2);
  1241 	const TSize largeBitmapSize(1026,40);
  1242 
  1243 	INFO_PRINTF1(_L("EGray2"));
  1244 	DoStretchScanline(smallBitmapSize,EGray2);
  1245 	DoStretchScanline(largeBitmapSize,EGray2);
  1246 
  1247 	INFO_PRINTF1(_L(" EGray4"));
  1248 	DoStretchScanline(smallBitmapSize,EGray4);
  1249 	DoStretchScanline(largeBitmapSize,EGray4);
  1250 
  1251 	INFO_PRINTF1(_L(" EGray16"));
  1252 	DoStretchScanline(smallBitmapSize,EGray16);
  1253 	DoStretchScanline(largeBitmapSize,EGray16);
  1254 
  1255 	INFO_PRINTF1(_L(" EGray256"));
  1256 	DoStretchScanline(smallBitmapSize,EGray256);
  1257 	DoStretchScanline(largeBitmapSize,EGray256);
  1258 
  1259 	INFO_PRINTF1(_L(" EColor16"));
  1260 	DoStretchScanline(smallBitmapSize,EColor16);
  1261 	DoStretchScanline(largeBitmapSize,EColor16);
  1262 
  1263 	INFO_PRINTF1(_L(" EColor256"));
  1264 	DoStretchScanline(smallBitmapSize,EColor256);
  1265 	DoStretchScanline(largeBitmapSize,EColor256);
  1266 
  1267 	INFO_PRINTF1(_L(" EColor4K"));
  1268 	DoStretchScanline(smallBitmapSize,EColor4K);
  1269 	DoStretchScanline(largeBitmapSize,EColor4K);
  1270 
  1271 	INFO_PRINTF1(_L(" EColor64K"));
  1272 	DoStretchScanline(smallBitmapSize,EColor64K);
  1273 	DoStretchScanline(largeBitmapSize,EColor64K);
  1274 
  1275 	INFO_PRINTF1(_L(" EColor16M"));
  1276 	DoStretchScanline(smallBitmapSize,EColor16M);
  1277 	DoStretchScanline(largeBitmapSize,EColor16M);
  1278 
  1279 	INFO_PRINTF1(_L(" EColor16MU"));
  1280 	DoStretchScanline(smallBitmapSize,EColor16MU);
  1281 	DoStretchScanline(largeBitmapSize,EColor16MU);
  1282 	
  1283 	INFO_PRINTF1(_L(" EColor16MA"));
  1284 	DoStretchScanline(smallBitmapSize,EColor16MA);
  1285 	DoStretchScanline(largeBitmapSize,EColor16MA);
  1286 
  1287 	INFO_PRINTF1(_L(" EColor16MAP"));
  1288 	DoStretchScanline(smallBitmapSize,EColor16MAP);
  1289 	DoStretchScanline(largeBitmapSize,EColor16MAP);
  1290 	
  1291 	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor16M, ETrue);
  1292 	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor16M, ETrue);
  1293 	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor16MU, ETrue);
  1294 	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor16MU, ETrue);
  1295 	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor16MA, ETrue);
  1296 	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor16MA, ETrue);
  1297 	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor64K, ETrue);
  1298 	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor64K, ETrue);
  1299 	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor4K, ETrue);
  1300 	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor4K, ETrue);
  1301 	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor256, ETrue);
  1302 	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor256, ETrue);
  1303 	
  1304 	DoStretchScanline(smallBitmapSize,EColor16M,EColor16MAP, ETrue);
  1305 	DoStretchScanline(largeBitmapSize,EColor16M,EColor16MAP, ETrue);
  1306 	DoStretchScanline(smallBitmapSize,EColor16MU,EColor16MAP, ETrue);
  1307 	DoStretchScanline(largeBitmapSize,EColor16MU,EColor16MAP, ETrue);
  1308 	DoStretchScanline(smallBitmapSize,EColor16MA,EColor16MAP, ETrue);
  1309 	DoStretchScanline(largeBitmapSize,EColor16MA,EColor16MAP, ETrue);
  1310 	DoStretchScanline(smallBitmapSize,EColor64K,EColor16MAP, ETrue);
  1311 	DoStretchScanline(largeBitmapSize,EColor64K,EColor16MAP, ETrue);
  1312 	DoStretchScanline(smallBitmapSize,EColor4K,EColor16MAP, ETrue);
  1313 	DoStretchScanline(largeBitmapSize,EColor4K,EColor16MAP, ETrue);
  1314 	DoStretchScanline(smallBitmapSize,EColor256,EColor16MAP, ETrue);
  1315 	DoStretchScanline(largeBitmapSize,EColor256,EColor16MAP, ETrue);
  1316 	
  1317 	DoStretchScanline(smallBitmapSize,EColor16MU,EColor16M, ETrue);
  1318 	DoStretchScanline(largeBitmapSize,EColor16MU,EColor16M, ETrue);
  1319 	
  1320 	INFO_PRINTF1(_L("\n"));
  1321 	}
  1322 
  1323 void CTBitmap::DoStretchScanline(const TSize& aSize,TDisplayMode aDispMode)
  1324 	{
  1325 	DoStretchScanline(aSize,aDispMode,aDispMode, EFalse);
  1326 	}
  1327 
  1328 /* this function is used to determine an acceptable colour difference based on the screen mode 
  1329    and the alpha value.  This is because when converting from PMA to non pre-multiplied, there
  1330    can be large errors, especially if alpha is small.
  1331  */	
  1332 TInt CTBitmap::ColorDifference(TDisplayMode aMode, TInt aAlpha)
  1333 	{
  1334 	switch (aMode)
  1335 		{
  1336 	case EGray2:// Monochrome display mode (1 bpp)
  1337 		return 0xff>>1;
  1338 	case EGray4:// Four grayscales display mode (2 bpp)
  1339 		return 0xff>>2;
  1340 	case EGray16:// 16 grayscales display mode (4 bpp)
  1341 		return 0xff>>2;
  1342 	case EGray256:// 256 grayscales display mode (8 bpp)
  1343 		return 0xff>>2;
  1344 	case EColor16:// Low colour EGA 16 colour display mode (4 bpp)
  1345 		return 0xff>>2;
  1346 	case EColor256: // 256 colour display mode (8 bpp)
  1347 		return 0xff>>2;
  1348 	case EColor64K: // 64,000 colour display mode (16 bpp) 
  1349 		return 0xff>>5;
  1350 	case EColor16M: // True colour display mode (24 bpp)
  1351 		return 0xff>>5;
  1352 	case EColor4K: // 4096 colour display (12 bpp).
  1353 		return 0xff>>4;
  1354 	case EColor16MU:// True colour display mode (32 bpp, but top byte is unused and unspecified)
  1355 		return 0xff>>5;
  1356 	case EColor16MA:// Display mode with alpha (24bpp colour plus 8bpp alpha)
  1357 		return 0xff>>6;
  1358 	case EColor16MAP:// Pre-multiplied Alpha display mode (24bpp color multiplied with the alpha channel value, plus 8bpp alpha)
  1359 		if (aAlpha==0xff)
  1360 			return 0xff>>4;
  1361 		else
  1362 			//make inaccuracy a function of alpha since the colour will the premultiplied, and then
  1363 			//unpremultiplied.  For small alpha this can be quite large.
  1364 			if (aAlpha==0)
  1365 				return 0xff;
  1366 			else
  1367 				return Max(0xff>>4,Min(0xff,(0xff/aAlpha)+0xf));//value corrected by trial and error, with minimum of 15.
  1368 		}
  1369 	return 0xff>>7;	
  1370 	}
  1371 
  1372 void CTBitmap::DoStretchScanline(const TSize& aSize,TDisplayMode aSrcMode,TDisplayMode aDstMode, TBool aUseCompareLikeness)
  1373 	{
  1374 	__UHEAP_MARK;
  1375 	CFbsBitmapEx bmp;
  1376 	CBitwiseBitmap* bmpadd=NULL;
  1377 
  1378 	TInt ret = bmp.Create(aSize,aSrcMode);
  1379 	TEST2(ret, KErrNone);
  1380 
  1381 	FillBitmap(bmp);
  1382 	bmpadd = bmp.BitmapAddress();
  1383 	bmp.LockHeap();
  1384 	TUint32* base = bmp.DataAddress();
  1385 	bmp.UnlockHeap();
  1386 
  1387 	TInt scanLineLength = CFbsBitmap::ScanLineLength(aSize.iWidth,aSrcMode);
  1388 	TInt scanLineDestLength = CFbsBitmap::ScanLineLength(aSize.iWidth,aDstMode)*2;
  1389 	TUint8* buffer = new TUint8[scanLineLength];
  1390 	TUint8* doubleBuffer = new TUint8[scanLineDestLength];
  1391 	TPtr8 scanline(buffer,scanLineLength,scanLineLength);
  1392 	TPtr8 doubleScanline(doubleBuffer,scanLineDestLength,scanLineDestLength);
  1393 
  1394 	TInt yy;
  1395 	for(yy = 0; yy < aSize.iHeight; yy++)
  1396 		{
  1397 		bmp.GetScanLine(scanline,TPoint(0,yy),aSize.iWidth,aSrcMode);
  1398 		bmpadd->StretchScanLine(doubleScanline,TPoint(0,yy),0,aSize.iWidth * 2,aSize.iWidth * 2,0,aSize.iWidth,TPoint(0,0),aDstMode,base);
  1399 		for(TInt xx = 0; xx < aSize.iWidth; xx++)
  1400 			{
  1401 			TRgb scanlineColor = ExtractRgb(buffer,xx,aSrcMode);
  1402 			TRgb firstStretchColor = ExtractRgb(doubleBuffer,xx * 2,aDstMode);
  1403 			TRgb secondStretchColor = ExtractRgb(doubleBuffer,(xx * 2) + 1,aDstMode);
  1404 			TRgb reportedColor;
  1405 			bmpadd->GetPixel(reportedColor,TPoint(xx,yy),base,NULL);
  1406 			if (!aUseCompareLikeness)
  1407 				{
  1408 				TEST(scanlineColor == firstStretchColor);
  1409 				TEST(firstStretchColor == secondStretchColor);
  1410 				TEST(secondStretchColor == reportedColor);
  1411 				}
  1412 			else
  1413 				{
  1414 				if (aDstMode==EColor16M||aDstMode==EColor16MU||aDstMode==EColor64K||aDstMode==EColor4K||aDstMode==EColor256)
  1415 					{
  1416 					//there is no alpha in the destination
  1417 					scanlineColor.SetAlpha(0xff);
  1418 					reportedColor.SetAlpha(0xff);	
  1419 					}	
  1420 				CompareColourLikeness(scanlineColor, firstStretchColor, ColorDifference(aDstMode,scanlineColor.Alpha()));
  1421 				CompareColourLikeness(firstStretchColor, secondStretchColor,ColorDifference(aDstMode,scanlineColor.Alpha()));
  1422 				CompareColourLikeness(secondStretchColor, reportedColor,ColorDifference(aDstMode,scanlineColor.Alpha()));
  1423 				}
  1424 			}
  1425 		}
  1426 
  1427 	for(yy = 0; yy < aSize.iHeight; yy++)
  1428 		{
  1429 		bmp.GetScanLine(scanline,TPoint(0,yy),aSize.iWidth,aSrcMode);
  1430 		bmpadd->StretchScanLine(doubleScanline,TPoint(0,yy),0,aSize.iWidth / 2,aSize.iWidth / 2,0,aSize.iWidth,TPoint(0,0),aDstMode,base);
  1431 		for(TInt xx = 0; xx < aSize.iWidth; xx += 2)
  1432 			{
  1433 			TRgb scanlineColor = ExtractRgb(buffer,xx,aSrcMode);
  1434 			TRgb compressColor = ExtractRgb(doubleBuffer,xx / 2,aDstMode);
  1435 			TRgb reportedColor;
  1436 			bmpadd->GetPixel(reportedColor,TPoint(xx,yy),base,NULL);
  1437 			if (!aUseCompareLikeness)
  1438 				{
  1439 				TEST(scanlineColor == compressColor);
  1440 				TEST(compressColor == reportedColor);
  1441 				}
  1442 			else
  1443 				{
  1444 				if (aDstMode==EColor16M||aDstMode==EColor16MU||aDstMode==EColor64K||aDstMode==EColor4K||aDstMode==EColor256)
  1445 					{
  1446 					//there is no alpha in the destination
  1447 					scanlineColor.SetAlpha(0xff);
  1448 					reportedColor.SetAlpha(0xff);	
  1449 					}
  1450 				CompareColourLikeness(scanlineColor, compressColor,ColorDifference(aDstMode,scanlineColor.Alpha()));
  1451 				CompareColourLikeness(compressColor, reportedColor,ColorDifference(aDstMode,scanlineColor.Alpha()));
  1452 				}
  1453 			}
  1454 		}
  1455 
  1456 	delete [] buffer;
  1457 	delete [] doubleBuffer;
  1458 	buffer = NULL;
  1459 	doubleBuffer = NULL;
  1460 
  1461 	TInt rgbScanLineLength = aSize.iWidth * sizeof(TRgb) * 2;
  1462 	TUint8* rgbBuffer = new TUint8[rgbScanLineLength];
  1463 	TPtr8 rgbScanline(rgbBuffer,rgbScanLineLength,rgbScanLineLength);
  1464 
  1465 	for(yy = 0; yy < aSize.iHeight; yy++)
  1466 		{
  1467 		bmpadd->StretchScanLine(rgbScanline,TPoint(0,yy),0,aSize.iWidth * 2,aSize.iWidth * 2,0,aSize.iWidth,TPoint(0,0),ERgb,base);
  1468 		for(TInt xx = 0; xx < aSize.iWidth; xx++)
  1469 			{
  1470 			TRgb firstStretchColor = ExtractRgb(rgbBuffer,xx * 2,ERgb);
  1471 			TRgb secondStretchColor = ExtractRgb(rgbBuffer,(xx * 2) + 1,ERgb);
  1472 			TRgb reportedColor;
  1473 			bmpadd->GetPixel(reportedColor,TPoint(xx,yy),base,NULL);
  1474 			if (!aUseCompareLikeness)
  1475 				{
  1476 				TEST(firstStretchColor == secondStretchColor);
  1477 				TEST(secondStretchColor == reportedColor);
  1478 				}
  1479 			else
  1480 				{
  1481 				CompareColourLikeness(firstStretchColor, secondStretchColor);
  1482 				CompareColourLikeness(secondStretchColor, reportedColor);
  1483 				}
  1484 			}
  1485 		}
  1486 
  1487 	for(yy = 0; yy < aSize.iHeight; yy++)
  1488 		{
  1489 		bmpadd->StretchScanLine(rgbScanline,TPoint(0,yy),0,aSize.iWidth / 2,aSize.iWidth / 2,0,aSize.iWidth,TPoint(0,0),ERgb,base);
  1490 		for(TInt xx = 0; xx < aSize.iWidth; xx += 2)
  1491 			{
  1492 			TRgb compressColor = ExtractRgb(rgbBuffer,xx / 2,ERgb);
  1493 			TRgb reportedColor;
  1494 			bmpadd->GetPixel(reportedColor,TPoint(xx,yy),base,NULL);
  1495 			if (!aUseCompareLikeness)
  1496 				{
  1497 				TEST(compressColor == reportedColor);
  1498 				}
  1499 			else
  1500 				{
  1501 				CompareColourLikeness(compressColor, reportedColor);
  1502 				}
  1503 			}
  1504 		}
  1505 
  1506 	delete [] rgbBuffer;
  1507 	rgbBuffer = NULL;
  1508 
  1509 	bmp.Reset();
  1510 	User::Heap().Check();
  1511 	DeleteScanLineBuffer();
  1512 	__UHEAP_MARKEND;
  1513 	}
  1514 
  1515 TRgb CTBitmap::ExtractRgb(TUint8* aBuffer,TInt aPixelOffset,TDisplayMode aDispMode)
  1516 	{
  1517 	switch (aDispMode)
  1518 		{
  1519 	case EGray2:
  1520 		{
  1521 		TUint8 byte = *(aBuffer + (aPixelOffset >> 3));
  1522 		if (byte & (1 << (aPixelOffset & 7)))
  1523 			return KRgbWhite;
  1524 		return KRgbBlack;
  1525 		}
  1526 	case EGray4:
  1527 		{
  1528 		TUint8 byte = *(aBuffer + (aPixelOffset >> 2));
  1529 		byte >>= ((aPixelOffset & 3) << 1);
  1530 		return TRgb::Gray4(byte & 3);
  1531 		}
  1532 	case EGray16:
  1533 		{
  1534 		TUint8 byte = *(aBuffer + (aPixelOffset >> 1));
  1535 		if (aPixelOffset & 1)
  1536 			byte >>= 4;
  1537 		return TRgb::Gray16(byte & 0xf);
  1538 		}
  1539 	case EGray256:
  1540 		return TRgb::Gray256(*(aBuffer + aPixelOffset));
  1541 	case EColor16:
  1542 		{
  1543 		TUint8 byte = *(aBuffer + (aPixelOffset >> 1));
  1544 		if (aPixelOffset & 1)
  1545 			byte >>= 4;
  1546 		return TRgb::Color16(byte & 0xf);
  1547 		}
  1548 	case EColor256:
  1549 		return TRgb::Color256(*(aBuffer + aPixelOffset));
  1550 	case EColor4K:
  1551 		{
  1552 		TUint16 doubleByte = *(((TUint16*)aBuffer) + aPixelOffset);
  1553 		return TRgb::Color4K(doubleByte & 0xfff);
  1554 		}
  1555 	case EColor64K:
  1556 		{
  1557 		TUint16 doubleByte = *(((TUint16*)aBuffer) + aPixelOffset);
  1558 		return TRgb::Color64K(doubleByte);
  1559 		}
  1560 	case EColor16M:
  1561 		{
  1562 		aBuffer += aPixelOffset * 3;
  1563 		TInt value = *aBuffer++;
  1564 		value |= *aBuffer++ << 8;
  1565 		value |= *aBuffer << 16;
  1566 		return TRgb::Color16M(value);
  1567 		}
  1568 	case ERgb:
  1569 		return *(((TRgb*)aBuffer) + aPixelOffset);
  1570 	case EColor16MU:
  1571 		{
  1572 		return TRgb::Color16MU(*(((TUint32*)aBuffer) + aPixelOffset));
  1573 		}
  1574 	case EColor16MA:
  1575 		{
  1576 		return TRgb::Color16MA(*(((TUint32*)aBuffer) + aPixelOffset));
  1577 		}	
  1578 	case EColor16MAP:
  1579 		{
  1580 		return TRgb::_Color16MAP(*(((TUint32*)aBuffer) + aPixelOffset));
  1581 		}	
  1582 	default:
  1583 		break;
  1584 		};
  1585 	return KRgbBlack;
  1586 	}
  1587 	
  1588 /**
  1589 	@SYMTestCaseID
  1590 	GRAPHICS-FBSERV-0523
  1591 
  1592 	@SYMTestCaseDesc
  1593 	Streams a bitmap in segments and compares it
  1594 	to an expected bitmap
  1595 	
  1596 	@SYMTestActions
  1597 	
  1598 	@SYMTestExpectedResults
  1599 	Test should pass
  1600 */
  1601 void CTBitmap::LoadInSegments()
  1602 	{
  1603 	INFO_PRINTF1(_L("Test Segmented Loading"));
  1604 
  1605 	__UHEAP_MARK;
  1606 	CFbsBitmapEx bmp;
  1607 	TInt ret=bmp.Load(iTestBitmapName,ETfbs,NULL);
  1608 	TEST2(ret, KErrNone);
  1609 	CFbsBitmapAsyncStreamer* bmploader=NULL;
  1610 	TRAP(ret,bmploader=CFbsBitmapAsyncStreamer::NewL(CFbsBitmapAsyncStreamer::ELoad));
  1611 	TEST2(ret, KErrNone);
  1612 	TInt slines=0;
  1613 	ret=bmploader->Load(iTestBitmapName,ETfbs,slines);
  1614 	TEST2(ret, KErrNone);
  1615 	TEST(slines>0);
  1616 	CFbsBitmap* newbmp=NULL;
  1617 	TBool done=EFalse;
  1618 	do	{
  1619 		TEST(newbmp==NULL);
  1620 		TRAP(ret,done=bmploader->LoadScanLinesL(slines/10,newbmp));
  1621 		TEST2(ret, KErrNone);
  1622 		}
  1623 	while(!done);
  1624 
  1625 	TEST(newbmp!=NULL);
  1626 	CompareBitmaps(bmp,(CFbsBitmapEx&)*newbmp,EColor16M);
  1627 	delete bmploader;
  1628 	delete newbmp;
  1629 
  1630 	TRAP(ret,iBmpHandler=CFbsBitmapAsyncStreamer::NewL(CFbsBitmapAsyncStreamer::ELoad));
  1631 	TEST2(ret, KErrNone);
  1632 	ret=iBmpHandler->Load(iTestBitmapName,ETfbs,slines);
  1633 	TEST2(ret, KErrNone);
  1634 	TEST(slines>0);
  1635 	CIdle* idleobj=CIdle::New(-20);
  1636 	TEST(idleobj!=NULL);
  1637 	TCallBack callback(BmpLoadCallBack,this);
  1638 	idleobj->Start(callback);
  1639 	
  1640 	CActiveScheduler* as = CActiveScheduler::Current();
  1641 	__ASSERT_DEBUG(as, User::Invariant());
  1642 	
  1643 	TRAP(ret,as->Start());
  1644 	TEST2(ret, KErrNone);
  1645 	
  1646 	CompareBitmaps(bmp,(CFbsBitmapEx&)*iBitmap,EColor16M);
  1647 
  1648 	delete iBmpHandler;
  1649 	delete iBitmap;
  1650 	bmp.Reset();
  1651 	delete idleobj;
  1652 	User::Heap().Check();
  1653 	__UHEAP_MARKEND;
  1654 
  1655 	
  1656 	}
  1657 
  1658 TInt CTBitmap::BmpLoadCallBack(TAny* aPtr)
  1659 	{
  1660 	CTBitmap* tbmp=(CTBitmap*)aPtr;
  1661 	tbmp->INFO_PRINTF1(_L("*"));
  1662 	TBool done=EFalse;
  1663 	TRAPD(ret,done=tbmp->iBmpHandler->LoadScanLinesL(10,tbmp->iBitmap));
  1664 	tbmp->TEST2(ret, KErrNone);
  1665 	if(done)
  1666 		{
  1667 		tbmp->TEST(tbmp->iBitmap!=NULL);
  1668 		CActiveScheduler::Stop();
  1669 		}
  1670 	else 
  1671 		{
  1672 		tbmp->TEST(tbmp->iBitmap==NULL);
  1673 		}
  1674 	return(ETrue);
  1675 	}
  1676 	
  1677 /**
  1678 	@SYMTestCaseID
  1679 	GRAPHICS-FBSERV-0524
  1680 
  1681 	@SYMTestCaseDesc
  1682 	A bitmap is saved in segments and then read back from file store
  1683 	and compared to an expected bitmap
  1684 
  1685 	@SYMTestActions
  1686 	
  1687 	@SYMTestExpectedResults
  1688 	Test should pass
  1689 */	
  1690 void CTBitmap::SaveInSegments()
  1691 	{
  1692 	INFO_PRINTF1(_L("Test Segmented Saving"));
  1693 
  1694 	__UHEAP_MARK;
  1695 	CFbsBitmapEx bmp;
  1696 	TInt ret=bmp.Load(iTestBitmapName,ETfbs,NULL);
  1697 	TEST2(ret, KErrNone);
  1698 	CFbsBitmapAsyncStreamer* bmpsaver=NULL;
  1699 	TRAP(ret,bmpsaver=CFbsBitmapAsyncStreamer::NewL(CFbsBitmapAsyncStreamer::ESave));
  1700 	TEST2(ret, KErrNone);
  1701 	TInt slines=0;
  1702 	TInt32 id;
  1703 	ret=bmpsaver->Save(KTempFilename,&bmp,id,slines);
  1704 	TEST2(ret, KErrNone);
  1705 	TEST(id==0);
  1706 	TEST(slines>0);
  1707 	TBool done=EFalse;
  1708 	do	{
  1709 		TRAP(ret,done=bmpsaver->SaveScanLinesL(slines/10));
  1710 		TEST2(ret, KErrNone);
  1711 		}
  1712 	while(!done);
  1713 	delete bmpsaver;
  1714 	CFbsBitmapEx bmp2;
  1715 	ret=bmp2.Load(KTempFilename,id,NULL);
  1716 	TEST2(ret, KErrNone);
  1717 	TUint8 buffer[40];
  1718 	TUint8 bufferst[40];
  1719 	TPtr8 scanline(&buffer[0],40,40);
  1720 	TPtr8 scanlinest(&bufferst[0],40,40);
  1721 	TInt yy=0;
  1722 	for(;yy<80;yy++)
  1723 		{
  1724 		bmp.GetScanLine(scanline,TPoint(0,yy),160,EGray4);
  1725 		bmp2.GetScanLine(scanlinest,TPoint(0,yy),160,EGray4);
  1726 		for(TInt count=0;count<40;count++)
  1727 			TEST(buffer[count]==bufferst[count]);
  1728 		}
  1729 	bmp2.Reset();
  1730 	iFs.Delete(KTempFilename);
  1731 
  1732 	CActiveScheduler* as = CActiveScheduler::Current();
  1733 	__ASSERT_DEBUG(as, User::Invariant());
  1734 
  1735 	TRAP(ret,iBmpHandler=CFbsBitmapAsyncStreamer::NewL(CFbsBitmapAsyncStreamer::ESave));
  1736 	TEST2(ret, KErrNone);
  1737 	ret=iBmpHandler->Save(KTempFilename,&bmp,id,slines);
  1738 	TEST2(ret, KErrNone);
  1739 	TEST(id==0);
  1740 	TEST(slines>0);
  1741 	CIdle* idleobj=CIdle::New(-20);
  1742 	TEST(idleobj!=NULL);
  1743 	TCallBack callback(BmpSaveCallBack,this);
  1744 	idleobj->Start(callback);
  1745 	TRAP(ret,as->Start());
  1746 	TEST2(ret, KErrNone);
  1747 	delete iBmpHandler;
  1748 	ret=bmp2.Load(KTempFilename,id,NULL);
  1749 	TEST2(ret, KErrNone);
  1750 	for(yy=0;yy<80;yy++)
  1751 		{
  1752 		bmp.GetScanLine(scanline,TPoint(0,yy),160,EGray4);
  1753 		bmp2.GetScanLine(scanlinest,TPoint(0,yy),160,EGray4);
  1754 		for(TInt count=0;count<40;count++)
  1755 			TEST(buffer[count]==bufferst[count]);
  1756 		}
  1757 	bmp.Reset();
  1758 	delete idleobj;
  1759 	iFs.Delete(KTempFilename);
  1760 	User::Heap().Check();
  1761 	__UHEAP_MARKEND;
  1762 
  1763 	INFO_PRINTF1(_L("\r\n"));
  1764 	
  1765 	}
  1766 
  1767 TInt CTBitmap::BmpSaveCallBack(TAny* aPtr)
  1768 	{
  1769 	CTBitmap* tbmp=(CTBitmap*)aPtr;
  1770 	tbmp->INFO_PRINTF1(_L("*"));
  1771 	TBool done=EFalse;
  1772 	TRAPD(ret,done=tbmp->iBmpHandler->SaveScanLinesL(10));
  1773 	tbmp->TEST2(ret, KErrNone);
  1774 	if(done) 
  1775 		{
  1776 		CActiveScheduler::Stop();
  1777 		}
  1778 	return(ETrue);
  1779 	}
  1780 
  1781 /**
  1782 	@SYMTestCaseID
  1783 	GRAPHICS-FBSERV-0525
  1784 
  1785 	@SYMTestCaseDesc
  1786 	Tests if a bitmap is monochrone for different
  1787 	color depths
  1788 
  1789 	@SYMTestActions
  1790 	
  1791 	@SYMTestExpectedResults
  1792 	Test should pass
  1793 */
  1794 void CTBitmap::MonoDetect()
  1795 	{
  1796 	INFO_PRINTF1(_L("Test Mono Detection"));
  1797 
  1798 	DoMonoDetect(EGray2);
  1799 	DoMonoDetect(EGray4);
  1800 	DoMonoDetect(EGray16);
  1801 	DoMonoDetect(EGray256);
  1802 	DoMonoDetect(EColor16);
  1803 	DoMonoDetect(EColor256);
  1804 	DoMonoDetect(EColor4K);
  1805 	DoMonoDetect(EColor64K);
  1806 	DoMonoDetect(EColor16M);
  1807 	DoMonoDetect(EColor16MU);
  1808 	DoMonoDetect(EColor16MAP);
  1809 	}
  1810 
  1811 void CTBitmap::DoMonoDetect(TDisplayMode aDisplayMode)
  1812 	{
  1813 	CFbsBitmapEx bmp;
  1814 	TInt ret = bmp.Create(TSize(100,3),aDisplayMode);
  1815 	TEST2(ret, KErrNone);
  1816 
  1817 	CBitwiseBitmap* bmpadd = bmp.BitmapAddress();
  1818 	bmp.LockHeap();
  1819 	TUint32* base = bmp.DataAddress();
  1820 	bmp.UnlockHeap();
  1821 	TUint32* data = bmpadd->ScanLineAddress(base,1);
  1822 
  1823 	if(aDisplayMode == EColor16M)
  1824 		{
  1825 		*(data+1) = 0x0000FFFF;
  1826 		*(data+2) = 0xFFFFFF00;
  1827 		//Pixel at (data + 1). Bytes (3) and (2) are part of the pixel at (data) addr.
  1828 		//LSB                        MSB
  1829 		//3        2        1        0
  1830 		//FF       FF       00       00  
  1831 		//Pixel at (data + 2). Byte (3) is part of the pixel at (data + 1) addr.
  1832 		//LSB                        MSB
  1833 		//3        2        1        0
  1834 		//00       FF       FF       FF
  1835 		}
  1836 	else
  1837 		{
  1838 		*(data+1) = 0;
  1839 		}
  1840 	TBool mono = bmp.IsMonochrome();
  1841 	TEST(mono);
  1842 
  1843 	*(data+1) = 0x1234abcd;
  1844 	mono = bmp.IsMonochrome();
  1845 	if (aDisplayMode == EGray2)
  1846 		TEST(mono);
  1847 	else
  1848 		TEST(!mono);
  1849 
  1850 	if(aDisplayMode == EColor16M)
  1851 		{
  1852 		*(data+1) = 0xffffffff;
  1853 		*(data+2) = 0xffffffff;
  1854 		}
  1855 	else
  1856 		{
  1857 		*(data+1) = 0xffffffff;
  1858 		}
  1859 	mono=bmp.IsMonochrome();
  1860 	TEST(mono);
  1861 
  1862 	bmp.Reset();
  1863 	}
  1864 
  1865 
  1866 #if defined(__WINS__)
  1867 // these are patchable constants defined in fbscli.dll but on the emulator
  1868 // it's not possible to import them so they are re-defined here
  1869 const TInt KFbServLargeChunkGrowByShifter = 1;
  1870 const TInt KFbServLargeChunkSizeShifter = 2;
  1871 const TInt KFbServLargeChunkMinPhysicalSize = 0x4000;
  1872 #elif defined(__X86GCC__)
  1873 IMPORT_D extern const TInt KFbServLargeChunkGrowByShifter;
  1874 IMPORT_D extern const TInt KFbServLargeChunkSizeShifter;
  1875 IMPORT_D extern const TInt KFbServLargeChunkMinPhysicalSize;
  1876 #endif
  1877 
  1878 /**
  1879 	@SYMTestCaseID
  1880 	GRAPHICS-FBSERV-0526
  1881 
  1882 	@SYMTestCaseDesc
  1883 	Allocates different sized chunks of memory
  1884 	in a loop and frees them
  1885 
  1886 	@SYMTestActions
  1887 	
  1888 	@SYMTestExpectedResults
  1889 	Test should pass
  1890 */
  1891 void CTBitmap::ChunkPileL()
  1892 	{
  1893 	INFO_PRINTF1(_L("Test Chunk Pile"));
  1894 
  1895 	TInt virtualSize = 0x4000000;
  1896 	RChunk chunk;
  1897 	TInt ret = chunk.CreateDisconnectedGlobal(_L("TFbsLargeChunk"), 0, 0, virtualSize);
  1898 	TEST2(ret, KErrNone);
  1899 	CleanupClosePushL(chunk);
  1900 	TInt pageSize = 0;
  1901 	HAL::Get(HAL::EMemoryPageSize, pageSize);
  1902 	TEST(pageSize == 4096);
  1903 	TUint8* chunkSmallBase = chunk.Base() + pageSize;
  1904 	TUint8* chunkLargeBase = chunk.Base() + (virtualSize >> KFbServLargeChunkSizeShifter);
  1905 
  1906 	CChunkPile* cp=NULL;
  1907 	TRAP(ret, cp = CChunkPile::NewL(chunk));
  1908 	TEST2(ret, KErrNone);
  1909 	TEST(cp!=NULL);
  1910 	CleanupStack::PushL(cp);
  1911 	TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
  1912 
  1913 	TUint8* chunkalloc[16];
  1914 	TInt size[16];
  1915 	for (TInt i = 0; i < 64; ++i)
  1916 		{
  1917 		chunkalloc[0] = cp->Alloc(size[0] = 512);
  1918 		TEST(chunkalloc[0] == chunkSmallBase);
  1919 		chunkalloc[1] = cp->Alloc(size[1] = 8);
  1920 		TEST(chunkalloc[1] == chunkalloc[0] + size[0]);
  1921 		chunkalloc[2] = cp->Alloc(size[2] = 128);
  1922 		TEST(chunkalloc[2] == chunkalloc[1] + size[1]);
  1923 		chunkalloc[3] = cp->Alloc(size[3] = 372);
  1924 		TEST(chunkalloc[3] == chunkalloc[2] + size[2]);
  1925 		chunkalloc[4] = cp->Alloc(size[4] = 256);
  1926 		TEST(chunkalloc[4] == chunkalloc[3] + size[3]);
  1927 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
  1928 		// now we should have [0], [1], [2], [3], [4]
  1929 
  1930 		cp->Free(chunkalloc[2]);
  1931 		cp->Free(chunkalloc[3]);
  1932 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
  1933 		chunkalloc[5] = cp->Alloc(size[5] = size[2] + size[3]);
  1934 		TEST(chunkalloc[5] == chunkalloc[2]);
  1935 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
  1936 		// now we should have [0], [1], [5], [4]
  1937 
  1938 		chunkalloc[6] = cp->Alloc(size[6] = 4);
  1939 		TEST(chunkalloc[6] == chunkalloc[4] + size[4]);
  1940 		chunkalloc[7] = cp->Alloc(size[7] = 1024);
  1941 		TEST(chunkalloc[7] == chunkalloc[6] + size[6]);
  1942 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
  1943 		cp->Free(chunkalloc[7]);
  1944 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
  1945 		// now we should have [0], [1], [5], [4], [6]
  1946 
  1947 		cp->Free(chunkalloc[1]);
  1948 		cp->Free(chunkalloc[0]);
  1949 		cp->Free(chunkalloc[4]);
  1950 		cp->Free(chunkalloc[5]);
  1951 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
  1952 		chunkalloc[8] = cp->Alloc(size[8] = size[0] + size[1] + size[4] + size[5] - 32);
  1953 		TEST(chunkalloc[8] == chunkalloc[0]);
  1954 		chunkalloc[9] = cp->Alloc(size[9] = 32);
  1955 		TEST(chunkalloc[9] == chunkalloc[8] + size[8]);
  1956 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
  1957 		// now we should have [8], [9], [6]
  1958 
  1959 		chunkalloc[10] = cp->Alloc(size[10] = KFbServLargeChunkMinPhysicalSize - size[6] - size[8] - size[9]);
  1960 		TEST(chunkalloc[10] == chunkalloc[6] + size[6]);
  1961 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
  1962 		chunkalloc[11] = cp->Alloc(size[11] = 16);
  1963 		TEST(chunkalloc[11] == chunkalloc[10] + size[10]);
  1964 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + (pageSize << KFbServLargeChunkGrowByShifter));
  1965 		chunkalloc[12] = cp->Alloc(size[12] = ((pageSize << KFbServLargeChunkGrowByShifter) - 16) / 2);
  1966 		TEST(chunkalloc[12] == chunkalloc[11] + size[11]);
  1967 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + (pageSize << KFbServLargeChunkGrowByShifter));
  1968 		chunkalloc[13] = cp->Alloc(size[13] = size[12]);
  1969 		TEST(chunkalloc[13] == chunkalloc[12] + size[12]);
  1970 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + (pageSize << KFbServLargeChunkGrowByShifter));
  1971 		chunkalloc[14] = cp->Alloc(size[14] = pageSize << KFbServLargeChunkGrowByShifter);
  1972 		TEST(chunkalloc[14] == chunkalloc[13] + size[13]);
  1973 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + 2 * (pageSize << KFbServLargeChunkGrowByShifter));
  1974 		chunkalloc[15] = cp->Alloc(size[15] = (pageSize << KFbServLargeChunkGrowByShifter) + 4);
  1975 		TEST(chunkalloc[15] == chunkalloc[14] + size[14]);
  1976 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + 4 * (pageSize << KFbServLargeChunkGrowByShifter));
  1977 		// now we should have [8], [9], [6], [10], [11], [12], [13], [14], [15]
  1978 
  1979 		cp->Free(chunkalloc[15]);
  1980 		cp->Free(chunkalloc[14]);
  1981 		cp->Free(chunkalloc[13]);
  1982 		cp->Free(chunkalloc[12]);
  1983 		cp->Free(chunkalloc[11]);
  1984 		cp->Free(chunkalloc[10]);
  1985 		cp->Free(chunkalloc[9]);
  1986 		cp->Free(chunkalloc[8]);
  1987 		cp->Free(chunkalloc[6]);
  1988 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
  1989 
  1990 		TEST(cp->Alloc(virtualSize) == NULL);
  1991 
  1992 		TInt largeSize = 4 * pageSize;
  1993 		chunkalloc[0] = cp->Alloc(size[0] = 2 * largeSize);
  1994 		TEST(chunkalloc[0] == chunkLargeBase);
  1995 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0]);
  1996 		chunkalloc[1] = cp->Alloc(2 * largeSize + 1);
  1997 		size[1] = 2 * largeSize + pageSize;
  1998 		TEST(chunkalloc[1] == chunkalloc[0] + size[0]);
  1999 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[1]);
  2000 		chunkalloc[2] = cp->Alloc(size[2] = 3 * largeSize + pageSize);
  2001 		TEST(chunkalloc[2] == chunkalloc[1] + size[1]);
  2002 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[1] + size[2]);
  2003 		// now we should have [0], [1], [2]
  2004 
  2005 		cp->Free(chunkalloc[1]);
  2006 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[2]);
  2007 		chunkalloc[3] = cp->Alloc(largeSize + 1);
  2008 		size[3] = largeSize + pageSize;
  2009 		TEST(chunkalloc[3] == chunkalloc[1]);
  2010 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[2] + size[3]);
  2011 		chunkalloc[4] = cp->Alloc(size[4] = largeSize);
  2012 		TEST(chunkalloc[4] == chunkalloc[3] + size[3]);
  2013 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[2] + size[3] + size[4]);
  2014 		chunkalloc[5] = cp->Alloc(size[5] = 64 * largeSize);
  2015 		TEST(chunkalloc[5] == chunkalloc[2] + size[2]);
  2016 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[2] + size[3] + size[4] + size[5]);
  2017 		// now we should have [0], [3], [4], [2], [5]
  2018 
  2019 		cp->Free(chunkalloc[0]);
  2020 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[2] + size[3] + size[4] + size[5]);
  2021 		cp->Free(chunkalloc[2]);
  2022 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[3] + size[4] + size[5]);
  2023 		cp->Free(chunkalloc[3]);
  2024 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[4] + size[5]);
  2025 		cp->Free(chunkalloc[4]);
  2026 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[5]);
  2027 		cp->Free(chunkalloc[5]);
  2028 		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
  2029 		}
  2030 
  2031 	CleanupStack::PopAndDestroy(2, &chunk); // cp, chunk
  2032 	}
  2033 
  2034 /**
  2035 	@SYMTestCaseID
  2036 	GRAPHICS-FBSERV-0527
  2037 
  2038 	@SYMTestCaseDesc
  2039 	Creates large bitmaps of different colour depth. 
  2040 
  2041 	@SYMTestActions
  2042 	The bitmaps allocated are too big so
  2043 	the allocation should fail.
  2044 	
  2045 	@SYMTestExpectedResults
  2046 	KErrNoMemory when allocating the bitmaps. 
  2047 */
  2048 void CTBitmap::LargeBitmaps()
  2049 	{
  2050 	INFO_PRINTF1(_L("Test Large Bitmaps"));
  2051 
  2052 	TMemoryInfoV1Buf membuf;
  2053 	UserHal::MemoryInfo(membuf);
  2054 	const TReal maxmem = membuf().iTotalRamInBytes;
  2055 
  2056 	TReal realSize = 0;
  2057 	TInt ret = Math::Sqrt(realSize,maxmem);
  2058 	TEST2(ret, KErrNone);
  2059 	TInt32 size = 0;
  2060 	ret = Math::Int(size,realSize);
  2061 	TEST2(ret, KErrNone);
  2062 
  2063 	DoLargeBitmaps(TSize(size * 8,size),EGray2);
  2064 	DoLargeBitmaps(TSize(size * 4,size),EGray4);
  2065 	DoLargeBitmaps(TSize(size * 2,size),EGray16);
  2066 	DoLargeBitmaps(TSize(size,size),EGray256);
  2067 	DoLargeBitmaps(TSize(size * 2,size),EColor16);
  2068 	DoLargeBitmaps(TSize(size,size),EColor256);
  2069 	DoLargeBitmaps(TSize(size / 2,size),EColor4K);
  2070 	DoLargeBitmaps(TSize(size / 2,size),EColor64K);
  2071 	DoLargeBitmaps(TSize(size / 3,size),EColor16M);
  2072 	DoLargeBitmaps(TSize(size / 4,size),EColor16MU);
  2073 	DoLargeBitmaps(TSize(size / 4,size),EColor16MAP);
  2074 	}
  2075 
  2076 void CTBitmap::DoLargeBitmaps(const TSize& aSize,TDisplayMode aDisplayMode)
  2077 	{
  2078 	CFbsBitmapEx bmp1;
  2079 	TInt ret = bmp1.Create(aSize,aDisplayMode);
  2080 	TEST2(ret, KErrNoMemory);
  2081 	}
  2082 
  2083 /**
  2084 	@SYMTestCaseID
  2085 	GRAPHICS-FBSERV-0528
  2086 
  2087 	@SYMTestCaseDesc
  2088 	Check error handling for bitmaps above pixel and byte size limits
  2089 
  2090 	@SYMTestActions
  2091 	
  2092 	@SYMTestExpectedResults
  2093 	Test should pass
  2094 */
  2095 void CTBitmap::HugeBitmaps()
  2096 	{
  2097 	// Check error handling for bitmaps above pixel and byte size limits
  2098 	INFO_PRINTF1(_L("Test Huge Bitmaps"));
  2099 
  2100 	const TInt KLargePixelSize = 50000;
  2101 
  2102 	DoHugeBitmaps(TSize(KLargePixelSize * 8,KLargePixelSize),EGray2);
  2103 	DoHugeBitmaps(TSize(KLargePixelSize * 4,KLargePixelSize),EGray4);
  2104 	DoHugeBitmaps(TSize(KLargePixelSize * 2,KLargePixelSize),EGray16);
  2105 	DoHugeBitmaps(TSize(KLargePixelSize,KLargePixelSize),EGray256);
  2106 	DoHugeBitmaps(TSize(KLargePixelSize * 2,KLargePixelSize),EColor16);
  2107 	DoHugeBitmaps(TSize(KLargePixelSize,KLargePixelSize),EColor256);
  2108 	DoHugeBitmaps(TSize(KLargePixelSize / 2,KLargePixelSize),EColor4K);
  2109 	DoHugeBitmaps(TSize(KLargePixelSize / 2,KLargePixelSize),EColor64K);
  2110 	DoHugeBitmaps(TSize(KLargePixelSize / 3,KLargePixelSize),EColor16M);
  2111 	DoHugeBitmaps(TSize(KLargePixelSize / 4,KLargePixelSize),EColor16MU);
  2112 	DoHugeBitmaps(TSize(KLargePixelSize / 4,KLargePixelSize),EColor16MAP);
  2113 	}
  2114 
  2115 void CTBitmap::DoHugeBitmaps(const TSize& aSize,TDisplayMode aDisplayMode)
  2116 	{
  2117 	const TInt KMaxPixelSize = KMaxTInt / 4 + 1;
  2118 
  2119 	CFbsBitmap bmp;
  2120 
  2121 	TInt ret = bmp.Create(TSize(aSize.iWidth / 2,aSize.iHeight / 2),aDisplayMode);
  2122 	TEST2(ret, KErrNoMemory);
  2123 
  2124 	ret = bmp.Create(aSize,aDisplayMode);
  2125 	TEST2(ret, KErrTooBig);
  2126 
  2127 	ret = bmp.Create(TSize(1,KMaxPixelSize),aDisplayMode);
  2128 	TEST2(ret, KErrTooBig);
  2129 
  2130 	ret = bmp.Create(TSize(KMaxPixelSize,1),aDisplayMode);
  2131 	TEST2(ret, KErrTooBig);
  2132 
  2133 	ret = bmp.Create(TSize(KMaxPixelSize,KMaxPixelSize),aDisplayMode);
  2134 	TEST2(ret, KErrTooBig);
  2135 
  2136 	ret = bmp.Create(TSize(KMaxTInt,KMaxTInt),aDisplayMode);
  2137 	TEST2(ret, KErrTooBig);
  2138 
  2139 
  2140 	ret = bmp.Create(TSize(1,1),aDisplayMode);
  2141 	TEST2(ret, KErrNone);
  2142 
  2143 	ret = bmp.Resize(TSize(aSize.iWidth / 2,aSize.iHeight / 2));
  2144 	TEST2(ret, KErrNoMemory);
  2145 
  2146 	ret = bmp.Resize(aSize);
  2147 	TEST2(ret, KErrTooBig);
  2148 
  2149 	ret = bmp.Resize(TSize(1,KMaxPixelSize));
  2150 	TEST2(ret, KErrTooBig);
  2151 
  2152 	ret = bmp.Resize(TSize(KMaxPixelSize,1));
  2153 	TEST2(ret, KErrTooBig);
  2154 
  2155 	ret = bmp.Resize(TSize(KMaxPixelSize,KMaxPixelSize));
  2156 	TEST2(ret, KErrTooBig);
  2157 
  2158 	ret = bmp.Resize(TSize(KMaxTInt,KMaxTInt));
  2159 	TEST2(ret, KErrTooBig);
  2160 
  2161 	bmp.Reset();
  2162 	}
  2163 
  2164 /**
  2165 	@SYMTestCaseID
  2166 	GRAPHICS-FBSERV-0529
  2167 
  2168 	@SYMTestCaseDesc
  2169 	Resizes a bitmap to a larger size and
  2170 	checks if the new bitmap is as expected
  2171 	
  2172 	@SYMTestActions
  2173 	
  2174 	@SYMTestExpectedResults
  2175 	Test should pass
  2176 */
  2177 void CTBitmap::Resize()
  2178 	{
  2179 	INFO_PRINTF1(_L("Test Resizing"));
  2180 
  2181 	DoResize(EGray2);
  2182 	DoResize(EGray4);
  2183 	DoResize(EGray16);
  2184 	DoResize(EGray256);
  2185 	DoResize(EColor16);
  2186 	DoResize(EColor256);
  2187 	DoResize(EColor4K);
  2188 	DoResize(EColor64K);
  2189 	DoResize(EColor16M);
  2190 	DoResize(EColor16MU);
  2191 	DoResize(EColor16MAP);
  2192 	}
  2193 
  2194 void CTBitmap::DoResize(TDisplayMode aDispMode)
  2195 	{
  2196 	const TSize KBitmapOriginalSize(256,24);
  2197 	const TSize KBitmapLargeSize(288,32);
  2198 	const TSize KBitmapSmallSize(1,1);
  2199 
  2200 	CFbsBitmapEx bmp;
  2201 	TInt ret = bmp.Create(KBitmapOriginalSize,aDispMode);
  2202 	TEST2(ret, KErrNone);
  2203 	bmp.SetSizeInTwips(KBitmapOriginalSize);
  2204 	TEST(bmp.SizeInPixels() == KBitmapOriginalSize);
  2205 	TEST(bmp.SizeInTwips() == KBitmapOriginalSize);
  2206 
  2207 	CBitwiseBitmap* bb = bmp.BitmapAddress();
  2208 	bmp.LockHeap();
  2209 	TUint32* base = bmp.DataAddress();
  2210 	bmp.UnlockHeap();
  2211 
  2212 	TInt scanLineLength = CFbsBitmap::ScanLineLength(256,aDispMode);
  2213 	TInt blockStart = scanLineLength / 4;
  2214 	TInt blockLength = scanLineLength / 2;
  2215 
  2216 	TInt row;
  2217 	for(row = 8; row < 16; row++)
  2218 		{
  2219 		TUint8* bmpadd = (TUint8*)bb->ScanLineAddress(base,row);
  2220 		Mem::FillZ(bmpadd + blockStart,blockLength);
  2221 		}
  2222 
  2223 	ret = bmp.Resize(KBitmapLargeSize);
  2224 	TEST2(ret, KErrNone);
  2225 	TEST(bmp.SizeInPixels() == KBitmapLargeSize);
  2226 	TEST(bmp.SizeInTwips() == KBitmapLargeSize);
  2227 	bb = bmp.BitmapAddress();
  2228 	bmp.LockHeap();
  2229 	base = bmp.DataAddress();
  2230 	bmp.UnlockHeap();
  2231 	scanLineLength = CFbsBitmap::ScanLineLength(288,aDispMode);
  2232 
  2233 	for(row = 0; row < 8; row++)
  2234 		{
  2235 		TUint8* bmpadd=(TUint8*)bb->ScanLineAddress(base,row);
  2236 		CheckWhite(bmpadd,scanLineLength,aDispMode);
  2237 		}
  2238 
  2239 	for(row = 16; row < 32; row++)
  2240 		{
  2241 		TUint8* bmpadd=(TUint8*)bb->ScanLineAddress(base,row);
  2242 		CheckWhite(bmpadd,scanLineLength,aDispMode);
  2243 		}
  2244 
  2245 	for(row = 8; row < 16; row++)
  2246 		{
  2247 		TUint8* bmpadd=(TUint8*)bb->ScanLineAddress(base,row);
  2248 		CheckWhite(bmpadd,blockStart,aDispMode);
  2249 
  2250 		TUint8* ptr = bmpadd + blockStart;
  2251 		TUint8* ptrLimit = ptr + blockLength;
  2252 		while (ptr < ptrLimit)
  2253 			TEST(*ptr++ == 0);
  2254 
  2255 		CheckWhite(ptr,scanLineLength - blockStart - blockLength,aDispMode);
  2256 		}
  2257 
  2258 	ret = bmp.Resize(KBitmapSmallSize);
  2259 	TEST2(ret, KErrNone);
  2260 	TEST(bmp.SizeInPixels() == KBitmapSmallSize);
  2261 	TEST(bmp.SizeInTwips() == KBitmapSmallSize);
  2262 
  2263 	ret = bmp.Resize(KBitmapOriginalSize);
  2264 	TEST2(ret, KErrNone);
  2265 	TEST(bmp.SizeInPixels() == KBitmapOriginalSize);
  2266 	TEST(bmp.SizeInTwips() == KBitmapOriginalSize);
  2267 
  2268 	bmp.Reset();
  2269 	}
  2270 
  2271 void CTBitmap::CheckWhite(TUint8* aData,TInt aDataLength,TDisplayMode aDispMode)
  2272 	{
  2273 	TUint8* dataLimit = aData + aDataLength;
  2274 
  2275 	if (aDispMode != EColor4K)
  2276 		{
  2277 		while (aData < dataLimit)
  2278 			TEST(*aData++ == 0xff);
  2279 		}
  2280 	else
  2281 		{
  2282 		while (aData < dataLimit)
  2283 			{
  2284 			TEST(*aData == 0xff || *aData == 0x0f);
  2285 			aData++;
  2286 			}
  2287 		}
  2288 	}
  2289 
  2290 /**
  2291 	@SYMTestCaseID
  2292 	GRAPHICS-FBSERV-0530
  2293 
  2294 	@SYMTestCaseDesc
  2295 	Creates BitmapUtil objects and sets the
  2296 	current position to different positions
  2297 	and retrieves and sets the pixels in these
  2298 	and compares it to another Bitmap Util object
  2299 	
  2300 	@SYMTestActions
  2301 
  2302 	@SYMTestExpectedResults
  2303 	Test should pass
  2304 */
  2305 void CTBitmap::BitmapUtil()
  2306 	{
  2307 	INFO_PRINTF1(_L("Test Bitmap Util"));
  2308 
  2309 	TSize bmpUtilSize1(256,4);
  2310 	TSize bmpUtilSize2(256,1);
  2311 	TSize bmpUtilSize3(256,256);
  2312 	TSize bmpUtilSize4(1024,1024);
  2313 
  2314 	INFO_PRINTF1(_L("256x4.. "));
  2315 	DoBitmapUtil(bmpUtilSize1,EGray2);
  2316 	DoBitmapUtil(bmpUtilSize1,EGray4);
  2317 	DoBitmapUtil(bmpUtilSize1,EGray16);
  2318 	DoBitmapUtil(bmpUtilSize1,EGray256);
  2319 	DoBitmapUtil(bmpUtilSize1,EColor16);
  2320 	DoBitmapUtil(bmpUtilSize1,EColor256);
  2321 	DoBitmapUtil(bmpUtilSize1,EColor4K);
  2322 	DoBitmapUtil(bmpUtilSize1,EColor64K);
  2323 	DoBitmapUtil(bmpUtilSize1,EColor16M);
  2324 	DoBitmapUtil(bmpUtilSize1,EColor16MU);
  2325 	DoBitmapUtil(bmpUtilSize1,EColor16MAP);
  2326 
  2327 	INFO_PRINTF1(_L("256x1.. "));
  2328 	DoBitmapUtil(bmpUtilSize2,EGray2);
  2329 	DoBitmapUtil(bmpUtilSize2,EGray4);
  2330 	DoBitmapUtil(bmpUtilSize2,EGray16);
  2331 	DoBitmapUtil(bmpUtilSize2,EGray256);
  2332 	DoBitmapUtil(bmpUtilSize2,EColor16);
  2333 	DoBitmapUtil(bmpUtilSize2,EColor256);
  2334 	DoBitmapUtil(bmpUtilSize2,EColor4K);
  2335 	DoBitmapUtil(bmpUtilSize2,EColor64K);
  2336 	DoBitmapUtil(bmpUtilSize2,EColor16M);
  2337 	DoBitmapUtil(bmpUtilSize2,EColor16MU);
  2338 	DoBitmapUtil(bmpUtilSize2,EColor16MAP);
  2339 
  2340 	INFO_PRINTF1(_L("256x256..\n"));
  2341 	DoBitmapUtil(bmpUtilSize3,EGray2);
  2342 	DoBitmapUtil(bmpUtilSize3,EGray4);
  2343 	DoBitmapUtil(bmpUtilSize3,EGray16);
  2344 	DoBitmapUtil(bmpUtilSize3,EGray256);
  2345 	DoBitmapUtil(bmpUtilSize3,EColor16);
  2346 	DoBitmapUtil(bmpUtilSize3,EColor256);
  2347 	DoBitmapUtil(bmpUtilSize3,EColor4K);
  2348 	DoBitmapUtil(bmpUtilSize3,EColor64K);
  2349 	DoBitmapUtil(bmpUtilSize3,EColor16M);
  2350 	DoBitmapUtil(bmpUtilSize3,EColor16MU);
  2351 	DoBitmapUtil(bmpUtilSize3,EColor16MAP);
  2352 		
  2353     INFO_PRINTF1(_L("Testing wastage bytes in 16M scanlines...\n"));
  2354 	bmpUtilSize1.SetSize(5,13);
  2355 	bmpUtilSize2.SetSize(6,14);
  2356 	bmpUtilSize3.SetSize(7,15);
  2357 	bmpUtilSize4.SetSize(8,16);
  2358 	DoBitmapUtil(bmpUtilSize1,EColor16M);
  2359 	DoBitmapUtil(bmpUtilSize2,EColor16M);
  2360 	DoBitmapUtil(bmpUtilSize3,EColor16M);
  2361 	DoBitmapUtil(bmpUtilSize4,EColor16M);
  2362 
  2363     /*
  2364 	 * Test code commented out as it results in test case failure. 
  2365 	 * Problem recorded in defect DEF001233.
  2366 	 *
  2367 	INFO_PRINTF1(_L("Testing wastage bits in Gray16 scanlines...\n\n"));
  2368 	bmpUtilSize1.SetSize(4,13);
  2369 	bmpUtilSize2.SetSize(5,14);
  2370 	bmpUtilSize3.SetSize(6,15);
  2371 	bmpUtilSize4.SetSize(7,16);
  2372 	DoBitmapUtil(bmpUtilSize1,EGray16);
  2373 	DoBitmapUtil(bmpUtilSize2,EGray16);
  2374 	DoBitmapUtil(bmpUtilSize3,EGray16);
  2375 	DoBitmapUtil(bmpUtilSize4,EGray16);
  2376 	 */
  2377 	}
  2378 
  2379 void CTBitmap::DoBitmapUtil(const TSize& aSize,TDisplayMode aDispMode)
  2380 	{
  2381 	const TPoint startPoint(aSize.iWidth / 3,aSize.iHeight / 3);
  2382 	const TPoint zeroPoint(0,0);
  2383 
  2384 	CFbsBitmapEx bmp1;
  2385 	TInt ret=bmp1.Create(aSize,aDispMode);
  2386 	TEST2(ret, KErrNone);
  2387 	FillBitmap(bmp1);
  2388 
  2389 
  2390 	const TInt numPixels = ((aSize.iWidth + 31) & ~0x1f) * aSize.iHeight;
  2391 	TInt count1;
  2392 	CFbsBitmapEx bmp2;
  2393 
  2394 	ret=bmp2.Create(aSize,aDispMode);
  2395 	TEST2(ret, KErrNone);
  2396 
  2397 	TBitmapUtil util1(&bmp1);
  2398 	util1.Begin(zeroPoint);
  2399 	TBitmapUtil util2(&bmp2);
  2400 	util2.Begin(zeroPoint,util1);
  2401 
  2402 	TPoint currentPosition;
  2403 	for (currentPosition.iY = 0; currentPosition.iY < aSize.iHeight; currentPosition.iY++)
  2404 		for (currentPosition.iX = 0; currentPosition.iX < aSize.iWidth; currentPosition.iX++)
  2405 			{
  2406 			util1.SetPos(currentPosition);
  2407 			util2.SetPos(currentPosition);
  2408 			TUint32 pixelData = util1.GetPixel();
  2409 			util2.SetPixel(pixelData);
  2410 			}
  2411 	util1.End();
  2412 	util2.End();
  2413 	CompareBitmaps(bmp1,bmp2,EColor16M);
  2414 	bmp2.Reset();
  2415 
  2416 	ret=bmp2.Create(aSize,aDispMode);
  2417 	TEST2(ret, KErrNone);
  2418 	util1.Begin(startPoint);
  2419 	util2.Begin(startPoint,util1);
  2420 	for (count1 = 0; count1 < numPixels; count1++)
  2421 		{
  2422 		util2.SetPixel(util1);
  2423 		util1.IncXPos();
  2424 		util2.IncXPos();
  2425 		}
  2426 	util1.End();
  2427 	util2.End();
  2428 	CompareBitmaps(bmp1,bmp2,EColor16M);
  2429 	bmp2.Reset();
  2430 
  2431 	ret=bmp2.Create(aSize,aDispMode);
  2432 	TEST2(ret, KErrNone);
  2433 	util1.Begin(zeroPoint);
  2434 	util2.Begin(zeroPoint,util1);
  2435 	for (currentPosition.iX = 0; currentPosition.iX < aSize.iWidth; currentPosition.iX++)
  2436 		{
  2437 		for (currentPosition.iY = 0; currentPosition.iY < aSize.iHeight; currentPosition.iY++)
  2438 			{
  2439 			util2.SetPixel(util1);
  2440 			util1.IncYPos();
  2441 			util2.IncYPos();
  2442 			}
  2443 		util1.IncXPos();
  2444 		util2.IncXPos();
  2445 		}
  2446 	util1.End();
  2447 	util2.End();
  2448 	CompareBitmaps(bmp1,bmp2,EColor16M);
  2449 	bmp2.Reset();
  2450 
  2451 	ret=bmp2.Create(aSize,aDispMode);
  2452 	TEST2(ret, KErrNone);
  2453 	util1.Begin(startPoint);
  2454 	util2.Begin(startPoint,util1);
  2455 	for (count1 = 0; count1 < numPixels; count1++)
  2456 		{
  2457 		util2.SetPixel(util1);
  2458 		util1.DecXPos();
  2459 		util2.DecXPos();
  2460 		}
  2461 	util1.End();
  2462 	util2.End();
  2463 	CompareBitmaps(bmp1,bmp2,EColor16M);
  2464 	bmp2.Reset();
  2465 
  2466 	ret=bmp2.Create(aSize,aDispMode);
  2467 	TEST2(ret, KErrNone);
  2468 	util1.Begin(zeroPoint);
  2469 	util2.Begin(zeroPoint,util1);
  2470 	for (currentPosition.iX = 0; currentPosition.iX < aSize.iWidth; currentPosition.iX++)
  2471 		{
  2472 		for (currentPosition.iY = 0; currentPosition.iY < aSize.iHeight; currentPosition.iY++)
  2473 			{
  2474 			util2.SetPixel(util1);
  2475 			util1.DecYPos();
  2476 			util2.DecYPos();
  2477 			}
  2478 		util1.DecXPos();
  2479 		util2.DecXPos();
  2480 		}
  2481 	util1.End();
  2482 	util2.End();
  2483 	CompareBitmaps(bmp1,bmp2,EColor16M);
  2484 	bmp2.Reset();
  2485 
  2486 	bmp1.Reset();
  2487 	}
  2488 
  2489 void CTBitmap::BitmapTiming()
  2490 	{
  2491 	INFO_PRINTF1(_L("Test Timing"));
  2492 
  2493 	CFbsBitmap bmp;
  2494 	TInt ret=bmp.Load(iTestBitmapName,ETfbs,NULL);
  2495 	TEST2(ret, KErrNone);
  2496 
  2497 	CDirectFileStore* writestore=NULL;
  2498 	TRAP(ret,writestore=CDirectFileStore::ReplaceL(iFs,KTempFilename,EFileStream|EFileWrite));
  2499 	TEST2(ret, KErrNone);
  2500 	TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
  2501 	TRAP(ret,writestore->SetTypeL(uidtype));
  2502 	TEST2(ret, KErrNone);
  2503 	RStoreWriteStream writestrm;
  2504 	TStreamId headerid(0);
  2505 	TRAP(ret,headerid=writestrm.CreateL(*writestore));
  2506 	TEST2(ret, KErrNone);
  2507 	TRAP(ret,writestore->SetRootL(headerid));
  2508 	TEST2(ret, KErrNone);
  2509 	INFO_PRINTF1(_L("Save time: "));
  2510 	TUint startTime=User::TickCount();
  2511 	for(TInt count=0;count<5000;count++)
  2512 		{
  2513 		TRAP(ret,bmp.ExternalizeL(writestrm));
  2514 		if(ret) break;
  2515 		}
  2516 	TUint stopTime=User::TickCount();
  2517 	TEST2(ret, KErrNone);
  2518 	writestrm.Close();
  2519 	delete writestore;
  2520 	INFO_PRINTF2(_L("%d ticks\r\n"),stopTime-startTime);
  2521 
  2522 	CDirectFileStore* readstore=NULL;
  2523 	TRAP(ret,readstore=CDirectFileStore::OpenL(iFs,KTempFilename,EFileStream|EFileRead));
  2524 	TEST2(ret, KErrNone);
  2525 	RStoreReadStream readstrm;
  2526 	headerid=readstore->Root();
  2527 	INFO_PRINTF1(_L("Load time: "));
  2528 	startTime=User::TickCount();
  2529 	for(TInt count2=0;count2<5000;count2++)
  2530 		{
  2531 		TRAP(ret,readstrm.OpenL(*readstore,headerid));
  2532 		if(ret) break;
  2533 		TRAP(ret,bmp.InternalizeL(readstrm));
  2534 		if(ret) break;
  2535 		readstrm.Close();
  2536 		}
  2537 	stopTime=User::TickCount();
  2538 	TEST2(ret, KErrNone);
  2539 	delete readstore;
  2540 	INFO_PRINTF2(_L("%d ticks\r\n"),stopTime-startTime);
  2541 
  2542 	bmp.Reset();
  2543 	iFs.Delete(KTempFilename);
  2544 
  2545 	
  2546 	}
  2547 
  2548 /**
  2549 	@SYMTestCaseID
  2550 	GRAPHICS-FBSERV-0531
  2551 
  2552 	@SYMTestCaseDesc
  2553 	Tries to load non existing bitmaps from the
  2554 	Z-drive.
  2555 
  2556 	@SYMTestActions
  2557 
  2558 	@SYMTestExpectedResults
  2559 	Test should pass
  2560 */
  2561 void CTBitmap::InvalidBitmap()
  2562 	{
  2563 	INFO_PRINTF1(_L("Test Invalid Bitmap"));
  2564 
  2565 	__UHEAP_MARK;
  2566 	CFbsBitmapEx bmp;
  2567 
  2568 	TInt ret=bmp.Load(_L("z:\\tfbsx.mbm"),ETfbs,NULL);
  2569 	TEST2(ret, KErrNotFound);
  2570 	ret=bmp.Load(_L("z:\\tfbs.xbm"),ETfbs,NULL);
  2571 	TEST2(ret, KErrNotFound);
  2572 	ret=bmp.Load(iTestBitmapName,999,NULL);
  2573 	TEST2(ret, KErrEof);
  2574 	ret=bmp.Load(iTestBitmapName,-1,NULL);
  2575 	TEST2(ret, KErrEof);
  2576 
  2577 	bmp.Reset();
  2578 	User::Heap().Check();
  2579 	__UHEAP_MARKEND;
  2580 
  2581 	
  2582 	}
  2583 
  2584 /**
  2585 	@SYMTestCaseID
  2586 	GRAPHICS-FBSERV-0532
  2587 
  2588 	@SYMTestCaseDesc
  2589 	Creates bitmaps and saves them to the C-drive
  2590 	and loads them back again and compares them to
  2591 	the original bitmaps. 
  2592 
  2593 	@SYMTestActions
  2594 	The test uses different colour depths and sizes
  2595 	of the bitmaps. The sizes of the bitmaps are
  2596 	large.
  2597 
  2598 	@SYMTestExpectedResults
  2599 	Test should pass
  2600 */
  2601 void CTBitmap::SaveAndLoad()
  2602 	{
  2603 	INFO_PRINTF1(_L("Test Save/Load Bitmap"));
  2604 
  2605 	const TInt sizes[] = { 1,2,3,4,5,7,8,9,15,16,17,31,32,33,100 };
  2606 	const TInt numSizes = sizeof(sizes) / sizeof(TInt);
  2607 	TSize size;
  2608 
  2609 	for (TInt widthIndex = 0; widthIndex < numSizes; widthIndex++)
  2610 		{
  2611 		INFO_PRINTF3(_L("Index %d/%d\r"), widthIndex + 1, numSizes);
  2612 		size.iWidth = sizes[widthIndex];
  2613 
  2614 		for (TInt heightIndex = 0; heightIndex < numSizes; heightIndex++)
  2615 			{
  2616 			size.iHeight = sizes[heightIndex];
  2617 
  2618 			DoSaveAndLoad(size,EGray2,EFalse);
  2619 			DoSaveAndLoad(size,EGray2,ETrue);
  2620 			DoSaveAndLoad(size,EGray4,EFalse);
  2621 			DoSaveAndLoad(size,EGray4,ETrue);
  2622 			DoSaveAndLoad(size,EGray16,EFalse);
  2623 			DoSaveAndLoad(size,EGray16,ETrue);
  2624 			DoSaveAndLoad(size,EGray256,EFalse);
  2625 			DoSaveAndLoad(size,EGray256,ETrue);
  2626 			DoSaveAndLoad(size,EColor16,EFalse);
  2627 			DoSaveAndLoad(size,EColor16,ETrue);
  2628 			DoSaveAndLoad(size,EColor256,EFalse);
  2629 			DoSaveAndLoad(size,EColor256,ETrue);
  2630 			DoSaveAndLoad(size,EColor4K,EFalse);
  2631 			DoSaveAndLoad(size,EColor4K,ETrue);
  2632 			DoSaveAndLoad(size,EColor64K,EFalse);
  2633 			DoSaveAndLoad(size,EColor64K,ETrue);
  2634 			DoSaveAndLoad(size,EColor16M,EFalse);
  2635 			DoSaveAndLoad(size,EColor16M,ETrue);
  2636 			DoSaveAndLoad(size,EColor16MU,EFalse);
  2637 			DoSaveAndLoad(size,EColor16MU,ETrue);
  2638 			DoSaveAndLoad(size,EColor16MAP,EFalse);
  2639 			DoSaveAndLoad(size,EColor16MAP,ETrue);
  2640 			}
  2641 		}
  2642 
  2643 	INFO_PRINTF1(_L("\r\n"));
  2644 	
  2645 	}
  2646 
  2647 /**
  2648 	@SYMTestCaseID
  2649 	GRAPHICS-FBSERV-0533
  2650 
  2651 	@SYMTestCaseDesc
  2652 	Creates bitmaps and saves them to the C-drive
  2653 	and loads them back again and compares them to
  2654 	the original bitmaps. 
  2655 
  2656 	@SYMTestActions
  2657 	The test uses different colour depths and sizes
  2658 	of the bitmaps. The sizes of the bitmaps are
  2659 	small.
  2660 
  2661 	@SYMTestExpectedResults
  2662 	Test should pass
  2663 */
  2664 void CTBitmap::SaveAndLoadFast()
  2665 	{
  2666 	INFO_PRINTF1(_L("Test Save/Load Fast Bitmap"));
  2667 
  2668 	// Keep this array small as the test time increases with n^2
  2669 	// This way we can put in bigger sizes...
  2670 	const TInt sizes[] = { 501, 107, 213 };
  2671 	const TInt numSizes = sizeof(sizes) / sizeof(TInt);
  2672 	TSize size;
  2673 
  2674 	for (TInt widthIndex = 0; widthIndex < numSizes; widthIndex++)
  2675 		{
  2676 		INFO_PRINTF3(_L("Index %d/%d\r"), widthIndex + 1, numSizes);
  2677 		size.iWidth = sizes[widthIndex];
  2678 
  2679 		for (TInt heightIndex = 0; heightIndex < numSizes; heightIndex++)
  2680 			{
  2681 			size.iHeight = sizes[heightIndex];
  2682 
  2683 			DoSaveAndLoad(size,EGray2,EFalse);
  2684 			DoSaveAndLoad(size,EGray2,ETrue);
  2685 			DoSaveAndLoad(size,EGray4,EFalse);
  2686 			DoSaveAndLoad(size,EGray4,ETrue);
  2687 			DoSaveAndLoad(size,EGray16,EFalse);
  2688 			DoSaveAndLoad(size,EGray16,ETrue);
  2689 			DoSaveAndLoad(size,EGray256,EFalse);
  2690 			DoSaveAndLoad(size,EGray256,ETrue);
  2691 			DoSaveAndLoad(size,EColor16,EFalse);
  2692 			DoSaveAndLoad(size,EColor16,ETrue);
  2693 			DoSaveAndLoad(size,EColor256,EFalse);
  2694 			DoSaveAndLoad(size,EColor256,ETrue);
  2695 			DoSaveAndLoad(size,EColor4K,EFalse);
  2696 			DoSaveAndLoad(size,EColor4K,ETrue);
  2697 			DoSaveAndLoad(size,EColor64K,EFalse);
  2698 			DoSaveAndLoad(size,EColor64K,ETrue);
  2699 			DoSaveAndLoad(size,EColor16M,EFalse);
  2700 			DoSaveAndLoad(size,EColor16M,ETrue);
  2701 			DoSaveAndLoad(size,EColor16MU,EFalse);
  2702 			DoSaveAndLoad(size,EColor16MU,ETrue);
  2703 			DoSaveAndLoad(size,EColor16MAP,EFalse);
  2704 			DoSaveAndLoad(size,EColor16MAP,ETrue);
  2705 			}
  2706 		}
  2707 
  2708 	INFO_PRINTF1(_L("\r\n"));
  2709 	
  2710 	}
  2711 
  2712 
  2713 void CTBitmap::DoSaveAndLoad(const TSize& aSize,TDisplayMode aDispMode,TBool aBlank)
  2714 	{
  2715 	CFbsBitmapEx bmp1;
  2716 	bmp1.Create(aSize,aDispMode);
  2717 
  2718 	if (aBlank)
  2719 		BlankBitmap(bmp1);
  2720 	else
  2721 		FillBitmap(bmp1);
  2722 
  2723 	TInt ret = bmp1.Save(KTempFilename);
  2724 	TEST2(ret, KErrNone);
  2725 
  2726 	CFbsBitmapEx bmp2;
  2727 	ret = bmp2.Load(KTempFilename);
  2728 	TEST2(ret, KErrNone);
  2729 
  2730 	CompareBitmaps(bmp1,bmp2,EColor16M);
  2731 
  2732 	ret = bmp2.Compress();
  2733 	TEST2(ret, KErrNone);
  2734 
  2735 	CompareBitmaps(bmp1,bmp2,EColor16M);
  2736 
  2737 	iFs.Delete(KTempFilename);
  2738 	}
  2739 
  2740 /**
  2741 	@SYMTestCaseID
  2742 	GRAPHICS-FBSERV-0534
  2743 
  2744 	@SYMTestCaseDesc
  2745 	Compresses bitmaps to ROM and RAM
  2746 
  2747 	@SYMTestActions
  2748 	Tries to compress a bitmap in ROM and expects it to fail. 
  2749 	Compresses a bitmap in RAM and expect it to succeed. 
  2750 	Compression tested when executed in the background.
  2751 	
  2752 	@SYMTestExpectedResults
  2753 	Test should pass
  2754 */
  2755 void CTBitmap::Compress()
  2756 	{
  2757 	INFO_PRINTF1(_L("Test Compression"));
  2758 
  2759 	CFbsBitmap bmp;
  2760 	RFbsSession* fbs = RFbsSession::GetSession();
  2761 	TRequestStatus rs;
  2762 
  2763 	if(!iSkipRomBitmapTests)
  2764 		{
  2765 		INFO_PRINTF1(_L("check compressing of ROM files causes error"));
  2766 
  2767 		TInt ret=bmp.Load(KRomBitmap,ETfbs,NULL);
  2768 		TEST2(ret, KErrNone);
  2769 
  2770 		ret = bmp.Compress();
  2771 		TEST2(ret, KErrAccessDenied); //cannot compress bitmaps in ROM
  2772 
  2773 		ret = bmp.CompressInBackground();
  2774 		TEST2(ret, KErrAccessDenied); //cannot compress bitmaps in ROM
  2775 
  2776 		bmp.CompressInBackground(rs);
  2777 		User::WaitForRequest(rs);
  2778 		TEST2(rs.Int(), KErrAccessDenied); //cannot compress bitmaps in ROM
  2779 
  2780 		ret = bmp.Save(KTempFilename);
  2781 		TEST2(ret, KErrNone);
  2782 		bmp.Reset();
  2783 
  2784 		ret = bmp.Load(KTempFilename);
  2785 		TEST2(ret, KErrNone);
  2786 
  2787 		ret = bmp.Compress();
  2788 		TEST2(ret, KErrNone);
  2789 		TEST(bmp.IsCompressedInRAM());
  2790 		bmp.Reset();
  2791 
  2792 
  2793 		ret = bmp.Load(KTempFilename);
  2794 		TEST2(ret, KErrNone);
  2795 
  2796 		ret = bmp.CompressInBackground();
  2797 		TEST2(ret, KErrNone);
  2798 
  2799 		fbs->SendCommand(EFbsCompress, 0); // force background compression to execute
  2800 
  2801 		TEST(bmp.IsCompressedInRAM());
  2802 		bmp.Reset();
  2803 
  2804 
  2805 		ret = bmp.Load(KTempFilename);
  2806 		TEST2(ret, KErrNone);
  2807 
  2808 		bmp.CompressInBackground(rs);
  2809 		User::WaitForRequest(rs); // wait until background compression is finished
  2810 		TEST2(rs.Int(), KErrNone);
  2811 
  2812 		TEST(bmp.IsCompressedInRAM());
  2813 		bmp.Reset();
  2814 
  2815 
  2816 		iFs.Delete(KTempFilename);
  2817 
  2818 		}
  2819 
  2820 	INFO_PRINTF1(_L("check compressing of RAM files is OK"));
  2821 	
  2822 		{
  2823 		TInt ret=bmp.Load(KTestBitmapOnC,ETfbs,NULL);
  2824 		if(ret != KErrNone)
  2825 			{
  2826 			INFO_PRINTF1(_L("Could not load "));
  2827 			INFO_PRINTF1(KTestBitmapOnC);
  2828 			INFO_PRINTF1(_L(" Ensure is it copied over and rerun test\n"));
  2829 			User::Panic(_L(""), ret);
  2830 			}
  2831 		
  2832 		ret = bmp.Compress();
  2833 		TEST2(ret, KErrNone);
  2834 
  2835 		TEST(bmp.IsCompressedInRAM());
  2836 			
  2837 		ret = bmp.Save(KTempFilename);
  2838 		TEST2(ret, KErrNone);
  2839 		bmp.Reset();
  2840 
  2841 
  2842 		ret = bmp.Load(KTempFilename);
  2843 		TEST2(ret, KErrNone);
  2844 
  2845 		ret = bmp.Compress();
  2846 		TEST2(ret, KErrNone);
  2847 
  2848 		TEST(bmp.IsCompressedInRAM());
  2849 		bmp.Reset();
  2850 
  2851 
  2852 		ret = bmp.Load(KTempFilename);
  2853 		TEST2(ret, KErrNone);
  2854 
  2855 		ret = bmp.CompressInBackground();
  2856 		TEST2(ret, KErrNone);
  2857 
  2858 		fbs->SendCommand(EFbsCompress, 0); // force background compression to execute
  2859 
  2860 		TEST(bmp.IsCompressedInRAM());
  2861 		bmp.Reset();
  2862 
  2863 
  2864 		ret = bmp.Load(KTempFilename);
  2865 		TEST2(ret, KErrNone);
  2866 
  2867 		bmp.CompressInBackground(rs);
  2868 		fbs->SendCommand(EFbsCompress, 0); // force background compression to execute
  2869 		User::WaitForRequest(rs);
  2870 		TEST2(rs.Int(), KErrNone);
  2871 
  2872 		TEST(bmp.IsCompressedInRAM());
  2873 		bmp.Reset();
  2874 
  2875 		iFs.Delete(KTempFilename);
  2876 		}
  2877 
  2878 		
  2879 		INFO_PRINTF1(_L("check compressing a created bitmap"));
  2880 		{
  2881 		INFO_PRINTF1(_L("1\r\n"));
  2882 		CFbsBitmapEx bitmap;
  2883 		TInt ret=bitmap.Create(TSize(200,200),EColor256);
  2884 		TEST2(ret, KErrNone);
  2885 		
  2886 		INFO_PRINTF1(_L("2\r\n"));
  2887 		BlankBitmap(bitmap);
  2888 		
  2889 		ret = bitmap.Compress();
  2890 		TEST2(ret, KErrNone);
  2891 		
  2892 		INFO_PRINTF1(_L("3\r\n"));
  2893 		
  2894 		TEST(bitmap.IsCompressedInRAM());
  2895 		}
  2896 	
  2897 	}
  2898 
  2899 void CTBitmap::BlankBitmap(CFbsBitmapEx& aBitmap)
  2900 	{
  2901 	TSize size = aBitmap.SizeInPixels();
  2902 	TInt dataLength = CFbsBitmap::ScanLineLength(size.iWidth,aBitmap.DisplayMode()) * size.iHeight;
  2903 	aBitmap.LockHeap();
  2904 	Mem::FillZ((TUint8*)aBitmap.DataAddress(),dataLength);
  2905 	aBitmap.UnlockHeap();
  2906 	}
  2907 
  2908 void CTBitmap::FillBitmap(CFbsBitmapEx& aBitmap)
  2909 	{
  2910 	TSize size = aBitmap.SizeInPixels();
  2911 	TInt dataLength = CFbsBitmap::ScanLineLength(size.iWidth,aBitmap.DisplayMode()) * size.iHeight;
  2912 
  2913 	aBitmap.LockHeap();
  2914 	TUint8* bmpBits = (TUint8*)aBitmap.DataAddress();
  2915 	aBitmap.UnlockHeap();
  2916 	TUint8* bmpBitsLimit = bmpBits + dataLength;
  2917 	TInt64 seed = aBitmap.Handle();
  2918 
  2919 	switch (aBitmap.DisplayMode())
  2920 		{
  2921 		case EColor4K:
  2922 			Mem::FillZ(bmpBits,dataLength);
  2923 
  2924 			while (bmpBits < bmpBitsLimit)
  2925 				{
  2926 				*bmpBits++ = (TUint8)Math::Rand(seed);
  2927 				*bmpBits++ = (TUint8)(Math::Rand(seed) & 0x0f);
  2928 				}	
  2929 			break;
  2930 		case EColor16MAP:
  2931 			while (bmpBits < bmpBitsLimit)
  2932 				{
  2933 				TUint32 alpha = (TUint8)Math::Rand(seed);
  2934 				TUint32 red = 	(TUint8)Math::Rand(seed);
  2935 				TUint32 green = (TUint8)Math::Rand(seed);
  2936 				TUint32 blue =  (TUint8)Math::Rand(seed);
  2937 				red = ((red * alpha)/255)&0xff;
  2938 				green  = ((green * alpha)/255)&0xff;
  2939 				blue = ((blue * alpha)/255)&0xff;
  2940 				*(TUint32*)bmpBits = (alpha<<24)|(red<<16)|(green<<8)|blue;
  2941 				bmpBits+=4;
  2942 				}
  2943 			break;
  2944 		default:
  2945 			while (bmpBits < bmpBitsLimit)
  2946 				*bmpBits++ = (TUint8)Math::Rand(seed);
  2947 			break;	
  2948 		}	
  2949 	}
  2950 
  2951 void CTBitmap::StripeBitmap(CFbsBitmapEx& aBitmap) // Compression friendly bitmap filling
  2952 	{
  2953 	TSize size = aBitmap.SizeInPixels();
  2954 	TInt dataLength = CFbsBitmap::ScanLineLength(size.iWidth,aBitmap.DisplayMode()) * size.iHeight;
  2955 
  2956 	aBitmap.LockHeap();
  2957 	TUint8* bmpBits = (TUint8*)aBitmap.DataAddress();
  2958 	aBitmap.UnlockHeap();
  2959 	TUint8* bmpBitsLimit = bmpBits + dataLength;
  2960 	TInt64 seed = aBitmap.Handle();
  2961 
  2962 	if (aBitmap.DisplayMode() != EColor4K)
  2963 		{
  2964 		while (bmpBits < bmpBitsLimit)
  2965 			{
  2966 			TUint8* tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)Math::Rand(seed));
  2967 			while (bmpBits < tempBmpBitsLimit)
  2968 				*bmpBits++ = 0;
  2969 			tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)Math::Rand(seed));
  2970 			while (bmpBits < tempBmpBitsLimit)
  2971 				*bmpBits++ = 0xff;
  2972 			}
  2973 		}
  2974 	else
  2975 		{
  2976 		Mem::FillZ(bmpBits,dataLength);
  2977 
  2978 		while (bmpBits < bmpBitsLimit)
  2979 			{
  2980 			TUint8* tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)(Math::Rand(seed) * 2));
  2981 			while (bmpBits < tempBmpBitsLimit)
  2982 				{
  2983 				*bmpBits++ = 0;
  2984 				*bmpBits++ = 0;
  2985 				}
  2986 			tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)Math::Rand(seed));
  2987 			while (bmpBits < tempBmpBitsLimit)
  2988 				{
  2989 				*bmpBits++ = 0xff;
  2990 				*bmpBits++ = 0x0f;
  2991 				}
  2992 			}		
  2993 		}
  2994 	}
  2995 
  2996 void CTBitmap::CompareBitmaps(CFbsBitmapEx& aBmp1,CFbsBitmapEx& aBmp2,TDisplayMode aDispMode)
  2997 	{
  2998 	// We will compare bitmaps that we draw beginning at four different offsets into the bitmap
  2999 	const TInt KTestBitmapOrigins = 4;
  3000 	const TSize bmpSize = aBmp1.SizeInPixels();
  3001 	TEST(bmpSize == aBmp2.SizeInPixels());
  3002 	TInt originIndex = 0;
  3003 	
  3004 	// Call DoCompareBitmaps() for four different origins
  3005 	for(TInt ii=0;ii<KTestBitmapOrigins;ii++)
  3006 		{
  3007 		TInt xCoord = originIndex*(bmpSize.iWidth/4);
  3008 		TInt yCoord = originIndex*(bmpSize.iHeight/4);
  3009 		DoCompareBitmaps(aBmp1,aBmp2,aDispMode,TPoint(xCoord, yCoord), bmpSize);
  3010 		originIndex++;
  3011 		}
  3012 	}
  3013 	
  3014 void CTBitmap::DoCompareBitmaps(CFbsBitmapEx& aBmp1,CFbsBitmapEx& aBmp2,TDisplayMode aDispMode, TPoint aLineOrigin, TSize aBmpSize)
  3015 	{
  3016 	// Compares two bitmaps line by line
  3017 	const TInt KBitmapWidth = aBmpSize.iWidth;
  3018 	const TInt KStartRow = aLineOrigin.iY;
  3019 	const TInt KBitmapHeight = aBmpSize.iHeight;
  3020 	
  3021 	HBufC8* buf1 = HBufC8::NewMax(KBitmapWidth * 4);
  3022 	HBufC8* buf2 = HBufC8::NewMax(KBitmapWidth * 4);
  3023 	TEST(buf1 && buf2);
  3024 
  3025 	TPtr8 des1(buf1->Des());
  3026 	TPtr8 des2(buf2->Des());
  3027 	
  3028 	for (TInt row = KStartRow; row < KBitmapHeight; row++) 
  3029 		{
  3030 		aBmp1.GetScanLine(des1,aLineOrigin,KBitmapWidth,aDispMode); 
  3031 		aBmp2.GetScanLine(des2,aLineOrigin,KBitmapWidth,aDispMode);
  3032 
  3033 		const TInt ret = des1.Compare(des2);
  3034 		if (ret!=0)
  3035 			{
  3036 			 INFO_PRINTF2(_L("Bitmap comparison failed, row %d differernt!\n"), row);
  3037 			 aBmp1.Save(KFail1Filename);
  3038 			 aBmp2.Save(KFail2Filename);
  3039 			}
  3040 		TEST(ret == 0);
  3041 		}
  3042 
  3043 	delete buf1;
  3044 	delete buf2;
  3045 	}
  3046 
  3047 void CTBitmap::CopyBitmap(CFbsBitmapEx& aBmp1,const CFbsBitmapEx& aBmp2)
  3048 	{
  3049 	TSize bmp1size = aBmp1.SizeInPixels();
  3050 	TSize bmp2size = aBmp2.SizeInPixels();
  3051 	TInt bmp1dataLength = CFbsBitmap::ScanLineLength(bmp1size.iWidth,aBmp1.DisplayMode()) * bmp1size.iHeight;
  3052 	TInt bmp2dataLength = CFbsBitmap::ScanLineLength(bmp2size.iWidth,aBmp2.DisplayMode()) * bmp2size.iHeight;
  3053 	TEST(bmp1dataLength == bmp2dataLength);
  3054 	aBmp1.LockHeap();
  3055 	TUint32* bmp1Bits = aBmp1.DataAddress();
  3056 	aBmp1.UnlockHeap();
  3057 	aBmp2.LockHeap();
  3058 	TUint32* bmp2Bits = aBmp2.DataAddress();
  3059 	aBmp2.UnlockHeap();
  3060 	Mem::Copy((TUint8*)bmp1Bits,(TUint8*)bmp2Bits,bmp1dataLength);
  3061 	}
  3062 
  3063 
  3064 /**
  3065 	@SYMTestCaseID
  3066 	GRAPHICS-FBSERV-0535
  3067 
  3068 	@SYMTestCaseDesc
  3069 	Loads and copies bitmaps and does a
  3070 	fuzzy compare on the bitmaps using 
  3071 	scan lines
  3072 
  3073 	@SYMTestActions
  3074 
  3075 	@SYMTestExpectedResults
  3076 	Test should pass
  3077 */
  3078 void CTBitmap::Color256BitmapUtil()
  3079 	{
  3080 	INFO_PRINTF1(_L("Test CFbsColor256BitmapUtil"));
  3081 
  3082 	CFbsBitmapEx bmpRefDitherFs;
  3083 	TInt ret=bmpRefDitherFs.Load(_L("z:\\system\\data\\8bitDitherFS.mbm"));
  3084 	TEST2(ret, KErrNone);
  3085 
  3086 	CFbsBitmapEx bmpRefNoDither;
  3087 	ret=bmpRefNoDither.Load(_L("z:\\system\\data\\8bitNoDither.mbm"));
  3088 	TEST2(ret, KErrNone);
  3089 
  3090 	TSize size = bmpRefNoDither.SizeInPixels();
  3091 
  3092 	CFbsColor256BitmapUtil* util = NULL;
  3093 	TRAP(ret, util=CFbsColor256BitmapUtil::NewL(NULL));
  3094 	TEST2(ret, KErrNone);
  3095 
  3096 	CFbsBitmapEx bmp2;
  3097 	ret = bmp2.Create(size,EColor256);
  3098 	TEST2(ret, KErrNone);
  3099 
  3100 	CFbsBitmapEx bmp1;
  3101 
  3102 	INFO_PRINTF1(_L("EColor256 "));
  3103 
  3104 	ret = util->CopyBitmap(&bmp2,&bmpRefNoDither,CFbsColor256BitmapUtil::ENoDither);
  3105 	TEST2(ret, KErrNone);
  3106 	CompareBitmaps(bmpRefNoDither,bmp2,EColor16M);
  3107 	ret = util->CopyBitmap(&bmp2,&bmpRefDitherFs,CFbsColor256BitmapUtil::EFloydSteinberg);
  3108 	TEST2(ret, KErrNone);
  3109 	CompareBitmaps(bmpRefDitherFs,bmp2,EColor16M);
  3110 
  3111 	INFO_PRINTF1(_L("EColor4K "));
  3112 
  3113 	ret=bmp1.Load(_L("z:\\system\\data\\12bit.mbm"));
  3114 	TEST2(ret, KErrNone);
  3115 	ret = util->CopyBitmap(&bmp2,&bmp1,CFbsColor256BitmapUtil::ENoDither);
  3116 	TEST2(ret, KErrNone);
  3117 	CompareBitmaps(bmpRefNoDither,bmp2,EColor16M);
  3118 	ret = util->CopyBitmap(&bmp2,&bmp1,CFbsColor256BitmapUtil::EFloydSteinberg);
  3119 	TEST2(ret, KErrNone);
  3120 	FuzzyCompareBitmapsColor256(bmpRefNoDither,bmp2,23);
  3121 
  3122 	INFO_PRINTF1(_L("EColor64K "));
  3123 
  3124 	ret=bmp1.Load(_L("z:\\system\\data\\16bit.mbm"));
  3125 	TEST2(ret, KErrNone);
  3126 	ret = util->CopyBitmap(&bmp2,&bmp1,CFbsColor256BitmapUtil::ENoDither);
  3127 	TEST2(ret, KErrNone);
  3128 	CompareBitmaps(bmpRefNoDither,bmp2,EColor16M);
  3129 	ret = util->CopyBitmap(&bmp2,&bmp1,CFbsColor256BitmapUtil::EFloydSteinberg);
  3130 	TEST2(ret, KErrNone);
  3131 	FuzzyCompareBitmapsColor256(bmpRefNoDither,bmp2,28);
  3132 
  3133 	INFO_PRINTF1(_L("EColor16M\r\n"));
  3134 
  3135 	ret=bmp1.Load(_L("z:\\system\\data\\24bit.mbm"));
  3136 	TEST2(ret, KErrNone);
  3137 	ret = util->CopyBitmap(&bmp2,&bmp1,CFbsColor256BitmapUtil::ENoDither);
  3138 	TEST2(ret, KErrNone);
  3139 	CompareBitmaps(bmpRefNoDither,bmp2,EColor16M);
  3140 	ret = util->CopyBitmap(&bmp2,&bmp1,CFbsColor256BitmapUtil::EFloydSteinberg);
  3141 	TEST2(ret, KErrNone);
  3142 	FuzzyCompareBitmapsColor256(bmpRefNoDither,bmp2,32);
  3143 
  3144 	INFO_PRINTF1(_L("EColor16MU\r\n"));
  3145 
  3146 	ret=bmp1.Load(_L("z:\\system\\data\\32bit.mbm"));
  3147 	TEST2(ret, KErrNone);
  3148 	ret = util->CopyBitmap(&bmp2,&bmp1,CFbsColor256BitmapUtil::ENoDither);
  3149 	TEST2(ret, KErrNone);
  3150 	CompareBitmaps(bmpRefNoDither,bmp2,EColor16M);
  3151 	ret = util->CopyBitmap(&bmp2,&bmp1,CFbsColor256BitmapUtil::EFloydSteinberg);
  3152 	TEST2(ret, KErrNone);
  3153 	FuzzyCompareBitmapsColor256(bmpRefNoDither,bmp2,32);
  3154 	
  3155 	CFbsBitmapEx bmp3;
  3156 	ret = bmp3.Create(size,EColor16MAP);
  3157 	TEST2(ret, KErrNone);
  3158 	CopyBitmap(bmp3,bmp1);
  3159 	TEST2(ret, KErrNone);
  3160 	ret = util->CopyBitmap(&bmp2,&bmp3,CFbsColor256BitmapUtil::ENoDither);
  3161 	TEST2(ret, KErrNone);
  3162 	//Do not compare bitmaps since there is no reference EColor16MAP image
  3163 	//CompareBitmaps(bmpRefNoDither,bmp2,EColor16M); - testing ensures that
  3164 	//copying succeeds, not accuracy
  3165 	ret = util->CopyBitmap(&bmp2,&bmp3,CFbsColor256BitmapUtil::EFloydSteinberg);
  3166 	TEST2(ret, KErrNone);
  3167 	//Do not compare bitmaps since there is no reference EColor16MAP image
  3168 	//FuzzyCompareBitmapsColor256(bmpRefNoDither,bmp2,32); - testing ensures that
  3169 	//copying succeeds, not accuracy
  3170 	bmp3.Reset();	
  3171 
  3172 //	bmp2.Save(_L("c:\\8bitSaved.mbm"));
  3173 
  3174 	bmp1.Reset();
  3175 	bmp2.Reset();
  3176 	bmpRefNoDither.Reset();
  3177 	bmpRefDitherFs.Reset();
  3178 	delete util;
  3179 
  3180 	
  3181 	}
  3182 
  3183 void CTBitmap::FuzzyCompareBitmapsColor256(CFbsBitmapEx& aBmp1,CFbsBitmapEx& aBmp2,TUint aDifLimit)
  3184 	{
  3185 	TSize bmp1size = aBmp1.SizeInPixels();
  3186 	TSize bmp2size = aBmp2.SizeInPixels();
  3187 	TInt bmp1dataLength = CFbsBitmap::ScanLineLength(bmp1size.iWidth,aBmp1.DisplayMode()) * bmp1size.iHeight;
  3188 	TInt bmp2dataLength = CFbsBitmap::ScanLineLength(bmp2size.iWidth,aBmp2.DisplayMode()) * bmp2size.iHeight;
  3189 	TEST(bmp1dataLength == bmp2dataLength);
  3190 	aBmp1.LockHeap();
  3191 	TUint8* bmp1Bits = (TUint8*)aBmp1.DataAddress();
  3192 	aBmp1.UnlockHeap();
  3193 	aBmp2.LockHeap();
  3194 	TUint8* bmp2Bits = (TUint8*)aBmp2.DataAddress();
  3195 	aBmp2.UnlockHeap();
  3196 
  3197 	TUint totalDifference = 0;
  3198 	TUint difference = 0;
  3199 	while(bmp1dataLength--)
  3200 		{
  3201 		difference = TRgb::Color256((TUint)*(bmp1Bits++)).Difference(TRgb::Color256((TUint)*(bmp2Bits++)));
  3202 		totalDifference+=difference;
  3203 		}
  3204 	TUint avDif = totalDifference/bmp2dataLength;
  3205 	TEST(avDif<=aDifLimit);
  3206 	}
  3207 
  3208 /**
  3209 	@SYMTestCaseID
  3210 	GRAPHICS-FBSERV-0536
  3211 
  3212 	@SYMTestCaseDesc
  3213 	Creates a hardware bitmap with a size and 
  3214 	display mode for different display modes. 
  3215 
  3216 	@SYMTestActions
  3217 	It checks some bitmap attributes, bitmapHandle,
  3218 	if it is a large bitmap and if the bitmap is in ROM.
  3219 	Creates a 'normal' bitmap with the same size as the 
  3220 	hardware one. Checks it can write to the hardware 
  3221 	bitmap. Checks reuse of a CFbsBitmap for mixture of 
  3222 	hardware and normal bitmaps works.
  3223 
  3224 	@SYMTestExpectedResults
  3225 	Test should pass
  3226 */
  3227 void CTBitmap::HardwareBitmaps()
  3228 	{
  3229 	static const TDisplayMode modes[] =
  3230 		{
  3231 		EGray2,
  3232 		EGray4,
  3233 		EGray16,
  3234 		EGray256,
  3235 		EColor16,
  3236 		EColor256,
  3237 		EColor64K,
  3238 		EColor16M,
  3239 		EColor16MU,
  3240 		EColor4K,
  3241 		EColor16MAP,
  3242 		ENone
  3243 		};
  3244 
  3245 	INFO_PRINTF1(_L("Test Hardware Bitmaps"));
  3246 
  3247 	CFbsBitmapEx bitmap1;
  3248 	// Large bitmap threshold increased from 4K to 64K
  3249 	TSize size(300,300);
  3250 	TDisplayMode displayMode;
  3251 
  3252 	// Try and find a display mode that hardware bitmaps support
  3253 	TInt ret = KErrNotSupported;
  3254 	TInt i=0;
  3255 	while((displayMode=modes[i])!=ENone)
  3256 		{
  3257 		ret = bitmap1.CreateHardwareBitmap(size,displayMode,TUid::Uid(0));
  3258 		if(ret!=KErrNotSupported)
  3259 			{
  3260 			TEST2(ret, KErrNone);
  3261 			break;
  3262 			}
  3263 		i++;
  3264 		}
  3265 
  3266 	if(ret==KErrNotSupported)
  3267 		{
  3268 		// Hardware bitmaps not supported on this device
  3269 		WARN_PRINTF1(_L("...Not Supported"));
  3270 		return;
  3271 		}
  3272 
  3273 	// Check some bitmap attributes
  3274 	TEST(bitmap1.HardwareBitmapHandle()!=NULL);
  3275 	TEST(!bitmap1.IsLargeBitmap());
  3276 	TEST(!bitmap1.IsRomBitmap());
  3277 
  3278 	// Create a 'normal' bitmap the same size as the hardware one
  3279 	CFbsBitmapEx bitmap2;
  3280 	ret = bitmap2.Create(size,displayMode);
  3281 	TEST2(ret, KErrNone);
  3282 	TEST(bitmap2.HardwareBitmapHandle()==NULL);
  3283 	TEST(bitmap2.IsLargeBitmap());
  3284 
  3285 	// Check we can write to the hardware bitmap OK
  3286 	FillBitmap(bitmap1);
  3287 	CopyBitmap(bitmap1,bitmap2);
  3288 	CompareBitmaps(bitmap1,bitmap2,EColor16M);
  3289 
  3290 	// Discard hardware bitmap
  3291 	bitmap1.Reset();
  3292 
  3293 	// Check reuse of a CFbsBitmap for mixture of hardware and normal bitmaps works
  3294 	ret = bitmap2.CreateHardwareBitmap(size,displayMode,TUid::Uid(0));
  3295 	TEST2(ret, KErrNone);
  3296 	ret = bitmap2.Create(TSize(10,10),displayMode);
  3297 	TEST2(ret, KErrNone);
  3298 	ret = bitmap2.CreateHardwareBitmap(size,displayMode,TUid::Uid(0));
  3299 	TEST2(ret, KErrNone);
  3300 	ret = bitmap2.Create(size,displayMode);
  3301 	TEST2(ret, KErrNone);
  3302 	}
  3303 
  3304 /**
  3305 	@SYMTestCaseID
  3306 	GRAPHICS-FBSERV-0537
  3307 
  3308 	@SYMTestCaseDesc
  3309 	GetScanLine test
  3310 	
  3311 	@SYMDEF INC036062
  3312 
  3313 	@SYMTestActions
  3314 	For each possible display mode it creates a test bitmap
  3315 	and initialize it with the data from the gray bitmap.
  3316 	Then for each possible display mode it calls GetScanLine 
  3317 	on the gray and	test bitmaps and compares the lines.
  3318 		
  3319 	@SYMTestExpectedResults
  3320 	Test should pass
  3321 */
  3322 void CTBitmap::INC036062L()
  3323 //INC036062  -  Optimise masked bitblit for 1 bit greyscale mask case 
  3324 	{
  3325 	INFO_PRINTF1(_L("INC036062"));
  3326 	TDisplayMode displayMode[] = 
  3327 		{
  3328 		EGray2, EGray4, EGray16, EGray256, EColor16, EColor256, 
  3329 		EColor64K, EColor16M, EColor4K, EColor16MU, EColor16MAP
  3330 		};
  3331 	//Two EGray2 test bitmaps with sizes (11, 11) and (121, 121).
  3332 	TSize size[] = 
  3333 		{
  3334 		TSize(11, 11), TSize(121, 121)
  3335 		};
  3336 	//Masks for for the last scanline byte (probably partially initialized)
  3337 	TUint8 mask[sizeof(size)/sizeof(size[0])][sizeof(displayMode)/sizeof(displayMode[0])] = 
  3338 		{
  3339 		//EGray2 EGray4 EGray16 EGray256 EColor16 EColor256 EColor64K EColor16M EColor4K EColor16MU
  3340 		{0x07,   0x3F,  0x0F,   0xFF,    0x0F,    0xFF,     0xFF,     0xFF,     0x0F,    0xFF},
  3341 		{0x01,   0x03,  0x0F,   0xFF,    0x0F,    0xFF,     0xFF,     0xFF,     0x0F,    0xFF}
  3342 		};
  3343 	for(TInt i=0;i<TInt(sizeof(size)/sizeof(size[0]));i++)
  3344 		{
  3345 		//Create EGray2 bitmap
  3346 		CFbsBitmap* bmp = CreateBitmapLC(size[i], EGray2);
  3347 		//GetScanLine test - for each possible display mode: create a test bitmap
  3348 		//and initialize it with the data from the gray bitmap.
  3349 		//After that: for each possible display mode - call GetScanLine on the gray and
  3350 		//test bitmaps and compare the lines.
  3351 		for(TInt m=0;m<TInt(sizeof(displayMode)/sizeof(displayMode[0]));m++)
  3352 			{
  3353 			HBufC8* row1 = HBufC8::NewLC(1000);
  3354 			TPtr8 prow1 = row1->Des();
  3355 			HBufC8* row2 = HBufC8::NewLC(1000);
  3356 			TPtr8 prow2 = row2->Des();
  3357 			//Create test bitmap
  3358 			CFbsBitmap* tbmp = CreateBitmapLC(size[i], displayMode[m], bmp);
  3359 			//Check test bitmap
  3360 			for(TInt m2=0;m2<TInt(sizeof(displayMode)/sizeof(displayMode[0]));m2++)
  3361 				{
  3362 				for(TInt y=0;y<size[i].iHeight;y++)
  3363 					{
  3364 					bmp->GetScanLine(prow1, TPoint(0, y), size[i].iWidth, displayMode[m2]);
  3365 					tbmp->GetScanLine(prow2, TPoint(0, y), size[i].iWidth, displayMode[m2]);
  3366 					TInt len = prow1.Length();
  3367 					TEST(len == prow2.Length());
  3368 					TEST(len > 0);
  3369 					TUint8 b1 = prow1[len - 1];
  3370 					TUint8 b2 = prow2[len - 1];
  3371 					if(mask[i][m2] != 0xFF)
  3372 						{//Not all bits from the last byte are used.
  3373 						TEST((b1 & mask[i][m2]) == (b2 & mask[i][m2]));
  3374 						prow1.SetLength(len - 1);
  3375 						prow2.SetLength(len - 1);
  3376 						}
  3377 					TEST(prow1 == prow2);
  3378 					}//end of - for(TInt y=0;y<size[i].iHeight;y++)
  3379 				}//end of - for(TInt m2=0;m2<(sizeof(displayMode)/sizeof(displayMode[0]));m2++)
  3380 			CleanupStack::PopAndDestroy(tbmp);
  3381 			CleanupStack::PopAndDestroy(row2);
  3382 			CleanupStack::PopAndDestroy(row1);
  3383 			}//end of - for(TInt m=0;m<(sizeof(displayMode)/sizeof(displayMode[0]));m++)
  3384 		CleanupStack::PopAndDestroy(bmp);
  3385 		}//end of - for(TInt i=0;i<(sizeof(size)/sizeof(size[0]));i++)
  3386 	}
  3387 
  3388 /**
  3389 	@SYMTestCaseID
  3390 	GRAPHICS-FBSERV-0538
  3391 
  3392 	@SYMTestCaseDesc
  3393 	Performance test of INC036062 (GetScanLine test)
  3394 
  3395 	@SYMDEF INC036062
  3396 
  3397 	@SYMTestActions
  3398 		
  3399 	@SYMTestExpectedResults
  3400 	Test should pass
  3401 */
  3402 void CTBitmap::PerformanceTest_INC036062L()
  3403 //INC036062  -  Optimise masked bitblit for 1 bit greyscale mask case 
  3404 	{
  3405 	INFO_PRINTF1(_L("INC036062-Performance Test"));
  3406 	TSize size(143, 143);
  3407 	//Create EGray2 bitmap
  3408 	CFbsBitmap* bmpGray2 = CreateBitmapLC(size, EGray2);
  3409 	//Create EColor64 bitmap
  3410 	CFbsBitmap* bmpEColor64 = CreateBitmapLC(size, EColor64K);
  3411 	//Performance test
  3412 	TDisplayMode displayMode[] = 
  3413 		{
  3414 		EGray2, EGray4, EGray16, EGray256, EColor16, EColor256, 
  3415 		EColor64K, EColor16M, EColor4K, EColor16MU, EColor16MAP
  3416 		};
  3417 	TInt i;
  3418 	HBufC8* row = HBufC8::NewLC(1000);
  3419 	TPtr8 prow = row->Des();
  3420 	for(TInt m=0;m<TInt(sizeof(displayMode)/sizeof(displayMode[0]));m++)
  3421 		{
  3422 		TUint time[2] = {0, 0};
  3423 		CFbsBitmap* pbmp[2] = {bmpGray2, bmpEColor64};
  3424 		for(TInt j=0;j<2;j++)
  3425 			{
  3426 			time[j] = User::TickCount();
  3427 			for(i=0;i<200;i++)
  3428 				{
  3429 				for(TInt y=0;y<size.iHeight;y++)
  3430 					{
  3431 					pbmp[j]->GetScanLine(prow, TPoint(0, y), size.iWidth, displayMode[m]);
  3432 					}
  3433 				}
  3434 			time[j] = User::TickCount() - time[j];
  3435 			}
  3436 		//"Time+" - time with optimized GetScanLine for EGray2 bitmaps
  3437 		//"Time-" - time with GetScanLine for all bitmaps which colour is not EGray2.
  3438 		INFO_PRINTF4(_L("GetScanLine. Mode=%d, Time+ =%d, Time- =%d\r\n"), displayMode[m], time[0], time[1]);
  3439 		}
  3440 	CleanupStack::PopAndDestroy(row);
  3441 	CleanupStack::PopAndDestroy(bmpEColor64);
  3442 	CleanupStack::PopAndDestroy(bmpGray2);
  3443 	}
  3444 
  3445 CFbsBitmap* CTBitmap::CreateBitmapLC(const TSize& aSize, TDisplayMode aMode)
  3446 	{
  3447 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  3448 	CleanupStack::PushL(bmp);
  3449 	User::LeaveIfError(bmp->Create(aSize, aMode));
  3450 	//Initialize the bitmap
  3451 	TBitmapUtil bmpUtil(bmp);
  3452 	bmpUtil.Begin(TPoint(0, 0));
  3453 	for(TInt y=0;y<aSize.iHeight;bmpUtil.IncYPos(),y++)
  3454 		{
  3455 		for(TInt x=0;x<aSize.iWidth;bmpUtil.IncXPos(),x++)
  3456 			{
  3457 			TUint32 color = 0;
  3458 			switch(aMode)
  3459 				{
  3460 				case EGray2:
  3461 					color = Math::Random() % 2;
  3462 					break;
  3463 				case EColor64K:
  3464 					color = Math::Random() % 0x10000;
  3465 					break;
  3466 				case EColor16MA:
  3467 					color = Math::Random();
  3468 					break;
  3469 				default:
  3470 					break;
  3471 				}
  3472 			bmpUtil.SetPixel(color);
  3473 			}
  3474 		}
  3475 	bmpUtil.End();
  3476 	return bmp;
  3477 	}
  3478 
  3479 CFbsBitmap* CTBitmap::CreateBitmapLC(const TSize& aSize, TDisplayMode aMode, const CFbsBitmap* aSrcBmp)
  3480 	{
  3481 	CFbsBitmap* tbmp = new (ELeave) CFbsBitmap;
  3482 	CleanupStack::PushL(tbmp);
  3483 	User::LeaveIfError(tbmp->Create(aSize, aMode));
  3484 	//Initialize test bitmap
  3485 	HBufC8* row = HBufC8::NewLC(1000);
  3486 	TPtr8 prow = row->Des();
  3487 	for(TInt y=0;y<aSize.iHeight;y++)
  3488 		{
  3489 		aSrcBmp->GetScanLine(prow, TPoint(0, y), aSize.iWidth, aMode);
  3490 		tbmp->SetScanLine(prow, y);
  3491 		}
  3492 	CleanupStack::PopAndDestroy(row);
  3493 	return tbmp;
  3494 	}
  3495 
  3496 /**
  3497 	@SYMTestCaseID
  3498 	GRAPHICS-FBSERV-0539
  3499 
  3500 	@SYMTestCaseDesc
  3501 	Loads bitmaps from ROM and RAM
  3502 	and does a GetScanLine on the bitmaps
  3503 	and measures the time it takes to do
  3504 	the GetScanLine.
  3505 	
  3506 	@SYMDEF INC037474
  3507 	
  3508 	@SYMTestActions
  3509 	
  3510 	@SYMTestExpectedResults
  3511 	Test should pass
  3512 */
  3513 void CTBitmap::INC037474L()
  3514 //INC037474 - SS66 - CBitwiseBitmap::GenerateLineFromCompressedSixteenBitData() is very slow
  3515 	{
  3516 	TPtrC bmpFile[] =
  3517 		{
  3518 		KBmpCompr12(),
  3519 		KBmpCompr16(),
  3520 		KBmpCompr24(),
  3521 		KBmpCCompr12(),
  3522 		KBmpCCompr16(),
  3523 		KBmpCCompr24()
  3524 		};
  3525 	TPtrC tt[] = {_L("rom"), _L("rom"), _L("rom"), _L("ram"), _L("ram"), _L("ram")};
  3526 	TBool inRam[] = {EFalse, EFalse, EFalse, ETrue, ETrue, ETrue};
  3527 	TInt bpp[] = {12, 16, 24, 12, 16, 24};
  3528 	TDisplayMode targetMode[] = {EColor4K, EColor64K, EColor16M, EColor4K, EColor64K, EColor16M};
  3529 	const TInt KMaxScanLineLen = 800;
  3530 	TBuf8<KMaxScanLineLen> scanLineBuf;
  3531 	for(TInt i=0;i<TInt(sizeof(bmpFile)/sizeof(bmpFile[0]));i++)
  3532 		{
  3533 		if(iSkipRomBitmapTests && !inRam[i])
  3534 			continue;
  3535 		
  3536 		CFbsBitmap* bmp = LoadBitmapLC(bmpFile[i]);
  3537 		if(inRam[i])
  3538 			{
  3539 			User::LeaveIfError(bmp->Compress());
  3540 			}
  3541 		//
  3542 		TDesC& des = tt[i];
  3543 		INFO_PRINTF3(_L("%d bpp %S compressed bitmap, GetScanLine test\r\n"), bpp[i], &des);
  3544 		TSize size = bmp->SizeInPixels();
  3545 		TEST(TInt(size.iWidth * sizeof(TInt16)) <= KMaxScanLineLen);
  3546 		TUint timeStart = User::TickCount();
  3547 		enum {KTestTimes = 15};//Greater KTestTimes values make the test is too slow!
  3548 		for(TInt j=0;j<KTestTimes;j++) 
  3549 			{
  3550 			TPoint startPixel(0, 0);
  3551 			for(TInt k=0;k<size.iHeight;k++)
  3552 				{
  3553 				startPixel.iY = k;
  3554 				bmp->GetScanLine(scanLineBuf, startPixel, size.iWidth, targetMode[i]);
  3555 				}
  3556 			}
  3557 		TUint timeEnd = User::TickCount();
  3558 		INFO_PRINTF4(_L("%d bpp %S compressed bitmap, time = %d\r\n"), bpp[i], &des, timeEnd - timeStart);
  3559 		//
  3560 		CleanupStack::PopAndDestroy(bmp);
  3561 		}
  3562 	}
  3563 
  3564 CFbsBitmap* CTBitmap::LoadBitmapLC(const TDesC& aFileName)
  3565 	{
  3566 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  3567 	CleanupStack::PushL(bmp);
  3568 	const TInt err = bmp->Load(aFileName, 0);
  3569 	TEST(err == KErrNone);
  3570 	User::LeaveIfError(err);
  3571 	return bmp;
  3572 	}
  3573 
  3574 /**
  3575 	@SYMTestCaseID
  3576 	GRAPHICS-FBSERV-0540
  3577 
  3578 	@SYMTestCaseDesc
  3579 	Test to verify defect DEF038286.
  3580 	
  3581 	@SYMDEF DEF038286
  3582 
  3583 	@SYMTestActions
  3584 	Initialized a test bitmap, compresses it
  3585 	and performs a GetScanLine on the compressed
  3586 	bitmap. Checks the color value against an
  3587 	expected value.
  3588 	
  3589 	@SYMTestExpectedResults
  3590 	Test should pass
  3591 */
  3592 void CTBitmap::DEF038286L()
  3593 //DEF038286 - CBitwiseBitmap::GenerateLineFromCompressedSixteenBitData returns wrong clr value	
  3594 	{
  3595 	INFO_PRINTF1(_L("DEF038286 fix test"));
  3596 	//Create test bitmap
  3597 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  3598 	CleanupStack::PushL(bmp);
  3599 	const TInt width = 16;
  3600 	const TSize size(width, 1);
  3601 	User::LeaveIfError(bmp->Create(size, EColor64K));
  3602 	//Test bitmap data
  3603 	TUint8 colorVal[width * 2] = 
  3604 	//	 0          1          2          3          4          5          6          7
  3605 		{0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
  3606 	//	 8          9          10         11         12         13         14         15
  3607 	     0x00,0x00, 0x00,0x00, 0x00,0x00, 0xFF,0xFF, 0xFF,0xFF, 0xFF,0xFF, 0xFF,0xFF, 0xFF,0xFF};
  3608 	//Initialize test bitmap
  3609 	TPtr8 ptr(colorVal, width * 2, width * 2);
  3610 	bmp->SetScanLine(ptr, 0);
  3611 	//Compress test bitmap
  3612 	User::LeaveIfError(bmp->Compress());
  3613 	//Check the test data
  3614 	TUint8 colorVal2[width * 2];
  3615 	TPtr8 ptr2(colorVal2, width * 2, width * 2);
  3616 	//test 1
  3617 	colorVal2[0] = colorVal2[1] = colorVal2[2] = colorVal2[3] = 0x12;
  3618 	bmp->GetScanLine(ptr2, TPoint(10, 0), 2, EColor64K);
  3619 	TEST(colorVal2[0] == colorVal[10 * 2] && colorVal2[1] == colorVal[10 * 2 + 1] &&
  3620 		  colorVal2[2] == colorVal[11 * 2] && colorVal2[3] == colorVal[11 * 2 + 1]);
  3621 	//test 2
  3622 	colorVal2[0] = colorVal2[1] = colorVal2[2] = colorVal2[3] = 0x12;
  3623 	bmp->GetScanLine(ptr2, TPoint(10, 0), 1, EColor64K);
  3624 	TEST(colorVal2[0] == colorVal[10 * 2] && colorVal2[1] == colorVal[10 * 2 + 1]);
  3625 	//test 3
  3626 	colorVal2[0] = colorVal2[1] = colorVal2[2] = colorVal2[3] = 0x12;
  3627 	bmp->GetScanLine(ptr2, TPoint(11, 0), 1, EColor64K);
  3628 	TEST(colorVal2[0] == colorVal[11 * 2] && colorVal2[1] == colorVal[11 * 2 + 1]);
  3629 
  3630 	//Destroy test bitmap and data
  3631 	CleanupStack::PopAndDestroy(bmp);
  3632 	}
  3633 
  3634 /**
  3635 	@SYMTestCaseID
  3636 	GRAPHICS-FBSERV-0541
  3637 
  3638 	@SYMTestCaseDesc
  3639 	Test to verify defect DEF038286.
  3640 	
  3641 	@SYMDEF DEF038286
  3642 
  3643 	@SYMTestActions
  3644 	Initialized a test bitmap, compresses it
  3645 	and performs a GetScanLine on the compressed
  3646 	bitmap. Checks the colour value against an
  3647 	expected value.
  3648 	
  3649 	@SYMTestExpectedResults
  3650 	Test should pass
  3651 */
  3652 void CTBitmap::DEF038286_2L()
  3653 //DEF038286 - CBitwiseBitmap::GenerateLineFromCompressedSixteenBitData returns wrong clr value
  3654 //24 bpp bitmap test
  3655 	{
  3656 	INFO_PRINTF1(_L("DEF038286 fix test. 24 bpp bitmap."));
  3657 	//Create test bitmap
  3658 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  3659 	CleanupStack::PushL(bmp);
  3660 	const TInt width = 16;
  3661 	const TSize size(width, 1);
  3662 	User::LeaveIfError(bmp->Create(size, EColor16M));
  3663 	//Test bitmap data
  3664 	TUint8 colorVal[width * 3] = 
  3665 	//	 0               1               2               3               4               5               6			     7
  3666 		{0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00,
  3667 	//	 8               9               10              11              12              13              14              15
  3668 	     0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF};
  3669 	//Initialize test bitmap
  3670 	TPtr8 ptr(colorVal, width * 3, width * 3);
  3671 	bmp->SetScanLine(ptr, 0);
  3672 	//Compress test bitmap
  3673 	User::LeaveIfError(bmp->Compress());
  3674 	//Check the test data
  3675 	TUint8 colorVal2[width * 3];
  3676 	TPtr8 ptr2(colorVal2, width * 3, width * 3);
  3677 	//test 1
  3678 	colorVal2[0] = colorVal2[1] = colorVal2[2] = colorVal2[3] = colorVal2[4] = colorVal2[5] = 0x12;
  3679 	bmp->GetScanLine(ptr2, TPoint(10, 0), 2, EColor16M);
  3680 	TEST(colorVal2[0] == colorVal[10 * 3] && colorVal2[1] == colorVal[10 * 3 + 1] && colorVal2[2] == colorVal[10 * 3 + 2] &&
  3681 		  colorVal2[3] == colorVal[11 * 3] && colorVal2[4] == colorVal[11 * 3 + 1] && colorVal2[5] == colorVal[11 * 3 + 2]);
  3682 	//test 2
  3683 	colorVal2[0] = colorVal2[1] = colorVal2[2] = colorVal2[3] = colorVal2[4] = colorVal2[5] = 0x12;
  3684 	bmp->GetScanLine(ptr2, TPoint(10, 0), 1, EColor16M);
  3685 	TEST(colorVal2[0] == colorVal[10 * 3] && colorVal2[1] == colorVal[10 * 3 + 1] && colorVal2[2] == colorVal[10 * 3 + 2]);
  3686 	//test 3
  3687 	colorVal2[0] = colorVal2[1] = colorVal2[2] = colorVal2[3] = colorVal2[4] = colorVal2[5] = 0x12;
  3688 	bmp->GetScanLine(ptr2, TPoint(11, 0), 1, EColor16M);
  3689 	TEST(colorVal2[0] == colorVal[11 * 3] && colorVal2[1] == colorVal[11 * 3 + 1] && colorVal2[2] == colorVal[11 * 3 + 2]);
  3690 
  3691 	//Destroy test bitmap and data
  3692 	CleanupStack::PopAndDestroy(bmp);
  3693 	}
  3694 
  3695 /**
  3696 	@SYMTestCaseID
  3697 	GRAPHICS-FBSERV-0542
  3698 
  3699 	@SYMTestCaseDesc
  3700 	Tests the function CFbsBitmap::IsMonochrome()
  3701 
  3702 	@SYMTestActions
  3703 	Loads uncompressed bitmaps and checks
  3704 	them if they are monochrome
  3705 	
  3706 	@SYMTestExpectedResults
  3707 	Test should pass
  3708 */
  3709 void CTBitmap::MonohromeL()
  3710 	{
  3711 	INFO_PRINTF1(_L("Monohrome bitmaps"));
  3712 	TPtrC bitmap_ram[] = 
  3713 		{
  3714 		KMono_M1(),
  3715 		KMono_M2(),
  3716 		KMono_M4(),
  3717 		KMono_M8(),
  3718 		KMono_C4(),
  3719 		KMono_C8(),
  3720 		KMono_C12(),
  3721 		KMono_C16(),
  3722 		KMono_C24(),
  3723 		KMono_C32()
  3724 		};
  3725 	TInt i;
  3726 	//Check monohrome bitmaps
  3727 	//1 bpp bitmap is always monochrome
  3728 	for(i=0;i<TInt(sizeof(bitmap_ram)/sizeof(bitmap_ram[0]));i++)
  3729 		{
  3730 		CFbsBitmap* uncompressedBitmap = NULL;
  3731 		LoadAndNotCompressBitmapLC(uncompressedBitmap, bitmap_ram[i]);
  3732 		TEST(!uncompressedBitmap->IsCompressedInRAM());
  3733 		TBool monochrome = uncompressedBitmap->IsMonochrome();
  3734 		TEST(monochrome);
  3735 		CleanupStack::PopAndDestroy(uncompressedBitmap);
  3736 		}
  3737 	//Modify monohrome bitmaps and check them
  3738 	//1 bpp bitmap is always monochrome
  3739 	for(i=0;i<TInt(sizeof(bitmap_ram)/sizeof(bitmap_ram[0]));i++)
  3740 		{
  3741 		CFbsBitmap* uncompressedBitmap = NULL;
  3742 		LoadAndNotCompressBitmapLC(uncompressedBitmap, bitmap_ram[i]);
  3743 		TEST(!uncompressedBitmap->IsCompressedInRAM());
  3744 		//Change something into the bitmap data
  3745 		uncompressedBitmap->LockHeap(ETrue);
  3746 		TUint32* data = uncompressedBitmap->DataAddress();
  3747 		*data = 0x12345678;
  3748 		uncompressedBitmap->UnlockHeap(ETrue);
  3749 		//Check the bitmap
  3750 		TBool monochrome = uncompressedBitmap->IsMonochrome();
  3751 		TEST(i > 0 ? !monochrome : monochrome);
  3752 		CleanupStack::PopAndDestroy(uncompressedBitmap);
  3753 		}
  3754 	}
  3755 
  3756 /**
  3757 	@SYMTestCaseID
  3758 	GRAPHICS-FBSERV-0543
  3759 
  3760 	@SYMTestCaseDesc
  3761 	Tests the function CFbsBitmap::GetVerticalScanLine
  3762 
  3763 	@SYMTestActions
  3764 	Gets the bitmap's vertical scanline starting at 
  3765 	a specified x co-ordinate.
  3766 	
  3767 	@SYMTestExpectedResults
  3768 	Test should pass
  3769 */
  3770 void CTBitmap::GetVerticalScanLineL()
  3771 	{
  3772 	INFO_PRINTF1(_L("GetVerticalScanLine()"));
  3773 	TDisplayMode displayMode[] = 
  3774 		{
  3775 		EGray2,
  3776 		EGray4,
  3777 		EGray16,
  3778 		EGray256,
  3779 		EColor16,
  3780 		EColor256,
  3781 		EColor64K,
  3782 		EColor16M,
  3783 		ERgb,
  3784 		EColor4K,
  3785 		EColor16MU,
  3786 		EColor16MAP,
  3787 		};
  3788 	CFbsBitmap* uncompressedBitmap = NULL;
  3789 	LoadAndNotCompressBitmapLC(uncompressedBitmap, KRamBitmap2);
  3790 	TEST(!uncompressedBitmap->IsCompressedInRAM());
  3791 	TSize sizeInPixels = uncompressedBitmap->SizeInPixels();
  3792 	HBufC8* vertScanLine = HBufC8::NewLC(sizeInPixels.iHeight * 4);
  3793 	TPtr8 p = vertScanLine->Des();
  3794 	TDes8& des = p;
  3795 	for(TInt i=0;i<TInt(sizeof(displayMode)/sizeof(displayMode[0]));i++)
  3796 		{
  3797 		TBuf<80> buf;
  3798 		buf.Format(_L("--mode=%d\r\n"), displayMode[i]);
  3799 		INFO_PRINTF1(buf);
  3800 		for(TInt j=0;j<sizeInPixels.iWidth;j++)
  3801 			{
  3802 			uncompressedBitmap->GetVerticalScanLine(des, j, displayMode[i]);
  3803 			}
  3804 		}
  3805 	CleanupStack::PopAndDestroy(vertScanLine);
  3806 	CleanupStack::PopAndDestroy(uncompressedBitmap);
  3807 	}
  3808 
  3809 /**
  3810 	@SYMTestCaseID
  3811 	GRAPHICS-FBSERV-0544
  3812 	
  3813 	@SYMTestCaseDesc
  3814 	Tests the performance of the function 
  3815 	CFbsBitmap::GetVerticalScanLine
  3816 
  3817 	@SYMTestActions
  3818 	Gets the bitmap's vertical scanline starting at 
  3819 	a specified x co-ordinate and measures the time
  3820 	it takes.
  3821 	
  3822 	@SYMTestExpectedResults
  3823 	Test should pass
  3824 */
  3825 void CTBitmap::GetVerticalScanLinePerformanceL()
  3826 	{
  3827 	INFO_PRINTF1(_L("GetVerticalScanLine() performance"));
  3828 	TDisplayMode displayMode[] = 
  3829 		{
  3830 		EGray2,
  3831 		EGray4,
  3832 		EGray16,
  3833 		EGray256,
  3834 		EColor16,
  3835 		EColor256,
  3836 		EColor64K,
  3837 		EColor16M,
  3838 		ERgb,
  3839 		EColor4K,
  3840 		EColor16MU,
  3841 		EColor16MAP
  3842 		};
  3843 	CFbsBitmap* uncompressedBitmap = NULL;
  3844 	LoadAndNotCompressBitmapLC(uncompressedBitmap, KRamBitmap2);
  3845 	TEST(!uncompressedBitmap->IsCompressedInRAM());
  3846 	TSize sizeInPixels = uncompressedBitmap->SizeInPixels();
  3847 	HBufC8* vertScanLine = HBufC8::NewLC(sizeInPixels.iHeight * 4);
  3848 	TPtr8 p = vertScanLine->Des();
  3849 	TDes8& des = p;
  3850 	TUint time;
  3851 	for(TInt i=0;i<TInt(sizeof(displayMode)/sizeof(displayMode[0]));i++)
  3852 		{
  3853 		time = User::TickCount();
  3854 		for(TInt j=0;j<sizeInPixels.iWidth;j++)
  3855 			{
  3856 			uncompressedBitmap->GetVerticalScanLine(des, j, displayMode[i]);
  3857 			}
  3858 		INFO_PRINTF3(_L("Vert. line. Mode=%d, Time=%d\r\n"), displayMode[i], User::TickCount() - time);
  3859 		}
  3860 	CleanupStack::PopAndDestroy(vertScanLine);
  3861 	CleanupStack::PopAndDestroy(uncompressedBitmap);
  3862 	}
  3863 
  3864 /**
  3865 	@SYMTestCaseID
  3866 	GRAPHICS-FBSERV-0545
  3867 
  3868 	@SYMTestCaseDesc
  3869 	Test to verify defect DEF071843
  3870 	
  3871 	@SYMDEF DEF071843
  3872 	
  3873 	@SYMTestActions
  3874 	Creates a test bitmap. Initializes it 
  3875 	with test data using SetScanLine. Saves 
  3876 	bitmap and then reloads it and compares 
  3877 	it against expected bitmap.
  3878 	
  3879 	@SYMTestExpectedResults
  3880 	Test should pass
  3881 */
  3882 void CTBitmap::DEF071843_16MAL()
  3883 	{
  3884 	INFO_PRINTF1(_L("DEF071843 fix test. Saving and loading 16MA 32bpp bitmap."));
  3885 	// Create test bitmap
  3886 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  3887 	CleanupStack::PushL(bmp);
  3888 	const TInt width = 12;
  3889 	const TSize size(width, 8);
  3890 	User::LeaveIfError(bmp->Create(size, EColor16MA));
  3891 
  3892 	//Test bitmap data - 8 rows of 12 pixels each containing various run lengths
  3893 	TUint8 colorVal0[width * 4] =  // runs: 12
  3894 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  3895 		{0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0};
  3896 	TUint8 colorVal1[width * 4] =  // runs: 1 1 1 1 1 1 1 1 1 1 1 1
  3897 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  3898 		{0,0,0,0,  1,1,1,1,  2,2,2,2,  3,3,3,3,  4,4,4,4,  5,5,5,5,  6,6,6,6,  7,7,7,7,  8,8,8,8,  9,9,9,9,  10,10,10,10,  11,11,11,11};
  3899 	TUint8 colorVal2[width * 4] =  // runs: 1 1 2 1 1 3 1 1 1
  3900 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  3901 		{0,0,0,0,  1,1,1,1,  2,2,2,2,  2,2,2,2,  3,3,3,3,  4,4,4,4,  5,5,5,5,  5,5,5,5,  5,5,5,5,  6,6,6,6,  7,7,7,7,  8,8,8,8};
  3902 	TUint8 colorVal3[width * 4] =   // runs: 1 2 1 3 1 4
  3903 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  3904 		{0,0,0,0,  1,1,1,1,  1,1,1,1,  2,2,2,2,  3,3,3,3,  3,3,3,3,  3,3,3,3,  4,4,4,4,  5,5,5,5,  5,5,5,5,  5,5,5,5,  5,5,5,5};
  3905 	TUint8 colorVal4[width * 4] =   // runs: 2 1 2 2 2 3
  3906 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  3907 		{0,0,0,0,  0,0,0,0,  1,1,1,1,  2,2,2,2,  2,2,2,2,  3,3,3,3,  3,3,3,3,  4,4,4,4,  4,4,4,4,  5,5,5,5,  5,5,5,5,  5,5,5,5};
  3908 	TUint8 colorVal5[width * 4] =   // runs: 3 1 3 2 3
  3909 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  3910 		{0,0,0,0,  0,0,0,0,  0,0,0,0,  1,1,1,1,  2,2,2,2,  2,2,2,2,  2,2,2,2,  3,3,3,3,  3,3,3,3,  4,4,4,4,  4,4,4,4,  4,4,4,4};
  3911 	TUint8 colorVal6[width * 4] =   // runs: 4 1 1 1 1 4
  3912 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  3913 		{0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  1,1,1,1,  2,2,2,2,  3,3,3,3,  4,4,4,4,  5,5,5,5,  5,5,5,5,  5,5,5,5,  5,5,5,5};
  3914 	TUint8 colorVal7[width * 4] =   // runs: 1 1 1 1 4 1 1 1 1
  3915 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  3916 		{0,0,0,0,  1,1,1,1,  2,2,2,2,  3,3,3,3,  4,4,4,4,  4,4,4,4,  4,4,4,4,  4,4,4,4,  5,5,5,5,  6,6,6,6,  7,7,7,7,  8,8,8,8};
  3917 
  3918 	//Initialize test bitmap
  3919 	TPtr8 line0(colorVal0, width * 4, width * 4);
  3920 	bmp->SetScanLine(line0, 0);
  3921 	TPtr8 line1(colorVal1, width * 4, width * 4);
  3922 	bmp->SetScanLine(line1, 1);
  3923 	TPtr8 line2(colorVal2, width * 4, width * 4);
  3924 	bmp->SetScanLine(line2, 2);
  3925 	TPtr8 line3(colorVal3, width * 4, width * 4);
  3926 	bmp->SetScanLine(line3, 3);
  3927 	TPtr8 line4(colorVal4, width * 4, width * 4);
  3928 	bmp->SetScanLine(line4, 4);
  3929 	TPtr8 line5(colorVal5, width * 4, width * 4);
  3930 	bmp->SetScanLine(line5, 5);
  3931 	TPtr8 line6(colorVal6, width * 4, width * 4);
  3932 	bmp->SetScanLine(line6, 6);
  3933 	TPtr8 line7(colorVal7, width * 4, width * 4);
  3934 	bmp->SetScanLine(line7, 7);
  3935 
  3936 	// Save bitmap then reload and compare
  3937 	_LIT(KTest16MABmpFile, "c:\\test16ma.mbm");
  3938 	bmp->Save(KTest16MABmpFile);	
  3939 	//
  3940 	CFbsBitmap* bmp2 = new (ELeave) CFbsBitmap;
  3941 	CleanupStack::PushL(bmp2);
  3942 	TInt err = bmp2->Load(KTest16MABmpFile);
  3943 	TEST2(err, KErrNone);
  3944 	//
  3945 	CompareBitmaps((CFbsBitmapEx&)*bmp, (CFbsBitmapEx&)*bmp2,EColor16MA);
  3946 	
  3947 	// Destroy test bitmaps
  3948 	CleanupStack::PopAndDestroy(2, bmp); // bmp2
  3949 	}
  3950 
  3951 /**
  3952 	@SYMTestCaseID
  3953 	GRAPHICS-FBSERV-0546
  3954 
  3955 	@SYMTestCaseDesc
  3956 	Test to verify defect DEF071843
  3957 	
  3958 	@SYMDEF DEF071843
  3959 	
  3960 	@SYMTestActions
  3961 	Creates a test bitmap. Initializes it 
  3962 	with test data using SetScanLine. Saves 
  3963 	bitmap and then reloads it and compares 
  3964 	it against expected bitmap.
  3965 	
  3966 	@SYMTestExpectedResults
  3967 	Test should pass
  3968 */
  3969 void CTBitmap::DEF071843_16MUL()
  3970 	{
  3971 	INFO_PRINTF1(_L("DEF071843 fix test. Compression improvements for 16MU 32bpp bitmap."));
  3972 	// Create test bitmap
  3973 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  3974 	CleanupStack::PushL(bmp);
  3975 	const TInt width = 12;
  3976 	const TSize size(width, 8);
  3977 	User::LeaveIfError(bmp->Create(size, EColor16MU));
  3978 
  3979 	//Test bitmap data - 8 rows of 12 pixels each containing various run lengths
  3980 	//Format is b,g,r,a where a (alpha) is unused, hence 255.
  3981 	TUint8 colorVal0[width * 4] =  // runs: 12
  3982 	//	 0           1           2           3           4           5           6           7           8           9           10          11
  3983 		{0,0,0,255,  0,0,0,255,  0,0,0,255,  0,0,0,255,  0,0,0,255,  0,0,0,255,  0,0,0,255,  0,0,0,255,  0,0,0,255,  0,0,0,255,  0,0,0,255,  0,0,0,255};
  3984 	TUint8 colorVal1[width * 4] =  // runs: 1 1 1 1 1 1 1 1 1 1 1 1
  3985 	//	 0           1           2           3           4           5           6           7           8           9           10          11
  3986 		{0,0,0,255,  1,1,1,255,  2,2,2,255,  3,3,3,255,  4,4,4,255,  5,5,5,255,  6,6,6,255,  7,7,7,255,  8,8,8,255,  9,9,9,255,  10,10,10,255,  11,11,11,255};
  3987 	TUint8 colorVal2[width * 4] =  // runs: 1 1 2 1 1 3 1 1 1
  3988 	//	 0           1           2           3           4           5           6           7           8           9           10          11
  3989 		{0,0,0,255,  1,1,1,255,  2,2,2,255,  2,2,2,255,  3,3,3,255,  4,4,4,255,  5,5,5,255,  5,5,5,255,  5,5,5,255,  6,6,6,255,  7,7,7,255,  8,8,8,255};
  3990 	TUint8 colorVal3[width * 4] =   // runs: 1 2 1 3 1 4
  3991 	//	 0           1           2           3           4           5           6           7           8           9           10          11
  3992 		{0,0,0,255,  1,1,1,255,  1,1,1,255,  2,2,2,255,  3,3,3,255,  3,3,3,255,  3,3,3,255,  4,4,4,255,  5,5,5,255,  5,5,5,255,  5,5,5,255,  5,5,5,255};
  3993 	TUint8 colorVal4[width * 4] =   // runs: 2 1 2 2 2 3
  3994 	//	 0           1           2           3           4           5           6           7           8           9           10          11
  3995 		{0,0,0,255,  0,0,0,255,  1,1,1,255,  2,2,2,255,  2,2,2,255,  3,3,3,255,  3,3,3,255,  4,4,4,255,  4,4,4,255,  5,5,5,255,  5,5,5,255,  5,5,5,255};
  3996 	TUint8 colorVal5[width * 4] =   // runs: 3 1 3 2 3
  3997 	//	 0           1           2           3           4           5           6           7           8           9           10          11
  3998 		{0,0,0,255,  0,0,0,255,  0,0,0,255,  1,1,1,255,  2,2,2,255,  2,2,2,255,  2,2,2,255,  3,3,3,255,  3,3,3,255,  4,4,4,255,  4,4,4,255,  4,4,4,255};
  3999 	TUint8 colorVal6[width * 4] =   // runs: 4 1 1 1 1 4
  4000 	//	 0           1           2           3           4           5           6           7           8           9           10          11
  4001 		{0,0,0,255,  0,0,0,255,  0,0,0,255,  0,0,0,255,  1,1,1,255,  2,2,2,255,  3,3,3,255,  4,4,4,255,  5,5,5,255,  5,5,5,255,  5,5,5,255,  5,5,5,255};
  4002 	TUint8 colorVal7[width * 4] =   // runs: 1 1 1 1 4 1 1 1 1
  4003 	//	 0           1           2           3           4           5           6           7           8           9           10          11
  4004 		{0,0,0,255,  1,1,1,255,  2,2,2,255,  3,3,3,255,  4,4,4,255,  4,4,4,255,  4,4,4,255,  4,4,4,255,  5,5,5,255,  6,6,6,255,  7,7,7,255,  8,8,8,255};
  4005 
  4006 	//Initialize test bitmap
  4007 	TPtr8 line0(colorVal0, width * 4, width * 4);
  4008 	bmp->SetScanLine(line0, 0);
  4009 	TPtr8 line1(colorVal1, width * 4, width * 4);
  4010 	bmp->SetScanLine(line1, 1);
  4011 	TPtr8 line2(colorVal2, width * 4, width * 4);
  4012 	bmp->SetScanLine(line2, 2);
  4013 	TPtr8 line3(colorVal3, width * 4, width * 4);
  4014 	bmp->SetScanLine(line3, 3);
  4015 	TPtr8 line4(colorVal4, width * 4, width * 4);
  4016 	bmp->SetScanLine(line4, 4);
  4017 	TPtr8 line5(colorVal5, width * 4, width * 4);
  4018 	bmp->SetScanLine(line5, 5);
  4019 	TPtr8 line6(colorVal6, width * 4, width * 4);
  4020 	bmp->SetScanLine(line6, 6);
  4021 	TPtr8 line7(colorVal7, width * 4, width * 4);
  4022 	bmp->SetScanLine(line7, 7);
  4023 
  4024 	// Save bitmap then reload and compare
  4025 	_LIT(KTest16MUBmpFile, "c:\\test16mu.mbm");
  4026 	bmp->Save(KTest16MUBmpFile);	
  4027 	//
  4028 	CFbsBitmap* bmp2 = new (ELeave) CFbsBitmap;
  4029 	CleanupStack::PushL(bmp2);
  4030 	TInt err = bmp2->Load(KTest16MUBmpFile);
  4031 	TEST2(err, KErrNone);
  4032 	//
  4033 	CompareBitmaps((CFbsBitmapEx&)*bmp, (CFbsBitmapEx&)*bmp2, EColor16MU);
  4034 	
  4035 	// Destroy test bitmaps
  4036 	CleanupStack::PopAndDestroy(2, bmp); // bmp2
  4037 	}
  4038 
  4039 /**
  4040 	@SYMTestCaseID
  4041 	GRAPHICS-FBSERV-0547
  4042 
  4043 	@SYMTestCaseDesc
  4044 	Test to verify defect DEF071843
  4045 	
  4046 	@SYMDEF DEF071843
  4047 	
  4048 	@SYMTestActions
  4049 	Creates a test bitmap. Initializes it 
  4050 	with test data using SetScanLine. Saves 
  4051 	bitmap and then reloads it and compares 
  4052 	it against expected bitmap.
  4053 	
  4054 	@SYMTestExpectedResults
  4055 	Test should pass
  4056 */
  4057 void CTBitmap::DEF071843_16ML()
  4058 	{
  4059 	INFO_PRINTF1(_L("DEF071843 fix test. Compression improvements for 16M 24bpp bitmap."));
  4060 	// Create test bitmap
  4061 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  4062 	CleanupStack::PushL(bmp);
  4063 	const TInt width = 12;
  4064 	const TSize size(width, 8);
  4065 	User::LeaveIfError(bmp->Create(size, EColor16M));
  4066 
  4067 	//Test bitmap data - 8 rows of 12 pixels each containing various run lengths
  4068 	TUint8 colorVal0[width * 3] =  // runs: 12
  4069 	//	 0       1       2       3       4       5       6       7       8       9       10      11
  4070 		{0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0};
  4071 	TUint8 colorVal1[width * 3] =  // runs: 1 1 1 1 1 1 1 1 1 1 1 1
  4072 	//	 0       1       2       3       4       5       6       7       8       9       10      11
  4073 		{0,0,0,  1,1,1,  2,2,2,  3,3,3,  4,4,4,  5,5,5,  6,6,6,  7,7,7,  8,8,8,  9,9,9,  10,10,10,  11,11,11};
  4074 	TUint8 colorVal2[width * 3] =  // runs: 1 1 2 1 1 3 1 1 1
  4075 	//	 0       1       2       3       4       5       6       7       8       9       10      11
  4076 		{0,0,0,  1,1,1,  2,2,2,  2,2,2,  3,3,3,  4,4,4,  5,5,5,  5,5,5,  5,5,5,  6,6,6,  7,7,7,  8,8,8};
  4077 	TUint8 colorVal3[width * 3] =   // runs: 1 2 1 3 1 4
  4078 	//	 0       1       2       3       4       5       6       7       8       9       10      11
  4079 		{0,0,0,  1,1,1,  1,1,1,  2,2,2,  3,3,3,  3,3,3,  3,3,3,  4,4,4,  5,5,5,  5,5,5,  5,5,5,  5,5,5};
  4080 	TUint8 colorVal4[width * 3] =   // runs: 2 1 2 2 2 3
  4081 	//	 0       1       2       3       4       5       6       7       8       9       10      11
  4082 		{0,0,0,  0,0,0,  1,1,1,  2,2,2,  2,2,2,  3,3,3,  3,3,3,  4,4,4,  4,4,4,  5,5,5,  5,5,5,  5,5,5};
  4083 	TUint8 colorVal5[width * 3] =   // runs: 3 1 3 2 3
  4084 	//	 0       1       2       3       4       5       6       7       8       9       10      11
  4085 		{0,0,0,  0,0,0,  0,0,0,  1,1,1,  2,2,2,  2,2,2,  2,2,2,  3,3,3,  3,3,3,  4,4,4,  4,4,4,  4,4,4};
  4086 	TUint8 colorVal6[width * 3] =   // runs: 4 1 1 1 1 4
  4087 	//	 0       1       2       3       4       5       6       7       8       9       10      11
  4088 		{0,0,0,  0,0,0,  0,0,0,  0,0,0,  1,1,1,  2,2,2,  3,3,3,  4,4,4,  5,5,5,  5,5,5,  5,5,5,  5,5,5};
  4089 	TUint8 colorVal7[width * 3] =   // runs: 1 1 1 1 4 1 1 1 1
  4090 	//	 0       1       2       3       4       5       6       7       8       9       10      11
  4091 		{0,0,0,  1,1,1,  2,2,2,  3,3,3,  4,4,4,  4,4,4,  4,4,4,  4,4,4,  5,5,5,  6,6,6,  7,7,7,  8,8,8};
  4092 
  4093 	//Initialize test bitmap
  4094 	TPtr8 line0(colorVal0, width * 3, width * 3);
  4095 	bmp->SetScanLine(line0, 0);
  4096 	TPtr8 line1(colorVal1, width * 3, width * 3);
  4097 	bmp->SetScanLine(line1, 1);
  4098 	TPtr8 line2(colorVal2, width * 3, width * 3);
  4099 	bmp->SetScanLine(line2, 2);
  4100 	TPtr8 line3(colorVal3, width * 3, width * 3);
  4101 	bmp->SetScanLine(line3, 3);
  4102 	TPtr8 line4(colorVal4, width * 3, width * 3);
  4103 	bmp->SetScanLine(line4, 4);
  4104 	TPtr8 line5(colorVal5, width * 3, width * 3);
  4105 	bmp->SetScanLine(line5, 5);
  4106 	TPtr8 line6(colorVal6, width * 3, width * 3);
  4107 	bmp->SetScanLine(line6, 6);
  4108 	TPtr8 line7(colorVal7, width * 3, width * 3);
  4109 	bmp->SetScanLine(line7, 7);
  4110 
  4111 	// Save bitmap then reload and compare
  4112 	_LIT(KTest16MBmpFile, "c:\\test16m.mbm");
  4113 	bmp->Save(KTest16MBmpFile);	
  4114 	//
  4115 	CFbsBitmap* bmp2 = new (ELeave) CFbsBitmap;
  4116 	CleanupStack::PushL(bmp2);
  4117 	TInt err = bmp2->Load(KTest16MBmpFile);
  4118 	TEST2(err, KErrNone);
  4119 	//
  4120 	CompareBitmaps((CFbsBitmapEx&)*bmp, (CFbsBitmapEx&)*bmp2, EColor16M);
  4121 	
  4122 	// Destroy test bitmaps
  4123 	CleanupStack::PopAndDestroy(2, bmp); // bmp2
  4124 	}
  4125 	
  4126 /**
  4127 	@SYMTestCaseID
  4128 	GRAPHICS-FBSERV-0548
  4129 
  4130 	@SYMTestCaseDesc
  4131 	Test to verify defect DEF074623 (Alpha bit)
  4132 
  4133 	@SYMDEF DEF074623
  4134 
  4135 	@SYMTestActions
  4136 	
  4137 	@SYMTestExpectedResults
  4138 	Test should pass
  4139 */
  4140 void CTBitmap::DEF074623_16MAL()
  4141 	{
  4142 	INFO_PRINTF1(_L("DEF074623 fix test For Alpha Bit."));
  4143 	// Create test bitmap
  4144 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  4145 	CleanupStack::PushL(bmp);
  4146 	const TInt iBitmapWidth = 10;
  4147 	const TInt iBitmapHeight = 10;
  4148 
  4149 	
  4150 	TInt rowIndex;
  4151 	TInt colIndex;
  4152 	TSize rectSize(iBitmapWidth,iBitmapHeight);
  4153 	TRect srcRect(0,0,iBitmapWidth,iBitmapHeight);
  4154 	User::LeaveIfError(bmp->Create(rectSize, EColor16MU));
  4155 	srcRect.SetSize(rectSize);
  4156 	TBitmapUtil bmpUtil(bmp);
  4157 	bmpUtil.Begin(TPoint(0,0));
  4158 	for (rowIndex=0;rowIndex<iBitmapHeight;++rowIndex)
  4159 		{
  4160 		TInt red=0;
  4161 		TInt blue=255;
  4162 		TInt green=0;
  4163 		bmpUtil.SetPos(TPoint(0,rowIndex));
  4164 		for (colIndex=0;colIndex<iBitmapWidth;++colIndex)
  4165 			{
  4166 			TRgb rgb(red,green,blue);
  4167 			bmpUtil.SetPixel(rgb.Color16MA());
  4168 			}
  4169 		bmpUtil.IncXPos();
  4170 		red-=10;
  4171 		blue+=10;
  4172 		green-=10;
  4173 		if(red <= 0)
  4174 			{
  4175 			red+=255;
  4176 			}
  4177 		if(blue >= 255)
  4178 			{
  4179 			blue-=255;
  4180 			}
  4181 		if(green <= 0)
  4182 			{
  4183 			green+=255;
  4184 			}
  4185 		}
  4186 	bmpUtil.End();
  4187 	
  4188 	bmp->SetDisplayMode(EColor16MA);
  4189 	
  4190 	for(TInt yy = 0; yy < iBitmapHeight; yy++)
  4191 		{
  4192 		
  4193 		for(TInt xx = 0; xx < iBitmapWidth; xx++)
  4194 			{
  4195 			TRgb bmpcol;
  4196 			bmp->GetPixel(bmpcol,TPoint(xx,yy));
  4197 			TEST(bmpcol.Alpha() == 255);
  4198 			}
  4199 		}
  4200 		
  4201 	CleanupStack::PopAndDestroy(bmp);	
  4202 
  4203 	}
  4204 	
  4205 #ifdef _DEBUG
  4206 /**
  4207 	@SYMTestCaseID
  4208 	GRAPHICS-FBSERV-0549
  4209 
  4210 	@SYMTestCaseDesc
  4211 	Test to verify defect DEF095361
  4212 	
  4213 	@SYMDEF DEF095361
  4214 	
  4215 	@SYMTestActions
  4216 	Creates a test bitmap. Initializes it 
  4217 	with test data using SetScanLine. Compresses
  4218 	the bitmap. Saves bitmap and then reloads it 
  4219 	and compares it against expected bitmap.
  4220 	Simulates heap allocation failure of memory.
  4221 	
  4222 	@SYMTestExpectedResults
  4223 	Test should pass
  4224 */
  4225 void CTBitmap::DEF095361_16MAL()
  4226 	{
  4227 	INFO_PRINTF1(_L("DEF095361 fix test. Compressing, Saving and loading 16MA 32bpp bitmap."));
  4228 	// Create test bitmap
  4229 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  4230 	CleanupStack::PushL(bmp);
  4231 	const TInt width = 12;
  4232 	const TSize size(width, 8);
  4233 	User::LeaveIfError(bmp->Create(size, EColor16MA));
  4234 
  4235 	//Test bitmap data - 8 rows of 12 pixels each containing various run lengths
  4236 	TUint8 colorVal0[width * 4] =  // runs: 12
  4237 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  4238 		{0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0};
  4239 	TUint8 colorVal1[width * 4] =  // runs: 1 1 1 1 1 1 1 1 1 1 1 1
  4240 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  4241 		{0,0,0,0,  1,1,1,1,  2,2,2,2,  3,3,3,3,  4,4,4,4,  5,5,5,5,  6,6,6,6,  7,7,7,7,  8,8,8,8,  9,9,9,9,  10,10,10,10,  11,11,11,11};
  4242 	TUint8 colorVal2[width * 4] =  // runs: 1 1 2 1 1 3 1 1 1
  4243 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  4244 		{0,0,0,0,  1,1,1,1,  2,2,2,2,  2,2,2,2,  3,3,3,3,  4,4,4,4,  5,5,5,5,  5,5,5,5,  5,5,5,5,  6,6,6,6,  7,7,7,7,  8,8,8,8};
  4245 	TUint8 colorVal3[width * 4] =   // runs: 1 2 1 3 1 4
  4246 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  4247 		{0,0,0,0,  1,1,1,1,  1,1,1,1,  2,2,2,2,  3,3,3,3,  3,3,3,3,  3,3,3,3,  4,4,4,4,  5,5,5,5,  5,5,5,5,  5,5,5,5,  5,5,5,5};
  4248 	TUint8 colorVal4[width * 4] =   // runs: 2 1 2 2 2 3
  4249 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  4250 		{0,0,0,0,  0,0,0,0,  1,1,1,1,  2,2,2,2,  2,2,2,2,  3,3,3,3,  3,3,3,3,  4,4,4,4,  4,4,4,4,  5,5,5,5,  5,5,5,5,  5,5,5,5};
  4251 	TUint8 colorVal5[width * 4] =   // runs: 3 1 3 2 3
  4252 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  4253 		{0,0,0,0,  0,0,0,0,  0,0,0,0,  1,1,1,1,  2,2,2,2,  2,2,2,2,  2,2,2,2,  3,3,3,3,  3,3,3,3,  4,4,4,4,  4,4,4,4,  4,4,4,4};
  4254 	TUint8 colorVal6[width * 4] =   // runs: 4 1 1 1 1 4
  4255 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  4256 		{0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  1,1,1,1,  2,2,2,2,  3,3,3,3,  4,4,4,4,  5,5,5,5,  5,5,5,5,  5,5,5,5,  5,5,5,5};
  4257 	TUint8 colorVal7[width * 4] =   // runs: 1 1 1 1 4 1 1 1 1
  4258 	//	 0         1         2         3         4         5         6         7         8         9         10        11
  4259 		{0,0,0,0,  1,1,1,1,  2,2,2,2,  3,3,3,3,  4,4,4,4,  4,4,4,4,  4,4,4,4,  4,4,4,4,  5,5,5,5,  6,6,6,6,  7,7,7,7,  8,8,8,8};
  4260 
  4261 	//Initialize test bitmap
  4262 	TPtr8 line0(colorVal0, width * 4, width * 4);
  4263 	bmp->SetScanLine(line0, 0);
  4264 	TPtr8 line1(colorVal1, width * 4, width * 4);
  4265 	bmp->SetScanLine(line1, 1);
  4266 	TPtr8 line2(colorVal2, width * 4, width * 4);
  4267 	bmp->SetScanLine(line2, 2);
  4268 	TPtr8 line3(colorVal3, width * 4, width * 4);
  4269 	bmp->SetScanLine(line3, 3);
  4270 	TPtr8 line4(colorVal4, width * 4, width * 4);
  4271 	bmp->SetScanLine(line4, 4);
  4272 	TPtr8 line5(colorVal5, width * 4, width * 4);
  4273 	bmp->SetScanLine(line5, 5);
  4274 	TPtr8 line6(colorVal6, width * 4, width * 4);
  4275 	bmp->SetScanLine(line6, 6);
  4276 	TPtr8 line7(colorVal7, width * 4, width * 4);
  4277 	bmp->SetScanLine(line7, 7);
  4278 
  4279 	//Compress bitmap using RLE Compression
  4280 	bmp->Compress(ERLECompression);
  4281  
  4282 	// Save bitmap then reload and compare
  4283 	_LIT(KTest16MABmpFile, "c:\\testDEF095361_16ma.mbm");
  4284 	bmp->Save(KTest16MABmpFile);	
  4285 	//
  4286 	CFbsBitmap* bmp2 = new (ELeave) CFbsBitmap;
  4287 	CleanupStack::PushL(bmp2);
  4288 	
  4289 	RFbsSession* fbs = RFbsSession::GetSession();
  4290 	
  4291 	TInt count;
  4292 	for (count = 1; ; count++)
  4293 		{
  4294 		fbs->SendCommand(EFbsMessDefaultAllocFail,count);
  4295 
  4296 		TInt ret = bmp2->Load(KTest16MABmpFile, 0, EFalse);
  4297 
  4298 		if (ret == KErrNoMemory)
  4299 			{
  4300 				// Do Nothing
  4301 			}
  4302 		else if (ret == KErrNone)
  4303 			{
  4304 			break;
  4305 			}
  4306 		else 
  4307 			TEST2(ret, KErrNone);
  4308 		}
  4309 
  4310 	fbs->SendCommand(EFbsMessDefaultAllocFail,0);
  4311 	
  4312 	//
  4313 	CompareBitmaps((CFbsBitmapEx&)*bmp, (CFbsBitmapEx&)*bmp2,EColor16MA);
  4314 	
  4315 	// Destroy test bitmaps
  4316 	CleanupStack::PopAndDestroy(2, bmp); // bmp2
  4317 	}
  4318 #endif
  4319 void CTBitmap::LoadAndCompressBitmapLC(CFbsBitmap*& aBmp, const TDesC& aBmpFile)
  4320 	{
  4321 	aBmp = new (ELeave) CFbsBitmap;
  4322 	CleanupStack::PushL(aBmp);
  4323 	TInt err = aBmp->Load(aBmpFile);
  4324 	TEST2(err, KErrNone);
  4325 	err = aBmp->Compress();
  4326 	TEST2(err, KErrNone);
  4327 	TEST(aBmp->IsCompressedInRAM());
  4328 	}
  4329 
  4330 /**
  4331 	@SYMTestCaseID
  4332 	GRAPHICS-FBSERV-0550
  4333 
  4334 	@SYMTestCaseDesc
  4335 	Compresses a bitmap containing two lines
  4336 
  4337 	@SYMTestActions
  4338 	Creates a test bitmap with two lines. Compresses it (16 bpp)
  4339 	and checks if compressed successfully
  4340 	
  4341 	@SYMTestExpectedResults
  4342 	Test should pass
  4343 */
  4344 
  4345 void CTBitmap::TwoComprLines()
  4346 	{
  4347 	INFO_PRINTF1(_L("16 bpp compressed bitmap - 2 lines"));
  4348 	//Create test bitmap
  4349 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  4350 	CleanupStack::PushL(bmp);
  4351 	const TInt width = 3;
  4352 	const TSize size(width, 2);
  4353 	User::LeaveIfError(bmp->Create(size, EColor64K));
  4354 	//Test bitmap data
  4355 	TUint8 colorVal[width * 2] = 
  4356 	//	 0          1          2        
  4357 		{0x13,0x13, 0x13,0x13, 0x13,0x13};
  4358 	//Initialize test bitmap
  4359 	TPtr8 ptr(colorVal, width * 2, width * 2);
  4360 	bmp->SetScanLine(ptr, 0);
  4361 	bmp->SetScanLine(ptr, 1);
  4362 	//Compress test bitmap
  4363 	User::LeaveIfError(bmp->Compress());
  4364 	//Check the test data
  4365 	TUint8 colorVal2[width * 2];
  4366 	TPtr8 ptr2(colorVal2, width * 2, width * 2);
  4367 	//test 1
  4368 	bmp->GetScanLine(ptr2, TPoint(0, 0), 3, EColor64K);
  4369 	TEST(ptr2 == ptr);
  4370 	bmp->GetScanLine(ptr2, TPoint(0, 1), 3, EColor64K);
  4371 	TEST(ptr2 == ptr);
  4372 	//Destroy test bitmap and data
  4373 	CleanupStack::PopAndDestroy(bmp);
  4374 	}
  4375 
  4376 void CTBitmap::LoadAndNotCompressBitmapLC(CFbsBitmap*& aBmp, const TDesC& aBmpFile)
  4377 	{
  4378 	aBmp = new (ELeave) CFbsBitmap;
  4379 	CleanupStack::PushL(aBmp);
  4380 	TInt err = aBmp->Load(aBmpFile);
  4381 	TEST2(err, KErrNone);
  4382 	}
  4383 
  4384 /**
  4385 	@SYMTestCaseID
  4386 	GRAPHICS-FBSERV-0551
  4387 
  4388 	@SYMTestCaseDesc
  4389 	The test verifies the 
  4390 	CFbsBitmap::Compress((TBitmapfileCompressionScheme aScheme) API.
  4391 	It loads bitmaps from ROM & saves (temporarily) to C-drive. 
  4392 	Then it loads from C-drive into a new bitmap.
  4393 
  4394 	@SYMTestActions
  4395 	
  4396 	@SYMTestExpectedResults
  4397 	Test should pass
  4398 */
  4399 void CTBitmap::TestPaletteCompressionL()
  4400 	{
  4401 	INFO_PRINTF1(_L("Test Palette Compression"));
  4402 	_LIT(KmbmFileInRom, "z:\\system\\data\\24bitskin.mbm");
  4403 	RFbsSession* fbs = RFbsSession::GetSession();
  4404 	//create bitmap
  4405 	CFbsBitmap* fbsCompressed = new(ELeave) CFbsBitmap;
  4406 	CFbsBitmap* fbsUnCompressed = new(ELeave) CFbsBitmap;
  4407 	CleanupStack::PushL(fbsCompressed);
  4408 	CleanupStack::PushL(fbsUnCompressed);
  4409 	TEST2(fbsUnCompressed->Load(KmbmFileInRom, 0, EFalse), KErrNone);
  4410 	fbsUnCompressed->Save(KTempFilename);
  4411 	//load bitmap
  4412 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4413 	//compress bitmap (force foreground compression)
  4414 	fbsCompressed->Compress(EPaletteCompression);
  4415 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4416 	//test that palette compression occurred
  4417 	TEST(fbsCompressed->Header().iCompression == EGenericPaletteCompression);
  4418 	//compare with original
  4419 	INFO_PRINTF1(_L("Compare Palette Compressed bmp with original"));
  4420 	CompareBitmaps((CFbsBitmapEx&)*fbsCompressed, (CFbsBitmapEx&)*fbsUnCompressed, EColor16M);
  4421 	CleanupStack::PopAndDestroy(2);
  4422 	iFs.Delete(KTempFilename);
  4423 
  4424 	//Test that the RLE option works.
  4425 	//------------------------------------
  4426 	//create bitmap
  4427 	fbsCompressed = new(ELeave) CFbsBitmap ;
  4428 	fbsUnCompressed = new(ELeave) CFbsBitmap ;
  4429 	CleanupStack::PushL(fbsCompressed);
  4430 	CleanupStack::PushL(fbsUnCompressed);
  4431 	TEST2(fbsUnCompressed->Load(KmbmFileInRom, 0, EFalse), KErrNone);
  4432 	fbsUnCompressed->Save(KTempFilename);
  4433 	//load bitmap
  4434 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4435 	//compress bitmap (force foreground compression)
  4436 	fbsCompressed->Compress(ERLECompression);
  4437 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4438 	//test that RLE compression occurred
  4439 	TEST(fbsCompressed->Header().iCompression == ETwentyFourBitRLECompression);
  4440 	CleanupStack::PopAndDestroy(2);
  4441 	iFs.Delete(KTempFilename);
  4442 
  4443 	//Test that unsuitable bitmaps are not palette compressed (too many colours).
  4444 	//----------------------------------------------------------------------------------------
  4445 	_LIT(KmbmMultiColourMBMInRom, "z:\\system\\data\\24bit.mbm");
  4446 	//create bitmap
  4447 	fbsCompressed = new(ELeave) CFbsBitmap;
  4448 	fbsUnCompressed = new(ELeave) CFbsBitmap;
  4449 	CleanupStack::PushL(fbsCompressed);
  4450 	CleanupStack::PushL(fbsUnCompressed);
  4451 	TEST2(fbsUnCompressed->Load(KmbmMultiColourMBMInRom, 0, EFalse), KErrNone);
  4452 	fbsUnCompressed->Save(KTempFilename);
  4453 	//load bitmap
  4454 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4455 	//compress bitmap (force foreground compression)
  4456 	fbsCompressed->Compress(EPaletteCompression);
  4457 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4458 	//test that palette compression occurred
  4459 	TEST(fbsCompressed->Header().iCompression != EGenericPaletteCompression);
  4460 	CleanupStack::PopAndDestroy(2);
  4461 	iFs.Delete(KTempFilename);
  4462 	
  4463 	//Test that unsuitable bitmaps are not palette compressed (too few BPP)
  4464 	//---------------------------------------------------------------------------------
  4465 	//create bitmap
  4466 	fbsCompressed = new(ELeave) CFbsBitmap ;
  4467 	fbsUnCompressed = new(ELeave) CFbsBitmap ;
  4468 	CleanupStack::PushL(fbsCompressed);
  4469 	CleanupStack::PushL(fbsUnCompressed);
  4470 	TEST2(fbsUnCompressed->Load(KmbmMultiColourMBMInRom, 0, EFalse), KErrNone);
  4471 	fbsUnCompressed->Save(KTempFilename);
  4472 	//load bitmap
  4473 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4474 	//compress bitmap (force foreground compression)
  4475 	fbsCompressed->Compress(EPaletteCompression);
  4476 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4477 	//test that palette compression occurred
  4478 	TEST(fbsCompressed->Header().iCompression != EGenericPaletteCompression);
  4479 	CleanupStack::PopAndDestroy(2);
  4480 	iFs.Delete(KTempFilename);
  4481 
  4482 	
  4483 	// Test that 12bitmap cannot pallete compress but will fall back to RLE
  4484 	// --------------------------------------------------------------------
  4485 	_LIT(Kmbm12BitMBMInRom, "z:\\system\\data\\file.mbm");
  4486 	fbsCompressed = new(ELeave) CFbsBitmap ;
  4487 	fbsUnCompressed = new(ELeave) CFbsBitmap ;
  4488 	CleanupStack::PushL(fbsCompressed);
  4489 	CleanupStack::PushL(fbsUnCompressed);
  4490 	TEST2(fbsUnCompressed->Load(Kmbm12BitMBMInRom, 0, EFalse), KErrNone);
  4491 	fbsUnCompressed->Save(KTempFilename);
  4492 	//load bitmap
  4493 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4494 	//compress bitmap (force foreground compression)
  4495 	fbsCompressed->Compress(EPaletteCompressionWithRLEFallback);
  4496 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4497 	TBitmapfileCompression comp = fbsCompressed->Header().iCompression;
  4498 	//test that palette compression occurred
  4499 	TEST(fbsCompressed->Header().iCompression != EGenericPaletteCompression);
  4500 	CleanupStack::PopAndDestroy(2);
  4501 	iFs.Delete(KTempFilename);
  4502 	
  4503 
  4504 	// Test that multi colour bitmap cannot pallete compress but will fall back to RLE
  4505 	// -------------------------------------------------------------------------------
  4506 	fbsCompressed = new(ELeave) CFbsBitmap ;
  4507 	fbsUnCompressed = new(ELeave) CFbsBitmap ;
  4508 	CleanupStack::PushL(fbsCompressed);
  4509 	CleanupStack::PushL(fbsUnCompressed);
  4510 	TEST2(fbsUnCompressed->Load(KmbmMultiColourMBMInRom, 0, EFalse), KErrNone);
  4511 	fbsUnCompressed->Save(KTempFilename);
  4512 	//load bitmap
  4513 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4514 	//compress bitmap (force foreground compression)
  4515 	fbsCompressed->Compress(EPaletteCompressionWithRLEFallback);
  4516 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4517 	comp = fbsCompressed->Header().iCompression;
  4518 	//test that palette compression occurred
  4519 	TEST(fbsCompressed->Header().iCompression != EGenericPaletteCompression);
  4520 	CleanupStack::PopAndDestroy(2);
  4521 	iFs.Delete(KTempFilename);
  4522 	
  4523 	
  4524 	
  4525 	//Test various BPP & bitmap widths
  4526 	//----------------------------------------
  4527 	INFO_PRINTF1(_L("Test assorted BPP & colour counts"));
  4528 	_LIT(Kmbm16NarrowFileInRom, "z:\\system\\data\\16bitskin.mbm");
  4529 	TestAssortedBPPandColourDepthL(Kmbm16NarrowFileInRom, fbs);
  4530 	_LIT(Kmbm24bit6colFileInRom, "z:\\system\\data\\24bit6col.mbm");
  4531 	TestAssortedBPPandColourDepthL(Kmbm24bit6colFileInRom, fbs);
  4532 	_LIT(Kmbm24bit2colFileInRom, "z:\\system\\data\\24bit2col.mbm");
  4533 	TestAssortedBPPandColourDepthL(Kmbm24bit2colFileInRom, fbs);
  4534 	_LIT(Kmbm24bit3colFileInRom, "z:\\system\\data\\24bit3col.mbm");
  4535 	TestAssortedBPPandColourDepthL(Kmbm24bit3colFileInRom, fbs);
  4536 	_LIT(Kmbm24bit20colFileInRom, "z:\\system\\data\\24bit20col.mbm");
  4537 	TestAssortedBPPandColourDepthL(Kmbm24bit20colFileInRom, fbs);
  4538 	_LIT(Kmbm16bit6colFileInRom, "z:\\system\\data\\16bit6col.mbm");
  4539 	TestAssortedBPPandColourDepthL(Kmbm16bit6colFileInRom, fbs);
  4540 	_LIT(Kmbm16bit2colFileInRom, "z:\\system\\data\\16bit2col.mbm");
  4541 	TestAssortedBPPandColourDepthL(Kmbm16bit2colFileInRom, fbs);
  4542 	_LIT(Kmbm16bit3colFileInRom, "z:\\system\\data\\16bit3col.mbm");
  4543 	TestAssortedBPPandColourDepthL(Kmbm16bit3colFileInRom, fbs);
  4544 	_LIT(Kmbm16bit20colFileInRom, "z:\\system\\data\\16bit20col.mbm");
  4545 	TestAssortedBPPandColourDepthL(Kmbm16bit20colFileInRom, fbs);
  4546 	_LIT(Kmbm32BitSkinFileInRom, "z:\\system\\data\\32bitskin.mbm");
  4547 	TestAssortedBPPandColourDepthL(Kmbm32BitSkinFileInRom, fbs);
  4548 	_LIT(Kmbm32bit6colFileInRom, "z:\\system\\data\\32bit6col.mbm");
  4549 	TestAssortedBPPandColourDepthL(Kmbm32bit6colFileInRom, fbs);
  4550 	_LIT(Kmbm32bit2colFileInRom, "z:\\system\\data\\32bit2col.mbm");
  4551 	TestAssortedBPPandColourDepthL(Kmbm32bit2colFileInRom, fbs);
  4552 	_LIT(Kmbm32bit3colFileInRom, "z:\\system\\data\\32bit3col.mbm");
  4553 	TestAssortedBPPandColourDepthL(Kmbm32bit3colFileInRom, fbs);
  4554 	_LIT(Kmbm32bit20colFileInRom, "z:\\system\\data\\32bit20col.mbm");
  4555 	TestAssortedBPPandColourDepthL(Kmbm32bit20colFileInRom, fbs);
  4556 	INFO_PRINTF1(_L("Test Palette Compression - COMPLETE"));
  4557 	}
  4558 
  4559 void CTBitmap::TestAssortedBPPandColourDepthL(const TDesC& aFilename, RFbsSession* aFbs)
  4560 	{
  4561 	//create bitmap
  4562 	CFbsBitmap* fbsCompressed = new (ELeave) CFbsBitmap ;
  4563 	CFbsBitmap* fbsUnCompressed = new (ELeave) CFbsBitmap ;
  4564 	CleanupStack::PushL(fbsCompressed);
  4565 	CleanupStack::PushL(fbsUnCompressed);
  4566 	TEST2(fbsUnCompressed->Load(aFilename, 0, EFalse), KErrNone);
  4567 	fbsUnCompressed->Save(KTempFilename);
  4568 	//load bitmap
  4569 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4570 	//compress bitmap (force foreground compression)
  4571 	fbsCompressed->Compress(EPaletteCompression);
  4572 	aFbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4573 	//test that palette compression occurred
  4574 	TEST(fbsCompressed->Header().iCompression == EGenericPaletteCompression);
  4575 	//compare with original
  4576 	INFO_PRINTF1(_L("Compare Palette Compressed bmp with original"));
  4577 	CompareBitmaps((CFbsBitmapEx&)*fbsCompressed, (CFbsBitmapEx&)*fbsUnCompressed, EColor16M);
  4578 	CleanupStack::PopAndDestroy(2);
  4579 	iFs.Delete(KTempFilename);
  4580 	}
  4581 	
  4582 /**
  4583 	@SYMTestCaseID
  4584 	GRAPHICS-FBSERV-0552
  4585 
  4586 	@SYMTestCaseDesc
  4587 	The test verifies the 
  4588 	CFbsBitmap::CompressInBackground((TBitmapfileCompressionScheme aScheme)
  4589 	API. It loads bitmaps from ROM & saves (temporarily) to C-drive. 
  4590 	Then it loads from C-drive into a new bitmap.
  4591 
  4592 	@SYMTestActions
  4593 	
  4594 	@SYMTestExpectedResults
  4595 	Test should pass
  4596 */
  4597 void CTBitmap::TestSynchronousBackgroundPaletteCompressionL()
  4598 	{
  4599 	INFO_PRINTF1(_L("Test Background Palette Compression"));
  4600 	_LIT(KmbmFileInRom, "z:\\system\\data\\24bitskin.mbm");
  4601 	RFbsSession* fbs = RFbsSession::GetSession();
  4602 	//create bitmap
  4603 	CFbsBitmap* fbsCompressed = new(ELeave) CFbsBitmap ;
  4604 	CFbsBitmap* fbsUnCompressed = new(ELeave) CFbsBitmap ;
  4605 	CleanupStack::PushL(fbsCompressed);
  4606 	CleanupStack::PushL(fbsUnCompressed);
  4607 	TEST2(fbsUnCompressed->Load(KmbmFileInRom, 0, EFalse), KErrNone);
  4608 	fbsUnCompressed->Save(KTempFilename);
  4609 	//load bitmap
  4610 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4611 	//compress bitmap (force immediate compression)
  4612 	fbsCompressed->CompressInBackground(EPaletteCompression);
  4613 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4614 	//test that palette compression occurred
  4615 	TEST(fbsCompressed->Header().iCompression == EGenericPaletteCompression);
  4616 	//compare with original
  4617 	INFO_PRINTF1(_L("Compare Palette Compressed bmp with original"));
  4618 	CompareBitmaps((CFbsBitmapEx&)*fbsCompressed, (CFbsBitmapEx&)*fbsUnCompressed, EColor16M);
  4619 	CleanupStack::PopAndDestroy(2);
  4620 	iFs.Delete(KTempFilename);
  4621 	
  4622 	//Test that the RLE option works.
  4623 	//------------------------------------
  4624 	//create bitmap
  4625 	fbsCompressed = new(ELeave) CFbsBitmap ;
  4626 	fbsUnCompressed = new(ELeave) CFbsBitmap ;
  4627 	CleanupStack::PushL(fbsCompressed);
  4628 	CleanupStack::PushL(fbsUnCompressed);
  4629 	TEST2(fbsUnCompressed->Load(KmbmFileInRom, 0, EFalse), KErrNone);
  4630 	fbsUnCompressed->Save(KTempFilename);
  4631 	//load bitmap
  4632 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4633 	//compress bitmap (force immediate compression)
  4634 	fbsCompressed->CompressInBackground(ERLECompression);
  4635 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4636 	//test that RLE compression occurred
  4637 	TEST(fbsCompressed->Header().iCompression == ETwentyFourBitRLECompression);
  4638 	CleanupStack::PopAndDestroy(2);
  4639 	iFs.Delete(KTempFilename);
  4640 
  4641 	//Test that unsuitable bitmaps are not palette compressed (too many colours).
  4642 	//----------------------------------------------------------------------------------------
  4643 	_LIT(KmbmMultiColourMBMInRom, "z:\\system\\data\\24bit.mbm");
  4644 	//create bitmap
  4645 	fbsCompressed = new(ELeave) CFbsBitmap ;
  4646 	fbsUnCompressed = new(ELeave) CFbsBitmap ;
  4647 	CleanupStack::PushL(fbsCompressed);
  4648 	CleanupStack::PushL(fbsUnCompressed);
  4649 	TEST2(fbsUnCompressed->Load(KmbmMultiColourMBMInRom, 0, EFalse), KErrNone);
  4650 	fbsUnCompressed->Save(KTempFilename);
  4651 	//load bitmap
  4652 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4653 	//compress bitmap (force immediate compression)
  4654 	fbsCompressed->CompressInBackground(EPaletteCompression);
  4655 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4656 	//test that palette compression occurred
  4657 	TEST(fbsCompressed->Header().iCompression != EGenericPaletteCompression);
  4658 	CleanupStack::PopAndDestroy(2);
  4659 	iFs.Delete(KTempFilename);
  4660 	
  4661 	//Test that unsuitable bitmaps are not palette compressed (too few BPP)
  4662 	//---------------------------------------------------------------------------------
  4663 	//create bitmap
  4664 	fbsCompressed = new(ELeave) CFbsBitmap ;
  4665 	fbsUnCompressed = new(ELeave) CFbsBitmap ;
  4666 	CleanupStack::PushL(fbsCompressed);
  4667 	CleanupStack::PushL(fbsUnCompressed);
  4668 	TEST2(fbsUnCompressed->Load(KmbmMultiColourMBMInRom, 0, EFalse), KErrNone);
  4669 	fbsUnCompressed->Save(KTempFilename);
  4670 	//load bitmap
  4671 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4672 	//compress bitmap (force immediate compression)
  4673 	fbsCompressed->CompressInBackground(EPaletteCompression);
  4674 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4675 	//test that palette compression occurred
  4676 	TEST(fbsCompressed->Header().iCompression != EGenericPaletteCompression);
  4677 	CleanupStack::PopAndDestroy(2);
  4678 	iFs.Delete(KTempFilename);
  4679 	INFO_PRINTF1(_L("Test Background Palette Compression - COMPLETE"));
  4680 	}
  4681 	
  4682 /**
  4683 	@SYMTestCaseID
  4684 	GRAPHICS-FBSERV-0553
  4685 
  4686 	@SYMTestCaseDesc
  4687 	The test verifies the 
  4688 	CFbsBitmap::CompressInBackground(TRequestStatus& aRequestStatus, TBitmapfileCompressionScheme aScheme)
  4689 	API. It loads bitmaps from ROM & saves (temporarily) to C-drive. 
  4690 	Then it loads from C-drive into a new bitmap.
  4691 
  4692 	@SYMTestActions
  4693 	
  4694 	@SYMTestExpectedResults
  4695 	Test should pass
  4696 */	
  4697 void CTBitmap::TestAsynchronousBackgroundPaletteCompressionL()
  4698 	{
  4699 	INFO_PRINTF1(_L("Test Asynch background Palette Compression"));
  4700 	TRequestStatus status ;
  4701 	_LIT(KmbmFileInRom, "z:\\system\\data\\24bitskin.mbm");
  4702 	RFbsSession* fbs = RFbsSession::GetSession();
  4703 	//create bitmap
  4704 	CFbsBitmap* fbsCompressed = new(ELeave) CFbsBitmap ;
  4705 	CFbsBitmap* fbsUnCompressed = new(ELeave) CFbsBitmap ;
  4706 	CleanupStack::PushL(fbsCompressed);
  4707 	CleanupStack::PushL(fbsUnCompressed);
  4708 	TEST2(fbsUnCompressed->Load(KmbmFileInRom, 0, EFalse), KErrNone);
  4709 	fbsUnCompressed->Save(KTempFilename);
  4710 	//load bitmap
  4711 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4712 	//compress bitmap (force immediate compression)
  4713 	fbsCompressed->CompressInBackground(status, EPaletteCompression);
  4714 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4715 	User::WaitForRequest(status);
  4716 	TEST2(status.Int(), KErrNone);
  4717 	//test that palette compression occurred
  4718 	TEST(fbsCompressed->Header().iCompression == EGenericPaletteCompression);
  4719 	//compare with original
  4720 	INFO_PRINTF1(_L("Compare Palette Compressed bmp with original"));
  4721 	CompareBitmaps((CFbsBitmapEx&)*fbsCompressed, (CFbsBitmapEx&)*fbsUnCompressed, EColor16M);
  4722 	CleanupStack::PopAndDestroy(2);
  4723 	iFs.Delete(KTempFilename);
  4724 	
  4725 	//Test that the RLE option works.
  4726 	//------------------------------------
  4727 	//create bitmap
  4728 	fbsCompressed = new (ELeave) CFbsBitmap ;
  4729 	fbsUnCompressed = new (ELeave) CFbsBitmap ;
  4730 	CleanupStack::PushL(fbsCompressed);
  4731 	CleanupStack::PushL(fbsUnCompressed);
  4732 	TEST2(fbsUnCompressed->Load(KmbmFileInRom, 0, EFalse), KErrNone);
  4733 	fbsUnCompressed->Save(KTempFilename);
  4734 	//load bitmap
  4735 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4736 	//compress bitmap (force immediate compression)
  4737 	fbsCompressed->CompressInBackground(status, ERLECompression);
  4738 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4739 	User::WaitForRequest(status);
  4740 	TEST2(status.Int(), KErrNone);
  4741 	//test that RLE compression occurred
  4742 	TEST(fbsCompressed->Header().iCompression == ETwentyFourBitRLECompression);
  4743 	CleanupStack::PopAndDestroy(2);
  4744 	iFs.Delete(KTempFilename);
  4745 
  4746 	//Test that unsuitable bitmaps are not palette compressed (too many colours).
  4747 	//----------------------------------------------------------------------------------------
  4748 	_LIT(KmbmMultiColourMBMInRom, "z:\\system\\data\\24bit.mbm");
  4749 	//create bitmap
  4750 	fbsCompressed = new (ELeave) CFbsBitmap ;
  4751 	fbsUnCompressed = new (ELeave) CFbsBitmap ;
  4752 	CleanupStack::PushL(fbsCompressed);
  4753 	CleanupStack::PushL(fbsUnCompressed);
  4754 	TEST2(fbsUnCompressed->Load(KmbmMultiColourMBMInRom, 0, EFalse), KErrNone);
  4755 	fbsUnCompressed->Save(KTempFilename);
  4756 	//load bitmap
  4757 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4758 	//compress bitmap (force immediate compression)
  4759 	fbsCompressed->CompressInBackground(status, EPaletteCompression);
  4760 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4761 	User::WaitForRequest(status);
  4762 	TEST2(status.Int(), KErrNotSupported);
  4763 	//test that palette compression occurred
  4764 	TEST(fbsCompressed->Header().iCompression != EGenericPaletteCompression);
  4765 	CleanupStack::PopAndDestroy(2);
  4766 	iFs.Delete(KTempFilename);
  4767 	
  4768 	//Test that unsuitable bitmaps are not palette compressed (too few BPP)
  4769 	//---------------------------------------------------------------------------------
  4770 	//create bitmap
  4771 	fbsCompressed = new(ELeave) CFbsBitmap ;
  4772 	fbsUnCompressed = new(ELeave) CFbsBitmap ;
  4773 	CleanupStack::PushL(fbsCompressed);
  4774 	CleanupStack::PushL(fbsUnCompressed);
  4775 	TEST2(fbsUnCompressed->Load(KmbmMultiColourMBMInRom, 0, EFalse), KErrNone);
  4776 	fbsUnCompressed->Save(KTempFilename);
  4777 	//load bitmap
  4778 	TEST2(fbsCompressed->Load(KTempFilename, 0, EFalse), KErrNone);
  4779 	//compress bitmap (force immediate compression)
  4780 	fbsCompressed->CompressInBackground(status, EPaletteCompression);
  4781 	fbs->SendCommand(EFbsCompress, 0); //force background compression to execute
  4782 	User::WaitForRequest(status);
  4783 	TEST2(status.Int(), KErrNotSupported);
  4784 	//test that palette compression occurred
  4785 	TEST(fbsCompressed->Header().iCompression != EGenericPaletteCompression);
  4786 	CleanupStack::PopAndDestroy(2);
  4787 	iFs.Delete(KTempFilename);
  4788 	INFO_PRINTF1(_L("Test Asynch background Palette Compressio - COMPLETE"));
  4789 	}
  4790 
  4791 /**
  4792 @SYMTestCaseID GRAPHICS-FBSERV-0501
  4793 
  4794 @SYMTestType UT
  4795 
  4796 @SYMTestPriority Medium
  4797 
  4798 @SYMCR DKRN-6QGJPT
  4799 
  4800 @SYMTestCaseDesc Get all bitmap handles before and after loading a bitmap. 
  4801 
  4802 @SYMTestActions
  4803 1) Get all bitmap handles and store number of bitmaps obtained
  4804 2) Load a new bitmap
  4805 3) Get all bitmap handles and store number of bitmaps obtained
  4806 
  4807 @SYMTestExpectedResults
  4808 The number of bitmap handles retrieved after loading the bitmap should be one more than prior to loading the bitmap.
  4809 */
  4810 void CTBitmap::GetAllBitmapsIdsL()
  4811 	{
  4812 	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
  4813 	CleanupStack::PushL(bitmap);
  4814 	
  4815 	RArray <TInt> bitmapHandleArray;
  4816 	CleanupClosePushL(bitmapHandleArray);
  4817 	
  4818 	// Get current number of bitmap handles
  4819 	User::LeaveIfError(bitmap->GetAllBitmapHandles(bitmapHandleArray));
  4820 	const TInt numBitmapHandles = bitmapHandleArray.Count();
  4821 	
  4822 	// Load another bitmap
  4823 	CFbsBitmap* bmp = LoadBitmapLC(KRc_Ram8);
  4824 	
  4825 	// Get current number of bitmap handles
  4826 	User::LeaveIfError(bitmap->GetAllBitmapHandles(bitmapHandleArray));
  4827 	const TInt newNumBitmapHandles = bitmapHandleArray.Count();
  4828 	TEST(numBitmapHandles == newNumBitmapHandles - 1);	// Ensure there is one more bitmap handle from the bitmap we just added
  4829 	
  4830 	const TInt handle = bmp->Handle();
  4831 	
  4832 	TInt foundHandle = 0;
  4833 	for (TInt count = newNumBitmapHandles-1; count>=0; --count)
  4834 		{
  4835 		if (handle == bitmapHandleArray[count])
  4836 			{
  4837 			foundHandle++;
  4838 			}
  4839 		}
  4840 	TEST(foundHandle==1);	// Ensure only one instance of this handle is found in the array
  4841 	CleanupStack::PopAndDestroy(3, bitmap);	// bmp, bitmapHandleArray, bitmap	
  4842 	}
  4843 
  4844 /**
  4845 	@SYMTestCaseID
  4846 	GRAPHICS-FBSERV-0554
  4847 
  4848 	@SYMTestCaseDesc
  4849 	Test Code For Corrupted MBM File.
  4850 	
  4851 	@SYMTestActions
  4852 	Loads a specific bitmap from a multi-bitmap 
  4853 	file from ROM and tests if it is corrupted.
  4854 	
  4855 	@SYMTestExpectedResults
  4856 	Test should pass
  4857 */
  4858 void CTBitmap::CheckBadBmp()
  4859 {
  4860 	INFO_PRINTF1(_L("MalformedBmp"));
  4861 	_LIT(KmalmbmFile0, "z:\\system\\data\\00_grbmap.mbm");
  4862 	_LIT(KmalmbmFile1, "z:\\system\\data\\01_totalstramsize!.mbm");
  4863 	_LIT(KmalmbmFile2, "z:\\system\\data\\02_headersize.mbm");
  4864 	_LIT(KmalmbmFile3, "z:\\system\\data\\03_width!.mbm");
  4865 	_LIT(KmalmbmFile4, "z:\\system\\data\\04_height!.mbm");
  4866 	_LIT(KmalmbmFile5, "z:\\system\\data\\05_bitsperpixel.mbm");
  4867 	_LIT(KmalmbmFile6, "z:\\system\\data\\bad_bmpsize.mbm");
  4868 	_LIT(KmalmbmFile7, "z:\\system\\data\\bad_colormode.mbm");
  4869 	_LIT(KmalmbmFile8, "z:\\system\\data\\bad_compression.mbm");
  4870 	_LIT(KmalmbmFile9, "z:\\system\\data\\bad_paletteentries.mbm"); 
  4871 
  4872 	CFbsBitmap* fbsmalBmp = new(ELeave) CFbsBitmap;
  4873 	CleanupStack::PushL(fbsmalBmp);
  4874 
  4875 	//load bitmap
  4876 	TEST2(fbsmalBmp->Load(KmalmbmFile0, 0, EFalse), KErrNone);
  4877 	TEST2(fbsmalBmp->Load(KmalmbmFile1, 0, EFalse), KErrCorrupt);
  4878 	TEST2(fbsmalBmp->Load(KmalmbmFile2, 0, EFalse), KErrCorrupt);
  4879 	TEST2(fbsmalBmp->Load(KmalmbmFile3, 0, EFalse), KErrCorrupt);
  4880 	TEST2(fbsmalBmp->Load(KmalmbmFile4, 0, EFalse), KErrCorrupt);
  4881 	TEST2(fbsmalBmp->Load(KmalmbmFile5, 0, EFalse), KErrNotSupported);
  4882 	TEST2(fbsmalBmp->Load(KmalmbmFile6, 0, EFalse), KErrCorrupt);
  4883 	TEST2(fbsmalBmp->Load(KmalmbmFile7, 0, EFalse), KErrCorrupt);
  4884 	TEST2(fbsmalBmp->Load(KmalmbmFile8, 0, EFalse), KErrCorrupt);
  4885 	TEST2(fbsmalBmp->Load(KmalmbmFile9, 0, EFalse), KErrNotSupported);
  4886 
  4887 	CleanupStack::PopAndDestroy(fbsmalBmp);
  4888 }
  4889 
  4890 /**
  4891 @SYMTestCaseID			GRAPHICS-FBSERV-0613
  4892 
  4893 @SYMDEF					PDEF111181
  4894 
  4895 @SYMTestCaseDesc		Test the return code of operations on bitmaps in the background compression queue
  4896 
  4897 @SYMTestPriority		Critical
  4898 
  4899 @SYMTestType			UT
  4900 
  4901 @SYMTestStatus			Implemented
  4902 
  4903 @SYMTestActions			1. Creates a bitmap
  4904 						2. Calls CompressInBackground()
  4905 						3. Call Resize
  4906 						4. Waits until compression is finished
  4907 
  4908 @SYMTestExpectedResults The call to resize should return with KErrInUse since the compression is in progress
  4909 */
  4910 
  4911 void CTBitmap::TestBgCompressInUseL()
  4912 	{
  4913 	INFO_PRINTF1(_L("Test the return code of operations on bitmaps in the background compression queue"));
  4914 	
  4915 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  4916 	CleanupStack::PushL(bmp);
  4917 
  4918 	TInt ret = bmp->Create(TSize(256, 256), EGray256); // create a solid grey bitmap
  4919 	TEST2 (ret,KErrNone);
  4920 	TRequestStatus status;
  4921 	bmp->CompressInBackground(status);
  4922 	TInt resizeRet = bmp->Resize(TSize(512,512));
  4923 	
  4924 	TEST2 (resizeRet,KErrInUse);
  4925 	User::WaitForRequest(status);
  4926 	TEST2 (status.Int(), KErrNone);
  4927 	CleanupStack::PopAndDestroy(bmp);
  4928 	}
  4929 
  4930 
  4931 //------------------------------------------------------------------------------
  4932 
  4933 LOCAL_D const TInt KTestBitmapWidth = 256; // this affects BitmapCheckCompressed()
  4934 LOCAL_D const TInt KTestBitmapHeight = 256;
  4935 LOCAL_D const TInt KTestBitmapResizeHeight = 512;
  4936 LOCAL_D const TInt KMaxRLERunLength = 127;
  4937 
  4938 LOCAL_C void SetBitmapDataWithVerticalGradient(TUint8* aDataPtr)
  4939 	{
  4940 	for (TInt y = 0; y < KTestBitmapHeight; ++y)
  4941 		for (TInt x = 0; x < KTestBitmapWidth; ++x)
  4942 			*aDataPtr++ = y;
  4943 	}
  4944 
  4945 LOCAL_C TBool BitmapDataCheckVerticalGradient(const TUint8* aDataPtr)
  4946 	{
  4947 	for (TInt y = 0; y < KTestBitmapHeight; ++y)
  4948 		for (TInt x = 0; x < KTestBitmapWidth; ++x)
  4949 			if (*aDataPtr++ != y)
  4950 				return EFalse;
  4951 	return ETrue;
  4952 	}
  4953 
  4954 LOCAL_C void SetBitmapDataWithHorizontalGradient(TUint8* aDataPtr)
  4955 	{
  4956 	for (TInt y = 0; y < KTestBitmapHeight; ++y)
  4957 		for (TInt x = 0; x < KTestBitmapWidth; ++x)
  4958 			*aDataPtr++ = x;
  4959 	}
  4960 
  4961 LOCAL_C TBool BitmapDataCheckHorizontalGradient(const TUint8* aDataPtr)
  4962 	{
  4963 	for (TInt y = 0; y < KTestBitmapHeight; ++y)
  4964 		for (TInt x = 0; x < KTestBitmapWidth; ++x)
  4965 			if (*aDataPtr++ != x)
  4966 				return EFalse;
  4967 	return ETrue;
  4968 	}
  4969 
  4970 LOCAL_C TInt ResizeTestBitmap(CFbsBitmap* aBitmap)
  4971 	{
  4972 	return aBitmap->Resize(TSize(KTestBitmapWidth, KTestBitmapResizeHeight));
  4973 	}
  4974 
  4975 LOCAL_C TBool BitmapCheckResized(const CFbsBitmap* aBitmap)
  4976 	{
  4977 	if (aBitmap->SizeInPixels() != TSize(KTestBitmapWidth, KTestBitmapResizeHeight))
  4978 		return EFalse;
  4979 	TUint8* dataPtr = (TUint8*)aBitmap->DataAddress();
  4980 	for (TInt y = 0; y < KTestBitmapHeight; ++y)
  4981 		for (TInt x = 0; x < KTestBitmapWidth; ++x)
  4982 			if (*dataPtr++ != y)
  4983 				return EFalse;
  4984 	for (TInt y = KTestBitmapHeight; y < KTestBitmapResizeHeight; ++y)
  4985 		for (TInt x = 0; x < KTestBitmapWidth; ++x)
  4986 			if (*dataPtr++ != 0xFF)
  4987 				return EFalse;
  4988 	return ETrue;
  4989 	}
  4990 
  4991 LOCAL_C TInt CompressTestBitmap(CFbsBitmap* aBitmap)
  4992 	{
  4993 	return aBitmap->Compress();
  4994 	}
  4995 
  4996 LOCAL_C TBool BitmapCheckCompressed(const CFbsBitmap* aBitmap)
  4997 	{
  4998 	if (aBitmap->SizeInPixels() != TSize(KTestBitmapWidth, KTestBitmapHeight))
  4999 		return EFalse;
  5000 	// check RLE compression on vertical gradient
  5001 	TUint8* dataPtr = (TUint8*)aBitmap->DataAddress();
  5002 	for (TInt y = 0; y < KTestBitmapHeight - 1; ++y)
  5003 		{
  5004 		// this works when the width of the bitmap is 256, or twice the maximum encodable run length, which is 128
  5005 		if (*dataPtr++ != KMaxRLERunLength)
  5006 			return EFalse;
  5007 		if (*dataPtr++ != y)
  5008 			return EFalse;
  5009 		if (*dataPtr++ != KMaxRLERunLength)
  5010 			return EFalse;
  5011 		if (*dataPtr++ != y)
  5012 			return EFalse;
  5013 		}
  5014 	return ETrue;
  5015 	}
  5016 
  5017 struct TTestThreadParams
  5018 	{
  5019 	TInt iBitmapHandle;
  5020 	TInt (*iBitmapFunction)(CFbsBitmap*); // operation to perform on the bitmap
  5021 	TBool (*iCheckFunction)(const CFbsBitmap*); // check that the operation was successfully performed
  5022 	};
  5023 
  5024 LOCAL_C void AlternateTestThreadL(const TTestThreadParams& aParams)
  5025 	{
  5026 	RFbsSession* fbs = RFbsSession::GetSession();
  5027 	if (fbs->ResourceCount() != 0)
  5028 		User::Leave(KErrGeneral);
  5029 	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
  5030 	CleanupStack::PushL(bmp);
  5031 	User::LeaveIfError(bmp->Duplicate(aParams.iBitmapHandle));
  5032 	if (fbs->ResourceCount() != 1)
  5033 		User::Leave(KErrGeneral);
  5034 	if (!BitmapDataCheckVerticalGradient((TUint8*)bmp->DataAddress()))
  5035 		User::Leave(KErrGeneral);
  5036 	User::LeaveIfError((*aParams.iBitmapFunction)(bmp));
  5037 	if (fbs->ResourceCount() != 1)
  5038 		User::Leave(KErrGeneral);
  5039 	if (aParams.iCheckFunction != NULL && !(*aParams.iCheckFunction)(bmp))
  5040 		User::Leave(KErrGeneral);
  5041 	CleanupStack::PopAndDestroy(bmp);
  5042 	if (fbs->ResourceCount() != 0)
  5043 		User::Leave(KErrGeneral);
  5044 	}
  5045 
  5046 LOCAL_C TInt AlternateTestThread(TAny* aParams)
  5047 	{
  5048 	__UHEAP_MARK;
  5049 	TInt ret = RFbsSession::Connect();
  5050 	if (ret != KErrNone)
  5051 		return ret;
  5052 	CTrapCleanup* cleanupStack = CTrapCleanup::New();
  5053 	if (cleanupStack == NULL)
  5054 		return KErrNoMemory;
  5055 	TRAP(ret, AlternateTestThreadL(*static_cast<TTestThreadParams*>(aParams)));
  5056 	delete cleanupStack;
  5057 	RFbsSession::Disconnect();
  5058 	__UHEAP_MARKEND;
  5059 	return ret;
  5060 	}
  5061 
  5062 void CTBitmap::MultiThreadedTestsL()
  5063 	{
  5064 	((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0503"));
  5065 	MultiThreadedResizeTestL();
  5066 	((CTBitmapStep*)iStep)->RecordTestResultL();
  5067 	((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0504"));
  5068 	MultiThreadedCompressTestL();
  5069 #ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
  5070 	((CTBitmapStep*)iStep)->RecordTestResultL();
  5071 	((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0505"));
  5072 	MultiThreadedLockHeapTestL();
  5073 #endif
  5074 	}
  5075 
  5076 /**
  5077 @SYMTestCaseID			GRAPHICS-FBSERV-0503
  5078 
  5079 @SYMDEF					DEF090812
  5080 
  5081 @SYMTestCaseDesc		Tests behaviour of CFbsBitmap::DataAddress() and CFbsBitmap::Resize() when called concurrently by different threads
  5082 
  5083 @SYMTestPriority		High
  5084 
  5085 @SYMTestType			UT
  5086 
  5087 @SYMTestStatus			Implemented
  5088 
  5089 @SYMTestActions			1. The 1st thread will create a bitmap, store a pointer to the bitmap data, launch the 2nd thread and then wait for it to terminate
  5090 						2. The 2nd thread will resize the same bitmap and exit
  5091 						3. The 1st thread will manipulate the bitmap data using the stored pointer and then re-fetch the bitmap data
  5092 
  5093 @SYMTestExpectedResults	The 1st thread should be able both to manipulate the old bitmap data and check the resized bitmap data
  5094 */
  5095 void CTBitmap::MultiThreadedResizeTestL()
  5096 	{
  5097 	INFO_PRINTF1(_L("Test Resize() with Multiple Threads"));
  5098 	DoMultiThreadedTestL(_L("AlternateResizeThread"), ResizeTestBitmap, BitmapCheckResized);
  5099 	}
  5100 
  5101 /**
  5102 @SYMTestCaseID			GRAPHICS-FBSERV-0504
  5103 
  5104 @SYMDEF					DEF090812
  5105 
  5106 @SYMTestCaseDesc		Tests behaviour of CFbsBitmap::DataAddress() and CFbsBitmap::Compress() when called concurrently by different threads
  5107 
  5108 @SYMTestPriority		High
  5109 
  5110 @SYMTestType			UT
  5111 
  5112 @SYMTestStatus			Implemented
  5113 
  5114 @SYMTestActions			1. The 1st thread will create a bitmap, store a pointer to the bitmap data, launch the 2nd thread and then wait for it to terminate
  5115 						2. The 2nd thread will compress the same bitmap and exit
  5116 						3. The 1st thread will manipulate the bitmap data using the stored pointer and then re-fetch the bitmap data
  5117 
  5118 @SYMTestExpectedResults	The 1st thread should be able both to manipulate the old bitmap data and check the compressed bitmap data
  5119 */
  5120 void CTBitmap::MultiThreadedCompressTestL()
  5121 	{
  5122 	INFO_PRINTF1(_L("Test Compress() with Multiple Threads"));
  5123 	DoMultiThreadedTestL(_L("AlternateCompressThread"), CompressTestBitmap, BitmapCheckCompressed);
  5124 	}
  5125 
  5126 void CTBitmap::DoMultiThreadedTestL(const TDesC& aThreadName, TInt (*aBitmapFunction)(CFbsBitmap*), TBool (*aCheckFunction)(const CFbsBitmap*))
  5127 	{
  5128 	CFbsBitmap* bmp = new CFbsBitmap;
  5129 	ASSERT_NOT_NULL(bmp);
  5130 	CleanupStack::PushL(bmp);
  5131 	TInt ret = bmp->Create(TSize(KTestBitmapWidth, KTestBitmapHeight), EGray256);
  5132 	ASSERT_EQUALS(ret, KErrNone);
  5133 	TUint8* dataPtr = (TUint8*)bmp->DataAddress();
  5134 	SetBitmapDataWithVerticalGradient(dataPtr);
  5135 	TTestThreadParams params;
  5136 	params.iBitmapHandle = bmp->Handle();
  5137 	params.iBitmapFunction = aBitmapFunction;
  5138 	params.iCheckFunction = aCheckFunction;
  5139 	RThread thread;
  5140 	ret = thread.Create(aThreadName, AlternateTestThread, KDefaultStackSize, 0x2000, 0x2000, &params);
  5141 	ASSERT_EQUALS(ret, KErrNone);
  5142 	TRequestStatus status;
  5143 	thread.Logon(status);
  5144 	thread.Resume();
  5145 	User::WaitForRequest(status);
  5146 	TExitType exitType = thread.ExitType();
  5147 	TInt exitReason = thread.ExitReason();
  5148 	TEST(exitType == EExitKill);
  5149 	TEST(exitReason == KErrNone);
  5150 	thread.Close();
  5151 	TEST(BitmapDataCheckVerticalGradient(dataPtr));
  5152 	SetBitmapDataWithHorizontalGradient(dataPtr);
  5153 	TEST(BitmapDataCheckHorizontalGradient(dataPtr));
  5154 	TEST((*aCheckFunction)(bmp));
  5155 	CleanupStack::PopAndDestroy(bmp);
  5156 	User::Heap().Check();
  5157 	}
  5158 
  5159 #ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
  5160 _LIT(KFBSERVClientPanicCategory, "FBSCLI");
  5161 
  5162 LOCAL_C TInt LockHeapTestBitmap(CFbsBitmap* aBitmap)
  5163 	{
  5164 	aBitmap->LockHeap();
  5165 	return KErrNone;
  5166 	}
  5167 
  5168 /**
  5169 @SYMTestCaseID			GRAPHICS-FBSERV-0505
  5170 
  5171 @SYMDEF					DEF090812
  5172 
  5173 @SYMTestCaseDesc		Tests behaviour of CFbsBitmap::LockHeap() when called concurrently by different threads
  5174 
  5175 @SYMTestPriority		High
  5176 
  5177 @SYMTestType			UT
  5178 
  5179 @SYMTestStatus			Implemented
  5180 
  5181 @SYMTestActions			1. The 1st thread will create a bitmap, call LockHeap() on it, launch the 2nd thread and then wait for it to terminate
  5182 						2. The 2nd thread will also call LockHeap() on the same bitmap
  5183 						3. The 1st thread will check that the 2nd thread has panicked
  5184 
  5185 @SYMTestExpectedResults	Panic FBSCLI 22
  5186 */
  5187 void CTBitmap::MultiThreadedLockHeapTestL()
  5188 	{
  5189 	INFO_PRINTF1(_L("Test LockHeap() Panic with Multiple Threads"));
  5190 	CFbsBitmap* bmp = new CFbsBitmap;
  5191 	ASSERT_NOT_NULL(bmp);
  5192 	CleanupStack::PushL(bmp);
  5193 	TInt ret = bmp->Create(TSize(KTestBitmapWidth, KTestBitmapHeight), EGray256);
  5194 	ASSERT_EQUALS(ret, KErrNone);
  5195 	SetBitmapDataWithVerticalGradient((TUint8*)bmp->DataAddress());
  5196 	bmp->LockHeap();
  5197 	TTestThreadParams params;
  5198 	params.iBitmapHandle = bmp->Handle();
  5199 	params.iBitmapFunction = LockHeapTestBitmap;
  5200 	params.iCheckFunction = NULL;
  5201 	RThread thread;
  5202 	ret = thread.Create(_L("AlternateLockHeapThread"), AlternateTestThread, KDefaultStackSize, 0x2000, 0x2000, &params);
  5203 	ASSERT_EQUALS(ret, KErrNone);
  5204 	TRequestStatus status;
  5205 	thread.Logon(status);
  5206 	thread.Resume();
  5207 	User::WaitForRequest(status);
  5208 	TExitType exitType = thread.ExitType();
  5209 	TExitCategoryName exitCategory = thread.ExitCategory();
  5210 	TInt exitReason = thread.ExitReason();
  5211 	TEST(exitType == EExitPanic);
  5212 	TEST(exitCategory == KFBSERVClientPanicCategory);
  5213 	TEST(exitReason == EFbsPanicBadHeapLock);
  5214 	thread.Close();
  5215 	CleanupStack::PopAndDestroy(bmp);
  5216 	User::Heap().Check();
  5217 	}
  5218 #endif
  5219 
  5220 //--------------
  5221 
  5222 class CStopTestBgCompress: public CAsyncOneShot
  5223 	{
  5224 public:
  5225 	CStopTestBgCompress(): CAsyncOneShot(CActive::EPriorityIdle - 1) {} // priority must be less than CFbsSessionHelper
  5226 	void RunL() { CActiveScheduler::Stop(); }
  5227 	};
  5228 
  5229 LOCAL_C TInt TestBgCompressThread(TAny* /*aParams*/)
  5230 	{
  5231 	const TInt KBmpSize = 0x100000 + sizeof(SEpocBitmapHeader);
  5232 	// assuming run-length encoding every scan line gets compressed into 8 runs of 128 bytes each
  5233 	// 2 bytes per encoded run results in 16 bytes per scan line so the compressed bitmap is large (>16K)
  5234 	// a few bytes added at the end for the compression bookmark are rounded up to a page
  5235 	const TInt KBmpCompressedSize = 0x5000;
  5236 	TInt ret = KErrNone;
  5237 	__UHEAP_MARK;
  5238 	CTrapCleanup* trap = CTrapCleanup::New();
  5239 	TRequestStatus status;
  5240 	if (trap == NULL)
  5241 		{
  5242 		ret = KErrNoMemory;
  5243 		goto exitNoTrap;
  5244 		}
  5245 	CActiveScheduler* scheduler = new CActiveScheduler;
  5246 	if (scheduler == NULL)
  5247 		{
  5248 		ret = KErrNoMemory;
  5249 		goto exitNoScheduler;
  5250 		}
  5251 	CActiveScheduler::Install(scheduler);
  5252 	CStopTestBgCompress* stop = new CStopTestBgCompress;
  5253 	if (stop == NULL)
  5254 		{
  5255 		ret = KErrNoMemory;
  5256 		goto exitNoStop;
  5257 		}
  5258 	ret = RFbsSession::Connect();
  5259 	if (ret != KErrNone)
  5260 		goto exitNoFbs;
  5261 	CFbsBitmapEx* bmp = new CFbsBitmapEx;
  5262 	if (bmp == NULL)
  5263 		{
  5264 		ret = KErrNoMemory;
  5265 		goto exitNoBmp;
  5266 		}
  5267 	CFbsBitmapEx* bmp2 = new CFbsBitmapEx;
  5268 	if (bmp2 == NULL)
  5269 		{
  5270 		ret = KErrNoMemory;
  5271 		goto exitNoBmp2;
  5272 		}
  5273 	ret = bmp->Create(TSize(1024, 1024), EGray256); // create a solid white bitmap
  5274 	if (ret != KErrNone)
  5275 		goto exitAll;
  5276 	ret = bmp2->Duplicate(bmp->Handle()); // duplicate the bitmap handle
  5277 	if (ret != KErrNone)
  5278 		goto exitAll;
  5279 	bmp->CompressInBackground(status);
  5280 	User::WaitForRequest(status);
  5281 	if (status != KErrNone)
  5282 		{
  5283 		ret = status.Int();
  5284 		goto exitAll;
  5285 		}
  5286 	if (bmp->BitmapAddress()->Header().iBitmapSize != KBmpSize || bmp->BitmapAddress() != bmp2->BitmapAddress())
  5287 		{
  5288 		ret = KErrGeneral;
  5289 		goto exitAll;
  5290 		}
  5291 	stop->Call();
  5292 	CActiveScheduler::Start(); // now CFbsSessionHelper should clean both bmp and bmp2 and free the dirty bitmap data
  5293 	if (!bmp->BitmapAddress()->IsCompressedInRAM() || bmp->BitmapAddress()->Header().iBitmapSize > KBmpCompressedSize || bmp->BitmapAddress() != bmp2->BitmapAddress())
  5294 		ret = KErrGeneral;
  5295 exitAll:
  5296 	delete bmp2;
  5297 exitNoBmp2:
  5298 	delete bmp;
  5299 exitNoBmp:
  5300 	RFbsSession::Disconnect();
  5301 exitNoFbs:
  5302 	delete stop;
  5303 exitNoStop:
  5304 	delete scheduler;
  5305 exitNoScheduler:
  5306 	delete trap;
  5307 exitNoTrap:
  5308 	__UHEAP_MARKEND;
  5309 	return ret;
  5310 	}
  5311 
  5312 /**
  5313 @SYMTestCaseID			GRAPHICS-FBSERV-0612
  5314 
  5315 @SYMDEF					INC109293
  5316 
  5317 @SYMTestCaseDesc		Tests memory usage with CFbsBitmap::CompressInBackground()
  5318 
  5319 @SYMTestPriority		High
  5320 
  5321 @SYMTestType			UT
  5322 
  5323 @SYMTestStatus			Implemented
  5324 
  5325 @SYMTestActions			1. Creates a bitmap
  5326 						2. Calls CompressInBackground()
  5327 						3. Waits until compression is finished
  5328 						4. Gives the active scheduler the chance to run the session's helper
  5329 
  5330 @SYMTestExpectedResults	Efficient use of memory
  5331 */
  5332 void CTBitmap::TestBgCompressL()
  5333 	{
  5334 	INFO_PRINTF1(_L("Test memory usage with CFbsBitmap::CompressInBackground()"));
  5335 	RThread thread;
  5336 	TInt ret = thread.Create(_L("TestBgCompressThread"), TestBgCompressThread, KDefaultStackSize, 0x2000, 0x2000, NULL);
  5337 	ASSERT_EQUALS(ret, KErrNone);
  5338 	TRequestStatus status;
  5339 	thread.Logon(status);
  5340 	thread.Resume();
  5341 	User::WaitForRequest(status);
  5342 	TExitType exitType = thread.ExitType();
  5343 	TInt exitReason = thread.ExitReason();
  5344 	TEST(exitType == EExitKill);
  5345 	TEST(exitReason == KErrNone);
  5346 	if (exitType != EExitKill || exitReason != KErrNone)
  5347 		{
  5348 		INFO_PRINTF3(_L("Exit Type = %d, Exit Reason = %d"), TInt(exitType), exitReason);
  5349 		}
  5350 	thread.Close();
  5351 	}
  5352 
  5353 /**
  5354 @SYMTestCaseID			GRAPHICS-FBSERV-0618
  5355 
  5356 @SYMDEF					DEF123068
  5357 
  5358 @SYMTestCaseDesc		Tests that small and large bitmaps are white-filled upon creation.
  5359 
  5360 @SYMTestPriority		High
  5361 
  5362 @SYMTestType			UT
  5363 
  5364 @SYMTestStatus			Implemented
  5365 
  5366 @SYMTestActions			1. Create a small bitmap
  5367 						2. Create a large bitmap
  5368 
  5369 @SYMTestExpectedResults	Both bitmaps are filled with white
  5370 */
  5371 void CTBitmap::TestBitmapWhiteFillL()
  5372 	{
  5373 	INFO_PRINTF1(_L("Test white fill of CFbsBitmap upon creation."));
  5374 	const TDisplayMode KDispMode = EColor16MAP;
  5375 	RPointerArray<CFbsBitmap> bmpArray;
  5376 	const TSize KBitmapSmallSize(4,4);
  5377 	const TSize KBitmapLargeSize(200,200);
  5378 	
  5379 	// Create small CFbsBitmap
  5380 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;;
  5381 	TInt ret = bmp->Create(KBitmapSmallSize,KDispMode);
  5382 	TEST2(ret, KErrNone);
  5383 	bmpArray.AppendL(bmp);
  5384 	// Create large CFbsBitmap
  5385 	bmp = new (ELeave) CFbsBitmap;;
  5386 	ret = bmp->Create(KBitmapLargeSize,KDispMode);
  5387 	TEST2(ret, KErrNone);
  5388 	bmpArray.AppendL(bmp);
  5389 	// Create small hardware bitmap
  5390 	bmp = new (ELeave) CFbsBitmap;;
  5391 	ret = bmp->CreateHardwareBitmap(KBitmapSmallSize, KDispMode, KNullUid);
  5392 	if (ret == KErrNotSupported)
  5393 		{
  5394 		INFO_PRINTF1(_L("WhiteFill test skipped for small hardware bitmaps as they are not supported"));
  5395 		delete bmp;
  5396 		}
  5397 	else
  5398 		{
  5399 		TEST2(ret, KErrNone);
  5400 		bmpArray.AppendL(bmp);
  5401 		}
  5402 	// Create large hardware bitmap
  5403 	bmp = new (ELeave) CFbsBitmap;;
  5404 	ret = bmp->CreateHardwareBitmap(KBitmapLargeSize, KDispMode, KNullUid);
  5405 	if (ret == KErrNotSupported)
  5406 		{
  5407 		INFO_PRINTF1(_L("WhiteFill test skipped for large hardware bitmaps as they are not supported"));
  5408 		delete bmp;
  5409 		}
  5410 	else
  5411 		{
  5412 		TEST2(ret, KErrNone);
  5413 		bmpArray.AppendL(bmp);
  5414 		}
  5415 	
  5416 	for (TInt ii = 0; ii < bmpArray.Count(); ++ii)
  5417 		{
  5418 		bmp = bmpArray[ii];
  5419 		bmp->BeginDataAccess();
  5420 		TUint32* base = bmp->DataAddress();
  5421 		TSize size = bmp->SizeInPixels();
  5422 		TInt scanLineLength = CFbsBitmap::ScanLineLength(size.iWidth,KDispMode);
  5423 		TInt dataLength = scanLineLength * size.iHeight;
  5424 		CheckWhite((TUint8*)base,dataLength,KDispMode);
  5425 		bmp->EndDataAccess(ETrue);
  5426 		delete bmp;
  5427 		}
  5428 	bmpArray.Close();
  5429 	}
  5430 
  5431 //--------------
  5432 
  5433 // The code for regression test case GRAPHICS-FBSERV-0614 must be in a separate thread
  5434 // because it has to call RFbsSession::Disconnect() and without the fix it panics.
  5435 LOCAL_C TInt TestDisconnectWithBitmapThread(TAny* /*aParams*/)
  5436 	{
  5437 	CTrapCleanup* trap = CTrapCleanup::New();
  5438 	if (trap == NULL)
  5439 		return KErrNoMemory;
  5440 	CActiveScheduler* scheduler = new CActiveScheduler;
  5441 	if (scheduler == NULL)
  5442 		{
  5443 		delete trap;
  5444 		return KErrNoMemory;
  5445 		}
  5446 	CActiveScheduler::Install(scheduler);
  5447 	TInt ret = RFbsSession::Connect();
  5448 	if (ret != KErrNone)
  5449 		{
  5450 		delete scheduler;
  5451 		delete trap;
  5452 		return ret;
  5453 		}
  5454 	CFbsBitmap* bmp = new CFbsBitmap;
  5455 	if (bmp == NULL)
  5456 		{
  5457 		RFbsSession::Disconnect();
  5458 		delete scheduler;
  5459 		delete trap;
  5460 		return KErrNoMemory;
  5461 		}
  5462 	ret = bmp->Create(TSize(256, 256), EGray256); // create a solid white bitmap
  5463 	if (ret != KErrNone)
  5464 		{
  5465 		RFbsSession::Disconnect();
  5466 		delete scheduler;
  5467 		delete trap;
  5468 		return ret;
  5469 		}
  5470 	RFbsSession::Disconnect();
  5471 	delete scheduler;
  5472 	delete trap;
  5473 	return ret;
  5474 	}
  5475 
  5476 /**
  5477 @SYMTestCaseID			GRAPHICS-FBSERV-0614
  5478 
  5479 @SYMDEF					INC113118
  5480 
  5481 @SYMTestCaseDesc		Tests behaviour when RFbsSession::Disconnect() is called and there is a CFbsBitmap not yet deleted
  5482 
  5483 @SYMTestPriority		High
  5484 
  5485 @SYMTestType			UT
  5486 
  5487 @SYMTestStatus			Implemented
  5488 
  5489 @SYMTestActions			1. Creates and installs an active scheduler so that CFbsSessionHelper can be activated
  5490 						2. Calls RFbsSession::Connect()
  5491 						3. Creates a bitmap
  5492 						4. Calls RFbsSession::Disconnect()
  5493 
  5494 @SYMTestExpectedResults	The bitmap should be destroyed automatically and no panics should occur
  5495 */
  5496 void CTBitmap::TestDisconnectWithBitmapL()
  5497 	{
  5498 	INFO_PRINTF1(_L("Test RFbsSession::Disconnect() with a CFbsBitmap not yet deleted"));
  5499 	RThread thread;
  5500 	TInt ret = thread.Create(_L("TestDisconnectWithBitmapThread"), TestDisconnectWithBitmapThread, KDefaultStackSize, 0x2000, 0x2000, NULL);
  5501 	ASSERT_EQUALS(ret, KErrNone);
  5502 	TRequestStatus status;
  5503 	thread.Logon(status);
  5504 	thread.Resume();
  5505 	User::WaitForRequest(status);
  5506 	TExitType exitType = thread.ExitType();
  5507 	TInt exitReason = thread.ExitReason();
  5508 	TEST(exitType == EExitKill);
  5509 	TEST(exitReason == KErrNone);
  5510 	thread.Close();
  5511 	}
  5512 
  5513 /**
  5514 @SYMTestCaseID			GRAPHICS-FBSERV-0617
  5515 
  5516 @SYMPREQ				PREQ39
  5517 
  5518 @SYMTestCaseDesc		Test that bitmaps have been touched when data changes.
  5519 						Test that bitmaps become volatile when DataAddress is called outside of 
  5520 						calls to  BeginDataAccess()	and EndDataAccess().
  5521 
  5522 @SYMTestStatus			Implemented
  5523 
  5524 @SYMTestPriority		High
  5525 
  5526 @SYMTestActions			Create a bitmap.
  5527 						Call each public API.
  5528 						Check that the touch count increases when the bitmap data has been modified.
  5529 						Check whether bitmap is volatile.
  5530 @SYMTestExpectedResults	Touch count only increases for the following functions:
  5531 	 						Resize,
  5532 	 						SetDisplayMode,
  5533 	 						SetScanLine,
  5534 	 						InternalizeL,
  5535 	 						SwapWidthAndHeight,
  5536 	 						DataAddress() called inside a Begin() and End(EFalse) pairing.
  5537 	 					Bitmap is volatile only when DataAddress() called outside
  5538 	 					a Begin() and End(EFalse) pairing.
  5539 */
  5540 void CTBitmap::TestTouchedAndVolatileL()
  5541 	{
  5542 	INFO_PRINTF1(_L("Test bitmaps become touched or volatile when data changes."));
  5543 	CFbsBitmap* bmp = new CFbsBitmap;
  5544 	TEST(bmp != NULL);
  5545 	TInt touchCount = 0;
  5546 	TInt newTouchCount = 0;
  5547 	CleanupStack::PushL(bmp);
  5548 	
  5549 	// Resize
  5550 	User::LeaveIfError(bmp->Create(TSize(4,4),EColor16MA));
  5551 	touchCount = bmp->TouchCount();
  5552 	TInt ret = bmp->Resize(TSize(5,5));
  5553 	TEST(ret == KErrNone);
  5554 	newTouchCount = bmp->TouchCount();
  5555 	TEST(newTouchCount == touchCount+1);
  5556 	TEST(!bmp->IsVolatile());
  5557 	touchCount = bmp->TouchCount();
  5558 	ret = bmp->Resize(TSize(3,3));
  5559 	TEST(ret == KErrNone);
  5560 	newTouchCount = bmp->TouchCount();
  5561 	TEST(newTouchCount == touchCount+1);
  5562 	TEST(!bmp->IsVolatile());
  5563 	touchCount = bmp->TouchCount();
  5564 	ret = bmp->Resize(TSize(3,3));
  5565 	TEST(ret == KErrNone);
  5566 	newTouchCount = bmp->TouchCount();
  5567 	TEST(newTouchCount == touchCount+1);
  5568 	TEST(!bmp->IsVolatile());
  5569 	bmp->Reset();
  5570 
  5571 	// SetDisplayMode
  5572 	User::LeaveIfError(bmp->Create(TSize(4,4),EColor16MA));
  5573 	touchCount = bmp->TouchCount();
  5574 	ret = bmp->SetDisplayMode(EColor16MAP);
  5575 	TEST(ret == KErrNone);
  5576 	newTouchCount = bmp->TouchCount();
  5577 	TEST(newTouchCount == touchCount+1);
  5578 	TEST(!bmp->IsVolatile());
  5579 	bmp->Reset();
  5580 
  5581 	// SetScanLine
  5582 	TInt scanLineLength = CFbsBitmap::ScanLineLength(256,EColor16MA);
  5583 	TUint8* buffer = new TUint8[scanLineLength];
  5584 	TEST(buffer != NULL);
  5585 	TPtr8 scanline(buffer,scanLineLength,scanLineLength);
  5586 	User::LeaveIfError(bmp->Create(TSize(4,4),EColor16MA));
  5587 	touchCount = bmp->TouchCount();
  5588 	bmp->SetScanLine(scanline, 1);
  5589 	newTouchCount = bmp->TouchCount();
  5590 	TEST(newTouchCount == touchCount+1);
  5591 	TEST(!bmp->IsVolatile());
  5592 	delete[] buffer;
  5593 	bmp->Reset();
  5594 
  5595 	// SwapWidthAndHeight
  5596 	User::LeaveIfError(bmp->Create(TSize(4,6),EColor16MA));
  5597 	touchCount = bmp->TouchCount();
  5598 	ret = bmp->SwapWidthAndHeight();
  5599 	TEST(ret == KErrNone);
  5600 	newTouchCount = bmp->TouchCount();
  5601 	TEST(newTouchCount == touchCount+1);
  5602 	TEST(!bmp->IsVolatile());
  5603 	bmp->Reset();
  5604 
  5605 	// InternalizeL
  5606 	// Requires data to be externalised first
  5607 	User::LeaveIfError(bmp->Create(TSize(4,6),EColor16MA));
  5608 	touchCount = bmp->TouchCount();
  5609 	CDirectFileStore* writestore = CDirectFileStore::ReplaceL(iFs,KTempFilename,EFileStream|EFileWrite);
  5610 	TEST(writestore != NULL);
  5611 	TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
  5612 	writestore->SetTypeL(uidtype);
  5613 	RStoreWriteStream writestrm;
  5614 	TStreamId headerid(0);
  5615 	headerid = writestrm.CreateL(*writestore);
  5616 	writestore->SetRootL(headerid);
  5617 	bmp->ExternalizeL(writestrm);
  5618 	writestrm.Close();
  5619 	delete writestore;
  5620 	bmp->Reset();
  5621 	// Now internalise data to reset bitmap.
  5622 	CDirectFileStore* readstore = CDirectFileStore::OpenL(iFs,KTempFilename,EFileStream|EFileRead);
  5623 	RStoreReadStream readstrm;
  5624 	headerid = readstore->Root();
  5625 	readstrm.OpenL(*readstore,headerid);
  5626 	bmp->InternalizeL(readstrm);
  5627 	readstrm.Close();
  5628 	delete readstore;
  5629 	newTouchCount = bmp->TouchCount();
  5630 	TEST(newTouchCount == touchCount+1);
  5631 	TEST(!bmp->IsVolatile());
  5632 	bmp->Reset();
  5633 	
  5634 	
  5635 	// DataAddress
  5636 	// 1. Call as read-only (by passing ETrue into End())
  5637 	// Expect: touch count doesn't increase & bitmap not volatile
  5638 	User::LeaveIfError(bmp->Create(TSize(4,6),EColor16MA));
  5639 	touchCount = bmp->TouchCount();
  5640 	bmp->BeginDataAccess();
  5641 	bmp->DataAddress(); // ignore returned value for this test.
  5642 	bmp->EndDataAccess(ETrue);
  5643 	newTouchCount = bmp->TouchCount();
  5644 	TEST(newTouchCount == touchCount);
  5645 	TEST(!bmp->IsVolatile());
  5646 	// 2. Call as writeable  (by passing EFalse into End())
  5647 	// Expect: touch count increases & bitmap not volatile
  5648 	touchCount = newTouchCount;
  5649 	bmp->BeginDataAccess();
  5650 	bmp->DataAddress(); // ignore returned value for this test.
  5651 	bmp->EndDataAccess(EFalse);
  5652 	newTouchCount = bmp->TouchCount();
  5653 	TEST(newTouchCount == touchCount+1);
  5654 	TEST(!bmp->IsVolatile());
  5655 	// 3. Call without Begin/End pairing
  5656 	// Expect: bitmap is volatile
  5657 	bmp->DataAddress(); // ignore returned value for this test.
  5658 	TEST(bmp->IsVolatile());
  5659 	bmp->Reset();
  5660 
  5661 	CleanupStack::PopAndDestroy(bmp);
  5662 	}
  5663 
  5664 #ifdef _DEBUG
  5665 /*
  5666  * Creates an extended bitmap and it tries to use it with TBitmapUtil, which should cause a panic
  5667  */
  5668 LOCAL_C void DoBitmapUtilWithExtendedBitmapThreadL()
  5669     {  
  5670     const TUint8 KTestData[]        = "Extended bitmap test data 123456";
  5671     const TInt KTestDataSize        = sizeof(KTestData);
  5672     const TSize KSizeInPixels       = TSize(50,50);
  5673     const TDisplayMode KDisplayMode = EColor64K;
  5674 
  5675     CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
  5676     CleanupStack::PushL(bmp);
  5677      
  5678     const TUid KUidTestExtendedBitmap   = TUid::Uid(0xFFFFFFFF);
  5679     User::LeaveIfError(bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidTestExtendedBitmap, KTestData, KTestDataSize));
  5680      
  5681     TBitmapUtil util(bmp); // this will cause a panic
  5682      
  5683     CleanupStack::PopAndDestroy(bmp);
  5684     }
  5685 
  5686 /*
  5687  * Creates a compressed bitmap and it tries to use it with TBitmapUtil, which should cause a panic
  5688  */
  5689 LOCAL_C void DoBitmapUtilWithCompressedBitmapThreadL()
  5690     {
  5691     CFbsBitmap*  bmp = new (ELeave) CFbsBitmap;
  5692     CleanupStack::PushL(bmp);
  5693     bmp->Load(KRamBitmap);
  5694     User::LeaveIfError(bmp->Compress());
  5695     if(!bmp->IsCompressedInRAM())
  5696         {
  5697         User::Leave(KErrArgument);
  5698         }
  5699      
  5700     TBitmapUtil util(bmp); // this will cause a panic
  5701      
  5702     CleanupStack::PopAndDestroy(bmp);
  5703     }
  5704 
  5705 typedef void (*TFunctionPtr)();
  5706 
  5707 LOCAL_C TInt BitmapUtilWithUnsupportedBitmapThreadFunc(TAny* aFunctionPtr)
  5708     {
  5709     TInt ret = RFbsSession::Connect();
  5710     if(ret != KErrNone)
  5711         {
  5712         return ret;
  5713         }
  5714     
  5715     CTrapCleanup* trap = CTrapCleanup::New();
  5716     if (!trap)
  5717          {
  5718          RFbsSession::Disconnect();
  5719          return KErrNoMemory;
  5720          }
  5721     
  5722     TRAP(ret, ((TFunctionPtr)aFunctionPtr)()); // this function can leave
  5723     
  5724     delete trap;
  5725     RFbsSession::Disconnect();
  5726     
  5727     return ret;
  5728     }
  5729 /*
  5730  * Creates a thread, and the test scenario for GRAPHICS-FBSERV-0661 is run in aThreadFunction, which 
  5731  * causes a panic. Checks if the thread has been terminated with panic with correct category and panic code.
  5732  */
  5733 void CTBitmap::TestBitmapUtilWithUnsupportedBitmap(const TDesC& aThreadName, TAny* aFunctionPtr)
  5734     {
  5735     RThread thread;
  5736     TInt ret = thread.Create(aThreadName, BitmapUtilWithUnsupportedBitmapThreadFunc, KDefaultStackSize, 0x2000, 0x2000, aFunctionPtr);
  5737     TEST(ret == KErrNone);
  5738     TRequestStatus status;
  5739     thread.Logon(status);
  5740     thread.Resume();
  5741     User::WaitForRequest(status);
  5742     TExitType exitType = thread.ExitType();
  5743     TExitCategoryName exitCategory = thread.ExitCategory();
  5744     TInt exitReason = thread.ExitReason();
  5745     TEST(exitType == EExitPanic);
  5746     TEST(exitCategory == KFBSERVClientPanicCategory);
  5747     TEST(exitReason == EFbsPanicInvalidBitmapType);
  5748     thread.Close();   
  5749     }
  5750 
  5751 /**
  5752 @SYMTestCaseID          GRAPHICS-FBSERV-0661
  5753 
  5754 @SYMTestCaseDesc        Test the use of TBitmapUtil with extended and compressed bitmaps. 
  5755                         NOTE: this is a debug only test.
  5756 
  5757 @SYMTestStatus          Implemented
  5758 
  5759 @SYMTestPriority        High
  5760 
  5761 @SYMTestActions         Create extended bitmap, and TBitmapUtil to process it. 
  5762                         Create bitmap and compress it,and TBitmapUtil to process it. 
  5763 
  5764 @SYMTestExpectedResults Panic FBSCLI 29
  5765 */
  5766 void CTBitmap::TestBitmapUtilWithUnsupportedBitmaps()
  5767     {
  5768     INFO_PRINTF1(_L("Test TBitmapUtil with unsupported bitmaps"));
  5769     
  5770     // extended bitmap
  5771     TestBitmapUtilWithUnsupportedBitmap(_L("BitmapUtilWithExtentedBitmapThread"), (TAny*)&DoBitmapUtilWithExtendedBitmapThreadL);
  5772     
  5773     // compressed bitmap
  5774     TestBitmapUtilWithUnsupportedBitmap(_L("BitmapUtilWithCompressedBitmapThread"), (TAny*)&DoBitmapUtilWithCompressedBitmapThreadL);  
  5775     }
  5776 #endif //_DEBUG
  5777 
  5778 //--------------
  5779 __CONSTRUCT_STEP__(Bitmap)
  5780 
  5781 void CTBitmapStep::TestSetupL()
  5782 	{
  5783 	TheFs.Connect();
  5784 	::CopyFilesOnC();
  5785 	}
  5786 	
  5787 void CTBitmapStep::TestClose()
  5788 	{
  5789 	::DeleteFilesFromC();		//clean up data files used by this test - must be done before call to End() - DEF047652
  5790 	TheFs.Close();
  5791 	}
  5792