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