sl@0: // Copyright (c) 2004-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: // Integration tests. sl@0: // This program is designed the test of the MMF_ACLNT. sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file TestPlayerFileSource.cpp sl@0: */ sl@0: sl@0: #include "TestPlayerUtils.h" sl@0: #include "TestPlayerFileSource.h" sl@0: sl@0: // sl@0: // CTestMmfAclntFileSource sl@0: // sl@0: sl@0: /** sl@0: * Constructor sl@0: */ sl@0: CTestMmfAclntFileSource::CTestMmfAclntFileSource(const TDesC& aTestName,const TDesC& aSectName, sl@0: const TDesC& aKeyName,const TBool aPlay, sl@0: const TInt aExpectedError) sl@0: :iPlay (aPlay) sl@0: ,iExpectedError (aExpectedError) sl@0: { sl@0: // store the name of this test case sl@0: iTestStepName = aTestName; sl@0: // store the section-name of the ini file sl@0: iSectName = aSectName; sl@0: // store the key-name of the ini file sl@0: iKeyName = aKeyName; sl@0: } sl@0: sl@0: /** sl@0: * NewL sl@0: */ sl@0: CTestMmfAclntFileSource* CTestMmfAclntFileSource::NewL(const TDesC& aTestName, const TDesC& aSectName, sl@0: const TDesC& aKeyName,const TBool aPlay, sl@0: const TInt aExpectedError = KErrNone) sl@0: { sl@0: CTestMmfAclntFileSource* self = new (ELeave) CTestMmfAclntFileSource(aTestName,aSectName,aKeyName,aPlay,aExpectedError); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: * NewLC sl@0: */ sl@0: CTestMmfAclntFileSource* CTestMmfAclntFileSource::NewLC(const TDesC& aTestName, const TDesC& aSectName, sl@0: const TDesC& aKeyName, sl@0: const TBool aPlay, sl@0: const TInt aExpectedError) sl@0: { sl@0: CTestMmfAclntFileSource* self = CTestMmfAclntFileSource::NewL(aTestName,aSectName,aKeyName,aPlay,aExpectedError); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: * MapcInitComplete sl@0: */ sl@0: void CTestMmfAclntFileSource::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration) sl@0: { sl@0: iError = aError; sl@0: iDuration = aDuration; sl@0: INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete")); sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: /** sl@0: * MapcPlayComplete sl@0: */ sl@0: void CTestMmfAclntFileSource::MapcPlayComplete(TInt aError) sl@0: { sl@0: iError = aError; sl@0: INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete")); sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: /** sl@0: * Load and initialise an audio file. sl@0: */ sl@0: TVerdict CTestMmfAclntFileSource::DoTestStepL( void ) sl@0: { sl@0: INFO_PRINTF1( _L("TestPlayerUtils : File")); sl@0: TVerdict ret = EFail; sl@0: sl@0: iError = KErrTimedOut; sl@0: sl@0: TBuf filename; sl@0: TPtrC filename1; sl@0: sl@0: if(!GetStringFromConfig(iSectName,iKeyName,filename1)) sl@0: { sl@0: return EInconclusive; sl@0: } sl@0: sl@0: GetDriveName(filename); sl@0: filename.Append(filename1); sl@0: sl@0: // Create CMdaAudioPlayerUtility Object sl@0: CMdaAudioPlayerUtility* player = NULL; sl@0: player = CMdaAudioPlayerUtility::NewL(*this); sl@0: sl@0: // Create TMMFileSource Object sl@0: TMMFileSource filesource(filename); sl@0: player->OpenFileL(filesource); sl@0: sl@0: // Wait for initialisation callback sl@0: INFO_PRINTF1(_L("Initialise CMdaAudioPlayerUtility")); sl@0: CActiveScheduler::Start(); sl@0: sl@0: // Check for expected errors. sl@0: if(iError != KErrNone && (iExpectedError == iError)) sl@0: { sl@0: ret = EPass; // all other tests pass sl@0: delete player; sl@0: User::After(KOneSecond); // wait for deletion to shut down devsound sl@0: ERR_PRINTF2( _L("CMdaAudioPlayerUtility failed with expected error %d"),iError ); sl@0: return ret; sl@0: } sl@0: sl@0: // Check for errors (after OPEN). sl@0: if (iError == KErrNone && player != NULL) sl@0: { sl@0: if(iPlay) sl@0: { sl@0: iError = KErrTimedOut; sl@0: player->Play(); sl@0: sl@0: // Wait for play complete callback sl@0: INFO_PRINTF1(_L("Play CMdaAudioPlayerUtility")); sl@0: CActiveScheduler::Start(); sl@0: sl@0: // Check for Callback errors sl@0: if(iError == KErrNone) sl@0: { sl@0: ret = EPass; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ret = EPass; sl@0: } sl@0: } sl@0: sl@0: // Clean up activities. sl@0: delete player; sl@0: User::After(KOneSecond); // wait for deletion to shut down devsound sl@0: sl@0: // Check for errors (final check). sl@0: if(iError != KErrNone) sl@0: { sl@0: ERR_PRINTF2( _L("CMdaAudioPlayerUtility failed with error %d"),iError ); sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: // sl@0: // CTestMmfAclntFileHandleSource sl@0: // sl@0: sl@0: /** sl@0: * Constructor sl@0: */ sl@0: CTestMmfAclntFileHandleSource::CTestMmfAclntFileHandleSource(const TDesC& aTestName,const TDesC& aSectName, sl@0: const TDesC& aKeyName,const TBool aPlay, sl@0: const TInt aExpectedError) sl@0: :iPlay (aPlay) sl@0: ,iExpectedError (aExpectedError) sl@0: { sl@0: // store the name of this test case sl@0: iTestStepName = aTestName; sl@0: // store the section-name of the ini file sl@0: iSectName = aSectName; sl@0: // store the key-name of the ini file sl@0: iKeyName = aKeyName; sl@0: } sl@0: sl@0: /** sl@0: * NewL sl@0: */ sl@0: CTestMmfAclntFileHandleSource* CTestMmfAclntFileHandleSource::NewL(const TDesC& aTestName, const TDesC& aSectName, sl@0: const TDesC& aKeyName,const TBool aPlay, sl@0: const TInt aExpectedError = KErrNone) sl@0: { sl@0: CTestMmfAclntFileHandleSource* self = new (ELeave) CTestMmfAclntFileHandleSource(aTestName,aSectName,aKeyName,aPlay,aExpectedError); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: * NewLC sl@0: */ sl@0: CTestMmfAclntFileHandleSource* CTestMmfAclntFileHandleSource::NewLC(const TDesC& aTestName, const TDesC& aSectName, sl@0: const TDesC& aKeyName, sl@0: const TBool aPlay, sl@0: const TInt aExpectedError) sl@0: { sl@0: CTestMmfAclntFileHandleSource* self = CTestMmfAclntFileHandleSource::NewL(aTestName,aSectName,aKeyName,aPlay,aExpectedError); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: * MapcInitComplete sl@0: */ sl@0: void CTestMmfAclntFileHandleSource::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration) sl@0: { sl@0: iError = aError; sl@0: iDuration = aDuration; sl@0: INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete")); sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: /** sl@0: * MapcPlayComplete sl@0: */ sl@0: void CTestMmfAclntFileHandleSource::MapcPlayComplete(TInt aError) sl@0: { sl@0: iError = aError; sl@0: INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete")); sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: /** sl@0: * Load and initialise an audio file. sl@0: */ sl@0: TVerdict CTestMmfAclntFileHandleSource::DoTestStepL( void ) sl@0: { sl@0: INFO_PRINTF1( _L("TestPlayerUtils : File")); sl@0: TVerdict ret = EFail; sl@0: sl@0: iError = KErrTimedOut; sl@0: sl@0: // Get the file name. sl@0: TBuf filename; sl@0: TPtrC filename1; sl@0: if(!GetStringFromConfig(iSectName,iKeyName,filename1)) sl@0: { sl@0: return EInconclusive; sl@0: } sl@0: GetDriveName(filename); sl@0: filename.Append(filename1); sl@0: sl@0: // Create CMdaAudioPlayerUtility Object sl@0: CMdaAudioPlayerUtility* player = NULL; sl@0: player = CMdaAudioPlayerUtility::NewL(*this); sl@0: sl@0: // Create RFs and RFile Objects sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: User::LeaveIfError(fs.ShareProtected()); sl@0: sl@0: RFile file; sl@0: User::LeaveIfError( file.Open( fs, filename, EFileRead ) ); sl@0: CleanupClosePushL(file); sl@0: sl@0: // Create TMMFileSource Object sl@0: TMMFileHandleSource filehandlesource(file); sl@0: player->OpenFileL(filehandlesource); sl@0: sl@0: // Wait for initialisation callback sl@0: INFO_PRINTF1(_L("CMdaAudioPlayerUtility->OpenFileL(TMMFileHandleSource)")); sl@0: CActiveScheduler::Start(); sl@0: sl@0: // Check for expected errors. sl@0: if((iError != KErrNone) && (iExpectedError == iError)) sl@0: { sl@0: ERR_PRINTF2(_L("CMdaAudioPlayerUtility->OpenFileL() Returned the Expected Error : %d"),iError); sl@0: ret=EPass; sl@0: } sl@0: sl@0: // Check for errors. sl@0: if(iError != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("CMdaAudioPlayerUtility->OpenFileL() Failed with Error : %d"),iError); sl@0: ret=EFail; sl@0: } sl@0: sl@0: // Check for No errors, so as to start Playback sl@0: if (iError == KErrNone && player != NULL) sl@0: { sl@0: if(iPlay) sl@0: { sl@0: iError = KErrTimedOut; sl@0: player->Play(); sl@0: sl@0: // Wait for play complete callback sl@0: INFO_PRINTF1(_L("CMdaAudioPlayerUtility->Play()")); sl@0: CActiveScheduler::Start(); sl@0: sl@0: // Check for Callback errors sl@0: if(iError == KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("CMdaAudioPlayerUtility->Play() completed successfully with return code : %d"),iError); sl@0: ret = EPass; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("CMdaAudioPlayerUtility->Play() Failed with Error : %d"),iError ); sl@0: ret = EFail; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ret = EPass; sl@0: } sl@0: } sl@0: sl@0: // Clean up activities. sl@0: delete player; sl@0: User::After(KOneSecond); // wait for deletion to shut down devsound sl@0: CleanupStack::PopAndDestroy(2); sl@0: sl@0: return ret; sl@0: }