sl@0: 
sl@0: // Copyright (c) 2002-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: // TestCapabilities.CPP
sl@0: // This program is designed the test of the MMF_ACLNT.
sl@0: // 
sl@0: //
sl@0: 
sl@0: /**
sl@0:  @file TestPlayerUtils.cpp
sl@0: */
sl@0: 
sl@0: #include <simulprocclient.h>
sl@0: #include "TestPlayerCaps.h"
sl@0: #include "TestPlayerCaps0012.h"
sl@0: 
sl@0: 
sl@0: 
sl@0: /**
sl@0:  * Constructor
sl@0:  */
sl@0: CTestMmfAclntCaps0012::CTestMmfAclntCaps0012(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName)
sl@0: 	{
sl@0: 	// store the name of this test case
sl@0: 	// this is the name that is used by the script file
sl@0: 	// Each test step initialises it's own name
sl@0: 	iTestStepName = aTestName;
sl@0: 	iSectName = aSectName;
sl@0: 	iKeyName = aKeyName;
sl@0: 	}
sl@0: 
sl@0: CTestMmfAclntCaps0012* CTestMmfAclntCaps0012::NewL(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName)
sl@0: 	{
sl@0: 	CTestMmfAclntCaps0012* self = new (ELeave) CTestMmfAclntCaps0012(aTestName, aSectName, aKeyName);
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: CTestMmfAclntCaps0012* CTestMmfAclntCaps0012::NewLC(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName)
sl@0: 	{
sl@0: 	CTestMmfAclntCaps0012* self = NewL(aTestName, aSectName, aKeyName);
sl@0: 	CleanupStack::PushL(self);
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: void CTestMmfAclntCaps0012::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
sl@0: 	{
sl@0: 	INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete"));
sl@0: 	DoProcess(aError);
sl@0: 	}
sl@0: 
sl@0: void CTestMmfAclntCaps0012::MapcPlayComplete(TInt aError)
sl@0: 	{
sl@0: 	INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete"));
sl@0: 	DoProcess(aError);
sl@0: 	}
sl@0: 
sl@0: 
sl@0: 
sl@0: /** Load and initialise an audio file.
sl@0:  */
sl@0: TVerdict CTestMmfAclntCaps0012::DoTestStepL( void )
sl@0: 	{
sl@0: 	INFO_PRINTF1( _L("TestPlayerUtils : Caps"));
sl@0: 	iVerdict = EFail;
sl@0: 
sl@0: 	iServerMonitor = CServerMonitor::NewL(this);
sl@0: 
sl@0: 	// Start Server to play back from another process
sl@0: 	RTestServ server;
sl@0: 	User::LeaveIfError(server.Connect(_L("CapTestServer")));
sl@0: 	CleanupClosePushL(server);
sl@0: 	
sl@0: 	RTestSession session1;
sl@0: 	User::LeaveIfError(session1.Open(server,_L("CapTestStep0012")));
sl@0: 	TRequestStatus* status = &iServerMonitor->ActiveStatus();
sl@0: 	// Start Server playback. The RunL of the CServerMonitor class will be called by the server when
sl@0: 	// playback has started
sl@0: 	session1.StartProcessing(*status);
sl@0: 	// Begin activescheduler loop. This will only exit when the whole test is complete 
sl@0: 	CActiveScheduler::Start();
sl@0: 	
sl@0: 	// The test is complete. Now shut down the server and get any errors /messages from the server
sl@0: 	TBuf8<256> message;
sl@0: 	TVerdict verdict = session1.EndProcessingAndReturnResult(message);
sl@0: 	if (verdict != EPass)
sl@0: 		iVerdict = verdict;
sl@0: 	TBuf16<256> copymess;
sl@0: 	copymess.Copy(message);
sl@0: 	INFO_PRINTF2(_L("end processing and return result: %S"),&copymess);
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(&server);
sl@0: 	return iVerdict;
sl@0: 	}
sl@0: 	
sl@0: void CTestMmfAclntCaps0012::CreatePlayer() 
sl@0: 	{
sl@0: 	// Get the test filename from the configuration file
sl@0: 	TBuf<KSizeBuf> filename;
sl@0: 	TPtrC filename1; 
sl@0: 	if(!GetStringFromConfig(iSectName,iKeyName,filename1))
sl@0: 		{
sl@0: 		iVerdict = EFail;
sl@0: 		CActiveScheduler::Stop();
sl@0: 		}
sl@0: 	GetDriveName(filename);
sl@0: 	filename.Append(filename1);
sl@0: 
sl@0: 	iPlayer = CMdaAudioPlayerUtility::NewFilePlayerL(filename, *this, EMdaPriorityNormal);	
sl@0: 	}
sl@0: 	
sl@0: void CTestMmfAclntCaps0012::BeginPlayback()
sl@0: 	{
sl@0: 	iPlayer->Play();
sl@0: 	}
sl@0: 	
sl@0: 	
sl@0: void CTestMmfAclntCaps0012::DoProcess(TInt aError)
sl@0: 	{
sl@0: 	if (aError == KErrNone)
sl@0: 		{
sl@0: 		InternalState nextState = iState;
sl@0: 		switch (iState)
sl@0: 			{
sl@0: 		case EWaitingForServer:
sl@0: 			CreatePlayer();
sl@0: 			nextState = EInitPlayer;
sl@0: 			break;
sl@0: 		case EInitPlayer : 
sl@0: 			BeginPlayback();
sl@0: 			nextState = EPlaying;
sl@0: 			break;
sl@0: 		case EPlaying :
sl@0: 			iVerdict = EPass;
sl@0: 			CActiveScheduler::Stop();
sl@0: 			break;
sl@0: 			}
sl@0: 		iState = nextState;
sl@0: 		}
sl@0: 	else 
sl@0: 		{
sl@0: 		iVerdict = EFail;
sl@0: 		INFO_PRINTF2(_L("Unexpected failure in test, error code %d"), aError);
sl@0: 		CActiveScheduler::Stop();
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: CTestMmfAclntCaps0012::CServerMonitor::CServerMonitor(CTestMmfAclntCaps0012* aParent)
sl@0: 	:CActive(EPriorityNormal), iParent(aParent)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: 	
sl@0: CTestMmfAclntCaps0012::CServerMonitor* CTestMmfAclntCaps0012::CServerMonitor::NewL(CTestMmfAclntCaps0012* aParent) 
sl@0: 	{
sl@0: 	CServerMonitor* self = new (ELeave) CServerMonitor(aParent);
sl@0: 	CleanupStack::PushL(self);
sl@0: 	self->ConstructL();
sl@0: 	CleanupStack::Pop(self);
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: void CTestMmfAclntCaps0012::CServerMonitor::ConstructL() 
sl@0: 	{
sl@0: 	CActiveScheduler::Add(this);
sl@0: 	}
sl@0: 
sl@0: void CTestMmfAclntCaps0012::CServerMonitor::DoCancel() 
sl@0: 	{
sl@0: 	Cancel();
sl@0: 	}
sl@0: 
sl@0: void CTestMmfAclntCaps0012::CServerMonitor::RunL() 
sl@0: 	{
sl@0: 	// start the client state machine
sl@0: 	iParent->DoProcess(iStatus.Int());
sl@0: 	}
sl@0: 	
sl@0: TRequestStatus& CTestMmfAclntCaps0012::CServerMonitor::ActiveStatus() 
sl@0: 	{
sl@0: 	SetActive();
sl@0: 	return iStatus;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: CTestMmfAclntCaps0012::~CTestMmfAclntCaps0012()
sl@0: 	{
sl@0: 	delete iPlayer;
sl@0: 	delete iServerMonitor;
sl@0: 	}