os/graphics/graphicsdeviceinterface/directgdi/test/tbitbltbase.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-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
#include "tbitbltbase.h"
sl@0
    17
sl@0
    18
sl@0
    19
CTBitBltBase::CTBitBltBase()
sl@0
    20
	{
sl@0
    21
	
sl@0
    22
	}
sl@0
    23
sl@0
    24
CTBitBltBase::~CTBitBltBase()
sl@0
    25
	{
sl@0
    26
	}
sl@0
    27
sl@0
    28
/** 
sl@0
    29
Override of base class pure virtual
sl@0
    30
Our implementation only gets called if the base class doTestStepPreambleL() did
sl@0
    31
not leave. That being the case, the current test result value will be EPass.
sl@0
    32
@leave Gets system wide error code
sl@0
    33
@return TVerdict code
sl@0
    34
*/	
sl@0
    35
TVerdict CTBitBltBase::doTestStepL()
sl@0
    36
	{
sl@0
    37
	// Test for each target pixel format
sl@0
    38
	for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
sl@0
    39
		{
sl@0
    40
		iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
sl@0
    41
		TBuf<KPixelFormatNameLength> targetPixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iTargetPixelFormat));
sl@0
    42
sl@0
    43
		// Test for each source pixel format
sl@0
    44
		for(TInt sourcePixelFormatIndex = iSourcePixelFormatArray.Count() - 1; sourcePixelFormatIndex >= 0; sourcePixelFormatIndex--)
sl@0
    45
			{
sl@0
    46
			TBool isEColor256 = EFalse;
sl@0
    47
			iTestParams.iSourcePixelFormat = iSourcePixelFormatArray[sourcePixelFormatIndex];
sl@0
    48
			if(EUidPixelFormatP_8 == iTestParams.iSourcePixelFormat)
sl@0
    49
				isEColor256 = ETrue;
sl@0
    50
			TBuf<KPixelFormatNameLength> sourcePixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iSourcePixelFormat));
sl@0
    51
sl@0
    52
			INFO_PRINTF3(_L("Target Pixel Format: %S;  Source Pixel Format: %S"), &targetPixelFormatName, &sourcePixelFormatName);
sl@0
    53
sl@0
    54
			// small target
sl@0
    55
			SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KTarget1Size);
sl@0
    56
			iLargeTarget = EFalse;
sl@0
    57
			
sl@0
    58
			// create source bitmaps for tests
sl@0
    59
			CreateBitmapsL(iTestParams.iSourcePixelFormat);
sl@0
    60
			RunTestsL();
sl@0
    61
			// only run OOM tests for one target pixel format to prevent duplication of tests
sl@0
    62
			if ((targetPixelFormatIndex == 0) && isEColor256)
sl@0
    63
				{
sl@0
    64
				RunOomTestsL();  //from base class
sl@0
    65
				}
sl@0
    66
			// delete source bitmaps
sl@0
    67
			DeleteBitmaps();
sl@0
    68
						
sl@0
    69
			// large target
sl@0
    70
			SetTargetL(iTestParams.iTargetPixelFormat, EOneContextOneTarget, KTarget2Size);
sl@0
    71
			iLargeTarget = ETrue;
sl@0
    72
			
sl@0
    73
			// create source bitmaps for tests
sl@0
    74
			CreateBitmapsL(iTestParams.iSourcePixelFormat);
sl@0
    75
			RunTestsL();
sl@0
    76
			if ((targetPixelFormatIndex == 0) && isEColor256)
sl@0
    77
				{
sl@0
    78
				RunOomTestsL();  //from base class
sl@0
    79
				}
sl@0
    80
			// delete source bitmaps
sl@0
    81
			DeleteBitmaps();
sl@0
    82
			}
sl@0
    83
		}
sl@0
    84
	CloseTMSGraphicsStep();
sl@0
    85
sl@0
    86
	return TestStepResult();
sl@0
    87
	}
sl@0
    88
sl@0
    89
/**
sl@0
    90
Override of base class virtual
sl@0
    91
@leave Gets system wide error code
sl@0
    92
@return - TVerdict code
sl@0
    93
*/
sl@0
    94
