1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/buffer/smpl_arr.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,2146 @@
1.4 +// Copyright (c) 1994-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\smpl_arr.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32test.h>
1.22 +#include <e32math.h>
1.23 +#include <e32std.h>
1.24 +#include <e32std_private.h>
1.25 +
1.26 +#define NUM_TESTS 200
1.27 +
1.28 +GLREF_D RTest test;
1.29 +GLREF_C TInt Random();
1.30 +
1.31 +struct SEntry
1.32 + {
1.33 + TInt iKey;
1.34 + TInt iValue;
1.35 + inline TBool operator!=(const SEntry& anEntry) const
1.36 + {return (iValue!=anEntry.iValue || iKey!=anEntry.iKey);}
1.37 + inline TBool operator==(const SEntry& anEntry) const
1.38 + {return (iValue==anEntry.iValue && iKey==anEntry.iKey);}
1.39 + };
1.40 +
1.41 +struct SArray
1.42 + {
1.43 + TInt iCount;
1.44 + TAny* iEntries;
1.45 + TInt iEntrySize;
1.46 + TInt iKeyOffset;
1.47 + TInt iAllocated;
1.48 + TInt iGranularity;
1.49 + };
1.50 +
1.51 +GLREF_C TInt OrderSEntry(const SEntry& aLeft, const SEntry& aRight);
1.52 +GLREF_C TInt OrderSEntryU(const SEntry& aLeft, const SEntry& aRight);
1.53 +GLREF_C TInt OrderSEntry2(const SEntry& aLeft, const SEntry& aRight);
1.54 +GLREF_C TInt OrderSEntryU2(const SEntry& aLeft, const SEntry& aRight);
1.55 +GLREF_C TBool CompareSEntryByKeyKey(const TInt* aKey, const SEntry& aRight);
1.56 +GLREF_C TBool CompareSEntryByKeyValue(const TInt* aValue, const SEntry& aRight);
1.57 +
1.58 +GLREF_D TLinearOrder<TInt64> Int64Order;
1.59 +GLREF_D TIdentityRelation<TInt64> Int64Identity;
1.60 +GLREF_D TLinearOrder<SEntry> SEntryOrder;
1.61 +GLREF_D TIdentityRelation<SEntry> SEntryKeyIdentity;
1.62 +GLREF_D TIdentityRelation<SEntry> SEntryIdentity;
1.63 +
1.64 +LOCAL_C TInt64 Random64(TInt64& aMask)
1.65 + {
1.66 + TInt64 x = MAKE_TINT64(Random()&I64HIGH(aMask), Random()&I64LOW(aMask));
1.67 + return x;
1.68 + }
1.69 +
1.70 +LOCAL_C TInt IntAppendAndAccessTest(TInt aCount, TInt aNumTests, TInt64 aMask)
1.71 + {
1.72 + TInt n;
1.73 + for (n=0; n<aNumTests; n++)
1.74 + {
1.75 + RArray<TInt64> a(aCount);
1.76 + TInt64 *pA=new TInt64[aCount];
1.77 + if (!pA)
1.78 + {
1.79 + a.Close();
1.80 + return -65535;
1.81 + }
1.82 + TInt i;
1.83 + for (i=0; i<aCount; i++)
1.84 + {
1.85 + TInt64 x=Random64(aMask);
1.86 + pA[i]=x;
1.87 + a.Append(x);
1.88 + }
1.89 + if (a.Count()!=aCount)
1.90 + {
1.91 + a.Close();
1.92 + return -1;
1.93 + }
1.94 + for (i=0; i<aCount; i++)
1.95 + {
1.96 + if (a[i]!=pA[i])
1.97 + {
1.98 + a.Close();
1.99 + return -2;
1.100 + }
1.101 + pA[i]=Random64(aMask);
1.102 + a[i]=pA[i];
1.103 + }
1.104 + if (a.Count()!=aCount)
1.105 + {
1.106 + a.Close();
1.107 + return -3;
1.108 + }
1.109 + for (i=0; i<aCount; i++)
1.110 + {
1.111 + if (a[i]!=pA[i])
1.112 + {
1.113 + a.Close();
1.114 + return -4;
1.115 + }
1.116 + }
1.117 + delete[] pA;
1.118 + a.Close();
1.119 + }
1.120 + return KErrNone;
1.121 + }
1.122 +
1.123 +LOCAL_C TInt IntRemoveTest()
1.124 + {
1.125 + TInt m=32;
1.126 + TInt n=m*m+1;
1.127 + RArray<TInt64> a(n);
1.128 + TInt i;
1.129 + for (i=0; i<n; i++)
1.130 + {
1.131 + TInt64 x = MAKE_TINT64(i*i,i);
1.132 + a.Append(x);
1.133 + }
1.134 + TInt p=2;
1.135 + for (i=2; i<=m; i++)
1.136 + {
1.137 + TInt j;
1.138 + for (j=0; j<(2*i-2); j++)
1.139 + {
1.140 + a.Remove(p);
1.141 + }
1.142 + p++;
1.143 + }
1.144 + if (a.Count()!=m+1)
1.145 + {
1.146 + a.Close();
1.147 + return -1;
1.148 + }
1.149 + for (i=0; i<m; i++)
1.150 + {
1.151 + TInt64 x = MAKE_TINT64(i*i*i*i,i*i);
1.152 + if (a[i]!=x)
1.153 + {
1.154 + a.Close();
1.155 + return -2;
1.156 + }
1.157 + }
1.158 + a.Close();
1.159 + return KErrNone;
1.160 + }
1.161 +
1.162 +LOCAL_C TInt IntFindTest(TInt aCount, TInt aNumTests, TInt64 aMask)
1.163 + {
1.164 + TInt n;
1.165 + for (n=0; n<aNumTests; n++)
1.166 + {
1.167 + RArray<TInt64> a(aCount);
1.168 + TInt64 *pA=new TInt64[aCount];
1.169 + if (!pA)
1.170 + {
1.171 + a.Close();
1.172 + return -65535;
1.173 + }
1.174 + TInt i;
1.175 + for (i=0; i<aCount; i++)
1.176 + {
1.177 + pA[i]=Random64(aMask);
1.178 + a.Append(pA[i]);
1.179 + }
1.180 + if (a.Count()!=aCount)
1.181 + {
1.182 + a.Close();
1.183 + return -1;
1.184 + }
1.185 + for (i=0; i<aCount; i++)
1.186 + {
1.187 + TInt r=a.Find(pA[i],Int64Identity);
1.188 + if (r<0 || pA[i]!=pA[r] || r>i)
1.189 + {
1.190 + a.Close();
1.191 + return -2;
1.192 + }
1.193 + }
1.194 + delete[] pA;
1.195 + a.Close();
1.196 + }
1.197 + return KErrNone;
1.198 + }
1.199 +
1.200 +template <class XTestInput>
1.201 +LOCAL_C TInt FindWithEqualityOp(XTestInput &aObject1, XTestInput &aObject2)
1.202 + {
1.203 + //Construct a suitable RArray
1.204 + RArray<XTestInput> testRArray;
1.205 +
1.206 + //Append the test objects to the RArray
1.207 + testRArray.AppendL(aObject1);
1.208 + testRArray.AppendL(aObject2);
1.209 + testRArray.AppendL(aObject1);
1.210 + testRArray.AppendL(aObject2);
1.211 +
1.212 + //Demonstrate that "regular" Find() method returns incorrect result
1.213 + TInt pos = KErrNotFound;
1.214 + pos = testRArray.Find(aObject1);
1.215 + if(pos!=0)
1.216 + return KErrNotFound;
1.217 + pos = testRArray.Find(aObject2);
1.218 + if(pos!=0)
1.219 + return KErrNotFound;
1.220 +
1.221 + //Test the Find() method using TIdentityRelation default CTOR
1.222 + pos = testRArray.Find(aObject1, TIdentityRelation<XTestInput>());
1.223 + if(pos!=0)
1.224 + return KErrNotFound;
1.225 + pos = testRArray.Find(aObject2, TIdentityRelation<XTestInput>());
1.226 + if(pos!=1)
1.227 + return KErrNotFound;
1.228 +
1.229 + //Test the FindReverse() method using TIdentityRelation default CTOR
1.230 + pos = testRArray.FindReverse(aObject1, TIdentityRelation<XTestInput>());
1.231 + if(pos!=2)
1.232 + return KErrNotFound;
1.233 + pos = testRArray.FindReverse(aObject2, TIdentityRelation<XTestInput>());
1.234 + if(pos!=3)
1.235 + return KErrNotFound;
1.236 +
1.237 + //Objects have been found correctly if this point reached
1.238 + testRArray.Close();
1.239 +
1.240 + return KErrNone;
1.241 + }
1.242 +
1.243 +LOCAL_C TInt FindWithEqualityOpTest()
1.244 + {
1.245 + //Test "complex" objects which would work incorrectly with the regular Find() method
1.246 +
1.247 + TPoint p1(0,0);
1.248 + TPoint p2(0,1);
1.249 + TPoint p3(0,2);
1.250 + test(FindWithEqualityOp(p1, p2) == KErrNone);
1.251 +
1.252 + TRect rect1(p1,p2);
1.253 + TRect rect2(p1,p3);
1.254 + test(FindWithEqualityOp(rect1, rect2) == KErrNone);
1.255 +
1.256 + TBuf<5> buf1(_L("test1"));
1.257 + TBuf<5> buf2(_L("test2"));
1.258 + test(FindWithEqualityOp(buf1, buf2) == KErrNone);
1.259 +
1.260 + return KErrNone;
1.261 + }
1.262 +
1.263 +LOCAL_C TInt EntryFindTest(TInt aCount, TInt aNumTests)
1.264 + {
1.265 + TInt n;
1.266 + for (n=0; n<aNumTests; n++)
1.267 + {
1.268 + RArray<SEntry> a(aCount,0); // keyed on iKey
1.269 + RArray<SEntry> b(aCount,4); // keyed on iValue
1.270 + SEntry *pE=new SEntry[aCount];
1.271 + if (!pE)
1.272 + {
1.273 + a.Close();
1.274 + b.Close();
1.275 + return -65535;
1.276 + }
1.277 + TInt i;
1.278 + for (i=0; i<aCount; i++)
1.279 + {
1.280 + pE[i].iValue=Random();
1.281 + pE[i].iKey=Random();
1.282 + a.Append(pE[i]);
1.283 + b.Append(pE[i]);
1.284 + }
1.285 + if (a.Count()!=aCount)
1.286 + {
1.287 + a.Close();
1.288 + b.Close();
1.289 + return -1;
1.290 + }
1.291 + if (b.Count()!=aCount)
1.292 + {
1.293 + a.Close();
1.294 + b.Close();
1.295 + return -1;
1.296 + }
1.297 + for (i=0; i<aCount; i++)
1.298 + {
1.299 + SEntry e1=pE[i];
1.300 + SEntry e2=pE[i];
1.301 + e2.iValue=~e2.iValue;
1.302 + SEntry e3=pE[i];
1.303 + e3.iKey=~e3.iKey;
1.304 + TInt r=a.Find(e1);
1.305 + if (r!=i)
1.306 + {
1.307 + a.Close();
1.308 + b.Close();
1.309 + return -2;
1.310 + }
1.311 + r=a.Find(e2);
1.312 + if (r!=i)
1.313 + {
1.314 + a.Close();
1.315 + b.Close();
1.316 + return -3;
1.317 + }
1.318 + r=a.Find(e3);
1.319 + if (r>=0 && pE[r].iKey!=e3.iKey)
1.320 + {
1.321 + a.Close();
1.322 + b.Close();
1.323 + return -4;
1.324 + }
1.325 + r=b.Find(e1);
1.326 + if (r!=i)
1.327 + {
1.328 + a.Close();
1.329 + b.Close();
1.330 + return -5;
1.331 + }
1.332 + r=b.Find(e3);
1.333 + if (r!=i)
1.334 + {
1.335 + a.Close();
1.336 + b.Close();
1.337 + return -6;
1.338 + }
1.339 + r=b.Find(e2);
1.340 + if (r>=0 && pE[r].iValue!=e3.iValue)
1.341 + {
1.342 + a.Close();
1.343 + b.Close();
1.344 + return -7;
1.345 + }
1.346 + r=a.Find(e1,SEntryIdentity);
1.347 + if (r!=i)
1.348 + {
1.349 + a.Close();
1.350 + b.Close();
1.351 + return -8;
1.352 + }
1.353 + r=a.Find(e2,SEntryIdentity);
1.354 + if (r>=0 && pE[r]!=e3)
1.355 + {
1.356 + a.Close();
1.357 + b.Close();
1.358 + return -9;
1.359 + }
1.360 + r=a.Find(e3,SEntryIdentity);
1.361 + if (r>=0 && pE[r]!=e3)
1.362 + {
1.363 + a.Close();
1.364 + b.Close();
1.365 + return -10;
1.366 + }
1.367 + r=b.Find(e1,SEntryIdentity);
1.368 + if (r!=i)
1.369 + {
1.370 + a.Close();
1.371 + b.Close();
1.372 + return -11;
1.373 + }
1.374 + r=b.Find(e3,SEntryIdentity);
1.375 + if (r>=0 && pE[r]!=e3)
1.376 + {
1.377 + a.Close();
1.378 + b.Close();
1.379 + return -12;
1.380 + }
1.381 + r=b.Find(e2,SEntryIdentity);
1.382 + if (r>=0 && pE[r]!=e3)
1.383 + {
1.384 + a.Close();
1.385 + b.Close();
1.386 + return -13;
1.387 + }
1.388 + r=a.Find(e1.iValue,CompareSEntryByKeyValue);
1.389 + if (r!=i)
1.390 + {
1.391 + a.Close();
1.392 + b.Close();
1.393 + return -14;
1.394 + }
1.395 + r=a.Find(e2.iValue,CompareSEntryByKeyValue);
1.396 + if (r>=0 && pE[r].iValue!=e2.iValue)
1.397 + {
1.398 + a.Close();
1.399 + b.Close();
1.400 + return -15;
1.401 + }
1.402 + r=b.Find(e1.iKey,CompareSEntryByKeyKey);
1.403 + if (r!=i)
1.404 + {
1.405 + a.Close();
1.406 + b.Close();
1.407 + return -16;
1.408 + }
1.409 + r=b.Find(e3.iKey,CompareSEntryByKeyKey);
1.410 + if (r>=0 && pE[r].iKey!=e3.iKey)
1.411 + {
1.412 + a.Close();
1.413 + b.Close();
1.414 + return -17;
1.415 + }
1.416 + }
1.417 + delete[] pE;
1.418 + a.Close();
1.419 + b.Close();
1.420 + }
1.421 + return KErrNone;
1.422 + }
1.423 +
1.424 +LOCAL_C TInt IntFindReverseTest(TInt aCount, TInt aNumTests, TInt64 aMask)
1.425 + {
1.426 + TInt n;
1.427 + for (n=0; n<aNumTests; n++)
1.428 + {
1.429 + RArray<TInt64> a(aCount);
1.430 + TInt64 *pA=new TInt64[aCount];
1.431 + if (!pA)
1.432 + {
1.433 + a.Close();
1.434 + return -65535;
1.435 + }
1.436 + TInt i;
1.437 + for (i=0; i<aCount; i++)
1.438 + {
1.439 + pA[i]=Random64(aMask);
1.440 + a.Append(pA[i]);
1.441 + }
1.442 + if (a.Count()!=aCount)
1.443 + {
1.444 + a.Close();
1.445 + return -1;
1.446 + }
1.447 + for (i=0; i<aCount; i++)
1.448 + {
1.449 + TInt r=a.FindReverse(pA[i],Int64Identity);
1.450 + if (pA[i]!=pA[r] || r<i)
1.451 + {
1.452 + a.Close();
1.453 + return -2;
1.454 + }
1.455 + }
1.456 + delete[] pA;
1.457 + a.Close();
1.458 + }
1.459 + return KErrNone;
1.460 + }
1.461 +
1.462 +LOCAL_C TInt EntryFindReverseTest(TInt aCount, TInt aNumTests)
1.463 + {
1.464 + TInt n;
1.465 + for (n=0; n<aNumTests; n++)
1.466 + {
1.467 + RArray<SEntry> a(aCount,0); // keyed on iKey
1.468 + RArray<SEntry> b(aCount,4); // keyed on iValue
1.469 + SEntry *pE=new SEntry[aCount];
1.470 + if (!pE)
1.471 + {
1.472 + a.Close();
1.473 + b.Close();
1.474 + return -65535;
1.475 + }
1.476 + TInt i;
1.477 + for (i=0; i<aCount; i++)
1.478 + {
1.479 + pE[i].iValue=Random();
1.480 + pE[i].iKey=Random();
1.481 + a.Append(pE[i]);
1.482 + b.Append(pE[i]);
1.483 + }
1.484 + if (a.Count()!=aCount)
1.485 + {
1.486 + a.Close();
1.487 + b.Close();
1.488 + return -1;
1.489 + }
1.490 + if (b.Count()!=aCount)
1.491 + {
1.492 + a.Close();
1.493 + b.Close();
1.494 + return -1;
1.495 + }
1.496 + for (i=0; i<aCount; i++)
1.497 + {
1.498 + SEntry e1=pE[i];
1.499 + SEntry e2=pE[i];
1.500 + e2.iValue=~e2.iValue;
1.501 + SEntry e3=pE[i];
1.502 + e3.iKey=~e3.iKey;
1.503 + TInt r=a.FindReverse(e1);
1.504 + if (r!=i)
1.505 + {
1.506 + a.Close();
1.507 + b.Close();
1.508 + return -2;
1.509 + }
1.510 + r=a.FindReverse(e2);
1.511 + if (r!=i)
1.512 + {
1.513 + a.Close();
1.514 + b.Close();
1.515 + return -3;
1.516 + }
1.517 + r=a.FindReverse(e3);
1.518 + if (r>=0 && pE[r].iKey!=e3.iKey)
1.519 + {
1.520 + a.Close();
1.521 + b.Close();
1.522 + return -4;
1.523 + }
1.524 + r=b.FindReverse(e1);
1.525 + if (r!=i)
1.526 + {
1.527 + a.Close();
1.528 + b.Close();
1.529 + return -5;
1.530 + }
1.531 + r=b.FindReverse(e3);
1.532 + if (r!=i)
1.533 + {
1.534 + a.Close();
1.535 + b.Close();
1.536 + return -6;
1.537 + }
1.538 + r=b.FindReverse(e2);
1.539 + if (r>=0 && pE[r].iValue!=e3.iValue)
1.540 + {
1.541 + a.Close();
1.542 + b.Close();
1.543 + return -7;
1.544 + }
1.545 + r=a.FindReverse(e1,SEntryIdentity);
1.546 + if (r!=i)
1.547 + {
1.548 + a.Close();
1.549 + b.Close();
1.550 + return -8;
1.551 + }
1.552 + r=a.FindReverse(e2,SEntryIdentity);
1.553 + if (r>=0 && pE[r]!=e3)
1.554 + {
1.555 + a.Close();
1.556 + b.Close();
1.557 + return -9;
1.558 + }
1.559 + r=a.FindReverse(e3,SEntryIdentity);
1.560 + if (r>=0 && pE[r]!=e3)
1.561 + {
1.562 + a.Close();
1.563 + b.Close();
1.564 + return -10;
1.565 + }
1.566 + r=b.FindReverse(e1,SEntryIdentity);
1.567 + if (r!=i)
1.568 + {
1.569 + a.Close();
1.570 + b.Close();
1.571 + return -11;
1.572 + }
1.573 + r=b.FindReverse(e3,SEntryIdentity);
1.574 + if (r>=0 && pE[r]!=e3)
1.575 + {
1.576 + a.Close();
1.577 + b.Close();
1.578 + return -12;
1.579 + }
1.580 + r=b.FindReverse(e2,SEntryIdentity);
1.581 + if (r>=0 && pE[r]!=e3)
1.582 + {
1.583 + a.Close();
1.584 + b.Close();
1.585 + return -13;
1.586 + }
1.587 + r=a.FindReverse(e1.iValue,CompareSEntryByKeyValue);
1.588 + if (r!=i)
1.589 + {
1.590 + a.Close();
1.591 + b.Close();
1.592 + return -14;
1.593 + }
1.594 + r=a.FindReverse(e2.iValue,CompareSEntryByKeyValue);
1.595 + if (r>=0 && pE[r].iValue!=e2.iValue)
1.596 + {
1.597 + a.Close();
1.598 + b.Close();
1.599 + return -15;
1.600 + }
1.601 + r=b.FindReverse(e1.iKey,CompareSEntryByKeyKey);
1.602 + if (r!=i)
1.603 + {
1.604 + a.Close();
1.605 + b.Close();
1.606 + return -16;
1.607 + }
1.608 + r=b.FindReverse(e3.iKey,CompareSEntryByKeyKey);
1.609 + if (r>=0 && pE[r].iKey!=e3.iKey)
1.610 + {
1.611 + a.Close();
1.612 + b.Close();
1.613 + return -17;
1.614 + }
1.615 + }
1.616 + delete[] pE;
1.617 + a.Close();
1.618 + b.Close();
1.619 + }
1.620 + return KErrNone;
1.621 + }
1.622 +
1.623 +LOCAL_C TInt IntFindInOrderTest(TInt aCount, TInt aNumTests, TInt64 aMask)
1.624 +// require aRange*aCount<2^32
1.625 + {
1.626 + TInt n;
1.627 + for (n=0; n<aNumTests; n++)
1.628 + {
1.629 + RArray<TInt64> a(aCount);
1.630 + TInt64 *pA=new TInt64[aCount];
1.631 + if (!pA)
1.632 + {
1.633 + a.Close();
1.634 + return -65535;
1.635 + }
1.636 + TInt i=0;
1.637 + TInt64 y=-256;
1.638 + for(i=0; i<aCount; i++)
1.639 + {
1.640 + TInt64 x=Random64(aMask); // this is always >=0
1.641 + pA[i]=y;
1.642 + a.Append(y);
1.643 + y+=x;
1.644 + }
1.645 + if (a.Count()!=aCount)
1.646 + {
1.647 + a.Close();
1.648 + return -1;
1.649 + }
1.650 + for (i=0; i<aCount; i++)
1.651 + {
1.652 + TInt r=a.FindInOrder(pA[i],Int64Order);
1.653 + if (r<0 || pA[r]!=pA[i])
1.654 + {
1.655 + a.Close();
1.656 + return -2;
1.657 + }
1.658 + TInt64 x=Random64(aMask);
1.659 + r=a.FindInOrder(x,Int64Order);
1.660 + if (r<0)
1.661 + {
1.662 + TInt j;
1.663 + for (j=0; j<aCount; j++)
1.664 + {
1.665 + if (pA[j]==x)
1.666 + {
1.667 + a.Close();
1.668 + return -3;
1.669 + }
1.670 + }
1.671 + }
1.672 + else if (pA[r]!=x)
1.673 + {
1.674 + a.Close();
1.675 + return -4;
1.676 + }
1.677 + }
1.678 + delete[] pA;
1.679 + a.Close();
1.680 + }
1.681 + return KErrNone;
1.682 + }
1.683 +
1.684 +LOCAL_C TInt EntryFindInOrderTest(TInt aCount, TInt aNumTests)
1.685 +// require aRange*aCount<2^32
1.686 + {
1.687 + TInt n;
1.688 + for (n=0; n<aNumTests; n++)
1.689 + {
1.690 + RArray<SEntry> a(aCount,0); // keyed on iKey
1.691 + RArray<SEntry> b(aCount,4); // keyed on iValue
1.692 + SEntry *pE=new SEntry[aCount];
1.693 + SEntry *pF=new SEntry[aCount];
1.694 + if (!pE || !pF)
1.695 + {
1.696 + a.Close();
1.697 + b.Close();
1.698 + return -65535;
1.699 + }
1.700 + TInt i=0;
1.701 + for(i=0; i<aCount; i++)
1.702 + {
1.703 + pE[i].iKey=i*19;
1.704 + pE[i].iValue=Random();
1.705 + a.Append(pE[i]);
1.706 + pF[i].iKey=Random();
1.707 + pF[i].iValue=i*i;
1.708 + b.Append(pF[i]);
1.709 + }
1.710 + if (a.Count()!=aCount)
1.711 + {
1.712 + a.Close();
1.713 + b.Close();
1.714 + return -1;
1.715 + }
1.716 + if (b.Count()!=aCount)
1.717 + {
1.718 + a.Close();
1.719 + b.Close();
1.720 + return -2;
1.721 + }
1.722 + for (i=0; i<aCount; i++)
1.723 + {
1.724 + TInt r=a.FindInSignedKeyOrder(pE[i]);
1.725 + if (r!=i)
1.726 + {
1.727 + a.Close();
1.728 + b.Close();
1.729 + return -2;
1.730 + }
1.731 + r=b.FindInSignedKeyOrder(pF[i]);
1.732 + if (r!=i)
1.733 + {
1.734 + a.Close();
1.735 + b.Close();
1.736 + return -3;
1.737 + }
1.738 + TInt x=Random()&1023;
1.739 + SEntry e;
1.740 + e.iKey=x;
1.741 + r=a.FindInSignedKeyOrder(e);
1.742 + if (r<0)
1.743 + {
1.744 + if (x%19==0)
1.745 + {
1.746 + a.Close();
1.747 + b.Close();
1.748 + return -4;
1.749 + }
1.750 + }
1.751 + else if (x!=r*19)
1.752 + {
1.753 + a.Close();
1.754 + b.Close();
1.755 + return -5;
1.756 + }
1.757 + TInt z=8+(Random()&127);
1.758 + TInt y=Random()&15;
1.759 + x=z*z+y;
1.760 + e.iKey=-2;
1.761 + e.iValue=x;
1.762 + r=b.FindInSignedKeyOrder(e);
1.763 + if (r<0)
1.764 + {
1.765 + if (y==0 && z<aCount)
1.766 + {
1.767 + a.Close();
1.768 + b.Close();
1.769 + return -6;
1.770 + }
1.771 + }
1.772 + else if (y!=0)
1.773 + {
1.774 + a.Close();
1.775 + b.Close();
1.776 + return -7;
1.777 + }
1.778 + }
1.779 + delete[] pE;
1.780 + delete[] pF;
1.781 + a.Close();
1.782 + b.Close();
1.783 + }
1.784 + return KErrNone;
1.785 + }
1.786 +
1.787 +LOCAL_C TInt IntInsertInOrderTest(TInt aCount, TInt aNumTests, TInt64 aMask)
1.788 + {
1.789 + TInt n;
1.790 + for (n=0; n<aNumTests; n++)
1.791 + {
1.792 + RArray<TInt64> a(aCount);
1.793 + RArray<TInt64> b(aCount);
1.794 + RArray<TInt64> c(aCount);
1.795 + TInt i;
1.796 + TInt cc=0;
1.797 + for (i=0; i<aCount; i++)
1.798 + {
1.799 + TInt64 x=Random64(aMask);
1.800 + a.Append(x);
1.801 + b.InsertInOrderAllowRepeats(x,Int64Order);
1.802 + TInt r=c.InsertInOrder(x,Int64Order);
1.803 + if (r==KErrNone)
1.804 + cc++;
1.805 + }
1.806 + if (a.Count()!=aCount)
1.807 + {
1.808 + a.Close();
1.809 + b.Close();
1.810 + c.Close();
1.811 + return -1;
1.812 + }
1.813 + if (b.Count()!=aCount)
1.814 + {
1.815 + a.Close();
1.816 + b.Close();
1.817 + c.Close();
1.818 + return -2;
1.819 + }
1.820 + for (i=0; i<aCount-1; i++)
1.821 + {
1.822 + if (b[i]>b[i+1])
1.823 + {
1.824 + a.Close();
1.825 + b.Close();
1.826 + c.Close();
1.827 + return -3;
1.828 + }
1.829 + }
1.830 + for (i=0; i<aCount; i++)
1.831 + {
1.832 + if (a.Find(b[i],Int64Identity)<0)
1.833 + {
1.834 + a.Close();
1.835 + b.Close();
1.836 + c.Close();
1.837 + return -4;
1.838 + }
1.839 + if (b.Find(a[i],Int64Identity)<0)
1.840 + {
1.841 + a.Close();
1.842 + b.Close();
1.843 + c.Close();
1.844 + return -5;
1.845 + }
1.846 + if (c.Find(a[i],Int64Identity)<0)
1.847 + {
1.848 + a.Close();
1.849 + b.Close();
1.850 + c.Close();
1.851 + return -6;
1.852 + }
1.853 + }
1.854 + if (c.Count()!=cc)
1.855 + {
1.856 + a.Close();
1.857 + b.Close();
1.858 + c.Close();
1.859 + return -7;
1.860 + }
1.861 + for (i=0; i<c.Count()-1; i++)
1.862 + {
1.863 + if (c[i]>=c[i+1])
1.864 + {
1.865 + a.Close();
1.866 + b.Close();
1.867 + c.Close();
1.868 + return -8;
1.869 + }
1.870 + if (a.Find(c[i],Int64Identity)<0)
1.871 + {
1.872 + a.Close();
1.873 + b.Close();
1.874 + c.Close();
1.875 + return -9;
1.876 + }
1.877 + }
1.878 + a.Close();
1.879 + b.Close();
1.880 + c.Close();
1.881 + }
1.882 + return KErrNone;
1.883 + }
1.884 +
1.885 +LOCAL_C TInt EntryInsertInOrderTest()
1.886 + {
1.887 + RArray<SEntry> a1(1024,0); // keyed on iKey
1.888 + RArray<SEntry> a2(1024,0); // keyed on iKey
1.889 + RArray<SEntry> b1(1024,4); // keyed on iValue
1.890 + RArray<SEntry> b2(1024,4); // keyed on iValue
1.891 + RArray<SEntry> c1(1024,0); // keyed on iKey
1.892 + RArray<SEntry> c2(1024,0); // keyed on iKey
1.893 + RArray<SEntry> d1(1024,4); // keyed on iValue
1.894 + RArray<SEntry> d2(1024,4); // keyed on iValue
1.895 + TInt i;
1.896 + for (i=0; i<1024; i++)
1.897 + {
1.898 + SEntry e;
1.899 + e.iValue=i-512;
1.900 + e.iKey=(i&31)-16;
1.901 + a1.InsertInSignedKeyOrderAllowRepeats(e);
1.902 + a2.InsertInSignedKeyOrder(e);
1.903 + b1.InsertInSignedKeyOrderAllowRepeats(e);
1.904 + b2.InsertInSignedKeyOrder(e);
1.905 + c1.InsertInUnsignedKeyOrderAllowRepeats(e);
1.906 + c2.InsertInUnsignedKeyOrder(e);
1.907 + d1.InsertInUnsignedKeyOrderAllowRepeats(e);
1.908 + d2.InsertInUnsignedKeyOrder(e);
1.909 + }
1.910 + if (a1.Count()!=1024)
1.911 + {
1.912 + a1.Close();
1.913 + a2.Close();
1.914 + b1.Close();
1.915 + b2.Close();
1.916 + c1.Close();
1.917 + c2.Close();
1.918 + d1.Close();
1.919 + d2.Close();
1.920 + return -1;
1.921 + }
1.922 + if (b1.Count()!=1024)
1.923 + {
1.924 + a1.Close();
1.925 + a2.Close();
1.926 + b1.Close();
1.927 + b2.Close();
1.928 + c1.Close();
1.929 + c2.Close();
1.930 + d1.Close();
1.931 + d2.Close();
1.932 + return -2;
1.933 + }
1.934 + if (c1.Count()!=1024)
1.935 + {
1.936 + a1.Close();
1.937 + a2.Close();
1.938 + b1.Close();
1.939 + b2.Close();
1.940 + c1.Close();
1.941 + c2.Close();
1.942 + d1.Close();
1.943 + d2.Close();
1.944 + return -3;
1.945 + }
1.946 + if (d1.Count()!=1024)
1.947 + {
1.948 + a1.Close();
1.949 + a2.Close();
1.950 + b1.Close();
1.951 + b2.Close();
1.952 + c1.Close();
1.953 + c2.Close();
1.954 + d1.Close();
1.955 + d2.Close();
1.956 + return -4;
1.957 + }
1.958 + for (i=0; i<1024; i++)
1.959 + {
1.960 + SEntry e=a1[i];
1.961 + if (e.iKey!=(i>>5)-16)
1.962 + {
1.963 + a1.Close();
1.964 + a2.Close();
1.965 + b1.Close();
1.966 + b2.Close();
1.967 + c1.Close();
1.968 + c2.Close();
1.969 + d1.Close();
1.970 + d2.Close();
1.971 + return -5;
1.972 + }
1.973 + if ( e.iValue!=(((i&31)<<5 | (i>>5))-512) )
1.974 + {
1.975 + a1.Close();
1.976 + a2.Close();
1.977 + b1.Close();
1.978 + b2.Close();
1.979 + c1.Close();
1.980 + c2.Close();
1.981 + d1.Close();
1.982 + d2.Close();
1.983 + return -6;
1.984 + }
1.985 + e=b1[i];
1.986 + if (e.iKey!=((i&31)-16))
1.987 + {
1.988 + a1.Close();
1.989 + a2.Close();
1.990 + b1.Close();
1.991 + b2.Close();
1.992 + c1.Close();
1.993 + c2.Close();
1.994 + d1.Close();
1.995 + d2.Close();
1.996 + return -7;
1.997 + }
1.998 + if ( e.iValue!=(i-512) )
1.999 + {
1.1000 + a1.Close();
1.1001 + a2.Close();
1.1002 + b1.Close();
1.1003 + b2.Close();
1.1004 + c1.Close();
1.1005 + c2.Close();
1.1006 + d1.Close();
1.1007 + d2.Close();
1.1008 + return -8;
1.1009 + }
1.1010 + e=c1[i];
1.1011 + TInt j=i>>5;
1.1012 + j^=16;
1.1013 + j=((i&31)<<5)|j;
1.1014 + SEntry f;
1.1015 + f.iValue=j-512;
1.1016 + f.iKey=(j&31)-16;
1.1017 + if (e.iKey!=f.iKey)
1.1018 + {
1.1019 + a1.Close();
1.1020 + a2.Close();
1.1021 + b1.Close();
1.1022 + b2.Close();
1.1023 + c1.Close();
1.1024 + c2.Close();
1.1025 + d1.Close();
1.1026 + d2.Close();
1.1027 + return -9;
1.1028 + }
1.1029 + if (e.iValue!=f.iValue)
1.1030 + {
1.1031 + a1.Close();
1.1032 + a2.Close();
1.1033 + b1.Close();
1.1034 + b2.Close();
1.1035 + c1.Close();
1.1036 + c2.Close();
1.1037 + d1.Close();
1.1038 + d2.Close();
1.1039 + return -10;
1.1040 + }
1.1041 + e=d1[i];
1.1042 + j=i^512;
1.1043 + f.iValue=j-512;
1.1044 + f.iKey=(j&31)-16;
1.1045 + if (e.iKey!=f.iKey)
1.1046 + {
1.1047 + a1.Close();
1.1048 + a2.Close();
1.1049 + b1.Close();
1.1050 + b2.Close();
1.1051 + c1.Close();
1.1052 + c2.Close();
1.1053 + d1.Close();
1.1054 + d2.Close();
1.1055 + return -11;
1.1056 + }
1.1057 + if (e.iValue!=f.iValue)
1.1058 + {
1.1059 + a1.Close();
1.1060 + a2.Close();
1.1061 + b1.Close();
1.1062 + b2.Close();
1.1063 + c1.Close();
1.1064 + c2.Close();
1.1065 + d1.Close();
1.1066 + d2.Close();
1.1067 + return -12;
1.1068 + }
1.1069 + }
1.1070 + if (a2.Count()!=32)
1.1071 + {
1.1072 + a1.Close();
1.1073 + a2.Close();
1.1074 + b1.Close();
1.1075 + b2.Close();
1.1076 + c1.Close();
1.1077 + c2.Close();
1.1078 + d1.Close();
1.1079 + d2.Close();
1.1080 + return -13;
1.1081 + }
1.1082 + if (b2.Count()!=1024)
1.1083 + {
1.1084 + a1.Close();
1.1085 + a2.Close();
1.1086 + b1.Close();
1.1087 + b2.Close();
1.1088 + c1.Close();
1.1089 + c2.Close();
1.1090 + d1.Close();
1.1091 + d2.Close();
1.1092 + return -14;
1.1093 + }
1.1094 + if (c2.Count()!=32)
1.1095 + {
1.1096 + a1.Close();
1.1097 + a2.Close();
1.1098 + b1.Close();
1.1099 + b2.Close();
1.1100 + c1.Close();
1.1101 + c2.Close();
1.1102 + d1.Close();
1.1103 + d2.Close();
1.1104 + return -15;
1.1105 + }
1.1106 + if (d2.Count()!=1024)
1.1107 + {
1.1108 + a1.Close();
1.1109 + a2.Close();
1.1110 + b1.Close();
1.1111 + b2.Close();
1.1112 + c1.Close();
1.1113 + c2.Close();
1.1114 + d1.Close();
1.1115 + d2.Close();
1.1116 + return -16;
1.1117 + }
1.1118 + for (i=0; i<1024; i++)
1.1119 + {
1.1120 + SEntry e=b2[i];
1.1121 + if (e.iKey!=((i&31)-16))
1.1122 + {
1.1123 + a1.Close();
1.1124 + a2.Close();
1.1125 + b1.Close();
1.1126 + b2.Close();
1.1127 + c1.Close();
1.1128 + c2.Close();
1.1129 + d1.Close();
1.1130 + d2.Close();
1.1131 + return -17;
1.1132 + }
1.1133 + if ( e.iValue!=(i-512) )
1.1134 + {
1.1135 + a1.Close();
1.1136 + a2.Close();
1.1137 + b1.Close();
1.1138 + b2.Close();
1.1139 + c1.Close();
1.1140 + c2.Close();
1.1141 + d1.Close();
1.1142 + d2.Close();
1.1143 + return -18;
1.1144 + }
1.1145 + e=d2[i];
1.1146 + TInt j=i^512;
1.1147 + SEntry f;
1.1148 + f.iValue=j-512;
1.1149 + f.iKey=(j&31)-16;
1.1150 + if (e.iKey!=f.iKey)
1.1151 + {
1.1152 + a1.Close();
1.1153 + a2.Close();
1.1154 + b1.Close();
1.1155 + b2.Close();
1.1156 + c1.Close();
1.1157 + c2.Close();
1.1158 + d1.Close();
1.1159 + d2.Close();
1.1160 + return -19;
1.1161 + }
1.1162 + if (e.iValue!=f.iValue)
1.1163 + {
1.1164 + a1.Close();
1.1165 + a2.Close();
1.1166 + b1.Close();
1.1167 + b2.Close();
1.1168 + c1.Close();
1.1169 + c2.Close();
1.1170 + d1.Close();
1.1171 + d2.Close();
1.1172 + return -20;
1.1173 + }
1.1174 + }
1.1175 + for (i=0; i<31; i++)
1.1176 + {
1.1177 + SEntry e=a2[i];
1.1178 + TInt j=i;
1.1179 + SEntry f;
1.1180 + f.iValue=j-512;
1.1181 + f.iKey=(j&31)-16;
1.1182 + if (e.iKey!=f.iKey)
1.1183 + {
1.1184 + a1.Close();
1.1185 + a2.Close();
1.1186 + b1.Close();
1.1187 + b2.Close();
1.1188 + c1.Close();
1.1189 + c2.Close();
1.1190 + d1.Close();
1.1191 + d2.Close();
1.1192 + return -21;
1.1193 + }
1.1194 + if (e.iValue!=f.iValue)
1.1195 + {
1.1196 + a1.Close();
1.1197 + a2.Close();
1.1198 + b1.Close();
1.1199 + b2.Close();
1.1200 + c1.Close();
1.1201 + c2.Close();
1.1202 + d1.Close();
1.1203 + d2.Close();
1.1204 + return -22;
1.1205 + }
1.1206 + e=c2[i];
1.1207 + j=i^16;
1.1208 + f.iValue=j-512;
1.1209 + f.iKey=(j&31)-16;
1.1210 + if (e.iKey!=f.iKey)
1.1211 + {
1.1212 + a1.Close();
1.1213 + a2.Close();
1.1214 + b1.Close();
1.1215 + b2.Close();
1.1216 + c1.Close();
1.1217 + c2.Close();
1.1218 + d1.Close();
1.1219 + d2.Close();
1.1220 + return -23;
1.1221 + }
1.1222 + if (e.iValue!=f.iValue)
1.1223 + {
1.1224 + a1.Close();
1.1225 + a2.Close();
1.1226 + b1.Close();
1.1227 + b2.Close();
1.1228 + c1.Close();
1.1229 + c2.Close();
1.1230 + d1.Close();
1.1231 + d2.Close();
1.1232 + return -24;
1.1233 + }
1.1234 + }
1.1235 + a1.Close();
1.1236 + a2.Close();
1.1237 + b1.Close();
1.1238 + b2.Close();
1.1239 + c1.Close();
1.1240 + c2.Close();
1.1241 + d1.Close();
1.1242 + d2.Close();
1.1243 + return KErrNone;
1.1244 + }
1.1245 +
1.1246 +LOCAL_C TInt IntSortTest(TInt aCount, TInt aNumTests, TInt64 aMask)
1.1247 + {
1.1248 + TInt n;
1.1249 + for (n=0; n<aNumTests; n++)
1.1250 + {
1.1251 + RArray<TInt64> a(aCount);
1.1252 + RArray<TInt64> b(aCount);
1.1253 + TInt i;
1.1254 + for (i=0; i<aCount; i++)
1.1255 + {
1.1256 + TInt64 x=Random64(aMask);
1.1257 + a.Append(x);
1.1258 + b.InsertInOrderAllowRepeats(x,Int64Order);
1.1259 + }
1.1260 + a.Sort(Int64Order);
1.1261 + if (a.Count()!=aCount)
1.1262 + {
1.1263 + a.Close();
1.1264 + b.Close();
1.1265 + return -1;
1.1266 + }
1.1267 + if (b.Count()!=aCount)
1.1268 + {
1.1269 + a.Close();
1.1270 + b.Close();
1.1271 + return -2;
1.1272 + }
1.1273 + for (i=0; i<aCount; i++)
1.1274 + {
1.1275 + if (a[i]!=b[i])
1.1276 + {
1.1277 + a.Close();
1.1278 + b.Close();
1.1279 + return -3;
1.1280 + }
1.1281 + }
1.1282 + a.Close();
1.1283 + b.Close();
1.1284 + }
1.1285 + return KErrNone;
1.1286 + }
1.1287 +
1.1288 +LOCAL_C TInt EntrySortTest(TInt aCount, TInt aNumTests)
1.1289 + {
1.1290 + TInt n;
1.1291 + for (n=0; n<aNumTests; n++)
1.1292 + {
1.1293 + RArray<SEntry> a1(aCount,0); // keyed on iKey
1.1294 + RArray<SEntry> a2(aCount,0); // keyed on iKey
1.1295 + RArray<SEntry> b1(aCount,4); // keyed on iValue
1.1296 + RArray<SEntry> b2(aCount,4); // keyed on iValue
1.1297 + RArray<SEntry> c1(aCount,0); // keyed on iKey
1.1298 + RArray<SEntry> c2(aCount,0); // keyed on iKey
1.1299 + RArray<SEntry> d1(aCount,4); // keyed on iValue
1.1300 + RArray<SEntry> d2(aCount,4); // keyed on iValue
1.1301 + TInt i;
1.1302 + for (i=0; i<aCount; i++)
1.1303 + {
1.1304 + SEntry e;
1.1305 + e.iKey=Random();
1.1306 + e.iValue=Random();
1.1307 + a1.Append(e);
1.1308 + a2.InsertInSignedKeyOrderAllowRepeats(e);
1.1309 + b1.Append(e);
1.1310 + b2.InsertInSignedKeyOrderAllowRepeats(e);
1.1311 + c1.Append(e);
1.1312 + c2.InsertInUnsignedKeyOrderAllowRepeats(e);
1.1313 + d1.Append(e);
1.1314 + d2.InsertInUnsignedKeyOrderAllowRepeats(e);
1.1315 + }
1.1316 + a1.SortSigned();
1.1317 + b1.SortSigned();
1.1318 + c1.SortUnsigned();
1.1319 + d1.SortUnsigned();
1.1320 + if (a1.Count()!=aCount)
1.1321 + {
1.1322 + a1.Close();
1.1323 + a2.Close();
1.1324 + b1.Close();
1.1325 + b2.Close();
1.1326 + c1.Close();
1.1327 + c2.Close();
1.1328 + d1.Close();
1.1329 + d2.Close();
1.1330 + return -1;
1.1331 + }
1.1332 + if (a2.Count()!=aCount)
1.1333 + {
1.1334 + a1.Close();
1.1335 + a2.Close();
1.1336 + b1.Close();
1.1337 + b2.Close();
1.1338 + c1.Close();
1.1339 + c2.Close();
1.1340 + d1.Close();
1.1341 + d2.Close();
1.1342 + return -2;
1.1343 + }
1.1344 + if (b1.Count()!=aCount)
1.1345 + {
1.1346 + a1.Close();
1.1347 + a2.Close();
1.1348 + b1.Close();
1.1349 + b2.Close();
1.1350 + c1.Close();
1.1351 + c2.Close();
1.1352 + d1.Close();
1.1353 + d2.Close();
1.1354 + return -3;
1.1355 + }
1.1356 + if (b2.Count()!=aCount)
1.1357 + {
1.1358 + a1.Close();
1.1359 + a2.Close();
1.1360 + b1.Close();
1.1361 + b2.Close();
1.1362 + c1.Close();
1.1363 + c2.Close();
1.1364 + d1.Close();
1.1365 + d2.Close();
1.1366 + return -4;
1.1367 + }
1.1368 + if (c1.Count()!=aCount)
1.1369 + {
1.1370 + a1.Close();
1.1371 + a2.Close();
1.1372 + b1.Close();
1.1373 + b2.Close();
1.1374 + c1.Close();
1.1375 + c2.Close();
1.1376 + d1.Close();
1.1377 + d2.Close();
1.1378 + return -5;
1.1379 + }
1.1380 + if (c2.Count()!=aCount)
1.1381 + {
1.1382 + a1.Close();
1.1383 + a2.Close();
1.1384 + b1.Close();
1.1385 + b2.Close();
1.1386 + c1.Close();
1.1387 + c2.Close();
1.1388 + d1.Close();
1.1389 + d2.Close();
1.1390 + return -6;
1.1391 + }
1.1392 + if (d1.Count()!=aCount)
1.1393 + {
1.1394 + a1.Close();
1.1395 + a2.Close();
1.1396 + b1.Close();
1.1397 + b2.Close();
1.1398 + c1.Close();
1.1399 + c2.Close();
1.1400 + d1.Close();
1.1401 + d2.Close();
1.1402 + return -7;
1.1403 + }
1.1404 + if (d2.Count()!=aCount)
1.1405 + {
1.1406 + a1.Close();
1.1407 + a2.Close();
1.1408 + b1.Close();
1.1409 + b2.Close();
1.1410 + c1.Close();
1.1411 + c2.Close();
1.1412 + d1.Close();
1.1413 + d2.Close();
1.1414 + return -8;
1.1415 + }
1.1416 + for (i=0; i<aCount; i++)
1.1417 + {
1.1418 + if (a1[i]!=a2[i])
1.1419 + {
1.1420 + a1.Close();
1.1421 + a2.Close();
1.1422 + b1.Close();
1.1423 + b2.Close();
1.1424 + c1.Close();
1.1425 + c2.Close();
1.1426 + d1.Close();
1.1427 + d2.Close();
1.1428 + return -9;
1.1429 + }
1.1430 + if (b1[i]!=b2[i])
1.1431 + {
1.1432 + a1.Close();
1.1433 + a2.Close();
1.1434 + b1.Close();
1.1435 + b2.Close();
1.1436 + c1.Close();
1.1437 + c2.Close();
1.1438 + d1.Close();
1.1439 + d2.Close();
1.1440 + return -10;
1.1441 + }
1.1442 + if (c1[i]!=c2[i])
1.1443 + {
1.1444 + a1.Close();
1.1445 + a2.Close();
1.1446 + b1.Close();
1.1447 + b2.Close();
1.1448 + c1.Close();
1.1449 + c2.Close();
1.1450 + d1.Close();
1.1451 + d2.Close();
1.1452 + return -11;
1.1453 + }
1.1454 + if (d1[i]!=d2[i])
1.1455 + {
1.1456 + a1.Close();
1.1457 + a2.Close();
1.1458 + b1.Close();
1.1459 + b2.Close();
1.1460 + c1.Close();
1.1461 + c2.Close();
1.1462 + d1.Close();
1.1463 + d2.Close();
1.1464 + return -12;
1.1465 + }
1.1466 + }
1.1467 + a1.Close();
1.1468 + a2.Close();
1.1469 + b1.Close();
1.1470 + b2.Close();
1.1471 + c1.Close();
1.1472 + c2.Close();
1.1473 + d1.Close();
1.1474 + d2.Close();
1.1475 + }
1.1476 + return KErrNone;
1.1477 + }
1.1478 +
1.1479 +LOCAL_C TInt SortAccessBoundsTest(TInt aCount)
1.1480 + {
1.1481 + TInt bytes = aCount * sizeof(TInt);
1.1482 + RChunk chunk;
1.1483 + TInt r = chunk.CreateDoubleEndedLocal(4096, bytes + 4096, bytes + 8192);
1.1484 + if (r != KErrNone)
1.1485 + return r;
1.1486 + TInt size = chunk.Size() / sizeof(TInt); // Now rounded up to page boundary
1.1487 + TInt* data = (TInt*)(chunk.Base() + chunk.Bottom());
1.1488 +
1.1489 + TInt i, j;
1.1490 +
1.1491 + for (i = 1 ; i < aCount ; ++i)
1.1492 + {
1.1493 + for (j = 0 ; j < i ; ++j)
1.1494 + data[j] = Random();
1.1495 + RArray<TInt> a(data, i);
1.1496 + a.Sort();
1.1497 +
1.1498 + for (j = 0 ; j < i ; ++j)
1.1499 + data[j] = Random();
1.1500 + RArray<TUint> b((TUint*)data, i);
1.1501 + b.Sort();
1.1502 +
1.1503 + if (i % 2 == 0)
1.1504 + {
1.1505 + RArray<SEntry> c(sizeof(SEntry), (SEntry*)data, i / 2);
1.1506 +
1.1507 + for (j = 0 ; j < i ; ++j)
1.1508 + data[j] = Random();
1.1509 + c.SortSigned();
1.1510 +
1.1511 + for (j = 0 ; j < i ; ++j)
1.1512 + data[j] = Random();
1.1513 + c.SortUnsigned();
1.1514 + }
1.1515 + }
1.1516 +
1.1517 + for (i = 1 ; i < aCount ; ++i)
1.1518 + {
1.1519 + for (j = 0 ; j < i ; ++j)
1.1520 + data[size - j - 1] = Random();
1.1521 + RArray<TInt> a(data + size - i, i);
1.1522 + a.Sort();
1.1523 +
1.1524 + for (j = 0 ; j < i ; ++j)
1.1525 + data[size - j - 1] = Random();
1.1526 + RArray<TUint> b((TUint*)(data + size - i), i);
1.1527 + b.Sort();
1.1528 +
1.1529 + if (i % 2 == 0)
1.1530 + {
1.1531 + RArray<SEntry> c(sizeof(SEntry), (SEntry*)(data + size - i), i / 2);
1.1532 +
1.1533 + for (j = 0 ; j < i ; ++j)
1.1534 + data[size - j - 1] = Random();
1.1535 + c.SortSigned();
1.1536 +
1.1537 + for (j = 0 ; j < i ; ++j)
1.1538 + data[size - j - 1] = Random();
1.1539 + c.SortUnsigned();
1.1540 + }
1.1541 + }
1.1542 +
1.1543 + chunk.Close();
1.1544 + return KErrNone;
1.1545 + }
1.1546 +
1.1547 +LOCAL_C TInt SEntrySpecificFindTests(TInt aCount, TInt aNumTests, TInt aRange)
1.1548 + {
1.1549 + TInt n;
1.1550 + TInt nmiss = 0;
1.1551 + TInt nrpt = 0;
1.1552 + TInt ntot = 0;
1.1553 + for (n=0; n<aNumTests; n++)
1.1554 + {
1.1555 + RArray<SEntry> a;
1.1556 + RArray<SEntry> b;
1.1557 + RArray<SEntry> c;
1.1558 + RArray<SEntry> d;
1.1559 + TInt i;
1.1560 + for (i=0; i<aCount; i++)
1.1561 + {
1.1562 + TInt x=Random()&aRange;
1.1563 + x-=(aRange>>1);
1.1564 + SEntry e;
1.1565 + e.iKey = x;
1.1566 + e.iValue = i;
1.1567 + a.Append(e);
1.1568 + c.Append(e);
1.1569 + b.InsertInSignedKeyOrderAllowRepeats(e);
1.1570 + d.InsertInUnsignedKeyOrderAllowRepeats(e);
1.1571 + }
1.1572 + a.Sort(&OrderSEntry2);
1.1573 + c.Sort(&OrderSEntryU2);
1.1574 + test(a.Count()==aCount);
1.1575 + test(b.Count()==aCount);
1.1576 + test(c.Count()==aCount);
1.1577 + test(d.Count()==aCount);
1.1578 + for (i=0; i<aCount; i++)
1.1579 + {
1.1580 + test(a[i]==b[i]);
1.1581 + test(c[i]==d[i]);
1.1582 + }
1.1583 + for (i=-(aRange>>1); i<=(aRange>>1); ++i)
1.1584 + {
1.1585 + SEntry es;
1.1586 + es.iKey = i;
1.1587 + TInt fk = a.SpecificFindInSignedKeyOrder(es, EArrayFindMode_First);
1.1588 + TInt lk = a.SpecificFindInSignedKeyOrder(es, EArrayFindMode_Last);
1.1589 + TInt ak = a.SpecificFindInSignedKeyOrder(es, EArrayFindMode_Any);
1.1590 + TInt fki, lki, aki;
1.1591 + TInt fk2 = a.SpecificFindInSignedKeyOrder(es, fki, EArrayFindMode_First);
1.1592 + TInt lk2 = a.SpecificFindInSignedKeyOrder(es, lki, EArrayFindMode_Last);
1.1593 + TInt ak2 = a.SpecificFindInSignedKeyOrder(es, aki, EArrayFindMode_Any);
1.1594 +
1.1595 + TInt first = a.SpecificFindInOrder(es, &OrderSEntry, EArrayFindMode_First);
1.1596 + TInt last = a.SpecificFindInOrder(es, &OrderSEntry, EArrayFindMode_Last);
1.1597 + TInt any = a.SpecificFindInOrder(es, &OrderSEntry, EArrayFindMode_Any);
1.1598 + TInt fi, li, ai;
1.1599 + TInt first2 = a.SpecificFindInOrder(es, fi, &OrderSEntry, EArrayFindMode_First);
1.1600 + TInt last2 = a.SpecificFindInOrder(es, li, &OrderSEntry, EArrayFindMode_Last);
1.1601 + TInt any2 = a.SpecificFindInOrder(es, ai, &OrderSEntry, EArrayFindMode_Any);
1.1602 + ++ntot;
1.1603 + test(first == fk);
1.1604 + test(last == lk);
1.1605 + test(any == ak);
1.1606 + test(first2 == fk2);
1.1607 + test(last2 == lk2);
1.1608 + test(any2 == ak2);
1.1609 + test(fki == fi);
1.1610 + test(lki == li);
1.1611 + test(aki == ai);
1.1612 + if (first < 0)
1.1613 + {
1.1614 + test(first == KErrNotFound);
1.1615 + test(first == last);
1.1616 + test(first == any);
1.1617 + test(first == first2);
1.1618 + test(first == last2);
1.1619 + test(first == any2);
1.1620 + test(fi == li);
1.1621 + test(fi == ai);
1.1622 + test(li==aCount || a[li].iKey>i);
1.1623 + test(li==0 || a[li-1].iKey<i);
1.1624 + ++nmiss;
1.1625 + }
1.1626 + else
1.1627 + {
1.1628 + test(first2 == KErrNone);
1.1629 + test(last2 == KErrNone);
1.1630 + test(any2 == KErrNone);
1.1631 + test(first == fi);
1.1632 + test(last == li);
1.1633 + test(any == ai);
1.1634 + test(a[fi].iKey == i);
1.1635 + test(a[li-1].iKey == i);
1.1636 + test(li==aCount || a[li].iKey>i);
1.1637 + test(ai>=fi && ai<li);
1.1638 + test(a[ai].iKey == i);
1.1639 + if (li-fi > 1)
1.1640 + {
1.1641 + ++nrpt;
1.1642 + TInt j;
1.1643 + for (j=fi+1; j<li; ++j)
1.1644 + test(a[j].iValue > a[j-1].iValue);
1.1645 + }
1.1646 + }
1.1647 + }
1.1648 + for (i=-(aRange>>1); i<=(aRange>>1); ++i)
1.1649 + {
1.1650 + TUint u = (TUint)i;
1.1651 + SEntry eu;
1.1652 + eu.iKey = i;
1.1653 + TInt fk = c.SpecificFindInUnsignedKeyOrder(eu, EArrayFindMode_First);
1.1654 + TInt lk = c.SpecificFindInUnsignedKeyOrder(eu, EArrayFindMode_Last);
1.1655 + TInt ak = c.SpecificFindInUnsignedKeyOrder(eu, EArrayFindMode_Any);
1.1656 + TInt fki, lki, aki;
1.1657 + TInt fk2 = c.SpecificFindInUnsignedKeyOrder(eu, fki, EArrayFindMode_First);
1.1658 + TInt lk2 = c.SpecificFindInUnsignedKeyOrder(eu, lki, EArrayFindMode_Last);
1.1659 + TInt ak2 = c.SpecificFindInUnsignedKeyOrder(eu, aki, EArrayFindMode_Any);
1.1660 +
1.1661 + TInt first = c.SpecificFindInOrder(eu, &OrderSEntryU, EArrayFindMode_First);
1.1662 + TInt last = c.SpecificFindInOrder(eu, &OrderSEntryU, EArrayFindMode_Last);
1.1663 + TInt any = c.SpecificFindInOrder(eu, &OrderSEntryU, EArrayFindMode_Any);
1.1664 + TInt fi, li, ai;
1.1665 + TInt first2 = c.SpecificFindInOrder(eu, fi, &OrderSEntryU, EArrayFindMode_First);
1.1666 + TInt last2 = c.SpecificFindInOrder(eu, li, &OrderSEntryU, EArrayFindMode_Last);
1.1667 + TInt any2 = c.SpecificFindInOrder(eu, ai, &OrderSEntryU, EArrayFindMode_Any);
1.1668 + ++ntot;
1.1669 + test(first == fk);
1.1670 + test(last == lk);
1.1671 + test(any == ak);
1.1672 + test(first2 == fk2);
1.1673 + test(last2 == lk2);
1.1674 + test(any2 == ak2);
1.1675 + test(fki == fi);
1.1676 + test(lki == li);
1.1677 + test(aki == ai);
1.1678 + if (first < 0)
1.1679 + {
1.1680 + test(first == KErrNotFound);
1.1681 + test(first == last);
1.1682 + test(first == any);
1.1683 + test(first == first2);
1.1684 + test(first == last2);
1.1685 + test(first == any2);
1.1686 + test(fi == li);
1.1687 + test(fi == ai);
1.1688 + test(li==aCount || TUint(c[li].iKey)>u);
1.1689 + test(li==0 || TUint(c[li-1].iKey)<u);
1.1690 + ++nmiss;
1.1691 + }
1.1692 + else
1.1693 + {
1.1694 + test(first2 == KErrNone);
1.1695 + test(last2 == KErrNone);
1.1696 + test(any2 == KErrNone);
1.1697 + test(first == fi);
1.1698 + test(last == li);
1.1699 + test(any == ai);
1.1700 + test(c[fi].iKey == i);
1.1701 + test(c[li-1].iKey == i);
1.1702 + test(li==aCount || TUint(c[li].iKey)>u);
1.1703 + test(ai>=fi && ai<li);
1.1704 + test(c[ai].iKey == i);
1.1705 + if (li-fi > 1)
1.1706 + {
1.1707 + ++nrpt;
1.1708 + TInt j;
1.1709 + for (j=fi+1; j<li; ++j)
1.1710 + test(c[j].iValue > c[j-1].iValue);
1.1711 + }
1.1712 + }
1.1713 + }
1.1714 + a.Close();
1.1715 + b.Close();
1.1716 + c.Close();
1.1717 + d.Close();
1.1718 + }
1.1719 + test.Printf(_L("ntot=%d nmiss=%d nrpt=%d\n"), ntot, nmiss, nrpt);
1.1720 + return KErrNone;
1.1721 + }
1.1722 +
1.1723 +LOCAL_C void TestGrowCompress(RArray<TInt64>* a, ...)
1.1724 + {
1.1725 + SArray& pa = *(SArray*)a;
1.1726 + VA_LIST list;
1.1727 + VA_START(list, a);
1.1728 + TInt64 x;
1.1729 + FOREVER
1.1730 + {
1.1731 + TInt r = KErrNone;
1.1732 + TInt action = VA_ARG(list, TInt);
1.1733 + if (action == -99)
1.1734 + break;
1.1735 + TInt result = VA_ARG(list, TInt);
1.1736 + TInt orig = pa.iAllocated;
1.1737 + if (action == -1)
1.1738 + a->Compress();
1.1739 + else if (action == -2)
1.1740 + a->GranularCompress();
1.1741 + else if (action == -3)
1.1742 + a->Remove(pa.iCount - 1);
1.1743 + else if (action > 0)
1.1744 + {
1.1745 + TInt i;
1.1746 + for (i=0; i<action && r==KErrNone; ++i)
1.1747 + r = a->Append(x);
1.1748 + }
1.1749 + if ( (r<0 && (result!=r || pa.iAllocated!=orig)) || (r==0 && pa.iAllocated!=result) )
1.1750 + {
1.1751 + test.Printf(_L("Action %d Orig %d Expected %d r=%d newalloc=%d\n"), action, orig, result, r, pa.iAllocated);
1.1752 + test(0);
1.1753 + }
1.1754 + }
1.1755 + a->Reset();
1.1756 + }
1.1757 +
1.1758 +LOCAL_C void TestGrowCompress()
1.1759 + {
1.1760 + RArray<TInt64> a;
1.1761 + TestGrowCompress(&a, 1, 8, 7, 8, 1, 16, 7, 16, 1, 24, -2, 24, -1, 17, 1, 25, -2, 25, -3, 25, -2, 24, -99);
1.1762 + TestGrowCompress(&a, 1, 8, 7, 8, 1, 16, 7, 16, 1, 24, -2, 24, -1, 17, 1, 25, -2, 25, -3, 25, -3, 25, -2, 16, -99);
1.1763 +
1.1764 + RArray<TInt64> b(100);
1.1765 + TestGrowCompress(&b, 1, 100, 99, 100, 1, 200, 99, 200, 1, 300, -2, 300, -1, 201, 1, 301, -2, 301, -3, 301, -2, 300, -99);
1.1766 + TestGrowCompress(&b, 1, 100, 99, 100, 1, 200, 99, 200, 1, 300, -2, 300, -1, 201, 1, 301, -2, 301, -3, 301, -3, 301, -2, 200, -99);
1.1767 +
1.1768 + RArray<TInt64> c(8, 0, 512);
1.1769 + TestGrowCompress(&c, 1, 8, 7, 8, 1, 16, 7, 16, 1, 32, 15, 32, 1, 64, -2, 40, 7, 40, 1, 80, -1, 41, -99);
1.1770 +
1.1771 + RArray<TInt64> d(20, 0, 640);
1.1772 + TestGrowCompress(&d, 1, 20, 19, 20, 1, 50, 29, 50, 1, 125, -2, 60, -1, 51, -99);
1.1773 +
1.1774 + RArray<TInt64> e(8, 0, 320);
1.1775 + TestGrowCompress(&e, 1, 8, 7, 8, 1, 16, 7, 16, 1, 24, 7, 24, 1, 32, 7, 32, 1, 40, 7, 40, 1, 50, 9, 50, 1, 63, -99);
1.1776 +
1.1777 + RArray<TInt64> f(2, 0, 257);
1.1778 + TestGrowCompress(&f, 1, 2, 255, 256, 256, 512, 128, 640, 1, 643, 2, 643, 1, 646, -99);
1.1779 + }
1.1780 +
1.1781 +GLDEF_C void DoSimpleArrayTests()
1.1782 + {
1.1783 + test.Start(_L("Simple Arrays..."));
1.1784 +
1.1785 + test.Next(_L("AppendAndAccess tests..."));
1.1786 + test.Next(_L("Count 10 Mask 0x0000000300000003"));
1.1787 + test(IntAppendAndAccessTest(10,NUM_TESTS,MAKE_TINT64(0x3,0x3))==KErrNone);
1.1788 + test.Next(_L("Count 100 Range all"));
1.1789 + test(IntAppendAndAccessTest(100,NUM_TESTS,MAKE_TINT64(0xffffffff,0xffffffff))==KErrNone);
1.1790 +
1.1791 + test.Next(_L("Remove test"));
1.1792 + test(IntRemoveTest()==KErrNone);
1.1793 +
1.1794 + test.Next(_L("Find tests..."));
1.1795 + test.Next(_L("Count 10 Mask 0x0000000300000003"));
1.1796 + test(IntFindTest(10,NUM_TESTS,MAKE_TINT64(3,3))==KErrNone);
1.1797 + test.Next(_L("Count 100 Range all"));
1.1798 + test(IntFindTest(100,NUM_TESTS,MAKE_TINT64(0xffffffff,0xffffffff))==KErrNone);
1.1799 + test.Next(_L("SEntry find tests"));
1.1800 + test(EntryFindTest(128,NUM_TESTS)==KErrNone);
1.1801 + test.Next(_L("Find with equality operator tests"));
1.1802 + test(FindWithEqualityOpTest()==KErrNone);
1.1803 +
1.1804 +
1.1805 + test.Next(_L("FindReverse tests..."));
1.1806 + test.Next(_L("Count 10 Mask 0x0000000300000003"));
1.1807 + test(IntFindReverseTest(10,NUM_TESTS,MAKE_TINT64(3,3))==KErrNone);
1.1808 + test.Next(_L("Count 100 Range all"));
1.1809 + test(IntFindReverseTest(100,NUM_TESTS,MAKE_TINT64(0xffffffff,0xffffffff))==KErrNone);
1.1810 + test.Next(_L("SEntry find tests"));
1.1811 + test(EntryFindReverseTest(128,NUM_TESTS)==KErrNone);
1.1812 +
1.1813 +
1.1814 + test.Next(_L("FindInOrder tests..."));
1.1815 + test.Next(_L("Count 20 Mask 0x00000003C0000000"));
1.1816 + test(IntFindInOrderTest(20,NUM_TESTS,MAKE_TINT64(0x3,0xc0000000))==KErrNone);
1.1817 + test.Next(_L("Count 100 Mask 0x0000000FF0000000"));
1.1818 + test(IntFindInOrderTest(100,NUM_TESTS,MAKE_TINT64(0xf,0xf0000000))==KErrNone);
1.1819 + test.Next(_L("SEntry FindInOrder test"));
1.1820 + test(EntryFindInOrderTest(128,NUM_TESTS)==KErrNone);
1.1821 +
1.1822 + test.Next(_L("InsertInOrder tests..."));
1.1823 + test.Next(_L("Count 50 Mask 0x00000003C0000000"));
1.1824 + test(IntInsertInOrderTest(50,NUM_TESTS,MAKE_TINT64(0x3,0xc0000000))==KErrNone);
1.1825 + test.Next(_L("Count 100 all"));
1.1826 + test(IntInsertInOrderTest(100,NUM_TESTS,MAKE_TINT64(0xffffffff,0xffffffff))==KErrNone);
1.1827 + test.Next(_L("SEntry InsertInOrder test"));
1.1828 + test(EntryInsertInOrderTest()==KErrNone);
1.1829 +
1.1830 + test.Next(_L("Sort tests..."));
1.1831 + test.Next(_L("Count 30 Mask 0x00000003C0000000"));
1.1832 + test(IntSortTest(30,NUM_TESTS,MAKE_TINT64(0x3,0xc0000000))==KErrNone);
1.1833 + test.Next(_L("Count 100 all"));
1.1834 + test(IntSortTest(100,NUM_TESTS,MAKE_TINT64(0xffffffff,0xffffffff))==KErrNone);
1.1835 + test.Next(_L("SEntry sort test"));
1.1836 + test(EntrySortTest(128,NUM_TESTS)==KErrNone);
1.1837 +
1.1838 + test.Next(_L("SEntrySpecificFindTests..."));
1.1839 + test(SEntrySpecificFindTests(100, 10, 15)==KErrNone);
1.1840 + test(SEntrySpecificFindTests(100, 10, 127)==KErrNone);
1.1841 +
1.1842 + test.Next(_L("Test Grow/Compress"));
1.1843 + TestGrowCompress();
1.1844 +
1.1845 + test.Next(_L("Test sort methods don't access memory beyond the end of the array"));
1.1846 + test(SortAccessBoundsTest(128)==KErrNone);
1.1847 +
1.1848 + test.End();
1.1849 + }
1.1850 +
1.1851 +
1.1852 +GLDEF_C void DoArrayLeavingInterfaceTest()
1.1853 + {
1.1854 + TInt trap, ret(0);
1.1855 + TInt64 Int64s[3];
1.1856 + for (TInt i=0;i<3;i++) Int64s[i] = i;
1.1857 +
1.1858 + RArray<TInt64> array;
1.1859 + CleanupClosePushL(array);
1.1860 +
1.1861 + test.Start(_L("Checking Leaving Arrays Interface..."));
1.1862 +
1.1863 + test.Next(_L("AppendL test..."));
1.1864 + TRAP(trap, array.AppendL(Int64s[0]));
1.1865 + test(trap==KErrNone);
1.1866 +
1.1867 + test.Next(_L("InsertL test..."));
1.1868 + TRAP(trap, array.InsertL(Int64s[1],1));
1.1869 + test(trap==KErrNone);
1.1870 +
1.1871 + test.Next(_L("Test FindL(const T& anEntry) const..."));
1.1872 + TRAP(trap, ret = array.FindL(Int64s[0]));
1.1873 + test(trap==0);
1.1874 + test(ret==0);
1.1875 + TRAP(trap, ret = array.FindL(Int64s[2]));
1.1876 + test(trap==KErrNotFound);
1.1877 +
1.1878 + test.Next(_L("Test FindL(const T& anEntry, TIdentityRelation<T> anIdentity) const..."));
1.1879 + TRAP(trap, ret = array.FindL(Int64s[0],Int64Identity));
1.1880 + test(trap==0);
1.1881 + test(ret==0);
1.1882 + TRAP(trap, ret = array.FindL(Int64s[2],Int64Identity));
1.1883 + test(trap==KErrNotFound);
1.1884 +
1.1885 + test.Next(_L("Test FindInSignedKeyOrderL(const T& anEntry) const..."));
1.1886 + TRAP(trap, ret = array.FindInSignedKeyOrderL(Int64s[0]));
1.1887 + test(trap==0);
1.1888 + test(ret==0);
1.1889 + TRAP(trap, ret = array.FindInSignedKeyOrderL(Int64s[2]));
1.1890 + test(trap==KErrNotFound);
1.1891 +
1.1892 + test.Next(_L("Test FindInUnsignedKeyOrderL(const T& anEntry) const..."));
1.1893 + TRAP(trap, ret = array.FindInUnsignedKeyOrderL(Int64s[0]));
1.1894 + test(trap==0);
1.1895 + test(ret==0);
1.1896 + TRAP(trap, ret = array.FindInUnsignedKeyOrderL(Int64s[2]));
1.1897 + test(trap==KErrNotFound);
1.1898 +
1.1899 + test.Next(_L("Test FindInOrderL(const T& anEntry, TLinearOrder<T> anOrder) const..."));
1.1900 + TRAP(trap, ret = array.FindInOrderL(Int64s[0], Int64Order));
1.1901 + test(trap==0);
1.1902 + test(ret==0);
1.1903 + TRAP(trap, ret = array.FindInOrderL(Int64s[2], Int64Order));
1.1904 + test(trap==KErrNotFound);
1.1905 +
1.1906 + test.Next(_L("Test FindInSignedKeyOrderL(const T& anEntry, TInt& anIndex) const..."));
1.1907 + TRAP(trap, array.FindInSignedKeyOrderL(Int64s[0], ret));
1.1908 + test(trap==0);
1.1909 + test(ret==0);
1.1910 + TRAP(trap, array.FindInSignedKeyOrderL(Int64s[2], ret));
1.1911 + test(trap==KErrNotFound);
1.1912 +
1.1913 + test.Next(_L("Test FindInUnsignedKeyOrderL(const T& anEntry, TInt& anIndex) const..."));
1.1914 + TRAP(trap, array.FindInUnsignedKeyOrderL(Int64s[0], ret));
1.1915 + test(trap==0);
1.1916 + test(ret==0);
1.1917 + TRAP(trap, array.FindInUnsignedKeyOrderL(Int64s[2], ret));
1.1918 + test(trap==KErrNotFound);
1.1919 +
1.1920 + test.Next(_L("Test FindInOrderL(const T& anEntry, TInt& anIndex, TLinearOrder<T> anOrder) const..."));
1.1921 + TRAP(trap, array.FindInOrderL(Int64s[0], ret, Int64Order));
1.1922 + test(trap==0);
1.1923 + test(ret==0);
1.1924 + TRAP(trap, array.FindInOrderL(Int64s[2], ret, Int64Order));
1.1925 + test(trap==KErrNotFound);
1.1926 +
1.1927 + test.Next(_L("Test SpecificFindInSignedKeyOrderL(const T& anEntry, TInt aMode) const..."));
1.1928 + TRAP(trap, ret = array.SpecificFindInSignedKeyOrderL(Int64s[0], EArrayFindMode_First));
1.1929 + test(trap==0);
1.1930 + test(ret==0);
1.1931 + TRAP(trap, ret = array.SpecificFindInSignedKeyOrderL(Int64s[2], EArrayFindMode_First));
1.1932 + test(trap==KErrNotFound);
1.1933 +
1.1934 + test.Next(_L("Test SpecificFindInUnsignedKeyOrderL(const T& anEntry, TInt aMode) const..."));
1.1935 + TRAP(trap, ret = array.SpecificFindInUnsignedKeyOrderL(Int64s[0], EArrayFindMode_First));
1.1936 + test(trap==0);
1.1937 + test(ret==0);
1.1938 + TRAP(trap, ret = array.SpecificFindInUnsignedKeyOrderL(Int64s[2], EArrayFindMode_First));
1.1939 + test(trap==KErrNotFound);
1.1940 +
1.1941 + test.Next(_L("Test SpecificFindInOrderL(const T& anEntry, TLinearOrder<T> anOrder, TInt aMode) const..."));
1.1942 + TRAP(trap, ret = array.SpecificFindInOrderL(Int64s[0], Int64Order, EArrayFindMode_First));
1.1943 + test(trap==0);
1.1944 + test(ret==0);
1.1945 + TRAP(trap, ret = array.SpecificFindInOrderL(Int64s[2], Int64Order, EArrayFindMode_First));
1.1946 + test(trap==KErrNotFound);
1.1947 +
1.1948 + test.Next(_L("Test SpecificFindInSignedKeyOrderL(const T& anEntry, TInt& anIndex, TInt aMode) const..."));
1.1949 + TRAP(trap, array.SpecificFindInSignedKeyOrderL(Int64s[0], ret, EArrayFindMode_First));
1.1950 + test(trap==0);
1.1951 + test(ret==0);
1.1952 + TRAP(trap, array.SpecificFindInSignedKeyOrderL(Int64s[2], ret, EArrayFindMode_First));
1.1953 + test(trap==KErrNotFound);
1.1954 +
1.1955 + test.Next(_L("Test SpecificFindInUnsignedKeyOrderL(const T& anEntry, TInt& anIndex, TInt aMode) const..."));
1.1956 + TRAP(trap, array.SpecificFindInUnsignedKeyOrderL(Int64s[0], ret, EArrayFindMode_First));
1.1957 + test(trap==0);
1.1958 + test(ret==0);
1.1959 + TRAP(trap, array.SpecificFindInUnsignedKeyOrderL(Int64s[2], ret, EArrayFindMode_First));
1.1960 + test(trap==KErrNotFound);
1.1961 +
1.1962 + test.Next(_L("Test SpecificFindInOrderL(const T& anEntry, TInt& anIndex, TLinearOrder<T> anOrder, TInt aMode) const..."));
1.1963 + TRAP(trap, array.SpecificFindInOrderL(Int64s[0], ret, Int64Order, EArrayFindMode_First));
1.1964 + test(trap==0);
1.1965 + test(ret==0);
1.1966 + TRAP(trap, array.SpecificFindInOrderL(Int64s[2], ret, Int64Order, EArrayFindMode_First));
1.1967 + test(trap==KErrNotFound);
1.1968 +
1.1969 + test.Next(_L("Test InsertInSignedKeyOrderL(const T& anEntry)..."));
1.1970 + TRAP(trap, array.InsertInSignedKeyOrderL(Int64s[0]));
1.1971 + test(trap==KErrAlreadyExists);
1.1972 + TRAP(trap, array.InsertInSignedKeyOrderL(Int64s[2]));
1.1973 + test(trap==KErrNone);
1.1974 + array.Remove(2);
1.1975 +
1.1976 + test.Next(_L("Test InsertInUnsignedKeyOrderL(const T& anEntry)..."));
1.1977 + TRAP(trap, array.InsertInUnsignedKeyOrderL(Int64s[0]));
1.1978 + test(trap==KErrAlreadyExists);
1.1979 + TRAP(trap, array.InsertInUnsignedKeyOrderL(Int64s[2]));
1.1980 + test(trap==KErrNone);
1.1981 + array.Remove(2);
1.1982 +
1.1983 + test.Next(_L("Test InsertInOrderL(const T& anEntry, TLinearOrder<T> anOrder)..."));
1.1984 + TRAP(trap, array.InsertInOrderL(Int64s[0], Int64Order));
1.1985 + test(trap==KErrAlreadyExists);
1.1986 + TRAP(trap, array.InsertInOrderL(Int64s[2], Int64Order));
1.1987 + test(trap==KErrNone);
1.1988 + array.Remove(2);
1.1989 +
1.1990 + test.Next(_L("Test InsertInSignedKeyOrderAllowRepeatsL(const T& anEntry)..."));
1.1991 + TRAP(trap, array.InsertInSignedKeyOrderAllowRepeatsL(Int64s[2]));
1.1992 + test(trap==KErrNone);
1.1993 + array.Remove(2);
1.1994 +
1.1995 + test.Next(_L("Test InsertInUnsignedKeyOrderAllowRepeatsL(const T& anEntry)..."));
1.1996 + TRAP(trap, array.InsertInUnsignedKeyOrderAllowRepeatsL(Int64s[2]));
1.1997 + test(trap==KErrNone);
1.1998 + array.Remove(2);
1.1999 +
1.2000 + test.Next(_L("Test InsertInOrderAllowRepeatsL(const T& anEntry, TLinearOrder<T> anOrder)..."));
1.2001 + TRAP(trap, array.InsertInOrderAllowRepeatsL(Int64s[2], Int64Order));
1.2002 + test(trap==KErrNone);
1.2003 + array.Remove(2);
1.2004 +
1.2005 + CleanupStack::PopAndDestroy(&array);
1.2006 + test.End();
1.2007 + }
1.2008 +
1.2009 +GLDEF_C void DoTIntArrayLeavingInterfaceTest()
1.2010 + {
1.2011 + TInt trap, ret(0);
1.2012 + TInt Ints[3];
1.2013 + for (TInt i=0;i<3;i++) Ints[i] = i;
1.2014 +
1.2015 + RArray<TInt> array;
1.2016 + CleanupClosePushL(array);
1.2017 +
1.2018 + test.Start(_L("Checking Leaving Array<TInt> Interface..."));
1.2019 +
1.2020 + test.Next(_L("AppendL test..."));
1.2021 + TRAP(trap, array.AppendL(Ints[0]));
1.2022 + test(trap==KErrNone);
1.2023 +
1.2024 + test.Next(_L("InsertL test..."));
1.2025 + TRAP(trap, array.InsertL(Ints[1],1));
1.2026 + test(trap==KErrNone);
1.2027 +
1.2028 + test.Next(_L("Test FindL(TInt anEntry) const..."));
1.2029 + TRAP(trap, ret = array.FindL(Ints[0]));
1.2030 + test(trap==0);
1.2031 + test(ret==0);
1.2032 + TRAP(trap, ret = array.FindL(Ints[2]));
1.2033 + test(trap==KErrNotFound);
1.2034 +
1.2035 +
1.2036 + test.Next(_L("Test FindInOrderL(TInt anEntry) const..."));
1.2037 + TRAP(trap, ret = array.FindInOrderL(Ints[0]));
1.2038 + test(trap==0);
1.2039 + test(ret==0);
1.2040 + TRAP(trap, ret = array.FindInOrderL(Ints[2]));
1.2041 + test(trap==KErrNotFound);
1.2042 +
1.2043 + test.Next(_L("Test FindInOrderL(TInt anEntry, TInt& anIndex) const..."));
1.2044 + TRAP(trap, array.FindInOrderL(Ints[0], ret));
1.2045 + test(trap==0);
1.2046 + test(ret==0);
1.2047 + TRAP(trap, array.FindInOrderL(Ints[2], ret));
1.2048 + test(trap==KErrNotFound);
1.2049 +
1.2050 + test.Next(_L("Test SpecificFindInOrderL(TInt anEntry, TInt aMode) const..."));
1.2051 + TRAP(trap, ret = array.SpecificFindInOrderL(Ints[0], EArrayFindMode_First));
1.2052 + test(trap==0);
1.2053 + test(ret==0);
1.2054 + TRAP(trap, ret = array.SpecificFindInOrderL(Ints[2], EArrayFindMode_First));
1.2055 + test(trap==KErrNotFound);
1.2056 +
1.2057 + test.Next(_L("Test SpecificFindInOrderL(TInt anEntry, TInt& anIndex, TInt aMode) const..."));
1.2058 + TRAP(trap, array.SpecificFindInOrderL(Ints[0], ret, EArrayFindMode_First));
1.2059 + test(trap==0);
1.2060 + test(ret==0);
1.2061 + TRAP(trap, array.SpecificFindInOrderL(Ints[2], ret, EArrayFindMode_First));
1.2062 + test(trap==KErrNotFound);
1.2063 +
1.2064 + test.Next(_L("Test InsertInOrderL(TInt anEntry)..."));
1.2065 + TRAP(trap, array.InsertInOrderL(Ints[0]));
1.2066 + test(trap==KErrAlreadyExists);
1.2067 + TRAP(trap, array.InsertInOrderL(Ints[2]));
1.2068 + test(trap==KErrNone);
1.2069 + array.Remove(2);
1.2070 +
1.2071 + test.Next(_L("Test InsertInOrderAllowRepeatsL(TInt anEntry)..."));
1.2072 + TRAP(trap, array.InsertInOrderAllowRepeatsL(Ints[2]));
1.2073 + test(trap==KErrNone);
1.2074 + array.Remove(2);
1.2075 +
1.2076 + CleanupStack::PopAndDestroy(&array);
1.2077 + test.End();
1.2078 + }
1.2079 +
1.2080 +GLDEF_C void DoTUintArrayLeavingInterfaceTest()
1.2081 + {
1.2082 + TInt trap, ret(0);
1.2083 + TInt UInts[3];
1.2084 + for (TInt i=0;i<3;i++) UInts[i] = i;
1.2085 +
1.2086 + RArray<TInt> array;
1.2087 + CleanupClosePushL(array);
1.2088 +
1.2089 + test.Start(_L("Checking Leaving Array<TUint> Interface..."));
1.2090 +
1.2091 + test.Next(_L("AppendL test..."));
1.2092 + TRAP(trap, array.AppendL(UInts[0]));
1.2093 + test(trap==KErrNone);
1.2094 +
1.2095 + test.Next(_L("InsertL test..."));
1.2096 + TRAP(trap, array.InsertL(UInts[1],1));
1.2097 + test(trap==KErrNone);
1.2098 +
1.2099 + test.Next(_L("Test FindL(TUint anEntry) const..."));
1.2100 + TRAP(trap, ret = array.FindL(UInts[0]));
1.2101 + test(trap==0);
1.2102 + test(ret==0);
1.2103 + TRAP(trap, ret = array.FindL(UInts[2]));
1.2104 + test(trap==KErrNotFound);
1.2105 +
1.2106 +
1.2107 + test.Next(_L("Test FindInOrderL(TUint anEntry) const..."));
1.2108 + TRAP(trap, ret = array.FindInOrderL(UInts[0]));
1.2109 + test(trap==0);
1.2110 + test(ret==0);
1.2111 + TRAP(trap, ret = array.FindInOrderL(UInts[2]));
1.2112 + test(trap==KErrNotFound);
1.2113 +
1.2114 + test.Next(_L("Test FindInOrderL(TUint anEntry, TInt& anIndex) const..."));
1.2115 + TRAP(trap, array.FindInOrderL(UInts[0], ret));
1.2116 + test(trap==0);
1.2117 + test(ret==0);
1.2118 + TRAP(trap, array.FindInOrderL(UInts[2], ret));
1.2119 + test(trap==KErrNotFound);
1.2120 +
1.2121 + test.Next(_L("Test SpecificFindInOrderL(TUint anEntry, TInt aMode) const..."));
1.2122 + TRAP(trap, ret = array.SpecificFindInOrderL(UInts[0], EArrayFindMode_First));
1.2123 + test(trap==0);
1.2124 + test(ret==0);
1.2125 + TRAP(trap, ret = array.SpecificFindInOrderL(UInts[2], EArrayFindMode_First));
1.2126 + test(trap==KErrNotFound);
1.2127 +
1.2128 + test.Next(_L("Test SpecificFindInOrderL(TUint anEntry, TInt& anIndex, TInt aMode) const..."));
1.2129 + TRAP(trap, array.SpecificFindInOrderL(UInts[0], ret, EArrayFindMode_First));
1.2130 + test(trap==0);
1.2131 + test(ret==0);
1.2132 + TRAP(trap, array.SpecificFindInOrderL(UInts[2], ret, EArrayFindMode_First));
1.2133 + test(trap==KErrNotFound);
1.2134 +
1.2135 + test.Next(_L("Test InsertInOrderL(TUint anEntry)..."));
1.2136 + TRAP(trap, array.InsertInOrderL(UInts[0]));
1.2137 + test(trap==KErrAlreadyExists);
1.2138 + TRAP(trap, array.InsertInOrderL(UInts[2]));
1.2139 + test(trap==KErrNone);
1.2140 + array.Remove(2);
1.2141 +
1.2142 + test.Next(_L("Test InsertInOrderAllowRepeatsL(TUint anEntry)..."));
1.2143 + TRAP(trap, array.InsertInOrderAllowRepeatsL(UInts[2]));
1.2144 + test(trap==KErrNone);
1.2145 + array.Remove(2);
1.2146 +
1.2147 + CleanupStack::PopAndDestroy(&array);
1.2148 + test.End();
1.2149 + }