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: //
sl@0: 
sl@0: #include "CapTestStep0006.h"
sl@0: 
sl@0: CSecDevSndTS0006* CSecDevSndTS0006::NewL()
sl@0: 	{
sl@0: 	CSecDevSndTS0006* self = new (ELeave) CSecDevSndTS0006;
sl@0: 	CleanupStack::PushL(self);
sl@0: 	self->ConstructL();
sl@0: 	CleanupStack::Pop();
sl@0: 	return self;
sl@0: 	}
sl@0: 	
sl@0: void CSecDevSndTS0006::ConstructL()
sl@0: 	{
sl@0: 	iIsFirstPlayed = EFalse;
sl@0: 	}
sl@0: 	
sl@0: 
sl@0: void CSecDevSndTS0006::StartProcessing(TRequestStatus& aStatus)
sl@0: 	{
sl@0: 	iStatus = &aStatus;
sl@0: 
sl@0: 	iVerdict = EFail;
sl@0: 	if( (iVerdict = DoTestStepPreambleL() ) == EPass )
sl@0: 		{
sl@0: 		iVerdict = DoPlayDualTone();
sl@0: 		}
sl@0: 	}
sl@0: 		
sl@0: 		
sl@0: CSecDevSndTS0006::~CSecDevSndTS0006()
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: /******************************************************************************
sl@0:  *
sl@0:  * DevSound methods
sl@0:  *
sl@0:  *****************************************************************************/
sl@0:  
sl@0: /**
sl@0:  *
sl@0:  * DoTestStepL
sl@0:  * @result TVerdict
sl@0:  *
sl@0:  */
sl@0: 
sl@0: const TInt	KShortTimeInterval = 1000000;
sl@0: const TInt	KLongTimeInterval = 10000000;
sl@0: 
sl@0: TVerdict CSecDevSndTS0006::DoPlayDualTone()
sl@0: 	{
sl@0: 	TInt freq1a = 1000;
sl@0: 	TInt freq1b = 500;
sl@0: 	TTimeIntervalMicroSeconds dur1(KShortTimeInterval);
sl@0: 	TInt freq2a = 2000;
sl@0: 	TInt freq2b = 750;
sl@0: 	TTimeIntervalMicroSeconds dur2(KLongTimeInterval);
sl@0: 
sl@0: 	//Initialize
sl@0: 	TVerdict initOK = TestInitialize(EMMFStateTonePlaying);
sl@0: 	if (initOK != EPass)
sl@0: 		{
sl@0: 		return EInconclusive;
sl@0: 		}
sl@0: 
sl@0: 	TestSetPriority(KDevSoundPriorityHigh);
sl@0: 	TestSetVolume(iMMFDevSound->MaxVolume());
sl@0: 
sl@0: 	iExpectedValue = KErrUnderflow;
sl@0: 	TestPlayTone(freq1a, freq1b, dur1);
sl@0: 	iExpectedValue = KErrInUse;
sl@0: 	return TestPlayTone(freq2a, freq2b, dur2);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0:  *
sl@0:  * TestPlayTone
sl@0:  * @param aFreq
sl@0:  * @param aDur
sl@0:  * @result TVerdict
sl@0:  *
sl@0:  */
sl@0: TVerdict CSecDevSndTS0006::TestPlayTone(TInt aFreq1, TInt aFreq2, TTimeIntervalMicroSeconds aDur)
sl@0: 	{
sl@0: 	iCallbackError = KErrNone;
sl@0: 
sl@0: 	ResetCallbacks();
sl@0: 
sl@0: 	TRAPD(err, iMMFDevSound->PlayDualToneL(aFreq1, aFreq2, aDur));
sl@0: 	if (err)
sl@0: 		{
sl@0: 		iCallbackError = err;
sl@0: 		return EFail;
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		// Start the active scheduler and catch the callback
sl@0:  		CActiveScheduler::Start();
sl@0: 		if (iCallbackError != iExpectedValue)
sl@0: 			{
sl@0: 			return EFail;
sl@0: 			}
sl@0: 		if (iCallbackArray[EToneFinished] != 1)
sl@0: 			{
sl@0: 			return EFail;
sl@0: 			}
sl@0: 		TInt tot = GetCallbackTotal();
sl@0: 		if (tot > 1)
sl@0: 			{
sl@0: 			return EFail;
sl@0: 			}
sl@0: 		}
sl@0: 	return EPass;
sl@0: 	}
sl@0: 
sl@0: /******************************************************************************
sl@0:  *
sl@0:  * DevSound mixin methods
sl@0:  *
sl@0:  *****************************************************************************/
sl@0:  
sl@0: /**
sl@0:  *
sl@0:  * ToneFinished
sl@0:  * @param aError
sl@0:  *
sl@0:  */
sl@0: void CSecDevSndTS0006::ToneFinished (TInt aError)
sl@0: 	{
sl@0: 	if( !iIsFirstPlayed )
sl@0: 		{
sl@0: 		// after first tone played inform client so we can be interrupted during second play
sl@0: 		iIsFirstPlayed = ETrue;
sl@0: 		User::RequestComplete(iStatus, aError);
sl@0: 		}
sl@0: 	iCallbackArray[EToneFinished] ++;
sl@0: 	iCallbackError = aError;
sl@0: 	CActiveScheduler::Stop();
sl@0: 	}