TVerdict CTBitBltBase::doTestStepPreambleL()
sl@0
    95
	{
sl@0
    96
	CTDirectGdiStepBase::doTestStepPreambleL();
sl@0
    97
	return TestStepResult();
sl@0
    98
	}
sl@0
    99
sl@0
   100
/**
sl@0
   101
Override of base class virtual
sl@0
   102
@leave Gets system wide error code
sl@0
   103
@return - TVerdict code
sl@0
   104
*/
sl@0
   105
TVerdict CTBitBltBase::doTestStepPostambleL()
sl@0
   106
	{
sl@0
   107
	DeleteBitmaps();
sl@0
   108
	CTDirectGdiStepBase::doTestStepPostambleL();
sl@0
   109
	return TestStepResult();
sl@0
   110
	}
sl@0
   111
sl@0
   112
/**
sl@0
   113
Write target output.
sl@0
   114
Call method from base class with test case name and source pixel format string.
sl@0
   115
@param aTestCaseName Name of test case.
sl@0
   116
*/
sl@0
   117
void CTBitBltBase::WriteTargetOutput(TPtrC aTestCaseName)
sl@0
   118
	{	
sl@0
   119
	TBuf<KFileNameLength> postfix;
sl@0
   120
	postfix.Append(KSourceString);
sl@0
   121
	postfix.Append(KSeparator);
sl@0
   122
	postfix.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(iTestParams.iSourcePixelFormat));
sl@0
   123
	
sl@0
   124
	TESTNOERROR(CTDirectGdiStepBase::WriteTargetOutput(iTestParams, aTestCaseName, &postfix));
sl@0
   125
	}
sl@0
   126
sl@0
   127
/**
sl@0
   128
Create set of bitmaps needed for tests.
sl@0
   129
@param aPixelFormat Source pixel format of bitmap.
sl@0
   130
*/
sl@0
   131
void CTBitBltBase::CreateBitmapsL(TUidPixelFormat aPixelFormat)
sl@0
   132
	{
sl@0
   133
	iNotInitialisedBitmap = new (ELeave)CFbsBitmap();
sl@0
   134
	iZeroSizeBitmap	 = new (ELeave)CFbsBitmap();
sl@0
   135
	TESTNOERRORL(iZeroSizeBitmap->Create(TSize(0,0),TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
sl@0
   136
	iCompressedBitmap = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(8, 8));
sl@0
   137
	iCompressedBitmap->Compress();
sl@0
   138
	iCompressedBitmapSmall = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap1Size, TSize(2,2));
sl@0
   139
	iCompressedBitmapSmall->Compress();
sl@0
   140
	iCheckedBoardBitmap1 = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap1Size, KBitmap1Size);
sl@0
   141
	iCheckedBoardBitmap2 = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(8, 8));
sl@0
   142
	iConcentricRectsBitmap1 = CreateConcentricRectsBitmapL(aPixelFormat, KBitmap1Size);
sl@0
   143
	iConcentricRectsBitmap2 = CreateConcentricRectsBitmapL(aPixelFormat, KBitmap2Size);
sl@0
   144
	iCheckedBoardWithAlphaBitmap = CreateCheckedBoardBitmapL(aPixelFormat, KBitmap2Size, TSize(16, 16), ETrue);
sl@0
   145
	}
sl@0
   146
sl@0
   147
/**
sl@0
   148
Delete set of test bitmaps.
sl@0
   149
*/
sl@0
   150
