os/graphics/fbs/fontandbitmapserver/tfbs/TBITMAP.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent - Internal Symbian test code
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include <e32math.h>
sl@0
    23
#include <s32file.h>
sl@0
    24
#include <bautils.h>
sl@0
    25
#include <hal.h>
sl@0
    26
#include <test/tefunit.h>
sl@0
    27
#include <graphics/bitmapuid.h>
sl@0
    28
#include "../sfbs/UTILS.H"
sl@0
    29
#include "TBitmap.h"
sl@0
    30
#include "../sfbs/fbsbitmapasyncstreamer.h"
sl@0
    31
#include "fbsmessage.h"
sl@0
    32
sl@0
    33
// Symbian modification to help reduce unnecessary warnings 
sl@0
    34
#if (__ARMCC_VERSION >= 310000)
sl@0
    35
//turn off Warning:  #546-D: transfer of control bypasses initialization of variable, which is unnecessary.
sl@0
    36
#pragma diag_suppress 546
sl@0
    37
#endif
sl@0
    38
// End of Symbian modification
sl@0
    39
sl@0
    40
sl@0
    41
sl@0
    42
//
sl@0
    43
//
sl@0
    44
//Globals
sl@0
    45
//LOCAL_D RTest	TheTest(_L("Test Bitmap"));
sl@0
    46
LOCAL_D RFs		TheFs;
sl@0
    47
const TUint8	KCheckValue = 0x69;//pixel value used in the tests
sl@0
    48
sl@0
    49
_LIT(KBmpCompr12, "z:\\system\\data\\compr12.mbm");
sl@0
    50
_LIT(KBmpCompr16, "z:\\system\\data\\compr16.mbm");
sl@0
    51
_LIT(KBmpCompr24, "z:\\system\\data\\compr24.mbm");
sl@0
    52
_LIT(KBmpZCompr12, "z:\\system\\data\\racompr12.mbm");
sl@0
    53
_LIT(KBmpZCompr16, "z:\\system\\data\\racompr16.mbm");
sl@0
    54
_LIT(KBmpZCompr24, "z:\\system\\data\\racompr24.mbm");
sl@0
    55
_LIT(KBmpCCompr12, "c:\\racompr12.mbm");
sl@0
    56
_LIT(KBmpCCompr16, "c:\\racompr16.mbm");
sl@0
    57
_LIT(KBmpCCompr24, "c:\\racompr24.mbm");
sl@0
    58
sl@0
    59
_LIT(KRc_RamInRom8, "z:\\system\\data\\rc_ram8.mbm");
sl@0
    60
_LIT(KRc_RamInRom12, "z:\\system\\data\\rc_ram12.mbm");
sl@0
    61
_LIT(KRc_RamInRom16, "z:\\system\\data\\rc_ram16.mbm");
sl@0
    62
_LIT(KRc_RamInRom24, "z:\\system\\data\\rc_ram24.mbm");
sl@0
    63
sl@0
    64
_LIT(KRc_Ram8, "c:\\rc_ram8.mbm");
sl@0
    65
_LIT(KRc_Ram12, "c:\\rc_ram12.mbm");
sl@0
    66
_LIT(KRc_Ram16, "c:\\rc_ram16.mbm");
sl@0
    67
_LIT(KRc_Ram24, "c:\\rc_ram24.mbm");
sl@0
    68
sl@0
    69
_LIT(KRamBitmapOnZ, "z:\\system\\data\\16RAM2.mbm");
sl@0
    70
_LIT(KRamBitmap, "c:\\16RAM2.mbm");
sl@0
    71
_LIT(KRamBitmap2, "c:\\16RAM3.mbm");
sl@0
    72
sl@0
    73
_LIT(KMono_RamInRom_M1, "z:\\system\\data\\mono_m1.mbm");
sl@0
    74
_LIT(KMono_RamInRom_M2, "z:\\system\\data\\mono_m2.mbm");
sl@0
    75
_LIT(KMono_RamInRom_M4, "z:\\system\\data\\mono_m4.mbm");
sl@0
    76
_LIT(KMono_RamInRom_M8, "z:\\system\\data\\mono_m8.mbm");
sl@0
    77
_LIT(KMono_RamInRom_C4, "z:\\system\\data\\mono_c4.mbm");
sl@0
    78
_LIT(KMono_RamInRom_C8, "z:\\system\\data\\mono_c8.mbm");
sl@0
    79
_LIT(KMono_RamInRom_C12, "z:\\system\\data\\mono_c12.mbm");
sl@0
    80
_LIT(KMono_RamInRom_C16, "z:\\system\\data\\mono_c16.mbm");
sl@0
    81
_LIT(KMono_RamInRom_C24, "z:\\system\\data\\mono_c24.mbm");
sl@0
    82
_LIT(KMono_RamInRom_C32, "z:\\system\\data\\mono_c32.mbm");
sl@0
    83
sl@0
    84
_LIT(KMono_M1, "c:\\mono_m1.mbm");
sl@0
    85
_LIT(KMono_M2, "c:\\mono_m2.mbm");
sl@0
    86
_LIT(KMono_M4, "c:\\mono_m4.mbm");
sl@0
    87
_LIT(KMono_M8, "c:\\mono_m8.mbm");
sl@0
    88
_LIT(KMono_C4, "c:\\mono_c4.mbm");
sl@0
    89
_LIT(KMono_C8, "c:\\mono_c8.mbm");
sl@0
    90
_LIT(KMono_C12, "c:\\mono_c12.mbm");
sl@0
    91
_LIT(KMono_C16, "c:\\mono_c16.mbm");
sl@0
    92
_LIT(KMono_C24, "c:\\mono_c24.mbm");
sl@0
    93
_LIT(KMono_C32, "c:\\mono_c32.mbm");
sl@0
    94
sl@0
    95
_LIT(KRomBitmap,"z:\\system\\data\\tfbs.rbm");
sl@0
    96
sl@0
    97
//
sl@0
    98
//
sl@0
    99
//Create/Destroy test environment global functions
sl@0
   100
sl@0
   101
//Delete "aFullName" file.
sl@0
   102
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
sl@0
   103
	{
sl@0
   104
	RFs fsSession;
sl@0
   105
	TInt err = fsSession.Connect();
sl@0
   106
	if(err == KErrNone)
sl@0
   107
		{
sl@0
   108
		TEntry entry;
sl@0
   109
		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0
   110
			{
sl@0
   111
			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
sl@0
   112
			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0
   113
			if(err != KErrNone) 
sl@0
   114
				{
sl@0
   115
				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
sl@0
   116
				}
sl@0
   117
			err = fsSession.Delete(aFullName);
sl@0
   118
			if(err != KErrNone) 
sl@0
   119
				{
sl@0
   120
				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
sl@0
   121
				}
sl@0
   122
			}
sl@0
   123
		fsSession.Close();
sl@0
   124
		}
sl@0
   125
	else
sl@0
   126
		{
sl@0
   127
		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
sl@0
   128
		}
sl@0
   129
	}
sl@0
   130
sl@0
   131
//Copy test bitmaps from Z: to C: drive. RFs::Connect() had to be called already 
sl@0
   132
//on "TheFs" object.
sl@0
   133
LOCAL_C void CopyFilesOnC()
sl@0
   134
	{
sl@0
   135
	BaflUtils::CopyFile(TheFs, KTestBitmapOnZ, KTestBitmapOnC);
sl@0
   136
	BaflUtils::CopyFile(TheFs, KBmpZCompr12, KBmpCCompr12);
sl@0
   137
	BaflUtils::CopyFile(TheFs, KBmpZCompr16, KBmpCCompr16);
sl@0
   138
	BaflUtils::CopyFile(TheFs, KBmpZCompr24, KBmpCCompr24);
sl@0
   139
	BaflUtils::CopyFile(TheFs, KRc_RamInRom8, KRc_Ram8);
sl@0
   140
	BaflUtils::CopyFile(TheFs, KRc_RamInRom12, KRc_Ram12);
sl@0
   141
	BaflUtils::CopyFile(TheFs, KRc_RamInRom16, KRc_Ram16);
sl@0
   142
	BaflUtils::CopyFile(TheFs, KRc_RamInRom24, KRc_Ram24);
sl@0
   143
	BaflUtils::CopyFile(TheFs, KRamBitmapOnZ, KRamBitmap);
sl@0
   144
	BaflUtils::CopyFile(TheFs, KRamBitmapOnZ, KRamBitmap2);
sl@0
   145
	BaflUtils::CopyFile(TheFs, KMono_RamInRom_M1, KMono_M1);
sl@0
   146
	BaflUtils::CopyFile(TheFs, KMono_RamInRom_M2, KMono_M2);
sl@0
   147
	BaflUtils::CopyFile(TheFs, KMono_RamInRom_M4, KMono_M4);
sl@0
   148
	BaflUtils::CopyFile(TheFs, KMono_RamInRom_M8, KMono_M8);
sl@0
   149
	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C4, KMono_C4);
sl@0
   150
	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C8, KMono_C8);
sl@0
   151
	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C12, KMono_C12);
sl@0
   152
	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C16, KMono_C16);
sl@0
   153
	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C24, KMono_C24);
sl@0
   154
	BaflUtils::CopyFile(TheFs, KMono_RamInRom_C32, KMono_C32);
sl@0
   155
	}
sl@0
   156
sl@0
   157
//Delete data files used by the test
sl@0
   158
LOCAL_C void DeleteFilesFromC()
sl@0
   159
	{
sl@0
   160
	DeleteDataFile(KTestBitmapOnC);
sl@0
   161
	DeleteDataFile(KBmpCCompr12);
sl@0
   162
	DeleteDataFile(KBmpCCompr16);
sl@0
   163
	DeleteDataFile(KBmpCCompr24);
sl@0
   164
	DeleteDataFile(KRc_Ram8);
sl@0
   165
	DeleteDataFile(KRc_Ram12);
sl@0
   166
	DeleteDataFile(KRc_Ram16);
sl@0
   167
	DeleteDataFile(KRc_Ram24);
sl@0
   168
	DeleteDataFile(KRamBitmap);
sl@0
   169
	DeleteDataFile(KRamBitmap2);
sl@0
   170
	DeleteDataFile(KMono_M1);
sl@0
   171
	DeleteDataFile(KMono_M2);
sl@0
   172
	DeleteDataFile(KMono_M4);
sl@0
   173
	DeleteDataFile(KMono_M8);
sl@0
   174
	DeleteDataFile(KMono_C4);
sl@0
   175
	DeleteDataFile(KMono_C8);
sl@0
   176
	DeleteDataFile(KMono_C12);
sl@0
   177
	DeleteDataFile(KMono_C16);
sl@0
   178
	DeleteDataFile(KMono_C24);
sl@0
   179
	DeleteDataFile(KMono_C32);
sl@0
   180
	}
sl@0
   181
sl@0
   182
//
sl@0
   183
//
sl@0
   184
sl@0
   185
void CTBitmap::DeleteScanLineBuffer()
sl@0
   186
	{
sl@0
   187
	RFbsSession* fbs = RFbsSession::GetSession();
sl@0
   188
	delete fbs->iScanLineBuffer;
sl@0
   189
	fbs->iScanLineBuffer = NULL;
sl@0
   190
	}
sl@0
   191
sl@0
   192
CTBitmap::CTBitmap(CTestStep* aStep):
sl@0
   193
	CTGraphicsBase(aStep),
sl@0
   194
	iBmpHandler(NULL),
sl@0
   195
	iBitmap(NULL),
sl@0
   196
	iAs(NULL)
sl@0
   197
	{
sl@0
   198
	__ASSERT_DEBUG(CActiveScheduler::Current(), User::Invariant());
sl@0
   199
	CFbsBitmap bmp;
sl@0
   200
	iTestBitmapName = KTestBitmapOnZ;
sl@0
   201
	TInt ret=bmp.Load(iTestBitmapName,ETfbs,NULL);
sl@0
   202
	TEST2(ret, KErrNone);
sl@0
   203
	bmp.Reset();
sl@0
   204
sl@0
   205
	ret = iFs.Connect();
sl@0
   206
	TEST2(ret, KErrNone);
sl@0
   207
sl@0
   208
	// Expand session scanline buffer cache to avoid spurious alloc heavens later on
sl@0
   209
	const TInt bufferSize = 1024;
sl@0
   210
sl@0
   211
	ret = bmp.Create(TSize(bufferSize,1),EColor256);
sl@0
   212
	TEST2(ret, KErrNone);
sl@0
   213
sl@0
   214
	ret = bmp.Compress();
sl@0
   215
	TEST2(ret, KErrNone);
sl@0
   216
sl@0
   217
	TUint8* buffer = new TUint8[bufferSize];
sl@0
   218
	TEST(buffer != NULL);
sl@0
   219
sl@0
   220
	TPtr8 scanline(buffer,bufferSize,bufferSize);
sl@0
   221
	bmp.GetScanLine(scanline,TPoint(0,0),bufferSize,EColor256);
sl@0
   222
	delete [] buffer;
sl@0
   223
	bmp.Reset();
sl@0
   224
	
sl@0
   225
	TUint32* romAddress = NULL;
sl@0
   226
	if(!CFbsBitmap::IsFileInRom(KRomBitmap, romAddress)) //any ROM bitmap
sl@0
   227
		{
sl@0
   228
		INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."),
sl@0
   229
				&KRomBitmap);
sl@0
   230
		INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported."));
sl@0
   231
		iSkipRomBitmapTests = ETrue;
sl@0
   232
		}
sl@0
   233
	}
sl@0
   234
sl@0
   235
CTBitmap::~CTBitmap()
sl@0
   236
	{
sl@0
   237
	iFs.Close();
sl@0
   238
	}
sl@0
   239
sl@0
   240
