commsfwutils/commsbufs/TS_mbufmgr/Test06SplitL.cpp
changeset 72 ae47d0499bee
parent 68 5da8188e392b
child 77 c9776eadbffd
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
     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 06 for SplitL method
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 
       
    21 // Test system includes
       
    22 #ifdef SYMBIAN_OLD_EXPORT_LOCATION
       
    23 #include "networking/log.h"
       
    24 #include "networking/teststep.h"
       
    25 #else
       
    26 #include <networking/log.h>
       
    27 #include <networking/teststep.h>
       
    28 #endif
       
    29 #include "TestStepCTMbufmgr.h"
       
    30 #include "TestSuiteCTMbufmgr.h"
       
    31 
       
    32 #include "Test06SplitL.h"
       
    33 #include <comms-infras/commsbufpond.h>
       
    34 // constructor
       
    35 CTest06Split::CTest06Split()
       
    36 	{
       
    37 	iTestStepName = _L("MBufMgrTest06");// Store the name of this test case
       
    38 	}
       
    39 
       
    40 // destructor
       
    41 CTest06Split::~CTest06Split()
       
    42 	{
       
    43 	}
       
    44 
       
    45 //
       
    46 enum TVerdict CTest06Split::doTestStepL(void)
       
    47 	{
       
    48 	__UHEAP_MARK;
       
    49 		
       
    50 	//-------------- substep 0 --------------------
       
    51 	Log(_L("  00 Read parameters from the script:"));
       
    52 	TInt aOffset;// Will contain the position in chain where split action will be done
       
    53 	TInt aLength;// Will contain the length of desc & chains in the test
       
    54 	TInt bRet = GetIntFromConfig(_L("MBufMgrTest06"), _L("Length"), aLength);
       
    55 	if (!bRet)
       
    56 		{
       
    57 		return EFail;
       
    58 		}
       
    59 	bRet = GetIntFromConfig(_L("MBufMgrTest06"), _L("Offset"), aOffset);
       
    60 	if (!bRet)
       
    61 		{
       
    62 		return EFail;
       
    63 		}
       
    64 	TBool forceSmallBuf = EFalse;
       
    65     bRet = GetIntFromConfig(_L("MBufMgrTest06"), _L("ForceSmallBuf"), forceSmallBuf);
       
    66  	Log(_L("     ------- Chain & Desc LENGTH   = %d --"), aLength);
       
    67  	Log(_L("     ------- OFFSET where to Split = %d --"), aOffset);
       
    68 	if ( (aLength > 1000)    ||(aLength <0) ||
       
    69 		 (aOffset > aLength) || (aOffset <0)  )
       
    70 		{
       
    71 		Log(_L("ERROR: Wrong input parameter(s)"));
       
    72 		return EFail;
       
    73 		}
       
    74 
       
    75 #ifdef __CFLOG_ACTIVE
       
    76 	__CFLOG_CREATEL;
       
    77 	__CFLOG_OPEN;
       
    78 #endif
       
    79 
       
    80 	//-------------- substep 1 --------------------
       
    81 	Log(_L("  01 Creating CMBufManager and installing active scheduler:"));
       
    82     CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
       
    83 	CActiveScheduler::Install(iActSch);
       
    84 
       
    85 	enum { KBigBuf = 256, KSmallBuf = 128 };
       
    86 	if(forceSmallBuf)
       
    87 	    {
       
    88         RArray<TCommsBufPoolCreateInfo> createInfoArray;
       
    89         
       
    90         TCommsBufPoolCreateInfo createInfo;
       
    91         createInfo.iBufSize = KSmallBuf;
       
    92         createInfo.iInitialBufs = 128;
       
    93         createInfo.iGrowByBufs = 64;
       
    94         createInfo.iMinFreeBufs = 40;
       
    95         createInfo.iCeiling = 410; 
       
    96         createInfoArray.AppendL(createInfo);
       
    97         
       
    98         createInfo.iBufSize = KBigBuf;
       
    99         createInfo.iInitialBufs = 3;
       
   100         createInfo.iGrowByBufs = 1;
       
   101         createInfo.iMinFreeBufs = 1;
       
   102         createInfo.iCeiling = 3;
       
   103         createInfoArray.AppendL(createInfo);
       
   104 
       
   105         CreateInstanceMBufMgrL(createInfoArray);
       
   106 
       
   107         createInfoArray.Close();
       
   108 	    }	
       
   109 	else
       
   110 	    {
       
   111         CreateInstanceMBufMgrL(KMBufDefaultHeapSize);
       
   112 	    }
       
   113 	
       
   114 	CleanupClosePushL(iBufPond);
       
   115 
       
   116 	//-------------- substep 2 --------------------
       
   117 	Log(_L("  02 Allocating two descriptors (Des1 & Des2):"));
       
   118 	TBuf8<1000> *aDes1, *aDes2;
       
   119     CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<1000> );
       
   120     CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<1000> );
       
   121 	aDes1->SetLength(aLength);
       
   122 	aDes2->SetLength(aLength);
       
   123 
       
   124 	//-------------- substep 3 --------------------
       
   125 	Log(_L("  03 Fill in Des1 with a pattern:"));
       
   126 	StripeDes(*aDes1, 0, aLength, '@', 'Z');
       
   127 
       
   128 	//-------------- substep 4 --------------------
       
   129 	Log(_L("  04 Fill in Des2 with zeros:"));
       
   130 	StripeDes(*aDes1, 0, aLength, 0, 0);
       
   131 
       
   132 	//-------------- substep 5 --------------------
       
   133 	Log(_L("  05 Allocate Chain1:"));
       
   134 	RMBufChain aChain1;
       
   135 	TRAPD(ret,aChain1.AllocL(aLength));
       
   136 	if (ret != KErrNone)
       
   137 		{
       
   138 		Log(_L("Error: Couldn't allocate Chain1:"));
       
   139 #ifdef __CFLOG_ACTIVE
       
   140 		__CFLOG_CLOSE;
       
   141 		__CFLOG_DELETE;
       
   142 #endif
       
   143 		User::Leave(EFail);
       
   144 		}
       
   145 	
       
   146 	if(forceSmallBuf)
       
   147 	    {
       
   148         for(RMBuf* buf = aChain1.First(); buf; buf = buf->Next())
       
   149             {
       
   150             if(buf->Size() != KBigBuf)
       
   151                 {
       
   152                 Log(_L("-- initial chain should be composed of %d buf, found %d buf"), KBigBuf, buf->Size());
       
   153                 User::Leave(EFail);
       
   154                 }
       
   155             }
       
   156 	    }
       
   157 
       
   158 	//-------------- substep 6 --------------------
       
   159 	Log(_L("  06 Copy in Des1 into Chain1:"));
       
   160 	aChain1.CopyIn(*aDes1);
       
   161 
       
   162 	//-------------- substep 7 --------------------
       
   163 	Log(_L("  07 Split Chain1. The 2nd part goes to Chain2:"));
       
   164 	RMBufChain aChain2;
       
   165 	TRAP(ret,aChain1.SplitL(aOffset, aChain2));
       
   166 	if (ret != KErrNone)
       
   167 		{
       
   168 		Log(_L("Error: Couldn't Split"));
       
   169 		aChain1.Free();
       
   170 		aChain2.Free();
       
   171 #ifdef __CFLOG_ACTIVE
       
   172 		__CFLOG_CLOSE;
       
   173 		__CFLOG_DELETE;
       
   174 #endif
       
   175 		User::Leave(EFail);
       
   176 		}
       
   177 
       
   178 	//-------------- substep 8 --------------------
       
   179 	Log(_L("  08 Check the length of the chains. They should be OFFSET and (LENGTH - OFFSET):"));
       
   180 	TInt temp;
       
   181 	if ( (temp = aChain1.Length()) != aOffset)
       
   182 		{
       
   183 		Log(_L("Error: Chain1 length is %d instead of %d"), temp, aOffset);
       
   184 		aChain1.Free();
       
   185 		aChain2.Free();
       
   186 #ifdef __CFLOG_ACTIVE
       
   187 		__CFLOG_CLOSE;
       
   188 		__CFLOG_DELETE;
       
   189 #endif
       
   190 		User::Leave(EFail);
       
   191 		}
       
   192 
       
   193 	if ( (temp = aChain2.Length()) != aLength - aOffset)
       
   194 		{
       
   195 		Log(_L("Error: Chain2 length is %d instead of %d"), temp, aLength - aOffset);
       
   196 		aChain1.Free();
       
   197 		aChain2.Free();
       
   198 #ifdef __CFLOG_ACTIVE
       
   199 		__CFLOG_CLOSE;
       
   200 		__CFLOG_DELETE;
       
   201 #endif
       
   202 		User::Leave(EFail);
       
   203 		}
       
   204 	
       
   205     if(forceSmallBuf)
       
   206         {
       
   207         if(!aChain2.First() || aChain2.First()->Size() != KSmallBuf ||
       
   208            !aChain2.First()->Next() || aChain2.First()->Next()->Size() != KSmallBuf)
       
   209             {
       
   210             Log(_L("-- split chain should start with two %d buf"), KSmallBuf);
       
   211             User::Leave(EFail);
       
   212             }
       
   213         }
       
   214 
       
   215 	//-------------- substep 9 --------------------
       
   216 	Log(_L("  09 Copy out Chain1 into Des2:"));
       
   217 	aChain1.CopyOut(*aDes2);
       
   218 
       
   219 	//-------------- substep 10 --------------------
       
   220 	Log(_L("  10 Check the length of Des2. It should be OFFSET "));
       
   221 	if ( (temp = aDes2->Length()) != aOffset)
       
   222 		{
       
   223 		Log(_L("Error: Des2 length is %d instead of %d"), temp, aOffset);
       
   224 		aChain1.Free();
       
   225 		aChain2.Free();
       
   226 #ifdef __CFLOG_ACTIVE
       
   227 		__CFLOG_CLOSE;
       
   228 		__CFLOG_DELETE;
       
   229 #endif
       
   230 		User::Leave(EFail);
       
   231 		}
       
   232 
       
   233 	//-------------- substep 11 --------------------
       
   234 	Log(_L("  11 Set the length of Des2 to LENGTH value"));
       
   235 	aDes2->SetLength(aLength);
       
   236 
       
   237 	//-------------- substep 12 --------------------
       
   238 	Log(_L("  12 Copy out the whole Chain2 into Des2 at offset = OFFSET"));
       
   239 	TPtr8 dest((TUint8*)aDes2->Ptr() + aOffset, aLength-aOffset, aLength - aOffset);
       
   240 	aChain2.CopyOut(dest);
       
   241 
       
   242 	//-------------- substep 13 --------------------
       
   243 	Log(_L("  13 Compare the content of Des1 & Des2:"));
       
   244 	if(aDes1->Compare(*aDes2))
       
   245 		{
       
   246 		aChain1.Free();
       
   247 		aChain2.Free();
       
   248 		Log(_L("Error: The content is not the same"));
       
   249 #ifdef __CFLOG_ACTIVE
       
   250 		__CFLOG_CLOSE;
       
   251 		__CFLOG_DELETE;
       
   252 #endif
       
   253 		User::Leave(EFail);
       
   254 		}
       
   255 
       
   256 	//-------------- substep 14 --------------------
       
   257 	Log(_L("  14 Free the chains. Clean up stack:"));
       
   258 	aChain1.Free();
       
   259 	aChain2.Free();
       
   260     CleanupStack::PopAndDestroy(aDes2);
       
   261     CleanupStack::PopAndDestroy(aDes1);
       
   262     CleanupStack::PopAndDestroy(); // iBufPond
       
   263 	CActiveScheduler::Install(NULL);
       
   264 	CleanupStack::PopAndDestroy(iActSch);
       
   265 
       
   266 #ifdef __CFLOG_ACTIVE
       
   267 	__CFLOG_CLOSE;
       
   268 	__CFLOG_DELETE;
       
   269 #endif
       
   270 	__UHEAP_MARKEND;
       
   271 	return EPass;
       
   272 	}