commsfwutils/commsbufs/version1/mbufmgr/TS_mbufmgr/Test11AsyncAlloc.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 11 Async. Allocate
       
    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 #include "Test11AsyncAlloc.h"
       
    27 
       
    28 
       
    29 // constructor
       
    30 CTest11AsyncAlloc::CTest11AsyncAlloc()
       
    31 	{
       
    32 	iTestStepName = _L("MBufMgrTest11");// Store the name of this test case
       
    33 	}
       
    34 
       
    35 // destructor
       
    36 CTest11AsyncAlloc::~CTest11AsyncAlloc()
       
    37 	{
       
    38 	}
       
    39 
       
    40 class CMBufAsyncReq : public CActive
       
    41 {
       
    42 public:
       
    43 	CMBufAsyncReq(RMBufAsyncRequest &aMBufAsyncReq)
       
    44 		:CActive(EPriorityStandard)
       
    45 		,iMBufAsyncReq(aMBufAsyncReq) 	{ }
       
    46 
       
    47 	~CMBufAsyncReq() { Cancel(); }
       
    48 
       
    49 	void RunL()      { CActiveScheduler::Stop(); }
       
    50 
       
    51 	void DoCancel()  { iMBufAsyncReq.Cancel(); }
       
    52 
       
    53 	TInt DoAsyncRequest(RMBufChain& aChain, TInt aSize)
       
    54 		{
       
    55 		iMBufAsyncReq.Alloc(aChain, aSize, iStatus);
       
    56 		SetActive();
       
    57 		CActiveScheduler::Start();
       
    58 		return iStatus.Int();
       
    59 		}
       
    60 private:
       
    61 	RMBufAsyncRequest& iMBufAsyncReq;
       
    62 };
       
    63 
       
    64 enum TVerdict CTest11AsyncAlloc::doTestStepL(void)
       
    65 	{
       
    66 	__UHEAP_MARK;
       
    67 	
       
    68 #ifdef __CFLOG_ACTIVE
       
    69 	__CFLOG_CREATEL;
       
    70 	__CFLOG_OPEN;
       
    71 #endif
       
    72 	
       
    73 	//-------------- substep 1 --------------------
       
    74 	Log(_L("  01 Create CMBufManager and install 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 Create and install active object that will do async. alloc on request:"));
       
    81 	RMBufAsyncRequest async;
       
    82 	CMBufAsyncReq* testAsync;
       
    83 	CleanupStack::PushL(testAsync = new(ELeave) CMBufAsyncReq(async));
       
    84 	CActiveScheduler::Add(testAsync);
       
    85 
       
    86 	//-------------- substep 3 --------------------
       
    87 	Log(_L("  03 Async. alloce 5000-bytes long RMBuf:"));
       
    88 	RMBufChain aChain;
       
    89 	TInt ret = testAsync->DoAsyncRequest(aChain, 5000);
       
    90 	if (ret != KErrNone)
       
    91 		{
       
    92 		Log(_L("Error: Couldn't allocate Chain:"));
       
    93 
       
    94 #ifdef __CFLOG_ACTIVE
       
    95 		__CFLOG_CLOSE;
       
    96 		__CFLOG_DELETE;
       
    97 #endif
       
    98 		User::Leave(EFail);
       
    99 		}
       
   100 
       
   101 	//-------------- substep 4 --------------------
       
   102 	Log(_L("  04 Free the chain. Clean up stack:"));
       
   103 	aChain.Free();
       
   104     CleanupStack::PopAndDestroy(testAsync);
       
   105     CleanupStack::PopAndDestroy(iMBMngr);
       
   106 	CActiveScheduler::Install(NULL);
       
   107 	CleanupStack::PopAndDestroy(iActSch);
       
   108 
       
   109 #ifdef __CFLOG_ACTIVE
       
   110 	__CFLOG_CLOSE;
       
   111 	__CFLOG_DELETE;
       
   112 #endif
       
   113    	__UHEAP_MARKEND;
       
   114 	return EPass;
       
   115 	}