void CTBitmap::RunTestCaseL(TInt aCurTestCase)
sl@0
   241
    {
sl@0
   242
    ((CTBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
   243
	switch(aCurTestCase)
sl@0
   244
		{
sl@0
   245
	case 1:		
sl@0
   246
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0550"));
sl@0
   247
		TwoComprLines();
sl@0
   248
		break;
sl@0
   249
	case 2:
sl@0
   250
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0517"));
sl@0
   251
	// they are fast hence at the beginning
sl@0
   252
		CheckScanlineL();
sl@0
   253
		break;
sl@0
   254
	case 3:
sl@0
   255
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0534"));
sl@0
   256
		Compress();
sl@0
   257
		break;
sl@0
   258
	case 4:
sl@0
   259
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0518"));
sl@0
   260
		StreamBitmap();
sl@0
   261
		break;
sl@0
   262
	case 5:
sl@0
   263
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0519"));
sl@0
   264
		StreamRectangle();
sl@0
   265
		break;
sl@0
   266
	case 6:
sl@0
   267
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0523"));
sl@0
   268
		LoadInSegments();
sl@0
   269
		break;
sl@0
   270
	case 7:
sl@0
   271
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0524"));
sl@0
   272
		SaveInSegments();
sl@0
   273
		break;
sl@0
   274
	case 8:
sl@0
   275
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0525"));
sl@0
   276
		MonoDetect();
sl@0
   277
		break;
sl@0
   278
	case 9:
sl@0
   279
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0526"));
sl@0
   280
		ChunkPileL();
sl@0
   281
		break;
sl@0
   282
	case 10:
sl@0
   283
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0527"));
sl@0
   284
		LargeBitmaps();
sl@0
   285
		break;
sl@0
   286
	case 12:
sl@0
   287
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0528"));
sl@0
   288
		HugeBitmaps();
sl@0
   289
		break;
sl@0
   290
	case 13:
sl@0
   291
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0529"));
sl@0
   292
		Resize();
sl@0
   293
		break;
sl@0
   294
	case 14:
sl@0
   295
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0520"));
sl@0
   296
		GetScanline();
sl@0
   297
		break;
sl@0
   298
	case 15:
sl@0
   299
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0521"));
sl@0
   300
		SetScanline();
sl@0
   301
		break;
sl@0
   302
	case 16:
sl@0
   303
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0522"));
sl@0
   304
		StretchScanline();
sl@0
   305
		break;
sl@0
   306
	case 17:
sl@0
   307
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0530"));
sl@0
   308
		BitmapUtil();
sl@0
   309
		break;
sl@0
   310
	case 18:
sl@0
   311
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0531"));
sl@0
   312
		InvalidBitmap();
sl@0
   313
		break;
sl@0
   314
	case 19:
sl@0
   315
		((CTBitmapStep*)iStep)->SetTestStepID(_L(" GRAPHICS-FBSERV-0533"));
sl@0
   316
		SaveAndLoadFast();
sl@0
   317
		break;
sl@0
   318
	case 20:
sl@0
   319
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0532"));
sl@0
   320
		SaveAndLoad();
sl@0
   321
		break;
sl@0
   322
	case 21:
sl@0
   323
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0535"));
sl@0
   324
		Color256BitmapUtil();
sl@0
   325
		break;
sl@0
   326
	case 22:
sl@0
   327
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0536"));
sl@0
   328
		HardwareBitmaps();
sl@0
   329
		break;
sl@0
   330
	case 23:
sl@0
   331
		((CTBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   332
	//	BitmapTiming(); 
sl@0
   333
		break;
sl@0
   334
	case 24:
sl@0
   335
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0537"));
sl@0
   336
		INC036062L();
sl@0
   337
		break;
sl@0
   338
	case 25:
sl@0
   339
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0538"));
sl@0
   340
		PerformanceTest_INC036062L();
sl@0
   341
		break;
sl@0
   342
	case 26:
sl@0
   343
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0539"));
sl@0
   344
		INC037474L();
sl@0
   345
		break;
sl@0
   346
	case 27:
sl@0
   347
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0540"));
sl@0
   348
		DEF038286L();
sl@0
   349
		break;
sl@0
   350
	case 28:
sl@0
   351
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0541"));
sl@0
   352
		DEF038286_2L();
sl@0
   353
		break;
sl@0
   354
	case 29:
sl@0
   355
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0542"));
sl@0
   356
		MonohromeL();
sl@0
   357
		break;
sl@0
   358
	case 30:
sl@0
   359
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0543"));
sl@0
   360
		GetVerticalScanLineL();
sl@0
   361
		break;
sl@0
   362
	case 31:
sl@0
   363
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0544"));
sl@0
   364
		GetVerticalScanLinePerformanceL();
sl@0
   365
		break;
sl@0
   366
	case 32:
sl@0
   367
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0545"));
sl@0
   368
		DEF071843_16MAL();
sl@0
   369
		((CTBitmapStep*)iStep)->RecordTestResultL();
sl@0
   370
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0546"));	
sl@0
   371
		DEF071843_16MUL();
sl@0
   372
		((CTBitmapStep*)iStep)->RecordTestResultL();
sl@0
   373
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0547"));
sl@0
   374
		DEF071843_16ML();
sl@0
   375
#ifdef _DEBUG
sl@0
   376
		((CTBitmapStep*)iStep)->RecordTestResultL();
sl@0
   377
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0549"));
sl@0
   378
		//It uses Heap Allocation failure macro 
sl@0
   379
		//which is supported only for debug mode	
sl@0
   380
		DEF095361_16MAL();
sl@0
   381
#endif		
sl@0
   382
		break;
sl@0
   383
	case 33:
sl@0
   384
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0548"));
sl@0
   385
		DEF074623_16MAL();
sl@0
   386
		break;
sl@0
   387
	case 34:
sl@0
   388
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0551"));
sl@0
   389
		TestPaletteCompressionL();
sl@0
   390
		break;
sl@0
   391
	case 35:
sl@0
   392
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0552"));
sl@0
   393
		TestSynchronousBackgroundPaletteCompressionL();
sl@0
   394
		break;
sl@0
   395
	case 36:
sl@0
   396
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0553"));
sl@0
   397
		TestAsynchronousBackgroundPaletteCompressionL();
sl@0
   398
		break;
sl@0
   399
	case 37:
sl@0
   400
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0501"));
sl@0
   401
		GetAllBitmapsIdsL();
sl@0
   402
		break;
sl@0
   403
	case 38:
sl@0
   404
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0554"));
sl@0
   405
		CheckBadBmp();
sl@0
   406
		break; 
sl@0
   407
	case 39:
sl@0
   408
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0516"));
sl@0
   409
		CheckSetDisplayModeL();
sl@0
   410
		break; 	
sl@0
   411
	case 40:
sl@0
   412
/**
sl@0
   413
	@SYMTestCaseID GRAPHICS-FBSERV-0619
sl@0
   414
*/
sl@0
   415
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0619"));
sl@0
   416
		MultiThreadedTestsL();
sl@0
   417
		break;
sl@0
   418
	case 41:
sl@0
   419
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0612"));
sl@0
   420
		TestBgCompressL();
sl@0
   421
		break;
sl@0
   422
	case 42:
sl@0
   423
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0613"));
sl@0
   424
		TestBgCompressInUseL();
sl@0
   425
		break;
sl@0
   426
	case 43:
sl@0
   427
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0614"));
sl@0
   428
		TestDisconnectWithBitmapL();
sl@0
   429
		break;
sl@0
   430
	case 44:
sl@0
   431
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0617"));
sl@0
   432
		TestTouchedAndVolatileL();
sl@0
   433
		break;
sl@0
   434
	case 45:
sl@0
   435
		((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0618"));
sl@0
   436
		TestBitmapWhiteFillL();
sl@0
   437
		break;
sl@0
   438
	case 46:
sl@0
   439
#ifdef _DEBUG
sl@0
   440
	    ((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0661"));
sl@0
   441
	    TestBitmapUtilWithUnsupportedBitmaps();
sl@0
   442
#endif
sl@0
   443
        break;
sl@0
   444
	case 47:
sl@0
   445
		((CTBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   446
		((CTBitmapStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   447
		TestComplete();
sl@0
   448
		break;
sl@0
   449
	default:
sl@0
   450
		((CTBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   451
		break;
sl@0
   452
		}
sl@0
   453
		
sl@0
   454
	((CTBitmapStep*)iStep)->RecordTestResultL();
sl@0
   455
    }
sl@0
   456
   
sl@0
   457
/**
sl@0
   458
	@SYMTestCaseID
sl@0
   459
	GRAPHICS-FBSERV-0516
sl@0
   460
sl@0
   461
	@SYMTestCaseDesc
sl@0
   462
	Checks that the display mode can be set 
sl@0
   463
	to various modes, including EColor16MAP
sl@0
   464
	
sl@0
   465
	@SYMTestActions
sl@0
   466
	
sl@0
   467
	@SYMTestExpectedResults
sl@0
   468
	Test should pass
sl@0
   469
*/  
sl@0
   470
void CTBitmap::CheckSetDisplayModeL()
sl@0
   471
	{
sl@0
   472
	INFO_PRINTF1(_L("Check SetDisplayMode EColor16MAP"));
sl@0
   473
sl@0
   474
	CFbsBitmap bmp;
sl@0
   475
	User::LeaveIfError(bmp.Create(TSize(4,4),EColor16MA));
sl@0
   476
	TInt ret=bmp.SetDisplayMode(EColor16MAP);
sl@0
   477
	TEST(ret==KErrNone);
sl@0
   478
	bmp.Reset();
sl@0
   479
sl@0
   480
	User::LeaveIfError(bmp.Create(TSize(4,4),EColor16MU));
sl@0
   481
	ret=bmp.SetDisplayMode(EColor16MAP);
sl@0
   482
	TEST(ret==KErrNone);
sl@0
   483
	bmp.Reset();
sl@0
   484
sl@0
   485
	User::LeaveIfError(bmp.Create(TSize(4,4),EColor64K));
sl@0
   486
	ret=bmp.SetDisplayMode(EColor16MAP);
sl@0
   487
	TEST(ret==KErrArgument);
sl@0
   488
	bmp.Reset();
sl@0
   489
sl@0
   490
	User::LeaveIfError(bmp.Create(TSize(4,4),EColor16MAP));
sl@0
   491
	ret=bmp.SetDisplayMode(EColor16MAP);
sl@0
   492
	TEST(ret==KErrNone);
sl@0
   493
sl@0
   494
	ret=bmp.SetDisplayMode(EColor16MU);
sl@0
   495
	TEST(ret==KErrNone);
sl@0
   496
	bmp.Reset();
sl@0
   497
	
sl@0
   498
	}    
sl@0
   499
sl@0
   500
/**
sl@0
   501
	@SYMTestCaseID
sl@0
   502
	GRAPHICS-FBSERV-0517
sl@0
   503
sl@0
   504
	@SYMTestCaseDesc
sl@0
   505
	Compares a pixel retrieved with GetPixel and GetScanLine
sl@0
   506
sl@0
   507
	@SYMTestActions
sl@0
   508
	Zero fills a buffer which has an uneven length of bytes and
sl@0
   509
	gets a pixel from a point which should coincide with
sl@0
   510
	that of a point retrieved with scan line
sl@0
   511
		
sl@0
   512
	@SYMTestExpectedResults
sl@0
   513
	Test should pass
sl@0
   514
*/
sl@0
   515
void CTBitmap::CheckScanlineL()
sl@0
   516
	{
sl@0
   517
	INFO_PRINTF1(_L("Scanline sanity check"));
sl@0
   518
sl@0
   519
	CFbsBitmap bmp;
sl@0
   520
	User::LeaveIfError(bmp.Create(TSize(32,1),EGray2));
sl@0
   521
sl@0
   522
	// try using a buffer that isn't a whole number of words long. 
sl@0
   523
	TUint8 buffer[3];
sl@0
   524
	Mem::FillZ(buffer,3);
sl@0
   525
	TPtr8 scanline(buffer,3,3);
sl@0
   526
	bmp.GetScanLine(scanline,TPoint(0,0),24,EGray2);
sl@0
   527
sl@0
   528
	TRgb pixel(KRgbRed);
sl@0
   529
	bmp.GetPixel(pixel,TPoint(0,0));
sl@0
   530
sl@0
   531
	// getscanline and getpixel should agree
sl@0
   532
	TEST(TRgb::Gray2(buffer[0] & 0x01) == pixel);
sl@0
   533
sl@0
   534
	bmp.Reset();
sl@0
   535
sl@0
   536
	
sl@0
   537
	}
sl@0
   538
sl@0
   539
/**
sl@0
   540
	@SYMTestCaseID
sl@0
   541
	GRAPHICS-FBSERV-0518
sl@0
   542
sl@0
   543
	@SYMTestCaseDesc
sl@0
   544
	Streams different bitmap size of different colour depth.
sl@0
   545
sl@0
   546
	@SYMTestActions
sl@0
   547
sl@0
   548
	
sl@0
   549
	@SYMTestExpectedResults
sl@0
   550
	Test should pass
sl@0
   551
*/
sl@0
   552
void CTBitmap::StreamBitmap()
sl@0
   553
	{
sl@0
   554
	INFO_PRINTF1(_L("Test Bitmap Streaming"));
sl@0
   555
sl@0
   556
	DoStreamBitmapSizes(EGray2);
sl@0
   557
	DoStreamBitmapSizes(EGray4);
sl@0
   558
	DoStreamBitmapSizes(EGray16);
sl@0
   559
	DoStreamBitmapSizes(EGray256);
sl@0
   560
	DoStreamBitmapSizes(EColor16);
sl@0
   561
	DoStreamBitmapSizes(EColor256);
sl@0
   562
	DoStreamBitmapSizes(EColor4K);
sl@0
   563
	DoStreamBitmapSizes(EColor64K);
sl@0
   564
	DoStreamBitmapSizes(EColor16M);
sl@0
   565
	DoStreamBitmapSizes(EColor16MU);
sl@0
   566
	DoStreamBitmapSizes(EColor16MAP);
sl@0
   567
	}
sl@0
   568
sl@0
   569
void CTBitmap::DoStreamBitmapSizes(TDisplayMode aDispMode)
sl@0
   570
	{
sl@0
   571
	const TSize smallStreamBitmapSize(32,10);
sl@0
   572
	const TSize largeStreamBitmapSize(256,256);
sl@0
   573
	const TSize oddStreamBitmapSize(31,2);
sl@0
   574
sl@0
   575
	DoStreamBitmap(smallStreamBitmapSize,aDispMode,ETrue);
sl@0
   576
	DoStreamBitmap(smallStreamBitmapSize,aDispMode,EFalse);
sl@0
   577
	DoStreamBitmap(largeStreamBitmapSize,aDispMode,ETrue);
sl@0
   578
	DoStreamBitmap(largeStreamBitmapSize,aDispMode,EFalse);
sl@0
   579
	DoStreamBitmap(oddStreamBitmapSize,aDispMode,ETrue);
sl@0
   580
	DoStreamBitmap(oddStreamBitmapSize,aDispMode,EFalse);
sl@0
   581
	}
sl@0
   582
sl@0
   583
void CTBitmap::DoStreamBitmap(const TSize& aSize,TDisplayMode aDispMode,TBool aBlank)
sl@0
   584
	{
sl@0
   585
	__UHEAP_MARK;
sl@0
   586
sl@0
   587
	CFbsBitmapEx bmp;
sl@0
   588
	TInt ret = bmp.Create(aSize,aDispMode);
sl@0
   589
	TEST2(ret, KErrNone);
sl@0
   590
sl@0
   591
	if (aBlank)
sl@0
   592
		BlankBitmap(bmp);
sl@0
   593
	else
sl@0
   594
		FillBitmap(bmp);
sl@0
   595
sl@0
   596
	CDirectFileStore* writestore=NULL;
sl@0
   597
sl@0
   598
	TRAP(ret,writestore=CDirectFileStore::ReplaceL(iFs,KTempFilename,EFileStream|EFileWrite));
sl@0
   599
	TEST2(ret, KErrNone);
sl@0
   600
sl@0
   601
	TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
sl@0
   602
sl@0
   603
	TRAP(ret,writestore->SetTypeL(uidtype));
sl@0
   604
	TEST2(ret, KErrNone);
sl@0
   605
sl@0
   606
	RStoreWriteStream writestrm;
sl@0
   607
	TStreamId headerid(0);
sl@0
   608
sl@0
   609
	TRAP(ret,headerid=writestrm.CreateL(*writestore));
sl@0
   610
	TEST2(ret, KErrNone);
sl@0
   611
sl@0
   612
	TRAP(ret,writestore->SetRootL(headerid));
sl@0
   613
	TEST2(ret, KErrNone);
sl@0
   614
sl@0
   615
	TRAP(ret,bmp.ExternalizeL(writestrm));
sl@0
   616
	TEST2(ret, KErrNone);
sl@0
   617
sl@0
   618
	writestrm.Close();
sl@0
   619
	delete writestore;
sl@0
   620
sl@0
   621
	CFbsBitmapEx bmpst;
sl@0
   622
	CDirectFileStore* readstore=NULL;
sl@0
   623
sl@0
   624
	TRAP(ret,readstore=CDirectFileStore::OpenL(iFs,KTempFilename,EFileStream|EFileRead));
sl@0
   625
	TEST2(ret, KErrNone);
sl@0
   626
sl@0
   627
	RStoreReadStream readstrm;
sl@0
   628
	headerid=readstore->Root();
sl@0
   629
sl@0
   630
	TRAP(ret,readstrm.OpenL(*readstore,headerid));
sl@0
   631
	TEST2(ret, KErrNone);
sl@0
   632
sl@0
   633
	TRAP(ret,bmpst.InternalizeL(readstrm));
sl@0
   634
	TEST2(ret, KErrNone);
sl@0
   635
sl@0
   636
	readstrm.Close();
sl@0
   637
	delete readstore;
sl@0
   638
sl@0
   639
	CompareBitmaps(bmp,bmpst,EColor16M);
sl@0
   640
sl@0
   641
	iFs.Delete(KTempFilename);
sl@0
   642
	bmp.Reset();
sl@0
   643
	bmpst.Reset();
sl@0
   644
	User::Heap().Check();
sl@0
   645
	__UHEAP_MARKEND;
sl@0
   646
	}
sl@0
   647
sl@0
   648
/**
sl@0
   649
	@SYMTestCaseID
sl@0
   650
	GRAPHICS-FBSERV-0519
sl@0
   651
sl@0
   652
	@SYMTestCaseDesc
sl@0
   653
	Streams bitmap rectangles of different colour depth
sl@0
   654
	to file store and reads them back again.
sl@0
   655
sl@0
   656
	@SYMTestActions
sl@0
   657
	Bitmap rectangles are externalized to file store and
sl@0
   658
	read back again. ScanLine is used and compared to GetPixel
sl@0
   659
	from the bitmap read back from file store.
sl@0
   660
	
sl@0
   661
	@SYMTestExpectedResults
sl@0
   662
	Test should pass
sl@0
   663
*/
sl@0
   664
void CTBitmap::StreamRectangle()
sl@0
   665
	{
sl@0
   666
	INFO_PRINTF1(_L("Test Rectangle Streaming"));
sl@0
   667
sl@0
   668
	DoStreamRectangle(EGray2,ETrue);
sl@0
   669
	DoStreamRectangle(EGray2,EFalse);
sl@0
   670
	DoStreamRectangle(EGray4,ETrue);
sl@0
   671
	DoStreamRectangle(EGray4,EFalse);
sl@0
   672
	DoStreamRectangle(EGray16,ETrue);
sl@0
   673
	DoStreamRectangle(EGray16,EFalse);
sl@0
   674
	DoStreamRectangle(EGray256,ETrue);
sl@0
   675
	DoStreamRectangle(EGray256,EFalse);
sl@0
   676
	DoStreamRectangle(EColor16,ETrue);
sl@0
   677
	DoStreamRectangle(EColor16,EFalse);
sl@0
   678
	DoStreamRectangle(EColor256,ETrue);
sl@0
   679
	DoStreamRectangle(EColor256,EFalse);
sl@0
   680
	DoStreamRectangle(EColor4K,ETrue);
sl@0
   681
	DoStreamRectangle(EColor4K,EFalse);
sl@0
   682
	DoStreamRectangle(EColor64K,ETrue);
sl@0
   683
	DoStreamRectangle(EColor64K,EFalse);
sl@0
   684
	DoStreamRectangle(EColor16M,ETrue);
sl@0
   685
	DoStreamRectangle(EColor16M,EFalse);
sl@0
   686
	DoStreamRectangle(EColor16MU,ETrue);
sl@0
   687
	DoStreamRectangle(EColor16MU,EFalse);
sl@0
   688
	DoStreamRectangle(EColor16MAP,ETrue);
sl@0
   689
	DoStreamRectangle(EColor16MAP,EFalse);
sl@0
   690
	}
sl@0
   691
sl@0
   692
void CTBitmap::DoStreamRectangle(TDisplayMode aDispMode,TBool aBlank)
sl@0
   693
	{
sl@0
   694
	__UHEAP_MARK;
sl@0
   695
	CFbsBitmapEx bmp;
sl@0
   696
	TInt ret = bmp.Create(TSize(160,80),aDispMode);
sl@0
   697
	TEST2(ret, KErrNone);
sl@0
   698
sl@0
   699
	if (aBlank)
sl@0
   700
		BlankBitmap(bmp);
sl@0
   701
	else
sl@0
   702
		FillBitmap(bmp);
sl@0
   703
sl@0
   704
	CDirectFileStore* writestore=NULL;
sl@0
   705
	TRAP(ret,writestore=CDirectFileStore::ReplaceL(iFs,KTempFilename,EFileStream|EFileWrite));
sl@0
   706
	TEST2(ret, KErrNone);
sl@0
   707
sl@0
   708
	TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
sl@0
   709
	TRAP(ret,writestore->SetTypeL(uidtype));
sl@0
   710
	TEST2(ret, KErrNone);
sl@0
   711
sl@0
   712
	RStoreWriteStream writestrm;
sl@0
   713
	TStreamId headerid(0);
sl@0
   714
	TRAP(ret,headerid=writestrm.CreateL(*writestore));
sl@0
   715
	TEST2(ret, KErrNone);
sl@0
   716
sl@0
   717
	TRAP(ret,writestore->SetRootL(headerid));
sl@0
   718
	TEST2(ret, KErrNone);
sl@0
   719
sl@0
   720
	TRAP(ret,bmp.ExternalizeRectangleL(writestrm,TRect(40,20,120,60)));
sl@0
   721
	TEST2(ret, KErrNone);
sl@0
   722
sl@0
   723
	writestrm.Close();
sl@0
   724
	delete writestore;
sl@0
   725
sl@0
   726
	CFbsBitmapEx bmpst;
sl@0
   727
	CDirectFileStore* readstore=NULL;
sl@0
   728
	TRAP(ret,readstore=CDirectFileStore::OpenL(iFs,KTempFilename,EFileStream|EFileRead));
sl@0
   729
	TEST2(ret, KErrNone);
sl@0
   730
sl@0
   731
	RStoreReadStream readstrm;
sl@0
   732
	headerid=readstore->Root();
sl@0
   733
	TRAP(ret,readstrm.OpenL(*readstore,headerid));
sl@0
   734
	TEST2(ret, KErrNone);
sl@0
   735
sl@0
   736
	TRAP(ret,bmpst.InternalizeL(readstrm));
sl@0
   737
	TEST2(ret, KErrNone);
sl@0
   738
sl@0
   739
	readstrm.Close();
sl@0
   740
	delete readstore;
sl@0
   741
sl@0
   742
	TInt scanLineLength = CFbsBitmap::ScanLineLength(80,aDispMode);
sl@0
   743
	TUint8* buffer = new TUint8[scanLineLength];
sl@0
   744
	TUint8* bufferst = new TUint8[scanLineLength];
sl@0
   745
	Mem::FillZ(buffer,scanLineLength);
sl@0
   746
	Mem::FillZ(bufferst,scanLineLength);
sl@0
   747
	TPtr8 scanline(buffer,scanLineLength,scanLineLength);
sl@0
   748
	TPtr8 scanlinest(bufferst,scanLineLength,scanLineLength);
sl@0
   749
sl@0
   750
	for(TInt yy=0;yy<40;yy++)
sl@0
   751
		{
sl@0
   752
		bmp.GetScanLine(scanline,TPoint(40,yy+20),80,aDispMode);
sl@0
   753
		bmpst.GetScanLine(scanlinest,TPoint(0,yy),80,aDispMode);
sl@0
   754
		
sl@0
   755
		if(aDispMode != EColor16MU)
sl@0
   756
			{
sl@0
   757
			TInt memRet = Mem::Compare(buffer,scanLineLength,bufferst,scanLineLength);
sl@0
   758
			TEST(memRet == 0);
sl@0
   759
			}
sl@0
   760
		else
sl@0
   761
			{
sl@0
   762
			TInt pixelsToCompare = scanLineLength / 4;
sl@0
   763
			TUint8* bufferCur = buffer;
sl@0
   764
			TUint8* bufferstCur = bufferst;
sl@0
   765
			
sl@0
   766
			//top byte is unused, and would be more accurate to ignore it
sl@0
   767
			for(TInt ii = 0; ii < pixelsToCompare; ii++)
sl@0
   768
				{
sl@0
   769
				TInt memRet = Mem::Compare(bufferCur,3,bufferstCur,3);
sl@0
   770
				TEST(memRet == 0);
sl@0
   771
				bufferCur += 4;
sl@0
   772
				bufferstCur += 4;
sl@0
   773
				}
sl@0
   774
			}	
sl@0
   775
		}
sl@0
   776
	delete [] bufferst;
sl@0
   777
	delete [] buffer;
sl@0
   778
sl@0
   779
	iFs.Delete(KTempFilename);
sl@0
   780
	bmp.Reset();
sl@0
   781
	bmpst.Reset();
sl@0
   782
	User::Heap().Check();
sl@0
   783
	__UHEAP_MARKEND;
sl@0
   784
	}
sl@0
   785
sl@0
   786
/**
sl@0
   787
	@SYMTestCaseID
sl@0
   788
	GRAPHICS-FBSERV-0520
sl@0
   789
sl@0
   790
	@SYMTestCaseDesc
sl@0
   791
	Calls GetScanLine for different screen modes with
sl@0
   792
	the bitmap compressed and uncompressed and checks
sl@0
   793
	if the pixels are correct.
sl@0
   794
sl@0
   795
	@SYMTestActions
sl@0
   796
sl@0
   797
	@SYMTestExpectedResults
sl@0
   798
	Test should pass
sl@0
   799
*/
sl@0
   800
void CTBitmap::GetScanline()
sl@0
   801
	{
sl@0
   802
	INFO_PRINTF1(_L("Test GetScanline"));
sl@0
   803
sl@0
   804
	const TSize size1(257,5);
sl@0
   805
	const TSize size2(33,17);
sl@0
   806
sl@0
   807
	INFO_PRINTF1(_L("EGray2"));
sl@0
   808
	DoGetScanline(size1,EGray2);
sl@0
   809
	DoGetScanline(size2,EGray2);
sl@0
   810
	DoGetScanlineAlt(EGray2);
sl@0
   811
sl@0
   812
	INFO_PRINTF1(_L(" EGray4"));
sl@0
   813
	DoGetScanline(size1,EGray4);
sl@0
   814
	DoGetScanline(size2,EGray4);
sl@0
   815
	DoGetScanlineAlt(EGray4);
sl@0
   816
sl@0
   817
	INFO_PRINTF1(_L(" EGray16"));
sl@0
   818
	DoGetScanline(size1,EGray16);
sl@0
   819
	DoGetScanline(size2,EGray16);
sl@0
   820
	DoGetScanlineAlt(EGray16);
sl@0
   821
sl@0
   822
	INFO_PRINTF1(_L(" EGray256"));
sl@0
   823
	DoGetScanline(size1,EGray256);
sl@0
   824
	DoGetScanline(size2,EGray256);
sl@0
   825
	DoGetScanlineAlt(EGray256);
sl@0
   826
sl@0
   827
	INFO_PRINTF1(_L(" EColor16"));
sl@0
   828
	DoGetScanline(size1,EColor16);
sl@0
   829
	DoGetScanline(size2,EColor16);
sl@0
   830
	DoGetScanlineAlt(EColor16);
sl@0
   831
sl@0
   832
	INFO_PRINTF1(_L(" EColor256"));
sl@0
   833
	DoGetScanline(size1,EColor256);
sl@0
   834
	DoGetScanline(size2,EColor256);
sl@0
   835
	DoGetScanlineAlt(EColor256);
sl@0
   836
sl@0
   837
	INFO_PRINTF1(_L(" EColor4K"));
sl@0
   838
	DoGetScanline(size1,EColor4K);
sl@0
   839
	DoGetScanline(size2,EColor4K);
sl@0
   840
	DoGetScanlineAlt(EColor4K);
sl@0
   841
sl@0
   842
	INFO_PRINTF1(_L(" EColor64K"));
sl@0
   843
	DoGetScanline(size1,EColor64K);
sl@0
   844
	DoGetScanline(size2,EColor64K);
sl@0
   845
	DoGetScanlineAlt(EColor64K);
sl@0
   846
sl@0
   847
	INFO_PRINTF1(_L(" EColor16M"));
sl@0
   848
	DoGetScanline(size1,EColor16M);
sl@0
   849
	DoGetScanline(size2,EColor16M);
sl@0
   850
	DoGetScanlineAlt(EColor16M);
sl@0
   851
sl@0
   852
	INFO_PRINTF1(_L(" EColor16MA"));
sl@0
   853
	DoGetScanline(size1,EColor16MA);
sl@0
   854
	DoGetScanline(size2,EColor16MA);
sl@0
   855
	DoGetScanlineAlt(EColor16MA);
sl@0
   856
sl@0
   857
	INFO_PRINTF1(_L(" EColor16MU"));
sl@0
   858
	DoGetScanline(size1,EColor16MU);
sl@0
   859
	DoGetScanline(size2,EColor16MU);
sl@0
   860
	DoGetScanlineAlt(EColor16MU);
sl@0
   861
sl@0
   862
	INFO_PRINTF1(_L(" EColor16MAP"));
sl@0
   863
	DoGetScanline(size1,EColor16MAP);
sl@0
   864
	DoGetScanline(size2,EColor16MAP);
sl@0
   865
	DoGetScanlineAlt(EColor16MAP);
sl@0
   866
sl@0
   867
	INFO_PRINTF1(_L("\n"));
sl@0
   868
	}
sl@0
   869
sl@0
   870
void CTBitmap::DoGetScanline(const TSize& aSize,TDisplayMode aDispMode)
sl@0
   871
	{
sl@0
   872
	__UHEAP_MARK;
sl@0
   873
	CFbsBitmapEx bmp;
sl@0
   874
	TInt ret = bmp.Create(aSize,aDispMode);
sl@0
   875
	TEST2(ret, KErrNone);
sl@0
   876
	FillBitmap(bmp);
sl@0
   877
sl@0
   878
	DoGetScanlineCheck1(bmp, bmp, aSize, aDispMode);
sl@0
   879
	DoGetScanlineCheck2(bmp, bmp, aSize, aDispMode);
sl@0
   880
	DoGetScanlineCheck3(bmp, aDispMode);
sl@0
   881
sl@0
   882
	ret = bmp.Create(aSize,aDispMode);
sl@0
   883
	TEST2(ret, KErrNone);
sl@0
   884
sl@0
   885
	StripeBitmap(bmp);
sl@0
   886
	CFbsBitmapEx ref;
sl@0
   887
	ret = ref.Create(aSize,aDispMode);
sl@0
   888
	TEST2(ret, KErrNone);
sl@0
   889
sl@0
   890
	CopyBitmap(ref, bmp);
sl@0
   891
	ret = bmp.Compress();
sl@0
   892
	TEST2(ret, KErrNone);
sl@0
   893
sl@0
   894
	DoGetScanlineCheck1(bmp, ref, aSize, aDispMode);
sl@0
   895
sl@0
   896
	ref.Reset();
sl@0
   897
	bmp.Reset();
sl@0
   898
	User::Heap().Check();
sl@0
   899
	__UHEAP_MARKEND;
sl@0
   900
	}
sl@0
   901
sl@0
   902
void CTBitmap::DoGetScanlineCheck1(CFbsBitmap& aBitmap,CFbsBitmap& aReference,const TSize& aSize,TDisplayMode aDispMode)
sl@0
   903
	{
sl@0
   904
	TInt byteWidth = CFbsBitmap::ScanLineLength(aSize.iWidth,aDispMode);
sl@0
   905
	TUint8* buffer = new TUint8[byteWidth + 1];
sl@0
   906
	buffer[byteWidth] = KCheckValue;
sl@0
   907
	TPtr8 scanline(buffer,byteWidth,byteWidth);
sl@0
   908
sl@0
   909
	for(TInt xStart = 0; xStart <= 33; xStart++)
sl@0
   910
		{
sl@0
   911
		for (TInt xLength = 1; xLength <= 33; xLength++)
sl@0
   912
			{
sl@0
   913
			TInt xEnd = xStart + xLength;
sl@0
   914
			if (xEnd <= aSize.iWidth)
sl@0
   915
				{
sl@0
   916
				aBitmap.GetScanLine(scanline,TPoint(xStart,0),xLength,aDispMode);
sl@0
   917
				for(TInt xx = xStart; xx < xEnd; xx++)
sl@0
   918
					{
sl@0
   919
					TRgb color;
sl@0
   920
					aReference.GetPixel(color,TPoint(xx,0));
sl@0
   921
					TRgb bufferColor = ExtractRgb(buffer,xx - xStart,aDispMode);
sl@0
   922
					TEST(bufferColor == color);
sl@0
   923
					}
sl@0
   924
				}
sl@0
   925
			}
sl@0
   926
		}
sl@0
   927
sl@0
   928
	for(TInt yy = 0; yy < aSize.iHeight; yy++)
sl@0
   929
		{
sl@0
   930
		aBitmap.GetScanLine(scanline,TPoint(0,yy),aSize.iWidth,aDispMode);
sl@0
   931
		for(TInt xx = 0; xx < aSize.iWidth; xx++)
sl@0
   932
			{
sl@0
   933
			TRgb color;
sl@0
   934
			aReference.GetPixel(color,TPoint(xx,yy));
sl@0
   935
			TRgb bufferColor = ExtractRgb(buffer,xx,aDispMode);
sl@0
   936
			TEST(bufferColor == color);
sl@0
   937
			}
sl@0
   938
		}
sl@0
   939
sl@0
   940
	TEST(buffer[byteWidth] == KCheckValue);
sl@0
   941
	delete [] buffer;
sl@0
   942
	}
sl@0
   943
sl@0
   944
void CTBitmap::DoGetScanlineCheck2(CFbsBitmap& aBitmap,CFbsBitmap& aReference,const TSize& aSize,TDisplayMode aDispMode)
sl@0
   945
	{
sl@0
   946
	TInt byteHeight = CFbsBitmap::ScanLineLength(aSize.iHeight,ERgb);
sl@0
   947
	TUint8* buffer = new TUint8[byteHeight];
sl@0
   948
	TPtr8 scanline(buffer,byteHeight,byteHeight);
sl@0
   949
sl@0
   950
	TInt xx;
sl@0
   951
	for(xx = 0; xx < aSize.iWidth; xx++)
sl@0
   952
		{
sl@0
   953
		aBitmap.GetVerticalScanLine(scanline,xx,aDispMode);
sl@0
   954
		for(TInt yy = 0; yy < aSize.iHeight; yy++)
sl@0
   955
			{
sl@0
   956
			TRgb color;
sl@0
   957
			aReference.GetPixel(color,TPoint(xx,yy));
sl@0
   958
			TRgb bufferColor = ExtractRgb(buffer,yy,aDispMode);
sl@0
   959
			TEST(bufferColor == color);
sl@0
   960
			}
sl@0
   961
		}
sl@0
   962
sl@0
   963
	for(xx = 0; xx < aSize.iWidth; xx++)
sl@0
   964
		{
sl@0
   965
		aBitmap.GetVerticalScanLine(scanline,xx,ERgb);
sl@0
   966
		for(TInt yy = 0; yy < aSize.iHeight; yy++)
sl@0
   967
			{
sl@0
   968
			TRgb color;
sl@0
   969
			aReference.GetPixel(color,TPoint(xx,yy));
sl@0
   970
			TRgb bufferColor = ExtractRgb(buffer,yy,ERgb);
sl@0
   971
			TEST(bufferColor == color);
sl@0
   972
			}
sl@0
   973
		}
sl@0
   974
sl@0
   975
	delete [] buffer;
sl@0
   976
	}
sl@0
   977
sl@0
   978
void CTBitmap::DoGetScanlineCheck3(CFbsBitmap& aBitmap,TDisplayMode aDispMode)
sl@0
   979
	{
sl@0
   980
	TUint32 wordline=0xffffffff;
sl@0
   981
	TPtr8 scanline((TUint8*)&wordline,4,4);
sl@0
   982
	aBitmap.Create(TSize(31,1),aDispMode);
sl@0
   983
	aBitmap.LockHeap();
sl@0
   984
	Mem::Fill(aBitmap.DataAddress(),CFbsBitmap::ScanLineLength(31,aDispMode),0xff);
sl@0
   985
	aBitmap.UnlockHeap();
sl@0
   986
	aBitmap.SetScanLine(scanline,0);
sl@0
   987
	TUint32 expected=0;
sl@0
   988
sl@0
   989
	for(TInt zz=1;zz<31;zz++)
sl@0
   990
		{
sl@0
   991
		expected|=1<<(zz-1);
sl@0
   992
		wordline=0;
sl@0
   993
		aBitmap.GetScanLine(scanline,TPoint(0,0),zz,EGray2);
sl@0
   994
		TUint32 actual=wordline&expected;
sl@0
   995
		TEST(actual==expected);
sl@0
   996
		}
sl@0
   997
	}
sl@0
   998
sl@0
   999
/* this function calls CheckScanLine with various screen modes, and with the bitmap
sl@0
  1000
   compressed, and not compressed
sl@0
  1001
 */
sl@0
  1002
void CTBitmap::DoGetScanlineAlt(TDisplayMode aDispMode)
sl@0
  1003
	{
sl@0
  1004
	__UHEAP_MARK;
sl@0
  1005
sl@0
  1006
	CFbsBitmapEx bmp;
sl@0
  1007
	TInt ret = bmp.Create(TSize(256,3),aDispMode);
sl@0
  1008
	TEST2(ret, KErrNone);
sl@0
  1009
sl@0
  1010
	FillBitmap(bmp);
sl@0
  1011
sl@0
  1012
	CheckScanLine(bmp,bmp,EGray2);
sl@0
  1013
	CheckScanLine(bmp,bmp,EGray4);
sl@0
  1014
	CheckScanLine(bmp,bmp,EGray16);
sl@0
  1015
	CheckScanLine(bmp,bmp,EGray256);
sl@0
  1016
	CheckScanLine(bmp,bmp,EColor16);
sl@0
  1017
	CheckScanLine(bmp,bmp,EColor256);
sl@0
  1018
	CheckScanLine(bmp,bmp,EColor4K);
sl@0
  1019
	CheckScanLine(bmp,bmp,EColor64K);
sl@0
  1020
	CheckScanLine(bmp,bmp,EColor16M);
sl@0
  1021
	CheckScanLine(bmp,bmp,ERgb);
sl@0
  1022
	CheckScanLine(bmp,bmp,EColor16MU);
sl@0
  1023
	CheckScanLine(bmp,bmp,EColor16MAP);
sl@0
  1024
sl@0
  1025
	CFbsBitmapEx ref;
sl@0
  1026
	ret = ref.Create(bmp.SizeInPixels(),aDispMode);
sl@0
  1027
	TEST2(ret, KErrNone);
sl@0
  1028
	CopyBitmap(ref,bmp);
sl@0
  1029
	bmp.Compress();
sl@0
  1030
sl@0
  1031
	CheckScanLine(bmp,ref,EGray2);
sl@0
  1032
	CheckScanLine(bmp,ref,EGray4);
sl@0
  1033
	CheckScanLine(bmp,ref,EGray16);
sl@0
  1034
	CheckScanLine(bmp,ref,EGray256);
sl@0
  1035
	CheckScanLine(bmp,ref,EColor16);
sl@0
  1036
	CheckScanLine(bmp,ref,EColor256);
sl@0
  1037
	CheckScanLine(bmp,ref,EColor4K);
sl@0
  1038
	CheckScanLine(bmp,ref,EColor64K);
sl@0
  1039
	CheckScanLine(bmp,ref,EColor16M);
sl@0
  1040
	CheckScanLine(bmp,ref,ERgb);
sl@0
  1041
	CheckScanLine(bmp,ref,EColor16MU);
sl@0
  1042
	CheckScanLine(bmp,ref,EColor16MAP);
sl@0
  1043
sl@0
  1044
	User::Heap().Check();
sl@0
  1045
	__UHEAP_MARKEND;
sl@0
  1046
	}
sl@0
  1047
sl@0
  1048
void CTBitmap::CheckScanLine(CFbsBitmapEx& aBitmap,CFbsBitmapEx& aReference,TDisplayMode aDispMode)
sl@0
  1049
	{
sl@0
  1050
	const TSize bmpSize(aBitmap.SizeInPixels());
sl@0
  1051
	TInt byteWidth = CFbsBitmap::ScanLineLength(bmpSize.iWidth,aDispMode);
sl@0
  1052
	TUint8* buffer = new TUint8[byteWidth + 1];
sl@0
  1053
	buffer[byteWidth] = KCheckValue;
sl@0
  1054
	TPtr8 scanLine(buffer,byteWidth,byteWidth);
sl@0
  1055
sl@0
  1056
	aBitmap.GetScanLine(scanLine,TPoint(0,1),bmpSize.iWidth,aDispMode);
sl@0
  1057
sl@0
  1058
	for(TInt xx = 0; xx < bmpSize.iWidth; xx++)
sl@0
  1059
		{
sl@0
  1060
		TRgb color;
sl@0
  1061
		aReference.GetPixel(color,TPoint(xx,1));
sl@0
  1062
		TRgb bufferColor = ExtractRgb(buffer,xx,aDispMode);
sl@0
  1063
		switch (aDispMode)
sl@0
  1064
			{
sl@0
  1065
		case EGray2:
sl@0
  1066
			if (color.Gray4() == 0 || color.Gray4() == 3) // doesn't check in great detail because dithering occurs
sl@0
  1067
				TEST(bufferColor.Gray2() == color.Gray2());
sl@0
  1068
			break;
sl@0
  1069
		case EGray4:
sl@0
  1070
			if (aBitmap.DisplayMode() != EGray16) // doesn't check EGray16 because dithering occurs
sl@0
  1071
				TEST(bufferColor.Gray4() == color.Gray4());
sl@0
  1072
			break;
sl@0
  1073
		case EGray16:
sl@0
  1074
			TEST(bufferColor.Gray16() == color.Gray16());
sl@0
  1075
			break;
sl@0
  1076
		case EGray256:
sl@0
  1077
			TEST(bufferColor.Gray256() == color.Gray256());
sl@0
  1078
			break;
sl@0
  1079
		case EColor16:
sl@0
  1080
			TEST(bufferColor.Color16() == color.Color16());
sl@0
  1081
			break;
sl@0
  1082
		case EColor256:
sl@0
  1083
			TEST(bufferColor.Color256() == color.Color256());
sl@0
  1084
			break;
sl@0
  1085
		case EColor4K:
sl@0
  1086
			TEST(bufferColor.Color4K() == color.Color4K());
sl@0
  1087
			break;
sl@0
  1088
		case EColor64K:
sl@0
  1089
			TEST(bufferColor.Color64K() == color.Color64K());
sl@0
  1090
			break;
sl@0
  1091
		case EColor16M:
sl@0
  1092
			TEST(bufferColor.Color16M() == color.Color16M());
sl@0
  1093
			break;
sl@0
  1094
		case ERgb:
sl@0
  1095
			TEST(bufferColor == color);
sl@0
  1096
			break;
sl@0
  1097
		case EColor16MU:
sl@0
  1098
			if (aReference.DisplayMode()==EColor16MAP || aReference.DisplayMode()==EColor16MA)
sl@0
  1099
				color.SetAlpha(0xff);
sl@0
  1100
			CompareColourLikeness(bufferColor, color);			
sl@0
  1101
			break;
sl@0
  1102
		case EColor16MAP:
sl@0
  1103
			//Compare the TRgb values.  For an exact match to work the comparison would
sl@0
  1104
			//need to be done in PMA space.
sl@0
  1105
			color.SetInternal(color.Color16MAP());
sl@0
  1106
			bufferColor.SetInternal(bufferColor.Color16MAP());
sl@0
  1107
			CompareColourLikeness(bufferColor, color);			
sl@0
  1108
			break;	
sl@0
  1109
		default:
sl@0
  1110
			break;
sl@0
  1111
			};
sl@0
  1112
		}
sl@0
  1113
sl@0
  1114
	TEST(buffer[byteWidth] == KCheckValue);
sl@0
  1115
	delete [] buffer;
sl@0
  1116
	}
sl@0
  1117
sl@0
  1118
/**
sl@0
  1119
Compares two TRgbs and tests if they are similar colour.
sl@0
  1120
This is required because there may be some rounding errors when converting bitmaps from one display mode to another
sl@0
  1121
or due to alpha blending calculations.
sl@0
  1122
sl@0
  1123
@param aSrc is the source colour
sl@0
  1124
@param aDest is the destination colour
sl@0
  1125
@param aDifference use this value for colour difference.  Value of 0 use KColourDifference;
sl@0
  1126
*/
sl@0
  1127
void CTBitmap::CompareColourLikeness(const TRgb& aSrc, const TRgb& aDest, TInt aDifference)
sl@0
  1128
	{
sl@0
  1129
	const TInt KColourDifference = 2;	// Acceptable difference to check for
sl@0
  1130
	TInt diff;
sl@0
  1131
	
sl@0
  1132
	if (aDifference==0)
sl@0
  1133
		diff=KColourDifference;
sl@0
  1134
	else
sl@0
  1135
		diff=aDifference;
sl@0
  1136
	
sl@0
  1137
	TInt redDiff = Abs(aSrc.Red() - aDest.Red());
sl@0
  1138
	TInt greenDiff = Abs(aSrc.Green() - aDest.Green());	
sl@0
  1139
	TInt blueDiff = Abs(aSrc.Blue() - aDest.Blue());	
sl@0
  1140
	TInt alphaDiff = Abs(aSrc.Alpha() - aDest.Alpha());	
sl@0
  1141
	
sl@0
  1142
	// Test each channel
sl@0
  1143
	TEST(redDiff <= diff);
sl@0
  1144
	TEST(greenDiff <= diff);
sl@0
  1145
	TEST(blueDiff <= diff);
sl@0
  1146
	TEST(alphaDiff <= diff);
sl@0
  1147
	
sl@0
  1148
	// the code below is useful for a breakpoint, to inspect the differences, in case of failure
sl@0
  1149
/**	
sl@0
  1150
	if ((redDiff > diff)||(greenDiff > diff)||(blueDiff > diff)||(alphaDiff > diff))
sl@0
  1151
		TInt temp=1;
sl@0
  1152
*/
sl@0
  1153
	}
sl@0
  1154
sl@0
  1155
/**
sl@0
  1156
	@SYMTestCaseID
sl@0
  1157
	GRAPHICS-FBSERV-0521
sl@0
  1158
sl@0
  1159
	@SYMTestCaseDesc
sl@0
  1160
	Sets a scanline of random values into
sl@0
  1161
	bitmaps of different color depths
sl@0
  1162
sl@0
  1163
	@SYMTestActions
sl@0
  1164
	
sl@0
  1165
	@SYMTestExpectedResults
sl@0
  1166
	Test should pass
sl@0
  1167
*/
sl@0
  1168
void CTBitmap::SetScanline()
sl@0
  1169
	{
sl@0
  1170
	INFO_PRINTF1(_L("Test SetScanline"));
sl@0
  1171
sl@0
  1172
	DoSetScanline(EGray2);
sl@0
  1173
	DoSetScanline(EGray4);
sl@0
  1174
	DoSetScanline(EGray16);
sl@0
  1175
	DoSetScanline(EGray256);
sl@0
  1176
	DoSetScanline(EColor16);
sl@0
  1177
	DoSetScanline(EColor256);
sl@0
  1178
	DoSetScanline(EColor4K);
sl@0
  1179
	DoSetScanline(EColor64K);
sl@0
  1180
	DoSetScanline(EColor16M);
sl@0
  1181
	DoSetScanline(EColor16MU);
sl@0
  1182
	DoSetScanline(EColor16MAP);
sl@0
  1183
	}
sl@0
  1184
sl@0
  1185
void CTBitmap::DoSetScanline(TDisplayMode aDispMode)
sl@0
  1186
	{
sl@0
  1187
	__UHEAP_MARK;
sl@0
  1188
	CFbsBitmap bmp;
sl@0
  1189
sl@0
  1190
	TInt ret = bmp.Create(TSize(256,2),aDispMode);
sl@0
  1191
	TEST2(ret, KErrNone);
sl@0
  1192
sl@0
  1193
	TInt scanLineLength = CFbsBitmap::ScanLineLength(256,aDispMode);
sl@0
  1194
	TUint8* buffer = new TUint8[scanLineLength];
sl@0
  1195
	TEST(buffer != NULL);
sl@0
  1196
	TPtr8 scanline(buffer,scanLineLength,scanLineLength);
sl@0
  1197
sl@0
  1198
	TUint8* bufptr = buffer;
sl@0
  1199
	TInt64 seed = bmp.Handle();
sl@0
  1200
	for(TInt count = 0; count < scanLineLength; count++)
sl@0
  1201
		*bufptr++ = (TUint8)Math::Rand(seed);
sl@0
  1202
sl@0
  1203
	bmp.SetScanLine(scanline,0);
sl@0
  1204
	bmp.SetScanLine(scanline,1);
sl@0
  1205
sl@0
  1206
	bmp.LockHeap();
sl@0
  1207
	TUint8* data = (TUint8*)bmp.DataAddress();
sl@0
  1208
	bmp.UnlockHeap();
sl@0
  1209
	ret = Mem::Compare(buffer,scanLineLength,data,scanLineLength);
sl@0
  1210
	TEST(ret == 0);
sl@0
  1211
sl@0
  1212
	data += scanLineLength;
sl@0
  1213
	ret = Mem::Compare(buffer,scanLineLength,data,scanLineLength);
sl@0
  1214
	TEST(ret == 0);
sl@0
  1215
sl@0
  1216
	delete [] buffer;
sl@0
  1217
	bmp.Reset();
sl@0
  1218
	User::Heap().Check();
sl@0
  1219
	__UHEAP_MARKEND;
sl@0
  1220
	}
sl@0
  1221
sl@0
  1222
/**
sl@0
  1223
	@SYMTestCaseID
sl@0
  1224
	GRAPHICS-FBSERV-0522
sl@0
  1225
sl@0
  1226
	@SYMTestCaseDesc
sl@0
  1227
	Stretches a scan line to make it
sl@0
  1228
	double as long for different colour depths
sl@0
  1229
	tested on both small and large bitmaps.
sl@0
  1230
sl@0
  1231
	@SYMTestActions
sl@0
  1232
sl@0
  1233
	@SYMTestExpectedResults
sl@0
  1234
	Test should pass
sl@0
  1235
*/
sl@0
  1236
void CTBitmap::StretchScanline()
sl@0
  1237
	{
sl@0
  1238
	INFO_PRINTF1(_L("Test StretchScanline"));
sl@0
  1239
sl@0
  1240
	const TSize smallBitmapSize(226,2);
sl@0
  1241
	const TSize largeBitmapSize(1026,40);
sl@0
  1242
sl@0
  1243
	INFO_PRINTF1(_L("EGray2"));
sl@0
  1244
	DoStretchScanline(smallBitmapSize,EGray2);
sl@0
  1245
	DoStretchScanline(largeBitmapSize,EGray2);
sl@0
  1246
sl@0
  1247
	INFO_PRINTF1(_L(" EGray4"));
sl@0
  1248
	DoStretchScanline(smallBitmapSize,EGray4);
sl@0
  1249
	DoStretchScanline(largeBitmapSize,EGray4);
sl@0
  1250
sl@0
  1251
	INFO_PRINTF1(_L(" EGray16"));
sl@0
  1252
	DoStretchScanline(smallBitmapSize,EGray16);
sl@0
  1253
	DoStretchScanline(largeBitmapSize,EGray16);
sl@0
  1254
sl@0
  1255
	INFO_PRINTF1(_L(" EGray256"));
sl@0
  1256
	DoStretchScanline(smallBitmapSize,EGray256);
sl@0
  1257
	DoStretchScanline(largeBitmapSize,EGray256);
sl@0
  1258
sl@0
  1259
	INFO_PRINTF1(_L(" EColor16"));
sl@0
  1260
	DoStretchScanline(smallBitmapSize,EColor16);
sl@0
  1261
	DoStretchScanline(largeBitmapSize,EColor16);
sl@0
  1262
sl@0
  1263
	INFO_PRINTF1(_L(" EColor256"));
sl@0
  1264
	DoStretchScanline(smallBitmapSize,EColor256);
sl@0
  1265
	DoStretchScanline(largeBitmapSize,EColor256);
sl@0
  1266
sl@0
  1267
	INFO_PRINTF1(_L(" EColor4K"));
sl@0
  1268
	DoStretchScanline(smallBitmapSize,EColor4K);
sl@0
  1269
	DoStretchScanline(largeBitmapSize,EColor4K);
sl@0
  1270
sl@0
  1271
	INFO_PRINTF1(_L(" EColor64K"));
sl@0
  1272
	DoStretchScanline(smallBitmapSize,EColor64K);
sl@0
  1273
	DoStretchScanline(largeBitmapSize,EColor64K);
sl@0
  1274
sl@0
  1275
	INFO_PRINTF1(_L(" EColor16M"));
sl@0
  1276
	DoStretchScanline(smallBitmapSize,EColor16M);
sl@0
  1277
	DoStretchScanline(largeBitmapSize,EColor16M);
sl@0
  1278
sl@0
  1279
	INFO_PRINTF1(_L(" EColor16MU"));
sl@0
  1280
	DoStretchScanline(smallBitmapSize,EColor16MU);
sl@0
  1281
	DoStretchScanline(largeBitmapSize,EColor16MU);
sl@0
  1282
	
sl@0
  1283
	INFO_PRINTF1(_L(" EColor16MA"));
sl@0
  1284
	DoStretchScanline(smallBitmapSize,EColor16MA);
sl@0
  1285
	DoStretchScanline(largeBitmapSize,EColor16MA);
sl@0
  1286
sl@0
  1287
	INFO_PRINTF1(_L(" EColor16MAP"));
sl@0
  1288
	DoStretchScanline(smallBitmapSize,EColor16MAP);
sl@0
  1289
	DoStretchScanline(largeBitmapSize,EColor16MAP);
sl@0
  1290
	
sl@0
  1291
	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor16M, ETrue);
sl@0
  1292
	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor16M, ETrue);
sl@0
  1293
	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor16MU, ETrue);
sl@0
  1294
	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor16MU, ETrue);
sl@0
  1295
	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor16MA, ETrue);
sl@0
  1296
	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor16MA, ETrue);
sl@0
  1297
	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor64K, ETrue);
sl@0
  1298
	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor64K, ETrue);
sl@0
  1299
	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor4K, ETrue);
sl@0
  1300
	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor4K, ETrue);
sl@0
  1301
	DoStretchScanline(smallBitmapSize,EColor16MAP,EColor256, ETrue);
sl@0
  1302
	DoStretchScanline(largeBitmapSize,EColor16MAP,EColor256, ETrue);
sl@0
  1303
	
sl@0
  1304
	DoStretchScanline(smallBitmapSize,EColor16M,EColor16MAP, ETrue);
sl@0
  1305
	DoStretchScanline(largeBitmapSize,EColor16M,EColor16MAP, ETrue);
sl@0
  1306
	DoStretchScanline(smallBitmapSize,EColor16MU,EColor16MAP, ETrue);
sl@0
  1307
	DoStretchScanline(largeBitmapSize,EColor16MU,EColor16MAP, ETrue);
sl@0
  1308
	DoStretchScanline(smallBitmapSize,EColor16MA,EColor16MAP, ETrue);
sl@0
  1309
	DoStretchScanline(largeBitmapSize,EColor16MA,EColor16MAP, ETrue);
sl@0
  1310
	DoStretchScanline(smallBitmapSize,EColor64K,EColor16MAP, ETrue);
sl@0
  1311
	DoStretchScanline(largeBitmapSize,EColor64K,EColor16MAP, ETrue);
sl@0
  1312
	DoStretchScanline(smallBitmapSize,EColor4K,EColor16MAP, ETrue);
sl@0
  1313
	DoStretchScanline(largeBitmapSize,EColor4K,EColor16MAP, ETrue);
sl@0
  1314
	DoStretchScanline(smallBitmapSize,EColor256,EColor16MAP, ETrue);
sl@0
  1315
	DoStretchScanline(largeBitmapSize,EColor256,EColor16MAP, ETrue);
sl@0
  1316
	
sl@0
  1317
	DoStretchScanline(smallBitmapSize,EColor16MU,EColor16M, ETrue);
sl@0
  1318
	DoStretchScanline(largeBitmapSize,EColor16MU,EColor16M, ETrue);
sl@0
  1319
	
sl@0
  1320
	INFO_PRINTF1(_L("\n"));
sl@0
  1321
	}
sl@0
  1322
sl@0
  1323
void CTBitmap::DoStretchScanline(const TSize& aSize,TDisplayMode aDispMode)
sl@0
  1324
	{
sl@0
  1325
	DoStretchScanline(aSize,aDispMode,aDispMode, EFalse);
sl@0
  1326
	}
sl@0
  1327
sl@0
  1328
/* this function is used to determine an acceptable colour difference based on the screen mode 
sl@0
  1329
   and the alpha value.  This is because when converting from PMA to non pre-multiplied, there
sl@0
  1330
   can be large errors, especially if alpha is small.
sl@0
  1331
 */	
sl@0
  1332
TInt CTBitmap::ColorDifference(TDisplayMode aMode, TInt aAlpha)
sl@0
  1333
	{
sl@0
  1334
	switch (aMode)
sl@0
  1335
		{
sl@0
  1336
	case EGray2:// Monochrome display mode (1 bpp)
sl@0
  1337
		return 0xff>>1;
sl@0
  1338
	case EGray4:// Four grayscales display mode (2 bpp)
sl@0
  1339
		return 0xff>>2;
sl@0
  1340
	case EGray16:// 16 grayscales display mode (4 bpp)
sl@0
  1341
		return 0xff>>2;
sl@0
  1342
	case EGray256:// 256 grayscales display mode (8 bpp)
sl@0
  1343
		return 0xff>>2;
sl@0
  1344
	case EColor16:// Low colour EGA 16 colour display mode (4 bpp)
sl@0
  1345
		return 0xff>>2;
sl@0
  1346
	case EColor256: // 256 colour display mode (8 bpp)
sl@0
  1347
		return 0xff>>2;
sl@0
  1348
	case EColor64K: // 64,000 colour display mode (16 bpp) 
sl@0
  1349
		return 0xff>>5;
sl@0
  1350
	case EColor16M: // True colour display mode (24 bpp)
sl@0
  1351
		return 0xff>>5;
sl@0
  1352
	case EColor4K: // 4096 colour display (12 bpp).
sl@0
  1353
		return 0xff>>4;
sl@0
  1354
	case EColor16MU:// True colour display mode (32 bpp, but top byte is unused and unspecified)
sl@0
  1355
		return 0xff>>5;
sl@0
  1356
	case EColor16MA:// Display mode with alpha (24bpp colour plus 8bpp alpha)
sl@0
  1357
		return 0xff>>6;
sl@0
  1358
	case EColor16MAP:// Pre-multiplied Alpha display mode (24bpp color multiplied with the alpha channel value, plus 8bpp alpha)
sl@0
  1359
		if (aAlpha==0xff)
sl@0
  1360
			return 0xff>>4;
sl@0
  1361
		else
sl@0
  1362
			//make inaccuracy a function of alpha since the colour will the premultiplied, and then
sl@0
  1363
			//unpremultiplied.  For small alpha this can be quite large.
sl@0
  1364
			if (aAlpha==0)
sl@0
  1365
				return 0xff;
sl@0
  1366
			else
sl@0
  1367
				return Max(0xff>>4,Min(0xff,(0xff/aAlpha)+0xf));//value corrected by trial and error, with minimum of 15.
sl@0
  1368
		}
sl@0
  1369
	return 0xff>>7;	
sl@0
  1370
	}
sl@0
  1371
sl@0
  1372
void CTBitmap::DoStretchScanline(const TSize& aSize,TDisplayMode aSrcMode,TDisplayMode aDstMode, TBool aUseCompareLikeness)
sl@0
  1373
	{
sl@0
  1374
	__UHEAP_MARK;
sl@0
  1375
	CFbsBitmapEx bmp;
sl@0
  1376
	CBitwiseBitmap* bmpadd=NULL;
sl@0
  1377
sl@0
  1378
	TInt ret = bmp.Create(aSize,aSrcMode);
sl@0
  1379
	TEST2(ret, KErrNone);
sl@0
  1380
sl@0
  1381
	FillBitmap(bmp);
sl@0
  1382
	bmpadd = bmp.BitmapAddress();
sl@0
  1383
	bmp.LockHeap();
sl@0
  1384
	TUint32* base = bmp.DataAddress();
sl@0
  1385
	bmp.UnlockHeap();
sl@0
  1386
sl@0
  1387
	TInt scanLineLength = CFbsBitmap::ScanLineLength(aSize.iWidth,aSrcMode);
sl@0
  1388
	TInt scanLineDestLength = CFbsBitmap::ScanLineLength(aSize.iWidth,aDstMode)*2;
sl@0
  1389
	TUint8* buffer = new TUint8[scanLineLength];
sl@0
  1390
	TUint8* doubleBuffer = new TUint8[scanLineDestLength];
sl@0
  1391
	TPtr8 scanline(buffer,scanLineLength,scanLineLength);
sl@0
  1392
	TPtr8 doubleScanline(doubleBuffer,scanLineDestLength,scanLineDestLength);
sl@0
  1393
sl@0
  1394
	TInt yy;
sl@0
  1395
	for(yy = 0; yy < aSize.iHeight; yy++)
sl@0
  1396
		{
sl@0
  1397
		bmp.GetScanLine(scanline,TPoint(0,yy),aSize.iWidth,aSrcMode);
sl@0
  1398
		bmpadd->StretchScanLine(doubleScanline,TPoint(0,yy),0,aSize.iWidth * 2,aSize.iWidth * 2,0,aSize.iWidth,TPoint(0,0),aDstMode,base);
sl@0
  1399
		for(TInt xx = 0; xx < aSize.iWidth; xx++)
sl@0
  1400
			{
sl@0
  1401
			TRgb scanlineColor = ExtractRgb(buffer,xx,aSrcMode);
sl@0
  1402
			TRgb firstStretchColor = ExtractRgb(doubleBuffer,xx * 2,aDstMode);
sl@0
  1403
			TRgb secondStretchColor = ExtractRgb(doubleBuffer,(xx * 2) + 1,aDstMode);
sl@0
  1404
			TRgb reportedColor;
sl@0
  1405
			bmpadd->GetPixel(reportedColor,TPoint(xx,yy),base,NULL);
sl@0
  1406
			if (!aUseCompareLikeness)
sl@0
  1407
				{
sl@0
  1408
				TEST(scanlineColor == firstStretchColor);
sl@0
  1409
				TEST(firstStretchColor == secondStretchColor);
sl@0
  1410
				TEST(secondStretchColor == reportedColor);
sl@0
  1411
				}
sl@0
  1412
			else
sl@0
  1413
				{
sl@0
  1414
				if (aDstMode==EColor16M||aDstMode==EColor16MU||aDstMode==EColor64K||aDstMode==EColor4K||aDstMode==EColor256)
sl@0
  1415
					{
sl@0
  1416
					//there is no alpha in the destination
sl@0
  1417
					scanlineColor.SetAlpha(0xff);
sl@0
  1418
					reportedColor.SetAlpha(0xff);	
sl@0
  1419
					}	
sl@0
  1420
				CompareColourLikeness(scanlineColor, firstStretchColor, ColorDifference(aDstMode,scanlineColor.Alpha()));
sl@0
  1421
				CompareColourLikeness(firstStretchColor, secondStretchColor,ColorDifference(aDstMode,scanlineColor.Alpha()));
sl@0
  1422
				CompareColourLikeness(secondStretchColor, reportedColor,ColorDifference(aDstMode,scanlineColor.Alpha()));
sl@0
  1423
				}
sl@0
  1424
			}
sl@0
  1425
		}
sl@0
  1426
sl@0
  1427
	for(yy = 0; yy < aSize.iHeight; yy++)
sl@0
  1428
		{
sl@0
  1429
		bmp.GetScanLine(scanline,TPoint(0,yy),aSize.iWidth,aSrcMode);
sl@0
  1430
		bmpadd->StretchScanLine(doubleScanline,TPoint(0,yy),0,aSize.iWidth / 2,aSize.iWidth / 2,0,aSize.iWidth,TPoint(0,0),aDstMode,base);
sl@0
  1431
		for(TInt xx = 0; xx < aSize.iWidth; xx += 2)
sl@0
  1432
			{
sl@0
  1433
			TRgb scanlineColor = ExtractRgb(buffer,xx,aSrcMode);
sl@0
  1434
			TRgb compressColor = ExtractRgb(doubleBuffer,xx / 2,aDstMode);
sl@0
  1435
			TRgb reportedColor;
sl@0
  1436
			bmpadd->GetPixel(reportedColor,TPoint(xx,yy),base,NULL);
sl@0
  1437
			if (!aUseCompareLikeness)
sl@0
  1438
				{
sl@0
  1439
				TEST(scanlineColor == compressColor);
sl@0
  1440
				TEST(compressColor == reportedColor);
sl@0
  1441
				}
sl@0
  1442
			else
sl@0
  1443
				{
sl@0
  1444
				if (aDstMode==EColor16M||aDstMode==EColor16MU||aDstMode==EColor64K||aDstMode==EColor4K||aDstMode==EColor256)
sl@0
  1445
					{
sl@0
  1446
					//there is no alpha in the destination
sl@0
  1447
					scanlineColor.SetAlpha(0xff);
sl@0
  1448
					reportedColor.SetAlpha(0xff);	
sl@0
  1449
					}
sl@0
  1450
				CompareColourLikeness(scanlineColor, compressColor,ColorDifference(aDstMode,scanlineColor.Alpha()));
sl@0
  1451
				CompareColourLikeness(compressColor, reportedColor,ColorDifference(aDstMode,scanlineColor.Alpha()));
sl@0
  1452
				}
sl@0
  1453
			}
sl@0
  1454
		}
sl@0
  1455
sl@0
  1456
	delete [] buffer;
sl@0
  1457
	delete [] doubleBuffer;
sl@0
  1458
	buffer = NULL;
sl@0
  1459
	doubleBuffer = NULL;
sl@0
  1460
sl@0
  1461
	TInt rgbScanLineLength = aSize.iWidth * sizeof(TRgb) * 2;
sl@0
  1462
	TUint8* rgbBuffer = new TUint8[rgbScanLineLength];
sl@0
  1463
	TPtr8 rgbScanline(rgbBuffer,rgbScanLineLength,rgbScanLineLength);
sl@0
  1464
sl@0
  1465
	for(yy = 0; yy < aSize.iHeight; yy++)
sl@0
  1466
		{
sl@0
  1467
		bmpadd->StretchScanLine(rgbScanline,TPoint(0,yy),0,aSize.iWidth * 2,aSize.iWidth * 2,0,aSize.iWidth,TPoint(0,0),ERgb,base);
sl@0
  1468
		for(TInt xx = 0; xx < aSize.iWidth; xx++)
sl@0
  1469
			{
sl@0
  1470
			TRgb firstStretchColor = ExtractRgb(rgbBuffer,xx * 2,ERgb);
sl@0
  1471
			TRgb secondStretchColor = ExtractRgb(rgbBuffer,(xx * 2) + 1,ERgb);
sl@0
  1472
			TRgb reportedColor;
sl@0
  1473
			bmpadd->GetPixel(reportedColor,TPoint(xx,yy),base,NULL);
sl@0
  1474
			if (!aUseCompareLikeness)
sl@0
  1475
				{
sl@0
  1476
				TEST(firstStretchColor == secondStretchColor);
sl@0
  1477
				TEST(secondStretchColor == reportedColor);
sl@0
  1478
				}
sl@0
  1479
			else
sl@0
  1480
				{
sl@0
  1481
				CompareColourLikeness(firstStretchColor, secondStretchColor);
sl@0
  1482
				CompareColourLikeness(secondStretchColor, reportedColor);
sl@0
  1483
				}
sl@0
  1484
			}
sl@0
  1485
		}
sl@0
  1486
sl@0
  1487
	for(yy = 0; yy < aSize.iHeight; yy++)
sl@0
  1488
		{
sl@0
  1489
		bmpadd->StretchScanLine(rgbScanline,TPoint(0,yy),0,aSize.iWidth / 2,aSize.iWidth / 2,0,aSize.iWidth,TPoint(0,0),ERgb,base);
sl@0
  1490
		for(TInt xx = 0; xx < aSize.iWidth; xx += 2)
sl@0
  1491
			{
sl@0
  1492
			TRgb compressColor = ExtractRgb(rgbBuffer,xx / 2,ERgb);
sl@0
  1493
			TRgb reportedColor;
sl@0
  1494
			bmpadd->GetPixel(reportedColor,TPoint(xx,yy),base,NULL);
sl@0
  1495
			if (!aUseCompareLikeness)
sl@0
  1496
				{
sl@0
  1497
				TEST(compressColor == reportedColor);
sl@0
  1498
				}
sl@0
  1499
			else
sl@0
  1500
				{
sl@0
  1501
				CompareColourLikeness(compressColor, reportedColor);
sl@0
  1502
				}
sl@0
  1503
			}
sl@0
  1504
		}
sl@0
  1505
sl@0
  1506
	delete [] rgbBuffer;
sl@0
  1507
	rgbBuffer = NULL;
sl@0
  1508
sl@0
  1509
	bmp.Reset();
sl@0
  1510
	User::Heap().Check();
sl@0
  1511
	DeleteScanLineBuffer();
sl@0
  1512
	__UHEAP_MARKEND;
sl@0
  1513
	}
sl@0
  1514
sl@0
  1515
TRgb CTBitmap::ExtractRgb(TUint8* aBuffer,TInt aPixelOffset,TDisplayMode aDispMode)
sl@0
  1516
	{
sl@0
  1517
	switch (aDispMode)
sl@0
  1518
		{
sl@0
  1519
	case EGray2:
sl@0
  1520
		{
sl@0
  1521
		TUint8 byte = *(aBuffer + (aPixelOffset >> 3));
sl@0
  1522
		if (byte & (1 << (aPixelOffset & 7)))
sl@0
  1523
			return KRgbWhite;
sl@0
  1524
		return KRgbBlack;
sl@0
  1525
		}
sl@0
  1526
	case EGray4:
sl@0
  1527
		{
sl@0
  1528
		TUint8 byte = *(aBuffer + (aPixelOffset >> 2));
sl@0
  1529
		byte >>= ((aPixelOffset & 3) << 1);
sl@0
  1530
		return TRgb::Gray4(byte & 3);
sl@0
  1531
		}
sl@0
  1532
	case EGray16:
sl@0
  1533
		{
sl@0
  1534
		TUint8 byte = *(aBuffer + (aPixelOffset >> 1));
sl@0
  1535
		if (aPixelOffset & 1)
sl@0
  1536
			byte >>= 4;
sl@0
  1537
		return TRgb::Gray16(byte & 0xf);
sl@0
  1538
		}
sl@0
  1539
	case EGray256:
sl@0
  1540
		return TRgb::Gray256(*(aBuffer + aPixelOffset));
sl@0
  1541
	case EColor16:
sl@0
  1542
		{
sl@0
  1543
		TUint8 byte = *(aBuffer + (aPixelOffset >> 1));
sl@0
  1544
		if (aPixelOffset & 1)
sl@0
  1545
			byte >>= 4;
sl@0
  1546
		return TRgb::Color16(byte & 0xf);
sl@0
  1547
		}
sl@0
  1548
	case EColor256:
sl@0
  1549
		return TRgb::Color256(*(aBuffer + aPixelOffset));
sl@0
  1550
	case EColor4K:
sl@0
  1551
		{
sl@0
  1552
		TUint16 doubleByte = *(((TUint16*)aBuffer) + aPixelOffset);
sl@0
  1553
		return TRgb::Color4K(doubleByte & 0xfff);
sl@0
  1554
		}
sl@0
  1555
	case EColor64K:
sl@0
  1556
		{
sl@0
  1557
		TUint16 doubleByte = *(((TUint16*)aBuffer) + aPixelOffset);
sl@0
  1558
		return TRgb::Color64K(doubleByte);
sl@0
  1559
		}
sl@0
  1560
	case EColor16M:
sl@0
  1561
		{
sl@0
  1562
		aBuffer += aPixelOffset * 3;
sl@0
  1563
		TInt value = *aBuffer++;
sl@0
  1564
		value |= *aBuffer++ << 8;
sl@0
  1565
		value |= *aBuffer << 16;
sl@0
  1566
		return TRgb::Color16M(value);
sl@0
  1567
		}
sl@0
  1568
	case ERgb:
sl@0
  1569
		return *(((TRgb*)aBuffer) + aPixelOffset);
sl@0
  1570
	case EColor16MU:
sl@0
  1571
		{
sl@0
  1572
		return TRgb::Color16MU(*(((TUint32*)aBuffer) + aPixelOffset));
sl@0
  1573
		}
sl@0
  1574
	case EColor16MA:
sl@0
  1575
		{
sl@0
  1576
		return TRgb::Color16MA(*(((TUint32*)aBuffer) + aPixelOffset));
sl@0
  1577
		}	
sl@0
  1578
	case EColor16MAP:
sl@0
  1579
		{
sl@0
  1580
		return TRgb::_Color16MAP(*(((TUint32*)aBuffer) + aPixelOffset));
sl@0
  1581
		}	
sl@0
  1582
	default:
sl@0
  1583
		break;
sl@0
  1584
		};
sl@0
  1585
	return KRgbBlack;
sl@0
  1586
	}
sl@0
  1587
	
sl@0
  1588
/**
sl@0
  1589
	@SYMTestCaseID
sl@0
  1590
	GRAPHICS-FBSERV-0523
sl@0
  1591
sl@0
  1592
	@SYMTestCaseDesc
sl@0
  1593
	Streams a bitmap in segments and compares it
sl@0
  1594
	to an expected bitmap
sl@0
  1595
	
sl@0
  1596
	@SYMTestActions
sl@0
  1597
	
sl@0
  1598
	@SYMTestExpectedResults
sl@0
  1599
	Test should pass
sl@0
  1600
*/
sl@0
  1601
void CTBitmap::LoadInSegments()
sl@0
  1602
	{
sl@0
  1603
	INFO_PRINTF1(_L("Test Segmented Loading"));
sl@0
  1604
sl@0
  1605
	__UHEAP_MARK;
sl@0
  1606
	CFbsBitmapEx bmp;
sl@0
  1607
	TInt ret=bmp.Load(iTestBitmapName,ETfbs,NULL);
sl@0
  1608
	TEST2(ret, KErrNone);
sl@0
  1609
	CFbsBitmapAsyncStreamer* bmploader=NULL;
sl@0
  1610
	TRAP(ret,bmploader=CFbsBitmapAsyncStreamer::NewL(CFbsBitmapAsyncStreamer::ELoad));
sl@0
  1611
	TEST2(ret, KErrNone);
sl@0
  1612
	TInt slines=0;
sl@0
  1613
	ret=bmploader->Load(iTestBitmapName,ETfbs,slines);
sl@0
  1614
	TEST2(ret, KErrNone);
sl@0
  1615
	TEST(slines>0);
sl@0
  1616
	CFbsBitmap* newbmp=NULL;
sl@0
  1617
	TBool done=EFalse;
sl@0
  1618
	do	{
sl@0
  1619
		TEST(newbmp==NULL);
sl@0
  1620
		TRAP(ret,done=bmploader->LoadScanLinesL(slines/10,newbmp));
sl@0
  1621
		TEST2(ret, KErrNone);
sl@0
  1622
		}
sl@0
  1623
	while(!done);
sl@0
  1624
sl@0
  1625
	TEST(newbmp!=NULL);
sl@0
  1626
	CompareBitmaps(bmp,(CFbsBitmapEx&)*newbmp,EColor16M);
sl@0
  1627
	delete bmploader;
sl@0
  1628
	delete newbmp;
sl@0
  1629
sl@0
  1630
	TRAP(ret,iBmpHandler=CFbsBitmapAsyncStreamer::NewL(CFbsBitmapAsyncStreamer::ELoad));
sl@0
  1631
	TEST2(ret, KErrNone);
sl@0
  1632
	ret=iBmpHandler->Load(iTestBitmapName,ETfbs,slines);
sl@0
  1633
	TEST2(ret, KErrNone);
sl@0
  1634
	TEST(slines>0);
sl@0
  1635
	CIdle* idleobj=CIdle::New(-20);
sl@0
  1636
	TEST(idleobj!=NULL);
sl@0
  1637
	TCallBack callback(BmpLoadCallBack,this);
sl@0
  1638
	idleobj->Start(callback);
sl@0
  1639
	
sl@0
  1640
	CActiveScheduler* as = CActiveScheduler::Current();
sl@0
  1641
	__ASSERT_DEBUG(as, User::Invariant());
sl@0
  1642
	
sl@0
  1643
	TRAP(ret,as->Start());
sl@0
  1644
	TEST2(ret, KErrNone);
sl@0
  1645
	
sl@0
  1646
	CompareBitmaps(bmp,(CFbsBitmapEx&)*iBitmap,EColor16M);
sl@0
  1647
sl@0
  1648
	delete iBmpHandler;
sl@0
  1649
	delete iBitmap;
sl@0
  1650
	bmp.Reset();
sl@0
  1651
	delete idleobj;
sl@0
  1652
	User::Heap().Check();
sl@0
  1653
	__UHEAP_MARKEND;
sl@0
  1654
sl@0
  1655
	
sl@0
  1656
	}
sl@0
  1657
sl@0
  1658
TInt CTBitmap::BmpLoadCallBack(TAny* aPtr)
sl@0
  1659
	{
sl@0
  1660
	CTBitmap* tbmp=(CTBitmap*)aPtr;
sl@0
  1661
	tbmp->INFO_PRINTF1(_L("*"));
sl@0
  1662
	TBool done=EFalse;
sl@0
  1663
	TRAPD(ret,done=tbmp->iBmpHandler->LoadScanLinesL(10,tbmp->iBitmap));
sl@0
  1664
	tbmp->TEST2(ret, KErrNone);
sl@0
  1665
	if(done)
sl@0
  1666
		{
sl@0
  1667
		tbmp->TEST(tbmp->iBitmap!=NULL);
sl@0
  1668
		CActiveScheduler::Stop();
sl@0
  1669
		}
sl@0
  1670
	else 
sl@0
  1671
		{
sl@0
  1672
		tbmp->TEST(tbmp->iBitmap==NULL);
sl@0
  1673
		}
sl@0
  1674
	return(ETrue);
sl@0
  1675
	}
sl@0
  1676
	
sl@0
  1677
/**
sl@0
  1678
	@SYMTestCaseID
sl@0
  1679
	GRAPHICS-FBSERV-0524
sl@0
  1680
sl@0
  1681
	@SYMTestCaseDesc
sl@0
  1682
	A bitmap is saved in segments and then read back from file store
sl@0
  1683
	and compared to an expected bitmap
sl@0
  1684
sl@0
  1685
	@SYMTestActions
sl@0
  1686
	
sl@0
  1687
	@SYMTestExpectedResults
sl@0
  1688
	Test should pass
sl@0
  1689
*/	
sl@0
  1690
void CTBitmap::SaveInSegments()
sl@0
  1691
	{
sl@0
  1692
	INFO_PRINTF1(_L("Test Segmented Saving"));
sl@0
  1693
sl@0
  1694
	__UHEAP_MARK;
sl@0
  1695
	CFbsBitmapEx bmp;
sl@0
  1696
	TInt ret=bmp.Load(iTestBitmapName,ETfbs,NULL);
sl@0
  1697
	TEST2(ret, KErrNone);
sl@0
  1698
	CFbsBitmapAsyncStreamer* bmpsaver=NULL;
sl@0
  1699
	TRAP(ret,bmpsaver=CFbsBitmapAsyncStreamer::NewL(CFbsBitmapAsyncStreamer::ESave));
sl@0
  1700
	TEST2(ret, KErrNone);
sl@0
  1701
	TInt slines=0;
sl@0
  1702
	TInt32 id;
sl@0
  1703
	ret=bmpsaver->Save(KTempFilename,&bmp,id,slines);
sl@0
  1704
	TEST2(ret, KErrNone);
sl@0
  1705
	TEST(id==0);
sl@0
  1706
	TEST(slines>0);
sl@0
  1707
	TBool done=EFalse;
sl@0
  1708
	do	{
sl@0
  1709
		TRAP(ret,done=bmpsaver->SaveScanLinesL(slines/10));
sl@0
  1710
		TEST2(ret, KErrNone);
sl@0
  1711
		}
sl@0
  1712
	while(!done);
sl@0
  1713
	delete bmpsaver;
sl@0
  1714
	CFbsBitmapEx bmp2;
sl@0
  1715
	ret=bmp2.Load(KTempFilename,id,NULL);
sl@0
  1716
	TEST2(ret, KErrNone);
sl@0
  1717
	TUint8 buffer[40];
sl@0
  1718
	TUint8 bufferst[40];
sl@0
  1719
	TPtr8 scanline(&buffer[0],40,40);
sl@0
  1720
	TPtr8 scanlinest(&bufferst[0],40,40);
sl@0
  1721
	TInt yy=0;
sl@0
  1722
	for(;yy<80;yy++)
sl@0
  1723
		{
sl@0
  1724
		bmp.GetScanLine(scanline,TPoint(0,yy),160,EGray4);
sl@0
  1725
		bmp2.GetScanLine(scanlinest,TPoint(0,yy),160,EGray4);
sl@0
  1726
		for(TInt count=0;count<40;count++)
sl@0
  1727
			TEST(buffer[count]==bufferst[count]);
sl@0
  1728
		}
sl@0
  1729
	bmp2.Reset();
sl@0
  1730
	iFs.Delete(KTempFilename);
sl@0
  1731
sl@0
  1732
	CActiveScheduler* as = CActiveScheduler::Current();
sl@0
  1733
	__ASSERT_DEBUG(as, User::Invariant());
sl@0
  1734
sl@0
  1735
	TRAP(ret,iBmpHandler=CFbsBitmapAsyncStreamer::NewL(CFbsBitmapAsyncStreamer::ESave));
sl@0
  1736
	TEST2(ret, KErrNone);
sl@0
  1737
	ret=iBmpHandler->Save(KTempFilename,&bmp,id,slines);
sl@0
  1738
	TEST2(ret, KErrNone);
sl@0
  1739
	TEST(id==0);
sl@0
  1740
	TEST(slines>0);
sl@0
  1741
	CIdle* idleobj=CIdle::New(-20);
sl@0
  1742
	TEST(idleobj!=NULL);
sl@0
  1743
	TCallBack callback(BmpSaveCallBack,this);
sl@0
  1744
	idleobj->Start(callback);
sl@0
  1745
	TRAP(ret,as->Start());
sl@0
  1746
	TEST2(ret, KErrNone);
sl@0
  1747
	delete iBmpHandler;
sl@0
  1748
	ret=bmp2.Load(KTempFilename,id,NULL);
sl@0
  1749
	TEST2(ret, KErrNone);
sl@0
  1750
	for(yy=0;yy<80;yy++)
sl@0
  1751
		{
sl@0
  1752
		bmp.GetScanLine(scanline,TPoint(0,yy),160,EGray4);
sl@0
  1753
		bmp2.GetScanLine(scanlinest,TPoint(0,yy),160,EGray4);
sl@0
  1754
		for(TInt count=0;count<40;count++)
sl@0
  1755
			TEST(buffer[count]==bufferst[count]);
sl@0
  1756
		}
sl@0
  1757
	bmp.Reset();
sl@0
  1758
	delete idleobj;
sl@0
  1759
	iFs.Delete(KTempFilename);
sl@0
  1760
	User::Heap().Check();
sl@0
  1761
	__UHEAP_MARKEND;
sl@0
  1762
sl@0
  1763
	INFO_PRINTF1(_L("\r\n"));
sl@0
  1764
	
sl@0
  1765
	}
sl@0
  1766
sl@0
  1767
TInt CTBitmap::BmpSaveCallBack(TAny* aPtr)
sl@0
  1768
	{
sl@0
  1769
	CTBitmap* tbmp=(CTBitmap*)aPtr;
sl@0
  1770
	tbmp->INFO_PRINTF1(_L("*"));
sl@0
  1771
	TBool done=EFalse;
sl@0
  1772
	TRAPD(ret,done=tbmp->iBmpHandler->SaveScanLinesL(10));
sl@0
  1773
	tbmp->TEST2(ret, KErrNone);
sl@0
  1774
	if(done) 
sl@0
  1775
		{
sl@0
  1776
		CActiveScheduler::Stop();
sl@0
  1777
		}
sl@0
  1778
	return(ETrue);
sl@0
  1779
	}
sl@0
  1780
sl@0
  1781
/**
sl@0
  1782
	@SYMTestCaseID
sl@0
  1783
	GRAPHICS-FBSERV-0525
sl@0
  1784
sl@0
  1785
	@SYMTestCaseDesc
sl@0
  1786
	Tests if a bitmap is monochrone for different
sl@0
  1787
	color depths
sl@0
  1788
sl@0
  1789
	@SYMTestActions
sl@0
  1790
	
sl@0
  1791
	@SYMTestExpectedResults
sl@0
  1792
	Test should pass
sl@0
  1793
*/
sl@0
  1794
void CTBitmap::MonoDetect()
sl@0
  1795
	{
sl@0
  1796
	INFO_PRINTF1(_L("Test Mono Detection"));
sl@0
  1797
sl@0
  1798
	DoMonoDetect(EGray2);
sl@0
  1799
	DoMonoDetect(EGray4);
sl@0
  1800
	DoMonoDetect(EGray16);
sl@0
  1801
	DoMonoDetect(EGray256);
sl@0
  1802
	DoMonoDetect(EColor16);
sl@0
  1803
	DoMonoDetect(EColor256);
sl@0
  1804
	DoMonoDetect(EColor4K);
sl@0
  1805
	DoMonoDetect(EColor64K);
sl@0
  1806
	DoMonoDetect(EColor16M);
sl@0
  1807
	DoMonoDetect(EColor16MU);
sl@0
  1808
	DoMonoDetect(EColor16MAP);
sl@0
  1809
	}
sl@0
  1810
sl@0
  1811
void CTBitmap::DoMonoDetect(TDisplayMode aDisplayMode)
sl@0
  1812
	{
sl@0
  1813
	CFbsBitmapEx bmp;
sl@0
  1814
	TInt ret = bmp.Create(TSize(100,3),aDisplayMode);
sl@0
  1815
	TEST2(ret, KErrNone);
sl@0
  1816
sl@0
  1817
	CBitwiseBitmap* bmpadd = bmp.BitmapAddress();
sl@0
  1818
	bmp.LockHeap();
sl@0
  1819
	TUint32* base = bmp.DataAddress();
sl@0
  1820
	bmp.UnlockHeap();
sl@0
  1821
	TUint32* data = bmpadd->ScanLineAddress(base,1);
sl@0
  1822
sl@0
  1823
	if(aDisplayMode == EColor16M)
sl@0
  1824
		{
sl@0
  1825
		*(data+1) = 0x0000FFFF;
sl@0
  1826
		*(data+2) = 0xFFFFFF00;
sl@0
  1827
		//Pixel at (data + 1). Bytes (3) and (2) are part of the pixel at (data) addr.
sl@0
  1828
		//LSB                        MSB
sl@0
  1829
		//3        2        1        0
sl@0
  1830
		//FF       FF       00       00  
sl@0
  1831
		//Pixel at (data + 2). Byte (3) is part of the pixel at (data + 1) addr.
sl@0
  1832
		//LSB                        MSB
sl@0
  1833
		//3        2        1        0
sl@0
  1834
		//00       FF       FF       FF
sl@0
  1835
		}
sl@0
  1836
	else
sl@0
  1837
		{
sl@0
  1838
		*(data+1) = 0;
sl@0
  1839
		}
sl@0
  1840
	TBool mono = bmp.IsMonochrome();
sl@0
  1841
	TEST(mono);
sl@0
  1842
sl@0
  1843
	*(data+1) = 0x1234abcd;
sl@0
  1844
	mono = bmp.IsMonochrome();
sl@0
  1845
	if (aDisplayMode == EGray2)
sl@0
  1846
		TEST(mono);
sl@0
  1847
	else
sl@0
  1848
		TEST(!mono);
sl@0
  1849
sl@0
  1850
	if(aDisplayMode == EColor16M)
sl@0
  1851
		{
sl@0
  1852
		*(data+1) = 0xffffffff;
sl@0
  1853
		*(data+2) = 0xffffffff;
sl@0
  1854
		}
sl@0
  1855
	else
sl@0
  1856
		{
sl@0
  1857
		*(data+1) = 0xffffffff;
sl@0
  1858
		}
sl@0
  1859
	mono=bmp.IsMonochrome();
sl@0
  1860
	TEST(mono);
sl@0
  1861
sl@0
  1862
	bmp.Reset();
sl@0
  1863
	}
sl@0
  1864
sl@0
  1865
sl@0
  1866
#if defined(__WINS__)
sl@0
  1867
// these are patchable constants defined in fbscli.dll but on the emulator
sl@0
  1868
// it's not possible to import them so they are re-defined here
sl@0
  1869
const TInt KFbServLargeChunkGrowByShifter = 1;
sl@0
  1870
const TInt KFbServLargeChunkSizeShifter = 2;
sl@0
  1871
const TInt KFbServLargeChunkMinPhysicalSize = 0x4000;
sl@0
  1872
#elif defined(__X86GCC__)
sl@0
  1873
IMPORT_D extern const TInt KFbServLargeChunkGrowByShifter;
sl@0
  1874
IMPORT_D extern const TInt KFbServLargeChunkSizeShifter;
sl@0
  1875
IMPORT_D extern const TInt KFbServLargeChunkMinPhysicalSize;
sl@0
  1876
#endif
sl@0
  1877
sl@0
  1878
/**
sl@0
  1879
	@SYMTestCaseID
sl@0
  1880
	GRAPHICS-FBSERV-0526
sl@0
  1881
sl@0
  1882
	@SYMTestCaseDesc
sl@0
  1883
	Allocates different sized chunks of memory
sl@0
  1884
	in a loop and frees them
sl@0
  1885
sl@0
  1886
	@SYMTestActions
sl@0
  1887
	
sl@0
  1888
	@SYMTestExpectedResults
sl@0
  1889
	Test should pass
sl@0
  1890
*/
sl@0
  1891
void CTBitmap::ChunkPileL()
sl@0
  1892
	{
sl@0
  1893
	INFO_PRINTF1(_L("Test Chunk Pile"));
sl@0
  1894
sl@0
  1895
	TInt virtualSize = 0x4000000;
sl@0
  1896
	RChunk chunk;
sl@0
  1897
	TInt ret = chunk.CreateDisconnectedGlobal(_L("TFbsLargeChunk"), 0, 0, virtualSize);
sl@0
  1898
	TEST2(ret, KErrNone);
sl@0
  1899
	CleanupClosePushL(chunk);
sl@0
  1900
	TInt pageSize = 0;
sl@0
  1901
	HAL::Get(HAL::EMemoryPageSize, pageSize);
sl@0
  1902
	TEST(pageSize == 4096);
sl@0
  1903
	TUint8* chunkSmallBase = chunk.Base() + pageSize;
sl@0
  1904
	TUint8* chunkLargeBase = chunk.Base() + (virtualSize >> KFbServLargeChunkSizeShifter);
sl@0
  1905
sl@0
  1906
	CChunkPile* cp=NULL;
sl@0
  1907
	TRAP(ret, cp = CChunkPile::NewL(chunk));
sl@0
  1908
	TEST2(ret, KErrNone);
sl@0
  1909
	TEST(cp!=NULL);
sl@0
  1910
	CleanupStack::PushL(cp);
sl@0
  1911
	TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
sl@0
  1912
sl@0
  1913
	TUint8* chunkalloc[16];
sl@0
  1914
	TInt size[16];
sl@0
  1915
	for (TInt i = 0; i < 64; ++i)
sl@0
  1916
		{
sl@0
  1917
		chunkalloc[0] = cp->Alloc(size[0] = 512);
sl@0
  1918
		TEST(chunkalloc[0] == chunkSmallBase);
sl@0
  1919
		chunkalloc[1] = cp->Alloc(size[1] = 8);
sl@0
  1920
		TEST(chunkalloc[1] == chunkalloc[0] + size[0]);
sl@0
  1921
		chunkalloc[2] = cp->Alloc(size[2] = 128);
sl@0
  1922
		TEST(chunkalloc[2] == chunkalloc[1] + size[1]);
sl@0
  1923
		chunkalloc[3] = cp->Alloc(size[3] = 372);
sl@0
  1924
		TEST(chunkalloc[3] == chunkalloc[2] + size[2]);
sl@0
  1925
		chunkalloc[4] = cp->Alloc(size[4] = 256);
sl@0
  1926
		TEST(chunkalloc[4] == chunkalloc[3] + size[3]);
sl@0
  1927
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
sl@0
  1928
		// now we should have [0], [1], [2], [3], [4]
sl@0
  1929
sl@0
  1930
		cp->Free(chunkalloc[2]);
sl@0
  1931
		cp->Free(chunkalloc[3]);
sl@0
  1932
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
sl@0
  1933
		chunkalloc[5] = cp->Alloc(size[5] = size[2] + size[3]);
sl@0
  1934
		TEST(chunkalloc[5] == chunkalloc[2]);
sl@0
  1935
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
sl@0
  1936
		// now we should have [0], [1], [5], [4]
sl@0
  1937
sl@0
  1938
		chunkalloc[6] = cp->Alloc(size[6] = 4);
sl@0
  1939
		TEST(chunkalloc[6] == chunkalloc[4] + size[4]);
sl@0
  1940
		chunkalloc[7] = cp->Alloc(size[7] = 1024);
sl@0
  1941
		TEST(chunkalloc[7] == chunkalloc[6] + size[6]);
sl@0
  1942
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
sl@0
  1943
		cp->Free(chunkalloc[7]);
sl@0
  1944
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
sl@0
  1945
		// now we should have [0], [1], [5], [4], [6]
sl@0
  1946
sl@0
  1947
		cp->Free(chunkalloc[1]);
sl@0
  1948
		cp->Free(chunkalloc[0]);
sl@0
  1949
		cp->Free(chunkalloc[4]);
sl@0
  1950
		cp->Free(chunkalloc[5]);
sl@0
  1951
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
sl@0
  1952
		chunkalloc[8] = cp->Alloc(size[8] = size[0] + size[1] + size[4] + size[5] - 32);
sl@0
  1953
		TEST(chunkalloc[8] == chunkalloc[0]);
sl@0
  1954
		chunkalloc[9] = cp->Alloc(size[9] = 32);
sl@0
  1955
		TEST(chunkalloc[9] == chunkalloc[8] + size[8]);
sl@0
  1956
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
sl@0
  1957
		// now we should have [8], [9], [6]
sl@0
  1958
sl@0
  1959
		chunkalloc[10] = cp->Alloc(size[10] = KFbServLargeChunkMinPhysicalSize - size[6] - size[8] - size[9]);
sl@0
  1960
		TEST(chunkalloc[10] == chunkalloc[6] + size[6]);
sl@0
  1961
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
sl@0
  1962
		chunkalloc[11] = cp->Alloc(size[11] = 16);
sl@0
  1963
		TEST(chunkalloc[11] == chunkalloc[10] + size[10]);
sl@0
  1964
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + (pageSize << KFbServLargeChunkGrowByShifter));
sl@0
  1965
		chunkalloc[12] = cp->Alloc(size[12] = ((pageSize << KFbServLargeChunkGrowByShifter) - 16) / 2);
sl@0
  1966
		TEST(chunkalloc[12] == chunkalloc[11] + size[11]);
sl@0
  1967
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + (pageSize << KFbServLargeChunkGrowByShifter));
sl@0
  1968
		chunkalloc[13] = cp->Alloc(size[13] = size[12]);
sl@0
  1969
		TEST(chunkalloc[13] == chunkalloc[12] + size[12]);
sl@0
  1970
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + (pageSize << KFbServLargeChunkGrowByShifter));
sl@0
  1971
		chunkalloc[14] = cp->Alloc(size[14] = pageSize << KFbServLargeChunkGrowByShifter);
sl@0
  1972
		TEST(chunkalloc[14] == chunkalloc[13] + size[13]);
sl@0
  1973
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + 2 * (pageSize << KFbServLargeChunkGrowByShifter));
sl@0
  1974
		chunkalloc[15] = cp->Alloc(size[15] = (pageSize << KFbServLargeChunkGrowByShifter) + 4);
sl@0
  1975
		TEST(chunkalloc[15] == chunkalloc[14] + size[14]);
sl@0
  1976
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + 4 * (pageSize << KFbServLargeChunkGrowByShifter));
sl@0
  1977
		// now we should have [8], [9], [6], [10], [11], [12], [13], [14], [15]
sl@0
  1978
sl@0
  1979
		cp->Free(chunkalloc[15]);
sl@0
  1980
		cp->Free(chunkalloc[14]);
sl@0
  1981
		cp->Free(chunkalloc[13]);
sl@0
  1982
		cp->Free(chunkalloc[12]);
sl@0
  1983
		cp->Free(chunkalloc[11]);
sl@0
  1984
		cp->Free(chunkalloc[10]);
sl@0
  1985
		cp->Free(chunkalloc[9]);
sl@0
  1986
		cp->Free(chunkalloc[8]);
sl@0
  1987
		cp->Free(chunkalloc[6]);
sl@0
  1988
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
sl@0
  1989
sl@0
  1990
		TEST(cp->Alloc(virtualSize) == NULL);
sl@0
  1991
sl@0
  1992
		TInt largeSize = 4 * pageSize;
sl@0
  1993
		chunkalloc[0] = cp->Alloc(size[0] = 2 * largeSize);
sl@0
  1994
		TEST(chunkalloc[0] == chunkLargeBase);
sl@0
  1995
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0]);
sl@0
  1996
		chunkalloc[1] = cp->Alloc(2 * largeSize + 1);
