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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include "srtreader.h"
19 #include "testsrtreader.h"
21 _LIT( KSampleSubtitleSRTFilepath, "c:\\mm\\subtitle1.srt" );
22 _LIT( KSampleSubtitleTempFilepath, "c:\\mm\\subtitle1t.srt" );
23 _LIT( KSampleSubtitleBogusFilepath, "c:\\mm\\bogussubtitle.srt" );
25 // Implementation of RTestSrtReaderStep0001
27 RTestSrtReaderStep0001::RTestSrtReaderStep0001()
29 iTestStepName = _L("MM-MMF-SUBTITLE-SRTREADER-U-0001-HP");
33 TVerdict RTestSrtReaderStep0001::DoTestStepPreambleL()
36 User::LeaveIfError(iFsSession.Connect());
41 TVerdict RTestSrtReaderStep0001::DoTestStepPostambleL()
43 if (BaflUtils::FileExists(iFsSession, KSampleSubtitleTempFilepath))
45 BaflUtils::DeleteFile(iFsSession, KSampleSubtitleTempFilepath);
53 TVerdict RTestSrtReaderStep0001::DoTestStepL()
55 INFO_PRINTF1(_L("Enter DoTestStepL"));
56 TVerdict result = EPass;
58 for(TInt bufSize = 0; bufSize <= 640 ; bufSize += 32)
61 TInt err = resultSource.Create(iFsSession, KSampleSubtitleTempFilepath, EFileRead | EFileWrite);
62 if (KErrAlreadyExists == err)
64 User::LeaveIfError(resultSource.Open(iFsSession, KSampleSubtitleTempFilepath, EFileRead | EFileWrite));
68 User::LeaveIfError(err);
71 CleanupClosePushL(resultSource);
73 HBufC8 *buf = HBufC8::NewL(bufSize);
74 CleanupStack::PushL(buf);
76 CSrtReader* srtReader = CSrtReader::NewL(KSampleSubtitleSRTFilepath);
77 CleanupStack::PushL(srtReader);
79 TInt error = KErrNone;
81 while(KErrNone == error)
83 TPtr8 ptr8 = buf->Des();
84 error = srtReader->GetBuffer(ptr8);
86 if (ptr8.Length() > 0)
88 User::LeaveIfError(resultSource.Write(ptr8));
92 CleanupStack::PopAndDestroy(srtReader);
93 CleanupStack::PopAndDestroy(buf);
94 CleanupStack::PopAndDestroy(&resultSource);
98 if (error != KErrArgument)
100 ERR_PRINTF3(_L("Error - CSrtReader::GetBuffer returned %d when the buffer is set to %d byte"), error, bufSize);
106 if (error != KErrEof)
108 ERR_PRINTF3(_L("Error - CSrtReader::GetBuffer returned %d when the buffer is set to %d bytes"), error, bufSize);
113 // compare KSampleSubtitleSRTFilepath with KSampleSubtitleTempFilepath
114 if (!RTestSrtDecoderStep::CompareFilesL(iFsSession, KSampleSubtitleSRTFilepath, KSampleSubtitleTempFilepath))
116 ERR_PRINTF1(_L("Error - the result file does not match the original file. "));
122 if (BaflUtils::FileExists(iFsSession, KSampleSubtitleTempFilepath))
124 User::LeaveIfError(BaflUtils::DeleteFile(iFsSession, KSampleSubtitleTempFilepath));
128 INFO_PRINTF1(_L("Exit DoTestStepL"));
133 // Implementation of RTestSrtReaderStep0100
135 RTestSrtReaderStep0100::RTestSrtReaderStep0100()
137 iTestStepName = _L("MM-MMF-SUBTITLE-SRTREADER-U-0100-HP");
140 TVerdict RTestSrtReaderStep0100::DoTestStepL()
142 INFO_PRINTF1(_L("Enter DoTestStepL"));
143 TInt expectedErr = KErrNotFound;
147 TVerdict result = EPass;
149 TRAPD(err, CSrtReader* srtReader = CSrtReader::NewL(KSampleSubtitleBogusFilepath));
151 if (err != expectedErr)
153 ERR_PRINTF2(_L("Error - CSrtReader constructor returned %d for a bogus srt source. "), err);
159 INFO_PRINTF1(_L("Exit DoTestStepL"));