commsfwutils/commsbufs/version1/mbufmgr/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 #include <networking/log.h>
       
    23 #include <networking/teststep.h>
       
    24 #include "TestStepCTMbufmgr.h"
       
    25 #include "TestSuiteCTMbufmgr.h"
       
    26 
       
    27 #include "Test07TrimStart.h"
       
    28 
       
    29 // constructor
       
    30 CTest07TrimStart::CTest07TrimStart()
       
    31 	{
       
    32 	iTestStepName = _L("MBufMgrTest07");// Store the name of this test case
       
    33 	}
       
    34 
       
    35 // destructor
       
    36 CTest07TrimStart::~CTest07TrimStart()
       
    37 	{
       
    38 	}
       
    39 
       
    40 //
       
    41 enum TVerdict CTest07TrimStart::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("MBufMgrTest07"), _L("Length"), aLength);
       
    50 	if (!bRet)
       
    51 		{
       
    52 		return EFail;
       
    53 		}
       
    54 	bRet = GetIntFromConfig(_L("MBufMgrTest07"), _L("Offset"), aOffset);
       
    55 	if (!bRet)
       
    56 		{
       
    57 		return EFail;
       
    58 		}
       
    59    	Log(_L("     ------- Chain LENGTH              = %d --"), aLength);
       
    60  	Log(_L("     ------- OFFSET where to TrimStart = %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 Allocate two desc. of Length:LENGTH(Des1) & (LENGTH-OFFSET)(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-aOffset);
       
    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(*aDes2, 0, aLength-aOffset, 0, 0);
       
    94 
       
    95 	//-------------- substep 5 --------------------
       
    96 	Log(_L("  05 Allocate Chain:"));
       
    97 	RMBufChain aChain;
       
    98 	TRAPD(ret,aChain.AllocL(aLength));
       
    99 	if (ret != KErrNone)
       
   100 		{
       
   101 		Log(_L("Error: Couldn't allocate RMBuf:"));
       
   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 	aChain.CopyIn(*aDes1);
       
   112 
       
   113 	//-------------- substep 7 --------------------
       
   114 	Log(_L("  07 TrimStart Chain1 at OFFSET position (actually, remove the 1st OFFSET bytes:"));
       
   115 	aChain.TrimStart(aOffset);
       
   116 
       
   117 	//-------------- substep 8 --------------------
       
   118 	Log(_L("  08 Check the length of the chain. It should be (LENGTH - OFFSET):"));
       
   119 	TInt temp;
       
   120 	if ( (temp = aChain.Length()) != aLength-aOffset)
       
   121 		{
       
   122 		Log(_L("Error: Chain length is %d instead of %d"), temp, aLength-aOffset);
       
   123 		aChain.Free();
       
   124 #ifdef __CFLOG_ACTIVE
       
   125 		__CFLOG_CLOSE;
       
   126 		__CFLOG_DELETE;
       
   127 #endif
       
   128 		User::Leave(EFail);
       
   129 		}
       
   130 
       
   131 	//-------------- substep 09 --------------------
       
   132 	Log(_L("  09 Copy the last (LENGTH-OFFSET) bytes of Des1 into the start of Des1:"));
       
   133 	(void)Mem::Copy((TUint8 *)aDes1->Ptr(), (TUint8 *)aDes1->Ptr()+aOffset, aLength-aOffset);
       
   134 
       
   135 	//-------------- substep 10 --------------------
       
   136 	Log(_L("  10 Set the length of Des1 to value LENGTH-OFFSET"));
       
   137 	aDes1->SetLength(aLength-aOffset);
       
   138 
       
   139 	//-------------- substep 11 --------------------
       
   140 	Log(_L("  11 Copy out Chain into Des2:"));
       
   141 	aChain.CopyOut(*aDes2);
       
   142 
       
   143 	//-------------- substep 12 --------------------
       
   144 	Log(_L("  12 Compare the content of Des1 & Des2:"));
       
   145 	if(aDes1->Compare(*aDes2))
       
   146 		{
       
   147 		aChain.Free();
       
   148 		Log(_L("Error: The content is not the same"));
       
   149 #ifdef __CFLOG_ACTIVE
       
   150 		__CFLOG_CLOSE;
       
   151 		__CFLOG_DELETE;
       
   152 #endif
       
   153 		User::Leave(EFail);
       
   154 		}
       
   155 
       
   156 	//-------------- substep 13 --------------------
       
   157 	Log(_L("  13 Free the chains. Clean up stack:"));
       
   158 	aChain.Free();
       
   159     CleanupStack::PopAndDestroy(aDes2);
       
   160     CleanupStack::PopAndDestroy(aDes1);
       
   161     CleanupStack::PopAndDestroy(iMBMngr);
       
   162 	CActiveScheduler::Install(NULL);
       
   163 	CleanupStack::PopAndDestroy(iActSch);
       
   164 
       
   165 #ifdef __CFLOG_ACTIVE
       
   166 	__CFLOG_CLOSE;
       
   167 	__CFLOG_DELETE;
       
   168 #endif
       
   169  	__UHEAP_MARKEND;
       
   170 	return EPass;
       
   171 	}