sl@0
  1997
		size[1] = 2 * largeSize + pageSize;
sl@0
  1998
		TEST(chunkalloc[1] == chunkalloc[0] + size[0]);
sl@0
  1999
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[1]);
sl@0
  2000
		chunkalloc[2] = cp->Alloc(size[2] = 3 * largeSize + pageSize);
sl@0
  2001
		TEST(chunkalloc[2] == chunkalloc[1] + size[1]);
sl@0
  2002
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[1] + size[2]);
sl@0
  2003
		// now we should have [0], [1], [2]
sl@0
  2004
sl@0
  2005
		cp->Free(chunkalloc[1]);
sl@0
  2006
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[2]);
sl@0
  2007
		chunkalloc[3] = cp->Alloc(largeSize + 1);
sl@0
  2008
		size[3] = largeSize + pageSize;
sl@0
  2009
		TEST(chunkalloc[3] == chunkalloc[1]);
sl@0
  2010
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[2] + size[3]);
sl@0
  2011
		chunkalloc[4] = cp->Alloc(size[4] = largeSize);
sl@0
  2012
		TEST(chunkalloc[4] == chunkalloc[3] + size[3]);
sl@0
  2013
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[2] + size[3] + size[4]);
sl@0
  2014
		chunkalloc[5] = cp->Alloc(size[5] = 64 * largeSize);
