os/graphics/graphicsdeviceinterface/directgdi/test/tdirectgdicontexttarget.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 "tdirectgdicontexttarget.h"
sl@0
    17
#include <graphics/directgdicontext.h>
sl@0
    18
sl@0
    19
CTDirectGdiContextTarget::CTDirectGdiContextTarget()
sl@0
    20
	{
sl@0
    21
	SetTestStepName(KTDirectGdiContextTargetStep);
sl@0
    22
	}
sl@0
    23
sl@0
    24
CTDirectGdiContextTarget::~CTDirectGdiContextTarget()
sl@0
    25
	{
sl@0
    26
	}
sl@0
    27
sl@0
    28
/**
sl@0
    29
@SYMTestCaseID		
sl@0
    30
	GRAPHICS-DIRECTGDI-CONTEXTTARGET-0001
sl@0
    31
sl@0
    32
@SYMTestPriority
sl@0
    33
	Critical
sl@0
    34
sl@0
    35
@SYMPREQ
sl@0
    36
	PREQ39
sl@0
    37
sl@0
    38
@SYMREQ
sl@0
    39
	REQ9195
sl@0
    40
	REQ9201 
sl@0
    41
	REQ9202 
sl@0
    42
	REQ9222 
sl@0
    43
	REQ9223 
sl@0
    44
	REQ9236 
sl@0
    45
	REQ9237
sl@0
    46
sl@0
    47
@SYMTestCaseDesc
sl@0
    48
	Use case - Single context and multiple targets.
sl@0
    49
sl@0
    50
@SYMTestActions		
sl@0
    51
	Construct CDirectGdiDriver.
sl@0
    52
	Construct CDirectGdiContext.
sl@0
    53
sl@0
    54
	Construct RSgImage1.
sl@0
    55
	Construct MDirectGdiImageTarget1. 
sl@0
    56
 	Create MDirectGdiImageTarget1, using RSgImage1.
sl@0
    57
sl@0
    58
	Activate CDirectGdiContext using MDirectGdiImageTarget1.
sl@0
    59
	Do some drawing operations using a different pen/brush setting
sl@0
    60
  
sl@0
    61
	Construct RSgImage2.
sl@0
    62
	Construct MDirectGdiImageTarget2. 
sl@0
    63
	Create MDirectGdiImageTarget2, using RSgImage2.
sl@0
    64
sl@0
    65
	Activate CDirectGdiContext using MDirectGdiImageTarget2.
sl@0
    66
	Do some drawing operations using a different pen/brush setting
sl@0
    67
  
sl@0
    68
	Destroy RSgImage.
sl@0
    69
	Destroy MDirectGdiImageTarget.
sl@0
    70
sl@0
    71
	Destroy CDirectGdiContext.
sl@0
    72
	Close CDirectGdiDriver.	
sl@0
    73
sl@0
    74
@SYMTestExpectedResults
sl@0
    75
	It should be able to switch the targets between the same context.
sl@0
    76
	
sl@0
    77
@SYMTestStatus 		
sl@0
    78
	Implemented
sl@0
    79
*/
sl@0
    80
void CTDirectGdiContextTarget::TestSwitchingTargetsL()
sl@0
    81
	{
sl@0
    82
	TInt result = KErrNone;
sl@0
    83
	_LIT(KTestName, "ContextTarget-SwitchingTargets"); 
sl@0
    84
	if(!iRunningOomTests)
sl@0
    85
		{
sl@0
    86
		INFO_PRINTF1(KTestName);
sl@0
    87
		}
sl@0
    88
	
sl@0
    89
	if (iTargetPixelFormatArray.Count() <= 1)
sl@0
    90
		{
sl@0
    91
		// The MBX driver only supports one pixelformat. This test has no purpose
sl@0
    92
		// when both targets are the same, so in this case we don't run it.
sl@0
    93
		INFO_PRINTF1(_L("Not enough formats supported. Skipping test..."));
sl@0
    94
		return;
sl@0
    95
		}
sl@0
    96
	
sl@0
    97
	TInt err = CDirectGdiDriver::Open();
sl@0
    98
	TESTNOERRORL(err);
sl@0
    99
			
sl@0
   100
	CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
sl@0
   101
	TESTL(dgdiDriver != NULL);	
sl@0
   102
	CleanupClosePushL(*dgdiDriver);	
sl@0
   103
	
sl@0
   104
	CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);	
sl@0
   105
	CleanupStack::PushL(gc);
sl@0
   106
	
sl@0
   107
	RSgImage rsgImage1;	
sl@0
   108
	RSgImage rsgImage2;	
