mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7806.cpp
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     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 "OpenFileByHandle7806.h"
       
    18 
       
    19 CTestMmfAclntOpenFile7806::CTestMmfAclntOpenFile7806(const TDesC& aTestName, const TDesC& aSectName)
       
    20 	: CTestMmfAclntOpenFile7804(aTestName, aSectName)
       
    21 	{}
       
    22 
       
    23 CTestMmfAclntOpenFile7806* CTestMmfAclntOpenFile7806::NewL(const TDesC& aTestName, const TDesC& aSectName)
       
    24 	{
       
    25 	CTestMmfAclntOpenFile7806* self = new (ELeave) CTestMmfAclntOpenFile7806(aTestName, aSectName);
       
    26 	return self;
       
    27 	}
       
    28 
       
    29 /**
       
    30  * Open new file.
       
    31  */
       
    32 TVerdict CTestMmfAclntOpenFile7806::DoTestL(CMdaAudioPlayerUtility* aPlayer)
       
    33 	{
       
    34 	TVerdict iAllocTestStepResult=EPass;
       
    35 	TInt err = KErrNone;
       
    36 	TBool result = EFalse;
       
    37 	
       
    38 	//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
       
    39 	if( PerformTestL(aPlayer) != EPass )
       
    40 		{
       
    41 		err = iError;
       
    42 		}
       
    43 
       
    44 	if (err != KErrNone)
       
    45 		{
       
    46 		INFO_PRINTF2(_L("Test error, returned error code =  %d"), err);
       
    47 		User::Leave(err);
       
    48 		}
       
    49 	else
       
    50 		{
       
    51 		//Check the iAllocTestStepResult
       
    52 		if (iAllocTestStepResult != EPass)
       
    53 			{
       
    54 			result = ETrue;
       
    55 			}
       
    56 		}	
       
    57 	
       
    58 	TInt failCount = 1;
       
    59 	TBool completed = EFalse;
       
    60 	iAllocTestStepResult = EPass; // XXX check?? assume pass
       
    61 	TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
       
    62 	for(;;)	
       
    63 		{
       
    64 		__UHEAP_SETFAIL(RHeap::EFailNext, failCount);
       
    65 		__MM_HEAP_MARK;
       
    66 
       
    67 		//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
       
    68 		TVerdict verdict = EFail;
       
    69 		TRAP(err, verdict = PerformTestL(aPlayer));
       
    70 		
       
    71 		if (err == KErrNone && verdict != EPass) 
       
    72 			{
       
    73 			err = iError;
       
    74 			}
       
    75 
       
    76 		completed = EFalse;
       
    77 		if (err == KErrNone)
       
    78 			{
       
    79 			TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
       
    80 			if (testAlloc == NULL)
       
    81 				{
       
    82 				reachedEnd = ETrue;
       
    83 				failCount -= 1;
       
    84 				}
       
    85 			else
       
    86 				{
       
    87 				User::Free(testAlloc);	
       
    88 				}			
       
    89 			
       
    90 			//Check the iAllocTestStepResult
       
    91 			if (iAllocTestStepResult != EPass)
       
    92 				{
       
    93 				result = ETrue;
       
    94 				}
       
    95 			
       
    96 			completed = reachedEnd || result;
       
    97 			}
       
    98 		else if (err != KErrNoMemory) // bad error code
       
    99 			{
       
   100 			completed = ETrue;
       
   101 			result = EFail;
       
   102 			}			
       
   103 
       
   104 		__MM_HEAP_MARKEND;
       
   105 		__UHEAP_SETFAIL(RHeap::ENone, 0);
       
   106 
       
   107 		if (completed)
       
   108 			{
       
   109 			break; // exit loop
       
   110 			}
       
   111 
       
   112 		failCount++;
       
   113 		}
       
   114 
       
   115 	failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc
       
   116 
       
   117 	if (err != KErrNone || result)
       
   118 		{
       
   119 		TBuf<80> format;
       
   120 		iAllocTestStepResult = EFail;
       
   121 		if (result)
       
   122 			{
       
   123 			format.Format(_L("  Bad result with %d memory allocations tested\n"), failCount);
       
   124 			}
       
   125 		else
       
   126 			{
       
   127 			format.Format(_L("  Error(%d) with %d memory allocations tested\n"), err, failCount);
       
   128 			}
       
   129 		Log(format);
       
   130 		}
       
   131 	else 
       
   132 		{
       
   133 		TBuf<80> format;
       
   134 		format.Format(_L("  Completed OK with %d memory allocations tested\n"), failCount);
       
   135 		Log(format);
       
   136 		}
       
   137 
       
   138 	return iAllocTestStepResult;
       
   139 	}
       
   140 
       
   141 CTestMmfAclntRepeatPlayAlloc::CTestMmfAclntRepeatPlayAlloc(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName)
       
   142 	: CTestMmfAclntOpenFile7806(aTestName, aSectName), iSectName(aSectName),iKeyName(aKeyName)
       
   143 	{}
       
   144 
       
   145 CTestMmfAclntRepeatPlayAlloc* CTestMmfAclntRepeatPlayAlloc::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName)
       
   146 	{
       
   147 	CTestMmfAclntRepeatPlayAlloc* self = new (ELeave) CTestMmfAclntRepeatPlayAlloc(aTestName, aSectName, aKeyName);
       
   148 	return self;
       
   149 	}
       
   150 
       
   151 TVerdict CTestMmfAclntRepeatPlayAlloc::PerformTestL(CMdaAudioPlayerUtility* aPlayer)
       
   152 	{
       
   153 	INFO_PRINTF1( _L("TestPlayerUtils : OpenFileL(RFile&)/Play"));
       
   154 	TInt repeatCount;
       
   155 	TVerdict ret = EFail;
       
   156 	iError = KErrNone;
       
   157 
       
   158 	RFs fs;
       
   159 
       
   160 	User::LeaveIfError(fs.Connect());
       
   161 	CleanupClosePushL(fs);
       
   162 	User::LeaveIfError(fs.ShareProtected());
       
   163 
       
   164 	TBuf<KSizeBuf>	filename;
       
   165 	TPtrC			filename1; 
       
   166 	RFile			file;
       
   167 
       
   168 	if(!GetStringFromConfig(iSectName, iKeyName, filename1))
       
   169 		{
       
   170 		return EInconclusive;
       
   171 		}
       
   172 
       
   173 	GetDriveName(filename);
       
   174 	filename.Append(filename1);
       
   175 
       
   176 	User::LeaveIfError( file.Open( fs, filename, EFileRead ) );
       
   177 	CleanupClosePushL(file);
       
   178 	if(!GetIntFromConfig(_L("SectionRepeatCount"), _L("numOfRepeat"), repeatCount))
       
   179 		{
       
   180 		return EInconclusive;
       
   181 		}
       
   182 	aPlayer->SetRepeats(repeatCount, TTimeIntervalMicroSeconds(2));
       
   183 	aPlayer->OpenFileL(file);
       
   184 	CActiveScheduler::Start();
       
   185 	
       
   186 	if (iError == KErrNone)
       
   187 		{
       
   188 		aPlayer->Play();
       
   189 		CActiveScheduler::Start();
       
   190 		}
       
   191 
       
   192 	if (iError == KErrNone)
       
   193 		{
       
   194 		ret = EPass;
       
   195 		}
       
   196 	
       
   197 	aPlayer->Close();	
       
   198 	CleanupStack::PopAndDestroy(2, &fs);
       
   199 
       
   200 	return ret;
       
   201 	}