sl@0
  2015
		TEST(chunkalloc[5] == chunkalloc[2] + size[2]);
sl@0
  2016
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[0] + size[2] + size[3] + size[4] + size[5]);
sl@0
  2017
		// now we should have [0], [3], [4], [2], [5]
sl@0
  2018
sl@0
  2019
		cp->Free(chunkalloc[0]);
sl@0
  2020
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[2] + size[3] + size[4] + size[5]);
sl@0
  2021
		cp->Free(chunkalloc[2]);
sl@0
  2022
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[3] + size[4] + size[5]);
sl@0
  2023
		cp->Free(chunkalloc[3]);
sl@0
  2024
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[4] + size[5]);
sl@0
  2025
		cp->Free(chunkalloc[4]);
sl@0
  2026
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize + size[5]);
sl@0
  2027
		cp->Free(chunkalloc[5]);
sl@0
  2028
		TEST(chunk.Size() == KFbServLargeChunkMinPhysicalSize);
sl@0
  2029
		}
sl@0
  2030
sl@0
  2031
	CleanupStack::PopAndDestroy(2, &chunk); // cp, chunk
sl@0
  2032
	}
sl@0
  2033
sl@0
  2034
/**
sl@0
  2035
	@SYMTestCaseID
sl@0
  2036
	GRAPHICS-FBSERV-0527
sl@0
  2037
sl@0
  2038
	@SYMTestCaseDesc
sl@0
  2039
	Creates large bitmaps of different colour depth. 
sl@0
  2040
sl@0
  2041
	@SYMTestActions
sl@0
  2042
	The bitmaps allocated are too big so
sl@0
  2043
	the allocation should fail.
sl@0
  2044
	
sl@0
  2045
	@SYMTestExpectedResults
sl@0
  2046
	KErrNoMemory when allocating the bitmaps. 
sl@0
  2047
*/
sl@0
  2048