sl@0
   109
	
sl@0
   110
	// Set the bitmap up...
sl@0
   111
	TSgImageInfo imageInfo;
sl@0
   112
	imageInfo.iSizeInPixels = TSize (320, 240);
sl@0
   113
	imageInfo.iPixelFormat = iTargetPixelFormatArray[0];
sl@0
   114
	imageInfo.iUsage = ESgUsageDirectGdiTarget;
sl@0
   115
	result = rsgImage1.Create(imageInfo, NULL,0);
sl@0
   116
	TESTNOERRORL(result);
sl@0
   117
	CleanupClosePushL(rsgImage1);
sl@0
   118
	
sl@0
   119
	imageInfo.iSizeInPixels = TSize (300, 300);
sl@0
   120
	imageInfo.iPixelFormat =  iTargetPixelFormatArray[1];
sl@0
   121
	result = rsgImage2.Create(imageInfo, NULL,0);
sl@0
   122
	TESTNOERRORL(result);
sl@0
   123
	CleanupClosePushL(rsgImage2);	
sl@0
   124
sl@0
   125
	RDirectGdiImageTarget dgdiImageTarget1(*dgdiDriver);	
sl@0
   126
	result = dgdiImageTarget1.Create(rsgImage1);
sl@0
   127
	TESTNOERRORL(result);
sl@0
   128
	CleanupClosePushL(dgdiImageTarget1);
sl@0
   129
sl@0
   130
	result = gc->Activate (dgdiImageTarget1);
sl@0
   131
	TESTNOERRORL(result);
sl@0
   132
	gc->SetPenColor(TRgb(100,100,100));
sl@0
   133
	TEST(gc->PenColor() == TRgb(100,100,100));
sl@0
   134
	gc->DrawEllipse(TRect(0,0,30,30));
sl@0
   135
	TESTNOERROR(dgdiDriver->GetError());
sl@0
   136
sl@0
   137
	RDirectGdiImageTarget dgdiImageTarget2(*dgdiDriver);	
sl@0
   138
	result = dgdiImageTarget2.Create(rsgImage1);
sl@0
   139
	TESTNOERRORL(result);
sl@0
   140
	CleanupClosePushL(dgdiImageTarget2);
sl@0
   141
sl@0
   142
	result = gc->Activate (dgdiImageTarget2);
sl@0
   143
	TESTNOERRORL(result);
sl@0
   144
	gc->SetPenColor(TRgb(0,0,0));
sl@0
   145
	TEST(gc->PenColor() == TRgb(0,0,0));	
sl@0
   146
	gc->DrawEllipse(TRect(0,0,30,30));
sl@0
   147
	TESTNOERROR(dgdiDriver->GetError());		
sl@0
   148
sl@0
   149
	CleanupStack::PopAndDestroy(6, dgdiDriver); //dgdiImageTarget1&2, rsgImage1&2, gc, dgdiDriver
sl@0
   150
	
sl@0
   151
	}
sl@0
   152
sl@0
   153
/**
sl@0
   154
@SYMTestCaseID		
sl@0
   155
	GRAPHICS-DIRECTGDI-CONTEXTTARGET-0002
sl@0
   156
sl@0
   157
@SYMTestPriority
sl@0
   158
	Critical
sl@0
   159
sl@0
   160
@SYMPREQ
sl@0
   161
	PREQ39
sl@0
   162
sl@0
   163
@SYMREQ
sl@0
   164
	REQ9195
sl@0
   165
	REQ9201 
sl@0
   166
	REQ9202 
sl@0
   167
	REQ9222 
sl@0
   168
	REQ9223 
sl@0
   169
	REQ9236 
sl@0
   170
	REQ9237
sl@0
   171
sl@0
   172
@SYMTestCaseDesc
sl@0
   173
	Test the integrity of RSgImage metadata after being written to.
sl@0
   174
sl@0
   175
@SYMTestActions		
sl@0
   176
	Construct CDirectGdiDriver.
sl@0
   177
	Construct CDirectGdiContext.
sl@0
   178
	Construct RSgImage.
sl@0
   179
	Construct MDirectGdiImageTarget. 
sl@0
   180
	Create MDirectGdiImageTarget1, using RSgImage.
sl@0
   181
	Check the current RSgImage info matches that at creation time.
sl@0
   182
	Activate CDirectGdiContext using MDirectGdiImageTarget.
sl@0
   183
	Do some drawing operations on the target.
sl@0
   184
	Check the current RSgImage info matches that at creation time.  
sl@0
   185
	Destroy RSgImage.
sl@0
   186
	Destroy MDirectGdiImageTarget.
sl@0
   187
	Destroy CDirectGdiContext.
sl@0
   188
	Close CDirectGdiDriver.
sl@0
   189
sl@0
   190
@SYMTestExpectedResults
sl@0
   191
	The RSgImage info should be the same at all times.
sl@0
   192
  
sl@0
   193
@SYMTestStatus 		
sl@0
   194
	Implemented
sl@0
   195
*/
sl@0
   196
