os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/TestAudioPlayerDRM.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Integration tests.
    15 // 
    16 //
    17 
    18 #include "TestAudioPlayerDRM.h"
    19 
    20 // CTestMmfDRMAudioPlayerBase implementation
    21 
    22 /**
    23 *
    24 * CTestMmfDRMAudioPlayerBase()
    25 *
    26 * Constructor to set the Test step name, section name and key names.
    27 *
    28 */
    29 CTestMmfDRMAudioPlayerBase::CTestMmfDRMAudioPlayerBase(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName, const TDesC& aUniqueId)
    30 	{
    31 	iTestStepName = aTestName;
    32 	iSectName = aSectName;
    33 	iKeyName = aKeyName;
    34 	iUniqueId = aUniqueId;
    35 	}
    36 
    37 /**
    38 *
    39 * FsmL()
    40 *
    41 * @param TMmfAudioEvents aEvent
    42 *
    43 */
    44 void CTestMmfDRMAudioPlayerBase::FsmL(TMmfAudioEvents aEvent, TInt aError)
    45     {
    46     switch (aEvent)
    47         {
    48         case EAudioOpen:
    49             INFO_PRINTF3(_L("Opening the file for PLAY intent : %S, UniqueID : %S"), &iFileName, &iUniqueId);
    50             iAudioPlayer->OpenFileL(TMMFileSource(iFileName, iUniqueId, ContentAccess::EPlay));
    51             break;
    52 
    53         case EAudioPlay:
    54             if (aError != KErrNone) // Check if there's error while opening the file
    55                 {
    56                 ERR_PRINTF2(_L("Opening the audio file failed, unexpected error %d."), aError);
    57                 CActiveScheduler::Stop();
    58                 }
    59             else
    60                 {
    61                 INFO_PRINTF1(_L("Playing the audio file..."));
    62                 AfterOpenL();
    63                 iAudioPlayer->Play();
    64                 }
    65             break;
    66 
    67         case EAudioPlayEnd:
    68             if (aError != KErrNone) // Check if there's error while playing the file
    69                 {
    70                 ERR_PRINTF2(_L("Playing the audio file failed, unexpected error %d."), aError);
    71                 }
    72             else
    73                 {
    74                 INFO_PRINTF1(_L("Audio file opened and played."));
    75                 iTestStepResult = EPass;
    76                 }
    77 			CActiveScheduler::Stop();
    78             break;
    79 
    80         default:
    81             INFO_PRINTF1(_L("Invalid Audio event!"));
    82         }
    83     };
    84     
    85 void CTestMmfDRMAudioPlayerBase::AfterOpenL()
    86 	{
    87 	}
    88 	
    89 /**
    90 *
    91 * Test step Preamble.
    92 *
    93 * @return TVerdict: The result of the test step.
    94 * 
    95 */
    96 TVerdict CTestMmfDRMAudioPlayerBase::DoTestStepPreambleL()
    97     {
    98     // Install the scheduler
    99     TVerdict verdict = CTestMmfAclntStep::DoTestStepPreambleL();
   100 
   101     iError = KErrNone;
   102 
   103     // Get the filename
   104     TPtrC filename1;
   105     if (!GetStringFromConfig(iSectName, iKeyName, filename1))
   106         {
   107         return EInconclusive;
   108         }
   109     GetDriveName(iFileName);
   110     iFileName.Append(filename1);
   111 
   112     // Create an audio player
   113     iAudioPlayer = CMdaAudioPlayerUtility::NewL(*this);
   114     if (iAudioPlayer == NULL)
   115         {
   116         return EInconclusive;
   117         }
   118 
   119     return verdict;
   120     }
   121 
   122 /**
   123 *
   124 * Test step Postamble.
   125 *
   126 * @return TVerdict: The result of the test step.
   127 * 
   128 */
   129 TVerdict CTestMmfDRMAudioPlayerBase::DoTestStepPostambleL()
   130     {
   131     delete iAudioPlayer;
   132     iAudioPlayer = NULL;
   133     User::After(KOneSecond); // wait for deletion to shut down devsound
   134     return CTestMmfAclntStep::DoTestStepPostambleL(); // Destroy the scheduler
   135     }
   136 
   137 /**
   138 *
   139 * Implementation of the MMdaAudioPlayerCallback interface function.
   140 *
   141 * @param TInt aError
   142 *
   143 */
   144 void CTestMmfDRMAudioPlayerBase::MapcInitComplete(TInt aError, 
   145     const TTimeIntervalMicroSeconds& /*aDuration*/)
   146     {
   147     INFO_PRINTF2(_L("MMdaAudioPlayerCallback Init Complete. Error = %d"), aError);
   148     iError = aError;
   149 	if (iError != KErrNone)
   150     	{
   151     	ERR_PRINTF2(_L("Opening the audio file failed, unexpected error %d."), aError);
   152     	iAudioPlayer->Close();
   153     	CActiveScheduler::Stop();
   154     	}
   155 	else
   156 		{
   157 		TRAP(iError, FsmL(EAudioPlay, aError)); // Call to play audio
   158 		if (iError != KErrNone)
   159     		{
   160     		ERR_PRINTF2(_L("Got an error from the FsmL(EAudioPlay) %d."), iError);
   161     		iAudioPlayer->Close();
   162     		CActiveScheduler::Stop();    		
   163     		}
   164 		}
   165 	}
   166 
   167 /**
   168 *
   169 * Implementation of the MMdaAudioPlayerCallback interface function.
   170 *
   171 * @param TInt aError
   172 *
   173 */
   174 void CTestMmfDRMAudioPlayerBase::MapcPlayComplete(TInt aError)
   175     {
   176     INFO_PRINTF2(_L("MMdaAudioPlayerCallback Play Complete. Error = %d"), aError);
   177     iError = aError;
   178 	if (iError != KErrNone)
   179     	{
   180     	ERR_PRINTF2(_L("Opening the audio file failed, unexpected error %d."), aError);
   181     	iAudioPlayer->Close();
   182     	CActiveScheduler::Stop();
   183     	}
   184 	else
   185 		{
   186 		TRAP(iError, FsmL(EAudioPlayEnd, aError));
   187 		if (iError != KErrNone)
   188     		{
   189     		ERR_PRINTF2(_L("Got an error from the FsmL(EAudioPlayEnd) %d."), iError);
   190     		iAudioPlayer->Close();
   191     		CActiveScheduler::Stop();    		
   192     		}
   193 		}
   194     }
   195 
   196 
   197 // Positive Tests
   198 
   199 /**
   200 *
   201 * NewL()
   202 *
   203 * @param const TDesC& aTestName
   204 *
   205 * @return CTestMmfAudioPlayDRMEnableAgentUI*
   206 *                       Constructed CTestMmfAudioPlayDRMEnableAgentUI object
   207 *
   208 */
   209 CTestMmfAudioPlayDRMEnableAgentUI* CTestMmfAudioPlayDRMEnableAgentUI::NewL(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName, const TDesC& aUniqueId)
   210     {
   211     return new (ELeave) CTestMmfAudioPlayDRMEnableAgentUI(aTestName, aSectName, aKeyName, aUniqueId);
   212     }
   213 
   214 /**
   215 *
   216 * Test step constructor.
   217 * Ctor for CTestMmfAudioPlayDRMEnableAgentUI.
   218 *
   219 * @param const TDesC& aTestName
   220 *
   221 */
   222 CTestMmfAudioPlayDRMEnableAgentUI::CTestMmfAudioPlayDRMEnableAgentUI(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName, const TDesC& aUniqueId)
   223 	:CTestMmfDRMAudioPlayerBase(aTestName, aSectName, aKeyName, aUniqueId)
   224     {
   225     }
   226 
   227 void CTestMmfAudioPlayDRMEnableAgentUI::AfterOpenL()
   228 	{
   229     // Create DRM custom command
   230     MMMFDRMCustomCommand* drmCustomCommand;
   231     drmCustomCommand = iAudioPlayer->GetDRMCustomCommand();
   232     if (drmCustomCommand == NULL)
   233         {
   234         ERR_PRINTF1(_L("MMMFDRMCustomCommand is NULL."));
   235         iError = KErrUnknown;
   236         User::Leave(KErrUnknown);
   237         }
   238 
   239     INFO_PRINTF1(_L("Enabling Agent's user interface for errors and confirmation requests..."));
   240     iError = drmCustomCommand->SetAgentProperty(ContentAccess::EAgentPropertyAgentUI, 3);
   241     // After DevCR JFOT-6EMFVL (which changes the CContentFile::SetAgentProperty to call 
   242     // SetProperty on a member of CData instead of CContent), the underlying reference test
   243     // agent returns a different error value (KErrCANotSupported instead of KErrNone).
   244     if (iError == KErrCANotSupported)
   245         {
   246         // Reset the error code as it's not really an error :)
   247 		iError = KErrNone;
   248         }
   249     else
   250     	{
   251         ERR_PRINTF2(_L("Enabling Agent's user interface failed, unexpected error %d."), iError);
   252         User::Leave(iError);
   253     	}
   254 	}
   255 
   256 /**
   257 *
   258 * Do the test step.
   259 * Each test step must supply an implementation for DoTestStepL.
   260 *
   261 * @return TVerdict: The result of the test step.
   262 *
   263 */
   264 TVerdict CTestMmfAudioPlayDRMEnableAgentUI::DoTestStepL()
   265     {
   266     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."));
   267 
   268     iTestStepResult = EFail;
   269 
   270     TRAPD(err,FsmL(EAudioOpen)); // Call to open the audio file
   271     if (err == KErrNone)
   272     	{
   273     	CActiveScheduler::Start(); // ActiveScheduler started ONLY once
   274     	if (iError == KErrNone)
   275 			{
   276 			iTestStepResult=EPass;
   277 			}
   278 	   	}
   279     return iTestStepResult;
   280     }
   281 
   282 
   283 /**
   284 *
   285 * NewL()
   286 *
   287 * @param const TDesC& aTestName
   288 *
   289 * @return CTestMmfAudioPlayDRMDisableAutoIntent*
   290 *                       Constructed CTestMmfAudioPlayDRMDisableAutoIntent object
   291 *
   292 */
   293 CTestMmfAudioPlayDRMDisableAutoIntent* CTestMmfAudioPlayDRMDisableAutoIntent::NewL(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName, const TDesC& aUniqueId)
   294     {
   295     return new (ELeave) CTestMmfAudioPlayDRMDisableAutoIntent(aTestName, aSectName, aKeyName, aUniqueId);
   296     }
   297 
   298 /**
   299 *
   300 * Test step constructor.
   301 * Ctor for CTestMmfAudioPlayDRMDisableAutoIntent.
   302 *
   303 * @param const TDesC& aTestName
   304 *
   305 */
   306 CTestMmfAudioPlayDRMDisableAutoIntent::CTestMmfAudioPlayDRMDisableAutoIntent(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName, const TDesC& aUniqueId)
   307 	:CTestMmfDRMAudioPlayerBase(aTestName, aSectName, aKeyName, aUniqueId)
   308     {
   309     }
   310     
   311 void CTestMmfAudioPlayDRMDisableAutoIntent::AfterOpenL()
   312 	{
   313     // Create DRM custom command
   314     MMMFDRMCustomCommand* drmCustomCommand;
   315     drmCustomCommand = iAudioPlayer->GetDRMCustomCommand();
   316 
   317     if (drmCustomCommand == NULL)
   318         {
   319         ERR_PRINTF1(_L("MMMFDRMCustomCommand is NULL."));
   320         iError = KErrUnknown;
   321         User::Leave(KErrUnknown);
   322         }
   323 
   324     INFO_PRINTF1(_L("Disabling automatic intent..."));
   325     iError = drmCustomCommand->DisableAutomaticIntent(EFalse);
   326     if (iError != KErrNone)
   327         {
   328         ERR_PRINTF2(_L("Disabling the automatic intent failed, unexpected error %d."), iError);
   329         User::Leave(iError);
   330         }	
   331 	}
   332 	
   333 /**
   334 *
   335 * Do the test step.
   336 * Each test step must supply an implementation for DoTestStepL.
   337 *
   338 * @return TVerdict: The result of the test step.
   339 *
   340 */
   341 TVerdict CTestMmfAudioPlayDRMDisableAutoIntent::DoTestStepL()
   342 	{
   343 
   344     INFO_PRINTF1(_L("Open a protected audio file and disable automatic intent. Play."));
   345 
   346     iTestStepResult = EFail;
   347 
   348     TRAPD(err,FsmL(EAudioOpen)); // Call to open the audio file
   349       
   350     if(err == KErrNone)  	
   351     	{
   352     	
   353    		CActiveScheduler::Start(); // ActiveScheduler started ONLY once
   354        
   355     	if (iError == KErrNone)
   356        		{
   357         		INFO_PRINTF1(_L("Executing intent..."));
   358 	    		MMMFDRMCustomCommand* drmCustomCommand;
   359 	    		drmCustomCommand = iAudioPlayer->GetDRMCustomCommand();
   360 
   361 	    	if (drmCustomCommand == NULL)
   362 	        	{
   363 	        	ERR_PRINTF1(_L("MMMFDRMCustomCommand is NULL."));
   364 	        	User::Leave(KErrUnknown);
   365 	        	}
   366         
   367         	iError = drmCustomCommand->ExecuteIntent(ContentAccess::EPlay);
   368         	if (iError != KErrNone)
   369             	{
   370             	ERR_PRINTF2(_L("Executing the intent failed, unexpected error %d."), iError);
   371             	}
   372         	}
   373         
   374 	   	if (iError == KErrNone)
   375 	   		{
   376 			iTestStepResult = EPass;
   377 			}
   378 
   379     	}
   380     return iTestStepResult;
   381     }