os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_hash_map.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_hash_map.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,131 @@
     1.4 +/***********************************************************************************
     1.5 +  test_hash_map.cpp
     1.6 +
     1.7 + * Copyright (c) 1997
     1.8 + * Mark of the Unicorn, Inc.
     1.9 + *
    1.10 + * Permission to use, copy, modify, distribute and sell this software
    1.11 + * and its documentation for any purpose is hereby granted without fee,
    1.12 + * provided that the above copyright notice appear in all copies and
    1.13 + * that both that copyright notice and this permission notice appear
    1.14 + * in supporting documentation.  Mark of the Unicorn makes no
    1.15 + * representations about the suitability of this software for any
    1.16 + * purpose.  It is provided "as is" without express or implied warranty.
    1.17 +
    1.18 +***********************************************************************************/
    1.19 +#include "Tests.h"
    1.20 +#if defined( EH_HASHED_CONTAINERS_IMPLEMENTED )
    1.21 +#include "TestClass.h"
    1.22 +#include "LeakCheck.h"
    1.23 +
    1.24 +#  include <hash_map>
    1.25 +
    1.26 +#include "test_construct.h"
    1.27 +#include "test_assign_op.h"
    1.28 +#include "test_push_back.h"
    1.29 +#include "test_insert.h"
    1.30 +#include "test_push_front.h"
    1.31 +#include "ThrowCompare.h"
    1.32 +#include "test_hash_resize.h"
    1.33 +/*
    1.34 +template struct pair<const TestClass, TestClass>;
    1.35 +template struct __hashtable_node<pair<const TestClass, TestClass> >;
    1.36 +template class hash_map<TestClass, TestClass, ThrowHash, ThrowEqual>;
    1.37 +template class hash_multimap<TestClass, TestClass, ThrowHash, ThrowEqual>;
    1.38 +*/
    1.39 +
    1.40 +typedef EH_STD::__hash_multimap__<TestClass, TestClass, ThrowHash, ThrowEqual,
    1.41 +  eh_allocator(TestClass) > TestMultiMap;
    1.42 +
    1.43 +
    1.44 +inline multimap_tag
    1.45 +container_category(const TestMultiMap&) {
    1.46 +  return multimap_tag();
    1.47 +}
    1.48 +
    1.49 +void test_hash_multimap() {
    1.50 +# if !(defined (_MSC_VER) && (_MSC_VER < 1100))
    1.51 +  TestMultiMap testMultiMap, testMultiMap2;
    1.52 +
    1.53 +        const size_t hash_mapSize = random_number(random_base);
    1.54 +
    1.55 +  while ( testMultiMap.size() < hash_mapSize )
    1.56 +  {
    1.57 +    TestMultiMap::value_type x;
    1.58 +    testMultiMap.insert( x );
    1.59 +    testMultiMap2.insert( TestMultiMap::value_type() );
    1.60 +  }
    1.61 +
    1.62 +#  if defined( EH_HASH_CONTAINERS_SUPPORT_RESIZE )
    1.63 +  WeakCheck( testMultiMap, test_hash_resize<TestMultiMap>() );
    1.64 +  // TestMultiMap == TestMultiMap: no such operator! - ptr
    1.65 +  // StrongCheck( testMultiMap, test_insert_noresize<TestMultiMap>(testMultiMap) );
    1.66 +#  endif
    1.67 +  WeakCheck( testMultiMap, test_insert_value<TestMultiMap>(testMultiMap) );
    1.68 +
    1.69 +  size_t insCnt = random_number(random_base);
    1.70 +  TestMultiMap::value_type *insFirst = new TestMultiMap::value_type[1+insCnt];
    1.71 +  WeakCheck( testMultiMap, insert_range_tester(testMultiMap, insFirst, insFirst+insCnt) );
    1.72 +  ConstCheck( 0, test_construct_pointer_range<TestMultiMap>(insFirst, insFirst+insCnt) );
    1.73 +  delete[] insFirst;
    1.74 +
    1.75 +  WeakCheck( testMultiMap, insert_range_tester(testMultiMap, testMultiMap2.begin(), testMultiMap2.end() ) );
    1.76 +
    1.77 +  ConstCheck( 0, test_default_construct<TestMultiMap>() );
    1.78 +#  if EH_HASH_CONTAINERS_SUPPORT_ITERATOR_CONSTRUCTION
    1.79 +  ConstCheck( 0, test_construct_iter_range_n<TestMultiMap>( testMultiMap2 ) );
    1.80 +#  endif
    1.81 +  ConstCheck( testMultiMap, test_copy_construct<TestMultiMap>() );
    1.82 +
    1.83 +  WeakCheck( testMultiMap, test_assign_op<TestMultiMap>( testMultiMap2 ) );
    1.84 +# endif
    1.85 +}
    1.86 +
    1.87 +typedef EH_STD::__hash_map__<TestClass, TestClass, ThrowHash,
    1.88 +  ThrowEqual, eh_allocator(TestClass) > TestMap;
    1.89 +
    1.90 +inline map_tag
    1.91 +container_category(const TestMap&)
    1.92 +{
    1.93 +  return map_tag();
    1.94 +}
    1.95 +
    1.96 +void test_hash_map()
    1.97 +{
    1.98 +# if !(defined (_MSC_VER) && (_MSC_VER < 1100))
    1.99 +  TestMap testMap, testMap2;
   1.100 +
   1.101 +  const size_t hash_mapSize = random_number(random_base);
   1.102 +
   1.103 +  while ( testMap.size() < hash_mapSize ) {
   1.104 +    TestMap::value_type x;
   1.105 +    testMap.insert( x );
   1.106 +    testMap2.insert( TestMap::value_type() );
   1.107 +  }
   1.108 +
   1.109 +#if defined( EH_HASH_CONTAINERS_SUPPORT_RESIZE )
   1.110 +  WeakCheck( testMap, test_hash_resize<TestMap>() );
   1.111 +  // TestMultiMap == TestMultiMap: no such operator! - ptr
   1.112 +  // StrongCheck( testMap, test_insert_noresize<TestMap>(testMap) );
   1.113 +#endif
   1.114 +  WeakCheck( testMap, test_insert_value<TestMap>(testMap) );
   1.115 +
   1.116 +  size_t insCnt = random_number(random_base);
   1.117 +  TestMap::value_type *insFirst = new TestMap::value_type[1+insCnt];
   1.118 +  WeakCheck( testMap, insert_range_tester(testMap, insFirst, insFirst+insCnt) );
   1.119 +  ConstCheck( 0, test_construct_pointer_range<TestMap>(insFirst, insFirst+insCnt) );
   1.120 +  delete[] insFirst;
   1.121 +
   1.122 +  WeakCheck( testMap, insert_range_tester(testMap, testMap2.begin(), testMap2.end() ) );
   1.123 +
   1.124 +  ConstCheck( 0, test_default_construct<TestMap>() );
   1.125 +#  if EH_HASH_CONTAINERS_SUPPORT_ITERATOR_CONSTRUCTION
   1.126 +  ConstCheck( 0, test_construct_iter_range_n<TestMap>( testMap2 ) );
   1.127 +#  endif
   1.128 +  ConstCheck( testMap, test_copy_construct<TestMap>() );
   1.129 +
   1.130 +  WeakCheck( testMap, test_assign_op<TestMap>( testMap2 ) );
   1.131 +# endif
   1.132 +}
   1.133 +
   1.134 +#endif  // EH_HASHED_CONTAINERS_IMPLEMENTED