void CTDirectGdiContextTarget::TestRSgImageMetadataIntegrityL()
sl@0
   197
	{
sl@0
   198
	_LIT(KTestName, "ContextTarget-RSgImageMetadataIntegrity"); 
sl@0
   199
	if(!iRunningOomTests)
sl@0
   200
		{
sl@0
   201
		INFO_PRINTF1(KTestName);
sl@0
   202
		}
sl@0
   203
	
sl@0
   204
	TInt err = CDirectGdiDriver::Open();
sl@0
   205
	TESTNOERRORL(err);			
sl@0
   206
	CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
sl@0
   207
	TESTL(dgdiDriver != NULL);	
sl@0
   208
	CleanupClosePushL(*dgdiDriver);	
sl@0
   209
	CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);
sl@0
   210
	CleanupStack::PushL(gc);
sl@0
   211
	
sl@0
   212
	// Create RSgImage, initialise some info.
sl@0
   213
	RSgImage rsgImage;	
sl@0
   214
	TSgImageInfo imageInfo;
sl@0
   215
	imageInfo.iSizeInPixels = TSize (320, 240);
sl@0
   216
	imageInfo.iPixelFormat = iTestParams.iTargetPixelFormat;
sl@0
   217
	imageInfo.iUsage = ESgUsageDirectGdiTarget;
sl@0
   218
	TInt result = rsgImage.Create(imageInfo, NULL,0);
sl@0
   219
	TESTNOERRORL(result);
sl@0
   220
	CleanupClosePushL(rsgImage);
sl@0
   221
	
sl@0
   222
	// Test that after creation, the info is still the same.
sl@0
   223
	TSgImageInfo retrievedInfo;
sl@0
   224
	TESTNOERRORL(rsgImage.GetInfo(retrievedInfo));
sl@0
   225
	TBool match = CompareInfos(retrievedInfo, imageInfo);
sl@0
   226
	TEST(match);
sl@0
   227
	
sl@0
   228
	// Perform writing to the target.
sl@0
   229
	RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver);	
sl@0
   230
	TESTNOERRORL(dgdiImageTarget.Create(rsgImage));
sl@0
   231
	CleanupClosePushL(dgdiImageTarget);
sl@0
   232
	TESTNOERRORL(gc->Activate (dgdiImageTarget) );
sl@0
   233
	gc->SetBrushColor(TRgb(255,0,0,255));
sl@0
   234
	gc->Clear();
sl@0
   235
	dgdiDriver->Finish();
sl@0
   236
	
sl@0
   237
	// Test that after being written to, the info is still the same. If this fails, 
sl@0
   238
	// an indication that image data is being written over the metadata.
sl@0
   239
	TESTNOERRORL(rsgImage.GetInfo(retrievedInfo));
sl@0
   240
	match = CompareInfos(retrievedInfo, imageInfo);
sl@0
   241
	TEST(match);
sl@0
   242
	
sl@0
   243
	CleanupStack::PopAndDestroy(4); //dgdiImageTarget, rsgImage, gc, dgdiDriver	
sl@0
   244
	}
sl@0
   245
sl@0
   246
