1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/TGDI.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1289 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// GDI.CPP
1.18 +// Test GDI functions
1.19 +//
1.20 +//
1.21 +
1.22 +/**
1.23 + @file
1.24 + @test
1.25 + @internalComponent - Internal Symbian test code
1.26 +*/
1.27 +
1.28 +#include "TGDI.H"
1.29 +
1.30 +#define TAUTO_BITMAP_NAME _L("Z:\\WSTEST\\TAUTO.MBM")
1.31 +
1.32 +//#define LOGGING on //Uncomment this line to get extra test logging - useful if debugging a failure of one of the tests
1.33 +
1.34 +typedef CGdiTestLowLevel *(*GdiTestFunc)();
1.35 +
1.36 +_LIT(KMonospaceTestFontTypefaceName,"Arial");
1.37 +const TInt KMaxFontSize = 200;
1.38 +
1.39 +static inline TBool IsLengthEqual(TInt aLLen, TInt aRLen, TInt aBbLen)
1.40 + {
1.41 +// 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
1.42 +// are stuck together. So add a tolerance of -1.
1.43 + return (((aLLen+aRLen)==aBbLen) || ((aLLen+aRLen-1)==aBbLen));
1.44 + }
1.45 +
1.46 +struct GdiTest
1.47 + {
1.48 + GdiTestFunc func;
1.49 + const TText *txt;
1.50 + };
1.51 +
1.52 +GdiTest GdiTestFuncs[]={
1.53 + {BoxTextTest,_S("BoxText")},
1.54 + {VertTextTest,_S("VertText")},
1.55 + /*{JustifiedTextTest,_S("JustifiedText")},*/ // DEF107985 The test for JustifiedText has been removed as it was a bad/useless test
1.56 + {VertBoxTextTest,_S("VertBoxText")},
1.57 + {SetOriginTest,_S("SetOrigin")},
1.58 + {PolyLineTest,_S("PolyLine")},
1.59 + {PolygonTest,_S("Polygon")},
1.60 + {DrawArcTest,_S("DrawArc")},
1.61 + {DrawPieTest,_S("DrawPie")},
1.62 + {DrawRoundRectTest,_S("DrawRoundRect")},
1.63 + {WideLineTest,_S("WideLine")},
1.64 + {DrawTextTest,_S("DrawText")},
1.65 + {DrawRectTest,_S("DrawRect")},
1.66 + };
1.67 +
1.68 +CTestWindow::CTestWindow(TRgb aCol) : CBlankWindow(aCol)
1.69 + {
1.70 + }
1.71 +
1.72 +CTestWindow::~CTestWindow()
1.73 + {
1.74 + }
1.75 +
1.76 +void CTestWindow::ConstructL(TPoint aPos,TSize aSize,CTWinBase* aParent, CWindowGc& aGc)
1.77 + {
1.78 + iWin=RWindow(TheClient->iWs);
1.79 + User::LeaveIfError(iWin.Construct(*(aParent->WinTreeNode()),ENullWsHandle));
1.80 + SetExt(aPos,aSize);
1.81 + Activate();
1.82 + AssignGC(aGc);
1.83 + }
1.84 +
1.85 +void CGdiTestLowLevel::SetGdiTest(CTGdi *aGdiTest)
1.86 + {
1.87 + iGdiTest=aGdiTest;
1.88 + }
1.89 +
1.90 +void CGdiTestLowLevel::AssignGdi(CWindowGc *aGc)
1.91 + {
1.92 + iGdi=aGc;
1.93 + }
1.94 +
1.95 +void CGdiTestLowLevel::ConstructL(TInt)
1.96 + {
1.97 + }
1.98 +
1.99 +void CGdiTestLowLevel::PreTestSetupL(const TRect &,TInt)
1.100 + {
1.101 + }
1.102 +
1.103 +//=======================================//
1.104 +// Individual GDI low level test classes //
1.105 +//=======================================//
1.106 +
1.107 +
1.108 +void CGdiRect::ConstructL(TInt)
1.109 + {
1.110 + }
1.111 +
1.112 +void CGdiRect::PreTestSetupL(const TRect &, TInt aCount)
1.113 + {
1.114 + iBrushCol=TRgb::Gray256(aCount&0x1 ? 0xFF : 0x60);
1.115 + iPenCol=TRgb::Gray256(aCount&0x1 ? 0xA0 : 0x0);
1.116 + }
1.117 +
1.118 +TInt CGdiRect::Count(TBool )
1.119 + {
1.120 + return(1);
1.121 + }
1.122 +
1.123 +void CGdiDrawRect::BaseTest(const TRect &aRect, TInt aCount)
1.124 + {
1.125 + TheTest(aRect,aCount);
1.126 + }
1.127 +
1.128 +void CGdiDrawRect::TheTest(const TRect &aRect, TInt)
1.129 + {
1.130 + iGdi->SetBrushColor(iBrushCol);
1.131 + iGdi->SetPenColor(iPenCol);
1.132 + iGdi->DrawRect(aRect);
1.133 + }
1.134 +
1.135 +TInt CGdiDrawRect::Count(TBool aMode)
1.136 + {
1.137 + return(aMode ? 4:1);
1.138 + }
1.139 +
1.140 +TInt CGdiDrawRoundRect::Count(TBool aMode)
1.141 + {
1.142 + return(aMode ? 4:1);
1.143 + }
1.144 +
1.145 +void CGdiDrawRoundRect::BaseTest(const TRect &aRect, TInt aCount)
1.146 + {
1.147 + TheTest(aRect,aCount);
1.148 + }
1.149 +
1.150 +void CGdiDrawRoundRect::TheTest(const TRect &aRect, TInt aCount)
1.151 + {
1.152 + iGdi->SetBrushColor(iBrushCol);
1.153 + iGdi->SetPenColor(iPenCol);
1.154 + TSize size((aRect.iBr.iX-aRect.iTl.iX)/4,(aRect.iBr.iY-aRect.iTl.iY)/4);
1.155 + switch(aCount)
1.156 + {
1.157 + case 0:
1.158 + size.SetSize((aRect.iBr.iX-aRect.iTl.iX)/4,(aRect.iBr.iY-aRect.iTl.iY)/4);
1.159 + break;
1.160 + case 1:
1.161 + size.SetSize(0,0);
1.162 + break;
1.163 + case 2:
1.164 + size.SetSize((aRect.iBr.iX-aRect.iTl.iX)/2,(aRect.iBr.iY-aRect.iTl.iY)/2);
1.165 + break;
1.166 + case 3:
1.167 + size.SetSize((aRect.iBr.iX-aRect.iTl.iX),(aRect.iBr.iY-aRect.iTl.iY));
1.168 + break;
1.169 + }
1.170 + iGdi->DrawRoundRect(aRect,size);
1.171 + }
1.172 +
1.173 +TInt CGdiDrawACP::Count(TBool )
1.174 + {
1.175 + return(1);
1.176 + }
1.177 +
1.178 +void CGdiDrawACP::ConstructL(TInt)
1.179 + {
1.180 + }
1.181 +
1.182 +void CGdiDrawACP::PreTestSetupL(const TRect &, TInt )
1.183 + {
1.184 + iBrushCol=TRgb::Gray256(0xff);
1.185 + iPenCol=TRgb(0,0,0);
1.186 + }
1.187 +
1.188 +void CGdiDrawArc::BaseTest(const TRect &aRect, TInt aCount)
1.189 + {
1.190 + TheTest(aRect,aCount);
1.191 + }
1.192 +
1.193 +void CGdiDrawArc::TheTest(const TRect &aRect, TInt)
1.194 + {
1.195 + iGdi->SetBrushColor(iBrushCol);
1.196 + iGdi->SetPenColor(iPenCol);
1.197 + TPoint start(aRect.iTl.iX/2+aRect.iBr.iX,aRect.iTl.iY/2+aRect.iBr.iY);
1.198 + iGdi->DrawArc(aRect,start,TPoint(0,0));
1.199 + }
1.200 +
1.201 +void CGdiDrawPie::BaseTest(const TRect &aRect, TInt aCount)
1.202 + {
1.203 + TheTest(aRect,aCount);
1.204 + }
1.205 +
1.206 +void CGdiDrawPie::TheTest(const TRect &aRect, TInt)
1.207 + {
1.208 + iGdi->SetBrushColor(iBrushCol);
1.209 + iGdi->SetPenColor(iPenCol);
1.210 + TPoint start(aRect.iTl.iX/2+aRect.iBr.iX,aRect.iTl.iY/2+aRect.iBr.iY);
1.211 + iGdi->DrawPie(aRect,start,TPoint(0,0));
1.212 + }
1.213 +
1.214 +//
1.215 +// Polyline tests
1.216 +//
1.217 +
1.218 +CGdiPolyLine::CGdiPolyLine() : iPnts(5)
1.219 + {}
1.220 +
1.221 +void CGdiPolyLine::PreTestSetupL(const TRect &aRect, TInt aCount)
1.222 + {
1.223 + iPnts.Reset();
1.224 + TInt wid=aRect.Width();
1.225 + TInt hgt=aRect.Height();
1.226 + if (aCount==0)
1.227 + {
1.228 + TInt pos;
1.229 + for(pos=0;pos<wid;pos+=10)
1.230 + {
1.231 + iPnts.AppendL(TPoint(aRect.iTl.iX+pos,aRect.iTl.iY));
1.232 + iPnts.AppendL(TPoint(aRect.iTl.iX+pos+5,aRect.iBr.iY));
1.233 + }
1.234 + for(pos=0;pos<hgt;pos+=10)
1.235 + {
1.236 + iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY+pos));
1.237 + iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iTl.iY+pos+5));
1.238 + }
1.239 + }
1.240 + else
1.241 + {
1.242 + TInt hgt=aRect.Height();
1.243 + iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY));
1.244 + iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iTl.iY+hgt/2));
1.245 + iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iBr.iY));
1.246 + iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iBr.iY));
1.247 + iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY+hgt/2));
1.248 + iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iTl.iY));
1.249 + iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY));
1.250 + }
1.251 + }
1.252 +
1.253 +void CGdiPolyLine::ConstructL(TInt )
1.254 + {
1.255 + }
1.256 +
1.257 +TInt CGdiPolyLine::Count(TBool aMainTests)
1.258 + {
1.259 + return(aMainTests ? 2 : 1);
1.260 + }
1.261 +
1.262 +void CGdiPolyLine::BaseTest(const TRect &, TInt )
1.263 + {
1.264 + TPoint prev;
1.265 + TInt index;
1.266 + for(index=0;index<iPnts.Count();index++)
1.267 + {
1.268 + if (index>0)
1.269 + iGdi->DrawLine(prev,iPnts[index]);
1.270 + prev=iPnts[index];
1.271 + }
1.272 + if (index>0)
1.273 + iGdi->Plot(iPnts[index-1]);
1.274 + }
1.275 +
1.276 +void CGdiPolyLine::TheTest(const TRect &, TInt )
1.277 + {
1.278 + iGdi->DrawPolyLine(&iPnts);
1.279 + }
1.280 +
1.281 +//
1.282 +// Polygon tests //
1.283 +//
1.284 +
1.285 +CGdiPolygon::CGdiPolygon() : iPnts(5)
1.286 + {}
1.287 +
1.288 +void CGdiPolygon::PreTestSetupL(const TRect &aRect, TInt )
1.289 + {
1.290 + iPnts.Reset();
1.291 + TPoint pnt;
1.292 + TInt maxPoints=Min((TInt)KMaxPolygonPoints,Min(aRect.Width(),aRect.Height())/KPolygonStep);
1.293 + TInt numPoints=0;
1.294 + if (maxPoints>0)
1.295 + {
1.296 + iPnts.AppendL(aRect.iTl);
1.297 + while(numPoints<maxPoints)
1.298 + {
1.299 + if (numPoints&1)
1.300 + pnt.SetXY(aRect.iTl.iX+(numPoints+1)*KPolygonStep,aRect.iTl.iY+numPoints*KPolygonStep);
1.301 + else
1.302 + pnt.SetXY(aRect.iTl.iX+numPoints*KPolygonStep,aRect.iTl.iY+(numPoints+1)*KPolygonStep);
1.303 + iPnts.AppendL(pnt);
1.304 + numPoints++;
1.305 + }
1.306 + pnt.SetXY(aRect.iTl.iX+numPoints*KPolygonStep,aRect.iTl.iY+numPoints*KPolygonStep);
1.307 + iPnts.AppendL(pnt);
1.308 + while(numPoints>0)
1.309 + {
1.310 + numPoints--;
1.311 + if (numPoints&1)
1.312 + pnt.SetXY(aRect.iTl.iX+numPoints*KPolygonStep,aRect.iTl.iY+(numPoints+1)*KPolygonStep);
1.313 + else
1.314 + pnt.SetXY(aRect.iTl.iX+(numPoints+1)*KPolygonStep,aRect.iTl.iY+numPoints*KPolygonStep);
1.315 + iPnts.AppendL(pnt);
1.316 + }
1.317 + }
1.318 + }
1.319 +
1.320 +void CGdiPolygon::ConstructL(TInt )
1.321 + {
1.322 + }
1.323 +
1.324 +TInt CGdiPolygon::Count(TBool aMainTests)
1.325 + {
1.326 + return(aMainTests ? 2 : 1);
1.327 + }
1.328 +
1.329 +void CGdiPolygon::BaseTest(const TRect &aRect, TInt )
1.330 + {
1.331 + iGdi->SetPenColor(TRgb::Gray4(2));
1.332 + iGdi->SetBrushColor(TRgb::Gray4(1));
1.333 + iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
1.334 + TInt maxPoints=Min((TInt)KMaxPolygonPoints,Min(aRect.Width(),aRect.Height())/KPolygonStep);
1.335 + for(TInt numPoints=0;numPoints<maxPoints;numPoints++)
1.336 + iGdi->DrawRect(TRect(aRect.iTl.iX+numPoints*KPolygonStep + 1,aRect.iTl.iY+numPoints*KPolygonStep + 1,
1.337 + aRect.iTl.iX+(numPoints+1)*KPolygonStep ,aRect.iTl.iY+(numPoints+1)*KPolygonStep));
1.338 + }
1.339 +
1.340 +void CGdiPolygon::TheTest(const TRect &, TInt )
1.341 +//This is the only one that can leave so it's not worth adding an 'L'
1.342 + {
1.343 + iGdi->SetPenColor(TRgb::Gray4(2));
1.344 + iGdi->SetBrushColor(TRgb::Gray4(1));
1.345 + iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
1.346 + User::LeaveIfError(iGdi->DrawPolygon(&iPnts,CGraphicsContext::EAlternate));
1.347 + }
1.348 +
1.349 +//
1.350 +
1.351 +TInt CGdiWideLine::Count(TBool aMainTests)
1.352 + {
1.353 + return(aMainTests ? EMainNumWidths : EMinorNumWidths);
1.354 + }
1.355 +
1.356 +void CGdiWideLine::ConstructL(TInt)
1.357 + {
1.358 + }
1.359 +
1.360 +void CGdiWideLine::PreTestSetupL(const TRect &, TInt aCount)
1.361 + {
1.362 + TInt widths[]={1,4,50,-2,
1.363 + 48,12345,0,3,
1.364 + 48,123,0,3,
1.365 + 4,111,555,1000,
1.366 + 10,-1,-10,-100};
1.367 + iWidth=widths[aCount];
1.368 + }
1.369 +
1.370 +void CGdiWideLine::BaseTest(const TRect &aRect, TInt)
1.371 + {
1.372 + iGdi->SetPenSize(TSize(iWidth,iWidth));
1.373 + iGdi->DrawLine(aRect.iTl,aRect.iBr);
1.374 + iGdi->MoveTo(aRect.iTl+TPoint(0,10));
1.375 + iGdi->DrawLineBy(aRect.iBr-aRect.iTl);
1.376 + iGdi->MoveBy(aRect.iTl-aRect.iBr+TPoint(0,10));
1.377 + iGdi->DrawLineTo(aRect.iBr+TPoint(0,20));
1.378 + }
1.379 +
1.380 +void CGdiWideLine::TheTest(const TRect &aRect, TInt)
1.381 + {
1.382 + iGdi->SetPenSize(TSize(iWidth,iWidth));
1.383 + iGdi->MoveTo(aRect.iTl);
1.384 + iGdi->DrawLineBy(aRect.iBr-aRect.iTl);
1.385 + iGdi->MoveBy(aRect.iTl-aRect.iBr+TPoint(0,10));
1.386 + iGdi->DrawLineTo(aRect.iBr+TPoint(0,10));
1.387 + iGdi->DrawLine(aRect.iTl+TPoint(0,20),aRect.iBr+TPoint(0,20));
1.388 + }
1.389 +
1.390 +//
1.391 +// Set Origin //
1.392 +//
1.393 +
1.394 +CGdiSetOrigin::~CGdiSetOrigin()
1.395 + {
1.396 + delete iPolylineArray;
1.397 + delete iPolygonArray;
1.398 + TheClient->iScreen->ReleaseFont(iFont);
1.399 + }
1.400 +
1.401 +TInt CGdiSetOrigin::Count(TBool )
1.402 + {
1.403 + return(1);
1.404 + }
1.405 +
1.406 +void CGdiSetOrigin::ConstructL(TInt)
1.407 + {
1.408 + iPolylineArray=new(ELeave) CArrayFixFlat<TPoint>(3);
1.409 + iPolylineArray->AppendL(TPoint(40,1));
1.410 + iPolylineArray->AppendL(TPoint(50,11));
1.411 + iPolylineArray->AppendL(TPoint(40,21));
1.412 + iPolygonArray=new(ELeave) CArrayFixFlat<TPoint>(3);
1.413 + iPolygonArray->AppendL(TPoint(40,30));
1.414 + iPolygonArray->AppendL(TPoint(50,40));
1.415 + iPolygonArray->AppendL(TPoint(40,45));
1.416 + TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
1.417 + User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
1.418 + }
1.419 +
1.420 +void CGdiSetOrigin::PreTestSetupL(const TRect &, TInt )
1.421 + {
1.422 + }
1.423 +
1.424 +void CGdiSetOrigin::DrawIt(const TPoint &aOffset)
1.425 + {
1.426 + iGdi->DrawLine(TPoint(10,10)+aOffset,TPoint(20,30)+aOffset);
1.427 + iGdi->DrawLineBy(TPoint(-10,5));
1.428 + iGdi->DrawLineTo(TPoint(20,5)+aOffset);
1.429 + iGdi->MoveTo(TPoint(20,10)+aOffset);
1.430 + iGdi->DrawLineTo(TPoint(30,15)+aOffset);
1.431 + iGdi->MoveBy(TPoint(-10,2));
1.432 + iGdi->DrawLineBy(TPoint(10,0));
1.433 + iGdi->UseFont(iFont);
1.434 + iGdi->DrawText(_L("Set Origin Test"),TPoint(40,20)+aOffset);
1.435 + iGdi->DiscardFont();
1.436 + iGdi->DrawRect(TRect(TPoint(10,45)+aOffset,TPoint(20,55)+aOffset));
1.437 + iGdi->DrawRoundRect(TRect(TPoint(21,45)+aOffset,TPoint(30,55)+aOffset),TSize(3,2));
1.438 + iGdi->DrawEllipse(TRect(TPoint(31,45)+aOffset,TPoint(40,55)+aOffset));
1.439 + TInt index;
1.440 + for(index=0;index<iPolylineArray->Count();index++)
1.441 + (*iPolylineArray)[index]+=aOffset;
1.442 + iGdi->DrawPolyLine(iPolylineArray);
1.443 + for(index=0;index<iPolylineArray->Count();index++)
1.444 + (*iPolylineArray)[index]-=aOffset;
1.445 + for(index=0;index<iPolygonArray->Count();index++)
1.446 + (*iPolygonArray)[index]+=aOffset;
1.447 + iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
1.448 + User::LeaveIfError(iGdi->DrawPolygon(iPolygonArray,CGraphicsContext::EAlternate)); //Doesn't cause any harm if it leaves
1.449 + for(index=0;index<iPolygonArray->Count();index++)
1.450 + (*iPolygonArray)[index]-=aOffset;
1.451 + }
1.452 +
1.453 +void CGdiSetOrigin::BaseTest(const TRect &aRect, TInt)
1.454 + {
1.455 + DrawIt(aRect.iTl);
1.456 + }
1.457 +
1.458 +void CGdiSetOrigin::TheTest(const TRect &aRect, TInt)
1.459 + {
1.460 + iGdi->SetOrigin(aRect.iTl);
1.461 + DrawIt(TPoint(0,0));
1.462 + }
1.463 +
1.464 +//
1.465 +// Draw text //
1.466 +//
1.467 +
1.468 +CGdiDrawText::~CGdiDrawText()
1.469 + {
1.470 + TheClient->iScreen->ReleaseFont(iFont);
1.471 + }
1.472 +
1.473 +TInt CGdiDrawText::Count(TBool )
1.474 + {
1.475 + return(1);
1.476 + }
1.477 +
1.478 +void CGdiDrawText::ConstructL(TInt)
1.479 + {
1.480 + TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
1.481 + User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
1.482 + TInt index;
1.483 + for(index=0;index<iBigBuffer.MaxLength();index++)
1.484 + iBigBuffer.Append(TChar((index%26)+'a'));
1.485 + const TInt characters=iBigBuffer.Length();
1.486 + TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
1.487 + for(index=0;index<iBigBuffer.MaxLength();index+=33)
1.488 + {
1.489 + TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(index));
1.490 + TInt rLen=iFont->TextWidthInPixels(iBigBuffer.Right(characters-index));
1.491 + TBool result = IsLengthEqual(lLen,rLen,bbLen);
1.492 + iGdiTest->TEST(result);
1.493 + if (!result)
1.494 + {
1.495 + _LIT(KLog,"Font width metrics error, Width(%dchars)=%d, Width(%dchars)=%d, Width(%dchars)=%d");
1.496 + iGdiTest->LOG_MESSAGE7(KLog,index,lLen,characters-index,rLen,characters,bbLen);
1.497 + }
1.498 + }
1.499 + }
1.500 +
1.501 +void CGdiDrawText::PreTestSetupL(const TRect&,TInt)
1.502 + {}
1.503 +
1.504 +void CGdiDrawText::BaseTest(const TRect& aRect,TInt)
1.505 + {
1.506 + TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
1.507 + TInt fAscent=iFont->AscentInPixels();
1.508 + TInt fHeight=iFont->HeightInPixels();
1.509 + iGdi->UseFont(iFont);
1.510 +//
1.511 + iGdi->DrawText(_L("Hello"), TPoint(aRect.iTl.iX, aRect.iTl.iY+fAscent));
1.512 + TInt missingChars=iFont->TextCount(iBigBuffer,bbLen-aRect.iBr.iX)-1; // -1 so one off screen char is drawn to handle overhang
1.513 + if (missingChars>=0)
1.514 + {
1.515 + TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars);
1.516 + TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars));
1.517 + TInt rLen=iFont->TextWidthInPixels(bbb);
1.518 + TBool result = IsLengthEqual(lLen,rLen,bbLen);
1.519 + iGdiTest->TEST(result);
1.520 + if (!result)
1.521 + {
1.522 + _LIT(KLog,"Font width metrics error, missingChars=%d %d+%d=%d");
1.523 + iGdiTest->LOG_MESSAGE5(KLog,missingChars,lLen,rLen,bbLen);
1.524 + }
1.525 + iGdi->DrawText(bbb,TPoint(aRect.iBr.iX-rLen,aRect.iTl.iY+fAscent+fHeight));
1.526 + }
1.527 + iGdi->DiscardFont();
1.528 + }
1.529 +
1.530 +void CGdiDrawText::TheTest(const TRect& aRect,TInt)
1.531 + {
1.532 + TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
1.533 + TInt fAscent=iFont->AscentInPixels();
1.534 + TInt fHeight=iFont->HeightInPixels();
1.535 + iGdi->UseFont(iFont);
1.536 +//
1.537 + iGdi->DrawText(_L("Hello"), TPoint(aRect.iTl.iX, aRect.iTl.iY+fAscent));
1.538 + iGdi->DrawText(iBigBuffer,TPoint(aRect.iBr.iX-bbLen,aRect.iTl.iY+fAscent+fHeight));
1.539 + iGdi->DiscardFont();
1.540 + }
1.541 +
1.542 +//
1.543 +// Draw vertical text //
1.544 +//
1.545 +
1.546 +CGdiDrawVertText::~CGdiDrawVertText()
1.547 + {
1.548 + TheClient->iScreen->ReleaseFont(iFont);
1.549 + }
1.550 +
1.551 +TInt CGdiDrawVertText::Count(TBool )
1.552 + {
1.553 + return(1);
1.554 + }
1.555 +
1.556 +void CGdiDrawVertText::ConstructL(TInt)
1.557 + {
1.558 + TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
1.559 + User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
1.560 + TInt index;
1.561 + for(index=0;index<iBigBuffer.MaxLength();index++)
1.562 + iBigBuffer.Append(TChar((index%26)+'a'));
1.563 +//
1.564 + TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
1.565 + for(index=0;index<iBigBuffer.MaxLength();index+=33)
1.566 + {
1.567 + TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(index));
1.568 + TInt rLen=iFont->TextWidthInPixels(iBigBuffer.Right(iBigBuffer.Length()-index));
1.569 + TBool result = IsLengthEqual(lLen,rLen,bbLen);
1.570 + iGdiTest->TEST(result);
1.571 + if (!result)
1.572 + iGdiTest->INFO_PRINTF3(_L("iFont->TextWidthInPixels(iBigBuffer) return value - Expected: %d, Actual: %d"), lLen+rLen, bbLen);
1.573 + }
1.574 + }
1.575 +
1.576 +void CGdiDrawVertText::PreTestSetupL(const TRect &, TInt )
1.577 + {
1.578 + }
1.579 +
1.580 +void CGdiDrawVertText::BaseTest(const TRect &aRect, TInt)
1.581 + {
1.582 + TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
1.583 + TInt fAscent=iFont->AscentInPixels();
1.584 + TInt fHeight=iFont->HeightInPixels();
1.585 + iGdi->UseFont(iFont);
1.586 +//
1.587 + TInt tlen=iFont->TextWidthInPixels(_L("Hello"));
1.588 + iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iTl.iX+fAscent, aRect.iTl.iY+tlen), ETrue);
1.589 + iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iBr.iX-fAscent, aRect.iTl.iY), EFalse);
1.590 + TInt missingChars=iFont->TextCount(iBigBuffer,bbLen-aRect.iBr.iY)-1; // -1 so one off screen char is drawn to handle overhang
1.591 + if (missingChars>=0)
1.592 + {
1.593 + TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars);
1.594 + TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars));
1.595 + TInt rLen=iFont->TextWidthInPixels(bbb);
1.596 + TBool result = IsLengthEqual(lLen,rLen,bbLen);
1.597 + iGdiTest->TEST(result);
1.598 + if (!result)
1.599 + iGdiTest->INFO_PRINTF3(_L("iFont->TextWidthInPixels(iBigBuffer) return value - Expected: %d, Actual: %d"), lLen+rLen, bbLen);
1.600 +
1.601 + iGdi->DrawTextVertical(bbb,TPoint(aRect.iTl.iX+fHeight-fAscent+fHeight,aRect.iBr.iY-rLen),EFalse);
1.602 + }
1.603 + iGdi->DiscardFont();
1.604 + }
1.605 +
1.606 +void CGdiDrawVertText::TheTest(const TRect &aRect, TInt)
1.607 + {
1.608 + TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
1.609 + TInt fAscent=iFont->AscentInPixels();
1.610 + TInt fHeight=iFont->HeightInPixels();
1.611 + iGdi->UseFont(iFont);
1.612 +//
1.613 + TInt tlen=iFont->TextWidthInPixels(_L("Hello"));
1.614 + iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iTl.iX+fAscent, aRect.iTl.iY+tlen), ETrue);
1.615 + iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iBr.iX-fAscent, aRect.iTl.iY), EFalse);
1.616 + iGdi->DrawTextVertical(iBigBuffer,TPoint(aRect.iTl.iX+fHeight-fAscent+fHeight,aRect.iBr.iY-bbLen),EFalse);
1.617 + iGdi->DiscardFont();
1.618 + }
1.619 +
1.620 +//
1.621 +// Draw Justified text //
1.622 +//
1.623 +
1.624 +// DEF107985 The test for JustifiedText has been removed as it was a bad/useless test. The original test was
1.625 +// broken after it was migrated to TEF TGdi test. It was not worth fixing as the purpose of test was not clear,
1.626 +// and fixing it basically required rewriting the whole test.
1.627 +//
1.628 +
1.629 +
1.630 +//
1.631 +// Box text //
1.632 +//
1.633 +
1.634 +CGdiBoxText::~CGdiBoxText()
1.635 + {
1.636 + TheClient->iScreen->ReleaseFont(iFont);
1.637 + }
1.638 +
1.639 +TInt CGdiBoxText::Count(TBool )
1.640 + {
1.641 + return(1);
1.642 + }
1.643 +
1.644 +void CGdiBoxText::ConstructL(TInt)
1.645 + {
1.646 + TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
1.647 + User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
1.648 + for(TInt index=0;index<iBigBuffer.MaxLength();index++)
1.649 + iBigBuffer.Append(TChar((index%26)+'a'));
1.650 + iBbLen=iFont->TextWidthInPixels(iBigBuffer);
1.651 + }
1.652 +
1.653 +void CGdiBoxText::PreTestSetupL(const TRect &, TInt )
1.654 + {
1.655 + }
1.656 +
1.657 +void CGdiBoxText::BaseTest(const TRect &aRect, TInt)
1.658 + {
1.659 + TInt rWid=aRect.iBr.iX-aRect.iTl.iX;
1.660 + TInt fAscent=iFont->AscentInPixels();
1.661 + TInt fHeight=iFont->HeightInPixels();
1.662 + iGdi->UseFont(iFont);
1.663 + iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
1.664 +//
1.665 + TRect rect(aRect);
1.666 + rect.iBr.iY=rect.iTl.iY+fHeight;
1.667 +//
1.668 + TInt missingChars=iFont->TextCount(iBigBuffer,iBbLen-rWid);
1.669 + TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars);
1.670 + TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars));
1.671 + TInt rLen=iFont->TextWidthInPixels(bbb);
1.672 + TBool result = IsLengthEqual(lLen,rLen,iBbLen);
1.673 + iGdiTest->TEST(result);
1.674 + if (!result)
1.675 + iGdiTest->INFO_PRINTF3(_L("(lLen+rLen)==iBbLen return value - Expected: %d, Actual: %d"), lLen+rLen, iBbLen);
1.676 +
1.677 + iGdi->DrawText(bbb, rect, fAscent,CGraphicsContext::ELeft, rWid-rLen);
1.678 +//
1.679 + rect.Move(TPoint(0,fHeight));
1.680 + iGdi->DrawText(iBigBuffer, rect, fAscent,CGraphicsContext::ELeft, 0);
1.681 +//
1.682 + TBuf<10> buf2(_L("1234567890"));
1.683 + rect.Move(TPoint(0,fHeight));
1.684 + iGdi->DrawText(buf2,rect,fAscent,CGraphicsContext::ERight,rect.Width()-iFont->TextWidthInPixels(buf2));
1.685 + }
1.686 +
1.687 +void CGdiBoxText::TheTest(const TRect &aRect, TInt)
1.688 + {
1.689 + TInt rWid=aRect.iBr.iX-aRect.iTl.iX;
1.690 + TInt fAscent=iFont->AscentInPixels();
1.691 + TInt fHeight=iFont->HeightInPixels();
1.692 + iGdi->UseFont(iFont);
1.693 + iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
1.694 + TRect rect(aRect);
1.695 + rect.iBr.iY=rect.iTl.iY+fHeight;
1.696 +//
1.697 + iGdi->DrawText(iBigBuffer, rect, fAscent, CGraphicsContext::ELeft, rWid-iBbLen);
1.698 +//
1.699 + rect.Move(TPoint(0,fHeight));
1.700 + iGdi->Clear(rect);
1.701 + iGdi->SetClippingRegion(TRegionFix<1>(rect));
1.702 + iGdi->DrawText(iBigBuffer, rect.iTl+TPoint(0,fAscent));
1.703 + TBuf<10> buf2(_L("1234567890"));
1.704 + rect.Move(TPoint(0,fHeight));
1.705 + iGdi->CancelClippingRegion();
1.706 + iGdi->DrawText(buf2,rect,fAscent);
1.707 + }
1.708 +
1.709 +//
1.710 +// Vert Box text //
1.711 +//
1.712 +
1.713 +CGdiVertBoxText::~CGdiVertBoxText()
1.714 + {
1.715 + TheClient->iScreen->ReleaseFont(iFont);
1.716 + }
1.717 +
1.718 +TInt CGdiVertBoxText::Count(TBool )
1.719 + {
1.720 + return(1);
1.721 + }
1.722 +
1.723 +void CGdiVertBoxText::ConstructL(TInt)
1.724 + {
1.725 + TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
1.726 + User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
1.727 + for(TInt index=0;index<iBigBuffer.MaxLength();index++)
1.728 + iBigBuffer.Append(TChar((index%26)+'a'));
1.729 + iBbLen=iFont->TextWidthInPixels(iBigBuffer);
1.730 + }
1.731 +
1.732 +void CGdiVertBoxText::PreTestSetupL(const TRect &, TInt )
1.733 + {
1.734 + }
1.735 +
1.736 +void CGdiVertBoxText::BaseTest(const TRect &aRect, TInt)
1.737 + {
1.738 + TInt rWid=aRect.iBr.iY-aRect.iTl.iY;
1.739 + TInt fAscent=iFont->AscentInPixels();
1.740 + TInt fHeight=iFont->HeightInPixels();
1.741 + iGdi->UseFont(iFont);
1.742 + iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
1.743 +//
1.744 + TRect rect(aRect);
1.745 + rect.iBr.iX=rect.iTl.iX+fHeight;
1.746 +//
1.747 + TInt missingChars=iFont->TextCount(iBigBuffer,iBbLen-rWid);
1.748 + TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars+1);
1.749 + TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars-1));
1.750 + TInt rLen=iFont->TextWidthInPixels(bbb);
1.751 + TBool result = IsLengthEqual(lLen,rLen,iBbLen);
1.752 + iGdiTest->TEST(result);
1.753 + if (!result)
1.754 + iGdiTest->INFO_PRINTF3(_L("(lLen+rLen)==iBbLen return value - Expected: %d, Actual: %d"), lLen+rLen, iBbLen);
1.755 +
1.756 + iGdi->DrawTextVertical(bbb, rect, fAscent, ETrue,CGraphicsContext::ELeft, rWid-rLen);
1.757 +//
1.758 + rect.iTl.iX=rect.iBr.iX;
1.759 + rect.iBr.iX=rect.iTl.iX+fHeight;
1.760 + iGdi->DrawTextVertical(iBigBuffer, rect, fAscent, ETrue,CGraphicsContext::ELeft, 0);
1.761 + }
1.762 +
1.763 +void CGdiVertBoxText::TheTest(const TRect &aRect, TInt)
1.764 + {
1.765 + TInt rWid=aRect.iBr.iY-aRect.iTl.iY;
1.766 + TInt fAscent=iFont->AscentInPixels();
1.767 + TInt fHeight=iFont->HeightInPixels();
1.768 + iGdi->UseFont(iFont);
1.769 + iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
1.770 + TRect rect(aRect);
1.771 + rect.iBr.iX=rect.iTl.iX+fHeight;
1.772 +//
1.773 + iGdi->DrawTextVertical(iBigBuffer, rect, fAscent, ETrue, CGraphicsContext::ELeft, rWid-iBbLen);
1.774 +//
1.775 + rect.iTl.iX=rect.iBr.iX;
1.776 + rect.iBr.iX=rect.iTl.iX+fHeight;
1.777 + iGdi->Clear(rect);
1.778 + iGdi->SetClippingRegion(TRegionFix<1>(rect));
1.779 + iGdi->DrawTextVertical(iBigBuffer, TPoint(rect.iTl.iX+fAscent,rect.iBr.iY), ETrue);
1.780 + }
1.781 +
1.782 +
1.783 +//
1.784 +//
1.785 +CGdiBlitMasked::~CGdiBlitMasked()
1.786 + {
1.787 + for(TInt index=0;index<ENumMasks;index++)
1.788 + delete iMask[index];
1.789 + delete iBitmap;
1.790 + delete iScratch;
1.791 + delete iScratchDevice;
1.792 + delete iScratchGc;
1.793 + delete iScratchMask;
1.794 + delete iScratchMaskDevice;
1.795 + delete iScratchMaskGc;
1.796 + }
1.797 +
1.798 +TInt CGdiBlitMasked::Count(TBool aMainTests)
1.799 + {
1.800 + return(aMainTests ? ENumMasks*2 : ENumMasks*2);
1.801 + }
1.802 +
1.803 +void CGdiBlitMasked::doCreateTestBitmapL(CFbsBitmap *aBitmap, CFbsBitGc *&aGc, CFbsBitmapDevice *&aDevice, const TSize &aSize)
1.804 + {
1.805 + User::LeaveIfNull(aDevice=CFbsBitmapDevice::NewL(aBitmap));
1.806 + User::LeaveIfError(aDevice->CreateContext(aGc));
1.807 +//
1.808 + aGc->SetBrushColor(TRgb(128,128,128));
1.809 + aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
1.810 + aGc->SetPenStyle(CGraphicsContext::ENullPen);
1.811 + aGc->DrawRect(TRect(aBitmap->SizeInPixels()));
1.812 + aGc->SetPenStyle(CGraphicsContext::ESolidPen);
1.813 + for(TInt index=(-aSize.iHeight);index<aSize.iWidth;index+=5)
1.814 + {
1.815 + aGc->DrawLine(TPoint(index,0),TPoint(index+aSize.iHeight,aSize.iHeight));
1.816 + aGc->DrawLine(TPoint(index,aSize.iHeight),TPoint(index+aSize.iHeight,0));
1.817 + }
1.818 + }
1.819 +
1.820 +void CGdiBlitMasked::createTestBitmapL(CFbsBitmap *&aBitmap, const TSize &aSize)
1.821 + {
1.822 + CFbsBitGc *gc=NULL;
1.823 + CFbsBitmapDevice *device=NULL;
1.824 + aBitmap=new(ELeave) CFbsBitmap();
1.825 + User::LeaveIfError(aBitmap->Create(aSize,EGray16));
1.826 + TRAPD(err,doCreateTestBitmapL(aBitmap, gc, device, aSize));
1.827 + delete gc;
1.828 + delete device;
1.829 + User::LeaveIfError(err);
1.830 + }
1.831 +
1.832 +void CGdiBlitMasked::ConstructL(TInt)
1.833 + {
1.834 + TSize max(0,0);
1.835 + for(TInt index=0;index<ENumMasks;index++)
1.836 + {
1.837 + iMask[index]=new(ELeave) CFbsBitmap();
1.838 + User::LeaveIfError(iMask[index]->Load(TAUTO_BITMAP_NAME,2+index));
1.839 + TSize size=iMask[index]->SizeInPixels();
1.840 + if (max.iWidth<size.iWidth)
1.841 + max.iWidth=size.iWidth;
1.842 + if (max.iHeight<size.iHeight)
1.843 + max.iHeight=size.iHeight;
1.844 + }
1.845 + iScratch=new(ELeave) CFbsBitmap();
1.846 + User::LeaveIfError(iScratch->Create(max,EGray16));
1.847 + iScratchDevice=CFbsBitmapDevice::NewL(iScratch);
1.848 + User::LeaveIfError(iScratchDevice->CreateContext(iScratchGc));
1.849 +
1.850 + iScratchMask=new(ELeave) CFbsBitmap();
1.851 + User::LeaveIfError(iScratchMask->Create(max,EGray16));
1.852 + iScratchMaskDevice=CFbsBitmapDevice::NewL(iScratchMask);
1.853 + User::LeaveIfError(iScratchMaskDevice->CreateContext(iScratchMaskGc));
1.854 +//
1.855 + createTestBitmapL(iBitmap, max);
1.856 + }
1.857 +
1.858 +void CGdiBlitMasked::PreTestSetupL(const TRect &, TInt aCount)
1.859 + {
1.860 + iInvertMask=aCount&0x1;
1.861 + aCount>>=1;
1.862 + iCurrMask= iMask[aCount%ENumMasks];
1.863 + iDrawMode=CGraphicsContext::EDrawModePEN;
1.864 + }
1.865 +
1.866 +void CGdiBlitMasked::BaseTest(const TRect &aRect, TInt)
1.867 + {
1.868 +// needs re-writing to emulate tiling of the source rect
1.869 + if (!aRect.Intersects(TRect(BaseWin->Size())))
1.870 + return;
1.871 + TSize size(aRect.Size());
1.872 + TSize bitSize=iBitmap->SizeInPixels();
1.873 + if (size.iWidth>bitSize.iWidth)
1.874 + size.iWidth=bitSize.iWidth;
1.875 + if (size.iHeight>bitSize.iHeight)
1.876 + size.iHeight=bitSize.iHeight;
1.877 +//
1.878 +// Set up the scratch mask as a black and white bitmap containing the mask to blit
1.879 +// The mask pattern is replicated all over the scratchmask bitmap
1.880 +//
1.881 + iScratchMaskGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
1.882 + iScratchMaskGc->SetPenStyle(CGraphicsContext::ENullPen);
1.883 + iScratchMaskGc->SetBrushColor(TRgb(0,0,0));
1.884 + iScratchMaskGc->DrawRect(TRect(iScratchMask->SizeInPixels()));
1.885 + iScratchMaskGc->SetPenColor(TRgb(255,255,255));
1.886 + iScratchMaskGc->SetPenStyle(CGraphicsContext::ESolidPen);
1.887 + TSize maskSize(iCurrMask->SizeInPixels());
1.888 + TPoint pos;
1.889 + TRgb *rgbBuf=(TRgb *)User::AllocL(maskSize.iWidth*sizeof(TRgb)); //Doesn't do any harm if it leaves
1.890 + for(pos.iY=0;pos.iY<maskSize.iHeight;pos.iY++)
1.891 + {
1.892 + TPtr8 ptr((TUint8 *)rgbBuf,maskSize.iWidth*sizeof(TRgb));
1.893 + iCurrMask->GetScanLine(ptr, pos, maskSize.iWidth, ERgb);
1.894 + for(TInt index=0;index<maskSize.iWidth;index++)
1.895 + {
1.896 + iScratchMaskGc->SetPenColor(rgbBuf[index]);
1.897 +// if ((isLow && !iLowCutOff) || (!isLow && iLowCutOff))
1.898 + iScratchMaskGc->Plot(TPoint(index,pos.iY));
1.899 + }
1.900 + }
1.901 + User::Free(rgbBuf);
1.902 +
1.903 + for(pos.iY=0;pos.iY<size.iHeight;pos.iY+=maskSize.iHeight)
1.904 + for(pos.iX=0;pos.iX<size.iWidth;pos.iX+=maskSize.iWidth)
1.905 + iScratchMaskGc->CopyRect(pos, TRect(maskSize));
1.906 +//
1.907 +// Blit this to the screen in ANDNOT mode to clear all the pixels we want the mask blit to draw to
1.908 +//
1.909 + iGdi->SetDrawMode(CGraphicsContext::EDrawModeANDNOT);
1.910 + iGdi->BitBlt(aRect.iTl, iScratchMask, TRect(size));
1.911 +//
1.912 +// Copy the test bitmap to the scratch bitmap then use the scratch mask to clear all the bits
1.913 +// that should masked out of the draw to the screen
1.914 +//
1.915 + iScratchGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
1.916 + iScratchGc->BitBlt(TPoint(0,0), iBitmap);
1.917 + iScratchGc->SetDrawMode(CGraphicsContext::EDrawModeAND);
1.918 + iScratchGc->BitBlt(TPoint(0,0), iScratchMask);
1.919 +//
1.920 +// Now copy the scratch bitmap to the screen in OR mode to get the final result
1.921 +//
1.922 + iGdi->SetDrawMode(CGraphicsContext::EDrawModeOR);
1.923 + iGdi->BitBlt(aRect.iTl, iScratch, TRect(size));
1.924 + }
1.925 +
1.926 +void CGdiBlitMasked::TheTest(const TRect &aRect, TInt)
1.927 + {
1.928 + iGdi->BitBltMasked(aRect.iTl,iBitmap,TRect((aRect.iBr-aRect.iTl).AsSize()),
1.929 + iCurrMask,iInvertMask);
1.930 + }
1.931 +//
1.932 +//
1.933 +
1.934 +CTGdi::CTGdi(CTestStep* aStep) : CTWsGraphicsBase(aStep), iGdiTest (NULL), iTextOffsetX(10),iTextOffsetY(10)
1.935 + {
1.936 + }
1.937 +
1.938 +void CTGdi::ConstructL()
1.939 + {
1.940 + iWinSize=TestWin->Size();
1.941 + }
1.942 +
1.943 +TSize CTGdi::WinSize()
1.944 + {
1.945 + return(iWinSize);
1.946 + }
1.947 +
1.948 +void CTGdi::DoGdiTestL(const TRect &aRect, TInt aNum)
1.949 + {
1.950 +//
1.951 + iGdiTest->PreTestSetupL(aRect,aNum);
1.952 +//
1.953 + BaseWin->Win()->Invalidate();
1.954 + BaseWin->Win()->BeginRedraw();
1.955 + TheGc->Activate(*BaseWin->Win());
1.956 + iTest->DrawTestBackground(EFalse,BaseWin->Size());
1.957 + iGdiTest->BaseTest(aRect,aNum);
1.958 + TheGc->Deactivate();
1.959 + BaseWin->Win()->EndRedraw();
1.960 +//
1.961 + TestWin->Win()->Invalidate();
1.962 + TestWin->Win()->BeginRedraw();
1.963 + TheGc->Activate(*TestWin->Win());
1.964 + iTest->DrawTestBackground(EFalse,TestWin->Size());
1.965 + iGdiTest->TheTest(aRect,aNum);
1.966 + TheGc->Deactivate();
1.967 + TestWin->Win()->EndRedraw();
1.968 +//
1.969 + TheClient->iWs.Flush();
1.970 + TheClient->WaitForRedrawsToFinish();
1.971 + TheClient->iWs.Finish();
1.972 +//
1.973 + _LIT(KLog,"GDI Substate=%d test=%d rect=(%d,%d,%d,%d) ");
1.974 + TBuf<64> buf;
1.975 + buf.Format(KLog,iSubState,aNum,aRect.iTl.iX,aRect.iTl.iY,aRect.iBr.iX,aRect.iBr.iY);
1.976 + iTestPassing=CompareWindows(buf);
1.977 + }
1.978 +
1.979 +void CTGdi::GdiTestL(CGdiTestLowLevel *aTest)
1.980 + {
1.981 + TTestRects::ResetSeed();
1.982 + iTestPassing=ETrue;
1.983 + iGdiTest=aTest;
1.984 + iGdiTest->SetGdiTest(this);
1.985 + iGdiTest->AssignGdi(TheGc);
1.986 + iGdiTest->ConstructL(iTest->iTestRects.Count1());
1.987 + TInt index;
1.988 + TInt index2;
1.989 + for(index=0; iTestPassing && index<iTest->iTestRects.Count2(); ++index)
1.990 + {
1.991 + TInt max=iGdiTest->Count(index<iTest->iTestRects.Count1());
1.992 + TRect rect=iTest->iTestRects[index];
1.993 + #if defined(LOGGING)
1.994 + _LIT(KLog1,"Testing rectangle %d (%d,%d,%d,%d) 1st pass");
1.995 + LOG_MESSAGE6(KLog1,index,rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
1.996 + #endif
1.997 + for(index2=0; iTestPassing && index2<max; ++index2)
1.998 + DoGdiTestL(rect,index2);
1.999 + if (!iTestPassing)
1.1000 + {
1.1001 + _LIT(KLog,"Test fail on rectangle %d at iteration %d");
1.1002 + LOG_MESSAGE3(KLog,index,index2);
1.1003 + }
1.1004 + }
1.1005 + for(; iTestPassing && index<iTest->iTestRects.Count3(); index++)
1.1006 + {
1.1007 + TRect rect=iTest->iTestRects[index];
1.1008 + #if defined(LOGGING)
1.1009 + _LIT(KLog2,"Testing rectangle %d (%d,%d,%d,%d) 2nd pass");
1.1010 + LOG_MESSAGE6(KLog2,index,rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
1.1011 + #endif
1.1012 + DoGdiTestL(rect,0);
1.1013 + }
1.1014 + delete iGdiTest;
1.1015 + iGdiTest=NULL;
1.1016 + }
1.1017 +
1.1018 +void CTGdi::NonDrawing()
1.1019 +//
1.1020 +// Test all non-drawing GDI functions
1.1021 +//
1.1022 + {
1.1023 + TDisplayMode mode=TheClient->iScreen->DisplayMode();
1.1024 + TEST((mode!=ERgb) && (mode!=ENone));
1.1025 +
1.1026 + RWsSession session;
1.1027 + TInt res = session.Connect();
1.1028 + TEST(res == KErrNone);
1.1029 +
1.1030 + CArrayFixFlat<TInt>* modeList= new CArrayFixFlat<TInt> (15);
1.1031 + if(!modeList)
1.1032 + return;
1.1033 +
1.1034 +#if defined(SYMBIAN_GRAPHICS_GCE)
1.1035 + res = session.GetColorModeList(iTest->iScreenNumber, modeList);
1.1036 +#else
1.1037 + res = session.GetColorModeList(modeList);
1.1038 +#endif //SYMBIAN_GRAPHICS_GCE
1.1039 + session.Close();
1.1040 + TEST(res == KErrNone);
1.1041 + if(res != KErrNone)
1.1042 + {
1.1043 + modeList->Reset();
1.1044 + delete modeList;
1.1045 + return;
1.1046 + }
1.1047 +
1.1048 + TBool found = EFalse;
1.1049 + for(TInt ii = 0; ii < modeList->Count() && !found; ii++)
1.1050 + {
1.1051 + TDisplayMode mode1 = (TDisplayMode) ((*modeList)[ii]);
1.1052 + if(mode == mode1)
1.1053 + {
1.1054 + found = ETrue;
1.1055 + }
1.1056 + }
1.1057 + modeList->Reset();
1.1058 + delete modeList;
1.1059 +
1.1060 + TEST(found);
1.1061 + }
1.1062 +
1.1063 +//
1.1064 +// Auxiliary Fn for Test Case ID CTGdi_TestDefetct_DEF045746
1.1065 +// This method draws the text represented by aText parameter on the window
1.1066 +// passed to it.
1.1067 +//
1.1068 +void CTGdi::DrawTextOnWindow(const TDesC& aText,CTWin* aWin)
1.1069 + {
1.1070 + aWin->Win()->BeginRedraw();
1.1071 + TheGc->Activate(*aWin->Win());
1.1072 + TheGc->Device()->GetNearestFontToDesignHeightInTwips(iFont,TFontSpec(_L("Arial"),250));
1.1073 + TheGc->UseFont(iFont);
1.1074 + TheGc->Clear();
1.1075 + TheGc->DrawRect(TRect(aWin->Win()->Size()));
1.1076 + TheGc->DrawText(aText,TPoint(iTextOffsetX,iTextOffsetY));
1.1077 + TheGc->Device()->ReleaseFont(iFont);
1.1078 + TheGc->Deactivate();
1.1079 + aWin->Win()->EndRedraw();
1.1080 + }
1.1081 +
1.1082 +
1.1083 +void CTGdi::TestDefetct_DEF045746L()
1.1084 + {
1.1085 + _LIT(KString,"This is a test window for the defect fix DEF045746 \
1.1086 + propagated from Opera browser. Most window graphics context drawing\
1.1087 + functions map to equivalent CFbsBitGc functions they are implemented\
1.1088 + on the screen with any co-ordinates being relative to the top left\
1.1089 + corner of the window. However extra clipping is applied. The drawing\
1.1090 + will always be clipped to the visible part of the window, in addition\
1.1091 + it will be clipped to the non-invalid part if you are not doing a\
1.1092 + redraw and to the region being validated if you are doing a redraw.");
1.1093 +
1.1094 + TPtrC TestText(KString().Ptr(),100);
1.1095 + TPtrC LargeText(KString().Ptr());
1.1096 + TPtrC ShortText(KString().Ptr(),200);
1.1097 +
1.1098 + TSize scrSize=TheClient->iScreen->SizeInPixels();
1.1099 + TSize winSize;
1.1100 + const TInt windowGap=5;
1.1101 + winSize.SetSize(scrSize.iWidth -2* windowGap,scrSize.iHeight/2 - windowGap);
1.1102 +
1.1103 + iWin=new(ELeave) CTestWindow(TRgb(0,0,0));
1.1104 + iWin->ConstructL(TPoint(5,5),TSize(winSize),TheClient->iGroup,*TheClient->iGc);
1.1105 + CTestWindow* expectWin= new(ELeave) CTestWindow(TRgb(0,0,0));
1.1106 + expectWin->ConstructL(TPoint(5,scrSize.iHeight/2 + windowGap),TSize(winSize),TheClient->iGroup,*TheClient->iGc);
1.1107 + DrawTextOnWindow(ShortText,iWin);
1.1108 + DrawTextOnWindow(TestText,expectWin);
1.1109 + TInt fHeight=iFont->HeightInPixels();//Used to compare only pixels where text is drawn
1.1110 + TRect iRect=winSize;
1.1111 + iRect.iTl.iX=iTextOffsetX;
1.1112 + iRect.iTl.iY=iTextOffsetY;
1.1113 + iRect.iBr.iY=iTextOffsetY+fHeight;
1.1114 + CheckRect(iWin,expectWin,iRect,_L("TestDefetct_DEF045746L A"));
1.1115 + iWin->Invalidate();
1.1116 + DrawTextOnWindow(LargeText,iWin);
1.1117 + CheckRect(iWin,expectWin,iRect,_L("TestDefetct_DEF045746L B"));
1.1118 + delete iWin;
1.1119 + iWin=NULL;
1.1120 + delete expectWin;
1.1121 + expectWin=NULL;
1.1122 + }
1.1123 +
1.1124 +void CTGdi::RunTestCaseL(TInt /*aCurTestCase*/)
1.1125 + {
1.1126 + //_LIT(KTest1,"NonDrawing"); this test is not running
1.1127 + _LIT(KTest2,"DEF045746");
1.1128 + _LIT(KTest3,"Drawing Tests");
1.1129 + ((CTGdiStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.1130 + static TTime startTime;
1.1131 + switch(++iTest->iState)
1.1132 + {
1.1133 +/**
1.1134 +@SYMTestCaseID GRAPHICS-WSERV-0262
1.1135 +
1.1136 +@SYMDEF DEF081259
1.1137 +
1.1138 +@SYMTestCaseDesc Test all non-drawing GDI functions
1.1139 +
1.1140 +@SYMTestPriority High
1.1141 +
1.1142 +@SYMTestStatus Implemented
1.1143 +
1.1144 +@SYMTestActions Check all non-drawing GDI functions operate correctly
1.1145 +
1.1146 +@SYMTestExpectedResults Non-drawing GDI functions operate correctly
1.1147 +*/
1.1148 + case 1:
1.1149 + // start time log
1.1150 + startTime.HomeTime();
1.1151 + ((CTGdiStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0262"));
1.1152 + //iTest->LogSubTest(KTest1);
1.1153 + //PeterI this tests whether the display mode is EGray4 or EGray16.
1.1154 + //The actual display mode is EColor16MU so this test will always fail
1.1155 + //NonDrawingL();
1.1156 + break;
1.1157 +/**
1.1158 + * @SYMTestCaseID GRAPHICS-WSERV-0263
1.1159 + *
1.1160 + * @SYMPREQ DEF045746
1.1161 + *
1.1162 + * @SYMTestCaseDesc Test defect fix for DEF045746
1.1163 + *
1.1164 + * @SYMTestPriority High
1.1165 + *
1.1166 + * @SYMTestStatus Implemented
1.1167 + *
1.1168 + * @SYMTestActions The method tests CWindowGc::DrawText().The test is carried
1.1169 + * out by writing small & very large strings to the window graphic context.
1.1170 + *
1.1171 + * @SYMTestExpectedResults The window with large / small strings written is
1.1172 + * compared with an expected result window. In both the cases strings should
1.1173 + * be displayed.
1.1174 + *
1.1175 + */
1.1176 + case 2:
1.1177 + ((CTGdiStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0263"));
1.1178 + iTest->LogSubTest(KTest2);
1.1179 + TestDefetct_DEF045746L();
1.1180 + break;
1.1181 +/**
1.1182 +@SYMTestCaseID GRAPHICS-WSERV-0264
1.1183 +
1.1184 +@SYMDEF DEF081259
1.1185 +
1.1186 +@SYMTestCaseDesc Test all drawing GDI functions
1.1187 +
1.1188 +@SYMTestPriority High
1.1189 +
1.1190 +@SYMTestStatus Implemented
1.1191 +
1.1192 +@SYMTestActions Check all drawing GDI functions operate correctly
1.1193 +
1.1194 +@SYMTestExpectedResults Drawing GDI functions operate correctly
1.1195 +*/
1.1196 + case 3:
1.1197 + {
1.1198 + ((CTGdiStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0264"));
1.1199 + iTest->LogSubTest(KTest3);
1.1200 + iSubState = 0;
1.1201 + TheClient->WaitForRedrawsToFinish(); //Just in case the two test windows have any invalid areas
1.1202 + TInt numTests = sizeof(GdiTestFuncs) / sizeof(GdiTestFuncs[0]);
1.1203 + while (iSubState < numTests)
1.1204 + {
1.1205 + LOG_MESSAGE(TPtrC(GdiTestFuncs[iSubState].txt));
1.1206 + GdiTestL((*GdiTestFuncs[iSubState].func)());
1.1207 + iSubState++;
1.1208 + }
1.1209 + }
1.1210 + break;
1.1211 + default:
1.1212 + ((CTGdiStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.1213 + ((CTGdiStep*)iStep)->CloseTMSGraphicsStep();
1.1214 + TestComplete();
1.1215 + // log time and print duration
1.1216 + TTime endTime;
1.1217 + endTime.HomeTime();
1.1218 + TInt64 duration = endTime.MicroSecondsFrom(startTime).Int64();
1.1219 + float time = (float) I64LOW(duration) / 1000.0f;
1.1220 + _LIT(KDuration,"Total test duration is %f millisec");
1.1221 + RDebug::Print(KDuration, time);
1.1222 + break;
1.1223 + }
1.1224 + ((CTGdiStep*)iStep)->RecordTestResultL();
1.1225 + }
1.1226 +
1.1227 +CGdiTestLowLevel *SetOriginTest()
1.1228 + {
1.1229 + return(new(ELeave) CGdiSetOrigin());
1.1230 + }
1.1231 +
1.1232 +CGdiTestLowLevel *PolyLineTest()
1.1233 + {
1.1234 + return(new(ELeave) CGdiPolyLine());
1.1235 + }
1.1236 +
1.1237 +CGdiTestLowLevel *PolygonTest()
1.1238 + {
1.1239 + return(new(ELeave) CGdiPolygon());
1.1240 + }
1.1241 +
1.1242 +CGdiTestLowLevel *BlitMaskedTest()
1.1243 + {
1.1244 + return(new(ELeave) CGdiBlitMasked());
1.1245 + }
1.1246 +
1.1247 +CGdiTestLowLevel *DrawArcTest()
1.1248 + {
1.1249 + return(new(ELeave) CGdiDrawArc());
1.1250 + }
1.1251 +
1.1252 +CGdiTestLowLevel *DrawPieTest()
1.1253 + {
1.1254 + return(new(ELeave) CGdiDrawPie());
1.1255 + }
1.1256 +
1.1257 +CGdiTestLowLevel *DrawRoundRectTest()
1.1258 + {
1.1259 + return(new(ELeave) CGdiDrawRoundRect());
1.1260 + }
1.1261 +
1.1262 +CGdiTestLowLevel *BoxTextTest()
1.1263 + {
1.1264 + return(new(ELeave) CGdiBoxText());
1.1265 + }
1.1266 +
1.1267 +CGdiTestLowLevel *VertTextTest()
1.1268 + {
1.1269 + return(new(ELeave) CGdiDrawVertText());
1.1270 + }
1.1271 +
1.1272 +CGdiTestLowLevel *VertBoxTextTest()
1.1273 + {
1.1274 + return(new(ELeave) CGdiVertBoxText());
1.1275 + }
1.1276 +
1.1277 +CGdiTestLowLevel *WideLineTest()
1.1278 + {
1.1279 + return(new(ELeave) CGdiWideLine());
1.1280 + }
1.1281 +
1.1282 +CGdiTestLowLevel *DrawTextTest()
1.1283 + {
1.1284 + return(new(ELeave) CGdiDrawText());
1.1285 + }
1.1286 +
1.1287 +CGdiTestLowLevel *DrawRectTest()
1.1288 + {
1.1289 + return(new(ELeave) CGdiDrawRect());
1.1290 + }
1.1291 +
1.1292 +__WS_CONSTRUCT_STEP__(Gdi)