1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/srtdecoder/src/testsrtdecoder.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,690 @@
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 <bautils.h>
1.20 +#include <bitdev.h>
1.21 +#include <gulutil.h>
1.22 +
1.23 +#include "srtdecoder.h"
1.24 +#include "srtreader.h"
1.25 +#include "testsrtdecoder.h"
1.26 +
1.27 +_LIT(KSampleSubtitleSRTFilepath1, "c:\\mm\\subtitle1.srt");
1.28 +_LIT(KSampleSubtitleSRTFilepath2, "c:\\mm\\subtitle2.srt");
1.29 +
1.30 +// subtitlebmp0.mbm -- subtitlebmp9.mbm: bitmaps for comparison
1.31 +_LIT(KSubtitleTargetBitmapFilePathSpec, "c:\\mm\\subtitlebmp%d.mbm");
1.32 +// subtitlecurbmp0.mbm -- subtitlecurbmp9.mbm: runtime bitmaps for comparison,
1.33 +// will be removed unless MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA is defined
1.34 +_LIT(KSubtitleCurrentBitmapFilePathSpec, "c:\\mm\\subtitlecurbmp%d.mbm");
1.35 +
1.36 +// defining MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA means re-creating the test data (bitmaps) for comparison, instead
1.37 +// of doing the comparison with the existing test data
1.38 +// at runtime with the spec of KSubtitleCurrentBitmapFilePathSpec
1.39 +#ifndef MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA
1.40 +// #define MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA
1.41 +#endif
1.42 +
1.43 +void RTestSrtDecoderStep::InitializeTestStepL(TBool aCreateSrtReaderOnly, const TDesC& aSrtFilePath)
1.44 + {
1.45 + __MM_HEAP_MARK;
1.46 + iSrtReader = CSrtReader::NewL(aSrtFilePath);
1.47 +
1.48 + iCreateSrtReaderOnly = aCreateSrtReaderOnly;
1.49 + if (!iCreateSrtReaderOnly)
1.50 + {
1.51 + User::LeaveIfError(iRbsSession.Connect());
1.52 + iSrtDecoder = CSrtSubtitleDecoder::NewL(*iSrtReader);
1.53 + }
1.54 + }
1.55 +
1.56 +void RTestSrtDecoderStep::UnInitializeTestStep()
1.57 + {
1.58 + if (!iCreateSrtReaderOnly)
1.59 + {
1.60 + iRbsSession.Disconnect();
1.61 + delete iSrtDecoder;
1.62 + }
1.63 + delete iSrtReader;
1.64 + __MM_HEAP_MARKEND;
1.65 + }
1.66 +
1.67 +// Implementation of the generic test step
1.68 +TBool RTestSrtDecoderStep::CompareFilesL(RFs &aFs, const TDesC& aFilePath1, const TDesC& aFilePath2)
1.69 + {
1.70 + TBool identical = EFalse;
1.71 + RFile file1;
1.72 + RFile file2;
1.73 + TInt file1Size = 0;
1.74 + TInt file2Size = 0;
1.75 +
1.76 + if (aFilePath1 == aFilePath2)
1.77 + {
1.78 + identical = ETrue;
1.79 + }
1.80 + else
1.81 + {
1.82 + User::LeaveIfError(file1.Open(aFs, aFilePath1, EFileRead));
1.83 + CleanupClosePushL(file1);
1.84 + User::LeaveIfError(file2.Open(aFs, aFilePath2, EFileRead));
1.85 + CleanupClosePushL(file2);
1.86 +
1.87 + User::LeaveIfError(file1.Size(file1Size));
1.88 + User::LeaveIfError(file2.Size(file2Size));
1.89 +
1.90 + if (file1Size == file2Size)
1.91 + {
1.92 + TBuf8<256> buffer1;
1.93 + TBuf8<256> buffer2;
1.94 +
1.95 + identical = ETrue;
1.96 + while(ETrue)
1.97 + {
1.98 + User::LeaveIfError(file1.Read(buffer1));
1.99 + User::LeaveIfError(file2.Read(buffer2));
1.100 +
1.101 + if (buffer1 != buffer2)
1.102 + {
1.103 + identical = EFalse;
1.104 + break;
1.105 + }
1.106 +
1.107 + if (0 == buffer1.Length())
1.108 + {
1.109 + break;
1.110 + }
1.111 + }
1.112 + }
1.113 +
1.114 + CleanupStack::PopAndDestroy(&file2);
1.115 + CleanupStack::PopAndDestroy(&file1);
1.116 + }
1.117 +
1.118 + return identical;
1.119 + }
1.120 +
1.121 +TBool RTestSrtDecoderStep::IsFontAvailableL(const TDesC& aTypefaceName)
1.122 + {
1.123 + TBool avail = EFalse;
1.124 + TSize bmpSize(100, 100);
1.125 +
1.126 + CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap();
1.127 + CleanupStack::PushL(sampleBitmap);
1.128 +
1.129 + User::LeaveIfError(sampleBitmap->Create(bmpSize, EColor16MA));
1.130 +
1.131 + CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL(sampleBitmap);
1.132 + CleanupStack::PushL(bmpDevice);
1.133 +
1.134 + if (0 != FontUtils::TypefaceAttributes(*bmpDevice, aTypefaceName))
1.135 + {
1.136 + const TInt KSubtitleFontMaxSpecHeights = 128;
1.137 + CArrayFix<TInt> *listHeights = new (ELeave) CArrayFixFlat<TInt>(KSubtitleFontMaxSpecHeights);
1.138 + CleanupStack::PushL(listHeights);
1.139 +
1.140 + FontUtils::GetAvailableHeightsInTwipsL(*bmpDevice, aTypefaceName, *listHeights);
1.141 + for (TInt i = 0; i < listHeights->Count(); i++)
1.142 + {
1.143 + if (KSrtTargetTypefaceHeightInTwips == (*listHeights)[i])
1.144 + {
1.145 + avail = ETrue;
1.146 + break;
1.147 + }
1.148 + }
1.149 +
1.150 + CleanupStack::PopAndDestroy(listHeights);
1.151 + }
1.152 +
1.153 + CleanupStack::PopAndDestroy(bmpDevice);
1.154 + CleanupStack::PopAndDestroy(sampleBitmap);
1.155 +
1.156 + return avail;
1.157 + }
1.158 +
1.159 +TBool RTestSrtDecoderStep::CompareBmpFilesL(TInt aStartIndex, TInt aEndIndex, const TDesC& aSrcFilePathSpec, const TDesC& aDestFilePathSpec)
1.160 + {
1.161 + TBool identical = ETrue;
1.162 + TBuf <KMaxFullName> bitmapFilename1;
1.163 + TBuf <KMaxFullName> bitmapFilename2;
1.164 + RFs rfs;
1.165 + User::LeaveIfError(rfs.Connect());
1.166 + CleanupClosePushL(rfs);
1.167 + for (TInt i = aStartIndex; i <= aEndIndex; i++)
1.168 + {
1.169 + bitmapFilename1.Format(aDestFilePathSpec, i);
1.170 + bitmapFilename2.Format(aSrcFilePathSpec, i);
1.171 + if (!CompareFilesL(rfs, bitmapFilename1, bitmapFilename2))
1.172 + {
1.173 + identical = EFalse;
1.174 + break;
1.175 + }
1.176 + }
1.177 + CleanupStack::PopAndDestroy(&rfs);
1.178 +
1.179 + return identical;
1.180 + }
1.181 +
1.182 +void RTestSrtDecoderStep::DeleteTempFiles(TInt aStartIndex, TInt aEndIndex, const TDesC& aFilePathSpec)
1.183 + {
1.184 + TBuf <KMaxFullName> bitmapFilename;
1.185 + RFs rfs;
1.186 +
1.187 + if (KErrNone == rfs.Connect())
1.188 + {
1.189 + for (TInt i = aStartIndex ; i <= aEndIndex; i++)
1.190 + {
1.191 + bitmapFilename.Format(aFilePathSpec, i);
1.192 + BaflUtils::DeleteFile(rfs, bitmapFilename);
1.193 + }
1.194 + }
1.195 + }
1.196 +
1.197 +
1.198 +// Implementation of RTestSrtDecoderStep0002
1.199 +
1.200 +RTestSrtDecoderStep0002::RTestSrtDecoderStep0002()
1.201 + {
1.202 + iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0002-HP");
1.203 + }
1.204 +
1.205 +TVerdict RTestSrtDecoderStep0002::DoTestStepPreambleL()
1.206 + {
1.207 + InitializeTestStepL(EFalse, KSampleSubtitleSRTFilepath1);
1.208 +
1.209 + // Install the Active Scheduler
1.210 + iActiveScheduler = new(ELeave) CActiveScheduler;
1.211 + CActiveScheduler::Install(iActiveScheduler);
1.212 + iActiveSchedulerStarted = EFalse;
1.213 +
1.214 + InitWservL();
1.215 +
1.216 + return EPass;
1.217 + }
1.218 +
1.219 +TVerdict RTestSrtDecoderStep0002::DoTestStepPostambleL()
1.220 + {
1.221 + UninitWserv();
1.222 + CActiveScheduler::Install(NULL);
1.223 + delete iActiveScheduler;
1.224 + iActiveScheduler = NULL;
1.225 +
1.226 + UnInitializeTestStep();
1.227 +
1.228 + return EPass;
1.229 + }
1.230 +
1.231 +TVerdict RTestSrtDecoderStep0002::DoTestStepL()
1.232 + {
1.233 + INFO_PRINTF1(_L("Enter DoTestStepL"));
1.234 + TVerdict result = EPass;
1.235 +
1.236 + TRAPD(err, TestGetNextFrameL());
1.237 + if (KErrNone != err)
1.238 + {
1.239 + result = EFail;
1.240 + ERR_PRINTF2(_L("Error - RTestSrtDecoderStep0002::TestGetNextFrameL failed. error code %d. "), err);
1.241 + }
1.242 +
1.243 + INFO_PRINTF1(_L("Exit DoTestStepL"));
1.244 + return result;
1.245 + }
1.246 +
1.247 +void RTestSrtDecoderStep0002::InitWservL()
1.248 + {
1.249 + TInt err = iWs.Connect();
1.250 +
1.251 + if (err != KErrNone)
1.252 + {
1.253 + // Access violation if ws is null
1.254 + ERR_PRINTF2(_L("Error - Failed to connect to RWsSession. error code %d. "), err);
1.255 + User::Leave(err);
1.256 + }
1.257 +
1.258 + iScreen = new (ELeave) CWsScreenDevice(iWs); // make device for this session
1.259 + User::LeaveIfError(iScreen->Construct()); // and complete its construction
1.260 +
1.261 + iRootWindow = RWindowGroup(iWs);
1.262 + User::LeaveIfError(iRootWindow.Construct((TUint32)this, ETrue));
1.263 +
1.264 + iWindow = new(ELeave) RWindow(iWs);
1.265 + User::LeaveIfError(((RWindow*)iWindow)->Construct(iRootWindow,((TUint32)(this)) + 1));
1.266 + iWindow->SetExtent(TPoint(0,0), iScreen->SizeInPixels());
1.267 + iWindow->SetVisible(ETrue);
1.268 + iWindow->SetRequiredDisplayMode(EColor16MA);
1.269 +
1.270 + // Light Sky Blue 135-206-250
1.271 + TRgb backgroundColour = TRgb(135, 206, 250);
1.272 + iWindow->SetBackgroundColor(backgroundColour);
1.273 +
1.274 + iGc = new(ELeave) CWindowGc(iScreen);
1.275 + User::LeaveIfError(iGc->Construct());
1.276 +
1.277 + iWindow->Activate();
1.278 + iWs.Flush();
1.279 + }
1.280 +
1.281 +void RTestSrtDecoderStep0002::UninitWserv()
1.282 + {
1.283 + if (iWindow)
1.284 + {
1.285 + iWindow->Close();
1.286 + delete iWindow;
1.287 + iWindow = NULL;
1.288 + }
1.289 +
1.290 + iRootWindow.Close();
1.291 + delete iScreen;
1.292 + iScreen = NULL;
1.293 +
1.294 + delete iGc;
1.295 + iGc = NULL;
1.296 +
1.297 + iWs.Flush();
1.298 + iWs.Close();
1.299 + }
1.300 +
1.301 +void RTestSrtDecoderStep0002::PrepGc()
1.302 + {
1.303 + iGc->Activate(*iWindow);
1.304 + iWindow->Invalidate();
1.305 + iWindow->BeginRedraw();
1.306 +
1.307 + iGc->Clear(TRect(iScreen->SizeInPixels()));
1.308 + iWs.Flush();
1.309 + }
1.310 +
1.311 +void RTestSrtDecoderStep0002::RetireGc()
1.312 + {
1.313 + iGc->Deactivate();
1.314 + iWindow->EndRedraw();
1.315 + iWs.Flush();
1.316 + }
1.317 +
1.318 +void RTestSrtDecoderStep0002::DrawBitmap(CFbsBitmap& aBitmap)
1.319 + {
1.320 + PrepGc();
1.321 +
1.322 + TSize size = iScreen->SizeInPixels();
1.323 + TInt width = size.iWidth;
1.324 + TInt height = size.iHeight;
1.325 + TPoint pos(0, 0);
1.326 +
1.327 + // Draw a square border
1.328 + iGc->SetPenColor(TRgb(255,0,0));
1.329 + iGc->DrawLine(TPoint(0,0),TPoint(0,height-1));
1.330 + iGc->DrawLine (TPoint (0, height-1), TPoint (width-1, height-1));
1.331 + iGc->DrawLine(TPoint(width-1,height-1),TPoint(width-1,0));
1.332 + iGc->DrawLine (TPoint (width-1, 0), TPoint (0, 0));
1.333 +
1.334 + // Draw a line between the corners of the window
1.335 + iGc->DrawLine(TPoint(0,0),TPoint(width, height));
1.336 + iGc->DrawLine (TPoint (0, height), TPoint (width, 0));
1.337 +
1.338 + // Draw bitmap
1.339 + iGc->BitBlt(pos, &aBitmap);
1.340 +
1.341 + RetireGc();
1.342 + }
1.343 +
1.344 +void RTestSrtDecoderStep0002::TestGetNextFrameL()
1.345 + {
1.346 + // start/stop for multiple times is also tested.
1.347 + const TInt64 KSrtMicroSecondsInAMilliSecond = 1000;
1.348 + const TInt64 KSrtMicroSecondsInASecond = KSrtMicroSecondsInAMilliSecond * 1000;
1.349 + const TInt64 KSrtMicroSecondsInAMinute = KSrtMicroSecondsInASecond * 60;
1.350 + const TInt64 KSrtMicroSecondsInAnHour = KSrtMicroSecondsInAMinute * 60;
1.351 + const TInt KSrtSetPosTestCount = 6;
1.352 + const TInt KSrtNumOfFrames = 10;
1.353 +
1.354 + TTimeIntervalMicroSeconds videoPos[KSrtSetPosTestCount] =
1.355 + {
1.356 + 0,
1.357 + KSrtMicroSecondsInAMinute,
1.358 + 1 * KSrtMicroSecondsInAMinute + 2 * KSrtMicroSecondsInASecond + 1 * KSrtMicroSecondsInAMilliSecond,
1.359 + 1 * KSrtMicroSecondsInAMinute + 6 * KSrtMicroSecondsInASecond + 20 * KSrtMicroSecondsInAMilliSecond,
1.360 + 1 * KSrtMicroSecondsInAnHour + 1 * KSrtMicroSecondsInAMinute + 20 * KSrtMicroSecondsInASecond + 1 * KSrtMicroSecondsInAMilliSecond,
1.361 + 2 * KSrtMicroSecondsInAnHour
1.362 + };
1.363 +
1.364 + TInt expectedNumOfFrames[KSrtSetPosTestCount] =
1.365 + {
1.366 + 10,
1.367 + 8,
1.368 + 6,
1.369 + 6,
1.370 + 2,
1.371 + 0
1.372 + };
1.373 +
1.374 + // check if the required Font is available before do the bitmap file comparison
1.375 + TInt requiredFontAvailable = IsFontAvailableL(KSrtTargetTypefaceName);
1.376 + if (!requiredFontAvailable)
1.377 + {
1.378 +#ifdef MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA
1.379 + INFO_PRINTF1(_L("Required font is not available, cannot save bitmap data. "));
1.380 + User::Leave(KErrGeneral);
1.381 +#else
1.382 + INFO_PRINTF1(_L("Required font is not available, no bitmap comparison. "));
1.383 +#endif //MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA
1.384 + }
1.385 +
1.386 + for (TInt i = 0; i < KSrtSetPosTestCount; i++)
1.387 + {
1.388 +#ifdef __WINSCW__
1.389 + TBool compareBitmap = (0 == i) && requiredFontAvailable;
1.390 +#else
1.391 + TBool compareBitmap = EFalse;
1.392 +#endif //__WINSCW__
1.393 +
1.394 + TestGetNextFrameByPositionsL(videoPos[i], expectedNumOfFrames[i], compareBitmap);
1.395 +
1.396 + // verify the bitmaps
1.397 + if (compareBitmap)
1.398 + {
1.399 +#ifndef MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA
1.400 + TBool compResult = CompareBmpFilesL(KSrtNumOfFrames - expectedNumOfFrames[i], KSrtNumOfFrames - 1, KSubtitleCurrentBitmapFilePathSpec, KSubtitleTargetBitmapFilePathSpec);
1.401 +
1.402 + DeleteTempFiles(KSrtNumOfFrames - expectedNumOfFrames[i], KSrtNumOfFrames - 1, KSubtitleCurrentBitmapFilePathSpec);
1.403 +
1.404 + if (!compResult)
1.405 + {
1.406 + INFO_PRINTF1(_L("At least one bitmap file does not match the expected one. "));
1.407 + User::Leave(KErrGeneral);
1.408 + }
1.409 +#endif //MMF_SUBTITLE_SUPPORT_TEST_SAVEDATA
1.410 + }
1.411 + }
1.412 + }
1.413 +
1.414 +void RTestSrtDecoderStep0002::TestGetNextFrameByPositionsL(const TTimeIntervalMicroSeconds& aPosition, TInt aExpectedNumOfFrames, TBool aSaveBitmap)
1.415 + {
1.416 + TRect dirtyRegion;
1.417 + TTimeIntervalMicroSeconds displayTime = 0;
1.418 + TTimeIntervalMicroSeconds displayDuration = 0;
1.419 + TInt64 tDisplayTime = 0;
1.420 + TInt64 tDisplayDuration = 0;
1.421 + TSize bmpSize(600, 300);
1.422 + TInt numOfFrames = 0;
1.423 + TInt err = KErrNone;
1.424 + TBuf <KMaxFullName> bitmapFilename;
1.425 +
1.426 + CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap();
1.427 + CleanupStack::PushL(sampleBitmap);
1.428 +
1.429 + User::LeaveIfError(sampleBitmap->Create(bmpSize, EColor16MA));
1.430 +
1.431 + iSrtDecoder->SetVideoPosition(aPosition);
1.432 + iSrtDecoder->Start();
1.433 +
1.434 + while (KErrNone == err)
1.435 + {
1.436 + TRAP(err, iSrtDecoder->GetNextFrameL(*sampleBitmap, dirtyRegion, displayTime, displayDuration));
1.437 + if (KErrNone == err)
1.438 + {
1.439 + // show bitmap
1.440 + DrawBitmap(*sampleBitmap);
1.441 +
1.442 + // save bitmap for the possible comparison
1.443 + if (aSaveBitmap)
1.444 + {
1.445 + bitmapFilename.Format(KSubtitleCurrentBitmapFilePathSpec, numOfFrames);
1.446 + User::LeaveIfError(sampleBitmap->Save(bitmapFilename));
1.447 + }
1.448 +
1.449 + if ((dirtyRegion.iTl.iX >= dirtyRegion.iBr.iX) ||
1.450 + (dirtyRegion.iTl.iY >= dirtyRegion.iBr.iY))
1.451 + {
1.452 + INFO_PRINTF2(_L("Invalid dirty region received. (frame %d)"), numOfFrames);
1.453 + User::Leave(KErrGeneral);
1.454 + }
1.455 +
1.456 + tDisplayTime = displayTime.Int64()/1000;
1.457 + tDisplayDuration = displayDuration.Int64()/1000;
1.458 + INFO_PRINTF4(_L("Frame[%d]: displayTime: %dms, displayDuration: %dms."),
1.459 + numOfFrames,
1.460 + I64LOW(tDisplayTime),
1.461 + I64LOW(tDisplayDuration));
1.462 +
1.463 + numOfFrames++;
1.464 + }
1.465 + }
1.466 +
1.467 + CleanupStack::PopAndDestroy(sampleBitmap);
1.468 +
1.469 + iSrtDecoder->Stop();
1.470 +
1.471 + if (KErrEof != err)
1.472 + {
1.473 + User::Leave(err);
1.474 + }
1.475 +
1.476 + if (aExpectedNumOfFrames != numOfFrames)
1.477 + {
1.478 + INFO_PRINTF2(_L("The number of frame (%d) is unexpected. "), numOfFrames);
1.479 + User::Leave(KErrGeneral);
1.480 + }
1.481 + }
1.482 +
1.483 +
1.484 +// Implementation of RTestSrtDecoderStep0101
1.485 +
1.486 +RTestSrtDecoderStep0101::RTestSrtDecoderStep0101()
1.487 + {
1.488 + iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0101-HP");
1.489 + }
1.490 +
1.491 +TVerdict RTestSrtDecoderStep0101::DoTestStepPreambleL()
1.492 + {
1.493 + InitializeTestStepL(EFalse, KSampleSubtitleSRTFilepath2);
1.494 +
1.495 + return EPass;
1.496 + }
1.497 +
1.498 +TVerdict RTestSrtDecoderStep0101::DoTestStepPostambleL()
1.499 + {
1.500 + UnInitializeTestStep();
1.501 +
1.502 + return EPass;
1.503 + }
1.504 +
1.505 +TVerdict RTestSrtDecoderStep0101::DoTestStepL()
1.506 + {
1.507 + INFO_PRINTF1(_L("Enter DoTestStepL"));
1.508 + TVerdict result = EPass;
1.509 +
1.510 + TRAPD(err, TestGetNextFrameL());
1.511 + if (KErrNone != err)
1.512 + {
1.513 + result = EFail;
1.514 + ERR_PRINTF2(_L("Error - RTestSrtDecoderStep0101::TestGetNextFrameL failed. error code %d. "), err);
1.515 + INFO_PRINTF1(_L("Exit CSrtDecoder"));
1.516 + return result;
1.517 + }
1.518 +
1.519 + INFO_PRINTF1(_L("Exit DoTestStepL"));
1.520 + return result;
1.521 + }
1.522 +
1.523 +void RTestSrtDecoderStep0101::TestGetNextFrameL()
1.524 + {
1.525 + TInt numOfValidFrame = 0;
1.526 + const TInt KSrtCase0101ExpectedValidFrame = 6;
1.527 + TRect dirtyRegion;
1.528 + TTimeIntervalMicroSeconds displayTime = 0;
1.529 + TTimeIntervalMicroSeconds displayDuration = 0;
1.530 + TSize bmpSize(320, 120);
1.531 +
1.532 + CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap();
1.533 + CleanupStack::PushL(sampleBitmap);
1.534 +
1.535 + TInt err = sampleBitmap->Create(
1.536 + bmpSize,
1.537 + EColor16MA
1.538 + );
1.539 + User::LeaveIfError(err);
1.540 +
1.541 + iSrtDecoder->SetVideoPosition(0);
1.542 + iSrtDecoder->Start();
1.543 +
1.544 + while (KErrNone == err)
1.545 + {
1.546 + TRAP(err, iSrtDecoder->GetNextFrameL(*sampleBitmap, dirtyRegion, displayTime, displayDuration));
1.547 + if (KErrNone == err)
1.548 + {
1.549 + numOfValidFrame++;
1.550 + }
1.551 + else if (KErrArgument == err)
1.552 + {
1.553 + err = KErrNone;
1.554 + }
1.555 + }
1.556 +
1.557 + CleanupStack::PopAndDestroy(sampleBitmap);
1.558 +
1.559 + iSrtDecoder->Stop();
1.560 +
1.561 + if (err != KErrEof)
1.562 + {
1.563 + User::Leave(err);
1.564 + }
1.565 +
1.566 + if (KSrtCase0101ExpectedValidFrame != numOfValidFrame)
1.567 + {
1.568 + INFO_PRINTF2(_L("The number of valid frame (%d) is unexpected. "), numOfValidFrame);
1.569 + User::Leave(KErrGeneral);
1.570 + }
1.571 + }
1.572 +
1.573 +// Implementation of RTestSrtDecoderStep0103
1.574 +
1.575 +RTestSrtDecoderStep0103::RTestSrtDecoderStep0103()
1.576 + {
1.577 + iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0103-HP");
1.578 + }
1.579 +
1.580 +TVerdict RTestSrtDecoderStep0103::DoTestStepPreambleL()
1.581 + {
1.582 + User::LeaveIfError(RFbsSession::Connect());
1.583 +
1.584 + return EPass;
1.585 + }
1.586 +
1.587 +TVerdict RTestSrtDecoderStep0103::DoTestStepPostambleL()
1.588 + {
1.589 + RFbsSession::Disconnect();
1.590 +
1.591 + return EPass;
1.592 + }
1.593 +
1.594 +TVerdict RTestSrtDecoderStep0103::DoTestStepL()
1.595 + {
1.596 + INFO_PRINTF1(_L("Enter DoTestStepL"));
1.597 + TVerdict result = EFail;
1.598 + TSize bmpSize(120, 320);
1.599 +
1.600 + CFbsBitmap* sampleBitmap = new (ELeave) CFbsBitmap();
1.601 + CleanupStack::PushL(sampleBitmap);
1.602 + User::LeaveIfError(sampleBitmap->Create(bmpSize, EColor16MA));
1.603 +
1.604 + for (TInt failRate = 1; ; ++failRate)
1.605 + {
1.606 + __UHEAP_SETFAIL(RHeap::EFailNext, failRate);
1.607 + __UHEAP_MARK;
1.608 +
1.609 + TRAPD(error, TestGetNextFrameL(*sampleBitmap));
1.610 + RDebug::Printf("Ending iteration %d. Result = %d. Failures = %d", failRate, error, __UHEAP_CHECKFAILURE);
1.611 +
1.612 + __UHEAP_MARKEND;
1.613 +
1.614 + if ((error != KErrNone) && (error != KErrNoMemory))
1.615 + {
1.616 + ERR_PRINTF3(_L("RTestSrtDecoderStep0103: TESTS FAILED TO COMPLETE (failRate=%i) error code: %d\n"), failRate, error);
1.617 + break;
1.618 + }
1.619 +
1.620 + TAny* const pointer = User::Alloc(1);
1.621 + User::Free(pointer);
1.622 + if (!pointer)
1.623 + {
1.624 + result = EPass;
1.625 + break;
1.626 + }
1.627 + }
1.628 +
1.629 + __UHEAP_RESET;
1.630 +
1.631 + CleanupStack::PopAndDestroy(sampleBitmap);
1.632 +
1.633 + INFO_PRINTF1(_L("Exit DoTestStepL"));
1.634 + return result;
1.635 + }
1.636 +
1.637 +void RTestSrtDecoderStep0103::TestGetNextFrameL(CFbsBitmap& aBitmap)
1.638 + {
1.639 + TRect dirtyRegion;
1.640 + CSrtReader *srtReader = CSrtReader::NewL(KSampleSubtitleSRTFilepath1);
1.641 + CleanupStack::PushL(srtReader);
1.642 +
1.643 + CSrtSubtitleDecoder *srtDecoder = CSrtSubtitleDecoder::NewL(*srtReader);
1.644 + CleanupStack::PushL(srtDecoder);
1.645 +
1.646 + TInt err = KErrNone;
1.647 + TTimeIntervalMicroSeconds displayTime = 0;
1.648 + TTimeIntervalMicroSeconds displayDuration = 0;
1.649 +
1.650 + srtDecoder->SetVideoPosition(0);
1.651 + srtDecoder->Start();
1.652 +
1.653 + while (KErrNone == err)
1.654 + {
1.655 + TRAP(err, srtDecoder->GetNextFrameL(aBitmap, dirtyRegion, displayTime, displayDuration));
1.656 + }
1.657 +
1.658 + if (err != KErrEof)
1.659 + {
1.660 + User::LeaveIfError(err);
1.661 + }
1.662 +
1.663 + srtDecoder->Stop();
1.664 +
1.665 + CleanupStack::PopAndDestroy(srtDecoder);
1.666 + CleanupStack::PopAndDestroy(srtReader);
1.667 + }
1.668 +
1.669 +RTestSrtDecoderStep0105::RTestSrtDecoderStep0105()
1.670 + {
1.671 + iTestStepName = _L("MM-MMF-SUBTITLE-SRTDECODER-U-0105-HP");
1.672 + }
1.673 +
1.674 +TVerdict RTestSrtDecoderStep0105::DoTestStepL()
1.675 + {
1.676 + iSrtDecoder->Start();
1.677 + iSrtDecoder->Start();
1.678 +
1.679 + ERR_PRINTF1(_L("Panic expected, so failing"));
1.680 + return EFail;
1.681 + }
1.682 +
1.683 +TVerdict RTestSrtDecoderStep0105::DoTestStepPreambleL()
1.684 + {
1.685 + InitializeTestStepL(EFalse, KSampleSubtitleSRTFilepath1);
1.686 + return EPass;
1.687 + }
1.688 +
1.689 +TVerdict RTestSrtDecoderStep0105::DoTestStepPostambleL()
1.690 + {
1.691 + UnInitializeTestStep();
1.692 + return EPass;
1.693 + }