home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / test / eh / test_hash_map.cpp < prev    next >
C/C++ Source or Header  |  2000-12-07  |  5KB  |  142 lines

  1. /***********************************************************************************
  2.     test_hash_map.cpp
  3.     
  4.  * Copyright (c) 1997
  5.  * Mark of the Unicorn, Inc.
  6.  *
  7.  * Permission to use, copy, modify, distribute and sell this software
  8.  * and its documentation for any purpose is hereby granted without fee,
  9.  * provided that the above copyright notice appear in all copies and
  10.  * that both that copyright notice and this permission notice appear
  11.  * in supporting documentation.  Mark of the Unicorn makes no
  12.  * representations about the suitability of this software for any
  13.  * purpose.  It is provided "as is" without express or implied warranty.
  14.  
  15. ***********************************************************************************/
  16. #include "Tests.h"
  17. #if defined( EH_HASHED_CONTAINERS_IMPLEMENTED )
  18. #include "TestClass.h"
  19. #include "LeakCheck.h"
  20. #if defined (__SGI_STL)
  21. # if defined (EH_NEW_HEADERS)
  22. #  include <hash_map>
  23. # else
  24. #  include <hash_map.h>
  25. # endif
  26. #elif defined (__MSL__)
  27. # include <hashmap.h>
  28. # include <hashmmap.h>
  29. #else
  30. # error where do I get hash_map/hash_multimap?
  31. #endif
  32. #include "test_construct.h"
  33. #include "test_assign_op.h"
  34. #include "test_push_back.h"
  35. #include "test_insert.h"
  36. #include "test_push_front.h"
  37. #include "ThrowCompare.h"
  38. #include "test_hash_resize.h"
  39. /*
  40. template struct pair<const TestClass, TestClass>;
  41. template struct __hashtable_node<pair<const TestClass, TestClass> >;
  42. template class hash_map<TestClass, TestClass, ThrowHash, ThrowEqual>;
  43. template class hash_multimap<TestClass, TestClass, ThrowHash, ThrowEqual>;
  44. */
  45.  
  46. typedef EH_STD::__hash_multimap__<TestClass, TestClass, ThrowHash, ThrowEqual,
  47.   eh_allocator(TestClass) > TestMultiMap;
  48.  
  49.  
  50. inline multimap_tag
  51. container_category(const TestMultiMap&)
  52. {
  53.     return multimap_tag();
  54. }
  55.  
  56. void test_hash_multimap()
  57. {
  58. # if !(defined (_MSC_VER) && (_MSC_VER < 1100))
  59.     TestMultiMap testMultiMap, testMultiMap2;
  60.     
  61.         const EH_STD::size_t hash_mapSize = random_number(random_base);
  62.     
  63.     while ( testMultiMap.size() < hash_mapSize )
  64.     {
  65.         TestMultiMap::value_type x;
  66.         testMultiMap.insert( x );
  67.         testMultiMap2.insert( TestMultiMap::value_type() );
  68.     }
  69.  
  70. #  if defined( EH_HASH_CONTAINERS_SUPPORT_RESIZE )
  71.     WeakCheck( testMultiMap, test_hash_resize<TestMultiMap>() );
  72.     StrongCheck( testMultiMap, test_insert_noresize<TestMultiMap>(testMultiMap) );
  73. #  endif
  74.     WeakCheck( testMultiMap, test_insert_value<TestMultiMap>(testMultiMap) );
  75.  
  76.     EH_STD::size_t insCnt = random_number(random_base);
  77.     TestMultiMap::value_type *insFirst = new TestMultiMap::value_type[1+insCnt];
  78.     WeakCheck( testMultiMap, insert_range_tester(testMultiMap, insFirst, insFirst+insCnt) );
  79.     ConstCheck( 0, test_construct_pointer_range<TestMultiMap>(insFirst, insFirst+insCnt) );
  80.     delete[] insFirst;
  81.     
  82.     WeakCheck( testMultiMap, insert_range_tester(testMultiMap, testMultiMap2.begin(), testMultiMap2.end() ) );
  83.     
  84.     ConstCheck( 0, test_default_construct<TestMultiMap>() );
  85. #  if EH_HASH_CONTAINERS_SUPPORT_ITERATOR_CONSTRUCTION
  86.     ConstCheck( 0, test_construct_iter_range_n<TestMultiMap>( testMultiMap2 ) );
  87. #  endif
  88.     ConstCheck( testMultiMap, test_copy_construct<TestMultiMap>() );
  89.     
  90.     WeakCheck( testMultiMap, test_assign_op<TestMultiMap>( testMultiMap2 ) );
  91. # endif
  92. }
  93.  
  94. typedef EH_STD::__hash_map__<TestClass, TestClass, ThrowHash, 
  95.   ThrowEqual, eh_allocator(TestClass) > TestMap;
  96.  
  97. inline map_tag
  98. container_category(const TestMap&)
  99. {
  100.     return map_tag();
  101. }
  102.  
  103. void test_hash_map()
  104. {
  105. # if !(defined (_MSC_VER) && (_MSC_VER < 1100))
  106.     TestMap testMap, testMap2;
  107.     
  108.     const EH_STD::size_t hash_mapSize = random_number(random_base);
  109.  
  110.     while ( testMap.size() < hash_mapSize )
  111.     {
  112.         TestMap::value_type x;
  113.         testMap.insert( x );
  114.         testMap2.insert( TestMap::value_type() );
  115.     }
  116.  
  117. #if defined( EH_HASH_CONTAINERS_SUPPORT_RESIZE )
  118.     WeakCheck( testMap, test_hash_resize<TestMap>() );
  119.     StrongCheck( testMap, test_insert_noresize<TestMap>(testMap) );
  120. #endif
  121.     WeakCheck( testMap, test_insert_value<TestMap>(testMap) );
  122.  
  123.     EH_STD::size_t insCnt = random_number(random_base);
  124.     TestMap::value_type *insFirst = new TestMap::value_type[1+insCnt];
  125.     WeakCheck( testMap, insert_range_tester(testMap, insFirst, insFirst+insCnt) );
  126.     ConstCheck( 0, test_construct_pointer_range<TestMap>(insFirst, insFirst+insCnt) );
  127.     delete[] insFirst;
  128.     
  129.     WeakCheck( testMap, insert_range_tester(testMap, testMap2.begin(), testMap2.end() ) );
  130.     
  131.     ConstCheck( 0, test_default_construct<TestMap>() );
  132. #  if EH_HASH_CONTAINERS_SUPPORT_ITERATOR_CONSTRUCTION
  133.     ConstCheck( 0, test_construct_iter_range_n<TestMap>( testMap2 ) );
  134. #  endif
  135.     ConstCheck( testMap, test_copy_construct<TestMap>() );
  136.     
  137.     WeakCheck( testMap, test_assign_op<TestMap>( testMap2 ) );
  138. # endif
  139. }
  140.  
  141. #endif    // EH_HASHED_CONTAINERS_IMPLEMENTED
  142.