os/mm/mmlibs/mmfw/tsrc/mmfunittest/subtitlegraphic/src/subtitlegraphicteststep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "subtitlegraphicteststep.h"
    17 #include "subtitlecommonutils.h"
    18 
    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");
    22          
    23 const TInt KTestBitmap1XSize(200);
    24 const TInt KTestBitmap1YSize(151);
    25 
    26 const TInt KTestBitmap2XSize(193);
    27 const TInt KTestBitmap2YSize(151);
    28 
    29 const TInt KTestBitmap3XSize(32);
    30 const TInt KTestBitmap3YSize(32);
    31 
    32 const TInt KSubtitleRegionXPos(0);
    33 const TInt KSubtitleRegionYPos(50);
    34 
    35 // Enable to draw a crosshatch over the main window.
    36 //#define DEBUG_MARK_WINDOW 1
    37 
    38 RSubtitleGraphicTestStep::RSubtitleGraphicTestStep(const TDesC& aStepName) :
    39 	iCRPId(TWsGraphicId::EUninitialized)
    40 	{
    41 	iTestStepName = aStepName;
    42 	}
    43 
    44 TVerdict RSubtitleGraphicTestStep::DoTestStepPreambleL()
    45 	{
    46 	User::LeaveIfError(iFs.Connect());
    47 	
    48     // Install the Active Scheduler
    49     iActiveScheduler = new(ELeave) CActiveScheduler;
    50     CActiveScheduler::Install(iActiveScheduler);
    51 	iActiveSchedulerStarted = EFalse;
    52 	
    53 	InitWservL();
    54 	
    55 	InitCrpL();
    56 
    57 	User::LeaveIfError(RFbsSession::Connect());
    58 	
    59     return EPass;
    60 	}
    61 
    62 TVerdict RSubtitleGraphicTestStep::DoTestStepPostambleL()
    63 	{
    64 	RFbsSession::Disconnect();
    65 	
    66 	iFs.Close(); 
    67 	
    68     // Destroy Window server objects
    69     DeInitWserv();
    70     
    71     DestroyBitmap1();
    72 	DestroyBitmap2();
    73 	DestroyBitmap3();
    74 	DestroyCrp();
    75 	
    76 	CActiveScheduler::Install(NULL);
    77 	delete iActiveScheduler;
    78     iActiveScheduler = NULL;
    79     
    80     return EPass;
    81 	}
    82 
    83 void RSubtitleGraphicTestStep::InitWservL()
    84     {
    85     TInt err = iWs.Connect();
    86     
    87     if (err != KErrNone)
    88         {
    89         // Access violation if ws is null
    90         ERR_PRINTF1(_L("Cannot test, no window server available"));
    91         User::Leave(err);
    92         }
    93 
    94     iScreen = new (ELeave) CWsScreenDevice(iWs); // make device for this session
    95     User::LeaveIfError(iScreen->Construct()); // and complete its construction
    96 
    97     iRootWindow = RWindowGroup(iWs);
    98     User::LeaveIfError(iRootWindow.Construct((TUint32)this, ETrue));
    99 
   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);
   105 
   106 	// Setup transparency
   107     TInt errorCode = iWindow->SetTransparencyAlphaChannel();
   108     TRgb backgroundColour = TRgb(0, 255, 255);
   109     backgroundColour.SetAlpha(0);
   110     iWindow->SetBackgroundColor(backgroundColour);
   111     
   112     iGc=new(ELeave) CWindowGc(iScreen);
   113 	User::LeaveIfError(iGc->Construct());
   114 	
   115     iWindow->Activate();
   116     iWs.Flush();
   117     }
   118 
   119 void RSubtitleGraphicTestStep::DeInitWserv()
   120     {
   121     if (iWindow)
   122         {
   123         iWindow->Close();
   124         delete iWindow;
   125         iWindow = NULL;
   126         }
   127     
   128     iRootWindow.Close();
   129     delete iScreen;
   130     iScreen = NULL;
   131     
   132     delete iGc;
   133     iGc = NULL;
   134     
   135     iWs.Flush();
   136     iWs.Close();
   137     }
   138 
   139 TVerdict RSubtitleGraphicTestStep::StartCrpDrawL()
   140 	{	
   141 	PrepGc();
   142 	
   143 	// Draw the CRP
   144 	TPoint regionTl(KSubtitleRegionXPos,KSubtitleRegionYPos);
   145     TPoint regionBr(iScreen->SizeInPixels().iWidth, iScreen->SizeInPixels().iHeight);
   146     
   147     iGc->DrawWsGraphic(iCRPGraphic->Id(), TRect(regionTl, regionBr));
   148            
   149     TInt width=iScreen->SizeInPixels().iWidth;
   150     TInt height=iScreen->SizeInPixels().iHeight;
   151 
   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));
   159 
   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));
   163 #endif
   164     
   165     // Draw a box around the display region
   166     iGc->SetPenColor(TRgb(255,0,0));
   167     iGc->DrawLine(regionTl, TPoint(width, height));
   168     
   169     iGc->DrawLine(TPoint(KSubtitleRegionXPos, height), TPoint(width, KSubtitleRegionYPos));
   170 	
   171 	RetireGc();
   172 
   173     return iTestStepResult;
   174 	}
   175 
   176 //
   177 // CWsGraphicBase::PrepGc
   178 // activate a gc & clear the two rects
   179 //
   180 void RSubtitleGraphicTestStep::PrepGc()
   181 	{
   182 	iGc->Activate(*iWindow);
   183 	iWindow->Invalidate();
   184 	iWindow->BeginRedraw();
   185 	iGc->Clear(TRect(iScreen->SizeInPixels()));
   186 	iWs.Flush();
   187 	}
   188 
   189 //
   190 // CWsGraphicBase::RetireGc
   191 // deactivate a gc & flush any outstanding RWindow requests
   192 void RSubtitleGraphicTestStep::RetireGc()
   193 	{
   194 	iGc->Deactivate();
   195 	iWindow->EndRedraw();
   196 	iWs.Flush();
   197 	}
   198 
   199 void RSubtitleGraphicTestStep::InitCrpL()
   200 	{
   201 	iCRPGraphic = CMMFSubtitleGraphic::NewL();
   202 	}
   203 
   204 void RSubtitleGraphicTestStep::DestroyCrp()
   205 	{
   206 	delete iCRPGraphic;
   207 	iCRPGraphic = NULL;
   208 	}
   209 
   210 TBool RSubtitleGraphicTestStep::CreateBitmap1L()
   211 	{
   212 	if ( iBitmap1 )
   213 		{
   214 		User::Invariant();
   215 		}
   216 		
   217 	iBitmap1 = new (ELeave) CFbsBitmap();
   218 	TSize testBitmap1Size(KTestBitmap1XSize, KTestBitmap1YSize);
   219 	
   220 	// Load test bitmap data
   221 	TInt err = iBitmap1->Create(testBitmap1Size, EColor16MA);
   222 	
   223 	if ( err != KErrNone )
   224 		{
   225 		ERR_PRINTF2(_L("Failed on iBitmap1->Create(KTestBitmap1Size, EColor16MA) error code %d"), err);
   226 		delete iBitmap1;
   227 		iBitmap1=NULL;
   228 		return EFalse;
   229 		}
   230 		
   231 	TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap1));
   232 	
   233 	if ( err != KErrNone )
   234 		{
   235 		ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap1) error code %d"), err);
   236 		delete iBitmap1;
   237 		iBitmap1=NULL;
   238 		return EFalse;
   239 		}
   240 		
   241 	return ETrue;
   242 	}
   243 
   244 TBool RSubtitleGraphicTestStep::CreateBitmap2L()
   245 	{
   246 	if ( iBitmap2 )
   247 		{
   248 		User::Invariant();
   249 		}
   250 	
   251 	iBitmap2 = new (ELeave) CFbsBitmap();
   252 	TSize testBitmap2Size(KTestBitmap2XSize, KTestBitmap2YSize);
   253 	
   254 	// Load test bitmap data
   255 	TInt err = iBitmap2->Create(testBitmap2Size, EColor16MA);
   256 	
   257 	if ( err != KErrNone )
   258 		{
   259 		ERR_PRINTF2(_L("Failed on iBitmap2->Create(KTestBitmap2Size, EColor16MA) error code %d"), err);
   260 		delete iBitmap2;
   261 		iBitmap2=NULL;
   262 		return EFalse;
   263 		}
   264 		
   265 	TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap2, *iBitmap2));
   266 	
   267 	if ( err != KErrNone )
   268 		{
   269 		ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap2) error code %d"), err);
   270 		delete iBitmap2;
   271 		iBitmap2=NULL;
   272 		return EFalse;
   273 		}
   274 	
   275 	return ETrue;
   276 	}
   277 	
   278 TBool RSubtitleGraphicTestStep::CreateBitmap3L()
   279 	{
   280 	if ( iBitmap3 )
   281 		{
   282 		User::Invariant();
   283 		}
   284 	
   285 	iBitmap3 = new (ELeave) CFbsBitmap();
   286 	TSize testBitmap3Size(KTestBitmap3XSize, KTestBitmap3YSize);
   287 	
   288 	// Load test bitmap data
   289 	TInt err = iBitmap3->Create(testBitmap3Size, EColor16MA);
   290 	
   291 	if ( err != KErrNone )
   292 		{
   293 		ERR_PRINTF2(_L("Failed on iBitmap3->Create(KTestBitmap3Size, EColor16MA) error code %d"), err);
   294 		delete iBitmap3;
   295 		iBitmap3=NULL;
   296 		return EFalse;
   297 		}
   298 		
   299 	TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap3, *iBitmap3));
   300 	
   301 	if ( err != KErrNone )
   302 		{
   303 		ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap3, *iBitmap3) error code %d"), err);
   304 		delete iBitmap3;
   305 		iBitmap3=NULL;
   306 		return EFalse;
   307 		}
   308 	
   309 	return ETrue;
   310 	}
   311 	
   312 void RSubtitleGraphicTestStep::DestroyBitmap1()
   313 	{
   314 	delete iBitmap1;
   315 	iBitmap1 = NULL;
   316 	}
   317 
   318 
   319 void RSubtitleGraphicTestStep::DestroyBitmap2()
   320 	{
   321 	delete iBitmap2;
   322 	iBitmap2 = NULL;
   323 	}
   324 	
   325 void RSubtitleGraphicTestStep::DestroyBitmap3()
   326 	{
   327 	delete iBitmap3;
   328 	iBitmap3 = NULL;
   329 	}