sl@0
|
1 |
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
// EPOC includes
|
sl@0
|
17 |
#include <e32base.h>
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <mmf/server/mmffile.h> // for TMMFFileParams and CMMFFile
|
sl@0
|
20 |
#include <mmf/server/mmfformat.h> // For CMMFFormatDecode
|
sl@0
|
21 |
#include <mmf/server/mmfdes.h> // for TMMFDescriptorParams and CMMFDescriptor
|
sl@0
|
22 |
#include <mmf/server/mmfdatasource.h>
|
sl@0
|
23 |
#include <mmf/plugin/mmfformatimplementationuids.hrh> // for KMmfUidFormatWAVRead UIDs
|
sl@0
|
24 |
|
sl@0
|
25 |
|
sl@0
|
26 |
// Test system includes
|
sl@0
|
27 |
#include "TSU_MMF_AFMT.h"
|
sl@0
|
28 |
#include "TSU_MMF_AFMTSuite.h"
|
sl@0
|
29 |
|
sl@0
|
30 |
|
sl@0
|
31 |
/**
|
sl@0
|
32 |
* This function creates a datasource object based on either a descriptor
|
sl@0
|
33 |
* or a file.
|
sl@0
|
34 |
* @param aFile - If 'ETrue', datasource if file based, else it's descriptor based.
|
sl@0
|
35 |
* @param aFilename - If filebased, this is the file name passed to the DataSource
|
sl@0
|
36 |
* If descriptor based, the data is read from the file.
|
sl@0
|
37 |
* @param aOffset - The offset from the start of the file to read (for Descriptor
|
sl@0
|
38 |
* based DataSources only)
|
sl@0
|
39 |
*/
|
sl@0
|
40 |
void CTestStep_MMF_AFMT::CreateDataSource(const TBool& aFile, const TDesC& aFilename,
|
sl@0
|
41 |
const TUint& aOffset)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
if (aFile)
|
sl@0
|
44 |
{ // File based DataSource (making a CMMFFile object)
|
sl@0
|
45 |
TMMFFileParams fileParams ;
|
sl@0
|
46 |
fileParams.iPath = TFileName(aFilename) ;
|
sl@0
|
47 |
TMMFFileConfig fileConfig( fileParams ) ;
|
sl@0
|
48 |
|
sl@0
|
49 |
// Create the iDataSource object.
|
sl@0
|
50 |
iDataSource = STATIC_CAST(CMMFFile*, MDataSource::NewSourceL( KUidMmfFileSource,
|
sl@0
|
51 |
*STATIC_CAST(TDesC8*,&fileConfig)));
|
sl@0
|
52 |
}
|
sl@0
|
53 |
else
|
sl@0
|
54 |
{ // Descriptor based DataSource
|
sl@0
|
55 |
// Reads first 4k buffer from file + puts in iData.
|
sl@0
|
56 |
ReadFileToDescriptorL(aFilename, aOffset, KFormatDefaultFrameSize);
|
sl@0
|
57 |
|
sl@0
|
58 |
// Create parameters for the DataSource
|
sl@0
|
59 |
RThread thread;
|
sl@0
|
60 |
TMMFDescriptorParams descParams;
|
sl@0
|
61 |
descParams.iDes = &iData;
|
sl@0
|
62 |
descParams.iDesThreadId = thread.Id(); // This thread
|
sl@0
|
63 |
TMMFDescriptorConfig descConfig(descParams);
|
sl@0
|
64 |
|
sl@0
|
65 |
// Create the MDataSource object.
|
sl@0
|
66 |
iDataSource = STATIC_CAST(CMMFDescriptor*, MDataSource::NewSourceL(
|
sl@0
|
67 |
KUidMmfDescriptorSource,
|
sl@0
|
68 |
*STATIC_CAST(TDesC8*,&descConfig)
|
sl@0
|
69 |
));
|
sl@0
|
70 |
}
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
|
sl@0
|
74 |
|
sl@0
|
75 |
|
sl@0
|
76 |
/**
|
sl@0
|
77 |
* This function creates a data sink object from a CMmfFile object.
|
sl@0
|
78 |
* @param aFile - If 'ETrue', datasource if file based, else it's descriptor based [NOTE
|
sl@0
|
79 |
* use of CMmfDescriptor based sinks is currently not supported]
|
sl@0
|
80 |
* @param aFilename - If filebased, this is the file name passed to the DataSource
|
sl@0
|
81 |
* If descriptor based, the data is read from the file.
|
sl@0
|
82 |
* @param aOffset - The offset from the start of the file to read (for Descriptor
|
sl@0
|
83 |
* based DataSources only)
|
sl@0
|
84 |
*/
|
sl@0
|
85 |
void CTestStep_MMF_AFMT::CreateDataSink(const TBool& aFile, const TDesC& aFilename,
|
sl@0
|
86 |
const TUint& /*aOffset*/)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
TInt err = KErrNone;
|
sl@0
|
89 |
|
sl@0
|
90 |
if (aFile)
|
sl@0
|
91 |
{ // File based DataSink (making a CMMFFile object)
|
sl@0
|
92 |
TMMFFileParams fileParams ;
|
sl@0
|
93 |
fileParams.iPath = TFileName(aFilename) ;
|
sl@0
|
94 |
TMMFFileConfig fileConfig( fileParams ) ;
|
sl@0
|
95 |
|
sl@0
|
96 |
TRAP(err, iDataSink = STATIC_CAST(CMMFFile*, MDataSink::NewSinkL( KUidMmfFileSink,
|
sl@0
|
97 |
*STATIC_CAST(TDesC8*,&fileConfig))));
|
sl@0
|
98 |
}
|
sl@0
|
99 |
else
|
sl@0
|
100 |
{ // Descriptor based DataSink
|
sl@0
|
101 |
// Not sure how to code this bit up yet, so leave with Not Supported.
|
sl@0
|
102 |
// User::Leave(KErrNotSupported);
|
sl@0
|
103 |
// Reads first 4k buffer from file + puts in iData.
|
sl@0
|
104 |
// ReadFileToDescriptorL(aFilename, aOffset, KFormatDefaultFrameSize);
|
sl@0
|
105 |
TRAP(err,
|
sl@0
|
106 |
iDescHBuf = HBufC8::NewL(0x1000);
|
sl@0
|
107 |
TPtr8 dataBuf = iDescHBuf->Des();
|
sl@0
|
108 |
|
sl@0
|
109 |
iData.Set(dataBuf);
|
sl@0
|
110 |
|
sl@0
|
111 |
// Create parameters for the DataSource
|
sl@0
|
112 |
RThread thread;
|
sl@0
|
113 |
TMMFDescriptorParams descParams;
|
sl@0
|
114 |
descParams.iDes = &iData;
|
sl@0
|
115 |
descParams.iDesThreadId = thread.Id(); // This thread
|
sl@0
|
116 |
TMMFDescriptorConfig descConfig(descParams);
|
sl@0
|
117 |
|
sl@0
|
118 |
// Create the MDataSource object.
|
sl@0
|
119 |
iDataSink = STATIC_CAST(CMMFDescriptor*, MDataSink::NewSinkL(
|
sl@0
|
120 |
KUidMmfDescriptorSink,
|
sl@0
|
121 |
*STATIC_CAST(TDesC8*,&descConfig)
|
sl@0
|
122 |
));
|
sl@0
|
123 |
);
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
// Check for errors
|
sl@0
|
127 |
if (err != KErrNone)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
ERR_PRINTF2(_L("CreateDataSink failed with error code %d"), err);
|
sl@0
|
130 |
}
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
|
sl@0
|
134 |
|
sl@0
|
135 |
|
sl@0
|
136 |
/**
|
sl@0
|
137 |
* This function creates a Format object (type of which is specified by 'aUid') and
|
sl@0
|
138 |
* a data source or data sink to go with the object. This function should be used
|
sl@0
|
139 |
* as a quick way for setting up objects for testing.
|
sl@0
|
140 |
* @param aIsFile - ETrue if we are using CMmfFile or EFalse if using
|
sl@0
|
141 |
* CMmfDescriptor as the DataSource. NOTE: CMmfDescriptor support has not
|
sl@0
|
142 |
* yet been added to this test harness for SINKs. Generally it's best to just use
|
sl@0
|
143 |
* CMmfFile based data sources rather than descriptors.
|
sl@0
|
144 |
* @param aFilename - The file which acts as the data sink. For a CMmfFile
|
sl@0
|
145 |
* based object, this is the file that data gets written to.
|
sl@0
|
146 |
* @param aUid - The UID of the format object to be created.
|
sl@0
|
147 |
*/
|
sl@0
|
148 |
void CTestStep_MMF_AFMT::CreateObjectL(TBool aIsFile, const TDesC& aFilename, TInt aUid)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
// Use the UID to work out whether we want a Source/Read or Sink/Write pair
|
sl@0
|
151 |
switch (aUid)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
case KMmfUidFormatAUWrite:
|
sl@0
|
154 |
case KMmfUidFormatRAWWrite:
|
sl@0
|
155 |
case KMmfUidFormatWAVWrite:
|
sl@0
|
156 |
// Create the CMMFWavFormatWrite object.
|
sl@0
|
157 |
CreateEncodeObjectL(aIsFile, aFilename, aUid);
|
sl@0
|
158 |
iDecode = EFalse;
|
sl@0
|
159 |
break;
|
sl@0
|
160 |
|
sl@0
|
161 |
case KMmfUidFormatAURead:
|
sl@0
|
162 |
case KMmfUidFormatRAWRead:
|
sl@0
|
163 |
case KMmfUidFormatWAVRead:
|
sl@0
|
164 |
// Create the CMMFWavFormatRead object.
|
sl@0
|
165 |
CreateDecodeObjectL(aIsFile, aFilename, aUid);
|
sl@0
|
166 |
iDecode = ETrue;
|
sl@0
|
167 |
break;
|
sl@0
|
168 |
default:
|
sl@0
|
169 |
INFO_PRINTF1(_L("Leaving from Setup as UID not supported"));
|
sl@0
|
170 |
User::Leave(KErrNotSupported);
|
sl@0
|
171 |
}
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
|
sl@0
|
175 |
|
sl@0
|
176 |
/**
|
sl@0
|
177 |
* This function is used as a quick way to setup objects for testing.
|
sl@0
|
178 |
* @param aFilename - The file which acts as the data sink. For a CMmfFile
|
sl@0
|
179 |
* based object, this is the file that data gets read/written.
|
sl@0
|
180 |
* @param aUid - The UID of the format object to be created.
|
sl@0
|
181 |
* @return TVerdict - Will always return EPass unless it leaves.
|
sl@0
|
182 |
*/
|
sl@0
|
183 |
TVerdict CTestStep_MMF_AFMT::SetupL(const TDesC& aFilename, TInt aUid)
|
sl@0
|
184 |
{
|
sl@0
|
185 |
CreateObjectL(ETrue, aFilename, aUid);
|
sl@0
|
186 |
return EPass;
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
|
sl@0
|
190 |
|
sl@0
|
191 |
/**
|
sl@0
|
192 |
* This function deletes all of the pointer member variables which may have been
|
sl@0
|
193 |
* initialised.
|
sl@0
|
194 |
*/
|
sl@0
|
195 |
void CTestStep_MMF_AFMT::Cleanup()
|
sl@0
|
196 |
{
|
sl@0
|
197 |
if (iFormatDec)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
iFormatDec->SourceThreadLogoff();
|
sl@0
|
200 |
}
|
sl@0
|
201 |
if (iFormatEnc)
|
sl@0
|
202 |
{
|
sl@0
|
203 |
iFormatEnc->SourceThreadLogoff();
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
|
sl@0
|
207 |
// Tidyup
|
sl@0
|
208 |
delete iDataSource; iDataSource = NULL;
|
sl@0
|
209 |
delete iFormatDec; iFormatDec = NULL;
|
sl@0
|
210 |
delete iFormatEnc; iFormatEnc = NULL;
|
sl@0
|
211 |
delete iDataSink; iDataSink = NULL;
|
sl@0
|
212 |
delete iDescHBuf; iDescHBuf = NULL;
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
|
sl@0
|
216 |
|
sl@0
|
217 |
|
sl@0
|
218 |
|
sl@0
|
219 |
/**
|
sl@0
|
220 |
* This function reads from a source file into the member variable heap buffer, 'iDescHBuf'.
|
sl@0
|
221 |
* This can be used to compare the contents of a file with a buffer for example.
|
sl@0
|
222 |
* @param aFilename - The file to read from.
|
sl@0
|
223 |
* @param aPosition - Where to start reading from in the file.
|
sl@0
|
224 |
* @param aSize - How much of the file to read (in bytes) though if you pass '-1', it will
|
sl@0
|
225 |
* try and read the whole file from 'aPosition' onwards.
|
sl@0
|
226 |
*/
|
sl@0
|
227 |
void CTestStep_MMF_AFMT::ReadFileToDescriptorL(const TDesC& aFilename,
|
sl@0
|
228 |
TInt aPosition,
|
sl@0
|
229 |
TInt aSize)
|
sl@0
|
230 |
{
|
sl@0
|
231 |
RFs rfs;
|
sl@0
|
232 |
rfs.Connect();
|
sl@0
|
233 |
RFile file;
|
sl@0
|
234 |
|
sl@0
|
235 |
// Try to open the file.
|
sl@0
|
236 |
User::LeaveIfError( file.Open(rfs,aFilename,EFileRead|EFileShareAny) );
|
sl@0
|
237 |
|
sl@0
|
238 |
// Create the databuffer in which to store the data.
|
sl@0
|
239 |
TInt fileSize = 0;
|
sl@0
|
240 |
file.Size(fileSize);
|
sl@0
|
241 |
if (aSize == -1) // if -1, use whole file size
|
sl@0
|
242 |
iDescHBuf = HBufC8::NewL(fileSize-aPosition);
|
sl@0
|
243 |
else
|
sl@0
|
244 |
iDescHBuf = HBufC8::NewL(aSize);
|
sl@0
|
245 |
TPtr8 dataBuf = iDescHBuf->Des();
|
sl@0
|
246 |
|
sl@0
|
247 |
// Check we are not trying to read past the end of the file...
|
sl@0
|
248 |
if (fileSize< (aPosition+aSize) )
|
sl@0
|
249 |
User::Leave(KErrEof);
|
sl@0
|
250 |
|
sl@0
|
251 |
// Seek to the place we want to start reading from
|
sl@0
|
252 |
TInt offset = aPosition;
|
sl@0
|
253 |
file.Seek(ESeekStart, offset);
|
sl@0
|
254 |
|
sl@0
|
255 |
// Read the data from the file to the data buffer
|
sl@0
|
256 |
|
sl@0
|
257 |
if(aSize == -1)
|
sl@0
|
258 |
{
|
sl@0
|
259 |
User::LeaveIfError(file.Read(dataBuf,fileSize-aPosition));
|
sl@0
|
260 |
}
|
sl@0
|
261 |
else
|
sl@0
|
262 |
{
|
sl@0
|
263 |
User::LeaveIfError(file.Read(dataBuf, aSize));
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
iData.Set(dataBuf);
|
sl@0
|
267 |
|
sl@0
|
268 |
file.Close();
|
sl@0
|
269 |
rfs.Close();
|
sl@0
|
270 |
}
|
sl@0
|
271 |
|
sl@0
|
272 |
|
sl@0
|
273 |
|
sl@0
|
274 |
|
sl@0
|
275 |
|
sl@0
|
276 |
/**
|
sl@0
|
277 |
* This function can be used to make sure that a specified file is not present
|
sl@0
|
278 |
* before a set of tests are run.
|
sl@0
|
279 |
* @param aFilename - The name of the file to delete/check is not present.
|
sl@0
|
280 |
*/
|
sl@0
|
281 |
void CTestStep_MMF_AFMT::DeleteFileL(const TDesC& aFilename)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
RFs fs;
|
sl@0
|
284 |
User::LeaveIfError( fs.Connect() );
|
sl@0
|
285 |
TInt ret = fs.Delete(aFilename);
|
sl@0
|
286 |
if (ret != KErrNone && ret != KErrNotFound)
|
sl@0
|
287 |
User::Leave(ret);
|
sl@0
|
288 |
}
|
sl@0
|
289 |
|
sl@0
|
290 |
|
sl@0
|
291 |
|
sl@0
|
292 |
|
sl@0
|
293 |
/**
|
sl@0
|
294 |
* This function creates a datasource object based on either a descriptor
|
sl@0
|
295 |
* or a file.
|
sl@0
|
296 |
* @param aIsFile - ETrue if we are using CMmfFile or EFalse if using
|
sl@0
|
297 |
* CMmfDescriptor as the DataSource
|
sl@0
|
298 |
* @param aFilename - The file which acts as the data source. For a CMmfFile
|
sl@0
|
299 |
* based object, this IS the file. For a CMmfDescriptor based object, this
|
sl@0
|
300 |
* file contains the data that is read into the descriptor for test purposes.
|
sl@0
|
301 |
* @param aUid - The UID of the format object to be created.
|
sl@0
|
302 |
*/
|
sl@0
|
303 |
void CTestStep_MMF_AFMT::CreateDecodeObjectL(TBool aIsFile, const TDesC& aFilename, TInt aUid)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
// Create the datasource (stored in iDataSource)
|
sl@0
|
306 |
CreateDataSource(aIsFile, aFilename);
|
sl@0
|
307 |
|
sl@0
|
308 |
iUID = TUid::Uid(aUid);
|
sl@0
|
309 |
|
sl@0
|
310 |
// Make the NewL call.
|
sl@0
|
311 |
iFormatDec = CMMFFormatDecode::NewL( iUID, iDataSource);
|
sl@0
|
312 |
|
sl@0
|
313 |
User::LeaveIfError(iFormatDec->SourceThreadLogon(*this));
|
sl@0
|
314 |
iFormatDec->SourcePrimeL();
|
sl@0
|
315 |
}
|
sl@0
|
316 |
|
sl@0
|
317 |
/**
|
sl@0
|
318 |
* This function creates a datasink object based on either a descriptor
|
sl@0
|
319 |
* or a file.
|
sl@0
|
320 |
* @param aIsFile - ETrue if we are using CMmfFile or EFalse if using
|
sl@0
|
321 |
* CMmfDescriptor as the DataSource. NOTE: CMmfDescriptor support has not
|
sl@0
|
322 |
* yet been added to this test harness for SINKs.
|
sl@0
|
323 |
* @param aFilename - The file which acts as the data sink. For a CMmfFile
|
sl@0
|
324 |
* based object, this IS the file.
|
sl@0
|
325 |
* @param aUid - The UID of the format object to be created.
|
sl@0
|
326 |
*/
|
sl@0
|
327 |
void CTestStep_MMF_AFMT::CreateEncodeObjectL(TBool aIsFile, const TDesC& aFilename, TInt aUid)
|
sl@0
|
328 |
{
|
sl@0
|
329 |
// Create the data sink (stored in iDataSink)
|
sl@0
|
330 |
CreateDataSink(aIsFile, aFilename);
|
sl@0
|
331 |
|
sl@0
|
332 |
iUID = TUid::Uid(aUid);
|
sl@0
|
333 |
|
sl@0
|
334 |
// Make the NewL call.
|
sl@0
|
335 |
iFormatEnc = CMMFFormatEncode::NewL( iUID, iDataSink);
|
sl@0
|
336 |
|
sl@0
|
337 |
User::LeaveIfError(iFormatEnc->SourceThreadLogon(*this));
|
sl@0
|
338 |
}
|
sl@0
|
339 |
|
sl@0
|
340 |
/**
|
sl@0
|
341 |
*
|
sl@0
|
342 |
* Destructor for this class.
|
sl@0
|
343 |
*
|
sl@0
|
344 |
*/
|
sl@0
|
345 |
CTestStep_MMF_AFMT::~CTestStep_MMF_AFMT()
|
sl@0
|
346 |
{
|
sl@0
|
347 |
Cleanup();
|
sl@0
|
348 |
}
|
sl@0
|
349 |
|
sl@0
|
350 |
/**
|
sl@0
|
351 |
*
|
sl@0
|
352 |
* Close
|
sl@0
|
353 |
*
|
sl@0
|
354 |
*/
|
sl@0
|
355 |
void CTestStep_MMF_AFMT::Close()
|
sl@0
|
356 |
{
|
sl@0
|
357 |
Cleanup();
|
sl@0
|
358 |
}
|
sl@0
|
359 |
|