commsfwutils/commsbufs/TE_mbufmgr/src/Test23RMBufQ.cpp
changeset 72 ae47d0499bee
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
       
     1 // Copyright (c) 2008-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 // Test23RMBufQ.cpp
       
    15 // Contains MBufMgr Test Step 22 for Append() methods
       
    16 //
       
    17 //
       
    18 
       
    19 // EPOC includes
       
    20 #include <e32base.h>
       
    21 
       
    22 // Test system includes
       
    23 //#ifdef SYMBIAN_OLD_EXPORT_LOCATION
       
    24 //#include "networking/log.h"
       
    25 //#include "networking/teststep.h"
       
    26 //#else
       
    27 //#include <networking/log.h>
       
    28 //#include <networking/teststep.h>
       
    29 //#endif
       
    30 
       
    31 #include "TestStepCTMbufmgr.h"
       
    32 
       
    33 #include "Test23RMBufQ.h"
       
    34 
       
    35 // constructor
       
    36 CTest23RMBufQ::CTest23RMBufQ()
       
    37 	{
       
    38 	SetTestStepName(_L("MBufMgrTest23"));// Store the name of this test case
       
    39 	}
       
    40 
       
    41 // destructor
       
    42 CTest23RMBufQ::~CTest23RMBufQ()
       
    43 	{
       
    44 	}
       
    45 
       
    46 //
       
    47 enum TVerdict CTest23RMBufQ::doTestStepL(void)
       
    48 	{
       
    49 	SetTestStepResult(EFail);
       
    50 
       
    51 	//-------------- substep 1 --------------------
       
    52 	INFO_PRINTF1(_L("  01 Create CMBufManager and install active scheduler:"));
       
    53     CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
       
    54 	CActiveScheduler::Install(iActSch);
       
    55 
       
    56 	RArray<TCommsBufPoolCreateInfo> poolInfoArray;
       
    57 	TCommsBufPoolCreateInfo createInfo;
       
    58 	createInfo.iBufSize = 128;
       
    59 	createInfo.iInitialBufs = 128;
       
    60 	createInfo.iGrowByBufs = 64;
       
    61 	createInfo.iMinFreeBufs = 40;
       
    62 	createInfo.iCeiling = (KMBufDefaultHeapSize / 2)/createInfo.iBufSize;
       
    63 	poolInfoArray.AppendL(createInfo);
       
    64 	CreateInstanceMBufMgrL(poolInfoArray);
       
    65 	CleanupClosePushL(iBufPond);
       
    66 	poolInfoArray.Close ();
       
    67 
       
    68 	TBool firstFail = EFalse;
       
    69 	TBool secondFail = EFalse;
       
    70 	TInt ret;
       
    71 	RMBufChain chain,chain2;
       
    72 
       
    73 	//-------------- substep 2 --------------------
       
    74 	INFO_PRINTF1(_L("  2 Append a chain onto an RMBuqQ"));
       
    75 	ret = chain.Alloc(20);
       
    76 	if (ret != KErrNone)
       
    77 	    {
       
    78         INFO_PRINTF1(_L("Error: Couldn't allocate initial chain:"));
       
    79         firstFail = ETrue;
       
    80 	    }
       
    81     else
       
    82         {
       
    83 		ret = chain2.Alloc(20);
       
    84 		if (ret != KErrNone)
       
    85 			{
       
    86 			INFO_PRINTF1(_L("Error: Couldn't allocate second chain:"));
       
    87 			firstFail = ETrue;
       
    88 			}
       
    89 		else
       
    90 			{
       
    91 			RMBuf* first2 = chain2.First();
       
    92 			RMBuf* first = chain.First();
       
    93 
       
    94 			RMBufQ aBufList;
       
    95 			aBufList.Assign(chain);
       
    96 
       
    97 			aBufList.Append(chain2);
       
    98 
       
    99 			// Check that the buffers come back out of the queue in the right order
       
   100 			if(aBufList.Remove() != first)
       
   101 				{
       
   102 				INFO_PRINTF1(_L("Error: chain not appended to RMBufQ correctly:"));
       
   103 				secondFail = ETrue;
       
   104 				}
       
   105 			if(aBufList.Remove() != first2)
       
   106 				{
       
   107 				INFO_PRINTF1(_L("Error: chain not appended to RMBufQ correctly:"));
       
   108 				secondFail = ETrue;
       
   109 				}
       
   110 			//-------------- substep 3 --------------------
       
   111 			INFO_PRINTF1(_L("  3 Deallocating RMBufChains"));
       
   112 			chain2.Free();
       
   113 		    }
       
   114 		chain.Free();
       
   115 		}
       
   116 	//-------------- substep 4 --------------------
       
   117 	INFO_PRINTF1(_L("  4 Prepend a chain onto an RMBuqQ"));
       
   118 	ret = chain.Alloc(20);
       
   119 	if (ret != KErrNone)
       
   120 	    {
       
   121         INFO_PRINTF1(_L("Error: Couldn't allocate initial chain:"));
       
   122         firstFail = ETrue;
       
   123 	    }
       
   124     else
       
   125         {
       
   126 		ret = chain2.Alloc(20);
       
   127 		if (ret != KErrNone)
       
   128 			{
       
   129 			INFO_PRINTF1(_L("Error: Couldn't allocate second chain:"));
       
   130 			firstFail = ETrue;
       
   131 			}
       
   132 		else
       
   133 			{
       
   134 			RMBuf* first2 = chain2.First();
       
   135 			RMBuf* first = chain.First();
       
   136 
       
   137 			RMBufQ aBufList;
       
   138 			aBufList.Assign(chain);
       
   139 
       
   140 			aBufList.Prepend(chain2);
       
   141 
       
   142 			// Check that the buffers come back out of the queue in the right order
       
   143 			if(aBufList.Remove() != first2)
       
   144 				{
       
   145 				INFO_PRINTF1(_L("Error: chain not prepended to RMBufQ correctly:"));
       
   146 				secondFail = ETrue;
       
   147 				}
       
   148 			if(aBufList.Remove() != first)
       
   149 				{
       
   150 				INFO_PRINTF1(_L("Error: chain not prepended to RMBufQ correctly:"));
       
   151 				secondFail = ETrue;
       
   152 				}
       
   153 			//-------------- substep 5 --------------------
       
   154 			INFO_PRINTF1(_L("  5 Deallocating RMBufChains"));
       
   155 			chain2.Free();
       
   156 		    }
       
   157 		chain.Free();
       
   158 		}
       
   159 	//-------------- substep 6 ---------------------
       
   160 	INFO_PRINTF1(_L("  6 Clean up stack:"));
       
   161     CleanupStack::PopAndDestroy(); // pond
       
   162 	CActiveScheduler::Install(NULL);
       
   163 	CleanupStack::PopAndDestroy(iActSch);
       
   164 	
       
   165 	if (firstFail || secondFail)
       
   166     	{
       
   167 		SetTestStepResult(EFail);
       
   168     	}
       
   169 	else
       
   170 		{
       
   171 		SetTestStepResult(EPass);
       
   172 		}
       
   173 	return TestStepResult();
       
   174 	}