void CTBitBltBase::DeleteBitmaps()
sl@0
   151
	{	
sl@0
   152
	delete iNotInitialisedBitmap;
sl@0
   153
	iNotInitialisedBitmap = NULL;
sl@0
   154
	delete iZeroSizeBitmap;
sl@0
   155
	iZeroSizeBitmap = NULL;
sl@0
   156
	delete iCompressedBitmap;
sl@0
   157
	iCompressedBitmap = NULL;
sl@0
   158
	delete iCompressedBitmapSmall;
sl@0
   159
	iCompressedBitmapSmall = NULL;
sl@0
   160
	delete iCheckedBoardBitmap1;
sl@0
   161
	iCheckedBoardBitmap1 = NULL;
sl@0
   162
	delete iCheckedBoardBitmap2;
sl@0
   163
	iCheckedBoardBitmap2 = NULL;
sl@0
   164
	delete iConcentricRectsBitmap1;
sl@0
   165
	iConcentricRectsBitmap1 = NULL;
sl@0
   166
	delete iConcentricRectsBitmap2;
sl@0
   167
	iConcentricRectsBitmap2 = NULL;
sl@0
   168
	delete iCheckedBoardWithAlphaBitmap;
sl@0
   169
	iCheckedBoardWithAlphaBitmap = NULL;
sl@0
   170
	}
sl@0
   171
sl@0
   172
/**
sl@0
   173
Common positioning test function for BitBlt() and DrawBitmap() tests.
sl@0
   174
The test iterates positions over whole target, outside target and on the target boundaries
sl@0
   175
and call tested function for those positions.
sl@0
   176
@param aTestName Name of test case.
sl@0
   177
@param aFunc Tested function. EBitBlt and EDrawBitmap are supported.
sl@0
   178
*/
sl@0
   179
void CTBitBltBase::TestPositioningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
sl@0
   180
	{	
sl@0
   181
	CFbsBitmap* bitmap;
sl@0
   182
	if(iTestParams.iDoCompressed)
sl@0
   183
		{
sl@0
   184
		bitmap = iCompressedBitmap;
sl@0
   185
		}
sl@0
   186
	else
sl@0
   187
		{
sl@0
   188
		bitmap = iConcentricRectsBitmap1;
sl@0
   189
		}
sl@0
   190
	
sl@0
   191
	TInt width = iGdiTarget->SizeInPixels().iWidth;
sl@0
   192
	TInt height = iGdiTarget->SizeInPixels().iHeight;
sl@0
   193
	TInt bmpWidth = bitmap->SizeInPixels().iWidth;
sl@0
   194
	TInt bmpHeight = bitmap->SizeInPixels().iHeight;
sl@0
   195
	TSize bmpSize(bmpWidth, bmpHeight);
sl@0
   196
sl@0
   197
	// test two versions of function
sl@0
   198
	for(TInt i = 0; i < 2; i++)
sl@0
   199
		{
sl@0
   200
		ResetGc();
sl@0
   201
sl@0
   202
		TPositionIterator posIterator(-30, width+30, bmpWidth, -30, height+30, bmpHeight);
sl@0
   203
		posIterator.Begin();
sl@0
   204
sl@0
   205
		do
sl@0
   206
			{
sl@0
   207
			//It is done to shift the rectangle drawn. It gives a slope effect in the image.
sl@0
   208
			TPoint pos(posIterator.iPosX+posIterator.iIndexY, posIterator.iPosY+posIterator.iIndexX);
sl@0
   209
			if(aFunc == EBitBlt)
sl@0
   210
				{
sl@0
   211
				if(i == 0)
sl@0
   212
					{
sl@0
   213
					iGc->BitBlt(pos, *bitmap);
sl@0
   214
					}
sl@0
   215
				else
sl@0
   216
					{
sl@0
   217
					// additionally source rect size is iterated
sl@0
   218
					iGc->BitBlt(pos, *bitmap, TRect(TPoint(0, 0), TSize(posIterator.iIndexX, posIterator.iIndexY)));
sl@0
   219
					}
sl@0
   220
				}
sl@0
   221
			else // (aFunc == EDrawBitmap)
sl@0
   222
				{
sl@0
   223
				if(i == 0)
sl@0
   224
					{
sl@0
   225
					iGc->DrawBitmap(TRect(pos, bmpSize), *bitmap);
sl@0
   226
					}
sl@0
   227
				else
sl@0
   228
					{
sl@0
   229
					// additionally source rect size is iterated
sl@0
   230
					iGc->DrawBitmap(TRect(pos, bmpSize),*bitmap, TRect(TPoint(0, 0), TSize(posIterator.iIndexX, posIterator.iIndexY)));
sl@0
   231
					}
sl@0
   232
				}
sl@0
   233
			}
sl@0
   234
		while(posIterator.Next());
sl@0
   235
sl@0
   236
		TESTNOERRORL(iGc->GetError());
sl@0
   237
sl@0
   238
		if(!iTestParams.iDoCompressed)
sl@0
   239
			{
sl@0
   240
			// add 1 or 2 to test case name to identity function version
sl@0
   241
			TBuf<30> testName;
sl@0
   242
			testName.Append(aTestName);
sl@0
   243
			testName.AppendNum(i+1);
sl@0
   244
			WriteTargetOutput(testName);
sl@0
   245
			}
sl@0
   246
		}
sl@0
   247
	}
