os/kernelhwsrv/kerneltest/e32test/buffer/t_readar.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\buffer\t_readar.cpp
sl@0
    15
// Overview:
sl@0
    16
// Test the CArrayFixFlat, CArrayPakFlat, CArrayVarFlat classes.
sl@0
    17
// API Information:
sl@0
    18
// CArrayFixFlat, CArrayPakFlat, CArrayVarFlat.
sl@0
    19
// Details:
sl@0
    20
// - Create an array of fixed length objects contained within a flat 
sl@0
    21
// dynamic buffer, append some elements onto the end of the array, 
sl@0
    22
// sort the array into key sequence, check the number of elements 
sl@0
    23
// in the array is as expected and read all of elements. Check 
sl@0
    24
// whether the heap has been corrupted.
sl@0
    25
// - Create an array of variable length objects implemented using a 
sl@0
    26
// flat dynamic buffer, append some elements onto the end of the 
sl@0
    27
// array, sort the array into key sequence, check the number of elements 
sl@0
    28
// in the array is as expected and read all of elements. Check whether 
sl@0
    29
// the heap has been corrupted.
sl@0
    30
// - Create an array of variable length objects packed into a flat buffer, 
sl@0
    31
// append some elements onto the end of the array, sort the array into 
sl@0
    32
// key sequence and check the number of elements held in the array is 
sl@0
    33
// as expected. Read all array elements. Check whether the heap has been 
sl@0
    34
// corrupted.
sl@0
    35
// - Check whether the heap has been corrupted by any of the tests.
sl@0
    36
// Platforms/Drives/Compatibility:
sl@0
    37
// All 
sl@0
    38
// Assumptions/Requirement/Pre-requisites:
sl@0
    39
// Failures and causes:
sl@0
    40
// Base Port information:
sl@0
    41
// 
sl@0
    42
//
sl@0
    43
sl@0
    44
#include <e32test.h>
sl@0
    45
sl@0
    46
const TInt KMaxStrings=3;
sl@0
    47
sl@0
    48
LOCAL_D RTest test(_L("T_READAR"));
sl@0
    49
LOCAL_D const TPtrC s1(_L("ZZZZ"));
sl@0
    50
LOCAL_D const TPtrC s2(_L("AAAA"));
sl@0
    51
LOCAL_D const TPtrC s3(_L("MMMM"));
sl@0
    52
LOCAL_D const TPtrC* str[KMaxStrings] = {&s1,&s2,&s3};
sl@0
    53
LOCAL_D const TPtrC* strSorted[KMaxStrings] = {&s2,&s3,&s1};
sl@0
    54
sl@0
    55
LOCAL_C void testReadAny(const TArray<TBufC<0x20> > anArray)
sl@0
    56
//
sl@0
    57
// Test with fixed length arrays.
sl@0
    58
//
sl@0
    59
	{
sl@0
    60
sl@0
    61
	test(anArray.Count()==KMaxStrings);
sl@0
    62
	for (TInt i=0;i<KMaxStrings;i++)
sl@0
    63
		test(anArray[i]==(*strSorted[i]));
sl@0
    64
	}
sl@0
    65
sl@0
    66
LOCAL_C void testFixL()
sl@0
    67
//
sl@0
    68
// Test with fixed length arrays.
sl@0
    69
//
sl@0
    70
	{
sl@0
    71
sl@0
    72
	__UHEAP_MARK;
sl@0
    73
//
sl@0
    74
	test.Start(_L("Creating Fix array"));
sl@0
    75
	CArrayFixFlat<TBufC<0x20> >* pFix=new(ELeave) CArrayFixFlat<TBufC<0x20> >(1);
sl@0
    76
	for (TInt i=0;i<KMaxStrings;i++)
sl@0
    77
		{
sl@0
    78
		TBufC<0x20> b=(*str[i]);
sl@0
    79
		pFix->AppendL(b);
sl@0
    80
		}
sl@0
    81
//
sl@0
    82
	test.Next(_L("Sorting Fix array"));
sl@0
    83
    TKeyArrayFix array(0,ECmpNormal);
sl@0
    84
	pFix->Sort(array);
sl@0
    85
//
sl@0
    86
	test.Next(_L("Reading Fix array"));
sl@0
    87
	testReadAny(pFix->Array());
sl@0
    88
//
sl@0
    89
	test.Next(_L("Destroying Fix array"));
sl@0
    90
	delete pFix;
sl@0
    91
	__UHEAP_MARKEND;
sl@0
    92
//
sl@0
    93
	test.End();
sl@0
    94
	}
