os/kernelhwsrv/kerneltest/e32test/buffer/t_readar.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/buffer/t_readar.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,181 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\buffer\t_readar.cpp
    1.18 +// Overview:
    1.19 +// Test the CArrayFixFlat, CArrayPakFlat, CArrayVarFlat classes.
    1.20 +// API Information:
    1.21 +// CArrayFixFlat, CArrayPakFlat, CArrayVarFlat.
    1.22 +// Details:
    1.23 +// - Create an array of fixed length objects contained within a flat 
    1.24 +// dynamic buffer, append some elements onto the end of the array, 
    1.25 +// sort the array into key sequence, check the number of elements 
    1.26 +// in the array is as expected and read all of elements. Check 
    1.27 +// whether the heap has been corrupted.
    1.28 +// - Create an array of variable length objects implemented using a 
    1.29 +// flat dynamic buffer, append some elements onto the end of the 
    1.30 +// array, sort the array into key sequence, check the number of elements 
    1.31 +// in the array is as expected and read all of elements. Check whether 
    1.32 +// the heap has been corrupted.
    1.33 +// - Create an array of variable length objects packed into a flat buffer, 
    1.34 +// append some elements onto the end of the array, sort the array into 
    1.35 +// key sequence and check the number of elements held in the array is 
    1.36 +// as expected. Read all array elements. Check whether the heap has been 
    1.37 +// corrupted.
    1.38 +// - Check whether the heap has been corrupted by any of the tests.
    1.39 +// Platforms/Drives/Compatibility:
    1.40 +// All 
    1.41 +// Assumptions/Requirement/Pre-requisites:
    1.42 +// Failures and causes:
    1.43 +// Base Port information:
    1.44 +// 
    1.45 +//
    1.46 +
    1.47 +#include <e32test.h>
    1.48 +
    1.49 +const TInt KMaxStrings=3;
    1.50 +
    1.51 +LOCAL_D RTest test(_L("T_READAR"));
    1.52 +LOCAL_D const TPtrC s1(_L("ZZZZ"));
    1.53 +LOCAL_D const TPtrC s2(_L("AAAA"));
    1.54 +LOCAL_D const TPtrC s3(_L("MMMM"));
    1.55 +LOCAL_D const TPtrC* str[KMaxStrings] = {&s1,&s2,&s3};
    1.56 +LOCAL_D const TPtrC* strSorted[KMaxStrings] = {&s2,&s3,&s1};
    1.57 +
    1.58 +LOCAL_C void testReadAny(const TArray<TBufC<0x20> > anArray)
    1.59 +//
    1.60 +// Test with fixed length arrays.
    1.61 +//
    1.62 +	{
    1.63 +
    1.64 +	test(anArray.Count()==KMaxStrings);
    1.65 +	for (TInt i=0;i<KMaxStrings;i++)
    1.66 +		test(anArray[i]==(*strSorted[i]));
    1.67 +	}
    1.68 +
    1.69 +LOCAL_C void testFixL()
    1.70 +//
    1.71 +// Test with fixed length arrays.
    1.72 +//
    1.73 +	{
    1.74 +
    1.75 +	__UHEAP_MARK;
    1.76 +//
    1.77 +	test.Start(_L("Creating Fix array"));
    1.78 +	CArrayFixFlat<TBufC<0x20> >* pFix=new(ELeave) CArrayFixFlat<TBufC<0x20> >(1);
    1.79 +	for (TInt i=0;i<KMaxStrings;i++)
    1.80 +		{
    1.81 +		TBufC<0x20> b=(*str[i]);
    1.82 +		pFix->AppendL(b);
    1.83 +		}
    1.84 +//
    1.85 +	test.Next(_L("Sorting Fix array"));
    1.86 +    TKeyArrayFix array(0,ECmpNormal);
    1.87 +	pFix->Sort(array);
    1.88 +//
    1.89 +	test.Next(_L("Reading Fix array"));
    1.90 +	testReadAny(pFix->Array());
    1.91 +//
    1.92 +	test.Next(_L("Destroying Fix array"));
    1.93 +	delete pFix;
    1.94 +	__UHEAP_MARKEND;
    1.95 +//
    1.96 +	test.End();
    1.97 +	}
    1.98 +
    1.99 +LOCAL_C void testVarL()
   1.100 +//
   1.101 +// Test with variable length arrays.
   1.102 +//
   1.103 +	{
   1.104 +
   1.105 +	__UHEAP_MARK;
   1.106 +//
   1.107 +	test.Start(_L("Creating Var array"));
   1.108 +	CArrayVarFlat<TBufC<0x20> >* pVar=new(ELeave) CArrayVarFlat<TBufC<0x20> >(1);
   1.109 +	for (TInt i=0;i<KMaxStrings;i++)
   1.110 +		{
   1.111 +		TBufC<0x20> b=(*str[i]);
   1.112 +		pVar->AppendL(b,b.Size()+sizeof(TUint));
   1.113 +		}
   1.114 +//
   1.115 +	test.Next(_L("Sorting Var array"));
   1.116 +    TKeyArrayVar array(0,ECmpNormal);
   1.117 +	pVar->Sort(array);
   1.118 +//
   1.119 +	test.Next(_L("Reading Var array"));
   1.120 +	testReadAny(pVar->Array());
   1.121 +//
   1.122 +	test.Next(_L("Destroying Var array"));
   1.123 +	delete pVar;
   1.124 +	__UHEAP_MARKEND;
   1.125 +//
   1.126 +	test.End();
   1.127 +	}
   1.128 +
   1.129 +LOCAL_C void testPakL()
   1.130 +//
   1.131 +// Test with variable length packed arrays.
   1.132 +//
   1.133 +	{
   1.134 +
   1.135 +	__UHEAP_MARK;
   1.136 +//
   1.137 +	test.Start(_L("Creating Pak array"));
   1.138 +	CArrayPakFlat<TBufC<0x20> >* pPak=new(ELeave) CArrayPakFlat<TBufC<0x20> >(1);
   1.139 +	for (TInt i=0;i<KMaxStrings;i++)
   1.140 +		{
   1.141 +		TBufC<0x20> b=(*str[i]);
   1.142 +		pPak->AppendL(b,b.Size()+sizeof(TUint));
   1.143 +		}
   1.144 +//
   1.145 +	test.Next(_L("Sorting Pak array"));
   1.146 +    TKeyArrayVar array(0,ECmpNormal);
   1.147 +	pPak->SortL(array);
   1.148 +//
   1.149 +	test.Next(_L("Reading Pak array"));
   1.150 +	testReadAny(pPak->Array());
   1.151 +//
   1.152 +	test.Next(_L("Destroying Pak array"));
   1.153 +	delete pPak;
   1.154 +	__UHEAP_MARKEND;
   1.155 +//
   1.156 +	test.End();
   1.157 +	}
   1.158 +
   1.159 +GLDEF_C TInt E32Main()
   1.160 +//
   1.161 +// Test the Array classes.
   1.162 +//
   1.163 +    {
   1.164 +
   1.165 +	test.Title();
   1.166 +	__UHEAP_MARK;
   1.167 +//
   1.168 +	test.Start(_L("Testing Fix arrays"));
   1.169 +	TRAPD(r,testFixL());
   1.170 +	test(r==KErrNone);
   1.171 +//
   1.172 +	test.Next(_L("Testing Var arrays"));
   1.173 +	TRAP(r,testVarL());
   1.174 +	test(r==KErrNone);
   1.175 +//
   1.176 +	test.Next(_L("Testing Pak arrays"));
   1.177 +	TRAP(r,testPakL());
   1.178 +	test(r==KErrNone);
   1.179 +//
   1.180 +	__UHEAP_MARKEND;
   1.181 +	test.End();
   1.182 +	return(0);
   1.183 +    }
   1.184 +