void CTBitmap::LargeBitmaps()
sl@0
  2049
	{
sl@0
  2050
	INFO_PRINTF1(_L("Test Large Bitmaps"));
sl@0
  2051
sl@0
  2052
	TMemoryInfoV1Buf membuf;
sl@0
  2053
	UserHal::MemoryInfo(membuf);
sl@0
  2054
	const TReal maxmem = membuf().iTotalRamInBytes;
sl@0
  2055
sl@0
  2056
	TReal realSize = 0;
sl@0
  2057
	TInt ret = Math::Sqrt(realSize,maxmem);
sl@0
  2058
	TEST2(ret, KErrNone);
sl@0
  2059
	TInt32 size = 0;
sl@0
  2060
	ret = Math::Int(size,realSize);
sl@0
  2061
	TEST2(ret, KErrNone);
sl@0
  2062
sl@0
  2063
	DoLargeBitmaps(TSize(size * 8,size),EGray2);
sl@0
  2064
	DoLargeBitmaps(TSize(size * 4,size),EGray4);
sl@0
  2065
	DoLargeBitmaps(TSize(size * 2,size),EGray16);
sl@0
  2066
	DoLargeBitmaps(TSize(size,size),EGray256);
sl@0
  2067
	DoLargeBitmaps(TSize(size * 2,size),EColor16);
sl@0
  2068
	DoLargeBitmaps(TSize(size,size),EColor256);
sl@0
  2069
	DoLargeBitmaps(TSize(size / 2,size),EColor4K);
sl@0
  2070
	DoLargeBitmaps(TSize(size / 2,size),EColor64K);
sl@0
  2071
	DoLargeBitmaps(TSize(size / 3,size),EColor16M);
sl@0
  2072
	DoLargeBitmaps(TSize(size / 4,size),EColor16MU);
sl@0
  2073
	DoLargeBitmaps(TSize(size / 4,size),EColor16MAP);
sl@0
  2074
	}