sl@0
    95
sl@0
    96
LOCAL_C void testVarL()
sl@0
    97
//
sl@0
    98
// Test with variable length arrays.
sl@0
    99
//
sl@0
   100
	{
sl@0
   101
sl@0
   102
	__UHEAP_MARK;
sl@0
   103
//
sl@0
   104
	test.Start(_L("Creating Var array"));
sl@0
   105
	CArrayVarFlat<TBufC<0x20> >* pVar=new(ELeave) CArrayVarFlat<TBufC<0x20> >(1);
sl@0
   106
	for (TInt i=0;i<KMaxStrings;i++)
sl@0
   107
		{
sl@0
   108
		TBufC<0x20> b=(*str[i]);
sl@0
   109
		pVar->AppendL(b,b.Size()+sizeof(TUint));
sl@0
   110
		}
sl@0
   111
//
sl@0
   112
	test.Next(_L("Sorting Var array"));
sl@0
   113
    TKeyArrayVar array(0,ECmpNormal);
sl@0
   114
	pVar->Sort(array);
sl@0
   115
//
sl@0
   116
	test.Next(_L("Reading Var array"));
sl@0
   117
	testReadAny(pVar->Array());
sl@0
   118
//
sl@0
   119
	test.Next(_L("Destroying Var array"));
sl@0
   120
	delete pVar;
sl@0
   121
	__UHEAP_MARKEND;
sl@0
   122
//
sl@0
   123
	test.End();
sl@0
   124
	}
sl@0
   125
sl@0
   126
LOCAL_C void testPakL()
sl@0
   127
//
sl@0
   128
// Test with variable length packed arrays.
sl@0
   129
//
sl@0
   130
	{
sl@0
   131
sl@0
   132
	__UHEAP_MARK;
sl@0
   133
//
sl@0
   134
	test.Start(_L("Creating Pak array"));
sl@0
   135
	CArrayPakFlat<TBufC<0x20> >* pPak=new(ELeave) CArrayPakFlat<TBufC<0x20> >(1);
sl@0
   136
	for (TInt i=0;i<KMaxStrings;i++)
sl@0
   137
		{
sl@0
   138
		TBufC<0x20> b=(*str[i]);
sl@0
   139
		pPak->AppendL(b,b.Size()+sizeof(TUint));
sl@0
   140
		}
sl@0
   141
//
sl@0
   142
	test.Next(_L("Sorting Pak array"));
sl@0
   143
    TKeyArrayVar array(0,ECmpNormal);
sl@0
   144
	pPak->SortL(array);
sl@0
   145
//
sl@0
   146
	test.Next(_L("Reading Pak array"));
sl@0
   147
	testReadAny(pPak->Array());
sl@0
   148
//
sl@0
   149
	test.Next(_L("Destroying Pak array"));
sl@0
   150
	delete pPak;
sl@0
   151
	__UHEAP_MARKEND;
sl@0
   152
//
sl@0
   153
	test.End();
sl@0
   154
	}
sl@0
   155
sl@0
   156
GLDEF_C TInt E32Main()
sl@0
   157
//
sl@0
   158
// Test the Array classes.
sl@0
   159
//
sl@0
   160
    {
sl@0
   161
sl@0
   162
	test.Title();
sl@0
   163
	__UHEAP_MARK;
sl@0
   164
//
sl@0
   165
	test.Start(_L("Testing Fix arrays"));
sl@0
   166
	TRAPD(r,testFixL());
sl@0
   167
	test(r==KErrNone);
sl@0
   168
//
sl@0
   169
	test.Next(_L("Testing Var arrays"));
sl@0
   170
	TRAP(r,testVarL());
sl@0
   171
	test(r==KErrNone);
sl@0
   172
//
sl@0
   173
	test.Next(_L("Testing Pak arrays"));
sl@0
   174
	TRAP(r,testPakL());
sl@0
   175
	test(r==KErrNone);
sl@0
   176
//
sl@0
   177
	__UHEAP_MARKEND;
sl@0
   178
	test.End();
sl@0
   179
	return(0);
sl@0
   180
    }
sl@0
   181