sl@0
   248
sl@0
   249
/**
sl@0
   250
Common invalid parameters test function for BitBlt() and DrawBitmap() tests.
sl@0
   251
The function tests against invalid source rectangle, zero size source bitmap
sl@0
   252
(both cases should return KErrArgument) and not initialised source bitmap (should
sl@0
   253
return KErrBadHandle).
sl@0
   254
@param aTestName Name of test case.
sl@0
   255
@param aFunc Tested function. EBitBlt and EDrawBitmap are supported.
sl@0
   256
*/
sl@0
   257
void CTBitBltBase::TestInvalidParametersBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
sl@0
   258
	{		
sl@0
   259
	ResetGc();
sl@0
   260
sl@0
   261
	CFbsBitmap* bitmap = iConcentricRectsBitmap2;
sl@0
   262
sl@0
   263
	TInt bmpWidth = bitmap->SizeInPixels().iWidth;
sl@0
   264
	TInt bmpHeight = bitmap->SizeInPixels().iHeight;
sl@0
   265
sl@0
   266
	// invalid source rectangle
sl@0
   267
	RArray<TRect> rectArray;
sl@0
   268
	CleanupClosePushL(rectArray);
sl@0
   269
	TInt err = KErrNone;
sl@0
   270
	err |= rectArray.Append(TRect(-30, -30, -10, -10));
sl@0
   271
	err |= rectArray.Append(TRect(bmpWidth+10, bmpHeight+10, bmpWidth+20, bmpHeight+20));
sl@0
   272
	err |= rectArray.Append(TRect(bmpWidth, bmpHeight, 0, 0));
sl@0
   273
	err |= rectArray.Append(TRect(-10, -10, -30, -30));
sl@0
   274
	err |= rectArray.Append(TRect(0, 0, 0, 0));
sl@0
   275
	TESTL(KErrNone == err);
sl@0
   276
	
sl@0
   277
	for(TInt i = 0; i < rectArray.Count(); i++)
sl@0
   278
		{
sl@0
   279
		if(aFunc == EBitBlt)
sl@0
   280
			{
sl@0
   281
			iGc->BitBlt(TPoint(i*20, 0), *bitmap, rectArray[i]);
sl@0
   282
			}
sl@0
   283
		else // (aFunc == EDrawBitmap)
sl@0
   284
			{
sl@0
   285
			iGc->DrawBitmap(TRect(TPoint(i*20, 0), TSize(50, 50)), *bitmap, rectArray[i]);
sl@0
   286
			}
sl@0
   287
		}
sl@0
   288
sl@0
   289
	TESTNOERRORL(iGc->GetError());
sl@0
   290
sl@0
   291
	CleanupStack::PopAndDestroy(&rectArray);
sl@0
   292
sl@0
   293
	if(aFunc == EBitBlt)
sl@0
   294
		{
sl@0
   295
		// invalid source bitmap, zero size bitmap
sl@0
   296
		iGc->BitBlt(TPoint(0, 20), *iZeroSizeBitmap);
sl@0
   297
		CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
sl@0
   298
		
sl@0
   299
		iGc->BitBlt(TPoint(20, 20), *iZeroSizeBitmap, TRect(TPoint(0, 0), TSize(0, 0)));
sl@0
   300
		CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
sl@0
   301
sl@0
   302
		// invalid source bitmap, not initialised bitmap
sl@0
   303
		iGc->BitBlt(TPoint(0, 40), *iNotInitialisedBitmap);
sl@0
   304
		CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
sl@0
   305
		
sl@0
   306
		iGc->BitBlt(TPoint(20, 40), *iNotInitialisedBitmap, TRect(TPoint(0, 0), TSize(0, 0)));
sl@0
   307
		CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
sl@0
   308
		}
sl@0
   309
	else // (aFunc == EDrawBitmap)
sl@0
   310
		{
sl@0
   311
		// invalid source bitmap, zero size bitmap
sl@0
   312
		iGc->DrawBitmap(TRect(TPoint(0, 20), TSize(50, 50)), *iZeroSizeBitmap);
sl@0
   313
		CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
sl@0
   314
		
sl@0
   315
		iGc->DrawBitmap(TRect(TPoint(20, 20), TSize(50, 50)), *iZeroSizeBitmap,	TRect(TPoint(0, 0), TSize(10, 10)));
sl@0
   316
		CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
sl@0
   317
sl@0
   318
		// invalid source bitmap, not initialised bitmap
sl@0
   319
		iGc->DrawBitmap(TRect(TPoint(0, 40), TSize(50, 50)), *iNotInitialisedBitmap);
sl@0
   320
		CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
sl@0
   321
		
sl@0
   322
		iGc->DrawBitmap(TRect(TPoint(20, 40), TSize(50, 50)), *iNotInitialisedBitmap,
sl@0
   323
				TRect(TPoint(0, 0), TSize(10, 10)));
sl@0
   324
		CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
sl@0
   325
		}
sl@0
   326
sl@0
   327
	// test if target is still clear
sl@0
   328
	TBool res = TestTargetL(KRgbWhite); 
sl@0
   329
	TEST(res);
sl@0
   330
	// output the bitmap if there was an error to assist with debugging
sl@0
   331
	if (res == EFalse)
sl@0
   332
		{			
sl@0
   333
		WriteTargetOutput(aTestName);
sl@0
   334
		}
sl@0
   335
	}
