First public contribution.
1 // Copyright (c) 2004-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.
15 // This program is designed the test of the MMF_ACLNT.
20 @file TestPlayerFileSource.cpp
23 #include "TestPlayerUtils.h"
24 #include "TestPlayerFileSource.h"
27 // CTestMmfAclntFileSource
33 CTestMmfAclntFileSource::CTestMmfAclntFileSource(const TDesC& aTestName,const TDesC& aSectName,
34 const TDesC& aKeyName,const TBool aPlay,
35 const TInt aExpectedError)
37 ,iExpectedError (aExpectedError)
39 // store the name of this test case
40 iTestStepName = aTestName;
41 // store the section-name of the ini file
42 iSectName = aSectName;
43 // store the key-name of the ini file
50 CTestMmfAclntFileSource* CTestMmfAclntFileSource::NewL(const TDesC& aTestName, const TDesC& aSectName,
51 const TDesC& aKeyName,const TBool aPlay,
52 const TInt aExpectedError = KErrNone)
54 CTestMmfAclntFileSource* self = new (ELeave) CTestMmfAclntFileSource(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
61 CTestMmfAclntFileSource* CTestMmfAclntFileSource::NewLC(const TDesC& aTestName, const TDesC& aSectName,
62 const TDesC& aKeyName,
64 const TInt aExpectedError)
66 CTestMmfAclntFileSource* self = CTestMmfAclntFileSource::NewL(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
67 CleanupStack::PushL(self);
74 void CTestMmfAclntFileSource::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
77 iDuration = aDuration;
78 INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete"));
79 CActiveScheduler::Stop();
85 void CTestMmfAclntFileSource::MapcPlayComplete(TInt aError)
88 INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete"));
89 CActiveScheduler::Stop();
93 * Load and initialise an audio file.
95 TVerdict CTestMmfAclntFileSource::DoTestStepL( void )
97 INFO_PRINTF1( _L("TestPlayerUtils : File"));
100 iError = KErrTimedOut;
102 TBuf<KSizeBuf> filename;
105 if(!GetStringFromConfig(iSectName,iKeyName,filename1))
107 return EInconclusive;
110 GetDriveName(filename);
111 filename.Append(filename1);
113 // Create CMdaAudioPlayerUtility Object
114 CMdaAudioPlayerUtility* player = NULL;
115 player = CMdaAudioPlayerUtility::NewL(*this);
117 // Create TMMFileSource Object
118 TMMFileSource filesource(filename);
119 player->OpenFileL(filesource);
121 // Wait for initialisation callback
122 INFO_PRINTF1(_L("Initialise CMdaAudioPlayerUtility"));
123 CActiveScheduler::Start();
125 // Check for expected errors.
126 if(iError != KErrNone && (iExpectedError == iError))
128 ret = EPass; // all other tests pass
130 User::After(KOneSecond); // wait for deletion to shut down devsound
131 ERR_PRINTF2( _L("CMdaAudioPlayerUtility failed with expected error %d"),iError );
135 // Check for errors (after OPEN).
136 if (iError == KErrNone && player != NULL)
140 iError = KErrTimedOut;
143 // Wait for play complete callback
144 INFO_PRINTF1(_L("Play CMdaAudioPlayerUtility"));
145 CActiveScheduler::Start();
147 // Check for Callback errors
148 if(iError == KErrNone)
159 // Clean up activities.
161 User::After(KOneSecond); // wait for deletion to shut down devsound
163 // Check for errors (final check).
164 if(iError != KErrNone)
166 ERR_PRINTF2( _L("CMdaAudioPlayerUtility failed with error %d"),iError );
172 // CTestMmfAclntFileHandleSource
178 CTestMmfAclntFileHandleSource::CTestMmfAclntFileHandleSource(const TDesC& aTestName,const TDesC& aSectName,
179 const TDesC& aKeyName,const TBool aPlay,
180 const TInt aExpectedError)
182 ,iExpectedError (aExpectedError)
184 // store the name of this test case
185 iTestStepName = aTestName;
186 // store the section-name of the ini file
187 iSectName = aSectName;
188 // store the key-name of the ini file
195 CTestMmfAclntFileHandleSource* CTestMmfAclntFileHandleSource::NewL(const TDesC& aTestName, const TDesC& aSectName,
196 const TDesC& aKeyName,const TBool aPlay,
197 const TInt aExpectedError = KErrNone)
199 CTestMmfAclntFileHandleSource* self = new (ELeave) CTestMmfAclntFileHandleSource(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
206 CTestMmfAclntFileHandleSource* CTestMmfAclntFileHandleSource::NewLC(const TDesC& aTestName, const TDesC& aSectName,
207 const TDesC& aKeyName,
209 const TInt aExpectedError)
211 CTestMmfAclntFileHandleSource* self = CTestMmfAclntFileHandleSource::NewL(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
212 CleanupStack::PushL(self);
219 void CTestMmfAclntFileHandleSource::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
222 iDuration = aDuration;
223 INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete"));
224 CActiveScheduler::Stop();
230 void CTestMmfAclntFileHandleSource::MapcPlayComplete(TInt aError)
233 INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete"));
234 CActiveScheduler::Stop();
238 * Load and initialise an audio file.
240 TVerdict CTestMmfAclntFileHandleSource::DoTestStepL( void )
242 INFO_PRINTF1( _L("TestPlayerUtils : File"));
243 TVerdict ret = EFail;
245 iError = KErrTimedOut;
247 // Get the file name.
248 TBuf<KSizeBuf> filename;
250 if(!GetStringFromConfig(iSectName,iKeyName,filename1))
252 return EInconclusive;
254 GetDriveName(filename);
255 filename.Append(filename1);
257 // Create CMdaAudioPlayerUtility Object
258 CMdaAudioPlayerUtility* player = NULL;
259 player = CMdaAudioPlayerUtility::NewL(*this);
261 // Create RFs and RFile Objects
263 User::LeaveIfError(fs.Connect());
264 CleanupClosePushL(fs);
265 User::LeaveIfError(fs.ShareProtected());
268 User::LeaveIfError( file.Open( fs, filename, EFileRead ) );
269 CleanupClosePushL(file);
271 // Create TMMFileSource Object
272 TMMFileHandleSource filehandlesource(file);
273 player->OpenFileL(filehandlesource);
275 // Wait for initialisation callback
276 INFO_PRINTF1(_L("CMdaAudioPlayerUtility->OpenFileL(TMMFileHandleSource)"));
277 CActiveScheduler::Start();
279 // Check for expected errors.
280 if((iError != KErrNone) && (iExpectedError == iError))
282 ERR_PRINTF2(_L("CMdaAudioPlayerUtility->OpenFileL() Returned the Expected Error : %d"),iError);
287 if(iError != KErrNone)
289 ERR_PRINTF2(_L("CMdaAudioPlayerUtility->OpenFileL() Failed with Error : %d"),iError);
293 // Check for No errors, so as to start Playback
294 if (iError == KErrNone && player != NULL)
298 iError = KErrTimedOut;
301 // Wait for play complete callback
302 INFO_PRINTF1(_L("CMdaAudioPlayerUtility->Play()"));
303 CActiveScheduler::Start();
305 // Check for Callback errors
306 if(iError == KErrNone)
308 ERR_PRINTF2(_L("CMdaAudioPlayerUtility->Play() completed successfully with return code : %d"),iError);
313 ERR_PRINTF2(_L("CMdaAudioPlayerUtility->Play() Failed with Error : %d"),iError );
323 // Clean up activities.
325 User::After(KOneSecond); // wait for deletion to shut down devsound
326 CleanupStack::PopAndDestroy(2);