os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/TestPlayerFileSource.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 // This program is designed the test of the MMF_ACLNT.
    16 // 
    17 //
    18 
    19 /**
    20  @file TestPlayerFileSource.cpp
    21 */
    22 
    23 #include "TestPlayerUtils.h"
    24 #include "TestPlayerFileSource.h"
    25 
    26 //
    27 // CTestMmfAclntFileSource
    28 //
    29 
    30 /**
    31  * Constructor
    32  */
    33 CTestMmfAclntFileSource::CTestMmfAclntFileSource(const TDesC& aTestName,const TDesC& aSectName,
    34 									 const TDesC& aKeyName,const TBool aPlay, 
    35 									 const TInt aExpectedError)
    36 	:iPlay (aPlay)
    37 	,iExpectedError (aExpectedError)
    38 	{
    39 	// store the name of this test case
    40 	iTestStepName = aTestName;
    41 	// store the section-name of the ini file
    42 	iSectName = aSectName;
    43 	// store the key-name of the ini file
    44 	iKeyName = aKeyName;
    45 	}
    46 
    47 /**
    48  * NewL
    49  */
    50 CTestMmfAclntFileSource* CTestMmfAclntFileSource::NewL(const TDesC& aTestName, const TDesC& aSectName,
    51 										   const TDesC& aKeyName,const TBool aPlay, 
    52 										   const TInt aExpectedError = KErrNone)
    53 	{
    54 	CTestMmfAclntFileSource* self = new (ELeave) CTestMmfAclntFileSource(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
    55 	return self;
    56 	}
    57 
    58 /**
    59  * NewLC
    60  */
    61 CTestMmfAclntFileSource* CTestMmfAclntFileSource::NewLC(const TDesC& aTestName, const TDesC& aSectName,
    62 											const TDesC& aKeyName,
    63 											const TBool aPlay,  
    64 											const TInt aExpectedError)
    65 	{
    66 	CTestMmfAclntFileSource* self = CTestMmfAclntFileSource::NewL(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
    67 	CleanupStack::PushL(self);
    68 	return self;
    69 	}
    70 
    71 /**
    72  * MapcInitComplete
    73  */
    74 void CTestMmfAclntFileSource::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
    75 	{
    76 	iError = aError;
    77 	iDuration = aDuration;
    78 	INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete"));
    79 	CActiveScheduler::Stop();
    80 	}
    81 
    82 /**
    83  * MapcPlayComplete
    84  */
    85 void CTestMmfAclntFileSource::MapcPlayComplete(TInt aError)
    86 	{
    87 	iError = aError;
    88 	INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete"));
    89 	CActiveScheduler::Stop();
    90 	}
    91 
    92 /**
    93  * Load and initialise an audio file.
    94  */
    95 TVerdict CTestMmfAclntFileSource::DoTestStepL( void )
    96 	{
    97 	INFO_PRINTF1( _L("TestPlayerUtils : File"));
    98 	TVerdict ret = EFail;
    99 	
   100 	iError = KErrTimedOut;
   101 	
   102 	TBuf<KSizeBuf>	filename;
   103 	TPtrC			filename1;
   104 	
   105 	if(!GetStringFromConfig(iSectName,iKeyName,filename1))
   106 		{
   107 		return EInconclusive;
   108 		}
   109 	
   110 	GetDriveName(filename);
   111 	filename.Append(filename1);
   112 	
   113 	// Create CMdaAudioPlayerUtility Object
   114 	CMdaAudioPlayerUtility* player = NULL;
   115 	player = CMdaAudioPlayerUtility::NewL(*this);
   116 	
   117 	// Create TMMFileSource Object
   118 	TMMFileSource filesource(filename);
   119 	player->OpenFileL(filesource);
   120 	
   121 	// Wait for initialisation callback
   122 	INFO_PRINTF1(_L("Initialise CMdaAudioPlayerUtility"));
   123 	CActiveScheduler::Start();
   124 	
   125 	// Check for expected errors.
   126 	if(iError != KErrNone && (iExpectedError == iError))
   127 		{
   128 		ret = EPass;	// all other tests pass
   129 		delete player;
   130 		User::After(KOneSecond); // wait for deletion to shut down devsound
   131 		ERR_PRINTF2( _L("CMdaAudioPlayerUtility failed with expected error %d"),iError );
   132 		return ret;
   133 		}
   134 
   135 	// Check for errors (after OPEN).
   136 	if (iError == KErrNone && player != NULL)
   137 		{
   138 		if(iPlay)
   139 			{
   140 			iError = KErrTimedOut;
   141 			player->Play();
   142 			
   143 			// Wait for play complete callback
   144 			INFO_PRINTF1(_L("Play CMdaAudioPlayerUtility"));
   145 			CActiveScheduler::Start();
   146 			
   147 			// Check for Callback errors
   148 			if(iError == KErrNone)
   149 				{
   150 				ret = EPass;
   151 				}
   152 			}
   153 		else
   154 			{
   155 			ret = EPass;
   156 			}
   157 		}
   158 	
   159 	// Clean up activities.
   160 	delete player;
   161 	User::After(KOneSecond); // wait for deletion to shut down devsound
   162 
   163 	// Check for errors (final check).
   164 	if(iError != KErrNone)
   165 		{
   166 		ERR_PRINTF2( _L("CMdaAudioPlayerUtility failed with error %d"),iError );
   167 		}
   168 	return	ret;
   169 	}
   170 
   171 //
   172 // CTestMmfAclntFileHandleSource
   173 //
   174 
   175 /**
   176  * Constructor
   177  */
   178 CTestMmfAclntFileHandleSource::CTestMmfAclntFileHandleSource(const TDesC& aTestName,const TDesC& aSectName,
   179 									 const TDesC& aKeyName,const TBool aPlay, 
   180 									 const TInt aExpectedError)
   181 	:iPlay (aPlay)
   182 	,iExpectedError (aExpectedError)
   183 	{
   184 	// store the name of this test case
   185 	iTestStepName = aTestName;
   186 	// store the section-name of the ini file
   187 	iSectName = aSectName;
   188 	// store the key-name of the ini file
   189 	iKeyName = aKeyName;
   190 	}
   191 
   192 /**
   193  * NewL
   194  */
   195 CTestMmfAclntFileHandleSource* CTestMmfAclntFileHandleSource::NewL(const TDesC& aTestName, const TDesC& aSectName,
   196 										   const TDesC& aKeyName,const TBool aPlay, 
   197 										   const TInt aExpectedError = KErrNone)
   198 	{
   199 	CTestMmfAclntFileHandleSource* self = new (ELeave) CTestMmfAclntFileHandleSource(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
   200 	return self;
   201 	}
   202 
   203 /**
   204  * NewLC
   205  */
   206 CTestMmfAclntFileHandleSource* CTestMmfAclntFileHandleSource::NewLC(const TDesC& aTestName, const TDesC& aSectName,
   207 											const TDesC& aKeyName,
   208 											const TBool aPlay,  
   209 											const TInt aExpectedError)
   210 	{
   211 	CTestMmfAclntFileHandleSource* self = CTestMmfAclntFileHandleSource::NewL(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
   212 	CleanupStack::PushL(self);
   213 	return self;
   214 	}
   215 
   216 /**
   217  * MapcInitComplete
   218  */
   219 void CTestMmfAclntFileHandleSource::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
   220 	{
   221 	iError = aError;
   222 	iDuration = aDuration;
   223 	INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete"));
   224 	CActiveScheduler::Stop();
   225 	}
   226 
   227 /**
   228  * MapcPlayComplete
   229  */
   230 void CTestMmfAclntFileHandleSource::MapcPlayComplete(TInt aError)
   231 	{
   232 	iError = aError;
   233 	INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete"));
   234 	CActiveScheduler::Stop();
   235 	}
   236 
   237 /**
   238  * Load and initialise an audio file.
   239  */
   240 TVerdict CTestMmfAclntFileHandleSource::DoTestStepL( void )
   241 	{
   242 	INFO_PRINTF1( _L("TestPlayerUtils : File"));
   243 	TVerdict ret = EFail;
   244 
   245 	iError = KErrTimedOut;
   246 	
   247 	// Get the file name.
   248 	TBuf<KSizeBuf> filename;
   249 	TPtrC filename1;
   250 	if(!GetStringFromConfig(iSectName,iKeyName,filename1))
   251 		{
   252 		return EInconclusive;
   253 		}
   254 	GetDriveName(filename);
   255 	filename.Append(filename1);
   256 	
   257 	// Create CMdaAudioPlayerUtility Object
   258 	CMdaAudioPlayerUtility* player = NULL;
   259 	player = CMdaAudioPlayerUtility::NewL(*this);
   260 	
   261 	// Create RFs and RFile Objects
   262 	RFs fs;
   263 	User::LeaveIfError(fs.Connect());
   264 	CleanupClosePushL(fs);
   265 	User::LeaveIfError(fs.ShareProtected());
   266 	
   267 	RFile file;
   268 	User::LeaveIfError( file.Open( fs, filename, EFileRead ) );
   269 	CleanupClosePushL(file);
   270 	
   271 	// Create TMMFileSource Object
   272 	TMMFileHandleSource filehandlesource(file);
   273 	player->OpenFileL(filehandlesource);
   274 	
   275 	// Wait for initialisation callback
   276 	INFO_PRINTF1(_L("CMdaAudioPlayerUtility->OpenFileL(TMMFileHandleSource)"));
   277 	CActiveScheduler::Start();
   278 	
   279 	// Check for expected errors.
   280 	if((iError != KErrNone) && (iExpectedError == iError))
   281 		{
   282 		ERR_PRINTF2(_L("CMdaAudioPlayerUtility->OpenFileL() Returned the Expected Error : %d"),iError);
   283 		ret=EPass;
   284 		}
   285 	
   286 	// Check for errors.
   287 	if(iError != KErrNone)
   288 		{
   289 		ERR_PRINTF2(_L("CMdaAudioPlayerUtility->OpenFileL() Failed with Error : %d"),iError);
   290 		ret=EFail;
   291 		}
   292 	
   293 	// Check for No errors, so as to start Playback
   294 	if (iError == KErrNone && player != NULL)
   295 		{
   296 		if(iPlay)
   297 			{
   298 			iError = KErrTimedOut;
   299 			player->Play();
   300 			
   301 			// Wait for play complete callback
   302 			INFO_PRINTF1(_L("CMdaAudioPlayerUtility->Play()"));
   303 			CActiveScheduler::Start();
   304 			
   305 			// Check for Callback errors
   306 			if(iError == KErrNone)
   307 				{
   308 				ERR_PRINTF2(_L("CMdaAudioPlayerUtility->Play() completed successfully with return code : %d"),iError);
   309 				ret = EPass;
   310 				}
   311 			else
   312 				{
   313 				ERR_PRINTF2(_L("CMdaAudioPlayerUtility->Play() Failed with Error : %d"),iError );
   314 				ret = EFail;
   315 				}
   316 			}
   317 		else
   318 			{
   319 			ret = EPass;
   320 			}
   321 		}
   322 	
   323 	// Clean up activities.
   324 	delete player;
   325 	User::After(KOneSecond); // wait for deletion to shut down devsound
   326 	CleanupStack::PopAndDestroy(2);
   327 
   328 	return	ret;
   329 	}