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: // 
sl@0: //
sl@0: 
sl@0: #include "TestAudioPlayerDRM.h"
sl@0: 
sl@0: // CTestMmfDRMAudioPlayerBase implementation
sl@0: 
sl@0: /**
sl@0: *
sl@0: * CTestMmfDRMAudioPlayerBase()
sl@0: *
sl@0: * Constructor to set the Test step name, section name and key names.
sl@0: *
sl@0: */
sl@0: CTestMmfDRMAudioPlayerBase::CTestMmfDRMAudioPlayerBase(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName, const TDesC& aUniqueId)
sl@0: 	{
sl@0: 	iTestStepName = aTestName;
sl@0: 	iSectName = aSectName;
sl@0: 	iKeyName = aKeyName;
sl@0: 	iUniqueId = aUniqueId;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: *
sl@0: * FsmL()
sl@0: *
sl@0: * @param TMmfAudioEvents aEvent
sl@0: *
sl@0: */
sl@0: void CTestMmfDRMAudioPlayerBase::FsmL(TMmfAudioEvents aEvent, TInt aError)
sl@0:     {
sl@0:     switch (aEvent)
sl@0:         {
sl@0:         case EAudioOpen:
sl@0:             INFO_PRINTF3(_L("Opening the file for PLAY intent : %S, UniqueID : %S"), &iFileName, &iUniqueId);
sl@0:             iAudioPlayer->OpenFileL(TMMFileSource(iFileName, iUniqueId, ContentAccess::EPlay));
sl@0:             break;
sl@0: 
sl@0:         case EAudioPlay:
sl@0:             if (aError != KErrNone) // Check if there's error while opening the file
sl@0:                 {
sl@0:                 ERR_PRINTF2(_L("Opening the audio file failed, unexpected error %d."), aError);
sl@0:                 CActiveScheduler::Stop();
sl@0:                 }
sl@0:             else
sl@0:                 {
sl@0:                 INFO_PRINTF1(_L("Playing the audio file..."));
sl@0:                 AfterOpenL();
sl@0:                 iAudioPlayer->Play();
sl@0:                 }
sl@0:             break;
sl@0: 
sl@0:         case EAudioPlayEnd:
sl@0:             if (aError != KErrNone) // Check if there's error while playing the file
sl@0:                 {
sl@0:                 ERR_PRINTF2(_L("Playing the audio file failed, unexpected error %d."), aError);
sl@0:                 }
sl@0:             else
sl@0:                 {
sl@0:                 INFO_PRINTF1(_L("Audio file opened and played."));
sl@0:                 iTestStepResult = EPass;
sl@0:                 }
sl@0: 			CActiveScheduler::Stop();
sl@0:             break;
sl@0: 
sl@0:         default:
sl@0:             INFO_PRINTF1(_L("Invalid Audio event!"));
sl@0:         }
sl@0:     };
sl@0:     
sl@0: void CTestMmfDRMAudioPlayerBase::AfterOpenL()
sl@0: 	{
sl@0: 	}
sl@0: 	
sl@0: /**
sl@0: *
sl@0: * Test step Preamble.
sl@0: *
sl@0: * @return TVerdict: The result of the test step.
sl@0: * 
sl@0: */
sl@0: TVerdict CTestMmfDRMAudioPlayerBase::DoTestStepPreambleL()
sl@0:     {
sl@0:     // Install the scheduler
sl@0:     TVerdict verdict = CTestMmfAclntStep::DoTestStepPreambleL();
sl@0: 
sl@0:     iError = KErrNone;
sl@0: 
sl@0:     // Get the filename
sl@0:     TPtrC filename1;
sl@0:     if (!GetStringFromConfig(iSectName, iKeyName, filename1))
sl@0:         {
sl@0:         return EInconclusive;
sl@0:         }
sl@0:     GetDriveName(iFileName);
sl@0:     iFileName.Append(filename1);
sl@0: 
sl@0:     // Create an audio player
sl@0:     iAudioPlayer = CMdaAudioPlayerUtility::NewL(*this);
sl@0:     if (iAudioPlayer == NULL)
sl@0:         {
sl@0:         return EInconclusive;
sl@0:         }
sl@0: 
sl@0:     return verdict;
sl@0:     }
sl@0: 
sl@0: /**
sl@0: *
sl@0: * Test step Postamble.
sl@0: *
sl@0: * @return TVerdict: The result of the test step.
sl@0: * 
sl@0: */
sl@0: TVerdict CTestMmfDRMAudioPlayerBase::DoTestStepPostambleL()
sl@0:     {
sl@0:     delete iAudioPlayer;
sl@0:     iAudioPlayer = NULL;
sl@0:     User::After(KOneSecond); // wait for deletion to shut down devsound
sl@0:     return CTestMmfAclntStep::DoTestStepPostambleL(); // Destroy the scheduler
sl@0:     }
sl@0: 
sl@0: /**
sl@0: *
sl@0: * Implementation of the MMdaAudioPlayerCallback interface function.
sl@0: *
sl@0: * @param TInt aError
sl@0: *
sl@0: */
sl@0: void CTestMmfDRMAudioPlayerBase::MapcInitComplete(TInt aError, 
sl@0:     const TTimeIntervalMicroSeconds& /*aDuration*/)
sl@0:     {
sl@0:     INFO_PRINTF2(_L("MMdaAudioPlayerCallback Init Complete. Error = %d"), aError);
sl@0:     iError = aError;
sl@0: 	if (iError != KErrNone)
sl@0:     	{
sl@0:     	ERR_PRINTF2(_L("Opening the audio file failed, unexpected error %d."), aError);
sl@0:     	iAudioPlayer->Close();
sl@0:     	CActiveScheduler::Stop();
sl@0:     	}
sl@0: 	else
sl@0: 		{
sl@0: 		TRAP(iError, FsmL(EAudioPlay, aError)); // Call to play audio
sl@0: 		if (iError != KErrNone)
sl@0:     		{
sl@0:     		ERR_PRINTF2(_L("Got an error from the FsmL(EAudioPlay) %d."), iError);
sl@0:     		iAudioPlayer->Close();
sl@0:     		CActiveScheduler::Stop();    		
sl@0:     		}
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: *
sl@0: * Implementation of the MMdaAudioPlayerCallback interface function.
sl@0: *
sl@0: * @param TInt aError
sl@0: *
sl@0: */
sl@0: void CTestMmfDRMAudioPlayerBase::MapcPlayComplete(TInt aError)
sl@0:     {
sl@0:     INFO_PRINTF2(_L("MMdaAudioPlayerCallback Play Complete. Error = %d"), aError);
sl@0:     iError = aError;
sl@0: 	if (iError != KErrNone)
sl@0:     	{
sl@0:     	ERR_PRINTF2(_L("Opening the audio file failed, unexpected error %d."), aError);
sl@0:     	iAudioPlayer->Close();
sl@0:     	CActiveScheduler::Stop();
sl@0:     	}
sl@0: 	else
sl@0: 		{
sl@0: 		TRAP(iError, FsmL(EAudioPlayEnd, aError));
sl@0: 		if (iError != KErrNone)
sl@0:     		{
sl@0:     		ERR_PRINTF2(_L("Got an error from the FsmL(EAudioPlayEnd) %d."), iError);
sl@0:     		iAudioPlayer->Close();
sl@0:     		CActiveScheduler::Stop();    		
sl@0:     		}
sl@0: 		}
sl@0:     }
sl@0: 
sl@0: 
sl@0: // Positive Tests
sl@0: 
sl@0: /**
sl@0: *
sl@0: * NewL()
sl@0: *
sl@0: * @param const TDesC& aTestName
sl@0: *
sl@0: * @return CTestMmfAudioPlayDRMEnableAgentUI*
sl@0: *                       Constructed CTestMmfAudioPlayDRMEnableAgentUI object
sl@0: *
sl@0: */
sl@0: CTestMmfAudioPlayDRMEnableAgentUI* CTestMmfAudioPlayDRMEnableAgentUI::NewL(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName, const TDesC& aUniqueId)
sl@0:     {
sl@0:     return new (ELeave) CTestMmfAudioPlayDRMEnableAgentUI(aTestName, aSectName, aKeyName, aUniqueId);
sl@0:     }
sl@0: 
sl@0: /**
sl@0: *
sl@0: * Test step constructor.
sl@0: * Ctor for CTestMmfAudioPlayDRMEnableAgentUI.
sl@0: *
sl@0: * @param const TDesC& aTestName
sl@0: *
sl@0: */
sl@0: CTestMmfAudioPlayDRMEnableAgentUI::CTestMmfAudioPlayDRMEnableAgentUI(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName, const TDesC& aUniqueId)
sl@0: 	:CTestMmfDRMAudioPlayerBase(aTestName, aSectName, aKeyName, aUniqueId)
sl@0:     {
sl@0:     }
sl@0: 
sl@0: void CTestMmfAudioPlayDRMEnableAgentUI::AfterOpenL()
sl@0: 	{
sl@0:     // Create DRM custom command
sl@0:     MMMFDRMCustomCommand* drmCustomCommand;
sl@0:     drmCustomCommand = iAudioPlayer->GetDRMCustomCommand();
sl@0:     if (drmCustomCommand == NULL)
sl@0:         {
sl@0:         ERR_PRINTF1(_L("MMMFDRMCustomCommand is NULL."));
sl@0:         iError = KErrUnknown;
sl@0:         User::Leave(KErrUnknown);
sl@0:         }
sl@0: 
sl@0:     INFO_PRINTF1(_L("Enabling Agent's user interface for errors and confirmation requests..."));
sl@0:     iError = drmCustomCommand->SetAgentProperty(ContentAccess::EAgentPropertyAgentUI, 3);
sl@0:     // After DevCR JFOT-6EMFVL (which changes the CContentFile::SetAgentProperty to call 
sl@0:     // SetProperty on a member of CData instead of CContent), the underlying reference test
sl@0:     // agent returns a different error value (KErrCANotSupported instead of KErrNone).
sl@0:     if (iError == KErrCANotSupported)
sl@0:         {
sl@0:         // Reset the error code as it's not really an error :)
sl@0: 		iError = KErrNone;
sl@0:         }
sl@0:     else
sl@0:     	{
sl@0:         ERR_PRINTF2(_L("Enabling Agent's user interface failed, unexpected error %d."), iError);
sl@0:         User::Leave(iError);
sl@0:     	}
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: *
sl@0: * Do the test step.
sl@0: * Each test step must supply an implementation for DoTestStepL.
sl@0: *
sl@0: * @return TVerdict: The result of the test step.
sl@0: *
sl@0: */
sl@0: TVerdict CTestMmfAudioPlayDRMEnableAgentUI::DoTestStepL()
sl@0:     {
sl@0:     INFO_PRINTF1(_L("Enable agent's user interface for errors and confirmation requests property. Open and play a protected audio clip from a file for PLAY intent."));
sl@0: 
sl@0:     iTestStepResult = EFail;
sl@0: 
sl@0:     TRAPD(err,FsmL(EAudioOpen)); // Call to open the audio file
sl@0:     if (err == KErrNone)
sl@0:     	{
sl@0:     	CActiveScheduler::Start(); // ActiveScheduler started ONLY once
sl@0:     	if (iError == KErrNone)
sl@0: 			{
sl@0: 			iTestStepResult=EPass;
sl@0: 			}
sl@0: 	   	}
sl@0:     return iTestStepResult;
sl@0:     }
sl@0: 
sl@0: 
sl@0: /**
sl@0: *
sl@0: * NewL()
sl@0: *
sl@0: * @param const TDesC& aTestName
sl@0: *
sl@0: * @return CTestMmfAudioPlayDRMDisableAutoIntent*
sl@0: *                       Constructed CTestMmfAudioPlayDRMDisableAutoIntent object
sl@0: *
sl@0: */
sl@0: CTestMmfAudioPlayDRMDisableAutoIntent* CTestMmfAudioPlayDRMDisableAutoIntent::NewL(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName, const TDesC& aUniqueId)
sl@0:     {
sl@0:     return new (ELeave) CTestMmfAudioPlayDRMDisableAutoIntent(aTestName, aSectName, aKeyName, aUniqueId);
sl@0:     }
sl@0: 
sl@0: /**
sl@0: *
sl@0: * Test step constructor.
sl@0: * Ctor for CTestMmfAudioPlayDRMDisableAutoIntent.
sl@0: *
sl@0: * @param const TDesC& aTestName
sl@0: *
sl@0: */
sl@0: CTestMmfAudioPlayDRMDisableAutoIntent::CTestMmfAudioPlayDRMDisableAutoIntent(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName, const TDesC& aUniqueId)
sl@0: 	:CTestMmfDRMAudioPlayerBase(aTestName, aSectName, aKeyName, aUniqueId)
sl@0:     {
sl@0:     }
sl@0:     
sl@0: void CTestMmfAudioPlayDRMDisableAutoIntent::AfterOpenL()
sl@0: 	{
sl@0:     // Create DRM custom command
sl@0:     MMMFDRMCustomCommand* drmCustomCommand;
sl@0:     drmCustomCommand = iAudioPlayer->GetDRMCustomCommand();
sl@0: 
sl@0:     if (drmCustomCommand == NULL)
sl@0:         {
sl@0:         ERR_PRINTF1(_L("MMMFDRMCustomCommand is NULL."));
sl@0:         iError = KErrUnknown;
sl@0:         User::Leave(KErrUnknown);
sl@0:         }
sl@0: 
sl@0:     INFO_PRINTF1(_L("Disabling automatic intent..."));
sl@0:     iError = drmCustomCommand->DisableAutomaticIntent(EFalse);
sl@0:     if (iError != KErrNone)
sl@0:         {
sl@0:         ERR_PRINTF2(_L("Disabling the automatic intent failed, unexpected error %d."), iError);
sl@0:         User::Leave(iError);
sl@0:         }	
sl@0: 	}
sl@0: 	
sl@0: /**
sl@0: *
sl@0: * Do the test step.
sl@0: * Each test step must supply an implementation for DoTestStepL.
sl@0: *
sl@0: * @return TVerdict: The result of the test step.
sl@0: *
sl@0: */
sl@0: TVerdict CTestMmfAudioPlayDRMDisableAutoIntent::DoTestStepL()
sl@0: 	{
sl@0: 
sl@0:     INFO_PRINTF1(_L("Open a protected audio file and disable automatic intent. Play."));
sl@0: 
sl@0:     iTestStepResult = EFail;
sl@0: 
sl@0:     TRAPD(err,FsmL(EAudioOpen)); // Call to open the audio file
sl@0:       
sl@0:     if(err == KErrNone)  	
sl@0:     	{
sl@0:     	
sl@0:    		CActiveScheduler::Start(); // ActiveScheduler started ONLY once
sl@0:        
sl@0:     	if (iError == KErrNone)
sl@0:        		{
sl@0:         		INFO_PRINTF1(_L("Executing intent..."));
sl@0: 	    		MMMFDRMCustomCommand* drmCustomCommand;
sl@0: 	    		drmCustomCommand = iAudioPlayer->GetDRMCustomCommand();
sl@0: 
sl@0: 	    	if (drmCustomCommand == NULL)
sl@0: 	        	{
sl@0: 	        	ERR_PRINTF1(_L("MMMFDRMCustomCommand is NULL."));
sl@0: 	        	User::Leave(KErrUnknown);
sl@0: 	        	}
sl@0:         
sl@0:         	iError = drmCustomCommand->ExecuteIntent(ContentAccess::EPlay);
sl@0:         	if (iError != KErrNone)
sl@0:             	{
sl@0:             	ERR_PRINTF2(_L("Executing the intent failed, unexpected error %d."), iError);
sl@0:             	}
sl@0:         	}
sl@0:         
sl@0: 	   	if (iError == KErrNone)
sl@0: 	   		{
sl@0: 			iTestStepResult = EPass;
sl@0: 			}
sl@0: 
sl@0:     	}
sl@0:     return iTestStepResult;
sl@0:     }