sl@0
   336
sl@0
   337
/**
sl@0
   338
Common source bitmap cloning test function for BitBlt() and DrawBitmap() tests.
sl@0
   339
@param aTestName Name of test case.
sl@0
   340
@param aFunc Tested function. EBitBlt and EDrawBitmap are supported.
sl@0
   341
*/
sl@0
   342
void CTBitBltBase::TestSourceBitmapCloningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
sl@0
   343
	{
sl@0
   344
	ResetGc();
sl@0
   345
sl@0
   346
	TSize bmpSize(KBitmap2Size);
sl@0
   347
sl@0
   348
	for(TInt i = 0; i < 5; i++)
sl@0
   349
		{
sl@0
   350
		CFbsBitmap* bitmap = CreateConcentricRectsBitmapL(iTestParams.iSourcePixelFormat, bmpSize);
sl@0
   351
		if(iTestParams.iDoCompressed)
sl@0
   352
			bitmap->Compress();
sl@0
   353
			
sl@0
   354
		if(aFunc == EBitBlt)
sl@0
   355
			{
sl@0
   356
			iGc->BitBlt(TPoint(55-35+i*10+1, -60+80+i*7+i), *bitmap);
sl@0
   357
			}
sl@0
   358
		else // (aFunc == EDrawBitmap)
sl@0
   359
			{
sl@0
   360
			iGc->DrawBitmap(TRect(TPoint(55-35+i*10+1, -60+80+i*7+i), bmpSize), *bitmap);
sl@0
   361
			}
sl@0
   362
sl@0
   363
		delete bitmap;
sl@0
   364
		bitmap = NULL;
sl@0
   365
sl@0
   366
		bmpSize -= TSize(10, 15);
sl@0
   367
		}
sl@0
   368
	
sl@0
   369
	TESTNOERRORL(iGc->GetError());
sl@0
   370
	if(!iTestParams.iDoCompressed)
sl@0
   371
		WriteTargetOutput(aTestName);
sl@0
   372
	}