Update contrib.
1 // Copyright (c) 2002-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.
19 #include <mmf/server/mmffile.h> // for TMMFFileParams and CMMFFile
20 #include <mmf/server/mmfformat.h> // For CMMFFormatDecode
21 #include <mmf/server/mmfdes.h> // for TMMFDescriptorParams and CMMFDescriptor
22 #include <mmf/server/mmfdatasource.h>
23 #include <mmf/plugin/mmfformatimplementationuids.hrh> // for KMmfUidFormatWAVRead UIDs
26 // Test system includes
27 #include "TSU_MMF_AFMT.h"
28 #include "TSU_MMF_AFMTSuite.h"
32 * This function creates a datasource object based on either a descriptor
34 * @param aFile - If 'ETrue', datasource if file based, else it's descriptor based.
35 * @param aFilename - If filebased, this is the file name passed to the DataSource
36 * If descriptor based, the data is read from the file.
37 * @param aOffset - The offset from the start of the file to read (for Descriptor
38 * based DataSources only)
40 void CTestStep_MMF_AFMT::CreateDataSource(const TBool& aFile, const TDesC& aFilename,
44 { // File based DataSource (making a CMMFFile object)
45 TMMFFileParams fileParams ;
46 fileParams.iPath = TFileName(aFilename) ;
47 TMMFFileConfig fileConfig( fileParams ) ;
49 // Create the iDataSource object.
50 iDataSource = STATIC_CAST(CMMFFile*, MDataSource::NewSourceL( KUidMmfFileSource,
51 *STATIC_CAST(TDesC8*,&fileConfig)));
54 { // Descriptor based DataSource
55 // Reads first 4k buffer from file + puts in iData.
56 ReadFileToDescriptorL(aFilename, aOffset, KFormatDefaultFrameSize);
58 // Create parameters for the DataSource
60 TMMFDescriptorParams descParams;
61 descParams.iDes = &iData;
62 descParams.iDesThreadId = thread.Id(); // This thread
63 TMMFDescriptorConfig descConfig(descParams);
65 // Create the MDataSource object.
66 iDataSource = STATIC_CAST(CMMFDescriptor*, MDataSource::NewSourceL(
67 KUidMmfDescriptorSource,
68 *STATIC_CAST(TDesC8*,&descConfig)
77 * This function creates a data sink object from a CMmfFile object.
78 * @param aFile - If 'ETrue', datasource if file based, else it's descriptor based [NOTE
79 * use of CMmfDescriptor based sinks is currently not supported]
80 * @param aFilename - If filebased, this is the file name passed to the DataSource
81 * If descriptor based, the data is read from the file.
82 * @param aOffset - The offset from the start of the file to read (for Descriptor
83 * based DataSources only)
85 void CTestStep_MMF_AFMT::CreateDataSink(const TBool& aFile, const TDesC& aFilename,
86 const TUint& /*aOffset*/)
91 { // File based DataSink (making a CMMFFile object)
92 TMMFFileParams fileParams ;
93 fileParams.iPath = TFileName(aFilename) ;
94 TMMFFileConfig fileConfig( fileParams ) ;
96 TRAP(err, iDataSink = STATIC_CAST(CMMFFile*, MDataSink::NewSinkL( KUidMmfFileSink,
97 *STATIC_CAST(TDesC8*,&fileConfig))));
100 { // Descriptor based DataSink
101 // Not sure how to code this bit up yet, so leave with Not Supported.
102 // User::Leave(KErrNotSupported);
103 // Reads first 4k buffer from file + puts in iData.
104 // ReadFileToDescriptorL(aFilename, aOffset, KFormatDefaultFrameSize);
106 iDescHBuf = HBufC8::NewL(0x1000);
107 TPtr8 dataBuf = iDescHBuf->Des();
111 // Create parameters for the DataSource
113 TMMFDescriptorParams descParams;
114 descParams.iDes = &iData;
115 descParams.iDesThreadId = thread.Id(); // This thread
116 TMMFDescriptorConfig descConfig(descParams);
118 // Create the MDataSource object.
119 iDataSink = STATIC_CAST(CMMFDescriptor*, MDataSink::NewSinkL(
120 KUidMmfDescriptorSink,
121 *STATIC_CAST(TDesC8*,&descConfig)
129 ERR_PRINTF2(_L("CreateDataSink failed with error code %d"), err);
137 * This function creates a Format object (type of which is specified by 'aUid') and
138 * a data source or data sink to go with the object. This function should be used
139 * as a quick way for setting up objects for testing.
140 * @param aIsFile - ETrue if we are using CMmfFile or EFalse if using
141 * CMmfDescriptor as the DataSource. NOTE: CMmfDescriptor support has not
142 * yet been added to this test harness for SINKs. Generally it's best to just use
143 * CMmfFile based data sources rather than descriptors.
144 * @param aFilename - The file which acts as the data sink. For a CMmfFile
145 * based object, this is the file that data gets written to.
146 * @param aUid - The UID of the format object to be created.
148 void CTestStep_MMF_AFMT::CreateObjectL(TBool aIsFile, const TDesC& aFilename, TInt aUid)
150 // Use the UID to work out whether we want a Source/Read or Sink/Write pair
153 case KMmfUidFormatAUWrite:
154 case KMmfUidFormatRAWWrite:
155 case KMmfUidFormatWAVWrite:
156 // Create the CMMFWavFormatWrite object.
157 CreateEncodeObjectL(aIsFile, aFilename, aUid);
161 case KMmfUidFormatAURead:
162 case KMmfUidFormatRAWRead:
163 case KMmfUidFormatWAVRead:
164 // Create the CMMFWavFormatRead object.
165 CreateDecodeObjectL(aIsFile, aFilename, aUid);
169 INFO_PRINTF1(_L("Leaving from Setup as UID not supported"));
170 User::Leave(KErrNotSupported);
177 * This function is used as a quick way to setup objects for testing.
178 * @param aFilename - The file which acts as the data sink. For a CMmfFile
179 * based object, this is the file that data gets read/written.
180 * @param aUid - The UID of the format object to be created.
181 * @return TVerdict - Will always return EPass unless it leaves.
183 TVerdict CTestStep_MMF_AFMT::SetupL(const TDesC& aFilename, TInt aUid)
185 CreateObjectL(ETrue, aFilename, aUid);
192 * This function deletes all of the pointer member variables which may have been
195 void CTestStep_MMF_AFMT::Cleanup()
199 iFormatDec->SourceThreadLogoff();
203 iFormatEnc->SourceThreadLogoff();
208 delete iDataSource; iDataSource = NULL;
209 delete iFormatDec; iFormatDec = NULL;
210 delete iFormatEnc; iFormatEnc = NULL;
211 delete iDataSink; iDataSink = NULL;
212 delete iDescHBuf; iDescHBuf = NULL;
220 * This function reads from a source file into the member variable heap buffer, 'iDescHBuf'.
221 * This can be used to compare the contents of a file with a buffer for example.
222 * @param aFilename - The file to read from.
223 * @param aPosition - Where to start reading from in the file.
224 * @param aSize - How much of the file to read (in bytes) though if you pass '-1', it will
225 * try and read the whole file from 'aPosition' onwards.
227 void CTestStep_MMF_AFMT::ReadFileToDescriptorL(const TDesC& aFilename,
235 // Try to open the file.
236 User::LeaveIfError( file.Open(rfs,aFilename,EFileRead|EFileShareAny) );
238 // Create the databuffer in which to store the data.
241 if (aSize == -1) // if -1, use whole file size
242 iDescHBuf = HBufC8::NewL(fileSize-aPosition);
244 iDescHBuf = HBufC8::NewL(aSize);
245 TPtr8 dataBuf = iDescHBuf->Des();
247 // Check we are not trying to read past the end of the file...
248 if (fileSize< (aPosition+aSize) )
249 User::Leave(KErrEof);
251 // Seek to the place we want to start reading from
252 TInt offset = aPosition;
253 file.Seek(ESeekStart, offset);
255 // Read the data from the file to the data buffer
259 User::LeaveIfError(file.Read(dataBuf,fileSize-aPosition));
263 User::LeaveIfError(file.Read(dataBuf, aSize));
277 * This function can be used to make sure that a specified file is not present
278 * before a set of tests are run.
279 * @param aFilename - The name of the file to delete/check is not present.
281 void CTestStep_MMF_AFMT::DeleteFileL(const TDesC& aFilename)
284 User::LeaveIfError( fs.Connect() );
285 TInt ret = fs.Delete(aFilename);
286 if (ret != KErrNone && ret != KErrNotFound)
294 * This function creates a datasource object based on either a descriptor
296 * @param aIsFile - ETrue if we are using CMmfFile or EFalse if using
297 * CMmfDescriptor as the DataSource
298 * @param aFilename - The file which acts as the data source. For a CMmfFile
299 * based object, this IS the file. For a CMmfDescriptor based object, this
300 * file contains the data that is read into the descriptor for test purposes.
301 * @param aUid - The UID of the format object to be created.
303 void CTestStep_MMF_AFMT::CreateDecodeObjectL(TBool aIsFile, const TDesC& aFilename, TInt aUid)
305 // Create the datasource (stored in iDataSource)
306 CreateDataSource(aIsFile, aFilename);
308 iUID = TUid::Uid(aUid);
310 // Make the NewL call.
311 iFormatDec = CMMFFormatDecode::NewL( iUID, iDataSource);
313 User::LeaveIfError(iFormatDec->SourceThreadLogon(*this));
314 iFormatDec->SourcePrimeL();
318 * This function creates a datasink object based on either a descriptor
320 * @param aIsFile - ETrue if we are using CMmfFile or EFalse if using
321 * CMmfDescriptor as the DataSource. NOTE: CMmfDescriptor support has not
322 * yet been added to this test harness for SINKs.
323 * @param aFilename - The file which acts as the data sink. For a CMmfFile
324 * based object, this IS the file.
325 * @param aUid - The UID of the format object to be created.
327 void CTestStep_MMF_AFMT::CreateEncodeObjectL(TBool aIsFile, const TDesC& aFilename, TInt aUid)
329 // Create the data sink (stored in iDataSink)
330 CreateDataSink(aIsFile, aFilename);
332 iUID = TUid::Uid(aUid);
334 // Make the NewL call.
335 iFormatEnc = CMMFFormatEncode::NewL( iUID, iDataSink);
337 User::LeaveIfError(iFormatEnc->SourceThreadLogon(*this));
342 * Destructor for this class.
345 CTestStep_MMF_AFMT::~CTestStep_MMF_AFMT()
355 void CTestStep_MMF_AFMT::Close()