graphicstest/uibench/src/toutlineshadowdrawing.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include "toutlineshadowdrawing.h"
       
    23 #include <hal.h>
       
    24 // When enabled allows testing with a variable windows size rather than fixed size
       
    25 #define _TESTWITHVARIABLEWINDOWSIZE
       
    26 
       
    27 _LIT(KTextPhrase, "$%() ShAdOW OLine 1234");
       
    28 _LIT(KFontTypeface, "fontTypeFace");
       
    29 
       
    30 const TInt KIterationsToTest = 50; 		// Number of iterations to run tests
       
    31 const TInt KHeight = 60;
       
    32 const TInt KTempLength = 60; // Used for temp buffer in side function
       
    33 const TInt KLengthOfTestCase = 256;
       
    34 _LIT(KTestCaseFormat, "%S_%S_ORIENT_%d");
       
    35 
       
    36 /**
       
    37 Auxilary function called to generate test case name based on input parameters
       
    38 @param aTestDesc holds the test case description (eg. GET_FONT_MAX_HEIGHT)
       
    39 @param aIsShadowOn holds bool value of shadow effects (eg. ETrue or EFalse)
       
    40 @param aIsOutlineOn holds bool value of outline effects (eg. ETrue or EFalse)
       
    41 @param aOrientation holds int value of orientation (eg. 0, 1, 2)
       
    42 @param aPenColor holds pen color used to extract alpha value.
       
    43 */
       
    44 HBufC* CTOutlineShadowDrawing::GenerateTestCaseLC(const TDesC& aTestDesc, TBool aIsShadowOn, TBool aIsOutlineOn, TInt aOrientation, const TRgb& aPenColor)
       
    45 	{
       
    46 	TBuf<KLengthOfTestCase> tempBuffer;
       
    47 	TBuf<KTempLength> temp;
       
    48 	if(aIsShadowOn && aIsOutlineOn)
       
    49 		{
       
    50 		temp.Format(_L("WITH BOTH OUTLINE & SHADOW ON_"));
       
    51 		}
       
    52 	else if(aIsOutlineOn)
       
    53 		{
       
    54 		temp.Format(_L("WITH OUTLINE ONLY ON_"));
       
    55 		}
       
    56 	else if(aIsShadowOn)
       
    57 		{
       
    58 		temp.Format(_L("WITH SHADOW ONLY ON_"));
       
    59 		}
       
    60 	else 
       
    61 		{
       
    62 		temp.Format(_L("WITH BOTH OUTLINE & SHADOW OFF_"));
       
    63 		}
       
    64 		temp.AppendNum(aPenColor.Alpha());
       
    65 	
       
    66 	tempBuffer.Format(KTestCaseFormat, &aTestDesc, &temp, aOrientation);
       
    67 	return tempBuffer.AllocLC();
       
    68 	}
       
    69 
       
    70 /**
       
    71 	@SYMTestCaseID GRAPHICS-UI-BENCH-0147
       
    72 
       
    73 	@SYMPREQ PREQ1543
       
    74 
       
    75 	@SYMTestCaseDesc Tests how long it takes to run GetNearestFontToDesignHeightInTwips API 
       
    76 	and calculate time with different screen modes with outline and shadow effects.
       
    77 	Also with Screen Rotation
       
    78 
       
    79 	@param aFontFace is the fontface which is used to set to fontspec
       
    80 	@param aRotation is the rotation index which is passed to ResultAnalysis
       
    81 	@param aIsShadowOn holds shadow status (True or False)
       
    82 	@param aIsOutlineOn holds outline status (True or False)
       
    83 
       
    84 	@SYMTestPriority High
       
    85 
       
    86 	@SYMTestStatus Implemented
       
    87 
       
    88 	@SYMTestActions Compare the results over time, GetNearestFontToDesignHeightInPixels() code.
       
    89 	Time Calculated with different Screen Modes and with Screen Rotation.
       
    90 	API Calls:
       
    91 	CFbsBitGc::GetNearestFontToDesignHeightInPixels()
       
    92 	TFontStyle::SetEffects()
       
    93 
       
    94 	@SYMTestExpectedResults Test should pass and display total test time and time per display mode
       
    95 */
       
    96 void CTOutlineShadowDrawing::DoGetAPIsOutlineandShadowFontsL(const TDesC& aFontFace, TInt aRotation, TBool aIsShadowOn, TBool aIsOutlineOn)
       
    97 	{
       
    98 	TFontSpec fsp;
       
    99 	iGc->Clear();
       
   100 	iGc->Reset();
       
   101 	fsp.iFontStyle.SetEffects(FontEffect::EDropShadow, aIsShadowOn);
       
   102 	fsp.iFontStyle.SetEffects(FontEffect::EOutline, aIsOutlineOn);
       
   103 	fsp.iTypeface.iName = aFontFace;
       
   104 	fsp.iHeight = KHeight;
       
   105 	TRgb outlinePenColor = iGc->PenColor();
       
   106 	
       
   107 	_LIT(KTestName1, "GET_FONT_MAX_HEIGHT");
       
   108 	HBufC* testCase1 = GenerateTestCaseLC(KTestName1, aIsShadowOn, aIsOutlineOn, aRotation, outlinePenColor);
       
   109 	CFbsFont* font = NULL;
       
   110 	iProfiler->InitResults();
       
   111 	TInt iteration = 0;
       
   112 	for(iteration=0; iteration<=KIterationsToTest; iteration++)
       
   113 		{
       
   114 		TEST(iDev->GetNearestFontToMaxHeightInPixels((CFont*&)font,fsp,fsp.iHeight) == KErrNone);
       
   115 		iProfiler->MarkResultSetL();
       
   116 		iDev->ReleaseFont(font);
       
   117 		font = NULL;
       
   118 		}
       
   119 	iProfiler->ResultsAnalysis(*testCase1, aRotation, 0, iDev->DisplayMode(), KIterationsToTest);
       
   120 	CleanupStack::PopAndDestroy(testCase1);
       
   121 
       
   122 	_LIT(KTestName2, "GET_FONT");
       
   123 	HBufC* testCase2 = GenerateTestCaseLC(KTestName2, aIsShadowOn, aIsOutlineOn, aRotation, outlinePenColor);
       
   124 	// Tests performance for GetNearestFontInPixels API
       
   125 	iProfiler->InitResults();
       
   126 	for(iteration=0; iteration<=KIterationsToTest; iteration++)
       
   127 		{
       
   128 		TEST(iDev->GetNearestFontInPixels((CFont*&)font,fsp) == KErrNone);
       
   129 		iProfiler->MarkResultSetL();
       
   130 		iDev->ReleaseFont(font);
       
   131 		font = NULL;
       
   132 		}
       
   133 	iProfiler->ResultsAnalysis(*testCase2, aRotation, 0, iDev->DisplayMode(), KIterationsToTest);
       
   134 	CleanupStack::PopAndDestroy(testCase2);
       
   135 
       
   136 	_LIT(KTestName3, "GET_FONT_DESIGN_HEIGHT");
       
   137 	HBufC* testCase3 = GenerateTestCaseLC(KTestName3, aIsShadowOn, aIsOutlineOn, aRotation, outlinePenColor);
       
   138 	// Tests performance for GetNearestFontToDesignHeightInPixels API
       
   139 	iProfiler->InitResults();
       
   140 	for(iteration=0; iteration<=KIterationsToTest; iteration++)
       
   141 		{
       
   142 		TEST(iDev->GetNearestFontToDesignHeightInPixels((CFont*&)font,fsp) == KErrNone);
       
   143 		iProfiler->MarkResultSetL();
       
   144 		iDev->ReleaseFont(font);
       
   145 		font = NULL;
       
   146 		}
       
   147 	iProfiler->ResultsAnalysis(*testCase3, aRotation, 0, iDev->DisplayMode(), KIterationsToTest);
       
   148 	CleanupStack::PopAndDestroy(testCase3);
       
   149 	}
       
   150 
       
   151 /**
       
   152 	@SYMTestCaseID GRAPHICS-UI-BENCH-0148
       
   153 
       
   154 	@SYMPREQ PREQ1543
       
   155 
       
   156 	@SYMTestCaseDesc Tests how long it takes to run DrawText API
       
   157 	and calculate time with different screen modes with and outline and shadow effects
       
   158 
       
   159 	@param aFontFace is the fontface which is used to set to fontspec
       
   160 	@param aRotation is the rotation index which is passed to ResultAnalysis
       
   161 	@param aBitmapType is the bitmap type (Here it is AntiAliased)
       
   162 	@param aOutlinePenColor is the pen color
       
   163 	@param aIsShadowOn holds shadow status (True or False)
       
   164 	@param aIsOutlineOn holds outline status (True or False)
       
   165 	@param aDispModeIndex is the display mode index used for displaying in log
       
   166 
       
   167 	@SYMTestPriority High 
       
   168 
       
   169 	@SYMTestStatus Implemented
       
   170 
       
   171 	@SYMTestActions Compare the results over time, DrawText with and without Outline & Shadow and
       
   172 	Time calculated with different Screen Modes and with Screen Rotation DrawText().
       
   173 	API Calls:
       
   174 	CFbsBitGc::DrawText()
       
   175 	TFontStyle::SetEffects()
       
   176 
       
   177 	@SYMTestExpectedResults Test should pass and display total test time and time per display mode
       
   178 */	
       
   179 void CTOutlineShadowDrawing::DoDrawTextOutlineShadowL(const TDesC& aFontFace, TInt aRotation, const TRgb& aOutlinePenColor, TBool aIsShadowOn, TBool aIsOutlineOn, TInt aDispModeIndex)
       
   180 	{
       
   181 	TFontSpec fsp;
       
   182 	iGc->Clear();
       
   183 	iGc->Reset();
       
   184 	fsp.iTypeface.iName = aFontFace;
       
   185 	fsp.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
       
   186 
       
   187 	_LIT(KTestName1, "DRAWTEXT_DISPLAYINDEX_%d");
       
   188 
       
   189 	TBuf<KTempLength> temp;
       
   190 	fsp.iHeight = KHeight;
       
   191 	fsp.iFontStyle.SetEffects(FontEffect::EDropShadow, aIsShadowOn);
       
   192 	fsp.iFontStyle.SetEffects(FontEffect::EOutline, aIsOutlineOn);
       
   193 	iGc->SetPenColor(aOutlinePenColor);
       
   194 	CFont* font = NULL;
       
   195 	User::LeaveIfError(iDev->GetNearestFontToDesignHeightInPixels((CFont*&)font,fsp));
       
   196 	iGc->UseFont(font);
       
   197 	
       
   198 	temp.Format(KTestName1, aDispModeIndex);
       
   199 	HBufC* testCase1 = GenerateTestCaseLC(temp, aIsShadowOn, aIsOutlineOn, aRotation, aOutlinePenColor);
       
   200 	iProfiler->InitResults();
       
   201 	for(TInt i = 0; i <= KIterationsToTest; i++)
       
   202 		{
       
   203 		iGc->DrawText(KTextPhrase,TPoint(10,100));
       
   204 		iProfiler->MarkResultSetL();
       
   205 		}
       
   206 	iProfiler->ResultsAnalysis(*testCase1, aRotation, 0, iDev->DisplayMode(), KIterationsToTest);
       
   207 	CleanupStack::PopAndDestroy(testCase1);
       
   208 	iGc->DiscardFont();
       
   209 	iDev->ReleaseFont(font);
       
   210 	}
       
   211 
       
   212 /**
       
   213 	@SYMTestCaseID GRAPHICS-UI-BENCH-0149
       
   214 	
       
   215 	@SYMPREQ PREQ1543
       
   216 
       
   217 	@SYMTestCaseDesc Tests how long it takes to run DrawTextVertical API
       
   218 	and calculate time with different screen modes with and outline and shadow effects
       
   219 
       
   220 	@param aFontFace is the fontface which is used to set to fontspec
       
   221 	@param aRotation is the rotation index which is passed to ResultAnalysis
       
   222 	@param aBitmapType is the bitmap type (Here it is AntiAliased)
       
   223 	@param aOutlinePenColor is the pen color
       
   224 	@param aIsShadowOn holds shadow status (True or False)
       
   225 	@param aIsOutlineOn holds outline status (True or False)
       
   226 	@param aDispModeIndex is the display mode index used for displaying in log
       
   227 
       
   228 	@SYMTestPriority High 
       
   229 
       
   230 	@SYMTestStatus Implemented
       
   231 
       
   232 	@SYMTestActions Compare the results over time, with DrawTextVertical with and without Outline & Shadow and
       
   233 	Time calculated with different Screen Modes and with Screen Rotation with DrawTextVertical
       
   234 	API Calls:
       
   235 	CFbsBitGc::DrawTextVertical()
       
   236 	TFontStyle::SetEffects()
       
   237 
       
   238 	@SYMTestExpectedResults Test should pass and display total test time and time per display mode
       
   239 */
       
   240 void CTOutlineShadowDrawing::DoDrawVerticalTextOutlineShadowL(const TDesC& aFontFace, TInt aRotation, const TRgb& aOutlinePenColor, TBool aIsShadowOn, TBool aIsOutlineOn, TInt aDispModeIndex)
       
   241 	{
       
   242 	TFontSpec fsp;
       
   243 	CFont* font = NULL;
       
   244 	iGc->Clear();
       
   245 	iGc->Reset();
       
   246 	TInt alpha = aOutlinePenColor.Alpha();
       
   247 	fsp.iTypeface.iName = aFontFace;
       
   248 	fsp.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
       
   249 
       
   250 	_LIT(KTestName1, "DRAWTEXTVERTICAL_DISPLAYINDEX_%d");
       
   251 
       
   252 	TBuf<KTempLength> temp;	
       
   253 	temp.Format(KTestName1, aDispModeIndex);
       
   254 	HBufC* testCase1 = GenerateTestCaseLC(temp, aIsShadowOn, aIsOutlineOn, aRotation, aOutlinePenColor);
       
   255 	fsp.iHeight = KHeight;
       
   256 	fsp.iFontStyle.SetEffects(FontEffect::EDropShadow, aIsShadowOn);
       
   257 	fsp.iFontStyle.SetEffects(FontEffect::EOutline, aIsOutlineOn);
       
   258 
       
   259 	iGc->SetPenColor(aOutlinePenColor);
       
   260 	User::LeaveIfError(iDev->GetNearestFontToDesignHeightInPixels((CFont*&)font,fsp));
       
   261 	iGc->UseFont(font);
       
   262 	iProfiler->InitResults();
       
   263 	for(TInt i=0; i<=KIterationsToTest; i++)
       
   264 		{
       
   265 		iGc->DrawTextVertical(KTextPhrase,TPoint(10,10),EFalse);
       
   266 		iProfiler->MarkResultSetL();
       
   267 		}
       
   268 	iProfiler->ResultsAnalysis(*testCase1, aRotation, 0, iDev->DisplayMode(), KIterationsToTest);
       
   269 	CleanupStack::PopAndDestroy(testCase1);
       
   270 	iGc->DiscardFont();
       
   271 	iDev->ReleaseFont(font);
       
   272 	}
       
   273 
       
   274 CTOutlineShadowDrawing::~CTOutlineShadowDrawing()
       
   275 	{
       
   276 	}
       
   277 
       
   278 CTOutlineShadowDrawing::CTOutlineShadowDrawing()
       
   279 	{
       
   280 	SetTestStepName(KTOutlineShadowDrawing);
       
   281 	}
       
   282 
       
   283 /** 
       
   284 Override of base class pure virtual
       
   285 Our implementation only gets called if the base class doTestStepPreambleL() did
       
   286 not leave. That being the case, the current test result value will be EPass.
       
   287 
       
   288 Takes Font Face from uibench.ini file and pass that value to functions.
       
   289 It also Rotates the screen before calling test functions.
       
   290 
       
   291 @return TVerdict code
       
   292 */	
       
   293 TVerdict CTOutlineShadowDrawing::doTestStepL()
       
   294 	{	
       
   295 	TPtrC fontface;
       
   296 
       
   297 	TBool returnValue1 = GetStringFromConfig(ConfigSection(), KFontTypeface, fontface);
       
   298 	if(returnValue1)
       
   299 		{
       
   300 		INFO_PRINTF1(_L("OutlineShadowDrawing"));
       
   301 		iGc->Reset();
       
   302 		TBool orientation[4];
       
   303 		SetTestStepID(_L("GRAPHICS-UI-BENCH-0147"));
       
   304 		DoGetAPIsOutlineandShadowFontsL(fontface, 0, ETrue, ETrue);
       
   305 		DoGetAPIsOutlineandShadowFontsL(fontface, 0, ETrue, EFalse);
       
   306 		DoGetAPIsOutlineandShadowFontsL(fontface, 0, EFalse, ETrue);
       
   307 		DoGetAPIsOutlineandShadowFontsL(fontface, 0, EFalse, EFalse);
       
   308 		RecordTestResultL();
       
   309 
       
   310 		for(TInt dispModeIndex = 0; dispModeIndex < KNumValidDisplayModes; dispModeIndex++)
       
   311 			{
       
   312 			SetScreenModeL(KValidDisplayModes[dispModeIndex]);
       
   313 			iDev = &iScreenDevice->BitmapDevice();
       
   314 			iGc->OrientationsAvailable(orientation);
       
   315 			for (TInt orient = CFbsBitGc::EGraphicsOrientationNormal; orient <= CFbsBitGc::EGraphicsOrientationRotated270; orient++)
       
   316 				{
       
   317 				iGc->SetOrientation((CFbsBitGc::TGraphicsOrientation)orient);
       
   318 				// Draw Text - without transperency
       
   319 				SetTestStepID(_L("GRAPHICS-UI-BENCH-0148"));
       
   320 				DoDrawTextOutlineShadowL(fontface, orient, KRgbGreen, ETrue, ETrue, dispModeIndex);
       
   321 				DoDrawTextOutlineShadowL(fontface, orient, KRgbGreen, EFalse, ETrue, dispModeIndex);
       
   322 				DoDrawTextOutlineShadowL(fontface, orient, KRgbGreen, ETrue, EFalse, dispModeIndex);
       
   323 				DoDrawTextOutlineShadowL(fontface, orient, KRgbGreen, EFalse, EFalse, dispModeIndex);
       
   324 				RecordTestResultL();
       
   325 				// Draw Vertical Text - without transperency
       
   326 				SetTestStepID(_L("GRAPHICS-UI-BENCH-0149"));
       
   327 				DoDrawVerticalTextOutlineShadowL(fontface, orient, KRgbRed, ETrue, ETrue, dispModeIndex);
       
   328 				DoDrawVerticalTextOutlineShadowL(fontface, orient, KRgbRed, ETrue, EFalse, dispModeIndex);
       
   329 				DoDrawVerticalTextOutlineShadowL(fontface, orient, KRgbRed, EFalse, ETrue, dispModeIndex);
       
   330 				DoDrawVerticalTextOutlineShadowL(fontface, orient, KRgbRed, EFalse, EFalse, dispModeIndex);
       
   331 				RecordTestResultL();
       
   332 				// Transperency tests - Draw Text
       
   333 				SetTestStepID(_L("GRAPHICS-UI-BENCH-0148"));
       
   334 				DoDrawTextOutlineShadowL(fontface, orient, TRgb(128, 128, 128, 120), ETrue, ETrue, dispModeIndex);
       
   335 				DoDrawTextOutlineShadowL(fontface, orient, TRgb(128, 128, 128, 120), EFalse, ETrue, dispModeIndex);
       
   336 				DoDrawTextOutlineShadowL(fontface, orient, TRgb(128, 128, 128, 120), ETrue, EFalse, dispModeIndex);
       
   337 				DoDrawTextOutlineShadowL(fontface, orient, TRgb(128, 128, 128, 120), EFalse, EFalse, dispModeIndex);
       
   338 				RecordTestResultL();
       
   339 				// Transperency tests - Draw Vertical Text
       
   340 				SetTestStepID(_L("GRAPHICS-UI-BENCH-0149"));
       
   341 				DoDrawVerticalTextOutlineShadowL(fontface, orient, TRgb(128, 128, 0, 20), ETrue, ETrue, dispModeIndex);
       
   342 				DoDrawVerticalTextOutlineShadowL(fontface, orient, TRgb(128, 128, 0, 20), ETrue, EFalse, dispModeIndex);
       
   343 				DoDrawVerticalTextOutlineShadowL(fontface, orient, TRgb(128, 128, 0, 20), EFalse, ETrue, dispModeIndex);
       
   344 				DoDrawVerticalTextOutlineShadowL(fontface, orient, TRgb(128, 128, 0, 20), EFalse, EFalse, dispModeIndex);					
       
   345 				RecordTestResultL();
       
   346 				}
       
   347 			iGc->SetOrientation(CFbsBitGc::EGraphicsOrientationNormal);
       
   348 			}
       
   349 		}
       
   350 	else
       
   351 		{
       
   352 		INFO_PRINTF1(_L("ERROR WHILE READING CONFIG FILE"));
       
   353 		User::Leave(returnValue1);
       
   354 		}
       
   355 	return TestStepResult();
       
   356 	}
       
   357 
       
   358 /**
       
   359 Override of base class pure virtual
       
   360 
       
   361 @return - TVerdict code
       
   362 */
       
   363 TVerdict CTOutlineShadowDrawing::doTestStepPreambleL()
       
   364 	{
       
   365 	CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
       
   366 	SetScreenModeL(EColor16MU);
       
   367 	iDev = &iScreenDevice->BitmapDevice();
       
   368 	return TestStepResult();
       
   369 	}