sl@0
  2075
sl@0
  2076
void CTBitmap::DoLargeBitmaps(const TSize& aSize,TDisplayMode aDisplayMode)
sl@0
  2077
	{
sl@0
  2078
	CFbsBitmapEx bmp1;
sl@0
  2079
	TInt ret = bmp1.Create(aSize,aDisplayMode);
sl@0
  2080
	TEST2(ret, KErrNoMemory);
sl@0
  2081
	}
sl@0
  2082
sl@0
  2083
/**
sl@0
  2084
	@SYMTestCaseID
sl@0
  2085
	GRAPHICS-FBSERV-0528
sl@0
  2086
sl@0
  2087
	@SYMTestCaseDesc
sl@0
  2088
	Check error handling for bitmaps above pixel and byte size limits
sl@0
  2089
sl@0
  2090
	@SYMTestActions
sl@0
  2091
	
sl@0
  2092
	@SYMTestExpectedResults
sl@0
  2093
	Test should pass
sl@0
  2094
*/
sl@0
  2095
void CTBitmap::HugeBitmaps()
sl@0
  2096
	{
sl@0
  2097
	// Check error handling for bitmaps above pixel and byte size limits
sl@0
  2098
	INFO_PRINTF1(_L("Test Huge Bitmaps"));
sl@0
  2099
sl@0
  2100
	const TInt KLargePixelSize = 50000;
sl@0
  2101
sl@0
  2102
	DoHugeBitmaps(TSize(KLargePixelSize * 8,KLargePixelSize),EGray2);
sl@0
  2103
	DoHugeBitmaps(TSize(KLargePixelSize * 4,KLargePixelSize),EGray4);
sl@0
  2104
	DoHugeBitmaps(TSize(KLargePixelSize * 2,KLargePixelSize),EGray16);
sl@0
  2105
	DoHugeBitmaps(TSize(KLargePixelSize,KLargePixelSize),EGray256);
sl@0
  2106
	DoHugeBitmaps(TSize(KLargePixelSize * 2,KLargePixelSize),EColor16);
sl@0
  2107
	DoHugeBitmaps(TSize(KLargePixelSize,KLargePixelSize),EColor256);
sl@0
  2108
	DoHugeBitmaps(TSize(KLargePixelSize / 2,KLargePixelSize),EColor4K);
sl@0
  2109
	DoHugeBitmaps(TSize(KLargePixelSize / 2,KLargePixelSize),EColor64K);
sl@0
  2110
	DoHugeBitmaps(TSize(KLargePixelSize / 3,KLargePixelSize),EColor16M);
sl@0
  2111
	DoHugeBitmaps(TSize(KLargePixelSize / 4,KLargePixelSize),EColor16MU);
sl@0
  2112
	DoHugeBitmaps(TSize(KLargePixelSize / 4,KLargePixelSize),EColor16MAP);
sl@0
  2113
	}
