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