diff -r 000000000000 -r a41df078684a kerneltest/e32test/buffer/uint_arr.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32test/buffer/uint_arr.cpp Mon Oct 19 15:55:17 2009 +0100 @@ -0,0 +1,572 @@ +// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// e32test\buffer\uint_arr.cpp +// +// + +#include +#include + +#define NUM_TESTS 250 + +GLREF_D RTest test; +GLREF_C TInt Random(); + +LOCAL_C TInt IntAppendAndAccessTest(TInt aCount, TInt aNumTests, TInt aRange) + { + TInt n; + for (n=0; n a; + TUint *pA=(TUint*)User::Alloc(aCount*sizeof(TUint)); + if (!pA) + { + a.Close(); + return -65535; + } + TInt i; + for (i=0; i a; + TInt i; + for (i=0; i a; + TUint *pA=(TUint*)User::Alloc(aCount*sizeof(TUint)); + if (!pA) + { + a.Close(); + return -65535; + } + TInt i; + for (i=0; ii) + { + a.Close(); + return -2; + } + TUint x=Random()&aRange; + r=a.Find(x); + if (r<0) + { + TInt j; + for (j=0; j a; + TUint *pA=(TUint*)User::Alloc(aCount*sizeof(TUint)); + if (!pA) + { + a.Close(); + return -65535; + } + TInt i=0; + TUint y=TUint(Random())>>16; + for(i=0; i=0 + a.Append(y); + pA[i]=y; + y+=x; + } + if (a.Count()!=aCount) + { + a.Close(); + return -1; + } + for (i=0; i sq; + for (i=0; i<1024; i++) + { + TInt j=i*i; + sq.Append(j); + } + for (i=0; i<10000; i++) + { + TInt x=Random()&1023; + TInt y=x*x; + TInt r=sq.FindInOrder(y); + if (r!=x) + { + sq.Close(); + return -1; + } + } + sq.Close(); + return 0; + } + +LOCAL_C TInt IntInsertInOrderTest(TInt aCount, TInt aNumTests, TInt aRange) + { + TInt n; + for (n=0; n a; + RArray b; + RArray c; + TInt i; + TInt cc=0; + for (i=0; ib[i+1]) + { + a.Close(); + b.Close(); + c.Close(); + return -3; + } + } + for (i=0; i=c[i+1]) + { + a.Close(); + b.Close(); + c.Close(); + return -8; + } + if (a.Find(c[i])<0) + { + a.Close(); + b.Close(); + c.Close(); + return -9; + } + } + a.Close(); + b.Close(); + c.Close(); + } + return KErrNone; + } + +LOCAL_C TInt IntInsertInOrderTest2() + { + TInt i; + RArray sq; + for (i=0; i<1024; i++) + { + TInt j=i*i; + sq.InsertInOrder(j); + sq.InsertInOrder(-j); + } + if (sq.Count()!=2047) + { + sq.Close(); + return -1; + } + for (i=0; i<2047; i++) + { + TInt y; + if (i<1024) + y=i*i; + else + y=-(2047-i)*(2047-i); + if (sq[i]!=TUint(y)) + { + sq.Close(); + return -2; + } + } + sq.Close(); + return 0; + } + +LOCAL_C TInt IntSortTest(TInt aCount, TInt aNumTests, TInt aRange) + { + TInt n; + for (n=0; n a; + RArray b; + TInt i; + for (i=0; i a; + RArray b; + TInt i; + for (i=0; i>1); + a.Append(TUint(x)); + b.InsertInOrderAllowRepeats(TUint(x)); + } + a.Sort(); + test(a.Count()==aCount); + test(b.Count()==aCount); + for (i=0; i>1); i<=(aRange>>1); ++i) + { + TUint u = (TUint)i; + TInt first = a.SpecificFindInOrder(u, EArrayFindMode_First); + TInt last = a.SpecificFindInOrder(u, EArrayFindMode_Last); + TInt any = a.SpecificFindInOrder(u, EArrayFindMode_Any); + TInt fi, li, ai; + TInt first2 = a.SpecificFindInOrder(u, fi, EArrayFindMode_First); + TInt last2 = a.SpecificFindInOrder(u, li, EArrayFindMode_Last); + TInt any2 = a.SpecificFindInOrder(u, ai, EArrayFindMode_Any); + ++ntot; + if (first < 0) + { + test(first == KErrNotFound); + test(first == last); + test(first == any); + test(first == first2); + test(first == last2); + test(first == any2); + test(fi == li); + test(fi == ai); + test(li==aCount || a[li]>u); + test(li==0 || a[li-1]u); + test(ai>=fi && ai 1) + ++nrpt; + } + } + a.Close(); + b.Close(); + } + test.Printf(_L("ntot=%d nmiss=%d nrpt=%d\n"), ntot, nmiss, nrpt); + return KErrNone; + } + +GLDEF_C void DoUintArrayTests() + { + test.Start(_L("Unsigned Integer Arrays...")); + + test.Next(_L("AppendAndAccess tests...")); + test.Next(_L("Count 10 Range 15")); + test(IntAppendAndAccessTest(10,NUM_TESTS,15)==KErrNone); + test.Next(_L("Count 20 Range 255")); + test(IntAppendAndAccessTest(20,NUM_TESTS,255)==KErrNone); + test.Next(_L("Count 100 Range all")); + test(IntAppendAndAccessTest(100,NUM_TESTS,-1)==KErrNone); + + test.Next(_L("Remove tests...")); + test(IntRemoveTest()==KErrNone); + + test.Next(_L("Find tests...")); + test.Next(_L("Count 10 Range 15")); + test(IntFindTest(10,NUM_TESTS,15)==KErrNone); + test.Next(_L("Count 20 Range 255")); + test(IntFindTest(20,NUM_TESTS,255)==KErrNone); + test.Next(_L("Count 100 Range all")); + test(IntFindTest(100,NUM_TESTS,-1)==KErrNone); + + test.Next(_L("FindInOrder tests...")); + test.Next(_L("Count 10 Range 15")); + test(IntFindInOrderTest(10,NUM_TESTS,15)==KErrNone); + test.Next(_L("Count 20 Range 255")); + test(IntFindInOrderTest(20,NUM_TESTS,255)==KErrNone); + test.Next(_L("Count 100 Range 4095")); + test(IntFindInOrderTest(100,NUM_TESTS,4095)==KErrNone); + test.Next(_L("Squares")); + test(IntFindInOrderTest2()==KErrNone); + + test.Next(_L("InsertInOrder tests...")); + test.Next(_L("Count 10 Range 15")); + test(IntInsertInOrderTest(10,NUM_TESTS,15)==KErrNone); + test.Next(_L("Count 20 Range 255")); + test(IntInsertInOrderTest(20,NUM_TESTS,255)==KErrNone); + test.Next(_L("Count 100 Range all")); + test(IntInsertInOrderTest(100,NUM_TESTS,-1)==KErrNone); + test.Next(_L("Squares")); + test(IntInsertInOrderTest2()==KErrNone); + + test.Next(_L("Sort tests...")); + test.Next(_L("Count 10 Range 15")); + test(IntSortTest(10,NUM_TESTS,15)==KErrNone); + test.Next(_L("Count 20 Range 255")); + test(IntSortTest(20,NUM_TESTS,255)==KErrNone); + test.Next(_L("Count 100 Range all")); + test(IntSortTest(100,NUM_TESTS,-1)==KErrNone); + + test.Next(_L("UIntSpecificFindTests...")); + test(UIntSpecificFindTests(100, 10, 15)==KErrNone); + test(UIntSpecificFindTests(100, 10, 127)==KErrNone); + + test.End(); + }