os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7908.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 //
    15 
    16 #include "TestPlayerUtils.h"
    17 #include "OpenFileByHandle7908.h"
    18 
    19 #include <caf/caf.h>
    20 
    21 /**
    22  * Constructor
    23  */
    24 CTestMmfAclntOpenFile7908::CTestMmfAclntOpenFile7908(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
    25 	: CTestMmfAclntOpenFile7902(aTestName, aSectName, aKeyName, aFormat, aCreateFile), iRecUtil(NULL),iPlayUtil(NULL)
    26 	{
    27 	}
    28 
    29 CTestMmfAclntOpenFile7908* CTestMmfAclntOpenFile7908::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
    30 	{
    31 	CTestMmfAclntOpenFile7908* self = new (ELeave) CTestMmfAclntOpenFile7908(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
    32 	return self;
    33 	}
    34 
    35 CTestMmfAclntOpenFile7908* CTestMmfAclntOpenFile7908::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
    36 	{
    37 	CTestMmfAclntOpenFile7908* self = CTestMmfAclntOpenFile7908::NewL(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
    38 	CleanupStack::PushL(self);
    39 	return self;
    40 	}
    41 
    42 /**
    43  * Open a file based clip and record, and then playback 
    44  * Performs alloc tests separately for each step in this test case
    45  * The 4 steps in this case are : 
    46  * 1> Create CMdaAudioRecorderUtility 
    47  * 2> Open CMdaAudioRecorderUtility and record a clip
    48  * 3> Create CMdaAudioPlayerUtility
    49  * 4> Open CMdaAudioRecorderUtility and playback the clip
    50  */
    51 TVerdict CTestMmfAclntOpenFile7908::DoTestStepL()
    52 	{
    53 	INFO_PRINTF1( _L("TestRecorder : Record File"));
    54 	TInt err = KErrNone;
    55 
    56 	//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
    57 	if( PerformTestStepL() != EPass )
    58 		{
    59 		err = iError;
    60 		}
    61 
    62 	if (err != KErrNone)
    63 		{
    64 		INFO_PRINTF2(_L("Test error, returned error code =  %d"), err);
    65 		User::Leave(err);
    66 		}
    67 		
    68 	TInt failCount = 0;//total fail count for all the steps = sum of fail counts in each step
    69 	TInt stepFailCount; //fail count in each step
    70 	TVerdict iAllocTestStepResult = EPass; // XXX check?? assume pass
    71 	
    72 	err = PerformTestStep(1, stepFailCount);
    73 	failCount += stepFailCount;
    74 	if (err != KErrNone)
    75 		{
    76 		iAllocTestStepResult = EFail;
    77 		TBuf<80> format;
    78 		format.Format(_L("  Error(%d) with %d memory allocations tested\n"), err, failCount);
    79 		Log(format);
    80 		return iAllocTestStepResult;
    81 		}		
    82 	
    83 	TRAP(err, ExecuteStep1L());//Till step1 alloc tests are done, now keep the conditions ready 
    84 							   //for performing alloc tests on step 2 i,e keep the iRecUtil 
    85 							   //created and open for recording in this step
    86 	if (err != KErrNone)
    87 		{
    88 		iAllocTestStepResult = EFail;
    89 		TBuf<80> format;
    90 		format.Format(_L("  Error(%d) with %d memory allocations tested\n"), err, failCount);
    91 		Log(format);
    92 		return iAllocTestStepResult;
    93 		}								  
    94 	err = PerformTestStep(2, stepFailCount);	
    95 	failCount += stepFailCount;
    96 	delete iRecUtil;// Was created in ExecuteStep1L to be used for performing alloc tests in step 2 	
    97 	if (err != KErrNone)
    98 		{
    99 		iAllocTestStepResult = EFail;
   100 		TBuf<80> format;
   101 		format.Format(_L("  Error(%d) with %d memory allocations tested\n"), err, failCount);
   102 		Log(format);
   103 		return iAllocTestStepResult;
   104 		}
   105 		
   106 	err = PerformTestStep(3, stepFailCount);
   107 	failCount += stepFailCount;
   108 	if (err != KErrNone)
   109 		{
   110 		iAllocTestStepResult = EFail;
   111 		TBuf<80> format;
   112 		format.Format(_L("  Error(%d) with %d memory allocations tested\n"), err, failCount);
   113 		Log(format);
   114 		return iAllocTestStepResult;
   115 		}
   116 	
   117 	TRAP(err, ExecuteStep3L());//Till step3 alloc tests are done, now keep the conditions ready 
   118 							   //for performing alloc tests on step 4 i,e keep the iPlayUtil 
   119 							   //created and open for playback in this step
   120 	if(err != KErrNone)
   121 		{
   122 		iAllocTestStepResult = EFail;
   123 		TBuf<80> format;
   124 		format.Format(_L("  Error(%d) with %d memory allocations tested\n"), err, failCount);
   125 		Log(format);
   126 		return iAllocTestStepResult;	
   127 		}			
   128 	err = PerformTestStep(4, stepFailCount);
   129 	failCount += stepFailCount;
   130 	delete iPlayUtil; // Was created in ExecuteStep3L to be used for performing alloc tests in step 4
   131 		
   132 	stepFailCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc
   133 	
   134 	if (err != KErrNone)
   135 		{
   136 		iAllocTestStepResult = EFail;
   137 		TBuf<80> format;
   138 		format.Format(_L("  Error(%d) with %d memory allocations tested\n"), err, failCount);
   139 		Log(format);
   140 		}
   141 	else 
   142 		{
   143 		TBuf<80> format;
   144 		format.Format(_L("  Completed OK with %d memory allocations tested\n"), failCount);
   145 		Log(format);
   146 		}
   147 
   148 	return iAllocTestStepResult;
   149 	}
   150 /*
   151  * TVerdict CTestMmfAclntOpenFile7908::PerformTestStep(TInt aStepNo, TInt& aStepFailCount)
   152  * Performs alloc tests on the step aStepNo in this test case
   153  */	
   154 TInt CTestMmfAclntOpenFile7908::PerformTestStep(TInt aStepNo, TInt& aStepFailCount)	
   155 	{
   156 	TBool completed;
   157 	TInt err;
   158 	for(aStepFailCount = 1;;)	
   159 		{
   160 		__UHEAP_SETFAIL(RHeap::EFailNext, aStepFailCount);
   161 		__MM_HEAP_MARK;
   162 
   163 //		INFO_PRINTF2(_L("CAudioRecorderUtility: Alloc Test Loop: %d"), failCount);
   164 		//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
   165 		TVerdict verdict = EFail;
   166 
   167 		switch( aStepNo )
   168 			{
   169 			case 1:
   170 				TRAP(err, verdict = ExecuteStep1L());	
   171 				if(err == KErrNone)
   172 					{
   173 					delete iRecUtil; //Created in ExecuteStep1L. We dont need it open anymore 						
   174 					}
   175 				break; 
   176 			case 2:
   177 				TRAP(err, verdict = ExecuteStep2L());	
   178 				break; 
   179 			case 3:
   180 				TRAP(err, verdict = ExecuteStep3L());
   181 				if(err == KErrNone)
   182 					{
   183 					delete iPlayUtil; //Created in ExecuteStep3L. We dont need it open anymore 						
   184 					}
   185 				break; 
   186 			case 4:
   187 				TRAP(err, verdict = ExecuteStep4L());	
   188 				break; 				
   189 			}
   190 				
   191 		if (err == KErrNone && verdict != EPass)
   192 			{
   193 			err = iError;
   194 			}
   195 
   196 		completed = EFalse;
   197 		if (err == KErrNone)
   198 			{
   199 			TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
   200 			if (testAlloc == NULL)
   201 				{
   202 				completed = ETrue;
   203 				aStepFailCount -= 1;
   204 				}
   205 			else
   206 				{
   207 				User::Free(testAlloc);	
   208 				}			
   209 			
   210 			}
   211 		else if (err != KErrNoMemory) // bad error code
   212 			{
   213 			completed = ETrue;
   214 			}			
   215 		
   216 		__MM_HEAP_MARKEND;
   217 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   218 
   219 		if (completed)
   220 			{
   221 			break; // exit loop
   222 			}
   223 
   224 		aStepFailCount++;
   225 		}//for
   226 		return err;	
   227 	}
   228 /*
   229  * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep1L()
   230  * Executes the statements for step 1 of this test case
   231  */
   232 TVerdict CTestMmfAclntOpenFile7908::ExecuteStep1L()
   233 	{
   234 	iError = KErrTimedOut;
   235 		
   236 	iRecUtil = CMdaAudioRecorderUtility::NewL(*this);
   237 	iError = KErrNone;
   238 	return EPass;	
   239 	}
   240 
   241 /*
   242  * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep2L()
   243  * Executes the statements for step 2 of this test case
   244  */
   245 TVerdict CTestMmfAclntOpenFile7908::ExecuteStep2L()
   246 	{
   247 	TVerdict ret = EFail;
   248 	iError = KErrTimedOut;
   249 	
   250 	User::LeaveIfError(iFs.Connect());
   251 	CleanupClosePushL(iFs);
   252 	User::LeaveIfError(iFs.ShareProtected());
   253 
   254 	if(!GetStringFromConfig(iSectName, iKeyName, iFilename))
   255 		{
   256 		ret = EInconclusive;
   257 		}
   258 
   259 	User::LeaveIfError(iFile.Replace(iFs,iFilename,EFileWrite));
   260 	CleanupClosePushL(iFile);
   261 	iRecUtil->OpenFileL(iFile);
   262 	CleanupClosePushL(*iRecUtil);
   263 	CActiveScheduler::Start();
   264 
   265 	if(iError == KErrNone)
   266 		{
   267 		iError = KErrTimedOut;
   268 		iRecUtil->RecordL();
   269 		CActiveScheduler::Start(); // open -> record
   270 		
   271 		User::After(500000);	// 0.5 sec
   272 		iRecUtil->Stop();
   273 		}
   274 	CleanupStack::PopAndDestroy(3, &iFs);	//iFs, iFile, iRecUtil
   275 	if(iError == KErrNone)
   276 		{
   277 		ret = EPass;
   278 		}		
   279 	return ret;	
   280 	}
   281 	
   282 /*
   283  * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep3L()
   284  * Executes the statements for step 3 of this test case
   285  */
   286  TVerdict CTestMmfAclntOpenFile7908::ExecuteStep3L()
   287 	{
   288 	TVerdict ret = EFail;
   289 	iError = KErrTimedOut;
   290 	
   291 	iPlayUtil = CMdaAudioPlayerUtility::NewL(*this);
   292 	iError = KErrNone;
   293 	ret = EPass;
   294 	return ret;
   295 	}
   296 	
   297 /*
   298  * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep4L()
   299  * Executes the statements for step 4 of this test case
   300  */
   301 TVerdict CTestMmfAclntOpenFile7908::ExecuteStep4L()
   302 	{
   303 	TVerdict ret = EFail;
   304 	iError = KErrTimedOut;	
   305 	
   306 	TRAPD(err, iPlayUtil->OpenFileL(iFilename));
   307 	if (err != KErrNone)
   308 		{
   309 		INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
   310 		ret = EFail;
   311 		}
   312 	CActiveScheduler::Start();
   313 	if (iError != KErrNone)
   314 		{
   315 		INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
   316 		ret = EFail;
   317 		}
   318 	if( iError == KErrNone )
   319 		{
   320 		iPlayUtil->Play();
   321 		CActiveScheduler::Start();
   322 		}
   323 	iPlayUtil->Close();		
   324 	if (iError != KErrNone)
   325 		{
   326 		INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError);
   327 		ret = EFail;
   328 		}	
   329 	if( iError == KErrNone ) 
   330 		{
   331 		RFile file;
   332 		TInt size = 0;
   333 		
   334 		User::LeaveIfError(iFs.Connect());
   335 		CleanupClosePushL(iFs);
   336 		User::LeaveIfError(iFs.ShareProtected());
   337 		User::LeaveIfError(file.Open(iFs,iFilename,EFileRead));
   338 		CleanupClosePushL(file);
   339 		User::LeaveIfError(file.Size(size));
   340 
   341 		if(size > 0)
   342 			{
   343 			ret = EPass;
   344 			}
   345 		CleanupStack::PopAndDestroy(2, &iFs); //iFile, iFs
   346 		}
   347 
   348 	ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError );
   349 	if(iError == KErrNone)
   350 		{
   351 		User::After(500000);	
   352 		}
   353 
   354 	return	ret;
   355 	}