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

  1. /***********************************************************************************
  2.     test_hash_set.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. #if defined (__SGI_STL)
  19. # if defined (EH_NEW_HEADERS)
  20. #  include <hash_set>
  21. # else
  22. #  include <hash_set.h>
  23. # endif
  24. #elif defined (__MSL__)
  25. # include <hashset.h>
  26. # include <hashmset.h>
  27. #else
  28. # error where do I get hash_set/hash_multiset?
  29. #endif
  30. #include "TestClass.h"
  31. #include "LeakCheck.h"
  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. typedef EH_STD::__hash_multiset__<TestClass, ThrowHash, ThrowEqual,
  41.   eh_allocator(TestClass) > TestMultiSet;
  42.  
  43. inline multiset_tag
  44. container_category(const TestMultiSet&)
  45. {
  46.   return multiset_tag();
  47. }
  48.  
  49. void test_hash_multiset()
  50. {
  51. # if !(defined (_MSC_VER) && (_MSC_VER < 1100))
  52.     TestMultiSet testMultiSet, testMultiSet2;
  53.     
  54.         const EH_STD::size_t hash_setSize = random_number(random_base);
  55.     
  56.     while ( testMultiSet.size() < hash_setSize )
  57.     {
  58.         TestMultiSet::value_type x;
  59.         testMultiSet.insert( x );
  60.         testMultiSet2.insert( TestMultiSet::value_type() );
  61.     }
  62.  
  63. #  if defined( EH_HASH_CONTAINERS_SUPPORT_RESIZE )
  64.     WeakCheck( testMultiSet, test_hash_resize<TestMultiSet>() );
  65.     StrongCheck( testMultiSet, test_insert_noresize<TestMultiSet>(testMultiSet) );
  66. #  endif
  67.     WeakCheck( testMultiSet, test_insert_value<TestMultiSet>(testMultiSet) );
  68.  
  69.     EH_STD::size_t insCnt = random_number(random_base);
  70.     TestMultiSet::value_type *insFirst = new TestMultiSet::value_type[1+insCnt];
  71.     WeakCheck( testMultiSet, insert_range_tester(testMultiSet, insFirst, insFirst+insCnt) );
  72.     ConstCheck( 0, test_construct_pointer_range<TestMultiSet>(insFirst, insFirst+insCnt) );
  73.     delete[] insFirst;
  74.     
  75.     WeakCheck( testMultiSet, insert_range_tester(testMultiSet, testMultiSet2.begin(), testMultiSet2.end() ) );
  76.     
  77.     ConstCheck( 0, test_default_construct<TestMultiSet>() );
  78. #  if EH_HASH_CONTAINERS_SUPPORT_ITERATOR_CONSTRUCTION
  79.     ConstCheck( 0, test_construct_iter_range_n<TestMultiSet>( testMultiSet2 ) );
  80. #  endif
  81.     ConstCheck( testMultiSet, test_copy_construct<TestMultiSet>() );
  82.     
  83.     WeakCheck( testMultiSet, test_assign_op<TestMultiSet>( testMultiSet2 ) );
  84. # endif
  85. }
  86.  
  87. typedef EH_STD::__hash_set__<TestClass, ThrowHash, ThrowEqual, eh_allocator(TestClass) > TestSet;
  88.  
  89. inline set_tag
  90. container_category(const TestSet&)
  91. {
  92.   return set_tag();
  93. }
  94.  
  95. void test_hash_set()
  96. {
  97. # if !(defined (_MSC_VER) && (_MSC_VER < 1100))
  98.     TestSet testSet, testSet2;
  99.     
  100.         const EH_STD::size_t hash_setSize = random_number(random_base);
  101.  
  102.     while ( testSet.size() < hash_setSize )
  103.     {
  104.         TestSet::value_type x;
  105.         testSet.insert( x );
  106.         testSet2.insert( TestSet::value_type() );
  107.     }
  108.  
  109. #  if defined( EH_HASH_CONTAINERS_SUPPORT_RESIZE )
  110.     WeakCheck( testSet, test_hash_resize<TestSet>() );
  111.     StrongCheck( testSet, test_insert_noresize<TestSet>(testSet) );
  112. #  endif
  113.     WeakCheck( testSet, test_insert_value<TestSet>(testSet) );
  114.  
  115.     EH_STD::size_t insCnt = random_number(random_base);
  116.     TestSet::value_type *insFirst = new TestSet::value_type[1+insCnt];
  117.     WeakCheck( testSet, insert_range_tester(testSet, insFirst, insFirst+insCnt) );
  118.     ConstCheck( 0, test_construct_pointer_range<TestSet>(insFirst, insFirst+insCnt) );
  119.     delete[] insFirst;
  120.     
  121.     WeakCheck( testSet, insert_range_tester(testSet, testSet2.begin(), testSet2.end() ) );
  122.     
  123.     ConstCheck( 0, test_default_construct<TestSet>() );
  124. #  if EH_HASH_CONTAINERS_SUPPORT_ITERATOR_CONSTRUCTION
  125.     ConstCheck( 0, test_construct_iter_range_n<TestSet>( testSet2 ) );
  126. #  endif
  127.     ConstCheck( testSet, test_copy_construct<TestSet>() );
  128.     
  129.     WeakCheck( testSet, test_assign_op<TestSet>( testSet2 ) );
  130. # endif
  131. }
  132.  
  133. #endif    // EH_HASHED_CONTAINERS_IMPLEMENTED
  134.