commsfwutils/commsbufs/version1/mbufmgr/TS_mbufmgr/Test14HeapFreeCheck.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2002-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 // Contains MBufMgr Test Step 14 that check rmbud does not use heap allocation
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 //#include <e32cmn.h>	// maybe this is needed for eka2 ?
       
    21 #include <e32std.h>
       
    22 
       
    23 // Test system includes
       
    24 #include <networking/log.h>
       
    25 #include <networking/teststep.h>
       
    26 #include "TestStepCTMbufmgr.h"
       
    27 #include "TestSuiteCTMbufmgr.h"
       
    28 
       
    29 #include "Test14HeapFreeCheck.h"
       
    30 
       
    31 // constructor
       
    32 CTest14HeapFreeCheck::CTest14HeapFreeCheck()
       
    33 	{
       
    34 	iTestStepName = _L("MBufMgrTest14");// Store the name of this test case
       
    35 	}
       
    36 
       
    37 // destructor
       
    38 CTest14HeapFreeCheck::~CTest14HeapFreeCheck()
       
    39 	{
       
    40 	}
       
    41 
       
    42 //
       
    43 enum TVerdict CTest14HeapFreeCheck::doTestStepL(void)
       
    44 	{
       
    45 
       
    46 #if defined (_DEBUG)
       
    47 	__UHEAP_MARK;
       
    48 	
       
    49 #ifdef __CFLOG_ACTIVE
       
    50 	__CFLOG_CREATEL;
       
    51 	__CFLOG_OPEN;
       
    52 #endif
       
    53 	
       
    54 	//-------------- substep 1 --------------------
       
    55 	Log(_L("  01 Creating CMBufManager and installing active scheduler:"));
       
    56     CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
       
    57 	CActiveScheduler::Install(iActSch);
       
    58 	CleanupStack::PushL(CreateInstanceMBufMgrL(KMBufDefaultHeapSize));
       
    59 
       
    60 	//-------------- substep 2 --------------------
       
    61 	Log(_L("  02 Allocating two descriptors (Des1 & Des2):"));
       
    62 	TBuf8<1000> *aDes1, *aDes2;
       
    63     CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<1000> );
       
    64     CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<1000> );
       
    65 	aDes1->SetLength(1000);
       
    66 	aDes2->SetLength(1000);
       
    67 
       
    68 	//-------------- substep 2 --------------------
       
    69 	Log(_L("  02 Set User heap to fail at the next alloc.:"));
       
    70 	User::__DbgSetAllocFail(RHeap::EUser, RHeap::EFailNext, 0);
       
    71 
       
    72 	//-------------- substep 3 --------------------
       
    73 	Log(_L("  03 Allocate Chain1:"));
       
    74 	RMBufChain aChain1;
       
    75 	TRAPD(ret,aChain1.AllocL(1000));
       
    76 	if (ret != KErrNone)
       
    77 		{
       
    78 		Log(_L("Error: Couldn't allocate Chain1:"));
       
    79 		User::__DbgSetAllocFail(RHeap::EUser, RHeap::ENone, 0);
       
    80 
       
    81 #ifdef __CFLOG_ACTIVE
       
    82 		__CFLOG_CLOSE;
       
    83 		__CFLOG_DELETE;
       
    84 #endif
       
    85 		User::Leave(EFail);
       
    86 		}
       
    87 
       
    88 	//-------------- substep 4 --------------------
       
    89 	Log(_L("  04 Copy in Des1 into Chain1:"));
       
    90 	aChain1.CopyIn(*aDes1);
       
    91 
       
    92 	//-------------- substep 5 --------------------
       
    93 	Log(_L("  05 Split Chain1. The 2nd part goes to Chain2:"));
       
    94 	RMBufChain aChain2;
       
    95 	TRAP(ret,aChain1.SplitL(300, aChain2));
       
    96 	if (ret != KErrNone)
       
    97 		{
       
    98 		Log(_L("Error: Couldn't Split"));
       
    99 		aChain1.Free();
       
   100 		aChain2.Free();
       
   101 		User::__DbgSetAllocFail(RHeap::EUser, RHeap::ENone, 0);
       
   102 
       
   103 #ifdef __CFLOG_ACTIVE
       
   104 		__CFLOG_CLOSE;
       
   105 		__CFLOG_DELETE;
       
   106 #endif
       
   107 		User::Leave(EFail);
       
   108 		}
       
   109 
       
   110 	//-------------- substep 6 --------------------
       
   111 	Log(_L("  06 Copy out Chain1 into Des2:"));
       
   112 	aChain1.CopyOut(*aDes2);
       
   113 
       
   114 	//-------------- substep 7 --------------------
       
   115 	Log(_L("  07 Copy Chain1 into Chain3:"));
       
   116     RMBufChain aChain3;
       
   117 	aChain1.CopyL(aChain3,0, 200);
       
   118 
       
   119 	//-------------- substep 8 --------------------
       
   120 	Log(_L("  08 Free the chains. Clean up stack:"));
       
   121 	aChain1.Free();
       
   122 	aChain2.Free();
       
   123 	aChain3.Free();
       
   124 	User::__DbgSetAllocFail(RHeap::EUser, RHeap::ENone, 0);
       
   125     CleanupStack::PopAndDestroy(aDes2);
       
   126     CleanupStack::PopAndDestroy(aDes1);
       
   127     CleanupStack::PopAndDestroy(iMBMngr);
       
   128 	CActiveScheduler::Install(NULL);
       
   129 	CleanupStack::PopAndDestroy(iActSch);
       
   130 
       
   131 #ifdef __CFLOG_ACTIVE
       
   132 	__CFLOG_CLOSE;
       
   133 	__CFLOG_DELETE;
       
   134 #endif
       
   135 	
       
   136    	__UHEAP_MARKEND;
       
   137 	return EPass;
       
   138 #else
       
   139 	Log(_L("Info: Test Disabled on release build"));
       
   140 	return EPass;
       
   141 #endif
       
   142 	}