commsfwutils/commsbufs/version1/mbufmgr/TS_mbufmgr/Test05CopyInOutOffset.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 05 for CopyIn() & CopyOut() methods with offset
       
    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 "Test05CopyInOutOffset.h"
       
    28 
       
    29 // constructor
       
    30 CTest05CopyInOutOffset::CTest05CopyInOutOffset()
       
    31 	{
       
    32 	iTestStepName = _L("MBufMgrTest05");// Store the name of this test case
       
    33 	}
       
    34 
       
    35 // destructor
       
    36 CTest05CopyInOutOffset::~CTest05CopyInOutOffset()
       
    37 	{
       
    38 	}
       
    39 
       
    40 //
       
    41 enum TVerdict CTest05CopyInOutOffset::doTestStepL(void)
       
    42 	{
       
    43 	__UHEAP_MARK;
       
    44 		
       
    45 	//-------------- substep 0 --------------------
       
    46 	bool aTest;
       
    47 	Log(_L("  00 Read from script which test to run:"));
       
    48 	TPtrC aPtrResult;
       
    49 	TInt bRet = GetStringFromConfig(_L("MBufMgrTest05"), _L("test"), aPtrResult);
       
    50 	if (!bRet)
       
    51 		{
       
    52 		return EFail;
       
    53 		}
       
    54 
       
    55 	if (aPtrResult==_L("CopyIn" ))
       
    56 		{
       
    57 		aTest = true;
       
    58 	 	Log(_L("     ------------ Copy In Test starts ---------------:"));
       
    59 		}
       
    60 	else if (aPtrResult==_L("CopyOut"))
       
    61 		{
       
    62 		aTest = false;
       
    63 	 	Log(_L("     ------------ Copy Out Test starts --------------:"));
       
    64 		}
       
    65 	else
       
    66 		{
       
    67 		Log(_L("Failed to read test case - there should be either CopyIn or CopyOut - case sensitive"));
       
    68 		return EFail;
       
    69 		}
       
    70 
       
    71 #ifdef __CFLOG_ACTIVE
       
    72 	__CFLOG_CREATEL;
       
    73 	__CFLOG_OPEN;
       
    74 #endif
       
    75 
       
    76 	//-------------- substep 1 --------------------
       
    77 	Log(_L("  01 Create CMBufManager and install active scheduler:"));
       
    78     CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
       
    79 	CActiveScheduler::Install(iActSch);
       
    80 	CleanupStack::PushL(CreateInstanceMBufMgrL(KMBufDefaultHeapSize));
       
    81 
       
    82 	//-------------- substep 2 --------------------
       
    83 	Log(_L("  02 Allocate two 5000-bytes long descriptors (Des1 & Des2):"));
       
    84 	TBuf8<5000> *aDes1, *aDes2;
       
    85     CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<5000> );
       
    86     CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<5000> );
       
    87 	aDes1->SetLength(5000);
       
    88 	aDes2->SetLength(5000);
       
    89 
       
    90 	//-------------- substep 3 --------------------
       
    91 	Log(_L("  03 Allocate 5000-bytes long RMBufChain:"));
       
    92 	RMBufChain aChain;
       
    93 	TRAPD(ret,aChain.AllocL(5000));
       
    94 	if (ret != KErrNone)
       
    95 		{
       
    96 		Log(_L("Error: Couldn't allocate RMBuf:"));
       
    97 #ifdef __CFLOG_ACTIVE
       
    98 		__CFLOG_CLOSE;
       
    99 		__CFLOG_DELETE;
       
   100 #endif
       
   101 		User::Leave(EFail);
       
   102 		}
       
   103 
       
   104 	//-------------- substep 4 --------------------
       
   105 	Log(_L("  04 Fill in Des1 with a pattern:"));
       
   106 	StripeDes(*aDes1, 0, 5000, '@', 'Z');
       
   107 
       
   108 	//-------------- substep 5 --------------------
       
   109 	Log(_L("  05 Fill in Des2 with a patter different then that in Des1:"));
       
   110 	StripeDes(*aDes2, 0, 5000, 'a', 'z');
       
   111 
       
   112 	//-------------- substep 6 --------------------
       
   113 	Log(_L("  06 Fill in Chain with zeros:"));
       
   114     aChain.FillZ();
       
   115 
       
   116 	if (aTest)
       
   117 		{
       
   118 	//----------- CopyIn() method check only-----------
       
   119 		//-------------- substep 7 --------------------
       
   120 		Log(_L("  07 Copy in the last 4000 bytes of Des1 into the last 4000 of Chain:"));
       
   121 		aChain.CopyIn(aDes1->Mid(1000),1000);
       
   122 
       
   123 		//-------------- substep 8 --------------------
       
   124 		Log(_L("  08 Copy out Chain into Des2:"));
       
   125 		aChain.CopyOut(*aDes2);
       
   126 
       
   127 		//-------------- substep 9 --------------------
       
   128 		Log(_L("  09 Fill in the 1st 1000 bytes of Des1 with zeros:"));
       
   129 		StripeDes(*aDes1, 0, 1000, '\0', '\0');
       
   130 		}
       
   131 	else
       
   132 		{
       
   133 	//----------- CopyOut() method check unly-----------
       
   134 		//-------------- substep 7 --------------------
       
   135 		Log(_L("  07 Copy in Des1 into Chain:"));
       
   136 		aChain.CopyIn(*aDes1);
       
   137 
       
   138 		//-------------- substep 8 --------------------
       
   139 		Log(_L("  08 Fill in the 1st 1000 bytes of Des1 & Des2 with zeros:"));
       
   140 		StripeDes(*aDes1, 0, 1000, '\0', '\0');
       
   141 		StripeDes(*aDes2, 0, 1000, '\0', '\0');
       
   142 
       
   143 		//-------------- substep 9 --------------------
       
   144 		Log(_L("  09 Copy out the last 4000 bytes of Chain into last 4000 of Des2:"));
       
   145 		TPtr8 dest((TUint8*)aDes2->Ptr()+1000,4000,4000);
       
   146 		aChain.CopyOut(dest, 1000);
       
   147 		}
       
   148 
       
   149 	//-------------- substep 10 --------------------
       
   150 	Log(_L("  10 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 11 --------------------
       
   163 	Log(_L("  11 Free the chain. Clean up stack:"));
       
   164 	aChain.Free();
       
   165     CleanupStack::PopAndDestroy(aDes2);
       
   166     CleanupStack::PopAndDestroy(aDes1);
       
   167     CleanupStack::PopAndDestroy(iMBMngr);
       
   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 	}