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