/**
sl@0
   247
@SYMTestCaseID		
sl@0
   248
	GRAPHICS-DIRECTGDI-CONTEXTTARGET-0003
sl@0
   249
sl@0
   250
@SYMTestPriority
sl@0
   251
	Critical
sl@0
   252
sl@0
   253
@SYMPREQ
sl@0
   254
	PREQ39
sl@0
   255
sl@0
   256
@SYMREQ
sl@0
   257
	REQ9195
sl@0
   258
	REQ9201 
sl@0
   259
	REQ9202 
sl@0
   260
	REQ9222 
sl@0
   261
	REQ9223 
sl@0
   262
	REQ9236 
sl@0
   263
	REQ9237
sl@0
   264
sl@0
   265
@SYMTestCaseDesc
sl@0
   266
	Test that the RdirectGdiImageTarget::Create() and RDirectGdiDrawableSource::Create() methods 
sl@0
   267
	validate their arguments.
sl@0
   268
	- Test that creation of a target from an RSgImage that was created as a source fails.
sl@0
   269
	- Test that creation of a source from an RSgImage that was created as a target fails.
sl@0
   270
sl@0
   271
@SYMTestActions		
sl@0
   272
	Construct CDirectGdiDriver.
sl@0
   273
	Construct CDirectGdiContext.
sl@0
   274
	Create a RSgImage 1 as a source.
sl@0
   275
	Create a RSgImage 2 as a target.
sl@0
   276
	Attempt to create RDirectGdiImageTarget from RSgImage 1 (a source).
sl@0
   277
	KErrNotSupported should be returned.
sl@0
   278
	Attempt to create RDirectGdiDrawableSource from RSgImage 2 (a target).
sl@0
   279
	KErrNotSupported should be returned.
sl@0
   280
sl@0
   281
@SYMTestExpectedResults
sl@0
   282
	Functions return the correct error code.
sl@0
   283
  
sl@0
   284
@SYMTestStatus 		
sl@0
   285
	Implemented
sl@0
   286
*/
sl@0
   287
void CTDirectGdiContextTarget::TestCreateCloseSourceTargetInvalidParametersL()
sl@0
   288
	{
sl@0
   289
	_LIT(KTestName, "ContextTarget-CreateCloseSourceTargetInvalidParameters"); 
sl@0
   290
	if(!iRunningOomTests)
sl@0
   291
		{
sl@0
   292
		INFO_PRINTF1(KTestName);
sl@0
   293
		}
sl@0
   294
	
sl@0
   295
	TInt err = CDirectGdiDriver::Open();
sl@0
   296
	TESTNOERRORL(err);			
sl@0
   297
	CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
sl@0
   298
	TESTL(dgdiDriver != NULL);	
sl@0
   299
	CleanupClosePushL(*dgdiDriver);	
sl@0
   300
	
sl@0
   301
	CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);	
sl@0
   302
	CleanupStack::PushL(gc);
sl@0
   303
	
sl@0
   304
	//Create an image with usage set to ESgUsageDirectGdiSource	
sl@0
   305
	TSgImageInfo info1;
sl@0
   306
	info1.iSizeInPixels = TSize(8, 8);
sl@0
   307
	info1.iUsage = ESgUsageDirectGdiSource;
sl@0
   308
	info1.iPixelFormat = EUidPixelFormatARGB_8888;
sl@0
   309
	info1.iCpuAccess = ESgCpuAccessReadWrite;
sl@0
   310
	info1.iShareable = ETrue;	
sl@0
   311
	RSgImage image1;
sl@0
   312
	TESTNOERRORL(image1.Create(info1, NULL, 0));
sl@0
   313
	CleanupClosePushL(image1);	
sl@0
   314
	
sl@0
   315
	//Create an image with usage set to ESgUsageDirectGdiTarget
sl@0
   316
	TSgImageInfo info2;
sl@0
   317
	info2.iSizeInPixels = TSize(8, 8);
sl@0
   318
	info2.iUsage = ESgUsageDirectGdiTarget;
sl@0
   319
	info2.iPixelFormat = EUidPixelFormatRGB_565;
sl@0
   320
	info2.iCpuAccess = ESgCpuAccessNone;
sl@0
   321
	info2.iShareable = ETrue;
sl@0
   322
	RSgImage image2;
sl@0
   323
	TESTNOERRORL(image2.Create(info2, NULL, 0));
sl@0
   324
	CleanupClosePushL(image2);
sl@0
   325
	
sl@0
   326
	//create a RDirectGdiImageTarget from an image with 
sl@0
   327
	//usage set to ESgUsageDirectGdiSource
sl@0
   328
	RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver);	
sl@0
   329
	TESTL(KErrNotSupported == dgdiImageTarget.Create(image1));	
sl@0
   330
	
sl@0
   331
	//create a RDirectGdiDrawableSource from an image with
sl@0
   332
	//usage set to ESgUsageDirectGdiTarget	
sl@0
   333
	RDirectGdiDrawableSource dgdiImageSource(*dgdiDriver);
sl@0
   334
	TESTL(KErrNotSupported == dgdiImageSource.Create(image2));
sl@0
   335
	
sl@0
   336
	//create a RDirectGdiImageTarget from an image with 
sl@0
   337
	//usage set to ESgUsageDirectGdiTarget	
sl@0
   338
	//should succeed
sl@0
   339
	TESTNOERRORL(dgdiImageTarget.Create(image2));
sl@0
   340
	CleanupClosePushL(dgdiImageTarget);
sl@0
   341
	
