os/mm/mmlibs/mmfw/tsrc/mmfunittest/subtitlegraphic/src/subtitlegraphicteststep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/subtitlegraphic/src/subtitlegraphicteststep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,329 @@
1.4 +// Copyright (c) 2008-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 +//
1.18 +
1.19 +#include "subtitlegraphicteststep.h"
1.20 +#include "subtitlecommonutils.h"
1.21 +
1.22 +_LIT(KTestBitmap1, "c:\\mm\\mmf\\testfiles\\subtitlegraphic\\subtitletestdata.png");
1.23 +_LIT(KTestBitmap2, "c:\\mm\\mmf\\testfiles\\subtitlegraphic\\subtitletestdata2.png");
1.24 +_LIT(KTestBitmap3, "c:\\mm\\mmf\\testfiles\\subtitlegraphic\\subtitletestdata3.png");
1.25 +
1.26 +const TInt KTestBitmap1XSize(200);
1.27 +const TInt KTestBitmap1YSize(151);
1.28 +
1.29 +const TInt KTestBitmap2XSize(193);
1.30 +const TInt KTestBitmap2YSize(151);
1.31 +
1.32 +const TInt KTestBitmap3XSize(32);
1.33 +const TInt KTestBitmap3YSize(32);
1.34 +
1.35 +const TInt KSubtitleRegionXPos(0);
1.36 +const TInt KSubtitleRegionYPos(50);
1.37 +
1.38 +// Enable to draw a crosshatch over the main window.
1.39 +//#define DEBUG_MARK_WINDOW 1
1.40 +
1.41 +RSubtitleGraphicTestStep::RSubtitleGraphicTestStep(const TDesC& aStepName) :
1.42 + iCRPId(TWsGraphicId::EUninitialized)
1.43 + {
1.44 + iTestStepName = aStepName;
1.45 + }
1.46 +
1.47 +TVerdict RSubtitleGraphicTestStep::DoTestStepPreambleL()
1.48 + {
1.49 + User::LeaveIfError(iFs.Connect());
1.50 +
1.51 + // Install the Active Scheduler
1.52 + iActiveScheduler = new(ELeave) CActiveScheduler;
1.53 + CActiveScheduler::Install(iActiveScheduler);
1.54 + iActiveSchedulerStarted = EFalse;
1.55 +
1.56 + InitWservL();
1.57 +
1.58 + InitCrpL();
1.59 +
1.60 + User::LeaveIfError(RFbsSession::Connect());
1.61 +
1.62 + return EPass;
1.63 + }
1.64 +
1.65 +TVerdict RSubtitleGraphicTestStep::DoTestStepPostambleL()
1.66 + {
1.67 + RFbsSession::Disconnect();
1.68 +
1.69 + iFs.Close();
1.70 +
1.71 + // Destroy Window server objects
1.72 + DeInitWserv();
1.73 +
1.74 + DestroyBitmap1();
1.75 + DestroyBitmap2();
1.76 + DestroyBitmap3();
1.77 + DestroyCrp();
1.78 +
1.79 + CActiveScheduler::Install(NULL);
1.80 + delete iActiveScheduler;
1.81 + iActiveScheduler = NULL;
1.82 +
1.83 + return EPass;
1.84 + }
1.85 +
1.86 +void RSubtitleGraphicTestStep::InitWservL()
1.87 + {
1.88 + TInt err = iWs.Connect();
1.89 +
1.90 + if (err != KErrNone)
1.91 + {
1.92 + // Access violation if ws is null
1.93 + ERR_PRINTF1(_L("Cannot test, no window server available"));
1.94 + User::Leave(err);
1.95 + }
1.96 +
1.97 + iScreen = new (ELeave) CWsScreenDevice(iWs); // make device for this session
1.98 + User::LeaveIfError(iScreen->Construct()); // and complete its construction
1.99 +
1.100 + iRootWindow = RWindowGroup(iWs);
1.101 + User::LeaveIfError(iRootWindow.Construct((TUint32)this, ETrue));
1.102 +
1.103 + iWindow = new(ELeave) RWindow(iWs);
1.104 + User::LeaveIfError(((RWindow*)iWindow)->Construct(iRootWindow,((TUint32)(this)) + 1));
1.105 + iWindow->SetExtent(TPoint(0,0), iScreen->SizeInPixels());
1.106 + iWindow->SetVisible(ETrue);
1.107 + iWindow->SetRequiredDisplayMode(EColor16MA);
1.108 +
1.109 + // Setup transparency
1.110 + TInt errorCode = iWindow->SetTransparencyAlphaChannel();
1.111 + TRgb backgroundColour = TRgb(0, 255, 255);
1.112 + backgroundColour.SetAlpha(0);
1.113 + iWindow->SetBackgroundColor(backgroundColour);
1.114 +
1.115 + iGc=new(ELeave) CWindowGc(iScreen);
1.116 + User::LeaveIfError(iGc->Construct());
1.117 +
1.118 + iWindow->Activate();
1.119 + iWs.Flush();
1.120 + }
1.121 +
1.122 +void RSubtitleGraphicTestStep::DeInitWserv()
1.123 + {
1.124 + if (iWindow)
1.125 + {
1.126 + iWindow->Close();
1.127 + delete iWindow;
1.128 + iWindow = NULL;
1.129 + }
1.130 +
1.131 + iRootWindow.Close();
1.132 + delete iScreen;
1.133 + iScreen = NULL;
1.134 +
1.135 + delete iGc;
1.136 + iGc = NULL;
1.137 +
1.138 + iWs.Flush();
1.139 + iWs.Close();
1.140 + }
1.141 +
1.142 +TVerdict RSubtitleGraphicTestStep::StartCrpDrawL()
1.143 + {
1.144 + PrepGc();
1.145 +
1.146 + // Draw the CRP
1.147 + TPoint regionTl(KSubtitleRegionXPos,KSubtitleRegionYPos);
1.148 + TPoint regionBr(iScreen->SizeInPixels().iWidth, iScreen->SizeInPixels().iHeight);
1.149 +
1.150 + iGc->DrawWsGraphic(iCRPGraphic->Id(), TRect(regionTl, regionBr));
1.151 +
1.152 + TInt width=iScreen->SizeInPixels().iWidth;
1.153 + TInt height=iScreen->SizeInPixels().iHeight;
1.154 +
1.155 +#ifdef DEBUG_MARK_WINDOW
1.156 + // Draw a square border
1.157 + iGc->SetPenColor(TRgb(255,0,0));
1.158 + iGc->DrawLine(TPoint(0,0),TPoint(0,height-1));
1.159 + iGc->DrawLine (TPoint (0, height-1), TPoint (width-1, height-1));
1.160 + iGc->DrawLine(TPoint(width-1,height-1),TPoint(width-1,0));
1.161 + iGc->DrawLine (TPoint (width-1, 0), TPoint (0, 0));
1.162 +
1.163 + // Draw a line between the corners of the window
1.164 + iGc->DrawLine(TPoint(0,0),TPoint(width, height));
1.165 + iGc->DrawLine (TPoint (0, height), TPoint (width, 0));
1.166 +#endif
1.167 +
1.168 + // Draw a box around the display region
1.169 + iGc->SetPenColor(TRgb(255,0,0));
1.170 + iGc->DrawLine(regionTl, TPoint(width, height));
1.171 +
1.172 + iGc->DrawLine(TPoint(KSubtitleRegionXPos, height), TPoint(width, KSubtitleRegionYPos));
1.173 +
1.174 + RetireGc();
1.175 +
1.176 + return iTestStepResult;
1.177 + }
1.178 +
1.179 +//
1.180 +// CWsGraphicBase::PrepGc
1.181 +// activate a gc & clear the two rects
1.182 +//
1.183 +void RSubtitleGraphicTestStep::PrepGc()
1.184 + {
1.185 + iGc->Activate(*iWindow);
1.186 + iWindow->Invalidate();
1.187 + iWindow->BeginRedraw();
1.188 + iGc->Clear(TRect(iScreen->SizeInPixels()));
1.189 + iWs.Flush();
1.190 + }
1.191 +
1.192 +//
1.193 +// CWsGraphicBase::RetireGc
1.194 +// deactivate a gc & flush any outstanding RWindow requests
1.195 +void RSubtitleGraphicTestStep::RetireGc()
1.196 + {
1.197 + iGc->Deactivate();
1.198 + iWindow->EndRedraw();
1.199 + iWs.Flush();
1.200 + }
1.201 +
1.202 +void RSubtitleGraphicTestStep::InitCrpL()
1.203 + {
1.204 + iCRPGraphic = CMMFSubtitleGraphic::NewL();
1.205 + }
1.206 +
1.207 +void RSubtitleGraphicTestStep::DestroyCrp()
1.208 + {
1.209 + delete iCRPGraphic;
1.210 + iCRPGraphic = NULL;
1.211 + }
1.212 +
1.213 +TBool RSubtitleGraphicTestStep::CreateBitmap1L()
1.214 + {
1.215 + if ( iBitmap1 )
1.216 + {
1.217 + User::Invariant();
1.218 + }
1.219 +
1.220 + iBitmap1 = new (ELeave) CFbsBitmap();
1.221 + TSize testBitmap1Size(KTestBitmap1XSize, KTestBitmap1YSize);
1.222 +
1.223 + // Load test bitmap data
1.224 + TInt err = iBitmap1->Create(testBitmap1Size, EColor16MA);
1.225 +
1.226 + if ( err != KErrNone )
1.227 + {
1.228 + ERR_PRINTF2(_L("Failed on iBitmap1->Create(KTestBitmap1Size, EColor16MA) error code %d"), err);
1.229 + delete iBitmap1;
1.230 + iBitmap1=NULL;
1.231 + return EFalse;
1.232 + }
1.233 +
1.234 + TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap1));
1.235 +
1.236 + if ( err != KErrNone )
1.237 + {
1.238 + ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap1) error code %d"), err);
1.239 + delete iBitmap1;
1.240 + iBitmap1=NULL;
1.241 + return EFalse;
1.242 + }
1.243 +
1.244 + return ETrue;
1.245 + }
1.246 +
1.247 +TBool RSubtitleGraphicTestStep::CreateBitmap2L()
1.248 + {
1.249 + if ( iBitmap2 )
1.250 + {
1.251 + User::Invariant();
1.252 + }
1.253 +
1.254 + iBitmap2 = new (ELeave) CFbsBitmap();
1.255 + TSize testBitmap2Size(KTestBitmap2XSize, KTestBitmap2YSize);
1.256 +
1.257 + // Load test bitmap data
1.258 + TInt err = iBitmap2->Create(testBitmap2Size, EColor16MA);
1.259 +
1.260 + if ( err != KErrNone )
1.261 + {
1.262 + ERR_PRINTF2(_L("Failed on iBitmap2->Create(KTestBitmap2Size, EColor16MA) error code %d"), err);
1.263 + delete iBitmap2;
1.264 + iBitmap2=NULL;
1.265 + return EFalse;
1.266 + }
1.267 +
1.268 + TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap2, *iBitmap2));
1.269 +
1.270 + if ( err != KErrNone )
1.271 + {
1.272 + ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap2) error code %d"), err);
1.273 + delete iBitmap2;
1.274 + iBitmap2=NULL;
1.275 + return EFalse;
1.276 + }
1.277 +
1.278 + return ETrue;
1.279 + }
1.280 +
1.281 +TBool RSubtitleGraphicTestStep::CreateBitmap3L()
1.282 + {
1.283 + if ( iBitmap3 )
1.284 + {
1.285 + User::Invariant();
1.286 + }
1.287 +
1.288 + iBitmap3 = new (ELeave) CFbsBitmap();
1.289 + TSize testBitmap3Size(KTestBitmap3XSize, KTestBitmap3YSize);
1.290 +
1.291 + // Load test bitmap data
1.292 + TInt err = iBitmap3->Create(testBitmap3Size, EColor16MA);
1.293 +
1.294 + if ( err != KErrNone )
1.295 + {
1.296 + ERR_PRINTF2(_L("Failed on iBitmap3->Create(KTestBitmap3Size, EColor16MA) error code %d"), err);
1.297 + delete iBitmap3;
1.298 + iBitmap3=NULL;
1.299 + return EFalse;
1.300 + }
1.301 +
1.302 + TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap3, *iBitmap3));
1.303 +
1.304 + if ( err != KErrNone )
1.305 + {
1.306 + ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap3, *iBitmap3) error code %d"), err);
1.307 + delete iBitmap3;
1.308 + iBitmap3=NULL;
1.309 + return EFalse;
1.310 + }
1.311 +
1.312 + return ETrue;
1.313 + }
1.314 +
1.315 +void RSubtitleGraphicTestStep::DestroyBitmap1()
1.316 + {
1.317 + delete iBitmap1;
1.318 + iBitmap1 = NULL;
1.319 + }
1.320 +
1.321 +
1.322 +void RSubtitleGraphicTestStep::DestroyBitmap2()
1.323 + {
1.324 + delete iBitmap2;
1.325 + iBitmap2 = NULL;
1.326 + }
1.327 +
1.328 +void RSubtitleGraphicTestStep::DestroyBitmap3()
1.329 + {
1.330 + delete iBitmap3;
1.331 + iBitmap3 = NULL;
1.332 + }