kerneltest/e32test/buffer/t_hashtab.cpp
changeset 271 dc268b18d709
parent 0 a41df078684a
equal deleted inserted replaced
269:d57b86b1867a 271:dc268b18d709
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
  1489 		test(r==KErrNone);
  1489 		test(r==KErrNone);
  1490 		}
  1490 		}
  1491 	map.ResetAndDestroy();
  1491 	map.ResetAndDestroy();
  1492 	}
  1492 	}
  1493 
  1493 
       
  1494 void TestInsertL()
       
  1495     {
       
  1496     TInt i;
       
  1497     TInt count=50;
       
  1498     const TInt KMaxBufferSize=256;
       
  1499     // Array used to hold test data to store in the hash objects
       
  1500     RPointerArray<TDesC16> iPointerArray;
       
  1501     
       
  1502     for (i=0; i<count; ++i)
       
  1503         {
       
  1504         HBufC* hbuf = HBufC::NewLC(KMaxBufferSize);
       
  1505         TPtr buf = hbuf->Des();
       
  1506         TTestName number(NumberInWords(i));
       
  1507         buf.Copy(number);
       
  1508 		// Append "one" "two" "three" .....
       
  1509         iPointerArray.AppendL(hbuf);
       
  1510         CleanupStack::Pop(hbuf);
       
  1511         }
       
  1512         
       
  1513     // Creates an object ptrHashMap using the template class RPtrHashMap
       
  1514     RPtrHashMap<TDesC16, TDesC16> ptrHashMap;
       
  1515     // Push object on to the cleanup stack
       
  1516     CleanupClosePushL(ptrHashMap);
       
  1517     // Expand the array with the number of key-value pairs for which space should be allocated
       
  1518     ptrHashMap.ReserveL(count);
       
  1519     
       
  1520     // Insert a key-value pairs into the array
       
  1521     for (i=0; i<count; ++i)
       
  1522         {
       
  1523         // "zero"-"forty nine" 
       
  1524         // "one"-"forty eight" .....
       
  1525         ptrHashMap.InsertL(iPointerArray[i], iPointerArray[count-1-i]);
       
  1526         }
       
  1527     
       
  1528     // Close and Cleanup
       
  1529     CleanupStack::PopAndDestroy(&ptrHashMap);
       
  1530     iPointerArray.ResetAndDestroy();
       
  1531     }
       
  1532                                        
       
  1533 
  1494 void TestOOM()
  1534 void TestOOM()
  1495 	{
  1535 	{
  1496 	// Max out memory and check it still works
  1536 	// Max out memory and check it still works
  1497 	test.Next(_L("Test OOM"));
  1537 	test.Next(_L("Test OOM"));
  1498 
  1538 
  2423 
  2463 
  2424 
  2464 
  2425 	TestOOM();
  2465 	TestOOM();
  2426 	Benchmark();
  2466 	Benchmark();
  2427 	TestSmallReserve();
  2467 	TestSmallReserve();
  2428 
  2468 	
       
  2469 	// Get cleanup stack
       
  2470 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
  2471 	TInt result = KErrNoMemory;
       
  2472 	if (cleanup)
       
  2473 	    {
       
  2474 	    TRAP(result, TestInsertL());
       
  2475 	    // Destroy the cleanup stack
       
  2476 	    delete cleanup;
       
  2477 	    }
       
  2478 		
  2429 	test.End();
  2479 	test.End();
  2430 
  2480 
  2431 	__UHEAP_MARKEND;
  2481 	__UHEAP_MARKEND;
  2432 	return 0;
  2482 	return 0;
  2433 	}
  2483 	}