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