[CMAKE]
[reactos.git] / lib / 3rdparty / stlport / test / eh / test_hash_map.cpp
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
21 # include <hash_map>
22
23 #include "test_construct.h"
24 #include "test_assign_op.h"
25 #include "test_push_back.h"
26 #include "test_insert.h"
27 #include "test_push_front.h"
28 #include "ThrowCompare.h"
29 #include "test_hash_resize.h"
30 /*
31 template struct pair<const TestClass, TestClass>;
32 template struct __hashtable_node<pair<const TestClass, TestClass> >;
33 template class hash_map<TestClass, TestClass, ThrowHash, ThrowEqual>;
34 template class hash_multimap<TestClass, TestClass, ThrowHash, ThrowEqual>;
35 */
36
37 typedef EH_STD::__hash_multimap__<TestClass, TestClass, ThrowHash, ThrowEqual,
38 eh_allocator(TestClass) > TestMultiMap;
39
40
41 inline multimap_tag
42 container_category(const TestMultiMap&) {
43 return multimap_tag();
44 }
45
46 void test_hash_multimap() {
47 # if !(defined (_MSC_VER) && (_MSC_VER < 1100))
48 TestMultiMap testMultiMap, testMultiMap2;
49
50 const size_t hash_mapSize = random_number(random_base);
51
52 while ( testMultiMap.size() < hash_mapSize )
53 {
54 TestMultiMap::value_type x;
55 testMultiMap.insert( x );
56 testMultiMap2.insert( TestMultiMap::value_type() );
57 }
58
59 # if defined( EH_HASH_CONTAINERS_SUPPORT_RESIZE )
60 WeakCheck( testMultiMap, test_hash_resize<TestMultiMap>() );
61 // TestMultiMap == TestMultiMap: no such operator! - ptr
62 // StrongCheck( testMultiMap, test_insert_noresize<TestMultiMap>(testMultiMap) );
63 # endif
64 WeakCheck( testMultiMap, test_insert_value<TestMultiMap>(testMultiMap) );
65
66 size_t insCnt = random_number(random_base);
67 TestMultiMap::value_type *insFirst = new TestMultiMap::value_type[1+insCnt];
68 WeakCheck( testMultiMap, insert_range_tester(testMultiMap, insFirst, insFirst+insCnt) );
69 ConstCheck( 0, test_construct_pointer_range<TestMultiMap>(insFirst, insFirst+insCnt) );
70 delete[] insFirst;
71
72 WeakCheck( testMultiMap, insert_range_tester(testMultiMap, testMultiMap2.begin(), testMultiMap2.end() ) );
73
74 ConstCheck( 0, test_default_construct<TestMultiMap>() );
75 # if EH_HASH_CONTAINERS_SUPPORT_ITERATOR_CONSTRUCTION
76 ConstCheck( 0, test_construct_iter_range_n<TestMultiMap>( testMultiMap2 ) );
77 # endif
78 ConstCheck( testMultiMap, test_copy_construct<TestMultiMap>() );
79
80 WeakCheck( testMultiMap, test_assign_op<TestMultiMap>( testMultiMap2 ) );
81 # endif
82 }
83
84 typedef EH_STD::__hash_map__<TestClass, TestClass, ThrowHash,
85 ThrowEqual, eh_allocator(TestClass) > TestMap;
86
87 inline map_tag
88 container_category(const TestMap&)
89 {
90 return map_tag();
91 }
92
93 void test_hash_map()
94 {
95 # if !(defined (_MSC_VER) && (_MSC_VER < 1100))
96 TestMap testMap, testMap2;
97
98 const size_t hash_mapSize = random_number(random_base);
99
100 while ( testMap.size() < hash_mapSize ) {
101 TestMap::value_type x;
102 testMap.insert( x );
103 testMap2.insert( TestMap::value_type() );
104 }
105
106 #if defined( EH_HASH_CONTAINERS_SUPPORT_RESIZE )
107 WeakCheck( testMap, test_hash_resize<TestMap>() );
108 // TestMultiMap == TestMultiMap: no such operator! - ptr
109 // StrongCheck( testMap, test_insert_noresize<TestMap>(testMap) );
110 #endif
111 WeakCheck( testMap, test_insert_value<TestMap>(testMap) );
112
113 size_t insCnt = random_number(random_base);
114 TestMap::value_type *insFirst = new TestMap::value_type[1+insCnt];
115 WeakCheck( testMap, insert_range_tester(testMap, insFirst, insFirst+insCnt) );
116 ConstCheck( 0, test_construct_pointer_range<TestMap>(insFirst, insFirst+insCnt) );
117 delete[] insFirst;
118
119 WeakCheck( testMap, insert_range_tester(testMap, testMap2.begin(), testMap2.end() ) );
120
121 ConstCheck( 0, test_default_construct<TestMap>() );
122 # if EH_HASH_CONTAINERS_SUPPORT_ITERATOR_CONSTRUCTION
123 ConstCheck( 0, test_construct_iter_range_n<TestMap>( testMap2 ) );
124 # endif
125 ConstCheck( testMap, test_copy_construct<TestMap>() );
126
127 WeakCheck( testMap, test_assign_op<TestMap>( testMap2 ) );
128 # endif
129 }
130
131 #endif // EH_HASHED_CONTAINERS_IMPLEMENTED