mmlibs/mmfw/tsrc/mmfintegrationtest/vclnt/OpenFileByHandle0524.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     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 "TestRecord.h"
       
    17 #include "OpenFileByHandle0524.h"
       
    18 
       
    19 #include <caf/caf.h>
       
    20 
       
    21 /**
       
    22  * Constructor
       
    23  */
       
    24 CTestMmfVclntOpenFile0524::CTestMmfVclntOpenFile0524(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName,const TBool aRec)
       
    25 	: CTestMmfVclntOpenFile0523(aTestName, aSectName, aKeyName, aRec)
       
    26 	{
       
    27 	}
       
    28 
       
    29 CTestMmfVclntOpenFile0524* CTestMmfVclntOpenFile0524::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName,const TBool aRec)
       
    30 	{
       
    31 	CTestMmfVclntOpenFile0524* self = new (ELeave) CTestMmfVclntOpenFile0524(aTestName,aSectName,aKeyName,aRec);
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 CTestMmfVclntOpenFile0524* CTestMmfVclntOpenFile0524::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName,const TBool aRec)
       
    36 	{
       
    37 	CTestMmfVclntOpenFile0524* self = CTestMmfVclntOpenFile0524::NewL(aTestName,aSectName,aKeyName,aRec);
       
    38 	CleanupStack::PushL(self);
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 /**
       
    43  * Load and initialise an audio file.
       
    44  */
       
    45 TVerdict CTestMmfVclntOpenFile0524::DoTestStepL()
       
    46 	{
       
    47 	TVerdict iAllocTestStepResult=EPass;
       
    48 	TInt err = KErrNone;
       
    49 	TBool result = EFalse;
       
    50 	
       
    51 	//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
       
    52 	if( PerformTestStepL() != EPass )
       
    53 		{
       
    54 		err = iError;
       
    55 		}
       
    56 
       
    57 	if (err != KErrNone)
       
    58 		{
       
    59 		INFO_PRINTF2(_L("Test error, returned error code =  %d"), err);
       
    60 		User::Leave(err);
       
    61 		}
       
    62 	else
       
    63 		{
       
    64 		//Check the iAllocTestStepResult
       
    65 		if (iAllocTestStepResult != EPass)
       
    66 			{
       
    67 			result = ETrue;
       
    68 			}
       
    69 		}	
       
    70 	
       
    71 	TInt failCount = 1;
       
    72 	TBool completed = EFalse;
       
    73 	iAllocTestStepResult = EPass; // TODO check?? assume pass
       
    74 	TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
       
    75 	for(;;)	
       
    76 		{
       
    77 		__UHEAP_SETFAIL(RHeap::EFailNext, failCount);
       
    78 		__MM_HEAP_MARK;
       
    79 
       
    80 		//INFO_PRINTF2(_L("CVideoRecorderUtility: Alloc Test Loop: %d"), failCount);
       
    81 		
       
    82 		//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
       
    83 		TVerdict verdict = EFail;
       
    84 		TRAP(err, verdict = PerformTestStepL())
       
    85 		if (err == KErrNone && verdict != EPass)
       
    86 			{
       
    87 			err = iError;
       
    88 			}
       
    89 
       
    90 		completed = EFalse;
       
    91 		if (err == KErrNone)
       
    92 			{
       
    93 			TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
       
    94 			if (testAlloc == NULL)
       
    95 				{
       
    96 				reachedEnd = ETrue;
       
    97 				failCount -= 1;
       
    98 				}
       
    99 			else
       
   100 				{
       
   101 				User::Free(testAlloc);	
       
   102 				}			
       
   103 			
       
   104 			//Check the iAllocTestStepResult
       
   105 			if (iAllocTestStepResult != EPass)
       
   106 				{
       
   107 				result = ETrue;
       
   108 				}
       
   109 			
       
   110 			completed = reachedEnd || result;
       
   111 			}
       
   112 		else if (err != KErrNoMemory) // bad error code
       
   113 			{
       
   114 			completed = ETrue;
       
   115 			result = EFail;
       
   116 			}			
       
   117 
       
   118 		__MM_HEAP_MARKEND;
       
   119 		__UHEAP_SETFAIL(RHeap::ENone, 0);
       
   120 
       
   121 		if (completed)
       
   122 			{
       
   123 			break; // exit loop
       
   124 			}
       
   125 
       
   126 		failCount++;
       
   127 		}
       
   128 
       
   129 	failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc
       
   130 
       
   131 	if (err != KErrNone || result)
       
   132 		{
       
   133 		iAllocTestStepResult = EFail;
       
   134 		TBuf<80> format;
       
   135 		if (result)
       
   136 			{
       
   137 			format.Format(_L("  Bad result with %d memory allocations tested\n"), failCount);
       
   138 			}
       
   139 		else
       
   140 			{
       
   141 			format.Format(_L("  Error(%d) with %d memory allocations tested\n"), err, failCount);
       
   142 			}
       
   143 		Log(format);
       
   144 		}
       
   145 	else 
       
   146 		{
       
   147 		TBuf<80> format;
       
   148 		format.Format(_L("  Completed OK with %d memory allocations tested\n"), failCount);
       
   149 		Log(format);
       
   150 		}
       
   151 
       
   152 	return iAllocTestStepResult;
       
   153 	}