servicediscoveryandcontrol/pnp/test/upnp/chunkmgr/ts_chunkmgr/src/test06alloccheckblocksize.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     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 // @file
       
    15 // @internalComponent
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <rmemchunk.h>
       
    22 #include <rmemcell.h>
       
    23 
       
    24 #include "test06alloccheckblocksize.h"
       
    25 
       
    26 
       
    27 TVerdict CTest06AllocCheckBlockSize::doTestStepL ()
       
    28 	{
       
    29 	__UHEAP_MARK;
       
    30 	
       
    31 	CleanupStack::PushL ( CreateChunkMgrL ( KMinHeapSize ) );
       
    32 	RMemoryAllocator allocator ( iChkMgr );
       
    33 	
       
    34 	iChkMgr->AddPoolL ( 2048, 8, 4, 3 );
       
    35 	iChkMgr->AddPoolL ( 1024, 16, 5, 4 );
       
    36 	iChkMgr->AddPoolL ( 512, 32, 6, 5 );
       
    37 	iChkMgr->AddPoolL ( 256, 64, 7, 6 );
       
    38 	iChkMgr->AddPoolL ( 128, 128, 64, 40 );
       
    39 	
       
    40 	TBool firstTestFail = EFalse;
       
    41 	TBool secondTestFail = EFalse;
       
    42 	TBool thirdTestFail = EFalse;
       
    43 	// --------------First Test
       
    44 	RMemChunk chunk;
       
    45 	INFO_PRINTF1 ( _L ( "\nAllocate 5000-bytes long RMemChunk" ) );
       
    46 	TInt ret = chunk.Alloc ( 5000, allocator );
       
    47 	if ( ret != KErrNone )
       
    48 		{
       
    49 		INFO_PRINTF1 ( _L ( "\nError: Couldn't allocate" ) );
       
    50 		User::Leave ( EFail );
       
    51 		}
       
    52 	
       
    53 	//Check Block size is really 512
       
    54 	RMemCell* block = chunk.First ();
       
    55 	if ( block->Size () != 1024 )
       
    56 		{
       
    57 		INFO_PRINTF1 ( _L ( "Error: Block size is not as expected" ) );
       
    58 		firstTestFail = ETrue;
       
    59 		}
       
    60 	
       
    61 	INFO_PRINTF1 ( _L ( "Deallocating RMemChunk" ) );
       
    62 	chunk.Free ();
       
    63 	
       
    64 	// --------------Second Test
       
    65 	INFO_PRINTF1 ( _L ( "Allocate 50-bytes long RMemChunk" ) );	
       
    66 	ret = chunk.Alloc ( 50, allocator );
       
    67 	if ( ret != KErrNone )
       
    68 		{
       
    69 		INFO_PRINTF1 ( _L ( "Error: Couldn't allocate" ) );
       
    70 		User::Leave ( EFail );
       
    71 		}
       
    72 	
       
    73 	//Check Block size is really 128
       
    74 	block = chunk.First ();
       
    75 	if ( block->Size () != 128 )
       
    76 		{
       
    77 		INFO_PRINTF1 ( _L ( "Error: Block size is not as expected" ) );
       
    78 		secondTestFail = ETrue;
       
    79 		}
       
    80 	
       
    81 	INFO_PRINTF1 ( _L ( "Deallocating RMemChunk" ) );
       
    82 	chunk.Free ();
       
    83 	
       
    84 	// --------------Third Test
       
    85 	INFO_PRINTF1 ( _L ( "Allocate 1024-bytes long RMemChunk" ) );
       
    86 	ret = chunk.Alloc ( 1024, allocator );
       
    87 	if ( ret != KErrNone )
       
    88 		{
       
    89 		INFO_PRINTF1 ( _L ( "Error: Couldn't allocate" ) );
       
    90 		User::Leave ( EFail );
       
    91 		}
       
    92 	
       
    93 	// Check Block size is really 1024
       
    94 	block = chunk.First ();
       
    95 	if ( block->Size () != 1024 )
       
    96 		{
       
    97 		INFO_PRINTF1 ( _L ( "Error: Block size is not as expected" ) );
       
    98 		thirdTestFail = ETrue;
       
    99 		}
       
   100 	
       
   101 	INFO_PRINTF1 ( _L ( "Deallocating RMemChunk" ) );
       
   102 	chunk.Free ();
       
   103 	
       
   104 	CleanupStack::PopAndDestroy ( iChkMgr );
       
   105 	
       
   106 	__UHEAP_MARKEND;
       
   107 	
       
   108 	if ( firstTestFail || secondTestFail || thirdTestFail )
       
   109 		return EFail;
       
   110 			
       
   111 	return EPass;
       
   112 	}