os/mm/mmlibs/mmfw/tsrc/mmfunittest/subtitlegraphic/src/subtitlegraphicteststep.cpp
Update contrib.
1 // Copyright (c) 2008-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.
16 #include "subtitlegraphicteststep.h"
17 #include "subtitlecommonutils.h"
19 _LIT(KTestBitmap1, "c:\\mm\\mmf\\testfiles\\subtitlegraphic\\subtitletestdata.png");
20 _LIT(KTestBitmap2, "c:\\mm\\mmf\\testfiles\\subtitlegraphic\\subtitletestdata2.png");
21 _LIT(KTestBitmap3, "c:\\mm\\mmf\\testfiles\\subtitlegraphic\\subtitletestdata3.png");
23 const TInt KTestBitmap1XSize(200);
24 const TInt KTestBitmap1YSize(151);
26 const TInt KTestBitmap2XSize(193);
27 const TInt KTestBitmap2YSize(151);
29 const TInt KTestBitmap3XSize(32);
30 const TInt KTestBitmap3YSize(32);
32 const TInt KSubtitleRegionXPos(0);
33 const TInt KSubtitleRegionYPos(50);
35 // Enable to draw a crosshatch over the main window.
36 //#define DEBUG_MARK_WINDOW 1
38 RSubtitleGraphicTestStep::RSubtitleGraphicTestStep(const TDesC& aStepName) :
39 iCRPId(TWsGraphicId::EUninitialized)
41 iTestStepName = aStepName;
44 TVerdict RSubtitleGraphicTestStep::DoTestStepPreambleL()
46 User::LeaveIfError(iFs.Connect());
48 // Install the Active Scheduler
49 iActiveScheduler = new(ELeave) CActiveScheduler;
50 CActiveScheduler::Install(iActiveScheduler);
51 iActiveSchedulerStarted = EFalse;
57 User::LeaveIfError(RFbsSession::Connect());
62 TVerdict RSubtitleGraphicTestStep::DoTestStepPostambleL()
64 RFbsSession::Disconnect();
68 // Destroy Window server objects
76 CActiveScheduler::Install(NULL);
77 delete iActiveScheduler;
78 iActiveScheduler = NULL;
83 void RSubtitleGraphicTestStep::InitWservL()
85 TInt err = iWs.Connect();
89 // Access violation if ws is null
90 ERR_PRINTF1(_L("Cannot test, no window server available"));
94 iScreen = new (ELeave) CWsScreenDevice(iWs); // make device for this session
95 User::LeaveIfError(iScreen->Construct()); // and complete its construction
97 iRootWindow = RWindowGroup(iWs);
98 User::LeaveIfError(iRootWindow.Construct((TUint32)this, ETrue));
100 iWindow = new(ELeave) RWindow(iWs);
101 User::LeaveIfError(((RWindow*)iWindow)->Construct(iRootWindow,((TUint32)(this)) + 1));
102 iWindow->SetExtent(TPoint(0,0), iScreen->SizeInPixels());
103 iWindow->SetVisible(ETrue);
104 iWindow->SetRequiredDisplayMode(EColor16MA);
106 // Setup transparency
107 TInt errorCode = iWindow->SetTransparencyAlphaChannel();
108 TRgb backgroundColour = TRgb(0, 255, 255);
109 backgroundColour.SetAlpha(0);
110 iWindow->SetBackgroundColor(backgroundColour);
112 iGc=new(ELeave) CWindowGc(iScreen);
113 User::LeaveIfError(iGc->Construct());
119 void RSubtitleGraphicTestStep::DeInitWserv()
139 TVerdict RSubtitleGraphicTestStep::StartCrpDrawL()
144 TPoint regionTl(KSubtitleRegionXPos,KSubtitleRegionYPos);
145 TPoint regionBr(iScreen->SizeInPixels().iWidth, iScreen->SizeInPixels().iHeight);
147 iGc->DrawWsGraphic(iCRPGraphic->Id(), TRect(regionTl, regionBr));
149 TInt width=iScreen->SizeInPixels().iWidth;
150 TInt height=iScreen->SizeInPixels().iHeight;
152 #ifdef DEBUG_MARK_WINDOW
153 // Draw a square border
154 iGc->SetPenColor(TRgb(255,0,0));
155 iGc->DrawLine(TPoint(0,0),TPoint(0,height-1));
156 iGc->DrawLine (TPoint (0, height-1), TPoint (width-1, height-1));
157 iGc->DrawLine(TPoint(width-1,height-1),TPoint(width-1,0));
158 iGc->DrawLine (TPoint (width-1, 0), TPoint (0, 0));
160 // Draw a line between the corners of the window
161 iGc->DrawLine(TPoint(0,0),TPoint(width, height));
162 iGc->DrawLine (TPoint (0, height), TPoint (width, 0));
165 // Draw a box around the display region
166 iGc->SetPenColor(TRgb(255,0,0));
167 iGc->DrawLine(regionTl, TPoint(width, height));
169 iGc->DrawLine(TPoint(KSubtitleRegionXPos, height), TPoint(width, KSubtitleRegionYPos));
173 return iTestStepResult;
177 // CWsGraphicBase::PrepGc
178 // activate a gc & clear the two rects
180 void RSubtitleGraphicTestStep::PrepGc()
182 iGc->Activate(*iWindow);
183 iWindow->Invalidate();
184 iWindow->BeginRedraw();
185 iGc->Clear(TRect(iScreen->SizeInPixels()));
190 // CWsGraphicBase::RetireGc
191 // deactivate a gc & flush any outstanding RWindow requests
192 void RSubtitleGraphicTestStep::RetireGc()
195 iWindow->EndRedraw();
199 void RSubtitleGraphicTestStep::InitCrpL()
201 iCRPGraphic = CMMFSubtitleGraphic::NewL();
204 void RSubtitleGraphicTestStep::DestroyCrp()
210 TBool RSubtitleGraphicTestStep::CreateBitmap1L()
217 iBitmap1 = new (ELeave) CFbsBitmap();
218 TSize testBitmap1Size(KTestBitmap1XSize, KTestBitmap1YSize);
220 // Load test bitmap data
221 TInt err = iBitmap1->Create(testBitmap1Size, EColor16MA);
223 if ( err != KErrNone )
225 ERR_PRINTF2(_L("Failed on iBitmap1->Create(KTestBitmap1Size, EColor16MA) error code %d"), err);
231 TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap1));
233 if ( err != KErrNone )
235 ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap1) error code %d"), err);
244 TBool RSubtitleGraphicTestStep::CreateBitmap2L()
251 iBitmap2 = new (ELeave) CFbsBitmap();
252 TSize testBitmap2Size(KTestBitmap2XSize, KTestBitmap2YSize);
254 // Load test bitmap data
255 TInt err = iBitmap2->Create(testBitmap2Size, EColor16MA);
257 if ( err != KErrNone )
259 ERR_PRINTF2(_L("Failed on iBitmap2->Create(KTestBitmap2Size, EColor16MA) error code %d"), err);
265 TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap2, *iBitmap2));
267 if ( err != KErrNone )
269 ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap2) error code %d"), err);
278 TBool RSubtitleGraphicTestStep::CreateBitmap3L()
285 iBitmap3 = new (ELeave) CFbsBitmap();
286 TSize testBitmap3Size(KTestBitmap3XSize, KTestBitmap3YSize);
288 // Load test bitmap data
289 TInt err = iBitmap3->Create(testBitmap3Size, EColor16MA);
291 if ( err != KErrNone )
293 ERR_PRINTF2(_L("Failed on iBitmap3->Create(KTestBitmap3Size, EColor16MA) error code %d"), err);
299 TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap3, *iBitmap3));
301 if ( err != KErrNone )
303 ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap3, *iBitmap3) error code %d"), err);
312 void RSubtitleGraphicTestStep::DestroyBitmap1()
319 void RSubtitleGraphicTestStep::DestroyBitmap2()
325 void RSubtitleGraphicTestStep::DestroyBitmap3()