mmlibs/mmfw/tsrc/mmfunittest/srtdecoder/src/testsrtreader.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     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 
       
    18 #include "srtreader.h"
       
    19 #include "testsrtreader.h"
       
    20 
       
    21 _LIT( KSampleSubtitleSRTFilepath, "c:\\mm\\subtitle1.srt" );
       
    22 _LIT( KSampleSubtitleTempFilepath, "c:\\mm\\subtitle1t.srt" );
       
    23 _LIT( KSampleSubtitleBogusFilepath, "c:\\mm\\bogussubtitle.srt" );
       
    24 
       
    25 // Implementation of RTestSrtReaderStep0001
       
    26 
       
    27 RTestSrtReaderStep0001::RTestSrtReaderStep0001()
       
    28 	{
       
    29 	iTestStepName = _L("MM-MMF-SUBTITLE-SRTREADER-U-0001-HP");
       
    30 	}
       
    31 
       
    32 
       
    33 TVerdict RTestSrtReaderStep0001::DoTestStepPreambleL()
       
    34     {
       
    35     __MM_HEAP_MARK;
       
    36     User::LeaveIfError(iFsSession.Connect());
       
    37     
       
    38     return EPass;
       
    39     }
       
    40 
       
    41 TVerdict RTestSrtReaderStep0001::DoTestStepPostambleL()
       
    42     {
       
    43     if (BaflUtils::FileExists(iFsSession, KSampleSubtitleTempFilepath))
       
    44         {
       
    45         BaflUtils::DeleteFile(iFsSession, KSampleSubtitleTempFilepath);
       
    46         }
       
    47     iFsSession.Close();
       
    48     
       
    49     __MM_HEAP_MARKEND;
       
    50     return EPass;
       
    51     }
       
    52     
       
    53 TVerdict RTestSrtReaderStep0001::DoTestStepL()
       
    54 	{
       
    55 	INFO_PRINTF1(_L("Enter DoTestStepL"));
       
    56 	TVerdict result = EPass;
       
    57 	
       
    58     for(TInt bufSize = 0; bufSize <= 640 ; bufSize += 32)
       
    59         {
       
    60         RFile resultSource;
       
    61         TInt err = resultSource.Create(iFsSession, KSampleSubtitleTempFilepath, EFileRead | EFileWrite);
       
    62         if (KErrAlreadyExists == err)
       
    63             {
       
    64             User::LeaveIfError(resultSource.Open(iFsSession, KSampleSubtitleTempFilepath, EFileRead | EFileWrite));
       
    65             }
       
    66         else
       
    67             {
       
    68             User::LeaveIfError(err);
       
    69             }
       
    70         
       
    71         CleanupClosePushL(resultSource);
       
    72         
       
    73         HBufC8 *buf = HBufC8::NewL(bufSize);
       
    74         CleanupStack::PushL(buf);
       
    75         
       
    76         CSrtReader* srtReader = CSrtReader::NewL(KSampleSubtitleSRTFilepath);
       
    77         CleanupStack::PushL(srtReader);
       
    78 
       
    79         TInt error = KErrNone;
       
    80         
       
    81         while(KErrNone == error)
       
    82             {
       
    83             TPtr8 ptr8 = buf->Des();
       
    84             error = srtReader->GetBuffer(ptr8);
       
    85             
       
    86             if (ptr8.Length() > 0)
       
    87                 {
       
    88                 User::LeaveIfError(resultSource.Write(ptr8));
       
    89                 }
       
    90             }
       
    91          
       
    92         CleanupStack::PopAndDestroy(srtReader);
       
    93         CleanupStack::PopAndDestroy(buf);
       
    94         CleanupStack::PopAndDestroy(&resultSource);
       
    95         
       
    96         if (bufSize == 0)
       
    97             {
       
    98             if (error != KErrArgument)
       
    99                 {
       
   100                 ERR_PRINTF3(_L("Error - CSrtReader::GetBuffer returned %d when the buffer is set to %d byte"), error, bufSize);
       
   101                 result = EFail;
       
   102                 }
       
   103             }
       
   104         else
       
   105             {
       
   106             if (error != KErrEof)
       
   107                 {
       
   108                 ERR_PRINTF3(_L("Error - CSrtReader::GetBuffer returned %d when the buffer is set to %d bytes"), error, bufSize);
       
   109                 result = EFail;
       
   110                 }
       
   111             else
       
   112                 {
       
   113                 // compare KSampleSubtitleSRTFilepath with KSampleSubtitleTempFilepath
       
   114                 if (!RTestSrtDecoderStep::CompareFilesL(iFsSession, KSampleSubtitleSRTFilepath, KSampleSubtitleTempFilepath))
       
   115                     {
       
   116                     ERR_PRINTF1(_L("Error - the result file does not match the original file. "));
       
   117                     result = EFail;
       
   118                     }
       
   119                 }
       
   120             }
       
   121         
       
   122         if (BaflUtils::FileExists(iFsSession, KSampleSubtitleTempFilepath))
       
   123             {
       
   124             User::LeaveIfError(BaflUtils::DeleteFile(iFsSession, KSampleSubtitleTempFilepath));  
       
   125             }
       
   126         }
       
   127 
       
   128     INFO_PRINTF1(_L("Exit DoTestStepL"));
       
   129 	return result;
       
   130 	}
       
   131 
       
   132 
       
   133 // Implementation of RTestSrtReaderStep0100
       
   134 
       
   135 RTestSrtReaderStep0100::RTestSrtReaderStep0100()
       
   136 	{
       
   137 	iTestStepName = _L("MM-MMF-SUBTITLE-SRTREADER-U-0100-HP");
       
   138 	}
       
   139 	
       
   140 TVerdict RTestSrtReaderStep0100::DoTestStepL()
       
   141 	{
       
   142 	INFO_PRINTF1(_L("Enter DoTestStepL"));
       
   143 	TInt expectedErr = KErrNotFound;
       
   144 	
       
   145 	__MM_HEAP_MARK
       
   146 	
       
   147 	TVerdict result = EPass;
       
   148 	
       
   149 	TRAPD(err, CSrtReader* srtReader = CSrtReader::NewL(KSampleSubtitleBogusFilepath));
       
   150 	
       
   151     if (err != expectedErr)
       
   152         {
       
   153         ERR_PRINTF2(_L("Error - CSrtReader constructor returned %d for a bogus srt source. "), err);
       
   154         result = EFail;
       
   155         }
       
   156 
       
   157     __MM_HEAP_MARKEND;
       
   158     
       
   159     INFO_PRINTF1(_L("Exit DoTestStepL"));
       
   160     
       
   161 	return result;
       
   162 	}
       
   163 
       
   164 
       
   165