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