commsfwutils/commsbufs/version1/mbufmgr/TS_mbufmgr/Test09Align.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 09 for Align() methods
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 
       
    21 // Test system includes
       
    22 #include <networking/log.h>
       
    23 #include <networking/teststep.h>
       
    24 #include "TestStepCTMbufmgr.h"
       
    25 #include "TestSuiteCTMbufmgr.h"
       
    26 
       
    27 #include "Test09Align.h"
       
    28 
       
    29 // constructor
       
    30 CTest09Align::CTest09Align()
       
    31 	{
       
    32 	iTestStepName = _L("MBufMgrTest09");// Store the name of this test case
       
    33 	}
       
    34 
       
    35 // destructor
       
    36 CTest09Align::~CTest09Align()
       
    37 	{
       
    38 	}
       
    39 
       
    40 //
       
    41 enum TVerdict CTest09Align::doTestStepL(void)
       
    42 	{
       
    43 	__UHEAP_MARK;
       
    44 	
       
    45 	//-------------- substep 0 --------------------
       
    46 	Log(_L("  00 Read parameters from the script:"));
       
    47 	CScriptInput* aInput;
       
    48 	CleanupStack::PushL( aInput= new (ELeave) CScriptInput );
       
    49 	TInt i;
       
    50 	TBuf<20> aBuf;
       
    51 	TInt bRet;
       
    52 	aInput->aBufsBefore=0;
       
    53 	for (i = 0;i<50;i++)
       
    54 		{
       
    55 		aBuf.Format(_L("Length%02d"),i+1);
       
    56 		bRet = GetIntFromConfig(_L("MBufMgrTest09"), aBuf, aInput->aBuf[i].aLength);
       
    57 		if (!bRet)
       
    58 			{
       
    59 			return EFail;
       
    60 			}
       
    61 		if (aInput->aBuf[i].aLength == -1) break;
       
    62 
       
    63 		aBuf.Format(_L("Offset%02d"),i+1);
       
    64 		bRet = GetIntFromConfig(_L("MBufMgrTest09"), aBuf, aInput->aBuf[i].aOffset);
       
    65 		if (!bRet)
       
    66 			{
       
    67 			return EFail;
       
    68 			}
       
    69 		aInput->aBufsBefore++;
       
    70 		}
       
    71 	bRet = GetIntFromConfig(_L("MBufMgrTest09"),_L("BuffsAfter") , aInput->aBufsAfter);
       
    72 
       
    73    	Log(_L("     The following has been read from the script:"));
       
    74    	Log(_L("     Number of RMBufs in chain before align= %2d"),aInput->aBufsBefore);
       
    75    	Log(_L("     Number of RMBufs in chain after align = %2d"),aInput->aBufsAfter);
       
    76 
       
    77 	for (i = 0; i < aInput->aBufsBefore ; i++ )
       
    78 		{
       
    79    		Log(_L("     Chain #%2d: Offset=%3d Length=%3d"),
       
    80 					         i+1, aInput->aBuf[i].aOffset, aInput->aBuf[i].aLength);
       
    81 		}
       
    82 
       
    83 #ifdef __CFLOG_ACTIVE
       
    84 	__CFLOG_CREATEL;
       
    85 	__CFLOG_OPEN;
       
    86 #endif
       
    87 	
       
    88 	//-------------- substep 1 --------------------
       
    89 	Log(_L("  01 Create CMBufManager and install active scheduler:"));
       
    90     CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
       
    91 	CActiveScheduler::Install(iActSch);
       
    92 	CleanupStack::PushL(CreateInstanceMBufMgrL(KMBufDefaultHeapSize));
       
    93 
       
    94 	//-------------- substep 2 --------------------
       
    95 	Log(_L("  02 Create TestStr structure and fill it with data:"));
       
    96 	CTestStr* aTestStr1;
       
    97 	CleanupStack::PushL( aTestStr1 = new (ELeave) CTestStr );
       
    98 
       
    99 	aTestStr1->iSrcAddr = 0x01234567;
       
   100 	aTestStr1->iDstAddr = 0x89abcdef;
       
   101 	aTestStr1->iSrcPort = 0x0246;
       
   102 	aTestStr1->iDstPort = 0x8ace;
       
   103 	aTestStr1->iLength  = sizeof(CTestStr);
       
   104 	aTestStr1->iOptions = 0x1359;
       
   105 	StripeMem(aTestStr1->iData, 0, sizeof(aTestStr1->iData), '@', 'Z');
       
   106 
       
   107 	//-------------- substep 3 --------------------
       
   108 	Log(_L("  03 Create a chain containing RMBufs as specified in the script:"));
       
   109 	RMBufChain aChain;
       
   110 	RMBuf *buf=0;
       
   111 	for (i = aInput->aBufsBefore-1; i >= 0 ; i-- )
       
   112 		{
       
   113 		TRAPD(ret,buf = iMBMngr->AllocL(KMBufSmallSize));
       
   114 		if (ret!=KErrNone)
       
   115 			{
       
   116 			Log(_L("Error:Could not allocate buffer"));
       
   117 			aChain.Free();
       
   118 
       
   119 #ifdef __CFLOG_ACTIVE
       
   120 			__CFLOG_CLOSE;
       
   121 			__CFLOG_DELETE;
       
   122 #endif
       
   123 			User::Leave(EFail);
       
   124 			}
       
   125 		buf->SetData(aInput->aBuf[i].aOffset,aInput->aBuf[i].aLength);
       
   126 		aChain.Prepend(buf);
       
   127 		}
       
   128 
       
   129 	//-------------- substep 4 --------------------
       
   130 	Log(_L("  04 Copy in TestStr into Chain:"));
       
   131 	aChain.CopyIn(TPtrC8((TUint8 *)aTestStr1, sizeof(CTestStr)));
       
   132 
       
   133 	//-------------- substep 5 --------------------
       
   134 	Log(_L("  05 Allign Chain for the size of TestStr:"));
       
   135 	aChain.Align(sizeof(CTestStr));
       
   136 
       
   137 	//-------------- substep 6 --------------------
       
   138 	Log(_L("  06 Check the number of RMBufs in chain after allign:"));
       
   139 	if (aChain.NumBufs() != aInput->aBufsAfter)
       
   140 		{
       
   141 		Log(_L("ERROR: Number of bufs is %d instead of %d"),aChain.NumBufs(),aInput->aBufsAfter);
       
   142 		aChain.Free();
       
   143 
       
   144 #ifdef __CFLOG_ACTIVE
       
   145 		__CFLOG_CLOSE;
       
   146 		__CFLOG_DELETE;
       
   147 #endif
       
   148 		User::Leave(EFail);
       
   149 		}
       
   150 
       
   151 	//-------------- substep 7 --------------------
       
   152 	Log(_L("  07 Create the pointer of TestStr type and point to the 1st RMBuf in chain:"));
       
   153 	CTestStr* aTestStr2 = (CTestStr*)(aChain.First()->Ptr());
       
   154 
       
   155 	//-------------- substep 8 --------------------
       
   156 	Log(_L("  08 Compare TestStr1 and TestData2. They should be the same:"));
       
   157 	if ( (aTestStr1->iSrcAddr != aTestStr2->iSrcAddr) ||
       
   158 		 (aTestStr1->iDstAddr != aTestStr2->iDstAddr) ||
       
   159 	     (aTestStr1->iSrcPort != aTestStr2->iSrcPort) ||
       
   160 		 (aTestStr1->iDstPort != aTestStr2->iDstPort) ||
       
   161 	     (aTestStr1->iLength  != aTestStr2->iLength)  ||
       
   162 	     (aTestStr1->iOptions != aTestStr2->iOptions) ||
       
   163 	     (Mem::Compare(aTestStr1->iData, sizeof(aTestStr1->iData),
       
   164 		      aTestStr2->iData, sizeof(aTestStr2->iData))) )
       
   165 		{
       
   166 		Log(_L("ERROR: They are not the same"));
       
   167 		aChain.Free();
       
   168 
       
   169 #ifdef __CFLOG_ACTIVE
       
   170 		__CFLOG_CLOSE;
       
   171 		__CFLOG_DELETE;
       
   172 #endif
       
   173 		User::Leave(EFail);
       
   174 		}
       
   175 
       
   176 	//-------------- substep 9 --------------------
       
   177 	Log(_L("  09 Free the chain. Clean up stack:"));
       
   178 	aChain.Free();
       
   179     CleanupStack::PopAndDestroy(aTestStr1);
       
   180     CleanupStack::PopAndDestroy(iMBMngr);
       
   181 	CActiveScheduler::Install(NULL);
       
   182     CleanupStack::PopAndDestroy(iActSch);
       
   183     CleanupStack::PopAndDestroy(aInput);
       
   184 
       
   185 #ifdef __CFLOG_ACTIVE
       
   186 	__CFLOG_CLOSE;
       
   187 	__CFLOG_DELETE;
       
   188 #endif
       
   189  	__UHEAP_MARKEND;
       
   190 	return EPass;
       
   191 	}