graphicsdeviceinterface/directgdi/test/tdirectgdioom.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "tdirectgdioom.h"
       
    17 #include <graphics/directgdicontext.h>
       
    18 
       
    19 CTDirectGdiOom::CTDirectGdiOom()
       
    20 	{
       
    21 	SetTestStepName(KTDirectGdiOom);
       
    22 	}
       
    23 
       
    24 CTDirectGdiOom::~CTDirectGdiOom()
       
    25 	{
       
    26 	}
       
    27 
       
    28 /**
       
    29 @SYMTestCaseID		
       
    30 	GRAPHICS-DIRECTGDI-OOM-0001
       
    31 
       
    32 @SYMTestPriority
       
    33 	Medium
       
    34 
       
    35 @SYMPREQ
       
    36 	PREQ39
       
    37 
       
    38 @SYMREQ
       
    39 	REQ9195
       
    40 	REQ9201 
       
    41 	REQ9202 
       
    42 	REQ9222 
       
    43 	REQ9223 
       
    44 	REQ9236 
       
    45 	REQ9237
       
    46 
       
    47 @SYMTestCaseDesc
       
    48 	Draw a line with many points to increase coverage of path drawing in OOM conditions.
       
    49 
       
    50 @SYMTestActions		
       
    51 	Create an array of 1000 points.
       
    52 	Draw it as a line.
       
    53 
       
    54 @SYMTestExpectedResults
       
    55 	No image is produced by this test, it is purely for checking that no OOM errors occur.
       
    56 */
       
    57 void CTDirectGdiOom::TestDrawLargePolyLineL()
       
    58 	{	
       
    59 	_LIT(KTestName, "OOM_TestDrawLargePolyLine"); 
       
    60 	if(!iRunningOomTests)
       
    61 		{
       
    62 		INFO_PRINTF1(KTestName);
       
    63 		}
       
    64 	
       
    65 	TInt err = CDirectGdiDriver::Open();
       
    66 	TESTNOERRORL(err);
       
    67 			
       
    68 	CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
       
    69 	TESTL(dgdiDriver != NULL);	
       
    70 	CleanupClosePushL(*dgdiDriver);	
       
    71 	
       
    72 	CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);
       
    73 	TESTL(gc != NULL);
       
    74 	CleanupStack::PushL(gc);
       
    75 	
       
    76 	// Set the bitmap up...
       
    77 	RSgImage rsgImage;
       
    78 	TSgImageInfo imageInfo;
       
    79 	imageInfo.iSizeInPixels = TSize (320, 240);
       
    80 	imageInfo.iPixelFormat = iTestParams.iTargetPixelFormat;
       
    81 	imageInfo.iUsage = ESgUsageDirectGdiTarget;
       
    82 	err = rsgImage.Create(imageInfo, NULL,0);
       
    83 	TESTNOERRORL(err);
       
    84 	CleanupClosePushL(rsgImage);	
       
    85 	
       
    86 	RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver);	
       
    87 	err = dgdiImageTarget.Create(rsgImage);
       
    88 	TESTNOERRORL(err);	
       
    89 	CleanupClosePushL(dgdiImageTarget);
       
    90 
       
    91 	err = gc->Activate(dgdiImageTarget);
       
    92 	TESTNOERRORL(err);
       
    93 	
       
    94 	// Draw a polygon that had lots of points to attempt to make the AppendPathCommand 
       
    95 	// methods in vgengine fail
       
    96 	const TInt pCount = 1000;
       
    97 	CArrayFixFlat<TPoint>* points = new (ELeave)CArrayFixFlat<TPoint>(pCount);
       
    98 	TESTL(points != NULL);
       
    99 	CleanupStack::PushL(points);
       
   100 	
       
   101 	for(TInt i = pCount; i > 0; --i)
       
   102 		{
       
   103 		points->AppendL(TPoint(i, i));
       
   104 		}
       
   105 	
       
   106 	gc->DrawPolyLine(points->Array());
       
   107 	TESTNOERRORL(dgdiDriver->GetError());
       
   108 	
       
   109 	CleanupStack::PopAndDestroy(5, dgdiDriver);
       
   110 	
       
   111 	FreeSgImagePixelFormatCache();
       
   112 	}
       
   113 
       
   114 /**
       
   115 @SYMTestCaseID		
       
   116 	GRAPHICS-DIRECTGDI-OOM-0002
       
   117 
       
   118 @SYMTestPriority
       
   119 	Medium
       
   120 
       
   121 @SYMPREQ
       
   122 	PREQ39
       
   123 
       
   124 @SYMREQ
       
   125 	REQ9195
       
   126 	REQ9201 
       
   127 	REQ9202 
       
   128 	REQ9222 
       
   129 	REQ9223 
       
   130 	REQ9236 
       
   131 	REQ9237
       
   132 
       
   133 @SYMTestCaseDesc
       
   134 	Set the pen size in OOM conditions.
       
   135 
       
   136 @SYMTestActions	
       
   137 	Create a graphics context.
       
   138 	Call SetPenSize().
       
   139 
       
   140 @SYMTestExpectedResults
       
   141 	No memory leak should occur.
       
   142 */
       
   143 void CTDirectGdiOom::TestSetPenSizeL()
       
   144 	{	
       
   145 	_LIT(KTestName, "OOM_TestSetPenSize"); 
       
   146 	if(!iRunningOomTests)
       
   147 		{
       
   148 		INFO_PRINTF1(KTestName);
       
   149 		}
       
   150 
       
   151 	TInt err = CDirectGdiDriver::Open();
       
   152 	TESTNOERRORL(err);
       
   153 			
       
   154 	CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
       
   155 	TESTL(dgdiDriver != NULL);	
       
   156 	CleanupClosePushL(*dgdiDriver);	
       
   157 	
       
   158 	CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);
       
   159 	TESTL(gc != NULL);
       
   160 	CleanupStack::PushL(gc);
       
   161 	
       
   162 	// Set the bitmap up...
       
   163 	RSgImage rsgImage;
       
   164 	TSgImageInfo imageInfo;
       
   165 	imageInfo.iSizeInPixels = TSize (320, 240);
       
   166 	imageInfo.iPixelFormat = iTestParams.iTargetPixelFormat;
       
   167 	imageInfo.iUsage = ESgUsageDirectGdiTarget;
       
   168 	err = rsgImage.Create(imageInfo, NULL,0);
       
   169 	TESTNOERRORL(err);
       
   170 	CleanupClosePushL(rsgImage);	
       
   171 	
       
   172 	RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver);	
       
   173 	err = dgdiImageTarget.Create(rsgImage);
       
   174 	TESTNOERRORL(err);	
       
   175 	CleanupClosePushL(dgdiImageTarget);
       
   176 	
       
   177 	err = gc->Activate(dgdiImageTarget);
       
   178 	TESTNOERRORL(err);
       
   179 	
       
   180 	TRect rect(0, 0, 200, 1000);
       
   181 	TSize csize(300, 300);
       
   182 	
       
   183 	for(TInt i = 0; i < 10; i++)
       
   184 		{
       
   185 		gc->SetPenSize(TSize(i,i));		
       
   186 		gc->SetPenStyle(DirectGdi::ENullPen);
       
   187 		gc->SetBrushStyle(DirectGdi::ESolidBrush);
       
   188 		gc->DrawRoundRect(rect, csize);
       
   189 		gc->SetPenStyle(DirectGdi::ESolidPen);
       
   190 		gc->DrawRoundRect(rect, csize);
       
   191 		TESTNOERRORL(dgdiDriver->GetError());
       
   192 		}
       
   193 	
       
   194 	CleanupStack::PopAndDestroy(4, dgdiDriver); 
       
   195 	
       
   196 	FreeSgImagePixelFormatCache();
       
   197 	}
       
   198 
       
   199 /**
       
   200 Helper function to force SgImage's internal cache of pixel formats to be emptied,
       
   201 by asking it to lookup a configuration that will always return 0.
       
   202 */
       
   203 void CTDirectGdiOom::FreeSgImagePixelFormatCache()
       
   204 	{
       
   205 	// This will force the SgImage's cached array of pixel formats to be freed.
       
   206 	TInt count;
       
   207 	TSgImageInfo info;
       
   208 	info.iSizeInPixels = TSize(10, 10);
       
   209 	info.iUsage = ESgUsageDirectGdiSource;
       
   210 	info.iShareable = EFalse;	
       
   211 	info.iCpuAccess = ESgCpuAccessReadWrite;
       
   212 	info.iScreenId = 100;
       
   213 	TEST(KErrNone == RSgImage::GetPixelFormats(info, NULL, count));
       
   214 	TEST(count == 0);
       
   215 	}
       
   216 
       
   217 /** 
       
   218 Override of base class pure virtual
       
   219 Our implementation only gets called if the base class doTestStepPreambleL() did
       
   220 not leave. That being the case, the current test result value will be EPass.
       
   221 @leave Gets system wide error code
       
   222 @return TVerdict code
       
   223 */	
       
   224 TVerdict CTDirectGdiOom::doTestStepL()
       
   225 	{		
       
   226 	if (iUseDirectGdi)
       
   227 		{
       
   228 		// Just test for one pixel format to speed up testing
       
   229 		iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[0];
       
   230 		RunOomTestsL();
       
   231 		}
       
   232 	SetOverallTestStepID(_L("GRAPHICS-DIRECTGDI-OOM-0001"));
       
   233 	RecordTestResultL();
       
   234 	SetOverallTestStepID(_L("GRAPHICS-DIRECTGDI-OOM-0002"));
       
   235 	RecordTestResultL();
       
   236 	CloseTMSGraphicsStep();
       
   237 	return TestStepResult();
       
   238 	}
       
   239 
       
   240 /**
       
   241 Override of base class virtual
       
   242 @leave Gets system wide error code
       
   243 @return - TVerdict code
       
   244 */
       
   245 TVerdict CTDirectGdiOom::doTestStepPreambleL()
       
   246 	{			
       
   247 	CTDirectGdiStepBase::doTestStepPreambleL();	
       
   248 	return TestStepResult();
       
   249 	}
       
   250 
       
   251 /**
       
   252 Override of base class pure virtual
       
   253 Lists the tests to be run
       
   254 */
       
   255 void CTDirectGdiOom::RunTestsL()
       
   256 	{
       
   257 	TestDrawLargePolyLineL();		
       
   258 	TestSetPenSizeL();
       
   259 	}
       
   260