sl@0
   342
	// Need to activate a target before we can create a source due to OpenVG limitation.
sl@0
   343
	// An OpenVG context must exist before a source can be created, but is not available
sl@0
   344
	// until a target is activated.
sl@0
   345
	gc->Activate(dgdiImageTarget);	
sl@0
   346
sl@0
   347
	//create a RDirectGdiDrawableSource from an image with
sl@0
   348
	//usage set to ESgUsageDirectGdiSource	
sl@0
   349
	//should succeed
sl@0
   350
	TESTNOERRORL(dgdiImageSource.Create(image1));
sl@0
   351
	CleanupClosePushL(dgdiImageSource);
sl@0
   352
	
sl@0
   353
	CleanupStack::PopAndDestroy(6, dgdiDriver);
sl@0
   354
	}
sl@0
   355
sl@0
   356
/** 
sl@0
   357
Override of base class pure virtual
sl@0
   358
Our implementation only gets called if the base class doTestStepPreambleL() did
sl@0
   359
not leave. That being the case, the current test result value will be EPass.
sl@0
   360
@leave Gets system wide error code
sl@0
   361
@return TVerdict code
sl@0
   362
*/	
sl@0
   363
TVerdict CTDirectGdiContextTarget::doTestStepL()
sl@0
   364
	{
sl@0
   365
	if(iUseDirectGdi)
sl@0
   366
		{
sl@0
   367
		// Test for each pixel format
sl@0
   368
		for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
sl@0
   369
			{	
sl@0
   370
			iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
sl@0
   371
			RunTestsL();
sl@0
   372
			RunOomTestsL();			
sl@0
   373
			}
sl@0
   374
		}
sl@0
   375
	else
sl@0
   376
		{
sl@0
   377
		INFO_PRINTF1(_L("BitGDI has no RSgImage to test!"));
sl@0
   378
		}
sl@0
   379
	CloseTMSGraphicsStep();
sl@0
   380
	return TestStepResult();
sl@0
   381
	}
sl@0
   382
sl@0
   383
/**
sl@0
   384
Override of base class virtual
sl@0
   385
@leave Gets system wide error code
sl@0
   386
@return - TVerdict code
sl@0
   387
*/
sl@0
   388
TVerdict CTDirectGdiContextTarget::doTestStepPreambleL()
sl@0
   389
	{			
sl@0
   390
	CTDirectGdiStepBase::doTestStepPreambleL();	
sl@0
   391
	return TestStepResult();
sl@0
   392
	}
sl@0
   393
sl@0
   394
/**
sl@0
   395
Override of base class pure virtual
sl@0
   396
Lists the tests to be run
sl@0
   397
*/
sl@0
   398
void CTDirectGdiContextTarget::RunTestsL()
sl@0
   399
	{
sl@0
   400
	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXTTARGET-0001"));
sl@0
   401
	TestSwitchingTargetsL();	
sl@0
   402
	RecordTestResultL();
sl@0
   403
	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXTTARGET-0002"));
sl@0
   404
	TestRSgImageMetadataIntegrityL();
sl@0
   405
	RecordTestResultL();
sl@0
   406
	SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXTTARGET-0003"));
sl@0
   407
	TestCreateCloseSourceTargetInvalidParametersL();
sl@0
   408
	RecordTestResultL();
sl@0
   409
	}
sl@0
   410
sl@0
   411
/**
sl@0
   412
Helper function to test the equivalence of two TSgImageInfo structures.
sl@0
   413
sl@0
   414
@see     CTSgTestStepBase::CompareInfos
sl@0
   415
@param   info1 A TSgImageInfo structure to compare.
sl@0
   416
@param   info2 A TSgImageInfo structure to compare.
sl@0
   417
sl@0
   418
@return  ETrue if the two are identical, EFalse otherwise.
sl@0
   419
*/
sl@0
   420
TBool CTDirectGdiContextTarget::CompareInfos(const TSgImageInfo& info1, const TSgImageInfo& info2)
sl@0
   421
	{
sl@0
   422
	return info1.iCpuAccess == info2.iCpuAccess 
sl@0
   423
			&& info1.iPixelFormat == info2.iPixelFormat
sl@0
   424
			&& info1.iScreenId == info2.iScreenId
sl@0
   425
			&& info1.iShareable == info2.iShareable
sl@0
   426
			&& info1.iSizeInPixels == info2.iSizeInPixels
sl@0
   427
			&& info1.iUsage | info2.iUsage
sl@0
   428
			&& info1.iUserAttributeCount == info2.iUserAttributeCount;
sl@0
   429
	}