windowing/windowserver/tauto/TGDI.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1996-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 // GDI.CPP
       
    15 // Test GDI functions
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @test
       
    22  @internalComponent - Internal Symbian test code
       
    23 */
       
    24 
       
    25 #include "TGDI.H"
       
    26 
       
    27 #define TAUTO_BITMAP_NAME _L("Z:\\WSTEST\\TAUTO.MBM")
       
    28 
       
    29 //#define LOGGING on		//Uncomment this line to get extra test logging - useful if debugging a failure of one of the tests
       
    30 
       
    31 typedef CGdiTestLowLevel *(*GdiTestFunc)();
       
    32 
       
    33 _LIT(KMonospaceTestFontTypefaceName,"Arial");
       
    34 const TInt KMaxFontSize = 200;
       
    35 
       
    36 static inline TBool IsLengthEqual(TInt aLLen, TInt aRLen, TInt aBbLen)
       
    37 	{
       
    38 // The bounding box of a 'w' is one pixel wider than it should be. W overlaps in to the bounding box of 'x' as the two  
       
    39 // are stuck together. So add a tolerance of -1.
       
    40 	return (((aLLen+aRLen)==aBbLen) || ((aLLen+aRLen-1)==aBbLen));
       
    41 	}
       
    42 
       
    43 struct GdiTest
       
    44 	{
       
    45 	GdiTestFunc func;
       
    46 	const TText *txt;
       
    47 	};
       
    48 
       
    49 GdiTest GdiTestFuncs[]={
       
    50 	{BoxTextTest,_S("BoxText")},
       
    51 	{VertTextTest,_S("VertText")},
       
    52 	/*{JustifiedTextTest,_S("JustifiedText")},*/ // DEF107985 The test for JustifiedText has been removed as it was a bad/useless test
       
    53 	{VertBoxTextTest,_S("VertBoxText")},
       
    54 	{SetOriginTest,_S("SetOrigin")},
       
    55 	{PolyLineTest,_S("PolyLine")},
       
    56 	{PolygonTest,_S("Polygon")},
       
    57 	{DrawArcTest,_S("DrawArc")},
       
    58 	{DrawPieTest,_S("DrawPie")},
       
    59 	{DrawRoundRectTest,_S("DrawRoundRect")},
       
    60 	{WideLineTest,_S("WideLine")},
       
    61 	{DrawTextTest,_S("DrawText")},
       
    62 	{DrawRectTest,_S("DrawRect")},
       
    63 	};
       
    64 
       
    65 CTestWindow::CTestWindow(TRgb aCol) : CBlankWindow(aCol)
       
    66 	{
       
    67 	}
       
    68 
       
    69 CTestWindow::~CTestWindow()
       
    70 	{
       
    71 	}
       
    72 
       
    73 void CTestWindow::ConstructL(TPoint aPos,TSize aSize,CTWinBase* aParent, CWindowGc& aGc)
       
    74 	{
       
    75 	iWin=RWindow(TheClient->iWs);
       
    76 	User::LeaveIfError(iWin.Construct(*(aParent->WinTreeNode()),ENullWsHandle));
       
    77 	SetExt(aPos,aSize);
       
    78 	Activate();
       
    79 	AssignGC(aGc);
       
    80 	}
       
    81 
       
    82 void CGdiTestLowLevel::SetGdiTest(CTGdi *aGdiTest)
       
    83 	{
       
    84 	iGdiTest=aGdiTest;
       
    85 	}
       
    86 
       
    87 void CGdiTestLowLevel::AssignGdi(CWindowGc *aGc)
       
    88 	{
       
    89 	iGdi=aGc;
       
    90 	}
       
    91 
       
    92 void CGdiTestLowLevel::ConstructL(TInt)
       
    93 	{
       
    94 	}
       
    95 
       
    96 void CGdiTestLowLevel::PreTestSetupL(const TRect &,TInt)
       
    97 	{
       
    98 	}
       
    99 
       
   100 //=======================================//
       
   101 // Individual GDI low level test classes //
       
   102 //=======================================//
       
   103 
       
   104 
       
   105 void CGdiRect::ConstructL(TInt)
       
   106 	{
       
   107 	}
       
   108 
       
   109 void CGdiRect::PreTestSetupL(const TRect &, TInt aCount)
       
   110 	{
       
   111 	iBrushCol=TRgb::Gray256(aCount&0x1 ? 0xFF : 0x60);
       
   112 	iPenCol=TRgb::Gray256(aCount&0x1 ? 0xA0 : 0x0);
       
   113 	}
       
   114 
       
   115 TInt CGdiRect::Count(TBool )
       
   116 	{
       
   117 	return(1);
       
   118 	}
       
   119 
       
   120 void CGdiDrawRect::BaseTest(const TRect &aRect, TInt aCount)
       
   121 	{
       
   122 	TheTest(aRect,aCount);
       
   123 	}
       
   124 
       
   125 void CGdiDrawRect::TheTest(const TRect &aRect, TInt)
       
   126 	{
       
   127 	iGdi->SetBrushColor(iBrushCol);
       
   128 	iGdi->SetPenColor(iPenCol);
       
   129 	iGdi->DrawRect(aRect);
       
   130 	}
       
   131 
       
   132 TInt CGdiDrawRect::Count(TBool aMode)
       
   133 	{
       
   134 	return(aMode ? 4:1);
       
   135 	}
       
   136 
       
   137 TInt CGdiDrawRoundRect::Count(TBool aMode)
       
   138 	{
       
   139 	return(aMode ? 4:1);
       
   140 	}
       
   141 
       
   142 void CGdiDrawRoundRect::BaseTest(const TRect &aRect, TInt aCount)
       
   143 	{
       
   144 	TheTest(aRect,aCount);
       
   145 	}
       
   146 
       
   147 void CGdiDrawRoundRect::TheTest(const TRect &aRect, TInt aCount)
       
   148 	{
       
   149 	iGdi->SetBrushColor(iBrushCol);
       
   150 	iGdi->SetPenColor(iPenCol);
       
   151 	TSize size((aRect.iBr.iX-aRect.iTl.iX)/4,(aRect.iBr.iY-aRect.iTl.iY)/4);
       
   152 	switch(aCount)
       
   153 		{
       
   154 		case 0:
       
   155 			size.SetSize((aRect.iBr.iX-aRect.iTl.iX)/4,(aRect.iBr.iY-aRect.iTl.iY)/4);
       
   156 			break;
       
   157 		case 1:
       
   158 			size.SetSize(0,0);
       
   159 			break;
       
   160 		case 2:
       
   161 			size.SetSize((aRect.iBr.iX-aRect.iTl.iX)/2,(aRect.iBr.iY-aRect.iTl.iY)/2);
       
   162 			break;
       
   163 		case 3:
       
   164 			size.SetSize((aRect.iBr.iX-aRect.iTl.iX),(aRect.iBr.iY-aRect.iTl.iY));
       
   165 			break;
       
   166 		}
       
   167 	iGdi->DrawRoundRect(aRect,size);
       
   168 	}
       
   169 
       
   170 TInt CGdiDrawACP::Count(TBool )
       
   171 	{
       
   172 	return(1);
       
   173 	}
       
   174 
       
   175 void CGdiDrawACP::ConstructL(TInt)
       
   176 	{
       
   177 	}
       
   178 
       
   179 void CGdiDrawACP::PreTestSetupL(const TRect &, TInt )
       
   180 	{
       
   181 	iBrushCol=TRgb::Gray256(0xff);
       
   182 	iPenCol=TRgb(0,0,0);
       
   183 	}
       
   184 
       
   185 void CGdiDrawArc::BaseTest(const TRect &aRect, TInt aCount)
       
   186 	{
       
   187 	TheTest(aRect,aCount);
       
   188 	}
       
   189 
       
   190 void CGdiDrawArc::TheTest(const TRect &aRect, TInt)
       
   191 	{
       
   192 	iGdi->SetBrushColor(iBrushCol);
       
   193 	iGdi->SetPenColor(iPenCol);
       
   194 	TPoint start(aRect.iTl.iX/2+aRect.iBr.iX,aRect.iTl.iY/2+aRect.iBr.iY);
       
   195 	iGdi->DrawArc(aRect,start,TPoint(0,0));
       
   196 	}
       
   197 
       
   198 void CGdiDrawPie::BaseTest(const TRect &aRect, TInt aCount)
       
   199 	{
       
   200 	TheTest(aRect,aCount);
       
   201 	}
       
   202 
       
   203 void CGdiDrawPie::TheTest(const TRect &aRect, TInt)
       
   204 	{
       
   205 	iGdi->SetBrushColor(iBrushCol);
       
   206 	iGdi->SetPenColor(iPenCol);
       
   207 	TPoint start(aRect.iTl.iX/2+aRect.iBr.iX,aRect.iTl.iY/2+aRect.iBr.iY);
       
   208 	iGdi->DrawPie(aRect,start,TPoint(0,0));
       
   209 	}
       
   210 
       
   211 //
       
   212 // Polyline tests
       
   213 //
       
   214 
       
   215 CGdiPolyLine::CGdiPolyLine() : iPnts(5)
       
   216 	{}
       
   217 
       
   218 void CGdiPolyLine::PreTestSetupL(const TRect &aRect, TInt aCount)
       
   219 	{
       
   220 	iPnts.Reset();
       
   221 	TInt wid=aRect.Width();
       
   222 	TInt hgt=aRect.Height();
       
   223 	if (aCount==0)
       
   224 		{
       
   225 		TInt pos;
       
   226 		for(pos=0;pos<wid;pos+=10)
       
   227 			{
       
   228 			iPnts.AppendL(TPoint(aRect.iTl.iX+pos,aRect.iTl.iY));
       
   229 			iPnts.AppendL(TPoint(aRect.iTl.iX+pos+5,aRect.iBr.iY));
       
   230 			}
       
   231 		for(pos=0;pos<hgt;pos+=10)
       
   232 			{
       
   233 			iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY+pos));
       
   234 			iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iTl.iY+pos+5));
       
   235 			}
       
   236 		}
       
   237 	else
       
   238 		{
       
   239 		TInt hgt=aRect.Height();
       
   240 		iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY));
       
   241 		iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iTl.iY+hgt/2));
       
   242 		iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iBr.iY));
       
   243 		iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iBr.iY));
       
   244 		iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY+hgt/2));
       
   245 		iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iTl.iY));
       
   246 		iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY));
       
   247 		}
       
   248 	}
       
   249 
       
   250 void CGdiPolyLine::ConstructL(TInt )
       
   251 	{
       
   252 	}
       
   253 
       
   254 TInt CGdiPolyLine::Count(TBool aMainTests)
       
   255 	{
       
   256 	return(aMainTests ? 2 : 1);
       
   257 	}
       
   258 
       
   259 void CGdiPolyLine::BaseTest(const TRect &, TInt )
       
   260 	{
       
   261 	TPoint prev;
       
   262 	TInt index;
       
   263 	for(index=0;index<iPnts.Count();index++)
       
   264 		{
       
   265 		if (index>0)
       
   266 			iGdi->DrawLine(prev,iPnts[index]);
       
   267 		prev=iPnts[index];
       
   268 		}
       
   269 	if (index>0)
       
   270 		iGdi->Plot(iPnts[index-1]);
       
   271 	}
       
   272 
       
   273 void CGdiPolyLine::TheTest(const TRect &, TInt )
       
   274 	{
       
   275 	iGdi->DrawPolyLine(&iPnts);
       
   276 	}
       
   277 
       
   278 //
       
   279 // Polygon tests //
       
   280 //
       
   281 
       
   282 CGdiPolygon::CGdiPolygon() : iPnts(5)
       
   283 	{}
       
   284 
       
   285 void CGdiPolygon::PreTestSetupL(const TRect &aRect, TInt )
       
   286 	{
       
   287 	iPnts.Reset();
       
   288 	TPoint pnt;
       
   289 	TInt maxPoints=Min((TInt)KMaxPolygonPoints,Min(aRect.Width(),aRect.Height())/KPolygonStep);
       
   290 	TInt numPoints=0;
       
   291 	if (maxPoints>0)
       
   292 		{
       
   293 		iPnts.AppendL(aRect.iTl);
       
   294 		while(numPoints<maxPoints)
       
   295 			{
       
   296 			if (numPoints&1)
       
   297 				pnt.SetXY(aRect.iTl.iX+(numPoints+1)*KPolygonStep,aRect.iTl.iY+numPoints*KPolygonStep);
       
   298 			else
       
   299 				pnt.SetXY(aRect.iTl.iX+numPoints*KPolygonStep,aRect.iTl.iY+(numPoints+1)*KPolygonStep);
       
   300 			iPnts.AppendL(pnt);
       
   301 			numPoints++;
       
   302 			}
       
   303 		pnt.SetXY(aRect.iTl.iX+numPoints*KPolygonStep,aRect.iTl.iY+numPoints*KPolygonStep);
       
   304 		iPnts.AppendL(pnt);
       
   305 		while(numPoints>0)
       
   306 			{
       
   307 			numPoints--;
       
   308 			if (numPoints&1)
       
   309 				pnt.SetXY(aRect.iTl.iX+numPoints*KPolygonStep,aRect.iTl.iY+(numPoints+1)*KPolygonStep);
       
   310 			else
       
   311 				pnt.SetXY(aRect.iTl.iX+(numPoints+1)*KPolygonStep,aRect.iTl.iY+numPoints*KPolygonStep);
       
   312 			iPnts.AppendL(pnt);
       
   313 			}
       
   314 		}
       
   315 	}
       
   316 
       
   317 void CGdiPolygon::ConstructL(TInt )
       
   318 	{
       
   319 	}
       
   320 
       
   321 TInt CGdiPolygon::Count(TBool aMainTests)
       
   322 	{
       
   323 	return(aMainTests ? 2 : 1);
       
   324 	}
       
   325 
       
   326 void CGdiPolygon::BaseTest(const TRect &aRect, TInt )
       
   327 	{
       
   328 	iGdi->SetPenColor(TRgb::Gray4(2));
       
   329 	iGdi->SetBrushColor(TRgb::Gray4(1));
       
   330 	iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   331 	TInt maxPoints=Min((TInt)KMaxPolygonPoints,Min(aRect.Width(),aRect.Height())/KPolygonStep);
       
   332 	for(TInt numPoints=0;numPoints<maxPoints;numPoints++)
       
   333 		iGdi->DrawRect(TRect(aRect.iTl.iX+numPoints*KPolygonStep + 1,aRect.iTl.iY+numPoints*KPolygonStep + 1,
       
   334 							 aRect.iTl.iX+(numPoints+1)*KPolygonStep ,aRect.iTl.iY+(numPoints+1)*KPolygonStep));
       
   335 	}
       
   336 
       
   337 void CGdiPolygon::TheTest(const TRect &, TInt )
       
   338 //This is the only one that can leave so it's not worth adding an 'L'
       
   339 	{
       
   340 	iGdi->SetPenColor(TRgb::Gray4(2));
       
   341 	iGdi->SetBrushColor(TRgb::Gray4(1));
       
   342 	iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   343 	User::LeaveIfError(iGdi->DrawPolygon(&iPnts,CGraphicsContext::EAlternate));
       
   344 	}
       
   345 
       
   346 //
       
   347 
       
   348 TInt CGdiWideLine::Count(TBool aMainTests)
       
   349 	{
       
   350 	return(aMainTests ? EMainNumWidths : EMinorNumWidths);
       
   351 	}
       
   352 
       
   353 void CGdiWideLine::ConstructL(TInt)
       
   354 	{
       
   355 	}
       
   356 
       
   357 void CGdiWideLine::PreTestSetupL(const TRect &, TInt aCount)
       
   358 	{
       
   359 	TInt widths[]={1,4,50,-2,
       
   360 				   48,12345,0,3,
       
   361 				   48,123,0,3,
       
   362 				   4,111,555,1000,
       
   363 				   10,-1,-10,-100};
       
   364 	iWidth=widths[aCount];
       
   365 	}
       
   366 
       
   367 void CGdiWideLine::BaseTest(const TRect &aRect, TInt)
       
   368 	{
       
   369 	iGdi->SetPenSize(TSize(iWidth,iWidth));
       
   370 	iGdi->DrawLine(aRect.iTl,aRect.iBr);
       
   371 	iGdi->MoveTo(aRect.iTl+TPoint(0,10));
       
   372 	iGdi->DrawLineBy(aRect.iBr-aRect.iTl);
       
   373 	iGdi->MoveBy(aRect.iTl-aRect.iBr+TPoint(0,10));
       
   374 	iGdi->DrawLineTo(aRect.iBr+TPoint(0,20));
       
   375 	}
       
   376 
       
   377 void CGdiWideLine::TheTest(const TRect &aRect, TInt)
       
   378 	{
       
   379 	iGdi->SetPenSize(TSize(iWidth,iWidth));
       
   380 	iGdi->MoveTo(aRect.iTl);
       
   381 	iGdi->DrawLineBy(aRect.iBr-aRect.iTl);
       
   382 	iGdi->MoveBy(aRect.iTl-aRect.iBr+TPoint(0,10));
       
   383 	iGdi->DrawLineTo(aRect.iBr+TPoint(0,10));
       
   384 	iGdi->DrawLine(aRect.iTl+TPoint(0,20),aRect.iBr+TPoint(0,20));
       
   385 	}
       
   386 
       
   387 //
       
   388 // Set Origin //
       
   389 //
       
   390 
       
   391 CGdiSetOrigin::~CGdiSetOrigin()
       
   392 	{
       
   393 	delete iPolylineArray;
       
   394 	delete iPolygonArray;
       
   395 	TheClient->iScreen->ReleaseFont(iFont);
       
   396 	}
       
   397 
       
   398 TInt CGdiSetOrigin::Count(TBool )
       
   399 	{
       
   400 	return(1);
       
   401 	}
       
   402 
       
   403 void CGdiSetOrigin::ConstructL(TInt)
       
   404 	{
       
   405 	iPolylineArray=new(ELeave) CArrayFixFlat<TPoint>(3);
       
   406 	iPolylineArray->AppendL(TPoint(40,1));
       
   407 	iPolylineArray->AppendL(TPoint(50,11));
       
   408 	iPolylineArray->AppendL(TPoint(40,21));
       
   409 	iPolygonArray=new(ELeave) CArrayFixFlat<TPoint>(3);
       
   410 	iPolygonArray->AppendL(TPoint(40,30));
       
   411 	iPolygonArray->AppendL(TPoint(50,40));
       
   412 	iPolygonArray->AppendL(TPoint(40,45));
       
   413 	TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
       
   414 	User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
       
   415 	}
       
   416 
       
   417 void CGdiSetOrigin::PreTestSetupL(const TRect &, TInt )
       
   418 	{
       
   419 	}
       
   420 
       
   421 void CGdiSetOrigin::DrawIt(const TPoint &aOffset)
       
   422 	{
       
   423 	iGdi->DrawLine(TPoint(10,10)+aOffset,TPoint(20,30)+aOffset);
       
   424 	iGdi->DrawLineBy(TPoint(-10,5));
       
   425 	iGdi->DrawLineTo(TPoint(20,5)+aOffset);
       
   426 	iGdi->MoveTo(TPoint(20,10)+aOffset);
       
   427 	iGdi->DrawLineTo(TPoint(30,15)+aOffset);
       
   428 	iGdi->MoveBy(TPoint(-10,2));
       
   429 	iGdi->DrawLineBy(TPoint(10,0));
       
   430 	iGdi->UseFont(iFont);
       
   431 	iGdi->DrawText(_L("Set Origin Test"),TPoint(40,20)+aOffset);
       
   432 	iGdi->DiscardFont();
       
   433 	iGdi->DrawRect(TRect(TPoint(10,45)+aOffset,TPoint(20,55)+aOffset));
       
   434 	iGdi->DrawRoundRect(TRect(TPoint(21,45)+aOffset,TPoint(30,55)+aOffset),TSize(3,2));
       
   435 	iGdi->DrawEllipse(TRect(TPoint(31,45)+aOffset,TPoint(40,55)+aOffset));
       
   436 	TInt index;
       
   437 	for(index=0;index<iPolylineArray->Count();index++)
       
   438 		(*iPolylineArray)[index]+=aOffset;
       
   439 	iGdi->DrawPolyLine(iPolylineArray);
       
   440 	for(index=0;index<iPolylineArray->Count();index++)
       
   441 		(*iPolylineArray)[index]-=aOffset;
       
   442 	for(index=0;index<iPolygonArray->Count();index++)
       
   443 		(*iPolygonArray)[index]+=aOffset;
       
   444 	iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   445 	User::LeaveIfError(iGdi->DrawPolygon(iPolygonArray,CGraphicsContext::EAlternate));		//Doesn't cause any harm if it leaves
       
   446 	for(index=0;index<iPolygonArray->Count();index++)
       
   447 		(*iPolygonArray)[index]-=aOffset;
       
   448 	}
       
   449 
       
   450 void CGdiSetOrigin::BaseTest(const TRect &aRect, TInt)
       
   451 	{
       
   452 	DrawIt(aRect.iTl);
       
   453 	}
       
   454 
       
   455 void CGdiSetOrigin::TheTest(const TRect &aRect, TInt)
       
   456 	{
       
   457 	iGdi->SetOrigin(aRect.iTl);
       
   458 	DrawIt(TPoint(0,0));
       
   459 	}
       
   460 
       
   461 //
       
   462 // Draw text //
       
   463 //
       
   464 
       
   465 CGdiDrawText::~CGdiDrawText()
       
   466 	{
       
   467 	TheClient->iScreen->ReleaseFont(iFont);
       
   468 	}
       
   469 
       
   470 TInt CGdiDrawText::Count(TBool )
       
   471 	{
       
   472 	return(1);
       
   473 	}
       
   474 
       
   475 void CGdiDrawText::ConstructL(TInt)
       
   476 	{
       
   477 	TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
       
   478 	User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
       
   479 	TInt index;
       
   480 	for(index=0;index<iBigBuffer.MaxLength();index++)
       
   481 		iBigBuffer.Append(TChar((index%26)+'a'));
       
   482 	const TInt characters=iBigBuffer.Length();
       
   483 	TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
       
   484 	for(index=0;index<iBigBuffer.MaxLength();index+=33)
       
   485 		{
       
   486 		TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(index));
       
   487 		TInt rLen=iFont->TextWidthInPixels(iBigBuffer.Right(characters-index));
       
   488 		TBool result = IsLengthEqual(lLen,rLen,bbLen);
       
   489 		iGdiTest->TEST(result);
       
   490 		if (!result)
       
   491 			{
       
   492 			_LIT(KLog,"Font width metrics error, Width(%dchars)=%d, Width(%dchars)=%d, Width(%dchars)=%d");
       
   493 			iGdiTest->LOG_MESSAGE7(KLog,index,lLen,characters-index,rLen,characters,bbLen);
       
   494 			}
       
   495 		}
       
   496 	}
       
   497 
       
   498 void CGdiDrawText::PreTestSetupL(const TRect&,TInt)
       
   499 	{}
       
   500 
       
   501 void CGdiDrawText::BaseTest(const TRect& aRect,TInt)
       
   502 	{
       
   503 	TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
       
   504 	TInt fAscent=iFont->AscentInPixels();
       
   505 	TInt fHeight=iFont->HeightInPixels();
       
   506 	iGdi->UseFont(iFont);
       
   507 //
       
   508 	iGdi->DrawText(_L("Hello"), TPoint(aRect.iTl.iX, aRect.iTl.iY+fAscent));
       
   509 	TInt missingChars=iFont->TextCount(iBigBuffer,bbLen-aRect.iBr.iX)-1;	// -1 so one off screen char is drawn to handle overhang
       
   510 	if (missingChars>=0)
       
   511 		{
       
   512 		TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars);
       
   513 		TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars));
       
   514 		TInt rLen=iFont->TextWidthInPixels(bbb);
       
   515 		TBool result = IsLengthEqual(lLen,rLen,bbLen);
       
   516 		iGdiTest->TEST(result);
       
   517 		if (!result)
       
   518 			{
       
   519 			_LIT(KLog,"Font width metrics error, missingChars=%d  %d+%d=%d");
       
   520 			iGdiTest->LOG_MESSAGE5(KLog,missingChars,lLen,rLen,bbLen);
       
   521 			}
       
   522 		iGdi->DrawText(bbb,TPoint(aRect.iBr.iX-rLen,aRect.iTl.iY+fAscent+fHeight));
       
   523 		}
       
   524 	iGdi->DiscardFont();
       
   525 	}
       
   526 
       
   527 void CGdiDrawText::TheTest(const TRect& aRect,TInt)
       
   528 	{
       
   529 	TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
       
   530 	TInt fAscent=iFont->AscentInPixels();
       
   531 	TInt fHeight=iFont->HeightInPixels();
       
   532 	iGdi->UseFont(iFont);
       
   533 //
       
   534 	iGdi->DrawText(_L("Hello"), TPoint(aRect.iTl.iX, aRect.iTl.iY+fAscent));
       
   535 	iGdi->DrawText(iBigBuffer,TPoint(aRect.iBr.iX-bbLen,aRect.iTl.iY+fAscent+fHeight));
       
   536 	iGdi->DiscardFont();
       
   537 	}
       
   538 
       
   539 //
       
   540 // Draw vertical text //
       
   541 //
       
   542 
       
   543 CGdiDrawVertText::~CGdiDrawVertText()
       
   544 	{
       
   545 	TheClient->iScreen->ReleaseFont(iFont);
       
   546 	}
       
   547 
       
   548 TInt CGdiDrawVertText::Count(TBool )
       
   549 	{
       
   550 	return(1);
       
   551 	}
       
   552 
       
   553 void CGdiDrawVertText::ConstructL(TInt)
       
   554 	{
       
   555 	TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
       
   556 	User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
       
   557 	TInt index;
       
   558 	for(index=0;index<iBigBuffer.MaxLength();index++)
       
   559 		iBigBuffer.Append(TChar((index%26)+'a'));
       
   560 //
       
   561 	TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
       
   562 	for(index=0;index<iBigBuffer.MaxLength();index+=33)
       
   563 		{
       
   564 		TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(index));
       
   565 		TInt rLen=iFont->TextWidthInPixels(iBigBuffer.Right(iBigBuffer.Length()-index));
       
   566 		TBool result = IsLengthEqual(lLen,rLen,bbLen);
       
   567 		iGdiTest->TEST(result);
       
   568 		if (!result)
       
   569 			iGdiTest->INFO_PRINTF3(_L("iFont->TextWidthInPixels(iBigBuffer) return value - Expected: %d, Actual: %d"), lLen+rLen, bbLen);		
       
   570 		}
       
   571 	}
       
   572 
       
   573 void CGdiDrawVertText::PreTestSetupL(const TRect &, TInt )
       
   574 	{
       
   575 	}
       
   576 
       
   577 void CGdiDrawVertText::BaseTest(const TRect &aRect, TInt)
       
   578 	{
       
   579 	TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
       
   580 	TInt fAscent=iFont->AscentInPixels();
       
   581 	TInt fHeight=iFont->HeightInPixels();
       
   582 	iGdi->UseFont(iFont);
       
   583 //
       
   584 	TInt tlen=iFont->TextWidthInPixels(_L("Hello"));
       
   585 	iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iTl.iX+fAscent, aRect.iTl.iY+tlen), ETrue);
       
   586 	iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iBr.iX-fAscent, aRect.iTl.iY), EFalse);
       
   587 	TInt missingChars=iFont->TextCount(iBigBuffer,bbLen-aRect.iBr.iY)-1;	// -1 so one off screen char is drawn to handle overhang
       
   588 	if (missingChars>=0)
       
   589 		{
       
   590 		TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars);
       
   591 		TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars));
       
   592 		TInt rLen=iFont->TextWidthInPixels(bbb);
       
   593 		TBool result = IsLengthEqual(lLen,rLen,bbLen);
       
   594 		iGdiTest->TEST(result);
       
   595 		if (!result)
       
   596 			iGdiTest->INFO_PRINTF3(_L("iFont->TextWidthInPixels(iBigBuffer) return value - Expected: %d, Actual: %d"), lLen+rLen, bbLen);		
       
   597 
       
   598 		iGdi->DrawTextVertical(bbb,TPoint(aRect.iTl.iX+fHeight-fAscent+fHeight,aRect.iBr.iY-rLen),EFalse);
       
   599 		}
       
   600 	iGdi->DiscardFont();
       
   601 	}
       
   602 
       
   603 void CGdiDrawVertText::TheTest(const TRect &aRect, TInt)
       
   604 	{
       
   605 	TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
       
   606 	TInt fAscent=iFont->AscentInPixels();
       
   607 	TInt fHeight=iFont->HeightInPixels();
       
   608 	iGdi->UseFont(iFont);
       
   609 //
       
   610 	TInt tlen=iFont->TextWidthInPixels(_L("Hello"));
       
   611 	iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iTl.iX+fAscent, aRect.iTl.iY+tlen), ETrue);
       
   612 	iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iBr.iX-fAscent, aRect.iTl.iY), EFalse);
       
   613 	iGdi->DrawTextVertical(iBigBuffer,TPoint(aRect.iTl.iX+fHeight-fAscent+fHeight,aRect.iBr.iY-bbLen),EFalse);
       
   614 	iGdi->DiscardFont();
       
   615 	}
       
   616 
       
   617 //
       
   618 // Draw Justified text //
       
   619 //
       
   620 
       
   621 // DEF107985 The test for JustifiedText has been removed as it was a bad/useless test. The original test was 
       
   622 // broken after it was migrated to TEF TGdi test. It was not worth fixing as the purpose of test was not clear, 
       
   623 // and fixing it basically required rewriting the whole test. 
       
   624 //  
       
   625 
       
   626 
       
   627 //
       
   628 // Box text //
       
   629 //
       
   630 
       
   631 CGdiBoxText::~CGdiBoxText()
       
   632 	{
       
   633 	TheClient->iScreen->ReleaseFont(iFont);
       
   634 	}
       
   635 
       
   636 TInt CGdiBoxText::Count(TBool )
       
   637 	{
       
   638 	return(1);
       
   639 	}
       
   640 
       
   641 void CGdiBoxText::ConstructL(TInt)
       
   642 	{
       
   643 	TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
       
   644 	User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
       
   645 	for(TInt index=0;index<iBigBuffer.MaxLength();index++)
       
   646 		iBigBuffer.Append(TChar((index%26)+'a'));
       
   647 	iBbLen=iFont->TextWidthInPixels(iBigBuffer);
       
   648 	}
       
   649 
       
   650 void CGdiBoxText::PreTestSetupL(const TRect &, TInt )
       
   651 	{
       
   652 	}
       
   653 
       
   654 void CGdiBoxText::BaseTest(const TRect &aRect, TInt)
       
   655 	{
       
   656 	TInt rWid=aRect.iBr.iX-aRect.iTl.iX;
       
   657 	TInt fAscent=iFont->AscentInPixels();
       
   658 	TInt fHeight=iFont->HeightInPixels();
       
   659 	iGdi->UseFont(iFont);
       
   660 	iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   661 //
       
   662 	TRect rect(aRect);
       
   663 	rect.iBr.iY=rect.iTl.iY+fHeight;
       
   664 //
       
   665 	TInt missingChars=iFont->TextCount(iBigBuffer,iBbLen-rWid);
       
   666 	TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars);
       
   667 	TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars));
       
   668 	TInt rLen=iFont->TextWidthInPixels(bbb);
       
   669 	TBool result = IsLengthEqual(lLen,rLen,iBbLen);
       
   670 	iGdiTest->TEST(result);	
       
   671 	if (!result)
       
   672 			iGdiTest->INFO_PRINTF3(_L("(lLen+rLen)==iBbLen return value - Expected: %d, Actual: %d"), lLen+rLen, iBbLen);		
       
   673 
       
   674 	iGdi->DrawText(bbb, rect, fAscent,CGraphicsContext::ELeft, rWid-rLen);
       
   675 //
       
   676 	rect.Move(TPoint(0,fHeight));
       
   677 	iGdi->DrawText(iBigBuffer, rect, fAscent,CGraphicsContext::ELeft, 0);
       
   678 //
       
   679 	TBuf<10> buf2(_L("1234567890"));
       
   680 	rect.Move(TPoint(0,fHeight));
       
   681 	iGdi->DrawText(buf2,rect,fAscent,CGraphicsContext::ERight,rect.Width()-iFont->TextWidthInPixels(buf2));
       
   682 	}
       
   683 
       
   684 void CGdiBoxText::TheTest(const TRect &aRect, TInt)
       
   685 	{
       
   686 	TInt rWid=aRect.iBr.iX-aRect.iTl.iX;
       
   687 	TInt fAscent=iFont->AscentInPixels();
       
   688 	TInt fHeight=iFont->HeightInPixels();
       
   689 	iGdi->UseFont(iFont);
       
   690 	iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   691 	TRect rect(aRect);
       
   692 	rect.iBr.iY=rect.iTl.iY+fHeight;
       
   693 //
       
   694 	iGdi->DrawText(iBigBuffer, rect, fAscent, CGraphicsContext::ELeft, rWid-iBbLen);
       
   695 //
       
   696 	rect.Move(TPoint(0,fHeight));
       
   697 	iGdi->Clear(rect);
       
   698 	iGdi->SetClippingRegion(TRegionFix<1>(rect));
       
   699 	iGdi->DrawText(iBigBuffer, rect.iTl+TPoint(0,fAscent));
       
   700 	TBuf<10> buf2(_L("1234567890"));
       
   701 	rect.Move(TPoint(0,fHeight));
       
   702 	iGdi->CancelClippingRegion();
       
   703 	iGdi->DrawText(buf2,rect,fAscent);
       
   704 	}
       
   705 
       
   706 //
       
   707 // Vert Box text //
       
   708 //
       
   709 
       
   710 CGdiVertBoxText::~CGdiVertBoxText()
       
   711 	{
       
   712 	TheClient->iScreen->ReleaseFont(iFont);
       
   713 	}
       
   714 
       
   715 TInt CGdiVertBoxText::Count(TBool )
       
   716 	{
       
   717 	return(1);
       
   718 	}
       
   719 
       
   720 void CGdiVertBoxText::ConstructL(TInt)
       
   721 	{
       
   722 	TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
       
   723 	User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
       
   724 	for(TInt index=0;index<iBigBuffer.MaxLength();index++)
       
   725 		iBigBuffer.Append(TChar((index%26)+'a'));
       
   726 	iBbLen=iFont->TextWidthInPixels(iBigBuffer);
       
   727 	}
       
   728 
       
   729 void CGdiVertBoxText::PreTestSetupL(const TRect &, TInt )
       
   730 	{
       
   731 	}
       
   732 
       
   733 void CGdiVertBoxText::BaseTest(const TRect &aRect, TInt)
       
   734 	{
       
   735 	TInt rWid=aRect.iBr.iY-aRect.iTl.iY;
       
   736 	TInt fAscent=iFont->AscentInPixels();
       
   737 	TInt fHeight=iFont->HeightInPixels();
       
   738 	iGdi->UseFont(iFont);
       
   739 	iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   740 //
       
   741 	TRect rect(aRect);
       
   742 	rect.iBr.iX=rect.iTl.iX+fHeight;
       
   743 //
       
   744 	TInt missingChars=iFont->TextCount(iBigBuffer,iBbLen-rWid);
       
   745 	TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars+1);
       
   746 	TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars-1));
       
   747 	TInt rLen=iFont->TextWidthInPixels(bbb);
       
   748 	TBool result = IsLengthEqual(lLen,rLen,iBbLen);
       
   749 	iGdiTest->TEST(result);
       
   750 	if (!result)
       
   751 			iGdiTest->INFO_PRINTF3(_L("(lLen+rLen)==iBbLen return value - Expected: %d, Actual: %d"), lLen+rLen, iBbLen);		
       
   752 
       
   753 	iGdi->DrawTextVertical(bbb, rect, fAscent, ETrue,CGraphicsContext::ELeft, rWid-rLen);
       
   754 //
       
   755 	rect.iTl.iX=rect.iBr.iX;
       
   756 	rect.iBr.iX=rect.iTl.iX+fHeight;
       
   757 	iGdi->DrawTextVertical(iBigBuffer, rect, fAscent, ETrue,CGraphicsContext::ELeft, 0);
       
   758 	}
       
   759 
       
   760 void CGdiVertBoxText::TheTest(const TRect &aRect, TInt)
       
   761 	{
       
   762 	TInt rWid=aRect.iBr.iY-aRect.iTl.iY;
       
   763 	TInt fAscent=iFont->AscentInPixels();
       
   764 	TInt fHeight=iFont->HeightInPixels();
       
   765 	iGdi->UseFont(iFont);
       
   766 	iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   767 	TRect rect(aRect);
       
   768 	rect.iBr.iX=rect.iTl.iX+fHeight;
       
   769 //
       
   770 	iGdi->DrawTextVertical(iBigBuffer, rect, fAscent, ETrue, CGraphicsContext::ELeft, rWid-iBbLen);
       
   771 //
       
   772 	rect.iTl.iX=rect.iBr.iX;
       
   773 	rect.iBr.iX=rect.iTl.iX+fHeight;
       
   774 	iGdi->Clear(rect);
       
   775 	iGdi->SetClippingRegion(TRegionFix<1>(rect));
       
   776 	iGdi->DrawTextVertical(iBigBuffer, TPoint(rect.iTl.iX+fAscent,rect.iBr.iY), ETrue);
       
   777 	}
       
   778 
       
   779 
       
   780 //
       
   781 //
       
   782 CGdiBlitMasked::~CGdiBlitMasked()
       
   783 	{
       
   784 	for(TInt index=0;index<ENumMasks;index++)
       
   785 		delete iMask[index];
       
   786 	delete iBitmap;
       
   787 	delete iScratch;
       
   788 	delete iScratchDevice;
       
   789 	delete iScratchGc;
       
   790 	delete iScratchMask;
       
   791 	delete iScratchMaskDevice;
       
   792 	delete iScratchMaskGc;
       
   793 	}
       
   794 
       
   795 TInt CGdiBlitMasked::Count(TBool aMainTests)
       
   796 	{
       
   797 	return(aMainTests ? ENumMasks*2 : ENumMasks*2);
       
   798 	}
       
   799 
       
   800 void CGdiBlitMasked::doCreateTestBitmapL(CFbsBitmap *aBitmap, CFbsBitGc *&aGc, CFbsBitmapDevice *&aDevice, const TSize &aSize)
       
   801 	{
       
   802 	User::LeaveIfNull(aDevice=CFbsBitmapDevice::NewL(aBitmap));
       
   803 	User::LeaveIfError(aDevice->CreateContext(aGc));
       
   804 //
       
   805 	aGc->SetBrushColor(TRgb(128,128,128));
       
   806 	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   807 	aGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   808 	aGc->DrawRect(TRect(aBitmap->SizeInPixels()));
       
   809 	aGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   810 	for(TInt index=(-aSize.iHeight);index<aSize.iWidth;index+=5)
       
   811 		{
       
   812 		aGc->DrawLine(TPoint(index,0),TPoint(index+aSize.iHeight,aSize.iHeight));
       
   813 		aGc->DrawLine(TPoint(index,aSize.iHeight),TPoint(index+aSize.iHeight,0));
       
   814 		}
       
   815 	}
       
   816 
       
   817 void CGdiBlitMasked::createTestBitmapL(CFbsBitmap *&aBitmap, const TSize &aSize)
       
   818 	{
       
   819 	CFbsBitGc *gc=NULL;
       
   820 	CFbsBitmapDevice *device=NULL;
       
   821 	aBitmap=new(ELeave) CFbsBitmap();
       
   822 	User::LeaveIfError(aBitmap->Create(aSize,EGray16));
       
   823 	TRAPD(err,doCreateTestBitmapL(aBitmap, gc, device, aSize));
       
   824 	delete gc;
       
   825 	delete device;
       
   826 	User::LeaveIfError(err);
       
   827 	}
       
   828 
       
   829 void CGdiBlitMasked::ConstructL(TInt)
       
   830 	{
       
   831 	TSize max(0,0);
       
   832 	for(TInt index=0;index<ENumMasks;index++)
       
   833 		{
       
   834 		iMask[index]=new(ELeave) CFbsBitmap();
       
   835 		User::LeaveIfError(iMask[index]->Load(TAUTO_BITMAP_NAME,2+index));
       
   836 		TSize size=iMask[index]->SizeInPixels();
       
   837 		if (max.iWidth<size.iWidth)
       
   838 			max.iWidth=size.iWidth;
       
   839 		if (max.iHeight<size.iHeight)
       
   840 			max.iHeight=size.iHeight;
       
   841 		}
       
   842 	iScratch=new(ELeave) CFbsBitmap();
       
   843 	User::LeaveIfError(iScratch->Create(max,EGray16));
       
   844 	iScratchDevice=CFbsBitmapDevice::NewL(iScratch);
       
   845 	User::LeaveIfError(iScratchDevice->CreateContext(iScratchGc));
       
   846 
       
   847 	iScratchMask=new(ELeave) CFbsBitmap();
       
   848 	User::LeaveIfError(iScratchMask->Create(max,EGray16));
       
   849 	iScratchMaskDevice=CFbsBitmapDevice::NewL(iScratchMask);
       
   850 	User::LeaveIfError(iScratchMaskDevice->CreateContext(iScratchMaskGc));
       
   851 //
       
   852 	createTestBitmapL(iBitmap, max);
       
   853 	}
       
   854 
       
   855 void CGdiBlitMasked::PreTestSetupL(const TRect &, TInt aCount)
       
   856 	{
       
   857 	iInvertMask=aCount&0x1;
       
   858 	aCount>>=1;
       
   859 	iCurrMask= iMask[aCount%ENumMasks];
       
   860 	iDrawMode=CGraphicsContext::EDrawModePEN;
       
   861 	}
       
   862 
       
   863 void CGdiBlitMasked::BaseTest(const TRect &aRect, TInt)
       
   864 	{
       
   865 // needs re-writing to emulate tiling of the source rect
       
   866 	if (!aRect.Intersects(TRect(BaseWin->Size())))
       
   867 		return;
       
   868 	TSize size(aRect.Size());
       
   869 	TSize bitSize=iBitmap->SizeInPixels();
       
   870 	if (size.iWidth>bitSize.iWidth)
       
   871 		size.iWidth=bitSize.iWidth;
       
   872 	if (size.iHeight>bitSize.iHeight)
       
   873 		size.iHeight=bitSize.iHeight;
       
   874 //
       
   875 // Set up the scratch mask as a black and white bitmap containing the mask to blit
       
   876 // The mask pattern is replicated all over the scratchmask bitmap
       
   877 //
       
   878 	iScratchMaskGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   879 	iScratchMaskGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   880 	iScratchMaskGc->SetBrushColor(TRgb(0,0,0));
       
   881 	iScratchMaskGc->DrawRect(TRect(iScratchMask->SizeInPixels()));
       
   882 	iScratchMaskGc->SetPenColor(TRgb(255,255,255));
       
   883 	iScratchMaskGc->SetPenStyle(CGraphicsContext::ESolidPen);
       
   884 	TSize maskSize(iCurrMask->SizeInPixels());
       
   885 	TPoint pos;
       
   886 	TRgb *rgbBuf=(TRgb *)User::AllocL(maskSize.iWidth*sizeof(TRgb));		//Doesn't do any harm if it leaves
       
   887 	for(pos.iY=0;pos.iY<maskSize.iHeight;pos.iY++)
       
   888 		{
       
   889 		TPtr8 ptr((TUint8 *)rgbBuf,maskSize.iWidth*sizeof(TRgb));
       
   890 		iCurrMask->GetScanLine(ptr, pos, maskSize.iWidth, ERgb);
       
   891 		for(TInt index=0;index<maskSize.iWidth;index++)
       
   892 			{
       
   893 			iScratchMaskGc->SetPenColor(rgbBuf[index]);
       
   894 //			if ((isLow && !iLowCutOff) || (!isLow && iLowCutOff))
       
   895 				iScratchMaskGc->Plot(TPoint(index,pos.iY));
       
   896 			}
       
   897 		}
       
   898 	User::Free(rgbBuf);
       
   899 
       
   900 	for(pos.iY=0;pos.iY<size.iHeight;pos.iY+=maskSize.iHeight)
       
   901 		for(pos.iX=0;pos.iX<size.iWidth;pos.iX+=maskSize.iWidth)
       
   902 			iScratchMaskGc->CopyRect(pos, TRect(maskSize));
       
   903 //
       
   904 // Blit this to the screen in ANDNOT mode to clear all the pixels we want the mask blit to draw to
       
   905 //
       
   906 	iGdi->SetDrawMode(CGraphicsContext::EDrawModeANDNOT);
       
   907 	iGdi->BitBlt(aRect.iTl, iScratchMask, TRect(size));
       
   908 //
       
   909 // Copy the test bitmap to the scratch bitmap then use the scratch mask to clear all the bits
       
   910 // that should masked out of the draw to the screen
       
   911 //
       
   912 	iScratchGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   913 	iScratchGc->BitBlt(TPoint(0,0), iBitmap);
       
   914 	iScratchGc->SetDrawMode(CGraphicsContext::EDrawModeAND);
       
   915 	iScratchGc->BitBlt(TPoint(0,0), iScratchMask);
       
   916 //
       
   917 // Now copy the scratch bitmap to the screen in OR mode to get the final result
       
   918 //
       
   919 	iGdi->SetDrawMode(CGraphicsContext::EDrawModeOR);
       
   920 	iGdi->BitBlt(aRect.iTl, iScratch, TRect(size));
       
   921 	}
       
   922 
       
   923 void CGdiBlitMasked::TheTest(const TRect &aRect, TInt)
       
   924 	{
       
   925 	iGdi->BitBltMasked(aRect.iTl,iBitmap,TRect((aRect.iBr-aRect.iTl).AsSize()),
       
   926 						iCurrMask,iInvertMask);
       
   927 	}
       
   928 //
       
   929 //
       
   930 
       
   931 CTGdi::CTGdi(CTestStep* aStep) : CTWsGraphicsBase(aStep), iGdiTest (NULL), iTextOffsetX(10),iTextOffsetY(10)
       
   932 	{
       
   933 	}
       
   934 
       
   935 void CTGdi::ConstructL()
       
   936 	{
       
   937 	iWinSize=TestWin->Size();
       
   938 	}
       
   939 
       
   940 TSize CTGdi::WinSize()
       
   941 	{
       
   942 	return(iWinSize);
       
   943 	}
       
   944 
       
   945 void CTGdi::DoGdiTestL(const TRect &aRect, TInt aNum)
       
   946 	{
       
   947 //
       
   948 	iGdiTest->PreTestSetupL(aRect,aNum);
       
   949 //
       
   950 	BaseWin->Win()->Invalidate();
       
   951 	BaseWin->Win()->BeginRedraw();
       
   952 	TheGc->Activate(*BaseWin->Win());
       
   953 	iTest->DrawTestBackground(EFalse,BaseWin->Size());
       
   954 	iGdiTest->BaseTest(aRect,aNum);
       
   955 	TheGc->Deactivate();
       
   956 	BaseWin->Win()->EndRedraw();
       
   957 //
       
   958 	TestWin->Win()->Invalidate();
       
   959 	TestWin->Win()->BeginRedraw();
       
   960 	TheGc->Activate(*TestWin->Win());
       
   961 	iTest->DrawTestBackground(EFalse,TestWin->Size());
       
   962 	iGdiTest->TheTest(aRect,aNum);
       
   963 	TheGc->Deactivate();
       
   964 	TestWin->Win()->EndRedraw();
       
   965 //
       
   966 	TheClient->iWs.Flush();
       
   967 	TheClient->WaitForRedrawsToFinish();
       
   968 	TheClient->iWs.Finish();
       
   969 //
       
   970 	_LIT(KLog,"GDI Substate=%d  test=%d  rect=(%d,%d,%d,%d) ");
       
   971 	TBuf<64> buf;
       
   972 	buf.Format(KLog,iSubState,aNum,aRect.iTl.iX,aRect.iTl.iY,aRect.iBr.iX,aRect.iBr.iY);
       
   973 	iTestPassing=CompareWindows(buf);
       
   974 	}
       
   975 
       
   976 void CTGdi::GdiTestL(CGdiTestLowLevel *aTest)
       
   977 	{
       
   978 	TTestRects::ResetSeed();
       
   979 	iTestPassing=ETrue;
       
   980 	iGdiTest=aTest;
       
   981 	iGdiTest->SetGdiTest(this);
       
   982 	iGdiTest->AssignGdi(TheGc);
       
   983 	iGdiTest->ConstructL(iTest->iTestRects.Count1());
       
   984 	TInt index;
       
   985 	TInt index2;
       
   986 	for(index=0; iTestPassing && index<iTest->iTestRects.Count2(); ++index)
       
   987 		{
       
   988 		TInt max=iGdiTest->Count(index<iTest->iTestRects.Count1());
       
   989 		TRect rect=iTest->iTestRects[index];
       
   990 	#if defined(LOGGING)
       
   991 		_LIT(KLog1,"Testing rectangle %d (%d,%d,%d,%d) 1st pass");
       
   992 		LOG_MESSAGE6(KLog1,index,rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
       
   993 	#endif
       
   994 		for(index2=0; iTestPassing && index2<max; ++index2)
       
   995 			DoGdiTestL(rect,index2);
       
   996 		if (!iTestPassing)
       
   997 			{
       
   998 			_LIT(KLog,"Test fail on rectangle %d at iteration %d");
       
   999 			LOG_MESSAGE3(KLog,index,index2);
       
  1000 			}
       
  1001 		}
       
  1002 	for(; iTestPassing && index<iTest->iTestRects.Count3(); index++)
       
  1003 		{
       
  1004 		TRect rect=iTest->iTestRects[index];
       
  1005 	#if defined(LOGGING)
       
  1006 		_LIT(KLog2,"Testing rectangle %d (%d,%d,%d,%d) 2nd pass");
       
  1007 		LOG_MESSAGE6(KLog2,index,rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
       
  1008 	#endif
       
  1009 		DoGdiTestL(rect,0);
       
  1010 		}
       
  1011 	delete iGdiTest;
       
  1012 	iGdiTest=NULL;
       
  1013 	}
       
  1014 
       
  1015 void CTGdi::NonDrawing()
       
  1016 //
       
  1017 // Test all non-drawing GDI functions
       
  1018 //
       
  1019 	{
       
  1020 	TDisplayMode mode=TheClient->iScreen->DisplayMode();
       
  1021 	TEST((mode!=ERgb) && (mode!=ENone));
       
  1022 
       
  1023 	RWsSession session;
       
  1024 	TInt res = session.Connect();
       
  1025 	TEST(res == KErrNone);
       
  1026 	
       
  1027 	CArrayFixFlat<TInt>* modeList= new CArrayFixFlat<TInt> (15);
       
  1028 	if(!modeList)
       
  1029 		return;
       
  1030 	
       
  1031 #if defined(SYMBIAN_GRAPHICS_GCE)
       
  1032 	res = session.GetColorModeList(iTest->iScreenNumber, modeList);
       
  1033 #else
       
  1034 	res = session.GetColorModeList(modeList);
       
  1035 #endif //SYMBIAN_GRAPHICS_GCE
       
  1036 	session.Close();
       
  1037 	TEST(res == KErrNone);
       
  1038 	if(res != KErrNone)
       
  1039 		{
       
  1040 		modeList->Reset();
       
  1041 		delete modeList;
       
  1042 		return;
       
  1043 		}
       
  1044 	
       
  1045 	TBool found = EFalse;
       
  1046 	for(TInt ii = 0; ii < modeList->Count() && !found; ii++)
       
  1047 		{
       
  1048 		TDisplayMode mode1 = (TDisplayMode) ((*modeList)[ii]);
       
  1049 		if(mode == mode1)
       
  1050 			{
       
  1051 			found = ETrue;
       
  1052 			}
       
  1053 		}
       
  1054 	modeList->Reset();
       
  1055 	delete modeList;
       
  1056 
       
  1057 	TEST(found);	
       
  1058 	}
       
  1059 
       
  1060 //
       
  1061 // Auxiliary Fn for Test Case ID CTGdi_TestDefetct_DEF045746
       
  1062 // This method draws the text represented by aText parameter on the window
       
  1063 // passed to it.
       
  1064 //
       
  1065 void CTGdi::DrawTextOnWindow(const TDesC& aText,CTWin* aWin)
       
  1066 	{
       
  1067 	aWin->Win()->BeginRedraw();
       
  1068 	TheGc->Activate(*aWin->Win());
       
  1069 	TheGc->Device()->GetNearestFontToDesignHeightInTwips(iFont,TFontSpec(_L("Arial"),250));
       
  1070 	TheGc->UseFont(iFont);
       
  1071 	TheGc->Clear();
       
  1072 	TheGc->DrawRect(TRect(aWin->Win()->Size()));
       
  1073 	TheGc->DrawText(aText,TPoint(iTextOffsetX,iTextOffsetY));
       
  1074 	TheGc->Device()->ReleaseFont(iFont);
       
  1075 	TheGc->Deactivate();
       
  1076 	aWin->Win()->EndRedraw();
       
  1077 	}
       
  1078 
       
  1079 
       
  1080 void CTGdi::TestDefetct_DEF045746L()
       
  1081 	{
       
  1082 	_LIT(KString,"This is a test window for the defect fix DEF045746 \
       
  1083 		propagated from Opera browser. Most window graphics context drawing\
       
  1084 		functions map to equivalent CFbsBitGc functions they are implemented\
       
  1085 		on the screen with any co-ordinates being relative to the top left\
       
  1086 		corner of the window. However extra clipping is applied. The drawing\
       
  1087 		will always be clipped to the visible part of the window, in addition\
       
  1088 		it will be clipped to the non-invalid part if you are not doing a\
       
  1089 		redraw and to the region being validated if you are doing a redraw.");
       
  1090 
       
  1091 	TPtrC TestText(KString().Ptr(),100);
       
  1092 	TPtrC LargeText(KString().Ptr());
       
  1093 	TPtrC ShortText(KString().Ptr(),200);
       
  1094 
       
  1095 	TSize scrSize=TheClient->iScreen->SizeInPixels();
       
  1096 	TSize winSize;
       
  1097 	const TInt windowGap=5;
       
  1098 	winSize.SetSize(scrSize.iWidth -2* windowGap,scrSize.iHeight/2 - windowGap);
       
  1099 
       
  1100 	iWin=new(ELeave) CTestWindow(TRgb(0,0,0));
       
  1101 	iWin->ConstructL(TPoint(5,5),TSize(winSize),TheClient->iGroup,*TheClient->iGc);
       
  1102 	CTestWindow* expectWin= new(ELeave) CTestWindow(TRgb(0,0,0));
       
  1103 	expectWin->ConstructL(TPoint(5,scrSize.iHeight/2 + windowGap),TSize(winSize),TheClient->iGroup,*TheClient->iGc);
       
  1104 	DrawTextOnWindow(ShortText,iWin);
       
  1105 	DrawTextOnWindow(TestText,expectWin);
       
  1106 	TInt fHeight=iFont->HeightInPixels();//Used to compare only pixels where text is drawn
       
  1107 	TRect iRect=winSize;
       
  1108 	iRect.iTl.iX=iTextOffsetX;
       
  1109 	iRect.iTl.iY=iTextOffsetY;
       
  1110 	iRect.iBr.iY=iTextOffsetY+fHeight;
       
  1111 	CheckRect(iWin,expectWin,iRect,_L("TestDefetct_DEF045746L A"));
       
  1112 	iWin->Invalidate();
       
  1113 	DrawTextOnWindow(LargeText,iWin);
       
  1114 	CheckRect(iWin,expectWin,iRect,_L("TestDefetct_DEF045746L B"));
       
  1115 	delete iWin;
       
  1116 	iWin=NULL;
       
  1117 	delete expectWin;
       
  1118 	expectWin=NULL;
       
  1119 	}
       
  1120 
       
  1121 void CTGdi::RunTestCaseL(TInt /*aCurTestCase*/)
       
  1122 	{
       
  1123 	//_LIT(KTest1,"NonDrawing"); this test is not running
       
  1124 	_LIT(KTest2,"DEF045746");
       
  1125 	_LIT(KTest3,"Drawing Tests");
       
  1126 	((CTGdiStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
       
  1127 	static TTime startTime;
       
  1128 	switch(++iTest->iState)
       
  1129 		{
       
  1130 /**
       
  1131 @SYMTestCaseID		GRAPHICS-WSERV-0262
       
  1132 
       
  1133 @SYMDEF             DEF081259
       
  1134 
       
  1135 @SYMTestCaseDesc    Test all non-drawing GDI functions
       
  1136 
       
  1137 @SYMTestPriority    High
       
  1138 
       
  1139 @SYMTestStatus      Implemented
       
  1140 
       
  1141 @SYMTestActions     Check all non-drawing GDI functions operate correctly
       
  1142 
       
  1143 @SYMTestExpectedResults Non-drawing GDI functions operate correctly
       
  1144 */
       
  1145 		case 1:
       
  1146 		    // start time log
       
  1147 		    startTime.HomeTime();
       
  1148 			((CTGdiStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0262"));
       
  1149 			//iTest->LogSubTest(KTest1);
       
  1150 			//PeterI this tests whether the display mode is EGray4 or EGray16.
       
  1151 			//The actual display mode is EColor16MU so this test will always fail
       
  1152 			//NonDrawingL();
       
  1153 			break;
       
  1154 /**
       
  1155  * @SYMTestCaseID GRAPHICS-WSERV-0263
       
  1156  *
       
  1157  * @SYMPREQ DEF045746
       
  1158  *
       
  1159  * @SYMTestCaseDesc Test defect fix for DEF045746
       
  1160  *
       
  1161  * @SYMTestPriority  High
       
  1162  *
       
  1163  * @SYMTestStatus Implemented
       
  1164  *
       
  1165  * @SYMTestActions The method tests CWindowGc::DrawText().The test is carried
       
  1166  * out by writing small & very large strings to the window graphic context.
       
  1167  *
       
  1168  * @SYMTestExpectedResults The window with large / small strings written is
       
  1169  * compared with an expected result window. In both the cases strings should
       
  1170  * be displayed.
       
  1171  *
       
  1172  */
       
  1173 		case 2:
       
  1174 			((CTGdiStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0263"));
       
  1175 			iTest->LogSubTest(KTest2);
       
  1176 			TestDefetct_DEF045746L();
       
  1177 			break;
       
  1178 /**
       
  1179 @SYMTestCaseID		GRAPHICS-WSERV-0264
       
  1180 
       
  1181 @SYMDEF             DEF081259
       
  1182 
       
  1183 @SYMTestCaseDesc    Test all drawing GDI functions
       
  1184 
       
  1185 @SYMTestPriority    High
       
  1186 
       
  1187 @SYMTestStatus      Implemented
       
  1188 
       
  1189 @SYMTestActions     Check all drawing GDI functions operate correctly
       
  1190 
       
  1191 @SYMTestExpectedResults Drawing GDI functions operate correctly
       
  1192 */
       
  1193 		case 3:
       
  1194 			{
       
  1195 			((CTGdiStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0264"));
       
  1196 			iTest->LogSubTest(KTest3);
       
  1197 			iSubState = 0;
       
  1198 			TheClient->WaitForRedrawsToFinish();		//Just in case the two test windows have any invalid areas
       
  1199 			TInt numTests = sizeof(GdiTestFuncs) / sizeof(GdiTestFuncs[0]);
       
  1200 			while (iSubState < numTests)
       
  1201 				{
       
  1202 				LOG_MESSAGE(TPtrC(GdiTestFuncs[iSubState].txt));
       
  1203 				GdiTestL((*GdiTestFuncs[iSubState].func)());
       
  1204 				iSubState++;
       
  1205 				}
       
  1206 			}
       
  1207 			break;
       
  1208 		default:
       
  1209             ((CTGdiStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
       
  1210 			((CTGdiStep*)iStep)->CloseTMSGraphicsStep();
       
  1211 			TestComplete();
       
  1212 			// log time and print duration
       
  1213 			TTime endTime;
       
  1214 			endTime.HomeTime();
       
  1215 			TInt64 duration = endTime.MicroSecondsFrom(startTime).Int64();
       
  1216 			float time = (float) I64LOW(duration) / 1000.0f;
       
  1217 			_LIT(KDuration,"Total test duration is %f millisec");
       
  1218 			RDebug::Print(KDuration, time);
       
  1219 			break;
       
  1220 		}
       
  1221 	((CTGdiStep*)iStep)->RecordTestResultL();
       
  1222 	}
       
  1223 
       
  1224 CGdiTestLowLevel *SetOriginTest()
       
  1225 	{
       
  1226 	return(new(ELeave) CGdiSetOrigin());
       
  1227 	}
       
  1228 
       
  1229 CGdiTestLowLevel *PolyLineTest()
       
  1230 	{
       
  1231 	return(new(ELeave) CGdiPolyLine());
       
  1232 	}
       
  1233 
       
  1234 CGdiTestLowLevel *PolygonTest()
       
  1235 	{
       
  1236 	return(new(ELeave) CGdiPolygon());
       
  1237 	}
       
  1238 
       
  1239 CGdiTestLowLevel *BlitMaskedTest()
       
  1240 	{
       
  1241 	return(new(ELeave) CGdiBlitMasked());
       
  1242 	}
       
  1243 
       
  1244 CGdiTestLowLevel *DrawArcTest()
       
  1245 	{
       
  1246 	return(new(ELeave) CGdiDrawArc());
       
  1247 	}
       
  1248 
       
  1249 CGdiTestLowLevel *DrawPieTest()
       
  1250 	{
       
  1251 	return(new(ELeave) CGdiDrawPie());
       
  1252 	}
       
  1253 
       
  1254 CGdiTestLowLevel *DrawRoundRectTest()
       
  1255 	{
       
  1256 	return(new(ELeave) CGdiDrawRoundRect());
       
  1257 	}
       
  1258 
       
  1259 CGdiTestLowLevel *BoxTextTest()
       
  1260 	{
       
  1261 	return(new(ELeave) CGdiBoxText());
       
  1262 	}
       
  1263 
       
  1264 CGdiTestLowLevel *VertTextTest()
       
  1265 	{
       
  1266 	return(new(ELeave) CGdiDrawVertText());
       
  1267 	}
       
  1268 
       
  1269 CGdiTestLowLevel *VertBoxTextTest()
       
  1270 	{
       
  1271 	return(new(ELeave) CGdiVertBoxText());
       
  1272 	}
       
  1273 
       
  1274 CGdiTestLowLevel *WideLineTest()
       
  1275 	{
       
  1276 	return(new(ELeave) CGdiWideLine());
       
  1277 	}
       
  1278 
       
  1279 CGdiTestLowLevel *DrawTextTest()
       
  1280 	{
       
  1281 	return(new(ELeave) CGdiDrawText());
       
  1282 	}
       
  1283 
       
  1284 CGdiTestLowLevel *DrawRectTest()
       
  1285 	{
       
  1286 	return(new(ELeave) CGdiDrawRect());
       
  1287 	}
       
  1288 
       
  1289 __WS_CONSTRUCT_STEP__(Gdi)