Update contrib.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent Internal Symbian test code
23 #include <graphics/fbsdefs.h>
26 #if defined (__WINS__)
27 #define PDD_NAME _L("ECDRV")
28 #define LDD_NAME _L("ECOMM")
30 #define PDD_NAME _L("EUART1")
31 #define LDD_NAME _L("ECOMM")
34 // Set KVerboseOutput to "ETrue" if extra INFO_PRINTFx for debug purposes are required
35 const TBool KVerboseOutput = EFalse;
37 _LIT( KDriveName, "z:" );
38 _LIT( KEpsonFileName, "epson.pdr" );
40 //--------------------------------------------------------------------------------
41 void CPdrTestPrint::RunL()
43 CActiveScheduler::Stop();
46 TRequestStatus& CPdrTestPrint::Queue()
52 TRequestStatus& CPdrTestPrint::Status()
57 //-------------------------------------------------------------------------------
59 CTPdr::CTPdr(CTestStep* aStep) :
69 void CTPdr::ConstructL()
71 INFO_PRINTF1(_L( "Start the various bits and pieces of the comms server\n" ));
74 #if !defined(__X86GCC__)
75 ret=User::LoadPhysicalDevice(PDD_NAME);
76 TEST(ret==KErrNone || ret==KErrAlreadyExists);
78 ret=User::LoadLogicalDevice(LDD_NAME);
79 TEST(ret==KErrNone || ret==KErrAlreadyExists);
82 // to avoid alloc heaven with the fbs server
83 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
84 CleanupStack::PushL(bitmap);
85 User::LeaveIfError(bitmap->Create(TSize(1024, 1024), EColor16MA));
86 CleanupStack::PopAndDestroy(bitmap);
88 // to avoid alloc heaven with the fbs server
91 ret=bmp1.Load(_L("z:\\test\\pdrstore.mbm"),0,NULL); // sheep
93 ret=bmp2.Load(_L("z:\\test\\pdrstore.mbm"),1,NULL); // pslogo
100 void CTPdr::testPrint(CPrinterDevice* aDevice)
102 INFO_PRINTF1(_L("calling testPrint()..."));
107 TInt ret=bmp1.Load(_L("z:\\test\\pdrstore.mbm"),0,EFalse); // sheep
109 ret=bmp2.Load(_L("z:\\test\\pdrstore.mbm"),1,EFalse); // pslogo
112 bmp1.SetSizeInTwips(TSize(3000,1500));
113 bmp2.SetSizeInTwips(TSize(2000,900));
115 TBandAttributes attributes;
116 CPrinterControl::TMoreOnPage moreonpage=CPrinterControl::EMoreOnPage;
118 TInt h=aDevice->HorizontalPixelsToTwips(1000);
119 TInt v=aDevice->VerticalPixelsToTwips(1000);
127 INFO_PRINTF2(_L("Get band %d"),i+1);
129 moreonpage=aDevice->iControl->QueueGetBand(iStopper->Queue(),attributes);
130 CActiveScheduler::Start();
132 CGraphicsContext* gc=NULL;
133 ret=aDevice->CreateContext((CGraphicsContext *&) gc);
136 gc->SetPenColor(KRgbBlack);
137 gc->SetPenStyle(CGraphicsContext::ESolidPen);
138 gc->SetPenSize(TSize(4*k/h,4*k/v));
139 gc->DrawEllipse(TRect(391,352,1152,601));
140 gc->DrawEllipse(TRect(391,336,1152,585));
142 gc->DrawEllipse(TRect(727,693,1488,942));
143 gc->DrawEllipse(TRect(727,677,1488,926));
145 TFontSpec spec (_L("CG Times"),300);
146 spec.iTypeface.SetIsProportional(ETrue);
147 ret=aDevice->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
152 INFO_PRINTF2(_L("TextWidthInPixels(HELLO WORLD) %d"),font->TextWidthInPixels(_L("HELLO WORLD")));
156 gc->SetUnderlineStyle(EUnderlineOn);
157 gc->DrawText(_L("HELLO WORLD"),TRect(300*k/h,200*k/v,1800*k/h,300*k/v),100*k/v,CGraphicsContext::ELeft,0);
158 gc->SetUnderlineStyle(EUnderlineOff);
159 gc->DrawText(_L("HELLO WORLD"),TRect(300*k/h,200*k/v,1800*k/h,300*k/v),100*k/v,CGraphicsContext::ERight,0);
160 gc->DrawText(_L("HELLO WORLD"),TRect(300*k/h,200*k/v,1800*k/h,300*k/v),100*k/v,CGraphicsContext::ECenter,0);
163 text.Format(_L("Test symbols %c %c %c %c"),130,131,132,133);
165 gc->SetPenColor(KRgbBlack);
166 gc->DrawText(text,TRect(1000*k/h,2500*k/v,1800*k/h,2700*k/v),50*k/v,CGraphicsContext::ELeft,0);
167 gc->SetWordJustification(1200*k/h,4);
168 gc->DrawText(_L("Bramm an gath"),TRect(1000*k/h,2500*k/v,1800*k/h,2700*k/v),100*k/v,CGraphicsContext::ELeft,0);
169 gc->DrawText(_L("Bramm an gath"),TRect(1000*k/h,2500*k/v,1800*k/h,2700*k/v),150*k/v,CGraphicsContext::ELeft,0);
170 aDevice->ReleaseFont(font);
172 ret=aDevice->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
175 gc->DrawText(_L("BRAMM AN GATH"),TRect(1000*k/h,2800*k/v,1800*k/h,3000*k/v),200*k/v,CGraphicsContext::ELeft,0);
176 spec.iFontStyle.SetPrintPosition(EPrintPosSuperscript);
177 aDevice->ReleaseFont(font);
178 ret=aDevice->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
181 gc->DrawText(_L("BRAMM AN GATH"),TRect(1000*k/h,2800*k/v,1800*k/h,3000*k/v),200*k/v,CGraphicsContext::ERight,0);
182 aDevice->ReleaseFont(font);
183 spec.iFontStyle.SetPrintPosition(EPrintPosSubscript);
184 ret=aDevice->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
187 gc->SetBrushColor(KRgbWhite);
188 gc->SetBrushStyle(CGraphicsContext::ENullBrush);
189 gc->DrawText(_L("BRAMM AN GATH"),TRect(1000*k/h,2800*k/v,1800*k/h,3000*k/v),200*k/v,CGraphicsContext::ECenter,0);
190 aDevice->ReleaseFont(font);
193 gc->DrawBitmap(TPoint(800*k/h,900*k/v),&bmp1);
194 gc->DrawBitmap(TPoint(1700*k/h,3100*k/v),&bmp2);
195 gc->DrawBitmap(TPoint(1000*k/h,1400*k/v),&bmp2);
196 gc->DrawBitmap(TPoint(100*k/h,1700*k/v),&bmp2);
199 gc->SetPenSize(TSize(30*k/h,30*k/v));
200 gc->DrawLine(TPoint(800*k/h,100*k/v),TPoint(2000*k/h,100*k/v));
201 gc->DrawLine(TPoint(1500*k/h,400*k/v),TPoint(1800*k/h,1500*k/v));
204 gc->SetPenSize(TSize(4*k/h,4*k/v));
205 gc->SetBrushStyle(CGraphicsContext::ENullBrush);
206 gc->SetBrushColor(KRgbWhite);
207 gc->DrawRect(TRect(300*k/h,200*k/v,1800*k/h,300*k/v));
210 gc->SetPenSize(TSize(10*k/h,10*k/v));
211 gc->DrawEllipse(TRect(300*k/h,2600*k/v,700*k/h,3000*k/v));
214 gc->SetPenSize(TSize(20*k/h,20*k/v));
215 gc->Plot(TPoint(1800*k/h,1600*k/v));
221 INFO_PRINTF2(_L("End of band %d"),i+1);
226 while (moreonpage==CPrinterControl::EMoreOnPage);
227 INFO_PRINTF1(_L("QueueEndPrint"));
228 aDevice->iControl->QueueEndPrint(iStopper->Queue());
229 CActiveScheduler::Start();
230 INFO_PRINTF2(_L("Request status %d"),iStopper->Status().Int());
239 // Test read file handling.
241 void CTPdr::testPdrStore()
245 INFO_PRINTF1(_L("Add to the active scheduler"));
246 iStopper=new(ELeave) CPdrTestPrint();
247 CActiveScheduler::Add(iStopper);
250 INFO_PRINTF1(_L("OpenPdrL(pdr file)"));
251 CPrinterDriver* driver=NULL;
252 TRAPD(ret,driver=CPrinterDriver::NewL());
255 TFileName filename( KDriveName );
256 filename.Append( KDefaultPrinterDriverPath );
257 filename.Append( KEpsonFileName );
259 TRAP(ret,driver->OpenPdrL( filename ));
261 INFO_PRINTF2(_L("NumModels %d"),driver->NumModels());
264 TPrinterModelEntry entry;
266 iNumModels = driver->NumModels();
267 for (i=0; i<iNumModels; i++)
269 entry=driver->Model(i);
270 INFO_PRINTF2(_L(" *********************** ModelName %S"),&entry.iModelName);
274 INFO_PRINTF1(_L("Create printer device"));
275 CPrinterDevice* device=NULL;
276 entry=driver->Model(iModelIndex);
277 TRAP(ret,device=driver->CreatePrinterDeviceL(entry.iUid));
279 CPrinterDriverUI* driverui=NULL;
280 TRAP(ret,driverui=driver->CreatePrinterDriverUIL());
281 INFO_PRINTF2(_L("DriverUI %d"),driverui);
284 INFO_PRINTF2(_L("NumTypefaces %d"),device->NumTypefaces());
285 INFO_PRINTF2(_L("**Model name %S**"),&entry.iModelName);
286 INFO_PRINTF2(_L("KPixelWidthInTwips %d"),device->HorizontalPixelsToTwips(1000));
287 INFO_PRINTF2(_L("KPixelHeightInTwips %d"),device->VerticalPixelsToTwips(1000));
288 TPageSpec pagespec(TPageSpec::EPortrait,KA4PaperSizeInTwips);
289 device->SelectPageSpecInTwips(pagespec);
292 INFO_PRINTF1(_L("Get typeface info"));
293 TTypefaceSupport support;
294 device->TypefaceSupport(support,0);
295 TBuf<KMaxTypefaceNameLength> name;
296 name.Copy(support.iTypeface.iName);
297 INFO_PRINTF2(_L("Typeface Name %S"),&name);
298 INFO_PRINTF2(_L("Typeface serif %d"),support.iTypeface.IsSerif());
299 INFO_PRINTF2(_L("Typeface proportional %d"),support.iTypeface.IsProportional());
300 INFO_PRINTF2(_L("Typeface symbol %d"),support.iTypeface.IsSymbol());
301 INFO_PRINTF2(_L("NumHeights %d"),support.iNumHeights);
302 INFO_PRINTF2(_L("MinHeightInTwips %d"),support.iMinHeightInTwips);
303 INFO_PRINTF2(_L("MaxHeightInTwips %d"),support.iMaxHeightInTwips);
304 INFO_PRINTF2(_L("IsScalable %d"),support.iIsScalable);
307 INFO_PRINTF1(_L("Get nearest font"));
310 support.iTypeface.iName=_L("DejaVu Sans Condensed");
311 support.iTypeface.SetIsProportional(ETrue);
312 support.iTypeface.SetIsSerif(ETrue);
313 spec.iTypeface=support.iTypeface;
315 spec.iFontStyle.SetPosture(EPostureUpright);
316 spec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
317 spec.iFontStyle.SetPrintPosition(EPrintPosNormal);
318 ret=device->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
320 INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels());
321 INFO_PRINTF2(_L("AscentInPixels %d"),font->AscentInPixels());
322 INFO_PRINTF3(_L("Font Posture %d StrokeWeight %d"),font->FontSpecInTwips().iFontStyle.Posture(),font->FontSpecInTwips().iFontStyle.StrokeWeight());
323 INFO_PRINTF3(_L("Font AlgPosture %d AlgStrokeWeight %d"),((CBitmapFont*)font)->iAlgStyle.IsItalic(),((CBitmapFont*)font)->iAlgStyle.IsBold());
324 spec=font->FontSpecInTwips();
325 device->ReleaseFont(font);
326 ret=device->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
328 INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels());
329 INFO_PRINTF2(_L("AscentInPixels %d"),font->AscentInPixels());
330 INFO_PRINTF3(_L("Font Posture %d StrokeWeight %d"),font->FontSpecInTwips().iFontStyle.Posture(),font->FontSpecInTwips().iFontStyle.StrokeWeight());
331 INFO_PRINTF3(_L("Font AlgPosture %d AlgStrokeWeight %d"),((CBitmapFont*)font)->iAlgStyle.IsItalic(),((CBitmapFont*)font)->iAlgStyle.IsBold());
332 name.Copy(font->FontSpecInTwips().iTypeface.iName);
333 INFO_PRINTF2(_L("Typeface Name %S"),&name);
334 INFO_PRINTF2(_L("Typeface Proportional %d"),font->FontSpecInTwips().iTypeface.IsProportional());
335 INFO_PRINTF2(_L("Typeface Serif %d"),font->FontSpecInTwips().iTypeface.IsSerif());
336 INFO_PRINTF2(_L("CharWidthInPixels(32) %d"),font->CharWidthInPixels(TChar(32)));
337 INFO_PRINTF2(_L("MaxCharWidthInPixels %d"),font->MaxCharWidthInPixels());
338 INFO_PRINTF2(_L("MaxNormalCharWidthInPixels %d"),font->MaxNormalCharWidthInPixels());
339 INFO_PRINTF2(_L("HeightInTwips %d"),font->FontSpecInTwips().iHeight);
340 INFO_PRINTF2(_L("HeightInPixels %d"),font->HeightInPixels());
341 INFO_PRINTF2(_L("AscentInPixels %d"),font->AscentInPixels());
342 INFO_PRINTF2(_L("TextWidthInPixels(HELLO WORLD) %d"),font->TextWidthInPixels(_L("HELLO WORLD")));
343 device->ReleaseFont(font);
346 spec.iFontStyle.SetPrintPosition(EPrintPosNormal);
348 spec.iFontStyle.SetPrintPosition(EPrintPosNormal);
349 spec.iFontStyle.SetPosture(EPostureUpright);
350 spec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
351 for (i=0; i<device->NumTypefaces(); i++)
353 device->TypefaceSupport(support,i);
354 name.Copy(support.iTypeface.iName);
355 INFO_PRINTF2(_L("Typeface Name %S"),&name);
356 for (TInt j=0; j<support.iNumHeights; j++)
358 spec.iTypeface=support.iTypeface;
359 spec.iHeight=device->FontHeightInTwips(i,j);
360 ret=device->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
364 INFO_PRINTF2(_L("Spec HeightInTwips %d"),spec.iHeight);
365 INFO_PRINTF2(_L("Font HeightInTwipss %d"),font->FontSpecInTwips().iHeight);
366 INFO_PRINTF3(_L("Font Posture %d StrokeWeight %d"),font->FontSpecInTwips().iFontStyle.Posture(),font->FontSpecInTwips().iFontStyle.StrokeWeight());
368 device->ReleaseFont(font);
376 _LIT(KPath,"C:\\system\\data\\");
378 ret=file.Replace(fs,_L("C:\\system\\data\\WIDTHS.TMP"),EFileStream|EFileWrite);
381 _LIT(KLog,"Doing Replace on file C:\\system\\data\\WIDTHS.TMP gave error %d");
382 INFO_PRINTF2(KLog,ret);
388 for (i=0; i<device->NumTypefaces(); i++)
390 device->TypefaceSupport(support,i);
391 spec.iTypeface=support.iTypeface;
392 for (TInt k=0; k<support.iNumHeights; k++)
394 spec.iHeight=device->FontHeightInTwips(i,k);
395 if ((spec.iHeight==1000))
397 for (TInt j=0; j<4; j++)
399 name.Copy(support.iTypeface.iName);
400 buf.Format(_L8("FontInfo %S"),&support.iTypeface.iName);
405 buf.Format(_L8("Std%d"),spec.iHeight/20);
408 spec.iFontStyle.SetPosture(EPostureUpright);
409 spec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
413 buf.Format(_L8("Bold%d"),spec.iHeight/20);
416 spec.iFontStyle.SetPosture(EPostureUpright);
417 spec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
421 buf.Format(_L8("Italic%d"),spec.iHeight/20);
424 spec.iFontStyle.SetPosture(EPostureItalic);
425 spec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
429 buf.Format(_L8("BoldItalic%d"),spec.iHeight/20);
432 spec.iFontStyle.SetPosture(EPostureItalic);
433 spec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
435 ret=device->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
437 INFO_PRINTF4(_L("Name %S Height %d CharWidthInPixels(W) %d"),&name,font->FontSpecInTwips().iHeight,font->CharWidthInPixels(TChar('W')));
438 buf.Format(_L8("MaxNormalCharWidth %dAscent %d"),font->MaxNormalCharWidthInPixels(),font->AscentInPixels());
441 ret=file.Write(_L8("CodeSection 0:255"));
443 for (TInt l=0; l<256; l++)
445 if (font->CharWidthInPixels(k))
447 buf.Format(_L8("%d:%d "),l,font->CharWidthInPixels(l));
453 ret=file.Write(_L8("\n"));
457 ret=file.Write(_L8("\nEndCodeSection\nEndFontInfo\n"));
459 device->ReleaseFont(font);
469 INFO_PRINTF1(_L("Create control"));
471 CPrinterPort* printerport=NULL;
472 #if defined (__WINS__)
473 if (device->Model().iRequiresPrinterPort)
475 TRAP(ret,printerport=CFilePrinterPort::NewL(_L("c:\\Printfile")));
478 if (device->Model().iRequiresPrinterPort)
480 TRAP(ret,printerport=CFilePrinterPort::NewL(_L("c:\\temp.prn")));
481 INFO_PRINTF2(_L("ret %d"),ret);
482 INFO_PRINTF2(_L("device displaymode %d"),device->DisplayMode());
487 TRAP(ret,device->CreateControlL(printerport));
488 INFO_PRINTF2(_L("CreateControlL() returns %d"), ret);
492 TRAP(ret,testPrint(device));
494 INFO_PRINTF2(_L("...testPrint() returns %d"), ret);
496 INFO_PRINTF1(_L("Delete printer driver"));
506 void CTPdr::bandTest(TBandingDirection aBandingDirection, TPtrC aName)
508 CBandedDevice* banded = NULL;
509 TInt expectedWidth=0;
510 TInt expectedheight=0;
512 TRect rect(0,0,1000,1000);
514 size.iWidth = size.iHeight = 2000;
517 if( aBandingDirection==EBandingLeftToRight || aBandingDirection==EBandingRightToLeft )
522 else if( aBandingDirection==EBandingBottomToTop || aBandingDirection==EBandingTopToBottom )
528 TRAP(ret, banded=CBandedDevice::NewL(rect,size,EColor256,aBandingDirection,0));
533 outRect = banded->BandRect();
535 TEST(outRect.Width() == expectedWidth && outRect.Height() == expectedheight);
537 INFO_PRINTF2(_L("*** BandRect call (%s) ***"), &aName[0]);
538 INFO_PRINTF3(_L("Expected results are Width=%d, Height=%d."), expectedWidth, expectedheight);
539 INFO_PRINTF3(_L("Actual results are Width=%d, Height=%d."), outRect.Width(), outRect.Height());
540 INFO_PRINTF5(_L("Tlx: %d, Tly: %d, Brx: %d, Bry: %d"), outRect.iTl.iX, outRect.iTl.iY, outRect.iBr.iX, outRect.iBr.iY);
545 void CTPdr::testPdrBandRect()
547 INFO_PRINTF1(_L("Running BandRect tests"));
550 bandTest(EBandingLeftToRight, _L("EBandingLeftToRight"));
551 bandTest(EBandingBottomToTop, _L("EBandingBottomToTop"));
552 bandTest(EBandingRightToLeft, _L("EBandingRightToLeft"));
553 bandTest(EBandingTopToBottom, _L("EBandingTopToBottom"));
556 INFO_PRINTF1(_L("BandRect tests completed"));
560 void CTPdr::RunTestCaseL(TInt aCurTestCase)
562 ((CTPdrStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
567 INFO_PRINTF1(_L("TEST CASE1 - testPdrStore"));
569 @SYMTestCaseID GRAPHICS-PDR-0001
571 ((CTPdrStep*)iStep)->SetTestStepID(_L("GRAPHICS-PDR-0001"));
577 while (iModelIndex < iNumModels);
578 INFO_PRINTF1(_L("TEST CASE1 - ended!\n"));
583 INFO_PRINTF1(_L("TEST CASE2 - testPdrBandRect"));
585 @SYMTestCaseID GRAPHICS-PDR-0002
587 ((CTPdrStep*)iStep)->SetTestStepID(_L("GRAPHICS-PDR-0002"));
589 INFO_PRINTF1(_L("TEST CASE2 - ended!\n"));
594 ((CTPdrStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
595 ((CTPdrStep*)iStep)->CloseTMSGraphicsStep();
600 ((CTPdrStep*)iStep)->RecordTestResultL();
606 __CONSTRUCT_STEP__(Pdr)
608 void CTPdrStep::TestSetupL()
611 User::LeaveIfError(RFbsSession::Connect());
614 void CTPdrStep::TestClose()
616 RFbsSession::Disconnect();