commsfwutils/commsbufs/TS_mbufmgr/Test08TrimEnd.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 8 for TrimEnd() 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 "Test08TrimEnd.h"
       
    33 #include <comms-infras/commsbufpond.h>
       
    34 // constructor
       
    35 CTest08TrimEnd::CTest08TrimEnd()
       
    36 	{
       
    37 	iTestStepName = _L("MBufMgrTest08");// Store the name of this test case
       
    38 	}
       
    39 
       
    40 // destructor
       
    41 CTest08TrimEnd::~CTest08TrimEnd()
       
    42 	{
       
    43 	}
       
    44 
       
    45 //
       
    46 enum TVerdict CTest08TrimEnd::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("MBufMgrTest08"), _L("Length"), aLength);
       
    55 	if (!bRet)
       
    56 		{
       
    57 		return EFail;
       
    58 		}
       
    59 	bRet = GetIntFromConfig(_L("MBufMgrTest08"), _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) & 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(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, 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 TrimEnd Chain1 at OFFSET position (i.e. remove the bytes after OFFSET position:"));
       
   121 	aChain.TrimEnd(aOffset);
       
   122 
       
   123 	//-------------- substep 8 --------------------
       
   124 	Log(_L("  08 Check the length of the chain. It should be OFFSET:"));
       
   125 	TInt temp;
       
   126 	if ( (temp = aChain.Length()) != aOffset)
       
   127 		{
       
   128 		Log(_L("Error: Chain length is %d instead of %d"), temp, aOffset);
       
   129 		aChain.Free();
       
   130 #ifdef __CFLOG_ACTIVE
       
   131 		__CFLOG_CLOSE;
       
   132 		__CFLOG_DELETE;
       
   133 #endif
       
   134 		User::Leave(EFail);
       
   135 		}
       
   136 
       
   137 	//-------------- substep 9 --------------------
       
   138 	Log(_L("  09 Set the length of Des1 to value OFFSET"));
       
   139 	aDes1->SetLength(aOffset);
       
   140 
       
   141 	//-------------- substep 10 --------------------
       
   142 	Log(_L("  10 Copy out Chain into Des2:"));
       
   143 	aChain.CopyOut(*aDes2);
       
   144 
       
   145 	//-------------- substep 11 --------------------
       
   146 	Log(_L("  11 Compare the content of Des1 & Des2:"));
       
   147 	if(aDes1->Compare(*aDes2))
       
   148 		{
       
   149 		aChain.Free();
       
   150 		Log(_L("Error: The content is not the same"));
       
   151 #ifdef __CFLOG_ACTIVE
       
   152 		__CFLOG_CLOSE;
       
   153 		__CFLOG_DELETE;
       
   154 #endif
       
   155 		User::Leave(EFail);
       
   156 		}
       
   157 
       
   158 	//-------------- substep 12 --------------------
       
   159 	Log(_L("  12 Free the chains. Clean up stack:"));
       
   160 	aChain.Free();
       
   161     CleanupStack::PopAndDestroy(aDes2);
       
   162     CleanupStack::PopAndDestroy(aDes1);
       
   163     CleanupStack::PopAndDestroy();
       
   164 	CActiveScheduler::Install(NULL);
       
   165 	CleanupStack::PopAndDestroy(iActSch);
       
   166 
       
   167 #ifdef __CFLOG_ACTIVE
       
   168 	__CFLOG_CLOSE;
       
   169 	__CFLOG_DELETE;
       
   170 #endif
       
   171  	__UHEAP_MARKEND;
       
   172 	return EPass;
       
   173 	}