os/mm/mmlibs/mmfw/tsrc/mmfunittest/srtdecoder/src/testsrtdecoder.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 <bautils.h> 
    17 #include <bitdev.h>
    18 #include <gulutil.h>
    19 
    20 #include "srtdecoder.h"
    21 #include "srtreader.h"
    22 #include "testsrtdecoder.h"
    23 
    24 _LIT(KSampleSubtitleSRTFilepath1, "c:\\mm\\subtitle1.srt");
    25 _LIT(KSampleSubtitleSRTFilepath2, "c:\\mm\\subtitle2.srt");
    26 
    27 // subtitlebmp0.mbm -- subtitlebmp9.mbm: bitmaps for comparison
    28 _LIT(KSubtitleTargetBitmapFilePathSpec, "c:\\mm\\subtitlebmp%d.mbm");
    29 // subtitlecurbmp0.mbm -- subtitlecurbmp9.mbm: runtime bitmaps for comparison, 
    30 // will be removed unless MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA is defined
    31 _LIT(KSubtitleCurrentBitmapFilePathSpec, "c:\\mm\\subtitlecurbmp%d.mbm");
    32 
    33 // defining MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA means re-creating the test data (bitmaps) for comparison, instead 
    34 // of doing the comparison with the existing test data 
    35 // at runtime with the spec of KSubtitleCurrentBitmapFilePathSpec  
    36 #ifndef MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA
    37 // #define MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA
    38 #endif 
    39 
    40 void RTestSrtDecoderStep::InitializeTestStepL(TBool aCreateSrtReaderOnly, const TDesC& aSrtFilePath)
    41     {
    42     __MM_HEAP_MARK;
    43     iSrtReader = CSrtReader::NewL(aSrtFilePath);
    44     
    45     iCreateSrtReaderOnly = aCreateSrtReaderOnly;
    46     if (!iCreateSrtReaderOnly)
    47         {
    48         User::LeaveIfError(iRbsSession.Connect());
    49         iSrtDecoder = CSrtSubtitleDecoder::NewL(*iSrtReader);
    50         }
    51     }
    52 	
    53 void RTestSrtDecoderStep::UnInitializeTestStep()
    54     {
    55     if (!iCreateSrtReaderOnly)
    56         {
    57         iRbsSession.Disconnect();
    58         delete iSrtDecoder;
    59         }
    60     delete iSrtReader;
    61     __MM_HEAP_MARKEND;
    62     }
    63 
    64 // Implementation of the generic test step
    65 TBool RTestSrtDecoderStep::CompareFilesL(RFs &aFs, const TDesC& aFilePath1, const TDesC& aFilePath2)
    66     {
    67     TBool identical = EFalse;
    68     RFile file1;
    69     RFile file2;
    70     TInt file1Size = 0;
    71     TInt file2Size = 0;
    72     
    73     if (aFilePath1 == aFilePath2)
    74         {
    75         identical = ETrue;
    76         }
    77     else
    78         {
    79         User::LeaveIfError(file1.Open(aFs, aFilePath1, EFileRead));
    80         CleanupClosePushL(file1);
    81         User::LeaveIfError(file2.Open(aFs, aFilePath2, EFileRead)); 
    82         CleanupClosePushL(file2);
    83         
    84         User::LeaveIfError(file1.Size(file1Size));
    85         User::LeaveIfError(file2.Size(file2Size));
    86         
    87         if (file1Size == file2Size)
    88             {
    89             TBuf8<256> buffer1;
    90             TBuf8<256> buffer2;
    91             
    92             identical = ETrue;
    93             while(ETrue)
    94                 {
    95                 User::LeaveIfError(file1.Read(buffer1));
    96                 User::LeaveIfError(file2.Read(buffer2));
    97                 
    98                 if (buffer1 != buffer2)
    99                     {
   100                     identical = EFalse;
   101                     break;
   102                     }
   103                 
   104                 if (0 == buffer1.Length())
   105                     {
   106                     break;
   107                     }
   108                 }
   109             }
   110         
   111         CleanupStack::PopAndDestroy(&file2);
   112         CleanupStack::PopAndDestroy(&file1);
   113         }
   114         
   115     return identical;     
   116     }
   117     
   118 TBool RTestSrtDecoderStep::IsFontAvailableL(const TDesC& aTypefaceName)
   119     {
   120     TBool avail = EFalse;
   121     TSize bmpSize(100, 100);
   122     
   123     CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap();
   124  	CleanupStack::PushL(sampleBitmap);
   125  	
   126  	User::LeaveIfError(sampleBitmap->Create(bmpSize, EColor16MA));
   127  	
   128     CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL(sampleBitmap);
   129     CleanupStack::PushL(bmpDevice);
   130     
   131     if (0 != FontUtils::TypefaceAttributes(*bmpDevice, aTypefaceName))
   132         {
   133         const TInt KSubtitleFontMaxSpecHeights = 128;
   134         CArrayFix<TInt> *listHeights = new (ELeave) CArrayFixFlat<TInt>(KSubtitleFontMaxSpecHeights); 
   135         CleanupStack::PushL(listHeights);
   136         
   137         FontUtils::GetAvailableHeightsInTwipsL(*bmpDevice, aTypefaceName, *listHeights);
   138         for (TInt i = 0; i < listHeights->Count(); i++) 
   139             {
   140             if (KSrtTargetTypefaceHeightInTwips == (*listHeights)[i])
   141                 {
   142                 avail = ETrue;
   143                 break;
   144                 }
   145             }
   146         
   147         CleanupStack::PopAndDestroy(listHeights);
   148         }
   149     
   150     CleanupStack::PopAndDestroy(bmpDevice);
   151     CleanupStack::PopAndDestroy(sampleBitmap);
   152     
   153     return avail; 
   154     }
   155     
   156 TBool RTestSrtDecoderStep::CompareBmpFilesL(TInt aStartIndex, TInt aEndIndex, const TDesC& aSrcFilePathSpec, const TDesC& aDestFilePathSpec)
   157     {
   158     TBool identical = ETrue;
   159     TBuf <KMaxFullName> bitmapFilename1;
   160     TBuf <KMaxFullName> bitmapFilename2;
   161     RFs rfs;
   162     User::LeaveIfError(rfs.Connect());
   163     CleanupClosePushL(rfs);
   164     for (TInt i = aStartIndex; i <= aEndIndex; i++)
   165         {
   166         bitmapFilename1.Format(aDestFilePathSpec, i);
   167         bitmapFilename2.Format(aSrcFilePathSpec, i);
   168         if (!CompareFilesL(rfs, bitmapFilename1, bitmapFilename2))
   169             {
   170             identical = EFalse;
   171             break;
   172             }
   173         }
   174     CleanupStack::PopAndDestroy(&rfs);
   175 
   176     return identical;
   177     }
   178     
   179 void RTestSrtDecoderStep::DeleteTempFiles(TInt aStartIndex, TInt aEndIndex, const TDesC& aFilePathSpec)
   180     {
   181     TBuf <KMaxFullName> bitmapFilename;
   182     RFs rfs;
   183     
   184     if (KErrNone == rfs.Connect())
   185         {
   186         for (TInt i = aStartIndex ; i <= aEndIndex; i++)
   187             {
   188             bitmapFilename.Format(aFilePathSpec, i);
   189             BaflUtils::DeleteFile(rfs, bitmapFilename);
   190             }
   191         }
   192     }    
   193     
   194     
   195 // Implementation of RTestSrtDecoderStep0002
   196 
   197 RTestSrtDecoderStep0002::RTestSrtDecoderStep0002()
   198 	{
   199 	iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0002-HP");
   200 	}
   201 
   202 TVerdict RTestSrtDecoderStep0002::DoTestStepPreambleL()
   203     {
   204     InitializeTestStepL(EFalse, KSampleSubtitleSRTFilepath1);
   205     
   206     // Install the Active Scheduler
   207     iActiveScheduler = new(ELeave) CActiveScheduler;
   208     CActiveScheduler::Install(iActiveScheduler);
   209 	iActiveSchedulerStarted = EFalse;
   210 	
   211     InitWservL();
   212     
   213     return EPass;
   214     }
   215 
   216 TVerdict RTestSrtDecoderStep0002::DoTestStepPostambleL()
   217     {
   218     UninitWserv();
   219     CActiveScheduler::Install(NULL);
   220 	delete iActiveScheduler;
   221     iActiveScheduler = NULL;
   222     
   223     UnInitializeTestStep();
   224     
   225     return EPass;
   226     }
   227 
   228 TVerdict RTestSrtDecoderStep0002::DoTestStepL()
   229 	{
   230 	INFO_PRINTF1(_L("Enter DoTestStepL"));
   231 	TVerdict result = EPass;
   232  
   233     TRAPD(err, TestGetNextFrameL());
   234     if (KErrNone != err)
   235         {
   236         result = EFail;
   237         ERR_PRINTF2(_L("Error - RTestSrtDecoderStep0002::TestGetNextFrameL failed. error code %d. "), err);
   238         }
   239    
   240     INFO_PRINTF1(_L("Exit DoTestStepL"));
   241 	return result;
   242 	}
   243 	
   244 void RTestSrtDecoderStep0002::InitWservL()
   245     {
   246     TInt err = iWs.Connect();
   247     
   248     if (err != KErrNone)
   249         {
   250         // Access violation if ws is null
   251         ERR_PRINTF2(_L("Error - Failed to connect to RWsSession. error code %d. "), err);
   252         User::Leave(err);
   253         }
   254 
   255     iScreen = new (ELeave) CWsScreenDevice(iWs); // make device for this session
   256     User::LeaveIfError(iScreen->Construct()); // and complete its construction
   257 
   258     iRootWindow = RWindowGroup(iWs);
   259     User::LeaveIfError(iRootWindow.Construct((TUint32)this, ETrue));
   260 
   261     iWindow = new(ELeave) RWindow(iWs);
   262     User::LeaveIfError(((RWindow*)iWindow)->Construct(iRootWindow,((TUint32)(this)) + 1));
   263     iWindow->SetExtent(TPoint(0,0), iScreen->SizeInPixels());
   264     iWindow->SetVisible(ETrue);
   265     iWindow->SetRequiredDisplayMode(EColor16MA);
   266 
   267     // Light Sky Blue 135-206-250
   268     TRgb backgroundColour = TRgb(135, 206, 250);
   269     iWindow->SetBackgroundColor(backgroundColour);
   270     
   271     iGc = new(ELeave) CWindowGc(iScreen);
   272 	User::LeaveIfError(iGc->Construct());
   273 	
   274     iWindow->Activate();
   275     iWs.Flush();
   276     }
   277     
   278 void RTestSrtDecoderStep0002::UninitWserv()
   279     {
   280     if (iWindow)
   281         {
   282         iWindow->Close();
   283         delete iWindow;
   284         iWindow = NULL;
   285         }
   286     
   287     iRootWindow.Close();
   288     delete iScreen;
   289     iScreen = NULL;
   290     
   291     delete iGc;
   292     iGc = NULL;
   293     
   294     iWs.Flush();
   295     iWs.Close();
   296     }
   297     
   298 void RTestSrtDecoderStep0002::PrepGc()
   299 	{
   300 	iGc->Activate(*iWindow);
   301 	iWindow->Invalidate();
   302 	iWindow->BeginRedraw();
   303 
   304 	iGc->Clear(TRect(iScreen->SizeInPixels()));
   305 	iWs.Flush();
   306 	}
   307 
   308 void RTestSrtDecoderStep0002::RetireGc()
   309 	{
   310 	iGc->Deactivate();
   311 	iWindow->EndRedraw();
   312 	iWs.Flush();
   313 	}
   314 	
   315 void RTestSrtDecoderStep0002::DrawBitmap(CFbsBitmap& aBitmap)
   316 	{	
   317 	PrepGc();
   318 	
   319     TSize size = iScreen->SizeInPixels();
   320     TInt width = size.iWidth;
   321     TInt height = size.iHeight;
   322     TPoint pos(0, 0);
   323 
   324     // Draw a square border
   325     iGc->SetPenColor(TRgb(255,0,0));
   326     iGc->DrawLine(TPoint(0,0),TPoint(0,height-1));
   327     iGc->DrawLine (TPoint (0, height-1), TPoint (width-1, height-1));
   328     iGc->DrawLine(TPoint(width-1,height-1),TPoint(width-1,0));
   329     iGc->DrawLine (TPoint (width-1, 0), TPoint (0, 0));
   330 
   331     // Draw a line between the corners of the window
   332     iGc->DrawLine(TPoint(0,0),TPoint(width, height));
   333     iGc->DrawLine (TPoint (0, height), TPoint (width, 0));
   334 	
   335 	// Draw bitmap
   336 	iGc->BitBlt(pos, &aBitmap);
   337 	
   338 	RetireGc();
   339 	}
   340 
   341 void RTestSrtDecoderStep0002::TestGetNextFrameL()
   342     {
   343     // start/stop for multiple times is also tested.
   344     const TInt64 KSrtMicroSecondsInAMilliSecond = 1000;
   345     const TInt64 KSrtMicroSecondsInASecond = KSrtMicroSecondsInAMilliSecond * 1000;
   346     const TInt64 KSrtMicroSecondsInAMinute = KSrtMicroSecondsInASecond * 60;
   347     const TInt64 KSrtMicroSecondsInAnHour = KSrtMicroSecondsInAMinute * 60;
   348     const TInt KSrtSetPosTestCount = 6;
   349     const TInt KSrtNumOfFrames = 10;
   350     
   351     TTimeIntervalMicroSeconds videoPos[KSrtSetPosTestCount] = 
   352         {
   353         0,
   354         KSrtMicroSecondsInAMinute,
   355         1 * KSrtMicroSecondsInAMinute + 2 * KSrtMicroSecondsInASecond + 1 * KSrtMicroSecondsInAMilliSecond,
   356         1 * KSrtMicroSecondsInAMinute + 6 * KSrtMicroSecondsInASecond + 20 * KSrtMicroSecondsInAMilliSecond,
   357         1 * KSrtMicroSecondsInAnHour + 1 * KSrtMicroSecondsInAMinute + 20 * KSrtMicroSecondsInASecond + 1 * KSrtMicroSecondsInAMilliSecond,
   358         2 * KSrtMicroSecondsInAnHour
   359         };
   360         
   361     TInt expectedNumOfFrames[KSrtSetPosTestCount] = 
   362         {
   363         10,
   364         8,
   365         6,
   366         6,
   367         2,
   368         0
   369         };
   370      
   371     // check if the required Font is available before do the bitmap file comparison
   372     TInt requiredFontAvailable = IsFontAvailableL(KSrtTargetTypefaceName);
   373     if (!requiredFontAvailable)
   374         {
   375 #ifdef MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA 
   376         INFO_PRINTF1(_L("Required font is not available, cannot save bitmap data. "));
   377         User::Leave(KErrGeneral);
   378 #else
   379         INFO_PRINTF1(_L("Required font is not available, no bitmap comparison. "));
   380 #endif //MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA 
   381         }
   382      
   383     for (TInt i = 0; i < KSrtSetPosTestCount; i++)
   384 		{
   385 #ifdef __WINSCW__
   386 		TBool compareBitmap = (0 == i) && requiredFontAvailable;
   387 #else
   388 		TBool compareBitmap = EFalse;
   389 #endif //__WINSCW__
   390         
   391         TestGetNextFrameByPositionsL(videoPos[i], expectedNumOfFrames[i], compareBitmap);
   392         
   393         // verify the bitmaps
   394         if (compareBitmap)
   395             {
   396 #ifndef MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA
   397             TBool compResult = CompareBmpFilesL(KSrtNumOfFrames - expectedNumOfFrames[i], KSrtNumOfFrames - 1, KSubtitleCurrentBitmapFilePathSpec, KSubtitleTargetBitmapFilePathSpec);
   398 
   399             DeleteTempFiles(KSrtNumOfFrames - expectedNumOfFrames[i], KSrtNumOfFrames - 1, KSubtitleCurrentBitmapFilePathSpec);
   400         
   401             if (!compResult)
   402                 {
   403                 INFO_PRINTF1(_L("At least one bitmap file does not match the expected one. "));
   404                 User::Leave(KErrGeneral);
   405                 }
   406 #endif //MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA 
   407             }
   408         }
   409     }
   410 
   411 void RTestSrtDecoderStep0002::TestGetNextFrameByPositionsL(const TTimeIntervalMicroSeconds& aPosition, TInt aExpectedNumOfFrames, TBool aSaveBitmap)
   412     {
   413     TRect dirtyRegion;
   414     TTimeIntervalMicroSeconds displayTime = 0;
   415     TTimeIntervalMicroSeconds displayDuration = 0;
   416     TInt64 tDisplayTime = 0;
   417     TInt64 tDisplayDuration = 0;
   418     TSize bmpSize(600, 300);
   419     TInt numOfFrames = 0;
   420  	TInt err = KErrNone;
   421  	TBuf <KMaxFullName> bitmapFilename;
   422  	
   423  	CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap();
   424  	CleanupStack::PushL(sampleBitmap);
   425 
   426     User::LeaveIfError(sampleBitmap->Create(bmpSize, EColor16MA));
   427 
   428     iSrtDecoder->SetVideoPosition(aPosition);
   429     iSrtDecoder->Start();
   430 
   431     while (KErrNone == err)
   432         {
   433         TRAP(err, iSrtDecoder->GetNextFrameL(*sampleBitmap, dirtyRegion, displayTime, displayDuration));
   434         if (KErrNone == err)
   435             {
   436             // show bitmap
   437             DrawBitmap(*sampleBitmap);
   438             
   439             // save bitmap for the possible comparison
   440             if (aSaveBitmap)
   441                 {
   442                 bitmapFilename.Format(KSubtitleCurrentBitmapFilePathSpec, numOfFrames);
   443                 User::LeaveIfError(sampleBitmap->Save(bitmapFilename));
   444                 }
   445                          
   446             if ((dirtyRegion.iTl.iX >= dirtyRegion.iBr.iX) || 
   447                 (dirtyRegion.iTl.iY >= dirtyRegion.iBr.iY))
   448                 {
   449                 INFO_PRINTF2(_L("Invalid dirty region received. (frame %d)"), numOfFrames);
   450                 User::Leave(KErrGeneral);
   451                 }
   452             
   453             tDisplayTime = displayTime.Int64()/1000;
   454             tDisplayDuration = displayDuration.Int64()/1000;
   455             INFO_PRINTF4(_L("Frame[%d]: displayTime: %dms, displayDuration: %dms."), 
   456                 numOfFrames, 
   457                 I64LOW(tDisplayTime), 
   458                 I64LOW(tDisplayDuration));
   459                 
   460             numOfFrames++;
   461             }
   462         }
   463     
   464     CleanupStack::PopAndDestroy(sampleBitmap);
   465     
   466     iSrtDecoder->Stop();
   467     
   468     if (KErrEof != err)
   469         {
   470         User::Leave(err);
   471         }
   472         
   473     if (aExpectedNumOfFrames != numOfFrames)
   474         {
   475         INFO_PRINTF2(_L("The number of frame (%d) is unexpected. "), numOfFrames);
   476         User::Leave(KErrGeneral);
   477         }
   478     }
   479     
   480     
   481 // Implementation of RTestSrtDecoderStep0101
   482 
   483 RTestSrtDecoderStep0101::RTestSrtDecoderStep0101()
   484 	{
   485 	iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0101-HP");
   486 	}
   487 
   488 TVerdict RTestSrtDecoderStep0101::DoTestStepPreambleL()
   489     {
   490     InitializeTestStepL(EFalse, KSampleSubtitleSRTFilepath2);
   491     
   492     return EPass;
   493     }
   494     
   495 TVerdict RTestSrtDecoderStep0101::DoTestStepPostambleL()
   496     {
   497     UnInitializeTestStep();
   498     
   499     return EPass;
   500     }
   501     
   502 TVerdict RTestSrtDecoderStep0101::DoTestStepL()
   503 	{
   504 	INFO_PRINTF1(_L("Enter DoTestStepL"));
   505 	TVerdict result = EPass;
   506  
   507     TRAPD(err, TestGetNextFrameL());
   508     if (KErrNone != err)
   509         {
   510         result = EFail;
   511         ERR_PRINTF2(_L("Error - RTestSrtDecoderStep0101::TestGetNextFrameL failed. error code %d. "), err);
   512         INFO_PRINTF1(_L("Exit CSrtDecoder"));
   513 	    return result;
   514         }
   515 
   516     INFO_PRINTF1(_L("Exit DoTestStepL"));
   517 	return result;
   518 	}
   519 
   520 void RTestSrtDecoderStep0101::TestGetNextFrameL()
   521     {
   522     TInt numOfValidFrame = 0;
   523     const TInt KSrtCase0101ExpectedValidFrame = 6;
   524     TRect dirtyRegion;
   525     TTimeIntervalMicroSeconds displayTime = 0;
   526     TTimeIntervalMicroSeconds displayDuration = 0;
   527     TSize bmpSize(320, 120);
   528     
   529     CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap();
   530  	CleanupStack::PushL(sampleBitmap);
   531  	
   532  	TInt err = sampleBitmap->Create(
   533 		bmpSize,
   534         EColor16MA
   535         );
   536     User::LeaveIfError(err);
   537      
   538     iSrtDecoder->SetVideoPosition(0);
   539     iSrtDecoder->Start();
   540     
   541     while (KErrNone == err)
   542         {
   543         TRAP(err, iSrtDecoder->GetNextFrameL(*sampleBitmap, dirtyRegion, displayTime, displayDuration));
   544         if (KErrNone == err)
   545             {
   546             numOfValidFrame++;
   547             }
   548         else if (KErrArgument == err)
   549             {
   550             err = KErrNone;
   551             }
   552         }
   553     
   554     CleanupStack::PopAndDestroy(sampleBitmap);
   555     
   556     iSrtDecoder->Stop();
   557     
   558     if (err != KErrEof)
   559         {
   560         User::Leave(err);
   561         }
   562         
   563     if (KSrtCase0101ExpectedValidFrame != numOfValidFrame)
   564         {
   565         INFO_PRINTF2(_L("The number of valid frame (%d) is unexpected. "), numOfValidFrame);
   566         User::Leave(KErrGeneral);
   567         }
   568     }
   569 
   570 // Implementation of RTestSrtDecoderStep0103
   571 
   572 RTestSrtDecoderStep0103::RTestSrtDecoderStep0103()
   573 	{
   574 	iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0103-HP");
   575 	}
   576 
   577 TVerdict RTestSrtDecoderStep0103::DoTestStepPreambleL()
   578     {
   579     User::LeaveIfError(RFbsSession::Connect());
   580     
   581     return EPass;
   582     }
   583     
   584 TVerdict RTestSrtDecoderStep0103::DoTestStepPostambleL()
   585     {
   586     RFbsSession::Disconnect();
   587     
   588     return EPass;
   589     }
   590      
   591 TVerdict RTestSrtDecoderStep0103::DoTestStepL()
   592 	{
   593 	INFO_PRINTF1(_L("Enter DoTestStepL"));
   594 	TVerdict result = EFail;
   595 	TSize bmpSize(120, 320);
   596 
   597     CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap();
   598  	CleanupStack::PushL(sampleBitmap);
   599  	User::LeaveIfError(sampleBitmap->Create(bmpSize, EColor16MA));
   600 	
   601     for (TInt failRate = 1; ; ++failRate)
   602         {
   603         __UHEAP_SETFAIL(RHeap::EFailNext, failRate);
   604     	__UHEAP_MARK;
   605 
   606     	TRAPD(error, TestGetNextFrameL(*sampleBitmap));
   607     	RDebug::Printf("Ending iteration %d.  Result = %d. Failures = %d", failRate, error, __UHEAP_CHECKFAILURE);
   608     	
   609         __UHEAP_MARKEND;
   610 
   611     	if ((error != KErrNone) && (error != KErrNoMemory))
   612     	    {
   613     	    ERR_PRINTF3(_L("RTestSrtDecoderStep0103: TESTS FAILED TO COMPLETE (failRate=%i) error code: %d\n"), failRate, error);
   614     		break;
   615     	    }    	
   616     	
   617         TAny* const pointer = User::Alloc(1);
   618     	User::Free(pointer);
   619     	if (!pointer)
   620     		{
   621     		result = EPass;
   622     		break;
   623     		}
   624         }
   625 
   626     __UHEAP_RESET; 
   627     
   628     CleanupStack::PopAndDestroy(sampleBitmap);
   629     
   630     INFO_PRINTF1(_L("Exit DoTestStepL"));
   631 	return result;
   632 	}
   633 	
   634 void RTestSrtDecoderStep0103::TestGetNextFrameL(CFbsBitmap& aBitmap)
   635     {
   636     TRect dirtyRegion;
   637     CSrtReader *srtReader = CSrtReader::NewL(KSampleSubtitleSRTFilepath1);
   638     CleanupStack::PushL(srtReader);
   639     
   640     CSrtSubtitleDecoder *srtDecoder = CSrtSubtitleDecoder::NewL(*srtReader);
   641     CleanupStack::PushL(srtDecoder);
   642     
   643     TInt err = KErrNone;
   644     TTimeIntervalMicroSeconds displayTime = 0;
   645     TTimeIntervalMicroSeconds displayDuration = 0;
   646  	
   647  	srtDecoder->SetVideoPosition(0);
   648     srtDecoder->Start();
   649     
   650     while (KErrNone == err)
   651         {
   652         TRAP(err, srtDecoder->GetNextFrameL(aBitmap, dirtyRegion, displayTime, displayDuration));
   653         }
   654 
   655     if (err != KErrEof)
   656         {
   657         User::LeaveIfError(err);
   658         }
   659     
   660     srtDecoder->Stop();
   661     
   662     CleanupStack::PopAndDestroy(srtDecoder);
   663     CleanupStack::PopAndDestroy(srtReader);
   664     }
   665     
   666 RTestSrtDecoderStep0105::RTestSrtDecoderStep0105()
   667 	{
   668 	iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0105-HP");
   669 	}
   670 
   671 TVerdict RTestSrtDecoderStep0105::DoTestStepL()
   672 	{
   673 	iSrtDecoder->Start();
   674 	iSrtDecoder->Start();
   675 	
   676 	ERR_PRINTF1(_L("Panic expected, so failing"));
   677 	return EFail;
   678 	}
   679 
   680 TVerdict RTestSrtDecoderStep0105::DoTestStepPreambleL()
   681 	{
   682 	InitializeTestStepL(EFalse, KSampleSubtitleSRTFilepath1);
   683 	return EPass;
   684 	}
   685 
   686 TVerdict RTestSrtDecoderStep0105::DoTestStepPostambleL()
   687 	{
   688 	UnInitializeTestStep();
   689 	return EPass;
   690 	}