os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/vclnt/src/OpenFileByHandle0036.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/vclnt/src/OpenFileByHandle0036.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,156 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "TestPlayer.h"
    1.20 +#include "OpenFileByHandle0036.h"
    1.21 +
    1.22 +#include <caf/caf.h>
    1.23 +#include <ecom/ecom.h>
    1.24 +
    1.25 +/**
    1.26 + * Constructor
    1.27 + */
    1.28 +CTestMmfVclntOpenFile0036::CTestMmfVclntOpenFile0036(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName,const TBool aPlay)
    1.29 +	:CTestMmfVclntOpenFile0034(aTestName, aSectName, aKeyName, aPlay)
    1.30 +	{
    1.31 +	}
    1.32 +
    1.33 +CTestMmfVclntOpenFile0036* CTestMmfVclntOpenFile0036::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName,const TBool aPlay)
    1.34 +	{
    1.35 +	CTestMmfVclntOpenFile0036* self = new (ELeave) CTestMmfVclntOpenFile0036(aTestName,aSectName,aKeyName,aPlay);
    1.36 +	return self;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    1.37 +	}
    1.38 +
    1.39 +CTestMmfVclntOpenFile0036* CTestMmfVclntOpenFile0036::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName,const TBool aPlay)
    1.40 +	{
    1.41 +	CTestMmfVclntOpenFile0036* self = CTestMmfVclntOpenFile0036::NewL(aTestName,aSectName,aKeyName,aPlay);
    1.42 +	CleanupStack::PushL(self);
    1.43 +	return self;
    1.44 +	}
    1.45 +
    1.46 +/**
    1.47 + * Load and initialise an audio file.
    1.48 + */
    1.49 +TVerdict CTestMmfVclntOpenFile0036::DoTestStepL()
    1.50 +	{
    1.51 +	TVerdict iAllocTestStepResult=EPass;
    1.52 +	TInt err = KErrNone;
    1.53 +	TBool result = EFalse;
    1.54 +	
    1.55 +	InitWservL();
    1.56 +
    1.57 +	
    1.58 +	//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
    1.59 +	if( PerformTestStepL() != EPass )
    1.60 +		{
    1.61 +		err = iError;
    1.62 +		}
    1.63 +
    1.64 +	if (err != KErrNone)
    1.65 +		{
    1.66 +		INFO_PRINTF2(_L("Test error, returned error code =  %d"), err);
    1.67 +		User::Leave(err);
    1.68 +		}
    1.69 +	else
    1.70 +		{
    1.71 +		//Check the iAllocTestStepResult
    1.72 +		if (iAllocTestStepResult != EPass)
    1.73 +			{
    1.74 +			result = ETrue;
    1.75 +			}
    1.76 +		}	
    1.77 +	
    1.78 +	TInt failCount = 1;
    1.79 +	TBool completed = EFalse;
    1.80 +	iAllocTestStepResult = EPass; // TODO check?? assume pass
    1.81 +	TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
    1.82 +	for(;;)	
    1.83 +		{
    1.84 +		__UHEAP_SETFAIL(RHeap::EFailNext, failCount);
    1.85 +		__MM_HEAP_MARK;
    1.86 +
    1.87 +		//INFO_PRINTF2(_L("CVideoPlayerUtility: Alloc Test Loop: %d"), failCount);
    1.88 +		//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
    1.89 +		TVerdict verdict = EFail;
    1.90 +		TRAP(err, verdict = PerformTestStepL());
    1.91 +		if (err == KErrNone && verdict != EPass)
    1.92 +			{
    1.93 +			err = iError;
    1.94 +			}
    1.95 +
    1.96 +		completed = EFalse;
    1.97 +		if (err == KErrNone)
    1.98 +			{
    1.99 +			TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
   1.100 +			if (testAlloc == NULL)
   1.101 +				{
   1.102 +				reachedEnd = ETrue;
   1.103 +				failCount -= 1;
   1.104 +				}
   1.105 +			else
   1.106 +				{
   1.107 +				User::Free(testAlloc);	
   1.108 +				}			
   1.109 +			
   1.110 +			//Check the iAllocTestStepResult
   1.111 +			if (iAllocTestStepResult != EPass)
   1.112 +				{
   1.113 +				result = ETrue;
   1.114 +				}
   1.115 +			
   1.116 +			completed = reachedEnd || result;
   1.117 +			}
   1.118 +		else if (err != KErrNoMemory) // bad error code
   1.119 +			{
   1.120 +			completed = ETrue;
   1.121 +			result = EFail;
   1.122 +			}			
   1.123 +
   1.124 +		__MM_HEAP_MARKEND;
   1.125 +		__UHEAP_SETFAIL(RHeap::ENone, 0);
   1.126 +
   1.127 +		if (completed)
   1.128 +			{
   1.129 +			break; // exit loop
   1.130 +			}
   1.131 +
   1.132 +		failCount++;
   1.133 +		}
   1.134 +
   1.135 +	failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc
   1.136 +
   1.137 +	if (err != KErrNone || result)
   1.138 +		{
   1.139 +		iAllocTestStepResult = EFail;
   1.140 +		TBuf<80> format;
   1.141 +		if (result)
   1.142 +			{
   1.143 +			format.Format(_L("  Bad result with %d memory allocations tested\n"), failCount);
   1.144 +			}
   1.145 +		else
   1.146 +			{
   1.147 +			format.Format(_L("  Error(%d) with %d memory allocations tested\n"), err, failCount);
   1.148 +			}
   1.149 +		Log(format);
   1.150 +		}
   1.151 +	else 
   1.152 +		{
   1.153 +		TBuf<80> format;
   1.154 +		format.Format(_L("  Completed OK with %d memory allocations tested\n"), failCount);
   1.155 +		Log(format);
   1.156 +		}
   1.157 +
   1.158 +	return iAllocTestStepResult;
   1.159 +	}