sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "srtdecoder.h" sl@0: #include "srtreader.h" sl@0: #include "testsrtdecoder.h" sl@0: sl@0: _LIT(KSampleSubtitleSRTFilepath1, "c:\\mm\\subtitle1.srt"); sl@0: _LIT(KSampleSubtitleSRTFilepath2, "c:\\mm\\subtitle2.srt"); sl@0: sl@0: // subtitlebmp0.mbm -- subtitlebmp9.mbm: bitmaps for comparison sl@0: _LIT(KSubtitleTargetBitmapFilePathSpec, "c:\\mm\\subtitlebmp%d.mbm"); sl@0: // subtitlecurbmp0.mbm -- subtitlecurbmp9.mbm: runtime bitmaps for comparison, sl@0: // will be removed unless MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA is defined sl@0: _LIT(KSubtitleCurrentBitmapFilePathSpec, "c:\\mm\\subtitlecurbmp%d.mbm"); sl@0: sl@0: // defining MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA means re-creating the test data (bitmaps) for comparison, instead sl@0: // of doing the comparison with the existing test data sl@0: // at runtime with the spec of KSubtitleCurrentBitmapFilePathSpec sl@0: #ifndef MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA sl@0: // #define MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA sl@0: #endif sl@0: sl@0: void RTestSrtDecoderStep::InitializeTestStepL(TBool aCreateSrtReaderOnly, const TDesC& aSrtFilePath) sl@0: { sl@0: __MM_HEAP_MARK; sl@0: iSrtReader = CSrtReader::NewL(aSrtFilePath); sl@0: sl@0: iCreateSrtReaderOnly = aCreateSrtReaderOnly; sl@0: if (!iCreateSrtReaderOnly) sl@0: { sl@0: User::LeaveIfError(iRbsSession.Connect()); sl@0: iSrtDecoder = CSrtSubtitleDecoder::NewL(*iSrtReader); sl@0: } sl@0: } sl@0: sl@0: void RTestSrtDecoderStep::UnInitializeTestStep() sl@0: { sl@0: if (!iCreateSrtReaderOnly) sl@0: { sl@0: iRbsSession.Disconnect(); sl@0: delete iSrtDecoder; sl@0: } sl@0: delete iSrtReader; sl@0: __MM_HEAP_MARKEND; sl@0: } sl@0: sl@0: // Implementation of the generic test step sl@0: TBool RTestSrtDecoderStep::CompareFilesL(RFs &aFs, const TDesC& aFilePath1, const TDesC& aFilePath2) sl@0: { sl@0: TBool identical = EFalse; sl@0: RFile file1; sl@0: RFile file2; sl@0: TInt file1Size = 0; sl@0: TInt file2Size = 0; sl@0: sl@0: if (aFilePath1 == aFilePath2) sl@0: { sl@0: identical = ETrue; sl@0: } sl@0: else sl@0: { sl@0: User::LeaveIfError(file1.Open(aFs, aFilePath1, EFileRead)); sl@0: CleanupClosePushL(file1); sl@0: User::LeaveIfError(file2.Open(aFs, aFilePath2, EFileRead)); sl@0: CleanupClosePushL(file2); sl@0: sl@0: User::LeaveIfError(file1.Size(file1Size)); sl@0: User::LeaveIfError(file2.Size(file2Size)); sl@0: sl@0: if (file1Size == file2Size) sl@0: { sl@0: TBuf8<256> buffer1; sl@0: TBuf8<256> buffer2; sl@0: sl@0: identical = ETrue; sl@0: while(ETrue) sl@0: { sl@0: User::LeaveIfError(file1.Read(buffer1)); sl@0: User::LeaveIfError(file2.Read(buffer2)); sl@0: sl@0: if (buffer1 != buffer2) sl@0: { sl@0: identical = EFalse; sl@0: break; sl@0: } sl@0: sl@0: if (0 == buffer1.Length()) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(&file2); sl@0: CleanupStack::PopAndDestroy(&file1); sl@0: } sl@0: sl@0: return identical; sl@0: } sl@0: sl@0: TBool RTestSrtDecoderStep::IsFontAvailableL(const TDesC& aTypefaceName) sl@0: { sl@0: TBool avail = EFalse; sl@0: TSize bmpSize(100, 100); sl@0: sl@0: CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap(); sl@0: CleanupStack::PushL(sampleBitmap); sl@0: sl@0: User::LeaveIfError(sampleBitmap->Create(bmpSize, EColor16MA)); sl@0: sl@0: CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL(sampleBitmap); sl@0: CleanupStack::PushL(bmpDevice); sl@0: sl@0: if (0 != FontUtils::TypefaceAttributes(*bmpDevice, aTypefaceName)) sl@0: { sl@0: const TInt KSubtitleFontMaxSpecHeights = 128; sl@0: CArrayFix *listHeights = new (ELeave) CArrayFixFlat(KSubtitleFontMaxSpecHeights); sl@0: CleanupStack::PushL(listHeights); sl@0: sl@0: FontUtils::GetAvailableHeightsInTwipsL(*bmpDevice, aTypefaceName, *listHeights); sl@0: for (TInt i = 0; i < listHeights->Count(); i++) sl@0: { sl@0: if (KSrtTargetTypefaceHeightInTwips == (*listHeights)[i]) sl@0: { sl@0: avail = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(listHeights); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(bmpDevice); sl@0: CleanupStack::PopAndDestroy(sampleBitmap); sl@0: sl@0: return avail; sl@0: } sl@0: sl@0: TBool RTestSrtDecoderStep::CompareBmpFilesL(TInt aStartIndex, TInt aEndIndex, const TDesC& aSrcFilePathSpec, const TDesC& aDestFilePathSpec) sl@0: { sl@0: TBool identical = ETrue; sl@0: TBuf bitmapFilename1; sl@0: TBuf bitmapFilename2; sl@0: RFs rfs; sl@0: User::LeaveIfError(rfs.Connect()); sl@0: CleanupClosePushL(rfs); sl@0: for (TInt i = aStartIndex; i <= aEndIndex; i++) sl@0: { sl@0: bitmapFilename1.Format(aDestFilePathSpec, i); sl@0: bitmapFilename2.Format(aSrcFilePathSpec, i); sl@0: if (!CompareFilesL(rfs, bitmapFilename1, bitmapFilename2)) sl@0: { sl@0: identical = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(&rfs); sl@0: sl@0: return identical; sl@0: } sl@0: sl@0: void RTestSrtDecoderStep::DeleteTempFiles(TInt aStartIndex, TInt aEndIndex, const TDesC& aFilePathSpec) sl@0: { sl@0: TBuf bitmapFilename; sl@0: RFs rfs; sl@0: sl@0: if (KErrNone == rfs.Connect()) sl@0: { sl@0: for (TInt i = aStartIndex ; i <= aEndIndex; i++) sl@0: { sl@0: bitmapFilename.Format(aFilePathSpec, i); sl@0: BaflUtils::DeleteFile(rfs, bitmapFilename); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: // Implementation of RTestSrtDecoderStep0002 sl@0: sl@0: RTestSrtDecoderStep0002::RTestSrtDecoderStep0002() sl@0: { sl@0: iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0002-HP"); sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0002::DoTestStepPreambleL() sl@0: { sl@0: InitializeTestStepL(EFalse, KSampleSubtitleSRTFilepath1); sl@0: sl@0: // Install the Active Scheduler sl@0: iActiveScheduler = new(ELeave) CActiveScheduler; sl@0: CActiveScheduler::Install(iActiveScheduler); sl@0: iActiveSchedulerStarted = EFalse; sl@0: sl@0: InitWservL(); sl@0: sl@0: return EPass; sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0002::DoTestStepPostambleL() sl@0: { sl@0: UninitWserv(); sl@0: CActiveScheduler::Install(NULL); sl@0: delete iActiveScheduler; sl@0: iActiveScheduler = NULL; sl@0: sl@0: UnInitializeTestStep(); sl@0: sl@0: return EPass; sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0002::DoTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("Enter DoTestStepL")); sl@0: TVerdict result = EPass; sl@0: sl@0: TRAPD(err, TestGetNextFrameL()); sl@0: if (KErrNone != err) sl@0: { sl@0: result = EFail; sl@0: ERR_PRINTF2(_L("Error - RTestSrtDecoderStep0002::TestGetNextFrameL failed. error code %d. "), err); sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("Exit DoTestStepL")); sl@0: return result; sl@0: } sl@0: sl@0: void RTestSrtDecoderStep0002::InitWservL() sl@0: { sl@0: TInt err = iWs.Connect(); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: // Access violation if ws is null sl@0: ERR_PRINTF2(_L("Error - Failed to connect to RWsSession. error code %d. "), err); sl@0: User::Leave(err); sl@0: } sl@0: sl@0: iScreen = new (ELeave) CWsScreenDevice(iWs); // make device for this session sl@0: User::LeaveIfError(iScreen->Construct()); // and complete its construction sl@0: sl@0: iRootWindow = RWindowGroup(iWs); sl@0: User::LeaveIfError(iRootWindow.Construct((TUint32)this, ETrue)); sl@0: sl@0: iWindow = new(ELeave) RWindow(iWs); sl@0: User::LeaveIfError(((RWindow*)iWindow)->Construct(iRootWindow,((TUint32)(this)) + 1)); sl@0: iWindow->SetExtent(TPoint(0,0), iScreen->SizeInPixels()); sl@0: iWindow->SetVisible(ETrue); sl@0: iWindow->SetRequiredDisplayMode(EColor16MA); sl@0: sl@0: // Light Sky Blue 135-206-250 sl@0: TRgb backgroundColour = TRgb(135, 206, 250); sl@0: iWindow->SetBackgroundColor(backgroundColour); sl@0: sl@0: iGc = new(ELeave) CWindowGc(iScreen); sl@0: User::LeaveIfError(iGc->Construct()); sl@0: sl@0: iWindow->Activate(); sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: void RTestSrtDecoderStep0002::UninitWserv() sl@0: { sl@0: if (iWindow) sl@0: { sl@0: iWindow->Close(); sl@0: delete iWindow; sl@0: iWindow = NULL; sl@0: } sl@0: sl@0: iRootWindow.Close(); sl@0: delete iScreen; sl@0: iScreen = NULL; sl@0: sl@0: delete iGc; sl@0: iGc = NULL; sl@0: sl@0: iWs.Flush(); sl@0: iWs.Close(); sl@0: } sl@0: sl@0: void RTestSrtDecoderStep0002::PrepGc() sl@0: { sl@0: iGc->Activate(*iWindow); sl@0: iWindow->Invalidate(); sl@0: iWindow->BeginRedraw(); sl@0: sl@0: iGc->Clear(TRect(iScreen->SizeInPixels())); sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: void RTestSrtDecoderStep0002::RetireGc() sl@0: { sl@0: iGc->Deactivate(); sl@0: iWindow->EndRedraw(); sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: void RTestSrtDecoderStep0002::DrawBitmap(CFbsBitmap& aBitmap) sl@0: { sl@0: PrepGc(); sl@0: sl@0: TSize size = iScreen->SizeInPixels(); sl@0: TInt width = size.iWidth; sl@0: TInt height = size.iHeight; sl@0: TPoint pos(0, 0); sl@0: sl@0: // Draw a square border sl@0: iGc->SetPenColor(TRgb(255,0,0)); sl@0: iGc->DrawLine(TPoint(0,0),TPoint(0,height-1)); sl@0: iGc->DrawLine (TPoint (0, height-1), TPoint (width-1, height-1)); sl@0: iGc->DrawLine(TPoint(width-1,height-1),TPoint(width-1,0)); sl@0: iGc->DrawLine (TPoint (width-1, 0), TPoint (0, 0)); sl@0: sl@0: // Draw a line between the corners of the window sl@0: iGc->DrawLine(TPoint(0,0),TPoint(width, height)); sl@0: iGc->DrawLine (TPoint (0, height), TPoint (width, 0)); sl@0: sl@0: // Draw bitmap sl@0: iGc->BitBlt(pos, &aBitmap); sl@0: sl@0: RetireGc(); sl@0: } sl@0: sl@0: void RTestSrtDecoderStep0002::TestGetNextFrameL() sl@0: { sl@0: // start/stop for multiple times is also tested. sl@0: const TInt64 KSrtMicroSecondsInAMilliSecond = 1000; sl@0: const TInt64 KSrtMicroSecondsInASecond = KSrtMicroSecondsInAMilliSecond * 1000; sl@0: const TInt64 KSrtMicroSecondsInAMinute = KSrtMicroSecondsInASecond * 60; sl@0: const TInt64 KSrtMicroSecondsInAnHour = KSrtMicroSecondsInAMinute * 60; sl@0: const TInt KSrtSetPosTestCount = 6; sl@0: const TInt KSrtNumOfFrames = 10; sl@0: sl@0: TTimeIntervalMicroSeconds videoPos[KSrtSetPosTestCount] = sl@0: { sl@0: 0, sl@0: KSrtMicroSecondsInAMinute, sl@0: 1 * KSrtMicroSecondsInAMinute + 2 * KSrtMicroSecondsInASecond + 1 * KSrtMicroSecondsInAMilliSecond, sl@0: 1 * KSrtMicroSecondsInAMinute + 6 * KSrtMicroSecondsInASecond + 20 * KSrtMicroSecondsInAMilliSecond, sl@0: 1 * KSrtMicroSecondsInAnHour + 1 * KSrtMicroSecondsInAMinute + 20 * KSrtMicroSecondsInASecond + 1 * KSrtMicroSecondsInAMilliSecond, sl@0: 2 * KSrtMicroSecondsInAnHour sl@0: }; sl@0: sl@0: TInt expectedNumOfFrames[KSrtSetPosTestCount] = sl@0: { sl@0: 10, sl@0: 8, sl@0: 6, sl@0: 6, sl@0: 2, sl@0: 0 sl@0: }; sl@0: sl@0: // check if the required Font is available before do the bitmap file comparison sl@0: TInt requiredFontAvailable = IsFontAvailableL(KSrtTargetTypefaceName); sl@0: if (!requiredFontAvailable) sl@0: { sl@0: #ifdef MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA sl@0: INFO_PRINTF1(_L("Required font is not available, cannot save bitmap data. ")); sl@0: User::Leave(KErrGeneral); sl@0: #else sl@0: INFO_PRINTF1(_L("Required font is not available, no bitmap comparison. ")); sl@0: #endif //MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA sl@0: } sl@0: sl@0: for (TInt i = 0; i < KSrtSetPosTestCount; i++) sl@0: { sl@0: #ifdef __WINSCW__ sl@0: TBool compareBitmap = (0 == i) && requiredFontAvailable; sl@0: #else sl@0: TBool compareBitmap = EFalse; sl@0: #endif //__WINSCW__ sl@0: sl@0: TestGetNextFrameByPositionsL(videoPos[i], expectedNumOfFrames[i], compareBitmap); sl@0: sl@0: // verify the bitmaps sl@0: if (compareBitmap) sl@0: { sl@0: #ifndef MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA sl@0: TBool compResult = CompareBmpFilesL(KSrtNumOfFrames - expectedNumOfFrames[i], KSrtNumOfFrames - 1, KSubtitleCurrentBitmapFilePathSpec, KSubtitleTargetBitmapFilePathSpec); sl@0: sl@0: DeleteTempFiles(KSrtNumOfFrames - expectedNumOfFrames[i], KSrtNumOfFrames - 1, KSubtitleCurrentBitmapFilePathSpec); sl@0: sl@0: if (!compResult) sl@0: { sl@0: INFO_PRINTF1(_L("At least one bitmap file does not match the expected one. ")); sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: #endif //MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA sl@0: } sl@0: } sl@0: } sl@0: sl@0: void RTestSrtDecoderStep0002::TestGetNextFrameByPositionsL(const TTimeIntervalMicroSeconds& aPosition, TInt aExpectedNumOfFrames, TBool aSaveBitmap) sl@0: { sl@0: TRect dirtyRegion; sl@0: TTimeIntervalMicroSeconds displayTime = 0; sl@0: TTimeIntervalMicroSeconds displayDuration = 0; sl@0: TInt64 tDisplayTime = 0; sl@0: TInt64 tDisplayDuration = 0; sl@0: TSize bmpSize(600, 300); sl@0: TInt numOfFrames = 0; sl@0: TInt err = KErrNone; sl@0: TBuf bitmapFilename; sl@0: sl@0: CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap(); sl@0: CleanupStack::PushL(sampleBitmap); sl@0: sl@0: User::LeaveIfError(sampleBitmap->Create(bmpSize, EColor16MA)); sl@0: sl@0: iSrtDecoder->SetVideoPosition(aPosition); sl@0: iSrtDecoder->Start(); sl@0: sl@0: while (KErrNone == err) sl@0: { sl@0: TRAP(err, iSrtDecoder->GetNextFrameL(*sampleBitmap, dirtyRegion, displayTime, displayDuration)); sl@0: if (KErrNone == err) sl@0: { sl@0: // show bitmap sl@0: DrawBitmap(*sampleBitmap); sl@0: sl@0: // save bitmap for the possible comparison sl@0: if (aSaveBitmap) sl@0: { sl@0: bitmapFilename.Format(KSubtitleCurrentBitmapFilePathSpec, numOfFrames); sl@0: User::LeaveIfError(sampleBitmap->Save(bitmapFilename)); sl@0: } sl@0: sl@0: if ((dirtyRegion.iTl.iX >= dirtyRegion.iBr.iX) || sl@0: (dirtyRegion.iTl.iY >= dirtyRegion.iBr.iY)) sl@0: { sl@0: INFO_PRINTF2(_L("Invalid dirty region received. (frame %d)"), numOfFrames); sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: tDisplayTime = displayTime.Int64()/1000; sl@0: tDisplayDuration = displayDuration.Int64()/1000; sl@0: INFO_PRINTF4(_L("Frame[%d]: displayTime: %dms, displayDuration: %dms."), sl@0: numOfFrames, sl@0: I64LOW(tDisplayTime), sl@0: I64LOW(tDisplayDuration)); sl@0: sl@0: numOfFrames++; sl@0: } sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(sampleBitmap); sl@0: sl@0: iSrtDecoder->Stop(); sl@0: sl@0: if (KErrEof != err) sl@0: { sl@0: User::Leave(err); sl@0: } sl@0: sl@0: if (aExpectedNumOfFrames != numOfFrames) sl@0: { sl@0: INFO_PRINTF2(_L("The number of frame (%d) is unexpected. "), numOfFrames); sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: } sl@0: sl@0: sl@0: // Implementation of RTestSrtDecoderStep0101 sl@0: sl@0: RTestSrtDecoderStep0101::RTestSrtDecoderStep0101() sl@0: { sl@0: iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0101-HP"); sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0101::DoTestStepPreambleL() sl@0: { sl@0: InitializeTestStepL(EFalse, KSampleSubtitleSRTFilepath2); sl@0: sl@0: return EPass; sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0101::DoTestStepPostambleL() sl@0: { sl@0: UnInitializeTestStep(); sl@0: sl@0: return EPass; sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0101::DoTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("Enter DoTestStepL")); sl@0: TVerdict result = EPass; sl@0: sl@0: TRAPD(err, TestGetNextFrameL()); sl@0: if (KErrNone != err) sl@0: { sl@0: result = EFail; sl@0: ERR_PRINTF2(_L("Error - RTestSrtDecoderStep0101::TestGetNextFrameL failed. error code %d. "), err); sl@0: INFO_PRINTF1(_L("Exit CSrtDecoder")); sl@0: return result; sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("Exit DoTestStepL")); sl@0: return result; sl@0: } sl@0: sl@0: void RTestSrtDecoderStep0101::TestGetNextFrameL() sl@0: { sl@0: TInt numOfValidFrame = 0; sl@0: const TInt KSrtCase0101ExpectedValidFrame = 6; sl@0: TRect dirtyRegion; sl@0: TTimeIntervalMicroSeconds displayTime = 0; sl@0: TTimeIntervalMicroSeconds displayDuration = 0; sl@0: TSize bmpSize(320, 120); sl@0: sl@0: CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap(); sl@0: CleanupStack::PushL(sampleBitmap); sl@0: sl@0: TInt err = sampleBitmap->Create( sl@0: bmpSize, sl@0: EColor16MA sl@0: ); sl@0: User::LeaveIfError(err); sl@0: sl@0: iSrtDecoder->SetVideoPosition(0); sl@0: iSrtDecoder->Start(); sl@0: sl@0: while (KErrNone == err) sl@0: { sl@0: TRAP(err, iSrtDecoder->GetNextFrameL(*sampleBitmap, dirtyRegion, displayTime, displayDuration)); sl@0: if (KErrNone == err) sl@0: { sl@0: numOfValidFrame++; sl@0: } sl@0: else if (KErrArgument == err) sl@0: { sl@0: err = KErrNone; sl@0: } sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(sampleBitmap); sl@0: sl@0: iSrtDecoder->Stop(); sl@0: sl@0: if (err != KErrEof) sl@0: { sl@0: User::Leave(err); sl@0: } sl@0: sl@0: if (KSrtCase0101ExpectedValidFrame != numOfValidFrame) sl@0: { sl@0: INFO_PRINTF2(_L("The number of valid frame (%d) is unexpected. "), numOfValidFrame); sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: } sl@0: sl@0: // Implementation of RTestSrtDecoderStep0103 sl@0: sl@0: RTestSrtDecoderStep0103::RTestSrtDecoderStep0103() sl@0: { sl@0: iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0103-HP"); sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0103::DoTestStepPreambleL() sl@0: { sl@0: User::LeaveIfError(RFbsSession::Connect()); sl@0: sl@0: return EPass; sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0103::DoTestStepPostambleL() sl@0: { sl@0: RFbsSession::Disconnect(); sl@0: sl@0: return EPass; sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0103::DoTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("Enter DoTestStepL")); sl@0: TVerdict result = EFail; sl@0: TSize bmpSize(120, 320); sl@0: sl@0: CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap(); sl@0: CleanupStack::PushL(sampleBitmap); sl@0: User::LeaveIfError(sampleBitmap->Create(bmpSize, EColor16MA)); sl@0: sl@0: for (TInt failRate = 1; ; ++failRate) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EFailNext, failRate); sl@0: __UHEAP_MARK; sl@0: sl@0: TRAPD(error, TestGetNextFrameL(*sampleBitmap)); sl@0: RDebug::Printf("Ending iteration %d. Result = %d. Failures = %d", failRate, error, __UHEAP_CHECKFAILURE); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if ((error != KErrNone) && (error != KErrNoMemory)) sl@0: { sl@0: ERR_PRINTF3(_L("RTestSrtDecoderStep0103: TESTS FAILED TO COMPLETE (failRate=%i) error code: %d\n"), failRate, error); sl@0: break; sl@0: } sl@0: sl@0: TAny* const pointer = User::Alloc(1); sl@0: User::Free(pointer); sl@0: if (!pointer) sl@0: { sl@0: result = EPass; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: __UHEAP_RESET; sl@0: sl@0: CleanupStack::PopAndDestroy(sampleBitmap); sl@0: sl@0: INFO_PRINTF1(_L("Exit DoTestStepL")); sl@0: return result; sl@0: } sl@0: sl@0: void RTestSrtDecoderStep0103::TestGetNextFrameL(CFbsBitmap& aBitmap) sl@0: { sl@0: TRect dirtyRegion; sl@0: CSrtReader *srtReader = CSrtReader::NewL(KSampleSubtitleSRTFilepath1); sl@0: CleanupStack::PushL(srtReader); sl@0: sl@0: CSrtSubtitleDecoder *srtDecoder = CSrtSubtitleDecoder::NewL(*srtReader); sl@0: CleanupStack::PushL(srtDecoder); sl@0: sl@0: TInt err = KErrNone; sl@0: TTimeIntervalMicroSeconds displayTime = 0; sl@0: TTimeIntervalMicroSeconds displayDuration = 0; sl@0: sl@0: srtDecoder->SetVideoPosition(0); sl@0: srtDecoder->Start(); sl@0: sl@0: while (KErrNone == err) sl@0: { sl@0: TRAP(err, srtDecoder->GetNextFrameL(aBitmap, dirtyRegion, displayTime, displayDuration)); sl@0: } sl@0: sl@0: if (err != KErrEof) sl@0: { sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: srtDecoder->Stop(); sl@0: sl@0: CleanupStack::PopAndDestroy(srtDecoder); sl@0: CleanupStack::PopAndDestroy(srtReader); sl@0: } sl@0: sl@0: RTestSrtDecoderStep0105::RTestSrtDecoderStep0105() sl@0: { sl@0: iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0105-HP"); sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0105::DoTestStepL() sl@0: { sl@0: iSrtDecoder->Start(); sl@0: iSrtDecoder->Start(); sl@0: sl@0: ERR_PRINTF1(_L("Panic expected, so failing")); sl@0: return EFail; sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0105::DoTestStepPreambleL() sl@0: { sl@0: InitializeTestStepL(EFalse, KSampleSubtitleSRTFilepath1); sl@0: return EPass; sl@0: } sl@0: sl@0: TVerdict RTestSrtDecoderStep0105::DoTestStepPostambleL() sl@0: { sl@0: UnInitializeTestStep(); sl@0: return EPass; sl@0: }