sl@0
  2114
sl@0
  2115
void CTBitmap::DoHugeBitmaps(const TSize& aSize,TDisplayMode aDisplayMode)
sl@0
  2116
	{
sl@0
  2117
	const TInt KMaxPixelSize = KMaxTInt / 4 + 1;
sl@0
  2118
sl@0
  2119
	CFbsBitmap bmp;
sl@0
  2120
sl@0
  2121
	TInt ret = bmp.Create(TSize(aSize.iWidth / 2,aSize.iHeight / 2),aDisplayMode);
sl@0
  2122
	TEST2(ret, KErrNoMemory);
sl@0
  2123
sl@0
  2124
	ret = bmp.Create(aSize,aDisplayMode);
sl@0
  2125
	TEST2(ret, KErrTooBig);
sl@0
  2126
sl@0
  2127
	ret = bmp.Create(TSize(1,KMaxPixelSize),aDisplayMode);
sl@0
  2128
	TEST2(ret, KErrTooBig);
sl@0
  2129
sl@0
  2130
	ret = bmp.Create(TSize(KMaxPixelSize,1),aDisplayMode);
sl@0
  2131
	TEST2(ret, KErrTooBig);
sl@0
  2132
sl@0
  2133
	ret = bmp.Create(TSize(KMaxPixelSize,KMaxPixelSize),aDisplayMode);
sl@0
  2134
	TEST2(ret, KErrTooBig);
sl@0
  2135
sl@0
  2136
	ret = bmp.Create(TSize(KMaxTInt,KMaxTInt),aDisplayMode);
sl@0
  2137
	TEST2(ret, KErrTooBig);
sl@0
  2138
sl@0
  2139
sl@0
  2140
	ret = bmp.Create(TSize(1,1),aDisplayMode);
sl@0
  2141
	TEST2(ret, KErrNone);
sl@0
  2142
sl@0
  2143
	ret = bmp.Resize(TSize(aSize.iWidth / 2,aSize.iHeight / 2));
sl@0
  2144
	TEST2(ret, KErrNoMemory);
sl@0
  2145
sl@0
  2146
	ret = bmp.Resize(aSize);
sl@0
  2147
	TEST2(ret, KErrTooBig);
sl@0
  2148
sl@0
  2149
	ret = bmp.Resize(TSize(1,KMaxPixelSize));
sl@0
  2150
	TEST2(ret, KErrTooBig);
sl@0
  2151
sl@0
  2152
	ret = bmp.Resize(TSize(KMaxPixelSize,1));
sl@0
  2153
	TEST2(ret, KErrTooBig);
sl@0
  2154
sl@0
  2155
	ret = bmp.Resize(TSize(KMaxPixelSize,KMaxPixelSize));
sl@0
  2156
	TEST2(ret, KErrTooBig);
sl@0
  2157
sl@0
  2158
	ret = bmp.Resize(TSize(KMaxTInt,KMaxTInt));
sl@0
  2159
	TEST2(ret, KErrTooBig);
sl@0
  2160
sl@0
  2161
	bmp.Reset();
sl@0
  2162
	}
sl@0
  2163
sl@0
  2164
/**
sl@0
  2165
	@SYMTestCaseID
sl@0
  2166
	GRAPHICS-FBSERV-0529
sl@0
  2167
sl@0
  2168
	@SYMTestCaseDesc
sl@0
  2169
	Resizes a bitmap to a larger size and
sl@0
  2170
	checks if the new bitmap is as expected
sl@0
  2171
	
sl@0
  2172
	@SYMTestActions
sl@0
  2173
	
sl@0
  2174
	@SYMTestExpectedResults
sl@0
  2175
	Test should pass
sl@0
  2176
*/
sl@0
  2177
void CTBitmap::Resize()
sl@0
  2178
	{
sl@0
  2179
	INFO_PRINTF1(_L("Test Resizing"));
sl@0
  2180
sl@0
  2181
	DoResize(EGray2);
sl@0
  2182
	DoResize(EGray4);
sl@0
  2183
	DoResize(EGray16);
sl@0
  2184
	DoResize(EGray256);
sl@0
  2185
	DoResize(EColor16);
sl@0
  2186
	DoResize(EColor256);
sl@0
  2187
	DoResize(EColor4K);
sl@0
  2188
	DoResize(EColor64K);
sl@0
  2189
	DoResize(EColor16M);
sl@0
  2190
	DoResize(EColor16MU);
sl@0
  2191
	DoResize(EColor16MAP);
sl@0
  2192
	}
sl@0
  2193
sl@0
  2194
void CTBitmap::DoResize(TDisplayMode aDispMode)
sl@0
  2195
	{
sl@0
  2196
	const TSize KBitmapOriginalSize(256,24);
sl@0
  2197
	const TSize KBitmapLargeSize(288,32);
sl@0
  2198
	const TSize KBitmapSmallSize(1,1);
sl@0
  2199
sl@0
  2200
	CFbsBitmapEx bmp;
sl@0
  2201
	TInt ret = bmp.Create(KBitmapOriginalSize,aDispMode);
sl@0
  2202
	TEST2(ret, KErrNone);
sl@0
  2203
	bmp.SetSizeInTwips(KBitmapOriginalSize);
sl@0
  2204
	TEST(bmp.SizeInPixels() == KBitmapOriginalSize);
sl@0
  2205
	TEST(bmp.SizeInTwips() == KBitmapOriginalSize);
sl@0
  2206
sl@0
  2207
	CBitwiseBitmap* bb = bmp.BitmapAddress();
sl@0
  2208
	bmp.LockHeap();
sl@0
  2209
	TUint32* base = bmp.DataAddress();
sl@0
  2210
	bmp.UnlockHeap();
sl@0
  2211
sl@0
  2212
	TInt scanLineLength = CFbsBitmap::ScanLineLength(256,aDispMode);
sl@0
  2213
	TInt blockStart = scanLineLength / 4;
sl@0
  2214
	TInt blockLength = scanLineLength / 2;
sl@0
  2215
sl@0
  2216
	TInt row;
sl@0
  2217
	for(row = 8; row < 16; row++)
sl@0
  2218
		{
sl@0
  2219
		TUint8* bmpadd = (TUint8*)bb->ScanLineAddress(base,row);
sl@0
  2220
		Mem::FillZ(bmpadd + blockStart,blockLength);
sl@0
  2221
		}
sl@0
  2222
sl@0
  2223
	ret = bmp.Resize(KBitmapLargeSize);
sl@0
  2224
	TEST2(ret, KErrNone);
sl@0
  2225
	TEST(bmp.SizeInPixels() == KBitmapLargeSize);
sl@0
  2226
	TEST(bmp.SizeInTwips() == KBitmapLargeSize);
sl@0
  2227
	bb = bmp.BitmapAddress();
sl@0
  2228
	bmp.LockHeap();
sl@0
  2229
	base = bmp.DataAddress();
sl@0
  2230
	bmp.UnlockHeap();
sl@0
  2231
	scanLineLength = CFbsBitmap::ScanLineLength(288,aDispMode);
sl@0
  2232
sl@0
  2233
	for(row = 0; row < 8; row++)
sl@0
  2234
		{
sl@0
  2235
		TUint8* bmpadd=(TUint8*)bb->ScanLineAddress(base,row);
sl@0
  2236
		CheckWhite(bmpadd,scanLineLength,aDispMode);
sl@0
  2237
		}
sl@0
  2238
sl@0
  2239
	for(row = 16; row < 32; row++)
sl@0
  2240
		{
sl@0
  2241
		TUint8* bmpadd=(TUint8*)bb->ScanLineAddress(base,row);
sl@0
  2242
		CheckWhite(bmpadd,scanLineLength,aDispMode);
sl@0
  2243
		}
sl@0
  2244
sl@0
  2245
	for(row = 8; row < 16; row++)
sl@0
  2246
		{
sl@0
  2247
		TUint8* bmpadd=(TUint8*)bb->ScanLineAddress(base,row);
sl@0
  2248
		CheckWhite(bmpadd,blockStart,aDispMode);
sl@0
  2249
sl@0
  2250
		TUint8* ptr = bmpadd + blockStart;
sl@0
  2251
		TUint8* ptrLimit = ptr + blockLength;
sl@0
  2252
		while (ptr < ptrLimit)
sl@0
  2253
			TEST(*ptr++ == 0);
sl@0
  2254
sl@0
  2255
		CheckWhite(ptr,scanLineLength - blockStart - blockLength,aDispMode);
sl@0
  2256
		}
sl@0
  2257
sl@0
  2258
	ret = bmp.Resize(KBitmapSmallSize);
sl@0
  2259
	TEST2(ret, KErrNone);
sl@0
  2260
	TEST(bmp.SizeInPixels() == KBitmapSmallSize);
sl@0
  2261
	TEST(bmp.SizeInTwips() == KBitmapSmallSize);
sl@0
  2262
sl@0
  2263
	ret = bmp.Resize(KBitmapOriginalSize);
sl@0
  2264
	TEST2(ret, KErrNone);
sl@0
  2265
	TEST(bmp.SizeInPixels() == KBitmapOriginalSize);
sl@0
  2266
	TEST(bmp.SizeInTwips() == KBitmapOriginalSize);
sl@0
  2267
sl@0
  2268
	bmp.Reset();
sl@0
  2269
	}
sl@0
  2270
sl@0
  2271
void CTBitmap::CheckWhite(TUint8* aData,TInt aDataLength,TDisplayMode aDispMode)
sl@0
  2272
	{
sl@0
  2273
	TUint8* dataLimit = aData + aDataLength;
sl@0
  2274
sl@0
  2275
	if (aDispMode != EColor4K)
sl@0
  2276
		{
sl@0
  2277
		while (aData < dataLimit)
sl@0
  2278
			TEST(*aData++ == 0xff);
sl@0
  2279
		}
sl@0
  2280
	else
sl@0
  2281
		{
sl@0
  2282
		while (aData < dataLimit)
sl@0
  2283
			{
sl@0
  2284
			TEST(*aData == 0xff || *aData == 0x0f);
sl@0
  2285
			aData++;
sl@0
  2286
			}
sl@0
  2287
		}
sl@0
  2288
	}
sl@0
  2289
