commsfwutils/commsbufs/TS_mbufmgr/Test07TrimStart.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 07 for TrimStart() 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 "Test07TrimStart.h"
       
    33 #include <comms-infras/commsbufpond.h>
       
    34 // constructor
       
    35 CTest07TrimStart::CTest07TrimStart()
       
    36 	{
       
    37 	iTestStepName = _L("MBufMgrTest07");// Store the name of this test case
       
    38 	}
       
    39 
       
    40 // destructor
       
    41 CTest07TrimStart::~CTest07TrimStart()
       
    42 	{
       
    43 	}
       
    44 
       
    45 //
       
    46 enum TVerdict CTest07TrimStart::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("MBufMgrTest07"), _L("Length"), aLength);
       
    55 	if (!bRet)
       
    56 		{
       
    57 		return EFail;
       
    58 		}
       
    59 	bRet = GetIntFromConfig(_L("MBufMgrTest07"), _L("Offset"), aOffset);
       
    60 	if (!bRet)
       
    61 		{
       
    62 		return EFail;
       
    63 		}
       
    64    	Log(_L("     ------- Chain LENGTH              = %d --"), aLength);
       
    65  	Log(_L("     ------- OFFSET where to TrimStart = %d --"), aOffset);
       
    66 	if ( (aLength > 1000)    ||(aLength <0) ||
       
    67 		 (aOffset > aLength) || (aOffset <0)  )
       
    68 		{
       
    69 		Log(_L("ERROR: Wrong input parameter(s)"));
       
    70 		return EFail;
       
    71 		}
       
    72 
       
    73 #ifdef __CFLOG_ACTIVE
       
    74 	__CFLOG_CREATEL;
       
    75 	__CFLOG_OPEN;
       
    76 #endif
       
    77 	
       
    78 	//-------------- substep 1 --------------------
       
    79 	Log(_L("  01 Creating CMBufManager and installing active scheduler:"));
       
    80     CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
       
    81 	CActiveScheduler::Install(iActSch);
       
    82 	CreateInstanceMBufMgrL(KMBufDefaultHeapSize);
       
    83 	CleanupClosePushL(iBufPond);
       
    84 
       
    85 	//-------------- substep 2 --------------------
       
    86 	Log(_L("  02 Allocate two desc. of Length:LENGTH(Des1) & (LENGTH-OFFSET)(Des2):"));
       
    87 	TBuf8<1000> *aDes1, *aDes2;
       
    88     CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<1000> );
       
    89     CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<1000> );
       
    90 	aDes1->SetLength(aLength);
       
    91 	aDes2->SetLength(aLength-aOffset);
       
    92 
       
    93 	//-------------- substep 3 --------------------
       
    94 	Log(_L("  03 Fill in Des1 with a pattern:"));
       
    95 	StripeDes(*aDes1, 0, aLength, '@', 'Z');
       
    96 
       
    97 	//-------------- substep 4 --------------------
       
    98 	Log(_L("  04 Fill in Des2 with zeros:"));
       
    99 	StripeDes(*aDes2, 0, aLength-aOffset, 0, 0);
       
   100 
       
   101 	//-------------- substep 5 --------------------
       
   102 	Log(_L("  05 Allocate Chain:"));
       
   103 	RMBufChain aChain;
       
   104 	TRAPD(ret,aChain.AllocL(aLength));
       
   105 	if (ret != KErrNone)
       
   106 		{
       
   107 		Log(_L("Error: Couldn't allocate RMBuf:"));
       
   108 #ifdef __CFLOG_ACTIVE
       
   109 		__CFLOG_CLOSE;
       
   110 		__CFLOG_DELETE;
       
   111 #endif
       
   112 		User::Leave(EFail);
       
   113 		}
       
   114 
       
   115 	//-------------- substep 6 --------------------
       
   116 	Log(_L("  06 Copy in Des1 into Chain1:"));
       
   117 	aChain.CopyIn(*aDes1);
       
   118 
       
   119 	//-------------- substep 7 --------------------
       
   120 	Log(_L("  07 TrimStart Chain1 at OFFSET position (actually, remove the 1st OFFSET bytes:"));
       
   121 	aChain.TrimStart(aOffset);
       
   122 
       
   123 	//-------------- substep 8 --------------------
       
   124 	Log(_L("  08 Check the length of the chain. It should be (LENGTH - OFFSET):"));
       
   125 	TInt temp;
       
   126 	if ( (temp = aChain.Length()) != aLength-aOffset)
       
   127 		{
       
   128 		Log(_L("Error: Chain length is %d instead of %d"), temp, aLength-aOffset);
       
   129 		aChain.Free();
       
   130 #ifdef __CFLOG_ACTIVE
       
   131 		__CFLOG_CLOSE;
       
   132 		__CFLOG_DELETE;
       
   133 #endif
       
   134 		User::Leave(EFail);
       
   135 		}
       
   136 
       
   137 	//-------------- substep 09 --------------------
       
   138 	Log(_L("  09 Copy the last (LENGTH-OFFSET) bytes of Des1 into the start of Des1:"));
       
   139 	(void)Mem::Copy((TUint8 *)aDes1->Ptr(), (TUint8 *)aDes1->Ptr()+aOffset, aLength-aOffset);
       
   140 
       
   141 	//-------------- substep 10 --------------------
       
   142 	Log(_L("  10 Set the length of Des1 to value LENGTH-OFFSET"));
       
   143 	aDes1->SetLength(aLength-aOffset);
       
   144 
       
   145 	//-------------- substep 11 --------------------
       
   146 	Log(_L("  11 Copy out Chain into Des2:"));
       
   147 	aChain.CopyOut(*aDes2);
       
   148 
       
   149 	//-------------- substep 12 --------------------
       
   150 	Log(_L("  12 Compare the content of Des1 & Des2:"));
       
   151 	if(aDes1->Compare(*aDes2))
       
   152 		{
       
   153 		aChain.Free();
       
   154 		Log(_L("Error: The content is not the same"));
       
   155 #ifdef __CFLOG_ACTIVE
       
   156 		__CFLOG_CLOSE;
       
   157 		__CFLOG_DELETE;
       
   158 #endif
       
   159 		User::Leave(EFail);
       
   160 		}
       
   161 
       
   162 	//-------------- substep 13 --------------------
       
   163 	Log(_L("  13 Free the chains. Clean up stack:"));
       
   164 	aChain.Free();
       
   165     CleanupStack::PopAndDestroy(aDes2);
       
   166     CleanupStack::PopAndDestroy(aDes1);
       
   167     CleanupStack::PopAndDestroy();
       
   168 	CActiveScheduler::Install(NULL);
       
   169 	CleanupStack::PopAndDestroy(iActSch);
       
   170 
       
   171 #ifdef __CFLOG_ACTIVE
       
   172 	__CFLOG_CLOSE;
       
   173 	__CFLOG_DELETE;
       
   174 #endif
       
   175  	__UHEAP_MARKEND;
       
   176 	return EPass;
       
   177 	}