1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/TestPlayerFileSource.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,329 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Integration tests.
1.18 +// This program is designed the test of the MMF_ACLNT.
1.19 +//
1.20 +//
1.21 +
1.22 +/**
1.23 + @file TestPlayerFileSource.cpp
1.24 +*/
1.25 +
1.26 +#include "TestPlayerUtils.h"
1.27 +#include "TestPlayerFileSource.h"
1.28 +
1.29 +//
1.30 +// CTestMmfAclntFileSource
1.31 +//
1.32 +
1.33 +/**
1.34 + * Constructor
1.35 + */
1.36 +CTestMmfAclntFileSource::CTestMmfAclntFileSource(const TDesC& aTestName,const TDesC& aSectName,
1.37 + const TDesC& aKeyName,const TBool aPlay,
1.38 + const TInt aExpectedError)
1.39 + :iPlay (aPlay)
1.40 + ,iExpectedError (aExpectedError)
1.41 + {
1.42 + // store the name of this test case
1.43 + iTestStepName = aTestName;
1.44 + // store the section-name of the ini file
1.45 + iSectName = aSectName;
1.46 + // store the key-name of the ini file
1.47 + iKeyName = aKeyName;
1.48 + }
1.49 +
1.50 +/**
1.51 + * NewL
1.52 + */
1.53 +CTestMmfAclntFileSource* CTestMmfAclntFileSource::NewL(const TDesC& aTestName, const TDesC& aSectName,
1.54 + const TDesC& aKeyName,const TBool aPlay,
1.55 + const TInt aExpectedError = KErrNone)
1.56 + {
1.57 + CTestMmfAclntFileSource* self = new (ELeave) CTestMmfAclntFileSource(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
1.58 + return self;
1.59 + }
1.60 +
1.61 +/**
1.62 + * NewLC
1.63 + */
1.64 +CTestMmfAclntFileSource* CTestMmfAclntFileSource::NewLC(const TDesC& aTestName, const TDesC& aSectName,
1.65 + const TDesC& aKeyName,
1.66 + const TBool aPlay,
1.67 + const TInt aExpectedError)
1.68 + {
1.69 + CTestMmfAclntFileSource* self = CTestMmfAclntFileSource::NewL(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
1.70 + CleanupStack::PushL(self);
1.71 + return self;
1.72 + }
1.73 +
1.74 +/**
1.75 + * MapcInitComplete
1.76 + */
1.77 +void CTestMmfAclntFileSource::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
1.78 + {
1.79 + iError = aError;
1.80 + iDuration = aDuration;
1.81 + INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete"));
1.82 + CActiveScheduler::Stop();
1.83 + }
1.84 +
1.85 +/**
1.86 + * MapcPlayComplete
1.87 + */
1.88 +void CTestMmfAclntFileSource::MapcPlayComplete(TInt aError)
1.89 + {
1.90 + iError = aError;
1.91 + INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete"));
1.92 + CActiveScheduler::Stop();
1.93 + }
1.94 +
1.95 +/**
1.96 + * Load and initialise an audio file.
1.97 + */
1.98 +TVerdict CTestMmfAclntFileSource::DoTestStepL( void )
1.99 + {
1.100 + INFO_PRINTF1( _L("TestPlayerUtils : File"));
1.101 + TVerdict ret = EFail;
1.102 +
1.103 + iError = KErrTimedOut;
1.104 +
1.105 + TBuf<KSizeBuf> filename;
1.106 + TPtrC filename1;
1.107 +
1.108 + if(!GetStringFromConfig(iSectName,iKeyName,filename1))
1.109 + {
1.110 + return EInconclusive;
1.111 + }
1.112 +
1.113 + GetDriveName(filename);
1.114 + filename.Append(filename1);
1.115 +
1.116 + // Create CMdaAudioPlayerUtility Object
1.117 + CMdaAudioPlayerUtility* player = NULL;
1.118 + player = CMdaAudioPlayerUtility::NewL(*this);
1.119 +
1.120 + // Create TMMFileSource Object
1.121 + TMMFileSource filesource(filename);
1.122 + player->OpenFileL(filesource);
1.123 +
1.124 + // Wait for initialisation callback
1.125 + INFO_PRINTF1(_L("Initialise CMdaAudioPlayerUtility"));
1.126 + CActiveScheduler::Start();
1.127 +
1.128 + // Check for expected errors.
1.129 + if(iError != KErrNone && (iExpectedError == iError))
1.130 + {
1.131 + ret = EPass; // all other tests pass
1.132 + delete player;
1.133 + User::After(KOneSecond); // wait for deletion to shut down devsound
1.134 + ERR_PRINTF2( _L("CMdaAudioPlayerUtility failed with expected error %d"),iError );
1.135 + return ret;
1.136 + }
1.137 +
1.138 + // Check for errors (after OPEN).
1.139 + if (iError == KErrNone && player != NULL)
1.140 + {
1.141 + if(iPlay)
1.142 + {
1.143 + iError = KErrTimedOut;
1.144 + player->Play();
1.145 +
1.146 + // Wait for play complete callback
1.147 + INFO_PRINTF1(_L("Play CMdaAudioPlayerUtility"));
1.148 + CActiveScheduler::Start();
1.149 +
1.150 + // Check for Callback errors
1.151 + if(iError == KErrNone)
1.152 + {
1.153 + ret = EPass;
1.154 + }
1.155 + }
1.156 + else
1.157 + {
1.158 + ret = EPass;
1.159 + }
1.160 + }
1.161 +
1.162 + // Clean up activities.
1.163 + delete player;
1.164 + User::After(KOneSecond); // wait for deletion to shut down devsound
1.165 +
1.166 + // Check for errors (final check).
1.167 + if(iError != KErrNone)
1.168 + {
1.169 + ERR_PRINTF2( _L("CMdaAudioPlayerUtility failed with error %d"),iError );
1.170 + }
1.171 + return ret;
1.172 + }
1.173 +
1.174 +//
1.175 +// CTestMmfAclntFileHandleSource
1.176 +//
1.177 +
1.178 +/**
1.179 + * Constructor
1.180 + */
1.181 +CTestMmfAclntFileHandleSource::CTestMmfAclntFileHandleSource(const TDesC& aTestName,const TDesC& aSectName,
1.182 + const TDesC& aKeyName,const TBool aPlay,
1.183 + const TInt aExpectedError)
1.184 + :iPlay (aPlay)
1.185 + ,iExpectedError (aExpectedError)
1.186 + {
1.187 + // store the name of this test case
1.188 + iTestStepName = aTestName;
1.189 + // store the section-name of the ini file
1.190 + iSectName = aSectName;
1.191 + // store the key-name of the ini file
1.192 + iKeyName = aKeyName;
1.193 + }
1.194 +
1.195 +/**
1.196 + * NewL
1.197 + */
1.198 +CTestMmfAclntFileHandleSource* CTestMmfAclntFileHandleSource::NewL(const TDesC& aTestName, const TDesC& aSectName,
1.199 + const TDesC& aKeyName,const TBool aPlay,
1.200 + const TInt aExpectedError = KErrNone)
1.201 + {
1.202 + CTestMmfAclntFileHandleSource* self = new (ELeave) CTestMmfAclntFileHandleSource(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
1.203 + return self;
1.204 + }
1.205 +
1.206 +/**
1.207 + * NewLC
1.208 + */
1.209 +CTestMmfAclntFileHandleSource* CTestMmfAclntFileHandleSource::NewLC(const TDesC& aTestName, const TDesC& aSectName,
1.210 + const TDesC& aKeyName,
1.211 + const TBool aPlay,
1.212 + const TInt aExpectedError)
1.213 + {
1.214 + CTestMmfAclntFileHandleSource* self = CTestMmfAclntFileHandleSource::NewL(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
1.215 + CleanupStack::PushL(self);
1.216 + return self;
1.217 + }
1.218 +
1.219 +/**
1.220 + * MapcInitComplete
1.221 + */
1.222 +void CTestMmfAclntFileHandleSource::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
1.223 + {
1.224 + iError = aError;
1.225 + iDuration = aDuration;
1.226 + INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete"));
1.227 + CActiveScheduler::Stop();
1.228 + }
1.229 +
1.230 +/**
1.231 + * MapcPlayComplete
1.232 + */
1.233 +void CTestMmfAclntFileHandleSource::MapcPlayComplete(TInt aError)
1.234 + {
1.235 + iError = aError;
1.236 + INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete"));
1.237 + CActiveScheduler::Stop();
1.238 + }
1.239 +
1.240 +/**
1.241 + * Load and initialise an audio file.
1.242 + */
1.243 +TVerdict CTestMmfAclntFileHandleSource::DoTestStepL( void )
1.244 + {
1.245 + INFO_PRINTF1( _L("TestPlayerUtils : File"));
1.246 + TVerdict ret = EFail;
1.247 +
1.248 + iError = KErrTimedOut;
1.249 +
1.250 + // Get the file name.
1.251 + TBuf<KSizeBuf> filename;
1.252 + TPtrC filename1;
1.253 + if(!GetStringFromConfig(iSectName,iKeyName,filename1))
1.254 + {
1.255 + return EInconclusive;
1.256 + }
1.257 + GetDriveName(filename);
1.258 + filename.Append(filename1);
1.259 +
1.260 + // Create CMdaAudioPlayerUtility Object
1.261 + CMdaAudioPlayerUtility* player = NULL;
1.262 + player = CMdaAudioPlayerUtility::NewL(*this);
1.263 +
1.264 + // Create RFs and RFile Objects
1.265 + RFs fs;
1.266 + User::LeaveIfError(fs.Connect());
1.267 + CleanupClosePushL(fs);
1.268 + User::LeaveIfError(fs.ShareProtected());
1.269 +
1.270 + RFile file;
1.271 + User::LeaveIfError( file.Open( fs, filename, EFileRead ) );
1.272 + CleanupClosePushL(file);
1.273 +
1.274 + // Create TMMFileSource Object
1.275 + TMMFileHandleSource filehandlesource(file);
1.276 + player->OpenFileL(filehandlesource);
1.277 +
1.278 + // Wait for initialisation callback
1.279 + INFO_PRINTF1(_L("CMdaAudioPlayerUtility->OpenFileL(TMMFileHandleSource)"));
1.280 + CActiveScheduler::Start();
1.281 +
1.282 + // Check for expected errors.
1.283 + if((iError != KErrNone) && (iExpectedError == iError))
1.284 + {
1.285 + ERR_PRINTF2(_L("CMdaAudioPlayerUtility->OpenFileL() Returned the Expected Error : %d"),iError);
1.286 + ret=EPass;
1.287 + }
1.288 +
1.289 + // Check for errors.
1.290 + if(iError != KErrNone)
1.291 + {
1.292 + ERR_PRINTF2(_L("CMdaAudioPlayerUtility->OpenFileL() Failed with Error : %d"),iError);
1.293 + ret=EFail;
1.294 + }
1.295 +
1.296 + // Check for No errors, so as to start Playback
1.297 + if (iError == KErrNone && player != NULL)
1.298 + {
1.299 + if(iPlay)
1.300 + {
1.301 + iError = KErrTimedOut;
1.302 + player->Play();
1.303 +
1.304 + // Wait for play complete callback
1.305 + INFO_PRINTF1(_L("CMdaAudioPlayerUtility->Play()"));
1.306 + CActiveScheduler::Start();
1.307 +
1.308 + // Check for Callback errors
1.309 + if(iError == KErrNone)
1.310 + {
1.311 + ERR_PRINTF2(_L("CMdaAudioPlayerUtility->Play() completed successfully with return code : %d"),iError);
1.312 + ret = EPass;
1.313 + }
1.314 + else
1.315 + {
1.316 + ERR_PRINTF2(_L("CMdaAudioPlayerUtility->Play() Failed with Error : %d"),iError );
1.317 + ret = EFail;
1.318 + }
1.319 + }
1.320 + else
1.321 + {
1.322 + ret = EPass;
1.323 + }
1.324 + }
1.325 +
1.326 + // Clean up activities.
1.327 + delete player;
1.328 + User::After(KOneSecond); // wait for deletion to shut down devsound
1.329 + CleanupStack::PopAndDestroy(2);
1.330 +
1.331 + return ret;
1.332 + }