sl@0
  2290
/**
sl@0
  2291
	@SYMTestCaseID
sl@0
  2292
	GRAPHICS-FBSERV-0530
sl@0
  2293
sl@0
  2294
	@SYMTestCaseDesc
sl@0
  2295
	Creates BitmapUtil objects and sets the
sl@0
  2296
	current position to different positions
sl@0
  2297
	and retrieves and sets the pixels in these
sl@0
  2298
	and compares it to another Bitmap Util object
sl@0
  2299
	
sl@0
  2300
	@SYMTestActions
sl@0
  2301
sl@0
  2302
	@SYMTestExpectedResults
sl@0
  2303
	Test should pass
sl@0
  2304
*/
sl@0
  2305
void CTBitmap::BitmapUtil()
sl@0
  2306
	{
sl@0
  2307
	INFO_PRINTF1(_L("Test Bitmap Util"));
sl@0
  2308
sl@0
  2309
	TSize bmpUtilSize1(256,4);
sl@0
  2310
	TSize bmpUtilSize2(256,1);
sl@0
  2311
	TSize bmpUtilSize3(256,256);
sl@0
  2312
	TSize bmpUtilSize4(1024,1024);
sl@0
  2313
sl@0
  2314
	INFO_PRINTF1(_L("256x4.. "));
sl@0
  2315
	DoBitmapUtil(bmpUtilSize1,EGray2);
sl@0
  2316
	DoBitmapUtil(bmpUtilSize1,EGray4);
sl@0
  2317
	DoBitmapUtil(bmpUtilSize1,EGray16);
sl@0
  2318
	DoBitmapUtil(bmpUtilSize1,EGray256);
sl@0
  2319
	DoBitmapUtil(bmpUtilSize1,EColor16);
sl@0
  2320
	DoBitmapUtil(bmpUtilSize1,EColor256);
sl@0
  2321
	DoBitmapUtil(bmpUtilSize1,EColor4K);
sl@0
  2322
	DoBitmapUtil(bmpUtilSize1,EColor64K);
sl@0
  2323
	DoBitmapUtil(bmpUtilSize1,EColor16M);
sl@0
  2324
	DoBitmapUtil(bmpUtilSize1,EColor16MU);
sl@0
  2325
	DoBitmapUtil(bmpUtilSize1,EColor16MAP);
sl@0
  2326
sl@0
  2327
	INFO_PRINTF1(_L("256x1.. "));
sl@0
  2328
	DoBitmapUtil(bmpUtilSize2,EGray2);
sl@0
  2329
	DoBitmapUtil(bmpUtilSize2,EGray4);
sl@0
  2330
	DoBitmapUtil(bmpUtilSize2,EGray16);
sl@0
  2331
	DoBitmapUtil(bmpUtilSize2,EGray256);
sl@0
  2332
	DoBitmapUtil(bmpUtilSize2,EColor16);
sl@0
  2333
	DoBitmapUtil(bmpUtilSize2,EColor256);
sl@0
  2334
	DoBitmapUtil(bmpUtilSize2,EColor4K);
sl@0
  2335
	DoBitmapUtil(bmpUtilSize2,EColor64K);
sl@0
  2336
	DoBitmapUtil(bmpUtilSize2,EColor16M);
sl@0
  2337
	DoBitmapUtil(bmpUtilSize2,EColor16MU);
sl@0
  2338
	DoBitmapUtil(bmpUtilSize2,EColor16MAP);
sl@0
  2339
sl@0
  2340
	INFO_PRINTF1(_L("256x256..\n"));
sl@0
  2341
	DoBitmapUtil(bmpUtilSize3,EGray2);
sl@0
  2342
	DoBitmapUtil(bmpUtilSize3,EGray4);
sl@0
  2343
	DoBitmapUtil(bmpUtilSize3,EGray16);
sl@0
  2344
	DoBitmapUtil(bmpUtilSize3,EGray256);
sl@0
  2345
	DoBitmapUtil(bmpUtilSize3,EColor16);
sl@0
  2346
	DoBitmapUtil(bmpUtilSize3,EColor256);
sl@0
  2347
	DoBitmapUtil(bmpUtilSize3,EColor4K);
sl@0
  2348
	DoBitmapUtil(bmpUtilSize3,EColor64K);
sl@0
  2349
	DoBitmapUtil(bmpUtilSize3,EColor16M);
sl@0
  2350
	DoBitmapUtil(bmpUtilSize3,EColor16MU);
sl@0
  2351
	DoBitmapUtil(bmpUtilSize3,EColor16MAP);
sl@0
  2352
		
sl@0
  2353
    INFO_PRINTF1(_L("Testing wastage bytes in 16M scanlines...\n"));
sl@0
  2354
	bmpUtilSize1.SetSize(5,13);
sl@0
  2355
	bmpUtilSize2.SetSize(6,14);
sl@0
  2356
	bmpUtilSize3.SetSize(7,15);
sl@0
  2357
	bmpUtilSize4.SetSize(8,16);
sl@0
  2358
	DoBitmapUtil(bmpUtilSize1,EColor16M);
sl@0
  2359
	DoBitmapUtil(bmpUtilSize2,EColor16M);
sl@0
  2360
	DoBitmapUtil(bmpUtilSize3,EColor16M);
sl@0
  2361
	DoBitmapUtil(bmpUtilSize4,EColor16M);
sl@0
  2362
sl@0
  2363
    /*
sl@0
  2364
	 * Test code commented out as it results in test case failure. 
sl@0
  2365
	 * Problem recorded in defect DEF001233.
sl@0
  2366
	 *
sl@0
  2367
	INFO_PRINTF1(_L("Testing wastage bits in Gray16 scanlines...\n\n"));
sl@0
  2368
	bmpUtilSize1.SetSize(4,13);
sl@0
  2369
	bmpUtilSize2.SetSize(5,14);
sl@0
  2370
	bmpUtilSize3.SetSize(6,15);
sl@0
  2371
	bmpUtilSize4.SetSize(7,16);
sl@0
  2372
	DoBitmapUtil(bmpUtilSize1,EGray16);
sl@0
  2373
	DoBitmapUtil(bmpUtilSize2,EGray16);
sl@0
  2374
	DoBitmapUtil(bmpUtilSize3,EGray16);
sl@0
  2375
	DoBitmapUtil(bmpUtilSize4,EGray16);
sl@0
  2376
	 */
sl@0
  2377
	}
sl@0
  2378
sl@0
  2379
void CTBitmap::DoBitmapUtil(const TSize& aSize,TDisplayMode aDispMode)
sl@0
  2380
	{
sl@0
  2381
	const TPoint startPoint(aSize.iWidth / 3,aSize.iHeight / 3);
sl@0
  2382
	const TPoint zeroPoint(0,0);
sl@0
  2383
sl@0
  2384
	CFbsBitmapEx bmp1;
sl@0
  2385
	TInt ret=bmp1.Create(aSize,aDispMode);
sl@0
  2386
	TEST2(ret, KErrNone);
sl@0
  2387
	FillBitmap(bmp1);
sl@0
  2388
sl@0
  2389
sl@0
  2390
	const TInt numPixels = ((aSize.iWidth + 31) & ~0x1f) * aSize.iHeight;
sl@0
  2391
	TInt count1;
sl@0
  2392
	CFbsBitmapEx bmp2;
sl@0
  2393
sl@0
  2394
	ret=bmp2.Create(aSize,aDispMode);
sl@0
  2395
	TEST2(ret, KErrNone);
sl@0
  2396
sl@0
  2397
	TBitmapUtil util1(&bmp1);
sl@0
  2398
	util1.Begin(zeroPoint);
sl@0
  2399
	TBitmapUtil util2(&bmp2);
sl@0
  2400
	util2.Begin(zeroPoint,util1);
sl@0
  2401
sl@0
  2402
	TPoint currentPosition;
sl@0
  2403
	for (currentPosition.iY = 0; currentPosition.iY < aSize.iHeight; currentPosition.iY++)
sl@0
  2404
		for (currentPosition.iX = 0; currentPosition.iX < aSize.iWidth; currentPosition.iX++)
sl@0
  2405
			{
sl@0
  2406
			util1.SetPos(currentPosition);
sl@0
  2407
			util2.SetPos(currentPosition);
sl@0
  2408
			TUint32 pixelData = util1.GetPixel();
sl@0
  2409
			util2.SetPixel(pixelData);
sl@0
  2410
			}
sl@0
  2411
	util1.End();
sl@0
  2412
	util2.End();
sl@0
  2413
	CompareBitmaps(bmp1,bmp2,EColor16M);
sl@0
  2414
	bmp2.Reset();
sl@0
  2415
sl@0
  2416
	ret=bmp2.Create(aSize,aDispMode);
sl@0
  2417
	TEST2(ret, KErrNone);
sl@0
  2418
	util1.Begin(startPoint);
sl@0
  2419
	util2.Begin(startPoint,util1);
sl@0
  2420
	for (count1 = 0; count1 < numPixels; count1++)
sl@0
  2421
		{
sl@0
  2422
		util2.SetPixel(util1);
sl@0
  2423
		util1.IncXPos();
sl@0
  2424
		util2.IncXPos();
sl@0
  2425
		}
sl@0
  2426
	util1.End();
sl@0
  2427
	util2.End();
sl@0
  2428
	CompareBitmaps(bmp1,bmp2,EColor16M);
sl@0
  2429
	bmp2.Reset();
sl@0
  2430
sl@0
  2431
	ret=bmp2.Create(aSize,aDispMode);
sl@0
  2432
	TEST2(ret, KErrNone);
sl@0
  2433
	util1.Begin(zeroPoint);
sl@0
  2434
	util2.Begin(zeroPoint,util1);
sl@0
  2435
	for (currentPosition.iX = 0; currentPosition.iX < aSize.iWidth; currentPosition.iX++)
sl@0
  2436
		{
sl@0
  2437
		for (currentPosition.iY = 0; currentPosition.iY < aSize.iHeight; currentPosition.iY++)
sl@0
  2438
			{
sl@0
  2439
			util2.SetPixel(util1);
sl@0
  2440
			util1.IncYPos();
sl@0
  2441
			util2.IncYPos();
sl@0
  2442
			}
sl@0
  2443
		util1.IncXPos();
sl@0
  2444
		util2.IncXPos();
sl@0
  2445
		}
sl@0
  2446
	util1.End();
sl@0
  2447
	util2.End();
sl@0
  2448
	CompareBitmaps(bmp1,bmp2,EColor16M);
sl@0
  2449
	bmp2.Reset();
sl@0
  2450
sl@0
  2451
	ret=bmp2.Create(aSize,aDispMode);
sl@0
  2452
	TEST2(ret, KErrNone);
sl@0
  2453
	util1.Begin(startPoint);
sl@0
  2454
	util2.Begin(startPoint,util1);
sl@0
  2455
	for (count1 = 0; count1 < numPixels; count1++)
sl@0
  2456
		{
sl@0
  2457
		util2.SetPixel(util1);
sl@0
  2458
		util1.DecXPos();
sl@0
  2459
		util2.DecXPos();
sl@0
  2460
		}
sl@0
  2461
	util1.End();
sl@0
  2462
	util2.End();
sl@0
  2463
	CompareBitmaps(bmp1,bmp2,EColor16M);
sl@0
  2464
	bmp2.Reset();
sl@0
  2465
sl@0
  2466
	ret=bmp2.Create(aSize,aDispMode);
sl@0
  2467
	TEST2(ret, KErrNone);
sl@0
  2468
	util1.Begin(zeroPoint);
sl@0
  2469
	util2.Begin(zeroPoint,util1);
sl@0
  2470
	for (currentPosition.iX = 0; currentPosition.iX < aSize.iWidth; currentPosition.iX++)
sl@0
  2471
		{
sl@0
  2472
		for (currentPosition.iY = 0; currentPosition.iY < aSize.iHeight; currentPosition.iY++)
sl@0
  2473
			{
sl@0
  2474
			util2.SetPixel(util1);
sl@0
  2475
			util1.DecYPos();
sl@0
  2476
			util2.DecYPos();
sl@0
  2477
			}
sl@0
  2478
		util1.DecXPos();
sl@0
  2479
		util2.DecXPos();
sl@0
  2480
		}
sl@0
  2481
	util1.End();
sl@0
  2482
	util2.End();
sl@0
  2483
	CompareBitmaps(bmp1,bmp2,EColor16M);
sl@0
  2484
	bmp2.Reset();
sl@0
  2485
sl@0
  2486
	bmp1.Reset();
sl@0
  2487
	}
sl@0
  2488
sl@0
  2489
void CTBitmap::BitmapTiming()
sl@0
  2490
	{
sl@0
  2491
	INFO_PRINTF1(_L("Test Timing"));
sl@0
  2492
sl@0
  2493
	CFbsBitmap bmp;
sl@0
  2494
	TInt ret=bmp.Load(iTestBitmapName,ETfbs,NULL);
sl@0
  2495
	TEST2(ret, KErrNone);
sl@0
  2496
sl@0
  2497
	CDirectFileStore* writestore=NULL;
sl@0
  2498
	TRAP(ret,writestore=CDirectFileStore::ReplaceL(iFs,KTempFilename,EFileStream|EFileWrite));
sl@0
  2499
	TEST2(ret, KErrNone);
sl@0
  2500
	TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
sl@0
  2501
	TRAP(ret,writestore->SetTypeL(uidtype));
sl@0
  2502
	TEST2(ret, KErrNone);
sl@0
  2503
	RStoreWriteStream writestrm;
sl@0
  2504
	TStreamId headerid(0);
sl@0
  2505
	TRAP(ret,headerid=writestrm.CreateL(*writestore));
sl@0
  2506
	TEST2(ret, KErrNone);
sl@0
  2507
	TRAP(ret,writestore->SetRootL(headerid));
sl@0
  2508
	TEST2(ret, KErrNone);
sl@0
  2509
	INFO_PRINTF1(_L("Save time: "));
sl@0
  2510
	TUint startTime=User::TickCount();
sl@0
  2511
	for(TInt count=0;count<5000;count++)
sl@0
  2512
		{
sl@0
  2513
		TRAP(ret,bmp.ExternalizeL(writestrm));
sl@0
  2514
		if(ret) break;
sl@0
  2515
		}
sl@0
  2516
	TUint stopTime=User::TickCount();
sl@0
  2517
	TEST2(ret, KErrNone);
sl@0
  2518
	writestrm.Close();
sl@0
  2519
	delete writestore;
sl@0
  2520
	INFO_PRINTF2(_L("%d ticks\r\n"),stopTime-startTime);
sl@0
  2521
sl@0
  2522
	CDirectFileStore* readstore=NULL;
sl@0
  2523
	TRAP(ret,readstore=CDirectFileStore::OpenL(iFs,KTempFilename,EFileStream|EFileRead));
sl@0
  2524
	TEST2(ret, KErrNone);
sl@0
  2525
	RStoreReadStream readstrm;
sl@0
  2526
	headerid=readstore->Root();
sl@0
  2527
	INFO_PRINTF1(_L("Load time: "));
sl@0
  2528
	startTime=User::TickCount();
sl@0
  2529
	for(TInt count2=0;count2<5000;count2++)
sl@0
  2530
		{
sl@0
  2531
		TRAP(ret,readstrm.OpenL(*readstore,headerid));
sl@0
  2532
		if(ret) break;
sl@0
  2533
		TRAP(ret,bmp.InternalizeL(readstrm));
sl@0
  2534
		if(ret) break;
sl@0
  2535
		readstrm.Close();
sl@0
  2536
		}
sl@0
  2537
	stopTime=User::TickCount();
sl@0
  2538
	TEST2(ret, KErrNone);
sl@0
  2539
	delete readstore;
sl@0
  2540
	INFO_PRINTF2(_L("%d ticks\r\n"),stopTime-startTime);
sl@0
  2541
sl@0
  2542
	bmp.Reset();
sl@0
  2543
	iFs.Delete(KTempFilename);
sl@0
  2544
sl@0
  2545
	
sl@0
  2546
	}
sl@0
  2547
sl@0
  2548
/**
sl@0
  2549
	@SYMTestCaseID
sl@0
  2550
	GRAPHICS-FBSERV-0531
sl@0
  2551
sl@0
  2552
	@SYMTestCaseDesc
sl@0
  2553
	Tries to load non existing bitmaps from the
sl@0
  2554
	Z-drive.
sl@0
  2555
sl@0
  2556
	@SYMTestActions
sl@0
  2557
sl@0
  2558
	@SYMTestExpectedResults
sl@0
  2559
	Test should pass
sl@0
  2560
*/
sl@0
  2561
void CTBitmap::InvalidBitmap()
sl@0
  2562
	{
sl@0
  2563
	INFO_PRINTF1(_L("Test Invalid Bitmap"));
sl@0
  2564
sl@0
  2565
	__UHEAP_MARK;
sl@0
  2566
	CFbsBitmapEx bmp;
sl@0
  2567
sl@0
  2568
	TInt ret=bmp.Load(_L("z:\\tfbsx.mbm"),ETfbs,NULL);
sl@0
  2569
	TEST2(ret, KErrNotFound);
sl@0
  2570
	ret=bmp.Load(_L("z:\\tfbs.xbm"),ETfbs,NULL);
sl@0
  2571
	TEST2(ret, KErrNotFound);
sl@0
  2572
	ret=bmp.Load(iTestBitmapName,999,NULL);
sl@0
  2573
	TEST2(ret, KErrEof);
sl@0
  2574
	ret=bmp.Load(iTestBitmapName,-1,NULL);
sl@0
  2575
	TEST2(ret, KErrEof);
sl@0
  2576
sl@0
  2577
	bmp.Reset();
sl@0
  2578
	User::Heap().Check();
sl@0
  2579
	__UHEAP_MARKEND;
sl@0
  2580
sl@0
  2581
	
sl@0
  2582
	}
sl@0
  2583
sl@0
  2584
/**
sl@0
  2585
	@SYMTestCaseID
sl@0
  2586
	GRAPHICS-FBSERV-0532
sl@0
  2587
sl@0
  2588
	@SYMTestCaseDesc
sl@0
  2589
	Creates bitmaps and saves them to the C-drive
sl@0
  2590
	and loads them back again and compares them to
sl@0
  2591
	the original bitmaps. 
sl@0
  2592
sl@0
  2593
	@SYMTestActions
sl@0
  2594
	The test uses different colour depths and sizes
sl@0
  2595
	of the bitmaps. The sizes of the bitmaps are
sl@0
  2596
	large.
sl@0
  2597
sl@0
  2598
	@SYMTestExpectedResults
sl@0
  2599
	Test should pass
sl@0
  2600
*/
sl@0
  2601
void CTBitmap::SaveAndLoad()
sl@0
  2602
	{
sl@0
  2603
	INFO_PRINTF1(_L("Test Save/Load Bitmap"));