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