sl@0: // Copyright (c) 2002-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: // EPOC includes sl@0: #include sl@0: sl@0: #include // for TMMFFileParams and CMMFFile sl@0: #include // For CMMFFormatDecode sl@0: #include // for TMMFDescriptorParams and CMMFDescriptor sl@0: #include sl@0: #include // for KMmfUidFormatWAVRead UIDs sl@0: sl@0: sl@0: // Test system includes sl@0: #include "TSU_MMF_AFMT.h" sl@0: #include "TSU_MMF_AFMTSuite.h" sl@0: sl@0: sl@0: /** sl@0: * This function creates a datasource object based on either a descriptor sl@0: * or a file. sl@0: * @param aFile - If 'ETrue', datasource if file based, else it's descriptor based. sl@0: * @param aFilename - If filebased, this is the file name passed to the DataSource sl@0: * If descriptor based, the data is read from the file. sl@0: * @param aOffset - The offset from the start of the file to read (for Descriptor sl@0: * based DataSources only) sl@0: */ sl@0: void CTestStep_MMF_AFMT::CreateDataSource(const TBool& aFile, const TDesC& aFilename, sl@0: const TUint& aOffset) sl@0: { sl@0: if (aFile) sl@0: { // File based DataSource (making a CMMFFile object) sl@0: TMMFFileParams fileParams ; sl@0: fileParams.iPath = TFileName(aFilename) ; sl@0: TMMFFileConfig fileConfig( fileParams ) ; sl@0: sl@0: // Create the iDataSource object. sl@0: iDataSource = STATIC_CAST(CMMFFile*, MDataSource::NewSourceL( KUidMmfFileSource, sl@0: *STATIC_CAST(TDesC8*,&fileConfig))); sl@0: } sl@0: else sl@0: { // Descriptor based DataSource sl@0: // Reads first 4k buffer from file + puts in iData. sl@0: ReadFileToDescriptorL(aFilename, aOffset, KFormatDefaultFrameSize); sl@0: sl@0: // Create parameters for the DataSource sl@0: RThread thread; sl@0: TMMFDescriptorParams descParams; sl@0: descParams.iDes = &iData; sl@0: descParams.iDesThreadId = thread.Id(); // This thread sl@0: TMMFDescriptorConfig descConfig(descParams); sl@0: sl@0: // Create the MDataSource object. sl@0: iDataSource = STATIC_CAST(CMMFDescriptor*, MDataSource::NewSourceL( sl@0: KUidMmfDescriptorSource, sl@0: *STATIC_CAST(TDesC8*,&descConfig) sl@0: )); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: * This function creates a data sink object from a CMmfFile object. sl@0: * @param aFile - If 'ETrue', datasource if file based, else it's descriptor based [NOTE sl@0: * use of CMmfDescriptor based sinks is currently not supported] sl@0: * @param aFilename - If filebased, this is the file name passed to the DataSource sl@0: * If descriptor based, the data is read from the file. sl@0: * @param aOffset - The offset from the start of the file to read (for Descriptor sl@0: * based DataSources only) sl@0: */ sl@0: void CTestStep_MMF_AFMT::CreateDataSink(const TBool& aFile, const TDesC& aFilename, sl@0: const TUint& /*aOffset*/) sl@0: { sl@0: TInt err = KErrNone; sl@0: sl@0: if (aFile) sl@0: { // File based DataSink (making a CMMFFile object) sl@0: TMMFFileParams fileParams ; sl@0: fileParams.iPath = TFileName(aFilename) ; sl@0: TMMFFileConfig fileConfig( fileParams ) ; sl@0: sl@0: TRAP(err, iDataSink = STATIC_CAST(CMMFFile*, MDataSink::NewSinkL( KUidMmfFileSink, sl@0: *STATIC_CAST(TDesC8*,&fileConfig)))); sl@0: } sl@0: else sl@0: { // Descriptor based DataSink sl@0: // Not sure how to code this bit up yet, so leave with Not Supported. sl@0: // User::Leave(KErrNotSupported); sl@0: // Reads first 4k buffer from file + puts in iData. sl@0: // ReadFileToDescriptorL(aFilename, aOffset, KFormatDefaultFrameSize); sl@0: TRAP(err, sl@0: iDescHBuf = HBufC8::NewL(0x1000); sl@0: TPtr8 dataBuf = iDescHBuf->Des(); sl@0: sl@0: iData.Set(dataBuf); sl@0: sl@0: // Create parameters for the DataSource sl@0: RThread thread; sl@0: TMMFDescriptorParams descParams; sl@0: descParams.iDes = &iData; sl@0: descParams.iDesThreadId = thread.Id(); // This thread sl@0: TMMFDescriptorConfig descConfig(descParams); sl@0: sl@0: // Create the MDataSource object. sl@0: iDataSink = STATIC_CAST(CMMFDescriptor*, MDataSink::NewSinkL( sl@0: KUidMmfDescriptorSink, sl@0: *STATIC_CAST(TDesC8*,&descConfig) sl@0: )); sl@0: ); sl@0: } sl@0: sl@0: // Check for errors sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("CreateDataSink failed with error code %d"), err); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: * This function creates a Format object (type of which is specified by 'aUid') and sl@0: * a data source or data sink to go with the object. This function should be used sl@0: * as a quick way for setting up objects for testing. sl@0: * @param aIsFile - ETrue if we are using CMmfFile or EFalse if using sl@0: * CMmfDescriptor as the DataSource. NOTE: CMmfDescriptor support has not sl@0: * yet been added to this test harness for SINKs. Generally it's best to just use sl@0: * CMmfFile based data sources rather than descriptors. sl@0: * @param aFilename - The file which acts as the data sink. For a CMmfFile sl@0: * based object, this is the file that data gets written to. sl@0: * @param aUid - The UID of the format object to be created. sl@0: */ sl@0: void CTestStep_MMF_AFMT::CreateObjectL(TBool aIsFile, const TDesC& aFilename, TInt aUid) sl@0: { sl@0: // Use the UID to work out whether we want a Source/Read or Sink/Write pair sl@0: switch (aUid) sl@0: { sl@0: case KMmfUidFormatAUWrite: sl@0: case KMmfUidFormatRAWWrite: sl@0: case KMmfUidFormatWAVWrite: sl@0: // Create the CMMFWavFormatWrite object. sl@0: CreateEncodeObjectL(aIsFile, aFilename, aUid); sl@0: iDecode = EFalse; sl@0: break; sl@0: sl@0: case KMmfUidFormatAURead: sl@0: case KMmfUidFormatRAWRead: sl@0: case KMmfUidFormatWAVRead: sl@0: // Create the CMMFWavFormatRead object. sl@0: CreateDecodeObjectL(aIsFile, aFilename, aUid); sl@0: iDecode = ETrue; sl@0: break; sl@0: default: sl@0: INFO_PRINTF1(_L("Leaving from Setup as UID not supported")); sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: * This function is used as a quick way to setup objects for testing. sl@0: * @param aFilename - The file which acts as the data sink. For a CMmfFile sl@0: * based object, this is the file that data gets read/written. sl@0: * @param aUid - The UID of the format object to be created. sl@0: * @return TVerdict - Will always return EPass unless it leaves. sl@0: */ sl@0: TVerdict CTestStep_MMF_AFMT::SetupL(const TDesC& aFilename, TInt aUid) sl@0: { sl@0: CreateObjectL(ETrue, aFilename, aUid); sl@0: return EPass; sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: * This function deletes all of the pointer member variables which may have been sl@0: * initialised. sl@0: */ sl@0: void CTestStep_MMF_AFMT::Cleanup() sl@0: { sl@0: if (iFormatDec) sl@0: { sl@0: iFormatDec->SourceThreadLogoff(); sl@0: } sl@0: if (iFormatEnc) sl@0: { sl@0: iFormatEnc->SourceThreadLogoff(); sl@0: } sl@0: sl@0: sl@0: // Tidyup sl@0: delete iDataSource; iDataSource = NULL; sl@0: delete iFormatDec; iFormatDec = NULL; sl@0: delete iFormatEnc; iFormatEnc = NULL; sl@0: delete iDataSink; iDataSink = NULL; sl@0: delete iDescHBuf; iDescHBuf = NULL; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: * This function reads from a source file into the member variable heap buffer, 'iDescHBuf'. sl@0: * This can be used to compare the contents of a file with a buffer for example. sl@0: * @param aFilename - The file to read from. sl@0: * @param aPosition - Where to start reading from in the file. sl@0: * @param aSize - How much of the file to read (in bytes) though if you pass '-1', it will sl@0: * try and read the whole file from 'aPosition' onwards. sl@0: */ sl@0: void CTestStep_MMF_AFMT::ReadFileToDescriptorL(const TDesC& aFilename, sl@0: TInt aPosition, sl@0: TInt aSize) sl@0: { sl@0: RFs rfs; sl@0: rfs.Connect(); sl@0: RFile file; sl@0: sl@0: // Try to open the file. sl@0: User::LeaveIfError( file.Open(rfs,aFilename,EFileRead|EFileShareAny) ); sl@0: sl@0: // Create the databuffer in which to store the data. sl@0: TInt fileSize = 0; sl@0: file.Size(fileSize); sl@0: if (aSize == -1) // if -1, use whole file size sl@0: iDescHBuf = HBufC8::NewL(fileSize-aPosition); sl@0: else sl@0: iDescHBuf = HBufC8::NewL(aSize); sl@0: TPtr8 dataBuf = iDescHBuf->Des(); sl@0: sl@0: // Check we are not trying to read past the end of the file... sl@0: if (fileSize< (aPosition+aSize) ) sl@0: User::Leave(KErrEof); sl@0: sl@0: // Seek to the place we want to start reading from sl@0: TInt offset = aPosition; sl@0: file.Seek(ESeekStart, offset); sl@0: sl@0: // Read the data from the file to the data buffer sl@0: sl@0: if(aSize == -1) sl@0: { sl@0: User::LeaveIfError(file.Read(dataBuf,fileSize-aPosition)); sl@0: } sl@0: else sl@0: { sl@0: User::LeaveIfError(file.Read(dataBuf, aSize)); sl@0: } sl@0: sl@0: iData.Set(dataBuf); sl@0: sl@0: file.Close(); sl@0: rfs.Close(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: * This function can be used to make sure that a specified file is not present sl@0: * before a set of tests are run. sl@0: * @param aFilename - The name of the file to delete/check is not present. sl@0: */ sl@0: void CTestStep_MMF_AFMT::DeleteFileL(const TDesC& aFilename) sl@0: { sl@0: RFs fs; sl@0: User::LeaveIfError( fs.Connect() ); sl@0: TInt ret = fs.Delete(aFilename); sl@0: if (ret != KErrNone && ret != KErrNotFound) sl@0: User::Leave(ret); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: * This function creates a datasource object based on either a descriptor sl@0: * or a file. sl@0: * @param aIsFile - ETrue if we are using CMmfFile or EFalse if using sl@0: * CMmfDescriptor as the DataSource sl@0: * @param aFilename - The file which acts as the data source. For a CMmfFile sl@0: * based object, this IS the file. For a CMmfDescriptor based object, this sl@0: * file contains the data that is read into the descriptor for test purposes. sl@0: * @param aUid - The UID of the format object to be created. sl@0: */ sl@0: void CTestStep_MMF_AFMT::CreateDecodeObjectL(TBool aIsFile, const TDesC& aFilename, TInt aUid) sl@0: { sl@0: // Create the datasource (stored in iDataSource) sl@0: CreateDataSource(aIsFile, aFilename); sl@0: sl@0: iUID = TUid::Uid(aUid); sl@0: sl@0: // Make the NewL call. sl@0: iFormatDec = CMMFFormatDecode::NewL( iUID, iDataSource); sl@0: sl@0: User::LeaveIfError(iFormatDec->SourceThreadLogon(*this)); sl@0: iFormatDec->SourcePrimeL(); sl@0: } sl@0: sl@0: /** sl@0: * This function creates a datasink object based on either a descriptor sl@0: * or a file. sl@0: * @param aIsFile - ETrue if we are using CMmfFile or EFalse if using sl@0: * CMmfDescriptor as the DataSource. NOTE: CMmfDescriptor support has not sl@0: * yet been added to this test harness for SINKs. sl@0: * @param aFilename - The file which acts as the data sink. For a CMmfFile sl@0: * based object, this IS the file. sl@0: * @param aUid - The UID of the format object to be created. sl@0: */ sl@0: void CTestStep_MMF_AFMT::CreateEncodeObjectL(TBool aIsFile, const TDesC& aFilename, TInt aUid) sl@0: { sl@0: // Create the data sink (stored in iDataSink) sl@0: CreateDataSink(aIsFile, aFilename); sl@0: sl@0: iUID = TUid::Uid(aUid); sl@0: sl@0: // Make the NewL call. sl@0: iFormatEnc = CMMFFormatEncode::NewL( iUID, iDataSink); sl@0: sl@0: User::LeaveIfError(iFormatEnc->SourceThreadLogon(*this)); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * Destructor for this class. sl@0: * sl@0: */ sl@0: CTestStep_MMF_AFMT::~CTestStep_MMF_AFMT() sl@0: { sl@0: Cleanup(); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * Close sl@0: * sl@0: */ sl@0: void CTestStep_MMF_AFMT::Close() sl@0: { sl@0: Cleanup(); sl@0: } sl@0: