commsfwutils/commsbufs/version1/mbufmgr/TS_mbufmgr/Test06SplitL.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 06 for SplitL method
       
    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 "Test06SplitL.h"
       
    28 
       
    29 // constructor
       
    30 CTest06Split::CTest06Split()
       
    31 	{
       
    32 	iTestStepName = _L("MBufMgrTest06");// Store the name of this test case
       
    33 	}
       
    34 
       
    35 // destructor
       
    36 CTest06Split::~CTest06Split()
       
    37 	{
       
    38 	}
       
    39 
       
    40 //
       
    41 enum TVerdict CTest06Split::doTestStepL(void)
       
    42 	{
       
    43 	__UHEAP_MARK;
       
    44 		
       
    45 	//-------------- substep 0 --------------------
       
    46 	Log(_L("  00 Read parameters from the script:"));
       
    47 	TInt aOffset;// Will contain the position in chain where split action will be done
       
    48 	TInt aLength;// Will contain the length of desc & chains in the test
       
    49 	TInt bRet = GetIntFromConfig(_L("MBufMgrTest06"), _L("Length"), aLength);
       
    50 	if (!bRet)
       
    51 		{
       
    52 		return EFail;
       
    53 		}
       
    54 	bRet = GetIntFromConfig(_L("MBufMgrTest06"), _L("Offset"), aOffset);
       
    55 	if (!bRet)
       
    56 		{
       
    57 		return EFail;
       
    58 		}
       
    59  	Log(_L("     ------- Chain & Desc LENGTH   = %d --"), aLength);
       
    60  	Log(_L("     ------- OFFSET where to Split = %d --"), aOffset);
       
    61 	if ( (aLength > 1000)    ||(aLength <0) ||
       
    62 		 (aOffset > aLength) || (aOffset <0)  )
       
    63 		{
       
    64 		Log(_L("ERROR: Wrong input parameter(s)"));
       
    65 		return EFail;
       
    66 		}
       
    67 
       
    68 #ifdef __CFLOG_ACTIVE
       
    69 	__CFLOG_CREATEL;
       
    70 	__CFLOG_OPEN;
       
    71 #endif
       
    72 
       
    73 	//-------------- substep 1 --------------------
       
    74 	Log(_L("  01 Creating CMBufManager and installing active scheduler:"));
       
    75     CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
       
    76 	CActiveScheduler::Install(iActSch);
       
    77 	CleanupStack::PushL(CreateInstanceMBufMgrL(KMBufDefaultHeapSize));
       
    78 
       
    79 	//-------------- substep 2 --------------------
       
    80 	Log(_L("  02 Allocating two descriptors (Des1 & Des2):"));
       
    81 	TBuf8<1000> *aDes1, *aDes2;
       
    82     CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<1000> );
       
    83     CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<1000> );
       
    84 	aDes1->SetLength(aLength);
       
    85 	aDes2->SetLength(aLength);
       
    86 
       
    87 	//-------------- substep 3 --------------------
       
    88 	Log(_L("  03 Fill in Des1 with a pattern:"));
       
    89 	StripeDes(*aDes1, 0, aLength, '@', 'Z');
       
    90 
       
    91 	//-------------- substep 4 --------------------
       
    92 	Log(_L("  04 Fill in Des2 with zeros:"));
       
    93 	StripeDes(*aDes1, 0, aLength, 0, 0);
       
    94 
       
    95 	//-------------- substep 5 --------------------
       
    96 	Log(_L("  05 Allocate Chain1:"));
       
    97 	RMBufChain aChain1;
       
    98 	TRAPD(ret,aChain1.AllocL(aLength));
       
    99 	if (ret != KErrNone)
       
   100 		{
       
   101 		Log(_L("Error: Couldn't allocate Chain1:"));
       
   102 #ifdef __CFLOG_ACTIVE
       
   103 		__CFLOG_CLOSE;
       
   104 		__CFLOG_DELETE;
       
   105 #endif
       
   106 		User::Leave(EFail);
       
   107 		}
       
   108 
       
   109 	//-------------- substep 6 --------------------
       
   110 	Log(_L("  06 Copy in Des1 into Chain1:"));
       
   111 	aChain1.CopyIn(*aDes1);
       
   112 
       
   113 	//-------------- substep 7 --------------------
       
   114 	Log(_L("  07 Split Chain1. The 2nd part goes to Chain2:"));
       
   115 	RMBufChain aChain2;
       
   116 	TRAP(ret,aChain1.SplitL(aOffset, aChain2));
       
   117 	if (ret != KErrNone)
       
   118 		{
       
   119 		Log(_L("Error: Couldn't Split"));
       
   120 		aChain1.Free();
       
   121 		aChain2.Free();
       
   122 #ifdef __CFLOG_ACTIVE
       
   123 		__CFLOG_CLOSE;
       
   124 		__CFLOG_DELETE;
       
   125 #endif
       
   126 		User::Leave(EFail);
       
   127 		}
       
   128 
       
   129 	//-------------- substep 8 --------------------
       
   130 	Log(_L("  08 Check the length of the chains. They should be OFFSET and (LENGTH - OFFSET):"));
       
   131 	TInt temp;
       
   132 	if ( (temp = aChain1.Length()) != aOffset)
       
   133 		{
       
   134 		Log(_L("Error: Chain1 length is %d instead of %d"), temp, aOffset);
       
   135 		aChain1.Free();
       
   136 		aChain2.Free();
       
   137 #ifdef __CFLOG_ACTIVE
       
   138 		__CFLOG_CLOSE;
       
   139 		__CFLOG_DELETE;
       
   140 #endif
       
   141 		User::Leave(EFail);
       
   142 		}
       
   143 
       
   144 	if ( (temp = aChain2.Length()) != aLength - aOffset)
       
   145 		{
       
   146 		Log(_L("Error: Chain2 length is %d instead of %d"), temp, aLength - aOffset);
       
   147 		aChain1.Free();
       
   148 		aChain2.Free();
       
   149 #ifdef __CFLOG_ACTIVE
       
   150 		__CFLOG_CLOSE;
       
   151 		__CFLOG_DELETE;
       
   152 #endif
       
   153 		User::Leave(EFail);
       
   154 		}
       
   155 
       
   156 	//-------------- substep 9 --------------------
       
   157 	Log(_L("  09 Copy out Chain1 into Des2:"));
       
   158 	aChain1.CopyOut(*aDes2);
       
   159 
       
   160 	//-------------- substep 10 --------------------
       
   161 	Log(_L("  10 Check the length of Des2. It should be OFFSET "));
       
   162 	if ( (temp = aDes2->Length()) != aOffset)
       
   163 		{
       
   164 		Log(_L("Error: Des2 length is %d instead of %d"), temp, aOffset);
       
   165 		aChain1.Free();
       
   166 		aChain2.Free();
       
   167 #ifdef __CFLOG_ACTIVE
       
   168 		__CFLOG_CLOSE;
       
   169 		__CFLOG_DELETE;
       
   170 #endif
       
   171 		User::Leave(EFail);
       
   172 		}
       
   173 
       
   174 	//-------------- substep 11 --------------------
       
   175 	Log(_L("  11 Set the length of Des2 to LENGTH value"));
       
   176 	aDes2->SetLength(aLength);
       
   177 
       
   178 	//-------------- substep 12 --------------------
       
   179 	Log(_L("  12 Copy out the whole Chain2 into Des2 at offset = OFFSET"));
       
   180 	TPtr8 dest((TUint8*)aDes2->Ptr() + aOffset, aLength-aOffset, aLength - aOffset);
       
   181 	aChain1.CopyOut(dest);
       
   182 
       
   183 	//-------------- substep 13 --------------------
       
   184 	Log(_L("  13 Compare the content of Des1 & Des2:"));
       
   185 	if(aDes1->Compare(*aDes2))
       
   186 		{
       
   187 		aChain1.Free();
       
   188 		aChain2.Free();
       
   189 		Log(_L("Error: The content is not the same"));
       
   190 #ifdef __CFLOG_ACTIVE
       
   191 		__CFLOG_CLOSE;
       
   192 		__CFLOG_DELETE;
       
   193 #endif
       
   194 		User::Leave(EFail);
       
   195 		}
       
   196 
       
   197 	//-------------- substep 14 --------------------
       
   198 	Log(_L("  14 Free the chains. Clean up stack:"));
       
   199 	aChain1.Free();
       
   200 	aChain2.Free();
       
   201     CleanupStack::PopAndDestroy(aDes2);
       
   202     CleanupStack::PopAndDestroy(aDes1);
       
   203     CleanupStack::PopAndDestroy(iMBMngr);
       
   204 	CActiveScheduler::Install(NULL);
       
   205 	CleanupStack::PopAndDestroy(iActSch);
       
   206 
       
   207 #ifdef __CFLOG_ACTIVE
       
   208 	__CFLOG_CLOSE;
       
   209 	__CFLOG_DELETE;
       
   210 #endif
       
   211 	__UHEAP_MARKEND;
       
   212 	return EPass;
       
   213 	}