commsfwutils/commsbufs/version1/mbufmgr/TS_mbufmgr/Test04CopyInOut.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 04 for CopyIn() & CopyOut() methods
       
    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 "Test04CopyInOut.h"
       
    28 
       
    29 // constructor
       
    30 CTest04CopyInOut::CTest04CopyInOut()
       
    31 	{
       
    32 	iTestStepName = _L("MBufMgrTest04");// Store the name of this test case
       
    33 	}
       
    34 
       
    35 // destructor
       
    36 CTest04CopyInOut::~CTest04CopyInOut()
       
    37 	{
       
    38 	}
       
    39 
       
    40 //
       
    41 enum TVerdict CTest04CopyInOut::doTestStepL(void)
       
    42 	{
       
    43 	__UHEAP_MARK;
       
    44 	
       
    45 #ifdef __CFLOG_ACTIVE
       
    46 	__CFLOG_CREATEL;
       
    47 	__CFLOG_OPEN;
       
    48 #endif
       
    49 	
       
    50 	//-------------- substep 1 --------------------
       
    51 	Log(_L("  01 Create CMBufManager and install active scheduler:"));
       
    52     CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
       
    53 	CActiveScheduler::Install(iActSch);
       
    54 	CleanupStack::PushL(CreateInstanceMBufMgrL(KMBufDefaultHeapSize));
       
    55 
       
    56 	//-------------- substep 2 --------------------
       
    57 	Log(_L("  02 Allocate two 5000-bytes long descriptors (Des1 & Des2):"));
       
    58 	TBuf8<5000> *aDes1, *aDes2;
       
    59     CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<5000> );
       
    60     CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<5000> );
       
    61 	aDes1->SetLength(5000);
       
    62 	aDes2->SetLength(5000);
       
    63 
       
    64 	//-------------- substep 3 --------------------
       
    65 	Log(_L("  03 Fill in the Des1 with a pattern:"));
       
    66 	StripeDes(*aDes1, 0, 5000, '@', 'Z');
       
    67 
       
    68 	//-------------- substep 4 --------------------
       
    69 	Log(_L("  04 Allocate 5000-bytes long RMBufChain:"));
       
    70 	RMBufChain aChain;
       
    71 	TRAPD(ret,aChain.AllocL(5000));
       
    72 	if (ret != KErrNone)
       
    73 		{
       
    74 		Log(_L("Error: Couldn't allocate RMBuf:"));
       
    75 
       
    76 #ifdef __CFLOG_ACTIVE
       
    77 		__CFLOG_CLOSE;
       
    78 		__CFLOG_DELETE;
       
    79 #endif
       
    80 		User::Leave(EFail);
       
    81 		}
       
    82 
       
    83 	//-------------- substep 5 --------------------
       
    84 	Log(_L("  05 Copy in Des1 into Chain:"));
       
    85     aChain.CopyIn(*aDes1);
       
    86 
       
    87 	//-------------- substep 6 --------------------
       
    88 	Log(_L("  06 Fill in Des2 with zeros:"));
       
    89 	StripeDes(*aDes2, 0, 5000, 0, 0);
       
    90 
       
    91 	//-------------- substep 7 --------------------
       
    92 	Log(_L("  07 Copy out Chain into Des2:"));
       
    93     aChain.CopyOut(*aDes2);
       
    94 
       
    95 	//-------------- substep 8 --------------------
       
    96 	Log(_L("  08 Compare the contents of Des1 & Des2:"));
       
    97 	if(aDes1->Compare(*aDes2))
       
    98 		{
       
    99 		Log(_L("Error: The content is not the same"));
       
   100 		aChain.Free();
       
   101 
       
   102 #ifdef __CFLOG_ACTIVE
       
   103 		__CFLOG_CLOSE;
       
   104 		__CFLOG_DELETE;
       
   105 #endif
       
   106 		User::Leave(EFail);
       
   107 		}
       
   108 
       
   109 	//-------------- substep 9 --------------------
       
   110 	Log(_L("  09 Free chain. Clean up stack:"));
       
   111 	aChain.Free();
       
   112     CleanupStack::PopAndDestroy(aDes2);
       
   113     CleanupStack::PopAndDestroy(aDes1);
       
   114     CleanupStack::PopAndDestroy(iMBMngr);
       
   115 	CActiveScheduler::Install(NULL);
       
   116 	CleanupStack::PopAndDestroy(iActSch);
       
   117 
       
   118 #ifdef __CFLOG_ACTIVE
       
   119 	__CFLOG_CLOSE;
       
   120 	__CFLOG_DELETE;
       
   121 #endif
       
   122  	__UHEAP_MARKEND;
       
   123 	return EPass;
       
   124 	}